Mercurial > hg > CbC > CbC_gcc
comparison libdecnumber/decNumberLocal.h @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
24 <http://www.gnu.org/licenses/>. */ | 24 <http://www.gnu.org/licenses/>. */ |
25 | 25 |
26 /* ------------------------------------------------------------------ */ | 26 /* ------------------------------------------------------------------ */ |
27 /* decNumber package local type, tuning, and macro definitions */ | 27 /* decNumber package local type, tuning, and macro definitions */ |
28 /* ------------------------------------------------------------------ */ | 28 /* ------------------------------------------------------------------ */ |
29 /* This header file is included by all modules in the decNumber */ | 29 /* This header file is included by all modules in the decNumber */ |
30 /* library, and contains local type definitions, tuning parameters, */ | 30 /* library, and contains local type definitions, tuning parameters, */ |
31 /* etc. It should not need to be used by application programs. */ | 31 /* etc. It should not need to be used by application programs. */ |
32 /* decNumber.h or one of decDouble (etc.) must be included first. */ | 32 /* decNumber.h or one of decDouble (etc.) must be included first. */ |
33 /* ------------------------------------------------------------------ */ | 33 /* ------------------------------------------------------------------ */ |
34 | 34 |
35 #if !defined(DECNUMBERLOC) | 35 #if !defined(DECNUMBERLOC) |
36 #define DECNUMBERLOC | 36 #define DECNUMBERLOC |
37 #define DECVERSION "decNumber 3.53" /* Package Version [16 max.] */ | 37 #define DECVERSION "decNumber 3.61" /* Package Version [16 max.] */ |
38 #define DECNLAUTHOR "Mike Cowlishaw" /* Who to blame */ | 38 #define DECNLAUTHOR "Mike Cowlishaw" /* Who to blame */ |
39 | 39 |
40 #include <stdlib.h> /* for abs */ | 40 #include <stdlib.h> /* for abs */ |
41 #include <string.h> /* for memset, strcpy */ | 41 #include <string.h> /* for memset, strcpy */ |
42 #include "dconfig.h" /* for WORDS_BIGENDIAN */ | 42 #include "dconfig.h" /* for WORDS_BIGENDIAN */ |
43 | 43 |
44 /* Conditional code flag -- set this to match hardware platform */ | 44 /* Conditional code flag -- set this to match hardware platform */ |
45 /* 1=little-endian, 0=big-endian */ | 45 /* 1=little-endian, 0=big-endian */ |
46 #if WORDS_BIGENDIAN | 46 #if WORDS_BIGENDIAN |
47 #define DECLITEND 0 | 47 #define DECLITEND 0 |
48 #else | 48 #else |
49 #define DECLITEND 1 | 49 #define DECLITEND 1 |
50 #endif | 50 #endif |
51 | 51 |
52 #if !defined(DECLITEND) | |
53 #define DECLITEND 1 /* 1=little-endian, 0=big-endian */ | |
54 #endif | |
55 | |
52 /* Conditional code flag -- set this to 1 for best performance */ | 56 /* Conditional code flag -- set this to 1 for best performance */ |
57 #if !defined(DECUSE64) | |
53 #define DECUSE64 1 /* 1=use int64s, 0=int32 & smaller only */ | 58 #define DECUSE64 1 /* 1=use int64s, 0=int32 & smaller only */ |
59 #endif | |
54 | 60 |
55 /* Conditional check flags -- set these to 0 for best performance */ | 61 /* Conditional check flags -- set these to 0 for best performance */ |
62 #if !defined(DECCHECK) | |
56 #define DECCHECK 0 /* 1 to enable robust checking */ | 63 #define DECCHECK 0 /* 1 to enable robust checking */ |
64 #endif | |
65 #if !defined(DECALLOC) | |
57 #define DECALLOC 0 /* 1 to enable memory accounting */ | 66 #define DECALLOC 0 /* 1 to enable memory accounting */ |
67 #endif | |
68 #if !defined(DECTRACE) | |
58 #define DECTRACE 0 /* 1 to trace certain internals, etc. */ | 69 #define DECTRACE 0 /* 1 to trace certain internals, etc. */ |
70 #endif | |
59 | 71 |
60 /* Tuning parameter for decNumber (arbitrary precision) module */ | 72 /* Tuning parameter for decNumber (arbitrary precision) module */ |
73 #if !defined(DECBUFFER) | |
61 #define DECBUFFER 36 /* Size basis for local buffers. This */ | 74 #define DECBUFFER 36 /* Size basis for local buffers. This */ |
62 /* should be a common maximum precision */ | 75 /* should be a common maximum precision */ |
63 /* rounded up to a multiple of 4; must */ | 76 /* rounded up to a multiple of 4; must */ |
64 /* be zero or positive. */ | 77 /* be zero or positive. */ |
78 #endif | |
65 | 79 |
66 /* ---------------------------------------------------------------- */ | 80 /* ---------------------------------------------------------------- */ |
67 /* Definitions for all modules (general-purpose) */ | 81 /* Definitions for all modules (general-purpose) */ |
68 /* ---------------------------------------------------------------- */ | 82 /* ---------------------------------------------------------------- */ |
69 | 83 |
70 /* Local names for common types -- for safety, decNumber modules do */ | 84 /* Local names for common types -- for safety, decNumber modules do */ |
71 /* not use int or long directly. */ | 85 /* not use int or long directly. */ |
72 #define Flag uint8_t | 86 #define Flag uint8_t |
73 #define Byte int8_t | 87 #define Byte int8_t |
74 #define uByte uint8_t | 88 #define uByte uint8_t |
75 #define Short int16_t | 89 #define Short int16_t |
76 #define uShort uint16_t | 90 #define uShort uint16_t |
77 #define Int int32_t | 91 #define Int int32_t |
78 #define uInt uint32_t | 92 #define uInt uint32_t |
79 #define Unit decNumberUnit | 93 #define Unit decNumberUnit |
80 #if DECUSE64 | 94 #if DECUSE64 |
81 #define Long int64_t | 95 #define Long int64_t |
82 #define uLong uint64_t | 96 #define uLong uint64_t |
83 #endif | 97 #endif |
84 | 98 |
85 /* Development-use definitions */ | 99 /* Development-use definitions */ |
86 typedef long int LI; /* for printf arguments only */ | 100 typedef long int LI; /* for printf arguments only */ |
87 #define DECNOINT 0 /* 1 to check no internal use of 'int' */ | 101 #define DECNOINT 0 /* 1 to check no internal use of 'int' */ |
102 /* or stdint types */ | |
88 #if DECNOINT | 103 #if DECNOINT |
89 /* if these interfere with your C includes, do not set DECNOINT */ | 104 /* if these interfere with your C includes, do not set DECNOINT */ |
90 #define int ? /* enable to ensure that plain C 'int' */ | 105 #define int ? /* enable to ensure that plain C 'int' */ |
91 #define long ?? /* .. or 'long' types are not used */ | 106 #define long ?? /* .. or 'long' types are not used */ |
92 #endif | 107 #endif |
93 | 108 |
94 /* Shared lookup tables */ | 109 /* Shared lookup tables */ |
95 extern const uByte DECSTICKYTAB[10]; /* re-round digits if sticky */ | 110 extern const uByte DECSTICKYTAB[10]; /* re-round digits if sticky */ |
96 extern const uInt DECPOWERS[10]; /* powers of ten table */ | 111 extern const uInt DECPOWERS[10]; /* powers of ten table */ |
97 /* The following are included from decDPD.h */ | 112 /* The following are included from decDPD.h */ |
98 #include "decDPDSymbols.h" | 113 #include "decDPDSymbols.h" |
99 extern const uShort DPD2BIN[1024]; /* DPD -> 0-999 */ | 114 extern const uShort DPD2BIN[1024]; /* DPD -> 0-999 */ |
100 extern const uShort BIN2DPD[1000]; /* 0-999 -> DPD */ | 115 extern const uShort BIN2DPD[1000]; /* 0-999 -> DPD */ |
101 extern const uInt DPD2BINK[1024]; /* DPD -> 0-999000 */ | 116 extern const uInt DPD2BINK[1024]; /* DPD -> 0-999000 */ |
102 extern const uInt DPD2BINM[1024]; /* DPD -> 0-999000000 */ | 117 extern const uInt DPD2BINM[1024]; /* DPD -> 0-999000000 */ |
103 extern const uByte DPD2BCD8[4096]; /* DPD -> ddd + len */ | 118 extern const uByte DPD2BCD8[4096]; /* DPD -> ddd + len */ |
104 extern const uByte BIN2BCD8[4000]; /* 0-999 -> ddd + len */ | 119 extern const uByte BIN2BCD8[4000]; /* 0-999 -> ddd + len */ |
105 extern const uShort BCD2DPD[2458]; /* 0-0x999 -> DPD (0x999=2457)*/ | 120 extern const uShort BCD2DPD[2458]; /* 0-0x999 -> DPD (0x999=2457)*/ |
106 | 121 |
107 /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts */ | 122 /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts */ |
108 /* (that is, sets w to be the high-order word of the 64-bit result; */ | 123 /* (that is, sets w to be the high-order word of the 64-bit result; */ |
109 /* the low-order word is simply u*v.) */ | 124 /* the low-order word is simply u*v.) */ |
110 /* This version is derived from Knuth via Hacker's Delight; */ | 125 /* This version is derived from Knuth via Hacker's Delight; */ |
111 /* it seems to optimize better than some others tried */ | 126 /* it seems to optimize better than some others tried */ |
112 #define LONGMUL32HI(w, u, v) { \ | 127 #define LONGMUL32HI(w, u, v) { \ |
113 uInt u0, u1, v0, v1, w0, w1, w2, t; \ | 128 uInt u0, u1, v0, v1, w0, w1, w2, t; \ |
114 u0=u & 0xffff; u1=u>>16; \ | 129 u0=u & 0xffff; u1=u>>16; \ |
115 v0=v & 0xffff; v1=v>>16; \ | 130 v0=v & 0xffff; v1=v>>16; \ |
116 w0=u0*v0; \ | 131 w0=u0*v0; \ |
117 t=u1*v0 + (w0>>16); \ | 132 t=u1*v0 + (w0>>16); \ |
118 w1=t & 0xffff; w2=t>>16; \ | 133 w1=t & 0xffff; w2=t>>16; \ |
119 w1=u0*v1 + w1; \ | 134 w1=u0*v1 + w1; \ |
120 (w)=u1*v1 + w2 + (w1>>16);} | 135 (w)=u1*v1 + w2 + (w1>>16);} |
121 | 136 |
122 /* ROUNDUP -- round an integer up to a multiple of n */ | 137 /* ROUNDUP -- round an integer up to a multiple of n */ |
123 #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n) | 138 #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n) |
139 #define ROUNDUP4(i) (((i)+3)&~3) /* special for n=4 */ | |
124 | 140 |
125 /* ROUNDDOWN -- round an integer down to a multiple of n */ | 141 /* ROUNDDOWN -- round an integer down to a multiple of n */ |
126 #define ROUNDDOWN(i, n) (((i)/n)*n) | 142 #define ROUNDDOWN(i, n) (((i)/n)*n) |
127 #define ROUNDDOWN4(i) ((i)&~3) /* special for n=4 */ | 143 #define ROUNDDOWN4(i) ((i)&~3) /* special for n=4 */ |
128 | 144 |
129 /* References to multi-byte sequences under different sizes */ | 145 /* References to multi-byte sequences under different sizes; these */ |
130 /* Refer to a uInt from four bytes starting at a char* or uByte*, */ | 146 /* require locally declared variables, but do not violate strict */ |
131 /* etc. */ | 147 /* aliasing or alignment (as did the UINTAT simple cast to uInt). */ |
132 #define UINTAT(b) (*((uInt *)(b))) | 148 /* Variables needed are uswork, uiwork, etc. [so do not use at same */ |
133 #define USHORTAT(b) (*((uShort *)(b))) | 149 /* level in an expression, e.g., UBTOUI(x)==UBTOUI(y) may fail]. */ |
134 #define UBYTEAT(b) (*((uByte *)(b))) | 150 |
151 /* Return a uInt, etc., from bytes starting at a char* or uByte* */ | |
152 #define UBTOUS(b) (memcpy((void *)&uswork, b, 2), uswork) | |
153 #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork) | |
154 | |
155 /* Store a uInt, etc., into bytes starting at a char* or uByte*. */ | |
156 /* Returns i, evaluated, for convenience; has to use uiwork because */ | |
157 /* i may be an expression. */ | |
158 #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) | |
159 #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) | |
135 | 160 |
136 /* X10 and X100 -- multiply integer i by 10 or 100 */ | 161 /* X10 and X100 -- multiply integer i by 10 or 100 */ |
137 /* [shifts are usually faster than multiply; could be conditional] */ | 162 /* [shifts are usually faster than multiply; could be conditional] */ |
138 #define X10(i) (((i)<<1)+((i)<<3)) | 163 #define X10(i) (((i)<<1)+((i)<<3)) |
139 #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6)) | 164 #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6)) |
142 #define MAXI(x,y) ((x)<(y)?(y):(x)) | 167 #define MAXI(x,y) ((x)<(y)?(y):(x)) |
143 #define MINI(x,y) ((x)>(y)?(y):(x)) | 168 #define MINI(x,y) ((x)>(y)?(y):(x)) |
144 | 169 |
145 /* Useful constants */ | 170 /* Useful constants */ |
146 #define BILLION 1000000000 /* 10**9 */ | 171 #define BILLION 1000000000 /* 10**9 */ |
147 /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC */ | 172 /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC */ |
148 #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0') | 173 #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0') |
149 | 174 |
150 | 175 |
151 /* ---------------------------------------------------------------- */ | 176 /* ---------------------------------------------------------------- */ |
152 /* Definitions for arbitary-precision modules (only valid after */ | 177 /* Definitions for arbitary-precision modules (only valid after */ |
165 #endif | 190 #endif |
166 #if (DECNUMMINE != DEC_MIN_EMIN) | 191 #if (DECNUMMINE != DEC_MIN_EMIN) |
167 #error Minimum exponent mismatch | 192 #error Minimum exponent mismatch |
168 #endif | 193 #endif |
169 | 194 |
170 /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN */ | 195 /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN */ |
171 /* digits, and D2UTABLE -- the initializer for the D2U table */ | 196 /* digits, and D2UTABLE -- the initializer for the D2U table */ |
172 #if DECDPUN==1 | 197 #if DECDPUN==1 |
173 #define DECDPUNMAX 9 | 198 #define DECDPUNMAX 9 |
174 #define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, \ | 199 #define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, \ |
175 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \ | 200 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \ |
246 #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN) | 271 #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN) |
247 | 272 |
248 /* D2N -- return the number of decNumber structs that would be */ | 273 /* D2N -- return the number of decNumber structs that would be */ |
249 /* needed to contain that number of digits (and the initial */ | 274 /* needed to contain that number of digits (and the initial */ |
250 /* decNumber struct) safely. Note that one Unit is included in the */ | 275 /* decNumber struct) safely. Note that one Unit is included in the */ |
251 /* initial structure. Used for allocating space that is aligned on */ | 276 /* initial structure. Used for allocating space that is aligned on */ |
252 /* a decNumber struct boundary. */ | 277 /* a decNumber struct boundary. */ |
253 #define D2N(d) \ | 278 #define D2N(d) \ |
254 ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber)) | 279 ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber)) |
255 | 280 |
256 /* TODIGIT -- macro to remove the leading digit from the unsigned */ | 281 /* TODIGIT -- macro to remove the leading digit from the unsigned */ |
257 /* integer u at column cut (counting from the right, LSD=0) and */ | 282 /* integer u at column cut (counting from the right, LSD=0) and */ |
258 /* place it as an ASCII character into the character pointed to by */ | 283 /* place it as an ASCII character into the character pointed to by */ |
259 /* c. Note that cut must be <= 9, and the maximum value for u is */ | 284 /* c. Note that cut must be <= 9, and the maximum value for u is */ |
260 /* 2,000,000,000 (as is needed for negative exponents of */ | 285 /* 2,000,000,000 (as is needed for negative exponents of */ |
261 /* subnormals). The unsigned integer pow is used as a temporary */ | 286 /* subnormals). The unsigned integer pow is used as a temporary */ |
262 /* variable. */ | 287 /* variable. */ |
263 #define TODIGIT(u, cut, c, pow) { \ | 288 #define TODIGIT(u, cut, c, pow) { \ |
264 *(c)='0'; \ | 289 *(c)='0'; \ |
267 pow*=4; \ | 292 pow*=4; \ |
268 if ((u)>=pow) {(u)-=pow; *(c)+=8;} \ | 293 if ((u)>=pow) {(u)-=pow; *(c)+=8;} \ |
269 pow/=2; \ | 294 pow/=2; \ |
270 if ((u)>=pow) {(u)-=pow; *(c)+=4;} \ | 295 if ((u)>=pow) {(u)-=pow; *(c)+=4;} \ |
271 pow/=2; \ | 296 pow/=2; \ |
272 } \ | 297 } \ |
273 if ((u)>=pow) {(u)-=pow; *(c)+=2;} \ | 298 if ((u)>=pow) {(u)-=pow; *(c)+=2;} \ |
274 pow/=2; \ | 299 pow/=2; \ |
275 if ((u)>=pow) {(u)-=pow; *(c)+=1;} \ | 300 if ((u)>=pow) {(u)-=pow; *(c)+=1;} \ |
276 } | 301 } |
277 | 302 |
282 | 307 |
283 /* bcdnum -- a structure describing a format-independent finite */ | 308 /* bcdnum -- a structure describing a format-independent finite */ |
284 /* number, whose coefficient is a string of bcd8 uBytes */ | 309 /* number, whose coefficient is a string of bcd8 uBytes */ |
285 typedef struct { | 310 typedef struct { |
286 uByte *msd; /* -> most significant digit */ | 311 uByte *msd; /* -> most significant digit */ |
287 uByte *lsd; /* -> least ditto */ | 312 uByte *lsd; /* -> least ditto */ |
288 uInt sign; /* 0=positive, DECFLOAT_Sign=negative */ | 313 uInt sign; /* 0=positive, DECFLOAT_Sign=negative */ |
289 Int exponent; /* Unadjusted signed exponent (q), or */ | 314 Int exponent; /* Unadjusted signed exponent (q), or */ |
290 /* DECFLOAT_NaN etc. for a special */ | 315 /* DECFLOAT_NaN etc. for a special */ |
291 } bcdnum; | 316 } bcdnum; |
292 | 317 |
293 /* Test if exponent or bcdnum exponent must be a special, etc. */ | 318 /* Test if exponent or bcdnum exponent must be a special, etc. */ |
294 #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp) | 319 #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp) |
301 /* automatically adjusting for endianness; similarly address a word */ | 326 /* automatically adjusting for endianness; similarly address a word */ |
302 /* in the next-wider format (decFloatWider, or dfw) */ | 327 /* in the next-wider format (decFloatWider, or dfw) */ |
303 #define DECWORDS (DECBYTES/4) | 328 #define DECWORDS (DECBYTES/4) |
304 #define DECWWORDS (DECWBYTES/4) | 329 #define DECWWORDS (DECWBYTES/4) |
305 #if DECLITEND | 330 #if DECLITEND |
306 #define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)]) | 331 #define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)]) |
307 #define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)]) | 332 #define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)]) |
308 #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)]) | 333 #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)]) |
309 #else | 334 #else |
310 #define DFWORD(df, off) ((df)->words[off]) | 335 #define DFBYTE(df, off) ((df)->bytes[off]) |
311 #define DFBYTE(df, off) ((df)->bytes[off]) | 336 #define DFWORD(df, off) ((df)->words[off]) |
312 #define DFWWORD(dfw, off) ((dfw)->words[off]) | 337 #define DFWWORD(dfw, off) ((dfw)->words[off]) |
313 #endif | 338 #endif |
314 | 339 |
315 /* Tests for sign or specials, directly on DECFLOATs */ | 340 /* Tests for sign or specials, directly on DECFLOATs */ |
316 #define DFISSIGNED(df) (DFWORD(df, 0)&0x80000000) | 341 #define DFISSIGNED(df) (DFWORD(df, 0)&0x80000000) |
331 #endif | 356 #endif |
332 | 357 |
333 /* Format-dependent macros and constants */ | 358 /* Format-dependent macros and constants */ |
334 #if defined(DECPMAX) | 359 #if defined(DECPMAX) |
335 | 360 |
336 /* Useful constants */ | 361 /* Useful constants */ |
337 #define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9) /* 'Pmax' in 10**9s */ | 362 #define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9) /* 'Pmax' in 10**9s */ |
338 /* Top words for a zero */ | 363 /* Top words for a zero */ |
339 #define SINGLEZERO 0x22500000 | 364 #define SINGLEZERO 0x22500000 |
340 #define DOUBLEZERO 0x22380000 | 365 #define DOUBLEZERO 0x22380000 |
341 #define QUADZERO 0x22080000 | 366 #define QUADZERO 0x22080000 |
343 | 368 |
344 /* Format-dependent common tests: */ | 369 /* Format-dependent common tests: */ |
345 /* DFISZERO -- test for (any) zero */ | 370 /* DFISZERO -- test for (any) zero */ |
346 /* DFISCCZERO -- test for coefficient continuation being zero */ | 371 /* DFISCCZERO -- test for coefficient continuation being zero */ |
347 /* DFISCC01 -- test for coefficient contains only 0s and 1s */ | 372 /* DFISCC01 -- test for coefficient contains only 0s and 1s */ |
348 /* DFISINT -- test for finite and exponent q=0 */ | 373 /* DFISINT -- test for finite and exponent q=0 */ |
349 /* DFISUINT01 -- test for sign=0, finite, exponent q=0, and */ | 374 /* DFISUINT01 -- test for sign=0, finite, exponent q=0, and */ |
350 /* MSD=0 or 1 */ | 375 /* MSD=0 or 1 */ |
351 /* ZEROWORD is also defined here. */ | 376 /* ZEROWORD is also defined here. */ |
352 /* In DFISZERO the first test checks the least-significant word */ | 377 /* In DFISZERO the first test checks the least-significant word */ |
353 /* (most likely to be non-zero); the penultimate tests MSD and */ | 378 /* (most likely to be non-zero); the penultimate tests MSD and */ |
354 /* DPDs in the signword, and the final test excludes specials and */ | 379 /* DPDs in the signword, and the final test excludes specials and */ |
355 /* MSD>7. DFISINT similarly has to allow for the two forms of */ | 380 /* MSD>7. DFISINT similarly has to allow for the two forms of */ |
356 /* MSD codes. DFISUINT01 only has to allow for one form of MSD */ | 381 /* MSD codes. DFISUINT01 only has to allow for one form of MSD */ |
400 /* declet is at offset k (a multiple of 2) in a uInt: */ | 425 /* declet is at offset k (a multiple of 2) in a uInt: */ |
401 #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \ | 426 #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \ |
402 || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k))) | 427 || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k))) |
403 /* declet is at offset k (a multiple of 2) in a pair of uInts: */ | 428 /* declet is at offset k (a multiple of 2) in a pair of uInts: */ |
404 /* [the top 2 bits will always be in the more-significant uInt] */ | 429 /* [the top 2 bits will always be in the more-significant uInt] */ |
405 #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \ | 430 #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \ |
406 || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \ | 431 || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \ |
407 || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k))) | 432 || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k))) |
408 | 433 |
409 /* Macro to test whether a full-length (length DECPMAX) BCD8 */ | 434 /* Macro to test whether a full-length (length DECPMAX) BCD8 */ |
410 /* coefficient is zero */ | 435 /* coefficient, starting at uByte u, is all zeros */ |
411 /* test just the LSWord first, then the remainder */ | 436 /* Test just the LSWord first, then the remainder as a sequence */ |
437 /* of tests in order to avoid same-level use of UBTOUI */ | |
412 #if DECPMAX==7 | 438 #if DECPMAX==7 |
413 #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \ | 439 #define ISCOEFFZERO(u) ( \ |
414 && UINTAT((u)+DECPMAX-7)==0) | 440 UBTOUI((u)+DECPMAX-4)==0 \ |
441 && UBTOUS((u)+DECPMAX-6)==0 \ | |
442 && *(u)==0) | |
415 #elif DECPMAX==16 | 443 #elif DECPMAX==16 |
416 #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \ | 444 #define ISCOEFFZERO(u) ( \ |
417 && (UINTAT((u)+DECPMAX-8)+UINTAT((u)+DECPMAX-12) \ | 445 UBTOUI((u)+DECPMAX-4)==0 \ |
418 +UINTAT((u)+DECPMAX-16))==0) | 446 && UBTOUI((u)+DECPMAX-8)==0 \ |
447 && UBTOUI((u)+DECPMAX-12)==0 \ | |
448 && UBTOUI(u)==0) | |
419 #elif DECPMAX==34 | 449 #elif DECPMAX==34 |
420 #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \ | 450 #define ISCOEFFZERO(u) ( \ |
421 && (UINTAT((u)+DECPMAX-8) +UINTAT((u)+DECPMAX-12) \ | 451 UBTOUI((u)+DECPMAX-4)==0 \ |
422 +UINTAT((u)+DECPMAX-16)+UINTAT((u)+DECPMAX-20) \ | 452 && UBTOUI((u)+DECPMAX-8)==0 \ |
423 +UINTAT((u)+DECPMAX-24)+UINTAT((u)+DECPMAX-28) \ | 453 && UBTOUI((u)+DECPMAX-12)==0 \ |
424 +UINTAT((u)+DECPMAX-32)+USHORTAT((u)+DECPMAX-34))==0) | 454 && UBTOUI((u)+DECPMAX-16)==0 \ |
455 && UBTOUI((u)+DECPMAX-20)==0 \ | |
456 && UBTOUI((u)+DECPMAX-24)==0 \ | |
457 && UBTOUI((u)+DECPMAX-28)==0 \ | |
458 && UBTOUI((u)+DECPMAX-32)==0 \ | |
459 && UBTOUS(u)==0) | |
425 #endif | 460 #endif |
426 | 461 |
427 /* Macros and masks for the exponent continuation field and MSD */ | 462 /* Macros and masks for the exponent continuation field and MSD */ |
428 /* Get the exponent continuation from a decFloat *df as an Int */ | 463 /* Get the exponent continuation from a decFloat *df as an Int */ |
429 #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL))) | 464 #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL))) |
441 #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL)) | 476 #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL)) |
442 /* same, not including its first digit (the qNaN/sNaN selector): */ | 477 /* same, not including its first digit (the qNaN/sNaN selector): */ |
443 #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL)) | 478 #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL)) |
444 | 479 |
445 /* Macros to decode the coefficient in a finite decFloat *df into */ | 480 /* Macros to decode the coefficient in a finite decFloat *df into */ |
446 /* a BCD string (uByte *bcdin) of length DECPMAX uBytes */ | 481 /* a BCD string (uByte *bcdin) of length DECPMAX uBytes. */ |
447 | 482 |
448 /* In-line sequence to convert 10 bits at right end of uInt dpd */ | 483 /* In-line sequence to convert least significant 10 bits of uInt */ |
449 /* to three BCD8 digits starting at uByte u. Note that an extra */ | 484 /* dpd to three BCD8 digits starting at uByte u. Note that an */ |
450 /* byte is written to the right of the three digits because this */ | 485 /* extra byte is written to the right of the three digits because */ |
451 /* moves four at a time for speed; the alternative macro moves */ | 486 /* four bytes are moved at a time for speed; the alternative */ |
452 /* exactly three bytes */ | 487 /* macro moves exactly three bytes (usually slower). */ |
453 #define dpd2bcd8(u, dpd) { \ | 488 #define dpd2bcd8(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 4) |
454 UINTAT(u)=UINTAT(&DPD2BCD8[((dpd)&0x3ff)*4]);} | 489 #define dpd2bcd83(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 3) |
455 | |
456 #define dpd2bcd83(u, dpd) { \ | |
457 *(u)=DPD2BCD8[((dpd)&0x3ff)*4]; \ | |
458 *(u+1)=DPD2BCD8[((dpd)&0x3ff)*4+1]; \ | |
459 *(u+2)=DPD2BCD8[((dpd)&0x3ff)*4+2];} | |
460 | 490 |
461 /* Decode the declets. After extracting each one, it is decoded */ | 491 /* Decode the declets. After extracting each one, it is decoded */ |
462 /* to BCD8 using a table lookup (also used for variable-length */ | 492 /* to BCD8 using a table lookup (also used for variable-length */ |
463 /* decode). Each DPD decode is 3 bytes BCD8 plus a one-byte */ | 493 /* decode). Each DPD decode is 3 bytes BCD8 plus a one-byte */ |
464 /* length which is not used, here). Fixed-length 4-byte moves */ | 494 /* length which is not used, here). Fixed-length 4-byte moves */ |
465 /* are fast, however, almost everywhere, and so are used except */ | 495 /* are fast, however, almost everywhere, and so are used except */ |
466 /* for the final three bytes (to avoid overrun). The code below */ | 496 /* for the final three bytes (to avoid overrun). The code below */ |
467 /* is 36 instructions for Doubles and about 70 for Quads, even */ | 497 /* is 36 instructions for Doubles and about 70 for Quads, even */ |
468 /* on IA32. */ | 498 /* on IA32. */ |
469 | 499 |
470 /* Two macros are defined for each format: */ | 500 /* Two macros are defined for each format: */ |
471 /* GETCOEFF extracts the coefficient of the current format */ | 501 /* GETCOEFF extracts the coefficient of the current format */ |
472 /* GETWCOEFF extracts the coefficient of the next-wider format. */ | 502 /* GETWCOEFF extracts the coefficient of the next-wider format. */ |
473 /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */ | 503 /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */ |
474 | 504 |
475 #if DECPMAX==7 | 505 #if DECPMAX==7 |
476 #define GETCOEFF(df, bcd) { \ | 506 #define GETCOEFF(df, bcd) { \ |
477 uInt sourhi=DFWORD(df, 0); \ | 507 uInt sourhi=DFWORD(df, 0); \ |
478 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ | 508 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ |
479 dpd2bcd8(bcd+1, sourhi>>10); \ | 509 dpd2bcd8(bcd+1, sourhi>>10); \ |
480 dpd2bcd83(bcd+4, sourhi);} | 510 dpd2bcd83(bcd+4, sourhi);} |
481 #define GETWCOEFF(df, bcd) { \ | 511 #define GETWCOEFF(df, bcd) { \ |
487 dpd2bcd8(bcd+7, sourlo>>20); \ | 517 dpd2bcd8(bcd+7, sourlo>>20); \ |
488 dpd2bcd8(bcd+10, sourlo>>10); \ | 518 dpd2bcd8(bcd+10, sourlo>>10); \ |
489 dpd2bcd83(bcd+13, sourlo);} | 519 dpd2bcd83(bcd+13, sourlo);} |
490 | 520 |
491 #elif DECPMAX==16 | 521 #elif DECPMAX==16 |
492 #define GETCOEFF(df, bcd) { \ | 522 #define GETCOEFF(df, bcd) { \ |
493 uInt sourhi=DFWORD(df, 0); \ | 523 uInt sourhi=DFWORD(df, 0); \ |
494 uInt sourlo=DFWORD(df, 1); \ | 524 uInt sourlo=DFWORD(df, 1); \ |
495 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ | 525 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ |
496 dpd2bcd8(bcd+1, sourhi>>8); \ | 526 dpd2bcd8(bcd+1, sourhi>>8); \ |
497 dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \ | 527 dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \ |
515 dpd2bcd8(bcd+25, sourlo>>20); \ | 545 dpd2bcd8(bcd+25, sourlo>>20); \ |
516 dpd2bcd8(bcd+28, sourlo>>10); \ | 546 dpd2bcd8(bcd+28, sourlo>>10); \ |
517 dpd2bcd83(bcd+31, sourlo);} | 547 dpd2bcd83(bcd+31, sourlo);} |
518 | 548 |
519 #elif DECPMAX==34 | 549 #elif DECPMAX==34 |
520 #define GETCOEFF(df, bcd) { \ | 550 #define GETCOEFF(df, bcd) { \ |
521 uInt sourhi=DFWORD(df, 0); \ | 551 uInt sourhi=DFWORD(df, 0); \ |
522 uInt sourmh=DFWORD(df, 1); \ | 552 uInt sourmh=DFWORD(df, 1); \ |
523 uInt sourml=DFWORD(df, 2); \ | 553 uInt sourml=DFWORD(df, 2); \ |
524 uInt sourlo=DFWORD(df, 3); \ | 554 uInt sourlo=DFWORD(df, 3); \ |
525 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ | 555 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \ |
533 dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \ | 563 dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \ |
534 dpd2bcd8(bcd+25, sourlo>>20); \ | 564 dpd2bcd8(bcd+25, sourlo>>20); \ |
535 dpd2bcd8(bcd+28, sourlo>>10); \ | 565 dpd2bcd8(bcd+28, sourlo>>10); \ |
536 dpd2bcd83(bcd+31, sourlo);} | 566 dpd2bcd83(bcd+31, sourlo);} |
537 | 567 |
538 #define GETWCOEFF(df, bcd) {??} /* [should never be used] */ | 568 #define GETWCOEFF(df, bcd) {??} /* [should never be used] */ |
539 #endif | 569 #endif |
540 | 570 |
541 /* Macros to decode the coefficient in a finite decFloat *df into */ | 571 /* Macros to decode the coefficient in a finite decFloat *df into */ |
542 /* a base-billion uInt array, with the least-significant */ | 572 /* a base-billion uInt array, with the least-significant */ |
543 /* 0-999999999 'digit' at offset 0. */ | 573 /* 0-999999999 'digit' at offset 0. */ |
544 | 574 |
545 /* Decode the declets. After extracting each one, it is decoded */ | 575 /* Decode the declets. After extracting each one, it is decoded */ |
546 /* to binary using a table lookup. Three tables are used; one */ | 576 /* to binary using a table lookup. Three tables are used; one */ |
547 /* the usual DPD to binary, the other two pre-multiplied by 1000 */ | 577 /* the usual DPD to binary, the other two pre-multiplied by 1000 */ |
548 /* and 1000000 to avoid multiplication during decode. These */ | 578 /* and 1000000 to avoid multiplication during decode. These */ |
590 +DPD2BINM[DECCOMBMSD[sourhi>>26]];} | 620 +DPD2BINM[DECCOMBMSD[sourhi>>26]];} |
591 | 621 |
592 #endif | 622 #endif |
593 | 623 |
594 /* Macros to decode the coefficient in a finite decFloat *df into */ | 624 /* Macros to decode the coefficient in a finite decFloat *df into */ |
595 /* a base-thousand uInt array, with the least-significant 0-999 */ | 625 /* a base-thousand uInt array (of size DECLETS+1, to allow for */ |
596 /* 'digit' at offset 0. */ | 626 /* the MSD), with the least-significant 0-999 'digit' at offset 0.*/ |
597 | 627 |
598 /* Decode the declets. After extracting each one, it is decoded */ | 628 /* Decode the declets. After extracting each one, it is decoded */ |
599 /* to binary using a table lookup. */ | 629 /* to binary using a table lookup. */ |
600 #if DECPMAX==7 | 630 #if DECPMAX==7 |
601 #define GETCOEFFTHOU(df, buf) { \ | 631 #define GETCOEFFTHOU(df, buf) { \ |
633 (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \ | 663 (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \ |
634 sourhi=DFWORD(df, 0); \ | 664 sourhi=DFWORD(df, 0); \ |
635 (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \ | 665 (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \ |
636 (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \ | 666 (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \ |
637 (buf)[11]=DECCOMBMSD[sourhi>>26];} | 667 (buf)[11]=DECCOMBMSD[sourhi>>26];} |
638 | |
639 #endif | 668 #endif |
669 | |
670 | |
671 /* Macros to decode the coefficient in a finite decFloat *df and */ | |
672 /* add to a base-thousand uInt array (as for GETCOEFFTHOU). */ | |
673 /* After the addition then most significant 'digit' in the array */ | |
674 /* might have a value larger then 10 (with a maximum of 19). */ | |
675 #if DECPMAX==7 | |
676 #define ADDCOEFFTHOU(df, buf) { \ | |
677 uInt sourhi=DFWORD(df, 0); \ | |
678 (buf)[0]+=DPD2BIN[sourhi&0x3ff]; \ | |
679 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \ | |
680 (buf)[1]+=DPD2BIN[(sourhi>>10)&0x3ff]; \ | |
681 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \ | |
682 (buf)[2]+=DECCOMBMSD[sourhi>>26];} | |
683 | |
684 #elif DECPMAX==16 | |
685 #define ADDCOEFFTHOU(df, buf) { \ | |
686 uInt sourhi, sourlo; \ | |
687 sourlo=DFWORD(df, 1); \ | |
688 (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \ | |
689 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \ | |
690 (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \ | |
691 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \ | |
692 (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \ | |
693 if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \ | |
694 sourhi=DFWORD(df, 0); \ | |
695 (buf)[3]+=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \ | |
696 if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \ | |
697 (buf)[4]+=DPD2BIN[(sourhi>>8)&0x3ff]; \ | |
698 if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \ | |
699 (buf)[5]+=DECCOMBMSD[sourhi>>26];} | |
700 | |
701 #elif DECPMAX==34 | |
702 #define ADDCOEFFTHOU(df, buf) { \ | |
703 uInt sourhi, sourmh, sourml, sourlo; \ | |
704 sourlo=DFWORD(df, 3); \ | |
705 (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \ | |
706 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \ | |
707 (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \ | |
708 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \ | |
709 (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \ | |
710 if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \ | |
711 sourml=DFWORD(df, 2); \ | |
712 (buf)[3]+=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \ | |
713 if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \ | |
714 (buf)[4]+=DPD2BIN[(sourml>>8)&0x3ff]; \ | |
715 if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \ | |
716 (buf)[5]+=DPD2BIN[(sourml>>18)&0x3ff]; \ | |
717 if (buf[5]>999) {buf[5]-=1000; buf[6]++;} \ | |
718 sourmh=DFWORD(df, 1); \ | |
719 (buf)[6]+=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \ | |
720 if (buf[6]>999) {buf[6]-=1000; buf[7]++;} \ | |
721 (buf)[7]+=DPD2BIN[(sourmh>>6)&0x3ff]; \ | |
722 if (buf[7]>999) {buf[7]-=1000; buf[8]++;} \ | |
723 (buf)[8]+=DPD2BIN[(sourmh>>16)&0x3ff]; \ | |
724 if (buf[8]>999) {buf[8]-=1000; buf[9]++;} \ | |
725 sourhi=DFWORD(df, 0); \ | |
726 (buf)[9]+=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \ | |
727 if (buf[9]>999) {buf[9]-=1000; buf[10]++;} \ | |
728 (buf)[10]+=DPD2BIN[(sourhi>>4)&0x3ff]; \ | |
729 if (buf[10]>999) {buf[10]-=1000; buf[11]++;} \ | |
730 (buf)[11]+=DECCOMBMSD[sourhi>>26];} | |
731 #endif | |
732 | |
640 | 733 |
641 /* Set a decFloat to the maximum positive finite number (Nmax) */ | 734 /* Set a decFloat to the maximum positive finite number (Nmax) */ |
642 #if DECPMAX==7 | 735 #if DECPMAX==7 |
643 #define DFSETNMAX(df) \ | 736 #define DFSETNMAX(df) \ |
644 {DFWORD(df, 0)=0x77f3fcff;} | 737 {DFWORD(df, 0)=0x77f3fcff;} |