Home | History | Annotate | Line # | Download | only in bid
      1      1.1  christos /* This is a software decimal floating point library.
      2  1.1.1.3  christos    Copyright (C) 2007-2018 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos This file is part of GCC.
      5      1.1  christos 
      6      1.1  christos GCC is free software; you can redistribute it and/or modify it under
      7      1.1  christos the terms of the GNU General Public License as published by the Free
      8      1.1  christos Software Foundation; either version 3, or (at your option) any later
      9      1.1  christos version.
     10      1.1  christos 
     11      1.1  christos GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12      1.1  christos WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13      1.1  christos FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14      1.1  christos for more details.
     15      1.1  christos 
     16      1.1  christos Under Section 7 of GPL version 3, you are granted additional
     17      1.1  christos permissions described in the GCC Runtime Library Exception, version
     18      1.1  christos 3.1, as published by the Free Software Foundation.
     19      1.1  christos 
     20      1.1  christos You should have received a copy of the GNU General Public License and
     21      1.1  christos a copy of the GCC Runtime Library Exception along with this program;
     22      1.1  christos see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23      1.1  christos <http://www.gnu.org/licenses/>.  */
     24      1.1  christos 
     25      1.1  christos #include <string.h>
     26      1.1  christos 
     27      1.1  christos #include "dconfig.h"
     28      1.1  christos #include "bid-dpd.h"
     29      1.1  christos #include "decimal128.h"
     30      1.1  christos 
     31      1.1  christos void __host_to_ieee_128 (_Decimal128 in, decimal128 *out);
     32      1.1  christos void __ieee_to_host_128 (decimal128 in, _Decimal128 *out);
     33      1.1  christos 
     34      1.1  christos /* The code for converting 128-bit values between DPD and BID presumes
     35      1.1  christos    that the 64-bit halves of the 128-bit value are in little-endian
     36      1.1  christos    order, so they need swapping on big-endian hosts.  */
     37      1.1  christos 
     38      1.1  christos void
     39      1.1  christos __host_to_ieee_128 (_Decimal128 in, decimal128 *out)
     40      1.1  christos {
     41      1.1  christos #if WORDS_BIGENDIAN
     42      1.1  christos   memcpy ((char *) out, (char *) &in + 8, 8);
     43      1.1  christos   memcpy ((char *) out + 8, (char *) &in, 8);
     44      1.1  christos #else
     45      1.1  christos   memcpy ((char *) out, (char *) &in, 16);
     46      1.1  christos #endif
     47      1.1  christos }
     48      1.1  christos 
     49      1.1  christos void
     50      1.1  christos __ieee_to_host_128 (decimal128 in, _Decimal128 *out)
     51      1.1  christos {
     52      1.1  christos #if WORDS_BIGENDIAN
     53      1.1  christos   memcpy ((char *) out, (char *) &in + 8, 8);
     54      1.1  christos   memcpy ((char *) out + 8, (char *) &in, 8);
     55      1.1  christos #else
     56      1.1  christos   memcpy ((char *) out, (char *) &in, 16);
     57      1.1  christos #endif
     58      1.1  christos }
     59