1 /*
2  * Various declarations and macros shared by
3  * several .c files, but useless to users of the library
4  *
5  * Copyright (C) 2002 David Defour and Florent de Dinechin
6  *
7  * This file is part of scslib, the Software Carry-Save multiple-precision
8  * library, which has been developed by the Arénaire project at École normale
9  * supérieure de Lyon.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
26 
27 #ifndef SCS_PRIVATE_H
28 #define SCS_PRIVATE_H 1
29 
30 
31 #define SCS_RADIX   ((unsigned int)(1<<SCS_NB_BITS))
32 
33 #define SCS_MASK_RADIX ((unsigned int)(SCS_RADIX-1))
34 
35 #include "scs.h"
36 
37 #ifdef WORDS_BIGENDIAN
38  #define HI 0
39  #define LO 1
40 #else
41  #define HI 1
42  #define LO 0
43 #endif
44 
45 /* An int such that SCS_MAX_RANGE * SCS_NB_BITS < 1024,
46    where 1024 is the max of the exponent of a double number.
47    Used in scs2double.c along with radix_rng_double et al.
48    The value of 32 is OK for all practical values of SCS_NB_BITS */
49 #define SCS_MAX_RANGE  32
50 
51 /*
52  * DEFINITION OF DOUBLE PRECISION FLOATING POINT NUMBER CONSTANTS
53  */
54 /* In all the following "radix" means 2^(SCS_NB_BITS),
55    and radix_blah means radix^blah.
56    (1023 + e)<<20 is the way to cast e into the exponent field of an IEEE-754 double
57  */
58 
59 
60  extern const db_number radix_one_double ;
61  extern const db_number radix_two_double ;
62  extern const db_number radix_mone_double;
63  extern const db_number radix_mtwo_double;
64  extern const db_number radix_rng_double ;
65  extern const db_number radix_mrng_double;
66  extern const db_number max_double       ;
67  extern const db_number min_double       ;
68 
69 
70 #define SCS_RADIX_ONE_DOUBLE     radix_one_double.d   /* 2^(SCS_NB_BITS)           */
71 #define SCS_RADIX_TWO_DOUBLE     radix_two_double.d   /* 2^(2.SCS_NB_BITS)         */
72 #define SCS_RADIX_MONE_DOUBLE    radix_mone_double.d  /* 2^-(SCS_NB_BITS)          */
73 #define SCS_RADIX_MTWO_DOUBLE    radix_mtwo_double.d  /* 2^-(2.SCS_NB_BITS)        */
74 #define SCS_RADIX_RNG_DOUBLE     radix_rng_double.d   /* 2^(SCS_NB_BITS.SCS_MAX_RANGE) */
75 #define SCS_RADIX_MRNG_DOUBLE    radix_mrng_double.d  /* 2^-(SCS_NB_BITS.SCS_MAX_RANGE)*/
76 #define SCS_MAX_DOUBLE           max_double.d         /* 2^1024-1              */
77 #define SCS_MIN_DOUBLE           min_double.d         /* 2^-1074             */
78 
79 
80 
81 
82 
83 
84 #define R_HW  result->h_word
85 #define R_SGN result->sign
86 #define R_IND result->index
87 #define R_EXP result->exception.d
88 
89 #define X_HW  x->h_word
90 #define X_SGN x->sign
91 #define X_IND x->index
92 #define X_EXP x->exception.d
93 
94 #define Y_HW  y->h_word
95 #define Y_SGN y->sign
96 #define Y_IND y->index
97 #define Y_EXP y->exception.d
98 
99 #define Z_HW  z->h_word
100 #define Z_SGN z->sign
101 #define Z_IND z->index
102 #define Z_EXP z->exception.d
103 
104 #define W_HW  w->h_word
105 #define W_SGN w->sign
106 #define W_IND w->index
107 #define W_EXP w->exception.d
108 
109 
110 
111 /* A few additional defines for the case when we use floating-point
112    multiplier  (OBSOLETE, NEVER USED ANYMORE but who knows, some day) */
113 
114 #ifdef SCS_USE_FLT_MULT
115 /* There is a "53" below, which means that these constants won't do
116    what we expect from them on x86 because of the double extended
117    precision. We could put more ifdefs, but why care, nobody wants to use the
118    FP muls on the x86. */
119 #ifdef WORDS_BIGENDIAN
120  static const db_number scs_flt_trunc_cst = {{ ((1023+SCS_NB_BITS-1)<<20) ,           0x00000000 }};
121  static const db_number scs_flt_shift_cst = {{ ((1023+SCS_NB_BITS+53)<<20),0x00000000}};
122 #else
123  static const db_number scs_flt_trunc_cst = {{ 0x00000000, ((1023+SCS_NB_BITS-1)<<20) }};
124  static const db_number scs_flt_shift_cst = {{ 0x00000000 ,((1023+SCS_NB_BITS+53)<<20)}};
125 #endif /*WORDS_BIGENDIAN*/
126 
127 #define SCS_FLT_TRUNC_CST  scs_flt_trunc_cst.d    /* 2^(SCS_NB_BITS+53-1) */
128 #define SCS_FLT_SHIFT_CST  scs_flt_shift_cst.d    /* 2^(SCS_NB_BITS)(1+1/2) */
129 #endif /* SCS_USE_FLTMULT */
130 
131 #endif /* SCS_PRIVATE_H */
132