(root)/
glibc-2.38/
sysdeps/
generic/
math_private.h
       1  /*
       2   * ====================================================
       3   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
       4   *
       5   * Developed at SunPro, a Sun Microsystems, Inc. business.
       6   * Permission to use, copy, modify, and distribute this
       7   * software is freely granted, provided that this notice
       8   * is preserved.
       9   * ====================================================
      10   */
      11  
      12  /*
      13   * from: @(#)fdlibm.h 5.1 93/09/24
      14   */
      15  
      16  #ifndef _MATH_PRIVATE_H_
      17  #define _MATH_PRIVATE_H_
      18  
      19  #include <endian.h>
      20  #include <stdbool.h>
      21  #include <stdint.h>
      22  #include <sys/types.h>
      23  
      24  /* Gather machine dependent _Floatn support.  */
      25  #include <bits/floatn.h>
      26  
      27  /* The original fdlibm code used statements like:
      28  	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
      29  	ix0 = *(n0+(int*)&x);			* high word of x *
      30  	ix1 = *((1-n0)+(int*)&x);		* low word of x *
      31     to dig two 32 bit words out of the 64 bit IEEE floating point
      32     value.  That is non-ANSI, and, moreover, the gcc instruction
      33     scheduler gets it wrong.  We instead use the following macros.
      34     Unlike the original code, we determine the endianness at compile
      35     time, not at run time; I don't see much benefit to selecting
      36     endianness at run time.  */
      37  
      38  /* A union which permits us to convert between a double and two 32 bit
      39     ints.  */
      40  
      41  #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
      42  
      43  typedef union
      44  {
      45    double value;
      46    struct
      47    {
      48      uint32_t msw;
      49      uint32_t lsw;
      50    } parts;
      51    uint64_t word;
      52  } ieee_double_shape_type;
      53  
      54  #endif
      55  
      56  #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
      57  
      58  typedef union
      59  {
      60    double value;
      61    struct
      62    {
      63      uint32_t lsw;
      64      uint32_t msw;
      65    } parts;
      66    uint64_t word;
      67  } ieee_double_shape_type;
      68  
      69  #endif
      70  
      71  /* Get two 32 bit ints from a double.  */
      72  
      73  #define EXTRACT_WORDS(ix0,ix1,d)				\
      74  do {								\
      75    ieee_double_shape_type ew_u;					\
      76    ew_u.value = (d);						\
      77    (ix0) = ew_u.parts.msw;					\
      78    (ix1) = ew_u.parts.lsw;					\
      79  } while (0)
      80  
      81  /* Get the more significant 32 bit int from a double.  */
      82  
      83  #ifndef GET_HIGH_WORD
      84  # define GET_HIGH_WORD(i,d)					\
      85  do {								\
      86    ieee_double_shape_type gh_u;					\
      87    gh_u.value = (d);						\
      88    (i) = gh_u.parts.msw;						\
      89  } while (0)
      90  #endif
      91  
      92  /* Get the less significant 32 bit int from a double.  */
      93  
      94  #ifndef GET_LOW_WORD
      95  # define GET_LOW_WORD(i,d)					\
      96  do {								\
      97    ieee_double_shape_type gl_u;					\
      98    gl_u.value = (d);						\
      99    (i) = gl_u.parts.lsw;						\
     100  } while (0)
     101  #endif
     102  
     103  /* Get all in one, efficient on 64-bit machines.  */
     104  #ifndef EXTRACT_WORDS64
     105  # define EXTRACT_WORDS64(i,d)					\
     106  do {								\
     107    ieee_double_shape_type gh_u;					\
     108    gh_u.value = (d);						\
     109    (i) = gh_u.word;						\
     110  } while (0)
     111  #endif
     112  
     113  /* Set a double from two 32 bit ints.  */
     114  #ifndef INSERT_WORDS
     115  # define INSERT_WORDS(d,ix0,ix1)				\
     116  do {								\
     117    ieee_double_shape_type iw_u;					\
     118    iw_u.parts.msw = (ix0);					\
     119    iw_u.parts.lsw = (ix1);					\
     120    (d) = iw_u.value;						\
     121  } while (0)
     122  #endif
     123  
     124  /* Get all in one, efficient on 64-bit machines.  */
     125  #ifndef INSERT_WORDS64
     126  # define INSERT_WORDS64(d,i)					\
     127  do {								\
     128    ieee_double_shape_type iw_u;					\
     129    iw_u.word = (i);						\
     130    (d) = iw_u.value;						\
     131  } while (0)
     132  #endif
     133  
     134  /* Set the more significant 32 bits of a double from an int.  */
     135  #ifndef SET_HIGH_WORD
     136  #define SET_HIGH_WORD(d,v)					\
     137  do {								\
     138    ieee_double_shape_type sh_u;					\
     139    sh_u.value = (d);						\
     140    sh_u.parts.msw = (v);						\
     141    (d) = sh_u.value;						\
     142  } while (0)
     143  #endif
     144  
     145  /* Set the less significant 32 bits of a double from an int.  */
     146  #ifndef SET_LOW_WORD
     147  # define SET_LOW_WORD(d,v)					\
     148  do {								\
     149    ieee_double_shape_type sl_u;					\
     150    sl_u.value = (d);						\
     151    sl_u.parts.lsw = (v);						\
     152    (d) = sl_u.value;						\
     153  } while (0)
     154  #endif
     155  
     156  /* We need to guarantee an expansion of name when building
     157     ldbl-128 files as another type (e.g _Float128).  */
     158  #define mathx_hidden_def(name) hidden_def(name)
     159  
     160  /* Get long double macros from a separate header.  */
     161  #include <math_ldbl.h>
     162  
     163  /* Include function declarations for each floating-point.  */
     164  #define _Mdouble_ double
     165  #define _MSUF_
     166  #include <math_private_calls.h>
     167  #undef _MSUF_
     168  #undef _Mdouble_
     169  
     170  #define _Mdouble_ float
     171  #define _MSUF_ f
     172  #define __MATH_DECLARING_FLOAT
     173  #include <math_private_calls.h>
     174  #undef __MATH_DECLARING_FLOAT
     175  #undef _MSUF_
     176  #undef _Mdouble_
     177  
     178  #define _Mdouble_ long double
     179  #define _MSUF_ l
     180  #define __MATH_DECLARING_LONG_DOUBLE
     181  #include <math_private_calls.h>
     182  #undef __MATH_DECLARING_LONG_DOUBLE
     183  #undef _MSUF_
     184  #undef _Mdouble_
     185  
     186  #if __HAVE_DISTINCT_FLOAT128
     187  # define _Mdouble_ _Float128
     188  # define _MSUF_ f128
     189  # define __MATH_DECLARING_FLOATN
     190  # include <math_private_calls.h>
     191  # undef __MATH_DECLARING_FLOATN
     192  # undef _MSUF_
     193  # undef _Mdouble_
     194  #endif
     195  
     196  #define NOINLINE __attribute__ ((noinline))
     197  
     198  /* Prototypes for functions of the IBM Accurate Mathematical Library.  */
     199  extern double __sin (double __x);
     200  extern double __cos (double __x);
     201  extern int __branred (double __x, double *__a, double *__aa);
     202  
     203  #endif /* _MATH_PRIVATE_H_ */