Blame sysdeps/x86_64/fpu/math_ldbl.h

Packit 6c4009
/* Manipulation of the bit representation of 'long double' quantities.
Packit 6c4009
   Copyright (C) 2001-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
Packit 6c4009
/* A union which permits us to convert between a long double and
Packit 6c4009
   three 32 bit ints.  */
Packit 6c4009
Packit 6c4009
typedef union
Packit 6c4009
{
Packit 6c4009
  long double value;
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    uint32_t lsw;
Packit 6c4009
    uint32_t msw;
Packit 6c4009
    int sign_exponent:16;
Packit 6c4009
    unsigned int empty1:16;
Packit 6c4009
    unsigned int empty0:32;
Packit 6c4009
  } parts;
Packit 6c4009
} ieee_long_double_shape_type;
Packit 6c4009
Packit 6c4009
/* Get three 32 bit ints from a double.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_WORDS(exp,ix0,ix1,d)			\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type ew_u;				\
Packit 6c4009
  ew_u.value = (d);						\
Packit 6c4009
  (exp) = ew_u.parts.sign_exponent;				\
Packit 6c4009
  (ix0) = ew_u.parts.msw;					\
Packit 6c4009
  (ix1) = ew_u.parts.lsw;					\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Set a double from two 32 bit ints.  */
Packit 6c4009
Packit 6c4009
#define SET_LDOUBLE_WORDS(d,exp,ix0,ix1)			\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type iw_u;				\
Packit 6c4009
  iw_u.parts.sign_exponent = (exp);				\
Packit 6c4009
  iw_u.parts.msw = (ix0);					\
Packit 6c4009
  iw_u.parts.lsw = (ix1);					\
Packit 6c4009
  (d) = iw_u.value;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Get the more significant 32 bits of a long double mantissa.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_MSW(v,d)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type sh_u;				\
Packit 6c4009
  sh_u.value = (d);						\
Packit 6c4009
  (v) = sh_u.parts.msw;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Set the more significant 32 bits of a long double mantissa from an int.  */
Packit 6c4009
Packit 6c4009
#define SET_LDOUBLE_MSW(d,v)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type sh_u;				\
Packit 6c4009
  sh_u.value = (d);						\
Packit 6c4009
  sh_u.parts.msw = (v);						\
Packit 6c4009
  (d) = sh_u.value;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Get int from the exponent of a long double.  */
Packit 6c4009
Packit 6c4009
#define GET_LDOUBLE_EXP(exp,d)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type ge_u;				\
Packit 6c4009
  ge_u.value = (d);						\
Packit 6c4009
  (exp) = ge_u.parts.sign_exponent;				\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Set exponent of a long double from an int.  */
Packit 6c4009
Packit 6c4009
#define SET_LDOUBLE_EXP(d,exp)					\
Packit 6c4009
do {								\
Packit 6c4009
  ieee_long_double_shape_type se_u;				\
Packit 6c4009
  se_u.value = (d);						\
Packit 6c4009
  se_u.parts.sign_exponent = (exp);				\
Packit 6c4009
  (d) = se_u.value;						\
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
#endif /* math_ldbl.h */