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