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