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