Blame sysdeps/ieee754/ldbl-128/math_ldbl.h

Packit 6c4009
/* Manipulation of the bit representation of 'long double' quantities.
Packit 6c4009
   Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _MATH_LDBL_H_
Packit 6c4009
#define _MATH_LDBL_H_ 1
Packit 6c4009
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <endian.h>
Packit 6c4009
Packit 6c4009
/* A union which permits us to convert between a long double and
Packit 6c4009
   four 32 bit ints or two 64 bit ints.  */
Packit 6c4009
Packit 6c4009
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
Packit 6c4009
Packit 6c4009
typedef union
Packit 6c4009
{
Packit 6c4009
  long double value;
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    uint64_t msw;
Packit 6c4009
    uint64_t lsw;
Packit 6c4009
  } parts64;
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    uint32_t w0, w1, w2, w3;
Packit 6c4009
  } parts32;
Packit 6c4009
} ieee854_long_double_shape_type;
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
Packit 6c4009
Packit 6c4009
typedef union
Packit 6c4009
{
Packit 6c4009
  long double value;
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    uint64_t lsw;
Packit 6c4009
    uint64_t msw;
Packit 6c4009
  } parts64;
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    uint32_t w3, w2, w1, w0;
Packit 6c4009
  } parts32;
Packit 6c4009
} ieee854_long_double_shape_type;
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Get two 64 bit ints from a long double.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_WORDS64(ix0,ix1,d)				\
Packit 6c4009
do {								\
Packit 6c4009
  ieee854_long_double_shape_type qw_u;				\
Packit 6c4009
  qw_u.value = (d);						\
Packit 6c4009
  (ix0) = qw_u.parts64.msw;					\
Packit 6c4009
  (ix1) = qw_u.parts64.lsw;					\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Set a long double from two 64 bit ints.  */
Packit 6c4009
Packit 6c4009
#define SET_LDOUBLE_WORDS64(d,ix0,ix1)				\
Packit 6c4009
do {								\
Packit 6c4009
  ieee854_long_double_shape_type qw_u;				\
Packit 6c4009
  qw_u.parts64.msw = (ix0);					\
Packit 6c4009
  qw_u.parts64.lsw = (ix1);					\
Packit 6c4009
  (d) = qw_u.value;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Get the more significant 64 bits of a long double mantissa.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_MSW64(v,d)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee854_long_double_shape_type sh_u;				\
Packit 6c4009
  sh_u.value = (d);						\
Packit 6c4009
  (v) = sh_u.parts64.msw;					\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Set the more significant 64 bits of a long double mantissa from an int.  */
Packit 6c4009
Packit 6c4009
#define SET_LDOUBLE_MSW64(d,v)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee854_long_double_shape_type sh_u;				\
Packit 6c4009
  sh_u.value = (d);						\
Packit 6c4009
  sh_u.parts64.msw = (v);					\
Packit 6c4009
  (d) = sh_u.value;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Get the least significant 64 bits of a long double mantissa.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_LSW64(v,d)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee854_long_double_shape_type sh_u;				\
Packit 6c4009
  sh_u.value = (d);						\
Packit 6c4009
  (v) = sh_u.parts64.lsw;					\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
   On a platform already supporting a binary128 long double,
Packit 6c4009
   _Float128 will alias to long double.  This transformation
Packit 6c4009
   makes aliasing *l functions to *f128 trivial.
Packit 6c4009
*/
Packit 6c4009
#define _Float128 long double
Packit 6c4009
#define L(x) x##L
Packit 6c4009
Packit 6c4009
#endif /* math_ldbl.h */