Back to index

cell-binutils  2.17cvs20070401
flonum-copy.c
Go to the documentation of this file.
00001 /* flonum_copy.c - copy a flonum
00002    Copyright 1987, 1990, 1991, 1992, 1993, 2000, 2003
00003    Free Software Foundation, Inc.
00004 
00005    This file is part of GAS, the GNU Assembler.
00006 
00007    GAS is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    GAS is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with GAS; see the file COPYING.  If not, write to the Free
00019    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00020    02110-1301, USA.  */
00021 
00022 #include "as.h"
00023 
00024 void
00025 flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out)
00026 {
00027   unsigned int in_length;   /* 0 origin */
00028   unsigned int out_length;  /* 0 origin */
00029 
00030   out->sign = in->sign;
00031   in_length = in->leader - in->low;
00032 
00033   if (in->leader < in->low)
00034     {
00035       out->leader = out->low - 1;  /* 0.0 case */
00036     }
00037   else
00038     {
00039       out_length = out->high - out->low;
00040       /* Assume no GAPS in packing of littlenums.
00041         I.e. sizeof(array) == sizeof(element) * number_of_elements.  */
00042       if (in_length <= out_length)
00043        {
00044          {
00045            /* For defensive programming, zero any high-order
00046               littlenums we don't need.  This is destroying evidence
00047               and wasting time, so why bother???  */
00048            if (in_length < out_length)
00049              {
00050               memset ((char *) (out->low + in_length + 1), '\0',
00051                      out_length - in_length);
00052              }
00053          }
00054          memcpy ((void *) (out->low), (void *) (in->low),
00055                 ((in_length + 1) * sizeof (LITTLENUM_TYPE)));
00056          out->exponent = in->exponent;
00057          out->leader = in->leader - in->low + out->low;
00058        }
00059       else
00060        {
00061          int shorten;              /* 1-origin. Number of littlenums we drop.  */
00062 
00063          shorten = in_length - out_length;
00064          /* Assume out_length >= 0 ! */
00065          memcpy ((void *) (out->low), (void *) (in->low + shorten),
00066                 ((out_length + 1) * sizeof (LITTLENUM_TYPE)));
00067          out->leader = out->high;
00068          out->exponent = in->exponent + shorten;
00069        }
00070     }                       /* if any significant bits */
00071 }