/src/binutils-gdb/gas/flonum-copy.c
Line | Count | Source |
1 | | /* flonum_copy.c - copy a flonum |
2 | | Copyright (C) 1987-2026 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GAS, the GNU Assembler. |
5 | | |
6 | | GAS is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | GAS is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with GAS; see the file COPYING. If not, write to the Free |
18 | | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | #include "as.h" |
22 | | |
23 | | void |
24 | | flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out) |
25 | 44 | { |
26 | 44 | unsigned int in_length; /* 0 origin */ |
27 | 44 | unsigned int out_length; /* 0 origin */ |
28 | | |
29 | 44 | out->sign = in->sign; |
30 | 44 | in_length = in->leader - in->low; |
31 | | |
32 | 44 | if (in->leader < in->low) |
33 | 0 | { |
34 | 0 | out->leader = out->low - 1; /* 0.0 case */ |
35 | 0 | } |
36 | 44 | else |
37 | 44 | { |
38 | 44 | out_length = out->high - out->low; |
39 | | /* Assume no GAPS in packing of littlenums. |
40 | | I.e. sizeof(array) == sizeof(element) * number_of_elements. */ |
41 | 44 | if (in_length <= out_length) |
42 | 44 | { |
43 | 44 | { |
44 | | /* For defensive programming, zero any high-order |
45 | | littlenums we don't need. This is destroying evidence |
46 | | and wasting time, so why bother??? */ |
47 | 44 | if (in_length < out_length) |
48 | 0 | { |
49 | 0 | memset (out->low + in_length + 1, 0, out_length - in_length); |
50 | 0 | } |
51 | 44 | } |
52 | 44 | memcpy (out->low, in->low, |
53 | 44 | (in_length + 1) * sizeof (LITTLENUM_TYPE)); |
54 | 44 | out->exponent = in->exponent; |
55 | 44 | out->leader = in->leader - in->low + out->low; |
56 | 44 | } |
57 | 0 | else |
58 | 0 | { |
59 | 0 | int shorten; /* 1-origin. Number of littlenums we drop. */ |
60 | |
|
61 | 0 | shorten = in_length - out_length; |
62 | | /* Assume out_length >= 0 ! */ |
63 | 0 | memcpy (out->low, in->low + shorten, |
64 | 0 | (out_length + 1) * sizeof (LITTLENUM_TYPE)); |
65 | 0 | out->leader = out->high; |
66 | 0 | out->exponent = in->exponent + shorten; |
67 | 0 | } |
68 | 44 | } /* if any significant bits */ |
69 | 44 | } |