Back to index

glibc  2.9
quad.h
Go to the documentation of this file.
00001 /* Software floating-point emulation.
00002    Definitions for IEEE Quad Precision.
00003    Copyright (C) 1997,1998,1999,2006,2007 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Richard Henderson (rth@cygnus.com),
00006                 Jakub Jelinek (jj@ultra.linux.cz),
00007                 David S. Miller (davem@redhat.com) and
00008                 Peter Maydell (pmaydell@chiark.greenend.org.uk).
00009 
00010    The GNU C Library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    In addition to the permissions in the GNU Lesser General Public
00016    License, the Free Software Foundation gives you unlimited
00017    permission to link the compiled version of this file into
00018    combinations with other programs, and to distribute those
00019    combinations without any restriction coming from the use of this
00020    file.  (The Lesser General Public License restrictions do apply in
00021    other respects; for example, they cover modification of the file,
00022    and distribution when not linked into a combine executable.)
00023 
00024    The GNU C Library is distributed in the hope that it will be useful,
00025    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027    Lesser General Public License for more details.
00028 
00029    You should have received a copy of the GNU Lesser General Public
00030    License along with the GNU C Library; if not, write to the Free
00031    Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
00032    MA 02110-1301, USA.  */
00033 
00034 #if _FP_W_TYPE_SIZE < 32
00035 #error "Here's a nickel, kid. Go buy yourself a real computer."
00036 #endif
00037 
00038 #if _FP_W_TYPE_SIZE < 64
00039 #define _FP_FRACTBITS_Q         (4*_FP_W_TYPE_SIZE)
00040 #else
00041 #define _FP_FRACTBITS_Q            (2*_FP_W_TYPE_SIZE)
00042 #endif
00043 
00044 #define _FP_FRACBITS_Q             113
00045 #define _FP_FRACXBITS_Q            (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
00046 #define _FP_WFRACBITS_Q            (_FP_WORKBITS + _FP_FRACBITS_Q)
00047 #define _FP_WFRACXBITS_Q    (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
00048 #define _FP_EXPBITS_Q              15
00049 #define _FP_EXPBIAS_Q              16383
00050 #define _FP_EXPMAX_Q        32767
00051 
00052 #define _FP_QNANBIT_Q              \
00053        ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
00054 #define _FP_QNANBIT_SH_Q           \
00055        ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
00056 #define _FP_IMPLBIT_Q              \
00057        ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
00058 #define _FP_IMPLBIT_SH_Q           \
00059        ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
00060 #define _FP_OVERFLOW_Q             \
00061        ((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
00062 
00063 typedef float TFtype __attribute__((mode(TF)));
00064 
00065 #if _FP_W_TYPE_SIZE < 64
00066 
00067 union _FP_UNION_Q
00068 {
00069    TFtype flt;
00070    struct 
00071    {
00072 #if __BYTE_ORDER == __BIG_ENDIAN
00073       unsigned sign : 1;
00074       unsigned exp : _FP_EXPBITS_Q;
00075       unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
00076       unsigned long frac2 : _FP_W_TYPE_SIZE;
00077       unsigned long frac1 : _FP_W_TYPE_SIZE;
00078       unsigned long frac0 : _FP_W_TYPE_SIZE;
00079 #else
00080       unsigned long frac0 : _FP_W_TYPE_SIZE;
00081       unsigned long frac1 : _FP_W_TYPE_SIZE;
00082       unsigned long frac2 : _FP_W_TYPE_SIZE;
00083       unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
00084       unsigned exp : _FP_EXPBITS_Q;
00085       unsigned sign : 1;
00086 #endif /* not bigendian */
00087    } bits __attribute__((packed));
00088 };
00089 
00090 
00091 #define FP_DECL_Q(X)        _FP_DECL(4,X)
00092 #define FP_UNPACK_RAW_Q(X,val)     _FP_UNPACK_RAW_4(Q,X,val)
00093 #define FP_UNPACK_RAW_QP(X,val)    _FP_UNPACK_RAW_4_P(Q,X,val)
00094 #define FP_PACK_RAW_Q(val,X)       _FP_PACK_RAW_4(Q,val,X)
00095 #define FP_PACK_RAW_QP(val,X)             \
00096   do {                             \
00097     if (!FP_INHIBIT_RESULTS)              \
00098       _FP_PACK_RAW_4_P(Q,val,X);   \
00099   } while (0)
00100 
00101 #define FP_UNPACK_Q(X,val)         \
00102   do {                             \
00103     _FP_UNPACK_RAW_4(Q,X,val);            \
00104     _FP_UNPACK_CANONICAL(Q,4,X);   \
00105   } while (0)
00106 
00107 #define FP_UNPACK_QP(X,val)        \
00108   do {                             \
00109     _FP_UNPACK_RAW_4_P(Q,X,val);   \
00110     _FP_UNPACK_CANONICAL(Q,4,X);   \
00111   } while (0)
00112 
00113 #define FP_UNPACK_SEMIRAW_Q(X,val) \
00114   do {                             \
00115     _FP_UNPACK_RAW_4(Q,X,val);            \
00116     _FP_UNPACK_SEMIRAW(Q,4,X);            \
00117   } while (0)
00118 
00119 #define FP_UNPACK_SEMIRAW_QP(X,val)       \
00120   do {                             \
00121     _FP_UNPACK_RAW_4_P(Q,X,val);   \
00122     _FP_UNPACK_SEMIRAW(Q,4,X);            \
00123   } while (0)
00124 
00125 #define FP_PACK_Q(val,X)           \
00126   do {                             \
00127     _FP_PACK_CANONICAL(Q,4,X);            \
00128     _FP_PACK_RAW_4(Q,val,X);              \
00129   } while (0)
00130 
00131 #define FP_PACK_QP(val,X)          \
00132   do {                             \
00133     _FP_PACK_CANONICAL(Q,4,X);            \
00134     if (!FP_INHIBIT_RESULTS)              \
00135       _FP_PACK_RAW_4_P(Q,val,X);   \
00136   } while (0)
00137 
00138 #define FP_PACK_SEMIRAW_Q(val,X)   \
00139   do {                             \
00140     _FP_PACK_SEMIRAW(Q,4,X);              \
00141     _FP_PACK_RAW_4(Q,val,X);              \
00142   } while (0)
00143 
00144 #define FP_PACK_SEMIRAW_QP(val,X)  \
00145   do {                             \
00146     _FP_PACK_SEMIRAW(Q,4,X);              \
00147     if (!FP_INHIBIT_RESULTS)              \
00148       _FP_PACK_RAW_4_P(Q,val,X);   \
00149   } while (0)
00150 
00151 #define FP_ISSIGNAN_Q(X)           _FP_ISSIGNAN(Q,4,X)
00152 #define FP_NEG_Q(R,X)                     _FP_NEG(Q,4,R,X)
00153 #define FP_ADD_Q(R,X,Y)                   _FP_ADD(Q,4,R,X,Y)
00154 #define FP_SUB_Q(R,X,Y)                   _FP_SUB(Q,4,R,X,Y)
00155 #define FP_MUL_Q(R,X,Y)                   _FP_MUL(Q,4,R,X,Y)
00156 #define FP_DIV_Q(R,X,Y)                   _FP_DIV(Q,4,R,X,Y)
00157 #define FP_SQRT_Q(R,X)                    _FP_SQRT(Q,4,R,X)
00158 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_4(R,S,T,X,Q)
00159 
00160 #define FP_CMP_Q(r,X,Y,un)  _FP_CMP(Q,4,r,X,Y,un)
00161 #define FP_CMP_EQ_Q(r,X,Y)  _FP_CMP_EQ(Q,4,r,X,Y)
00162 #define FP_CMP_UNORD_Q(r,X,Y)      _FP_CMP_UNORD(Q,4,r,X,Y)
00163 
00164 #define FP_TO_INT_Q(r,X,rsz,rsg)   _FP_TO_INT(Q,4,r,X,rsz,rsg)
00165 #define FP_FROM_INT_Q(X,r,rs,rt)   _FP_FROM_INT(Q,4,X,r,rs,rt)
00166 
00167 #define _FP_FRAC_HIGH_Q(X)  _FP_FRAC_HIGH_4(X)
00168 #define _FP_FRAC_HIGH_RAW_Q(X)     _FP_FRAC_HIGH_4(X)
00169 
00170 #else   /* not _FP_W_TYPE_SIZE < 64 */
00171 union _FP_UNION_Q
00172 {
00173   TFtype flt /* __attribute__((mode(TF))) */ ;
00174   struct {
00175     _FP_W_TYPE a, b;
00176   } longs;
00177   struct {
00178 #if __BYTE_ORDER == __BIG_ENDIAN
00179     unsigned sign    : 1;
00180     unsigned exp     : _FP_EXPBITS_Q;
00181     _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
00182     _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
00183 #else
00184     _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
00185     _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
00186     unsigned exp     : _FP_EXPBITS_Q;
00187     unsigned sign    : 1;
00188 #endif
00189   } bits;
00190 };
00191 
00192 #define FP_DECL_Q(X)        _FP_DECL(2,X)
00193 #define FP_UNPACK_RAW_Q(X,val)     _FP_UNPACK_RAW_2(Q,X,val)
00194 #define FP_UNPACK_RAW_QP(X,val)    _FP_UNPACK_RAW_2_P(Q,X,val)
00195 #define FP_PACK_RAW_Q(val,X)       _FP_PACK_RAW_2(Q,val,X)
00196 #define FP_PACK_RAW_QP(val,X)             \
00197   do {                             \
00198     if (!FP_INHIBIT_RESULTS)              \
00199       _FP_PACK_RAW_2_P(Q,val,X);   \
00200   } while (0)
00201 
00202 #define FP_UNPACK_Q(X,val)         \
00203   do {                             \
00204     _FP_UNPACK_RAW_2(Q,X,val);            \
00205     _FP_UNPACK_CANONICAL(Q,2,X);   \
00206   } while (0)
00207 
00208 #define FP_UNPACK_QP(X,val)        \
00209   do {                             \
00210     _FP_UNPACK_RAW_2_P(Q,X,val);   \
00211     _FP_UNPACK_CANONICAL(Q,2,X);   \
00212   } while (0)
00213 
00214 #define FP_UNPACK_SEMIRAW_Q(X,val) \
00215   do {                             \
00216     _FP_UNPACK_RAW_2(Q,X,val);            \
00217     _FP_UNPACK_SEMIRAW(Q,2,X);            \
00218   } while (0)
00219 
00220 #define FP_UNPACK_SEMIRAW_QP(X,val)       \
00221   do {                             \
00222     _FP_UNPACK_RAW_2_P(Q,X,val);   \
00223     _FP_UNPACK_SEMIRAW(Q,2,X);            \
00224   } while (0)
00225 
00226 #define FP_PACK_Q(val,X)           \
00227   do {                             \
00228     _FP_PACK_CANONICAL(Q,2,X);            \
00229     _FP_PACK_RAW_2(Q,val,X);              \
00230   } while (0)
00231 
00232 #define FP_PACK_QP(val,X)          \
00233   do {                             \
00234     _FP_PACK_CANONICAL(Q,2,X);            \
00235     if (!FP_INHIBIT_RESULTS)              \
00236       _FP_PACK_RAW_2_P(Q,val,X);   \
00237   } while (0)
00238 
00239 #define FP_PACK_SEMIRAW_Q(val,X)   \
00240   do {                             \
00241     _FP_PACK_SEMIRAW(Q,2,X);              \
00242     _FP_PACK_RAW_2(Q,val,X);              \
00243   } while (0)
00244 
00245 #define FP_PACK_SEMIRAW_QP(val,X)  \
00246   do {                             \
00247     _FP_PACK_SEMIRAW(Q,2,X);              \
00248     if (!FP_INHIBIT_RESULTS)              \
00249       _FP_PACK_RAW_2_P(Q,val,X);   \
00250   } while (0)
00251 
00252 #define FP_ISSIGNAN_Q(X)           _FP_ISSIGNAN(Q,2,X)
00253 #define FP_NEG_Q(R,X)                     _FP_NEG(Q,2,R,X)
00254 #define FP_ADD_Q(R,X,Y)                   _FP_ADD(Q,2,R,X,Y)
00255 #define FP_SUB_Q(R,X,Y)                   _FP_SUB(Q,2,R,X,Y)
00256 #define FP_MUL_Q(R,X,Y)                   _FP_MUL(Q,2,R,X,Y)
00257 #define FP_DIV_Q(R,X,Y)                   _FP_DIV(Q,2,R,X,Y)
00258 #define FP_SQRT_Q(R,X)                    _FP_SQRT(Q,2,R,X)
00259 #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
00260 
00261 #define FP_CMP_Q(r,X,Y,un)  _FP_CMP(Q,2,r,X,Y,un)
00262 #define FP_CMP_EQ_Q(r,X,Y)  _FP_CMP_EQ(Q,2,r,X,Y)
00263 #define FP_CMP_UNORD_Q(r,X,Y)      _FP_CMP_UNORD(Q,2,r,X,Y)
00264 
00265 #define FP_TO_INT_Q(r,X,rsz,rsg)   _FP_TO_INT(Q,2,r,X,rsz,rsg)
00266 #define FP_FROM_INT_Q(X,r,rs,rt)   _FP_FROM_INT(Q,2,X,r,rs,rt)
00267 
00268 #define _FP_FRAC_HIGH_Q(X)  _FP_FRAC_HIGH_2(X)
00269 #define _FP_FRAC_HIGH_RAW_Q(X)     _FP_FRAC_HIGH_2(X)
00270 
00271 #endif /* not _FP_W_TYPE_SIZE < 64 */