Blame libdecnumber/bid/host-ieee128.c

Packit 7cb7d8
/* This is a software decimal floating point library.
Packit 7cb7d8
   Copyright (C) 2007-2018 Free Software Foundation, Inc.
Packit 7cb7d8
Packit 7cb7d8
This file is part of GCC.
Packit 7cb7d8
Packit 7cb7d8
GCC is free software; you can redistribute it and/or modify it under
Packit 7cb7d8
the terms of the GNU General Public License as published by the Free
Packit 7cb7d8
Software Foundation; either version 3, or (at your option) any later
Packit 7cb7d8
version.
Packit 7cb7d8
Packit 7cb7d8
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
Packit 7cb7d8
WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit 7cb7d8
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 7cb7d8
for more details.
Packit 7cb7d8
Packit 7cb7d8
Under Section 7 of GPL version 3, you are granted additional
Packit 7cb7d8
permissions described in the GCC Runtime Library Exception, version
Packit 7cb7d8
3.1, as published by the Free Software Foundation.
Packit 7cb7d8
Packit 7cb7d8
You should have received a copy of the GNU General Public License and
Packit 7cb7d8
a copy of the GCC Runtime Library Exception along with this program;
Packit 7cb7d8
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
Packit 7cb7d8
<http://www.gnu.org/licenses/>.  */
Packit 7cb7d8
Packit 7cb7d8
#include <string.h>
Packit 7cb7d8
Packit 7cb7d8
#include "dconfig.h"
Packit 7cb7d8
#include "bid-dpd.h"
Packit 7cb7d8
#include "decimal128.h"
Packit 7cb7d8
Packit 7cb7d8
void __host_to_ieee_128 (_Decimal128 in, decimal128 *out);
Packit 7cb7d8
void __ieee_to_host_128 (decimal128 in, _Decimal128 *out);
Packit 7cb7d8
Packit 7cb7d8
/* The code for converting 128-bit values between DPD and BID presumes
Packit 7cb7d8
   that the 64-bit halves of the 128-bit value are in little-endian
Packit 7cb7d8
   order, so they need swapping on big-endian hosts.  */
Packit 7cb7d8
Packit 7cb7d8
void
Packit 7cb7d8
__host_to_ieee_128 (_Decimal128 in, decimal128 *out)
Packit 7cb7d8
{
Packit 7cb7d8
#if WORDS_BIGENDIAN
Packit 7cb7d8
  memcpy ((char *) out, (char *) &in + 8, 8);
Packit 7cb7d8
  memcpy ((char *) out + 8, (char *) &in, 8);
Packit 7cb7d8
#else
Packit 7cb7d8
  memcpy ((char *) out, (char *) &in, 16);
Packit 7cb7d8
#endif
Packit 7cb7d8
}
Packit 7cb7d8
Packit 7cb7d8
void
Packit 7cb7d8
__ieee_to_host_128 (decimal128 in, _Decimal128 *out)
Packit 7cb7d8
{
Packit 7cb7d8
#if WORDS_BIGENDIAN
Packit 7cb7d8
  memcpy ((char *) out, (char *) &in + 8, 8);
Packit 7cb7d8
  memcpy ((char *) out + 8, (char *) &in, 8);
Packit 7cb7d8
#else
Packit 7cb7d8
  memcpy ((char *) out, (char *) &in, 16);
Packit 7cb7d8
#endif
Packit 7cb7d8
}