xref: /openbmc/qemu/include/libdecnumber/decNumberLocal.h (revision f10e7b9f6fc18be390b3bc189e04b5147eb8dbf8)
172ac97cdSTom Musta /* Local definitions for the decNumber C Library.
272ac97cdSTom Musta    Copyright (C) 2007 Free Software Foundation, Inc.
372ac97cdSTom Musta    Contributed by IBM Corporation.  Author Mike Cowlishaw.
472ac97cdSTom Musta 
572ac97cdSTom Musta    This file is part of GCC.
672ac97cdSTom Musta 
772ac97cdSTom Musta    GCC is free software; you can redistribute it and/or modify it under
872ac97cdSTom Musta    the terms of the GNU General Public License as published by the Free
972ac97cdSTom Musta    Software Foundation; either version 2, or (at your option) any later
1072ac97cdSTom Musta    version.
1172ac97cdSTom Musta 
1272ac97cdSTom Musta    In addition to the permissions in the GNU General Public License,
1372ac97cdSTom Musta    the Free Software Foundation gives you unlimited permission to link
1472ac97cdSTom Musta    the compiled version of this file into combinations with other
1572ac97cdSTom Musta    programs, and to distribute those combinations without any
1672ac97cdSTom Musta    restriction coming from the use of this file.  (The General Public
1772ac97cdSTom Musta    License restrictions do apply in other respects; for example, they
1872ac97cdSTom Musta    cover modification of the file, and distribution when not linked
1972ac97cdSTom Musta    into a combine executable.)
2072ac97cdSTom Musta 
2172ac97cdSTom Musta    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
2272ac97cdSTom Musta    WARRANTY; without even the implied warranty of MERCHANTABILITY or
2372ac97cdSTom Musta    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2472ac97cdSTom Musta    for more details.
2572ac97cdSTom Musta 
2672ac97cdSTom Musta    You should have received a copy of the GNU General Public License
2772ac97cdSTom Musta    along with GCC; see the file COPYING.  If not, write to the Free
2872ac97cdSTom Musta    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2972ac97cdSTom Musta    02110-1301, USA.  */
3072ac97cdSTom Musta 
3172ac97cdSTom Musta /* ------------------------------------------------------------------ */
3272ac97cdSTom Musta /* decNumber package local type, tuning, and macro definitions	      */
3372ac97cdSTom Musta /* ------------------------------------------------------------------ */
3472ac97cdSTom Musta /* This header file is included by all modules in the decNumber	      */
3572ac97cdSTom Musta /* library, and contains local type definitions, tuning parameters,   */
3672ac97cdSTom Musta /* etc.	 It should not need to be used by application programs.	      */
3772ac97cdSTom Musta /* decNumber.h or one of decDouble (etc.) must be included first.     */
3872ac97cdSTom Musta /* ------------------------------------------------------------------ */
3972ac97cdSTom Musta 
40121d0712SMarkus Armbruster #ifndef DECNUMBERLOCAL_H
41121d0712SMarkus Armbruster #define DECNUMBERLOCAL_H
42121d0712SMarkus Armbruster 
4372ac97cdSTom Musta   #define DECVERSION	"decNumber 3.53" /* Package Version [16 max.] */
4472ac97cdSTom Musta   #define DECNLAUTHOR	"Mike Cowlishaw"	      /* Who to blame */
4572ac97cdSTom Musta 
460f2d3732STom Musta   #include "libdecnumber/dconfig.h"
47ec150c7eSMarkus Armbruster   #include "libdecnumber/decContext.h"
4872ac97cdSTom Musta 
4972ac97cdSTom Musta   /* Conditional code flag -- set this to match hardware platform     */
5072ac97cdSTom Musta   /* 1=little-endian, 0=big-endian	                              */
5172ac97cdSTom Musta   #if WORDS_BIGENDIAN
5272ac97cdSTom Musta   #define DECLITEND 0
5372ac97cdSTom Musta   #else
5472ac97cdSTom Musta   #define DECLITEND 1
5572ac97cdSTom Musta   #endif
5672ac97cdSTom Musta 
5772ac97cdSTom Musta   /* Conditional code flag -- set this to 1 for best performance      */
5872ac97cdSTom Musta   #define DECUSE64  1	      /* 1=use int64s, 0=int32 & smaller only */
5972ac97cdSTom Musta 
6072ac97cdSTom Musta   /* Conditional check flags -- set these to 0 for best performance   */
6172ac97cdSTom Musta   #define DECCHECK  0	      /* 1 to enable robust checking	      */
6272ac97cdSTom Musta   #define DECALLOC  0	      /* 1 to enable memory accounting	      */
6372ac97cdSTom Musta   #define DECTRACE  0	      /* 1 to trace certain internals, etc.   */
6472ac97cdSTom Musta 
6572ac97cdSTom Musta   /* Tuning parameter for decNumber (arbitrary precision) module      */
6672ac97cdSTom Musta   #define DECBUFFER 36	      /* Size basis for local buffers.	This  */
6772ac97cdSTom Musta 			      /* should be a common maximum precision */
6872ac97cdSTom Musta 			      /* rounded up to a multiple of 4; must  */
6972ac97cdSTom Musta 			      /* be zero or positive.		      */
7072ac97cdSTom Musta 
7172ac97cdSTom Musta   /* ---------------------------------------------------------------- */
7272ac97cdSTom Musta   /* Definitions for all modules (general-purpose)		      */
7372ac97cdSTom Musta   /* ---------------------------------------------------------------- */
7472ac97cdSTom Musta 
7572ac97cdSTom Musta   /* Local names for common types -- for safety, decNumber modules do */
7672ac97cdSTom Musta   /* not use int or long directly.				      */
7772ac97cdSTom Musta   #define Flag	 uint8_t
7872ac97cdSTom Musta   #define Byte	 int8_t
7972ac97cdSTom Musta   #define uByte	 uint8_t
8072ac97cdSTom Musta   #define Short	 int16_t
8172ac97cdSTom Musta   #define uShort uint16_t
8272ac97cdSTom Musta   #define Int	 int32_t
8372ac97cdSTom Musta   #define uInt	 uint32_t
8472ac97cdSTom Musta   #define Unit	 decNumberUnit
8572ac97cdSTom Musta   #if DECUSE64
8672ac97cdSTom Musta   #define Long	 int64_t
8772ac97cdSTom Musta   #define uLong	 uint64_t
8872ac97cdSTom Musta   #endif
8972ac97cdSTom Musta 
9072ac97cdSTom Musta   /* Development-use definitions				      */
9172ac97cdSTom Musta   typedef long int LI;	      /* for printf arguments only	      */
9272ac97cdSTom Musta   #define DECNOINT  0	      /* 1 to check no internal use of 'int'  */
9372ac97cdSTom Musta   #if DECNOINT
9472ac97cdSTom Musta     /* if these interfere with your C includes, do not set DECNOINT   */
9572ac97cdSTom Musta     #define  int ?	      /* enable to ensure that plain C 'int'  */
9672ac97cdSTom Musta     #define  long ??	      /* .. or 'long' types are not used      */
9772ac97cdSTom Musta   #endif
9872ac97cdSTom Musta 
9972ac97cdSTom Musta   /* Shared lookup tables					      */
10072ac97cdSTom Musta   extern const uByte  DECSTICKYTAB[10]; /* re-round digits if sticky  */
101*21d7826fSLuis Pires   extern const uLong  DECPOWERS[20];    /* powers of ten table        */
10272ac97cdSTom Musta   /* The following are included from decDPD.h			      */
10372ac97cdSTom Musta   extern const uShort DPD2BIN[1024];	/* DPD -> 0-999		      */
10472ac97cdSTom Musta   extern const uShort BIN2DPD[1000];	/* 0-999 -> DPD		      */
10572ac97cdSTom Musta   extern const uInt   DPD2BINK[1024];	/* DPD -> 0-999000	      */
10672ac97cdSTom Musta   extern const uInt   DPD2BINM[1024];	/* DPD -> 0-999000000	      */
10772ac97cdSTom Musta   extern const uByte  DPD2BCD8[4096];	/* DPD -> ddd + len	      */
10872ac97cdSTom Musta   extern const uByte  BIN2BCD8[4000];	/* 0-999 -> ddd + len	      */
10972ac97cdSTom Musta   extern const uShort BCD2DPD[2458];	/* 0-0x999 -> DPD (0x999=2457)*/
11072ac97cdSTom Musta 
11172ac97cdSTom Musta   /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts      */
11272ac97cdSTom Musta   /* (that is, sets w to be the high-order word of the 64-bit result; */
11372ac97cdSTom Musta   /* the low-order word is simply u*v.)				      */
11472ac97cdSTom Musta   /* This version is derived from Knuth via Hacker's Delight;	      */
11572ac97cdSTom Musta   /* it seems to optimize better than some others tried		      */
11672ac97cdSTom Musta   #define LONGMUL32HI(w, u, v) {	     \
11772ac97cdSTom Musta     uInt u0, u1, v0, v1, w0, w1, w2, t;	     \
11872ac97cdSTom Musta     u0=u & 0xffff; u1=u>>16;		     \
11972ac97cdSTom Musta     v0=v & 0xffff; v1=v>>16;		     \
12072ac97cdSTom Musta     w0=u0*v0;				     \
12172ac97cdSTom Musta     t=u1*v0 + (w0>>16);			     \
12272ac97cdSTom Musta     w1=t & 0xffff; w2=t>>16;		     \
12372ac97cdSTom Musta     w1=u0*v1 + w1;			     \
12472ac97cdSTom Musta     (w)=u1*v1 + w2 + (w1>>16);}
12572ac97cdSTom Musta 
12672ac97cdSTom Musta   /* ROUNDUP -- round an integer up to a multiple of n		      */
12772ac97cdSTom Musta   #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
12872ac97cdSTom Musta 
12972ac97cdSTom Musta   /* ROUNDDOWN -- round an integer down to a multiple of n	      */
13072ac97cdSTom Musta   #define ROUNDDOWN(i, n) (((i)/n)*n)
13172ac97cdSTom Musta   #define ROUNDDOWN4(i)	  ((i)&~3)	/* special for n=4	      */
13272ac97cdSTom Musta 
13372ac97cdSTom Musta   /* References to multi-byte sequences under different sizes	      */
13472ac97cdSTom Musta   /* Refer to a uInt from four bytes starting at a char* or uByte*,   */
13572ac97cdSTom Musta   /* etc.							      */
13672ac97cdSTom Musta   #define UINTAT(b)   (*((uInt	 *)(b)))
13772ac97cdSTom Musta   #define USHORTAT(b) (*((uShort *)(b)))
13872ac97cdSTom Musta   #define UBYTEAT(b)  (*((uByte	 *)(b)))
13972ac97cdSTom Musta 
14072ac97cdSTom Musta   /* X10 and X100 -- multiply integer i by 10 or 100		      */
14172ac97cdSTom Musta   /* [shifts are usually faster than multiply; could be conditional]  */
14272ac97cdSTom Musta   #define X10(i)  (((i)<<1)+((i)<<3))
14372ac97cdSTom Musta   #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
14472ac97cdSTom Musta 
14572ac97cdSTom Musta   /* MAXI and MINI -- general max & min (not in ANSI) for integers    */
14672ac97cdSTom Musta   #define MAXI(x,y) ((x)<(y)?(y):(x))
14772ac97cdSTom Musta   #define MINI(x,y) ((x)>(y)?(y):(x))
14872ac97cdSTom Musta 
14972ac97cdSTom Musta   /* Useful constants						      */
15072ac97cdSTom Musta   #define BILLION      1000000000	     /* 10**9		      */
15172ac97cdSTom Musta   /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC	      */
15272ac97cdSTom Musta   #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
15372ac97cdSTom Musta 
15472ac97cdSTom Musta 
15572ac97cdSTom Musta   /* ---------------------------------------------------------------- */
156a9dd38dbSStefan Weil   /* Definitions for arbitrary-precision modules (only valid after    */
15772ac97cdSTom Musta   /* decNumber.h has been included)				      */
15872ac97cdSTom Musta   /* ---------------------------------------------------------------- */
15972ac97cdSTom Musta 
16072ac97cdSTom Musta   /* Limits and constants					      */
16172ac97cdSTom Musta   #define DECNUMMAXP 999999999	/* maximum precision code can handle  */
16272ac97cdSTom Musta   #define DECNUMMAXE 999999999	/* maximum adjusted exponent ditto    */
16372ac97cdSTom Musta   #define DECNUMMINE -999999999 /* minimum adjusted exponent ditto    */
16472ac97cdSTom Musta   #if (DECNUMMAXP != DEC_MAX_DIGITS)
16572ac97cdSTom Musta     #error Maximum digits mismatch
16672ac97cdSTom Musta   #endif
16772ac97cdSTom Musta   #if (DECNUMMAXE != DEC_MAX_EMAX)
16872ac97cdSTom Musta     #error Maximum exponent mismatch
16972ac97cdSTom Musta   #endif
17072ac97cdSTom Musta   #if (DECNUMMINE != DEC_MIN_EMIN)
17172ac97cdSTom Musta     #error Minimum exponent mismatch
17272ac97cdSTom Musta   #endif
17372ac97cdSTom Musta 
17472ac97cdSTom Musta   /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN	      */
17572ac97cdSTom Musta   /* digits, and D2UTABLE -- the initializer for the D2U table	      */
17672ac97cdSTom Musta   #if	DECDPUN==1
17772ac97cdSTom Musta     #define DECDPUNMAX 9
17872ac97cdSTom Musta     #define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,  \
17972ac97cdSTom Musta 		      18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \
18072ac97cdSTom Musta 		      33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
18172ac97cdSTom Musta 		      48,49}
18272ac97cdSTom Musta   #elif DECDPUN==2
18372ac97cdSTom Musta     #define DECDPUNMAX 99
18472ac97cdSTom Musta     #define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,  \
18572ac97cdSTom Musta 		      11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
18672ac97cdSTom Musta 		      18,19,19,20,20,21,21,22,22,23,23,24,24,25}
18772ac97cdSTom Musta   #elif DECDPUN==3
18872ac97cdSTom Musta     #define DECDPUNMAX 999
18972ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,  \
19072ac97cdSTom Musta 		      8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
19172ac97cdSTom Musta 		      13,14,14,14,15,15,15,16,16,16,17}
19272ac97cdSTom Musta   #elif DECDPUN==4
19372ac97cdSTom Musta     #define DECDPUNMAX 9999
19472ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,  \
19572ac97cdSTom Musta 		      6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
19672ac97cdSTom Musta 		      11,11,11,12,12,12,12,13}
19772ac97cdSTom Musta   #elif DECDPUN==5
19872ac97cdSTom Musta     #define DECDPUNMAX 99999
19972ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,  \
20072ac97cdSTom Musta 		      5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,  \
20172ac97cdSTom Musta 		      9,9,10,10,10,10}
20272ac97cdSTom Musta   #elif DECDPUN==6
20372ac97cdSTom Musta     #define DECDPUNMAX 999999
20472ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,  \
20572ac97cdSTom Musta 		      4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,  \
20672ac97cdSTom Musta 		      8,8,8,8,8,9}
20772ac97cdSTom Musta   #elif DECDPUN==7
20872ac97cdSTom Musta     #define DECDPUNMAX 9999999
20972ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,  \
21072ac97cdSTom Musta 		      4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,  \
21172ac97cdSTom Musta 		      7,7,7,7,7,7}
21272ac97cdSTom Musta   #elif DECDPUN==8
21372ac97cdSTom Musta     #define DECDPUNMAX 99999999
21472ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,  \
21572ac97cdSTom Musta 		      3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,  \
21672ac97cdSTom Musta 		      6,6,6,6,6,7}
21772ac97cdSTom Musta   #elif DECDPUN==9
21872ac97cdSTom Musta     #define DECDPUNMAX 999999999
21972ac97cdSTom Musta     #define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,  \
22072ac97cdSTom Musta 		      3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,  \
22172ac97cdSTom Musta 		      5,5,6,6,6,6}
22272ac97cdSTom Musta   #elif defined(DECDPUN)
22372ac97cdSTom Musta     #error DECDPUN must be in the range 1-9
22472ac97cdSTom Musta   #endif
22572ac97cdSTom Musta 
22672ac97cdSTom Musta   /* ----- Shared data (in decNumber.c) ----- */
22772ac97cdSTom Musta   /* Public lookup table used by the D2U macro (see below)	      */
22872ac97cdSTom Musta   #define DECMAXD2U 49
22972ac97cdSTom Musta   extern const uByte d2utable[DECMAXD2U+1];
23072ac97cdSTom Musta 
23172ac97cdSTom Musta   /* ----- Macros ----- */
23272ac97cdSTom Musta   /* ISZERO -- return true if decNumber dn is a zero		      */
23372ac97cdSTom Musta   /* [performance-critical in some situations]			      */
23472ac97cdSTom Musta   #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
23572ac97cdSTom Musta 
23672ac97cdSTom Musta   /* D2U -- return the number of Units needed to hold d digits	      */
23772ac97cdSTom Musta   /* (runtime version, with table lookaside for small d)	      */
23872ac97cdSTom Musta   #if DECDPUN==8
23972ac97cdSTom Musta     #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
24072ac97cdSTom Musta   #elif DECDPUN==4
24172ac97cdSTom Musta     #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
24272ac97cdSTom Musta   #else
24372ac97cdSTom Musta     #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
24472ac97cdSTom Musta   #endif
24572ac97cdSTom Musta   /* SD2U -- static D2U macro (for compile-time calculation)	      */
24672ac97cdSTom Musta   #define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
24772ac97cdSTom Musta 
24872ac97cdSTom Musta   /* MSUDIGITS -- returns digits in msu, from digits, calculated      */
24972ac97cdSTom Musta   /* using D2U							      */
25072ac97cdSTom Musta   #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
25172ac97cdSTom Musta 
25272ac97cdSTom Musta   /* D2N -- return the number of decNumber structs that would be      */
25372ac97cdSTom Musta   /* needed to contain that number of digits (and the initial	      */
25472ac97cdSTom Musta   /* decNumber struct) safely.	Note that one Unit is included in the */
25572ac97cdSTom Musta   /* initial structure.	 Used for allocating space that is aligned on */
25672ac97cdSTom Musta   /* a decNumber struct boundary. */
25772ac97cdSTom Musta   #define D2N(d) \
25872ac97cdSTom Musta     ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
25972ac97cdSTom Musta 
26072ac97cdSTom Musta   /* TODIGIT -- macro to remove the leading digit from the unsigned   */
26172ac97cdSTom Musta   /* integer u at column cut (counting from the right, LSD=0) and     */
26272ac97cdSTom Musta   /* place it as an ASCII character into the character pointed to by  */
26372ac97cdSTom Musta   /* c.	 Note that cut must be <= 9, and the maximum value for u is   */
26472ac97cdSTom Musta   /* 2,000,000,000 (as is needed for negative exponents of	      */
26572ac97cdSTom Musta   /* subnormals).  The unsigned integer pow is used as a temporary    */
26672ac97cdSTom Musta   /* variable. */
26772ac97cdSTom Musta   #define TODIGIT(u, cut, c, pow) {	  \
26872ac97cdSTom Musta     *(c)='0';				  \
26972ac97cdSTom Musta     pow=DECPOWERS[cut]*2;		  \
27072ac97cdSTom Musta     if ((u)>pow) {			  \
27172ac97cdSTom Musta       pow*=4;				  \
27272ac97cdSTom Musta       if ((u)>=pow) {(u)-=pow; *(c)+=8;}  \
27372ac97cdSTom Musta       pow/=2;				  \
27472ac97cdSTom Musta       if ((u)>=pow) {(u)-=pow; *(c)+=4;}  \
27572ac97cdSTom Musta       pow/=2;				  \
27672ac97cdSTom Musta       }					  \
27772ac97cdSTom Musta     if ((u)>=pow) {(u)-=pow; *(c)+=2;}	  \
27872ac97cdSTom Musta     pow/=2;				  \
27972ac97cdSTom Musta     if ((u)>=pow) {(u)-=pow; *(c)+=1;}	  \
28072ac97cdSTom Musta     }
28172ac97cdSTom Musta 
28272ac97cdSTom Musta   /* ---------------------------------------------------------------- */
28372ac97cdSTom Musta   /* Definitions for fixed-precision modules (only valid after	      */
28472ac97cdSTom Musta   /* decSingle.h, decDouble.h, or decQuad.h has been included)	      */
28572ac97cdSTom Musta   /* ---------------------------------------------------------------- */
28672ac97cdSTom Musta 
28772ac97cdSTom Musta   /* bcdnum -- a structure describing a format-independent finite     */
28872ac97cdSTom Musta   /* number, whose coefficient is a string of bcd8 uBytes	      */
28972ac97cdSTom Musta   typedef struct {
29072ac97cdSTom Musta     uByte   *msd;	      /* -> most significant digit	      */
29172ac97cdSTom Musta     uByte   *lsd;	      /* -> least ditto			      */
29272ac97cdSTom Musta     uInt     sign;	      /* 0=positive, DECFLOAT_Sign=negative   */
29372ac97cdSTom Musta     Int	     exponent;	      /* Unadjusted signed exponent (q), or   */
29472ac97cdSTom Musta 			      /* DECFLOAT_NaN etc. for a special      */
29572ac97cdSTom Musta     } bcdnum;
29672ac97cdSTom Musta 
29772ac97cdSTom Musta   /* Test if exponent or bcdnum exponent must be a special, etc.      */
29872ac97cdSTom Musta   #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
29972ac97cdSTom Musta   #define EXPISINF(exp) (exp==DECFLOAT_Inf)
30072ac97cdSTom Musta   #define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
30172ac97cdSTom Musta   #define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
30272ac97cdSTom Musta 
30372ac97cdSTom Musta   /* Refer to a 32-bit word or byte in a decFloat (df) by big-endian  */
30472ac97cdSTom Musta   /* (array) notation (the 0 word or byte contains the sign bit),     */
30572ac97cdSTom Musta   /* automatically adjusting for endianness; similarly address a word */
30672ac97cdSTom Musta   /* in the next-wider format (decFloatWider, or dfw)		      */
30772ac97cdSTom Musta   #define DECWORDS  (DECBYTES/4)
30872ac97cdSTom Musta   #define DECWWORDS (DECWBYTES/4)
30972ac97cdSTom Musta   #if DECLITEND
31072ac97cdSTom Musta     #define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)])
31172ac97cdSTom Musta     #define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)])
31272ac97cdSTom Musta     #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
31372ac97cdSTom Musta   #else
31472ac97cdSTom Musta     #define DFWORD(df, off) ((df)->words[off])
31572ac97cdSTom Musta     #define DFBYTE(df, off) ((df)->bytes[off])
31672ac97cdSTom Musta     #define DFWWORD(dfw, off) ((dfw)->words[off])
31772ac97cdSTom Musta   #endif
31872ac97cdSTom Musta 
31972ac97cdSTom Musta   /* Tests for sign or specials, directly on DECFLOATs		      */
32072ac97cdSTom Musta   #define DFISSIGNED(df)   (DFWORD(df, 0)&0x80000000)
32172ac97cdSTom Musta   #define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
32272ac97cdSTom Musta   #define DFISINF(df)	  ((DFWORD(df, 0)&0x7c000000)==0x78000000)
32372ac97cdSTom Musta   #define DFISNAN(df)	  ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
32472ac97cdSTom Musta   #define DFISQNAN(df)	  ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
32572ac97cdSTom Musta   #define DFISSNAN(df)	  ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
32672ac97cdSTom Musta 
32772ac97cdSTom Musta   /* Shared lookup tables					      */
32872ac97cdSTom Musta   extern const uInt   DECCOMBMSD[64];	/* Combination field -> MSD   */
32972ac97cdSTom Musta   extern const uInt   DECCOMBFROM[48];	/* exp+msd -> Combination     */
33072ac97cdSTom Musta 
33172ac97cdSTom Musta   /* Private generic (utility) routine				      */
33272ac97cdSTom Musta   #if DECCHECK || DECTRACE
33372ac97cdSTom Musta     extern void decShowNum(const bcdnum *, const char *);
33472ac97cdSTom Musta   #endif
33572ac97cdSTom Musta 
33672ac97cdSTom Musta   /* Format-dependent macros and constants			      */
33772ac97cdSTom Musta   #if defined(DECPMAX)
33872ac97cdSTom Musta 
33972ac97cdSTom Musta     /* Useful constants						      */
34072ac97cdSTom Musta     #define DECPMAX9  (ROUNDUP(DECPMAX, 9)/9)  /* 'Pmax' in 10**9s    */
34172ac97cdSTom Musta     /* Top words for a zero					      */
34272ac97cdSTom Musta     #define SINGLEZERO	 0x22500000
34372ac97cdSTom Musta     #define DOUBLEZERO	 0x22380000
34472ac97cdSTom Musta     #define QUADZERO	 0x22080000
34572ac97cdSTom Musta     /* [ZEROWORD is defined to be one of these in the DFISZERO macro] */
34672ac97cdSTom Musta 
34772ac97cdSTom Musta     /* Format-dependent common tests:				      */
34872ac97cdSTom Musta     /*	 DFISZERO   -- test for (any) zero			      */
34972ac97cdSTom Musta     /*	 DFISCCZERO -- test for coefficient continuation being zero   */
35072ac97cdSTom Musta     /*	 DFISCC01   -- test for coefficient contains only 0s and 1s   */
35172ac97cdSTom Musta     /*	 DFISINT    -- test for finite and exponent q=0		      */
35272ac97cdSTom Musta     /*	 DFISUINT01 -- test for sign=0, finite, exponent q=0, and     */
35372ac97cdSTom Musta     /*		       MSD=0 or 1				      */
35472ac97cdSTom Musta     /*	 ZEROWORD is also defined here.				      */
35572ac97cdSTom Musta     /* In DFISZERO the first test checks the least-significant word   */
35672ac97cdSTom Musta     /* (most likely to be non-zero); the penultimate tests MSD and    */
35772ac97cdSTom Musta     /* DPDs in the signword, and the final test excludes specials and */
35872ac97cdSTom Musta     /* MSD>7.  DFISINT similarly has to allow for the two forms of    */
35972ac97cdSTom Musta     /* MSD codes.  DFISUINT01 only has to allow for one form of MSD   */
36072ac97cdSTom Musta     /* code.							      */
36172ac97cdSTom Musta     #if DECPMAX==7
36272ac97cdSTom Musta       #define ZEROWORD SINGLEZERO
36372ac97cdSTom Musta       /* [test macros not needed except for Zero]		      */
36472ac97cdSTom Musta       #define DFISZERO(df)  ((DFWORD(df, 0)&0x1c0fffff)==0	   \
36572ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x60000000)!=0x60000000)
36672ac97cdSTom Musta     #elif DECPMAX==16
36772ac97cdSTom Musta       #define ZEROWORD DOUBLEZERO
36872ac97cdSTom Musta       #define DFISZERO(df)  ((DFWORD(df, 1)==0			   \
36972ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x1c03ffff)==0	   \
37072ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x60000000)!=0x60000000))
37172ac97cdSTom Musta       #define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000  \
37272ac97cdSTom Musta 			 ||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
37372ac97cdSTom Musta       #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
37472ac97cdSTom Musta       #define DFISCCZERO(df) (DFWORD(df, 1)==0			   \
37572ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x0003ffff)==0)
37672ac97cdSTom Musta       #define DFISCC01(df)  ((DFWORD(df, 0)&~0xfffc9124)==0	   \
37772ac97cdSTom Musta 			  && (DFWORD(df, 1)&~0x49124491)==0)
37872ac97cdSTom Musta     #elif DECPMAX==34
37972ac97cdSTom Musta       #define ZEROWORD QUADZERO
38072ac97cdSTom Musta       #define DFISZERO(df)  ((DFWORD(df, 3)==0			   \
38172ac97cdSTom Musta 			  &&  DFWORD(df, 2)==0			   \
38272ac97cdSTom Musta 			  &&  DFWORD(df, 1)==0			   \
38372ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x1c003fff)==0	   \
38472ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x60000000)!=0x60000000))
38572ac97cdSTom Musta       #define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000  \
38672ac97cdSTom Musta 			 ||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
38772ac97cdSTom Musta       #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
38872ac97cdSTom Musta       #define DFISCCZERO(df) (DFWORD(df, 3)==0			   \
38972ac97cdSTom Musta 			  &&  DFWORD(df, 2)==0			   \
39072ac97cdSTom Musta 			  &&  DFWORD(df, 1)==0			   \
39172ac97cdSTom Musta 			  && (DFWORD(df, 0)&0x00003fff)==0)
39272ac97cdSTom Musta 
39372ac97cdSTom Musta       #define DFISCC01(df)   ((DFWORD(df, 0)&~0xffffc912)==0	   \
39472ac97cdSTom Musta 			  &&  (DFWORD(df, 1)&~0x44912449)==0	   \
39572ac97cdSTom Musta 			  &&  (DFWORD(df, 2)&~0x12449124)==0	   \
39672ac97cdSTom Musta 			  &&  (DFWORD(df, 3)&~0x49124491)==0)
39772ac97cdSTom Musta     #endif
39872ac97cdSTom Musta 
39972ac97cdSTom Musta     /* Macros to test if a certain 10 bits of a uInt or pair of uInts */
40072ac97cdSTom Musta     /* are a canonical declet [higher or lower bits are ignored].     */
40172ac97cdSTom Musta     /* declet is at offset 0 (from the right) in a uInt:	      */
40272ac97cdSTom Musta     #define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
40372ac97cdSTom Musta     /* declet is at offset k (a multiple of 2) in a uInt:	      */
40472ac97cdSTom Musta     #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0	    \
40572ac97cdSTom Musta       || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
40672ac97cdSTom Musta     /* declet is at offset k (a multiple of 2) in a pair of uInts:    */
40772ac97cdSTom Musta     /* [the top 2 bits will always be in the more-significant uInt]   */
40872ac97cdSTom Musta     #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0	    \
40972ac97cdSTom Musta       || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k)))		    \
41072ac97cdSTom Musta       || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
41172ac97cdSTom Musta 
41272ac97cdSTom Musta     /* Macro to test whether a full-length (length DECPMAX) BCD8      */
41372ac97cdSTom Musta     /* coefficient is zero					      */
41472ac97cdSTom Musta     /* test just the LSWord first, then the remainder		      */
41572ac97cdSTom Musta     #if DECPMAX==7
41672ac97cdSTom Musta       #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0		    \
41772ac97cdSTom Musta 	&& UINTAT((u)+DECPMAX-7)==0)
41872ac97cdSTom Musta     #elif DECPMAX==16
41972ac97cdSTom Musta       #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0		    \
42072ac97cdSTom Musta 	&& (UINTAT((u)+DECPMAX-8)+UINTAT((u)+DECPMAX-12)	    \
42172ac97cdSTom Musta 	   +UINTAT((u)+DECPMAX-16))==0)
42272ac97cdSTom Musta     #elif DECPMAX==34
42372ac97cdSTom Musta       #define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0		    \
42472ac97cdSTom Musta 	&& (UINTAT((u)+DECPMAX-8) +UINTAT((u)+DECPMAX-12)	    \
42572ac97cdSTom Musta 	   +UINTAT((u)+DECPMAX-16)+UINTAT((u)+DECPMAX-20)	    \
42672ac97cdSTom Musta 	   +UINTAT((u)+DECPMAX-24)+UINTAT((u)+DECPMAX-28)	    \
42772ac97cdSTom Musta 	   +UINTAT((u)+DECPMAX-32)+USHORTAT((u)+DECPMAX-34))==0)
42872ac97cdSTom Musta     #endif
42972ac97cdSTom Musta 
43072ac97cdSTom Musta     /* Macros and masks for the exponent continuation field and MSD   */
43172ac97cdSTom Musta     /* Get the exponent continuation from a decFloat *df as an Int    */
43272ac97cdSTom Musta     #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
43372ac97cdSTom Musta     /* Ditto, from the next-wider format			      */
43472ac97cdSTom Musta     #define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
43572ac97cdSTom Musta     /* Get the biased exponent similarly			      */
43672ac97cdSTom Musta     #define GETEXP(df)	((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
43772ac97cdSTom Musta     /* Get the unbiased exponent similarly			      */
43872ac97cdSTom Musta     #define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
43972ac97cdSTom Musta     /* Get the MSD similarly (as uInt)				      */
44072ac97cdSTom Musta     #define GETMSD(df)	 (DECCOMBMSD[DFWORD((df), 0)>>26])
44172ac97cdSTom Musta 
44272ac97cdSTom Musta     /* Compile-time computes of the exponent continuation field masks */
44372ac97cdSTom Musta     /* full exponent continuation field:			      */
44472ac97cdSTom Musta     #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
44572ac97cdSTom Musta     /* same, not including its first digit (the qNaN/sNaN selector):  */
44672ac97cdSTom Musta     #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
44772ac97cdSTom Musta 
44872ac97cdSTom Musta     /* Macros to decode the coefficient in a finite decFloat *df into */
44972ac97cdSTom Musta     /* a BCD string (uByte *bcdin) of length DECPMAX uBytes	      */
45072ac97cdSTom Musta 
45172ac97cdSTom Musta     /* In-line sequence to convert 10 bits at right end of uInt dpd   */
45272ac97cdSTom Musta     /* to three BCD8 digits starting at uByte u.  Note that an extra  */
45372ac97cdSTom Musta     /* byte is written to the right of the three digits because this  */
45472ac97cdSTom Musta     /* moves four at a time for speed; the alternative macro moves    */
45572ac97cdSTom Musta     /* exactly three bytes					      */
45672ac97cdSTom Musta     #define dpd2bcd8(u, dpd) {				 \
45772ac97cdSTom Musta       UINTAT(u)=UINTAT(&DPD2BCD8[((dpd)&0x3ff)*4]);}
45872ac97cdSTom Musta 
45972ac97cdSTom Musta     #define dpd2bcd83(u, dpd) {				 \
46072ac97cdSTom Musta       *(u)=DPD2BCD8[((dpd)&0x3ff)*4];			 \
46172ac97cdSTom Musta       *(u+1)=DPD2BCD8[((dpd)&0x3ff)*4+1];		 \
46272ac97cdSTom Musta       *(u+2)=DPD2BCD8[((dpd)&0x3ff)*4+2];}
46372ac97cdSTom Musta 
46472ac97cdSTom Musta     /* Decode the declets.  After extracting each one, it is decoded  */
46572ac97cdSTom Musta     /* to BCD8 using a table lookup (also used for variable-length    */
46672ac97cdSTom Musta     /* decode).	 Each DPD decode is 3 bytes BCD8 plus a one-byte      */
46772ac97cdSTom Musta     /* length which is not used, here).	 Fixed-length 4-byte moves    */
46872ac97cdSTom Musta     /* are fast, however, almost everywhere, and so are used except   */
46972ac97cdSTom Musta     /* for the final three bytes (to avoid overrun).  The code below  */
47072ac97cdSTom Musta     /* is 36 instructions for Doubles and about 70 for Quads, even    */
47172ac97cdSTom Musta     /* on IA32.							      */
47272ac97cdSTom Musta 
47372ac97cdSTom Musta     /* Two macros are defined for each format:			      */
47472ac97cdSTom Musta     /*	 GETCOEFF extracts the coefficient of the current format      */
47572ac97cdSTom Musta     /*	 GETWCOEFF extracts the coefficient of the next-wider format. */
47672ac97cdSTom Musta     /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */
47772ac97cdSTom Musta 
47872ac97cdSTom Musta     #if DECPMAX==7
47972ac97cdSTom Musta     #define GETCOEFF(df, bcd) {				 \
48072ac97cdSTom Musta       uInt sourhi=DFWORD(df, 0);			 \
48172ac97cdSTom Musta       *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
48272ac97cdSTom Musta       dpd2bcd8(bcd+1, sourhi>>10);			 \
48372ac97cdSTom Musta       dpd2bcd83(bcd+4, sourhi);}
48472ac97cdSTom Musta     #define GETWCOEFF(df, bcd) {			 \
48572ac97cdSTom Musta       uInt sourhi=DFWWORD(df, 0);			 \
48672ac97cdSTom Musta       uInt sourlo=DFWWORD(df, 1);			 \
48772ac97cdSTom Musta       *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
48872ac97cdSTom Musta       dpd2bcd8(bcd+1, sourhi>>8);			 \
48972ac97cdSTom Musta       dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30));	 \
49072ac97cdSTom Musta       dpd2bcd8(bcd+7, sourlo>>20);			 \
49172ac97cdSTom Musta       dpd2bcd8(bcd+10, sourlo>>10);			 \
49272ac97cdSTom Musta       dpd2bcd83(bcd+13, sourlo);}
49372ac97cdSTom Musta 
49472ac97cdSTom Musta     #elif DECPMAX==16
49572ac97cdSTom Musta     #define GETCOEFF(df, bcd) {				 \
49672ac97cdSTom Musta       uInt sourhi=DFWORD(df, 0);			 \
49772ac97cdSTom Musta       uInt sourlo=DFWORD(df, 1);			 \
49872ac97cdSTom Musta       *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
49972ac97cdSTom Musta       dpd2bcd8(bcd+1, sourhi>>8);			 \
50072ac97cdSTom Musta       dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30));	 \
50172ac97cdSTom Musta       dpd2bcd8(bcd+7, sourlo>>20);			 \
50272ac97cdSTom Musta       dpd2bcd8(bcd+10, sourlo>>10);			 \
50372ac97cdSTom Musta       dpd2bcd83(bcd+13, sourlo);}
50472ac97cdSTom Musta     #define GETWCOEFF(df, bcd) {			 \
50572ac97cdSTom Musta       uInt sourhi=DFWWORD(df, 0);			 \
50672ac97cdSTom Musta       uInt sourmh=DFWWORD(df, 1);			 \
50772ac97cdSTom Musta       uInt sourml=DFWWORD(df, 2);			 \
50872ac97cdSTom Musta       uInt sourlo=DFWWORD(df, 3);			 \
50972ac97cdSTom Musta       *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
51072ac97cdSTom Musta       dpd2bcd8(bcd+1, sourhi>>4);			 \
51172ac97cdSTom Musta       dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26));	 \
51272ac97cdSTom Musta       dpd2bcd8(bcd+7, sourmh>>16);			 \
51372ac97cdSTom Musta       dpd2bcd8(bcd+10, sourmh>>6);			 \
51472ac97cdSTom Musta       dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28));	 \
51572ac97cdSTom Musta       dpd2bcd8(bcd+16, sourml>>18);			 \
51672ac97cdSTom Musta       dpd2bcd8(bcd+19, sourml>>8);			 \
51772ac97cdSTom Musta       dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30));	 \
51872ac97cdSTom Musta       dpd2bcd8(bcd+25, sourlo>>20);			 \
51972ac97cdSTom Musta       dpd2bcd8(bcd+28, sourlo>>10);			 \
52072ac97cdSTom Musta       dpd2bcd83(bcd+31, sourlo);}
52172ac97cdSTom Musta 
52272ac97cdSTom Musta     #elif DECPMAX==34
52372ac97cdSTom Musta     #define GETCOEFF(df, bcd) {				 \
52472ac97cdSTom Musta       uInt sourhi=DFWORD(df, 0);			 \
52572ac97cdSTom Musta       uInt sourmh=DFWORD(df, 1);			 \
52672ac97cdSTom Musta       uInt sourml=DFWORD(df, 2);			 \
52772ac97cdSTom Musta       uInt sourlo=DFWORD(df, 3);			 \
52872ac97cdSTom Musta       *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
52972ac97cdSTom Musta       dpd2bcd8(bcd+1, sourhi>>4);			 \
53072ac97cdSTom Musta       dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26));	 \
53172ac97cdSTom Musta       dpd2bcd8(bcd+7, sourmh>>16);			 \
53272ac97cdSTom Musta       dpd2bcd8(bcd+10, sourmh>>6);			 \
53372ac97cdSTom Musta       dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28));	 \
53472ac97cdSTom Musta       dpd2bcd8(bcd+16, sourml>>18);			 \
53572ac97cdSTom Musta       dpd2bcd8(bcd+19, sourml>>8);			 \
53672ac97cdSTom Musta       dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30));	 \
53772ac97cdSTom Musta       dpd2bcd8(bcd+25, sourlo>>20);			 \
53872ac97cdSTom Musta       dpd2bcd8(bcd+28, sourlo>>10);			 \
53972ac97cdSTom Musta       dpd2bcd83(bcd+31, sourlo);}
54072ac97cdSTom Musta 
54172ac97cdSTom Musta       #define GETWCOEFF(df, bcd) {??} /* [should never be used]	      */
54272ac97cdSTom Musta     #endif
54372ac97cdSTom Musta 
54472ac97cdSTom Musta     /* Macros to decode the coefficient in a finite decFloat *df into */
54572ac97cdSTom Musta     /* a base-billion uInt array, with the least-significant	      */
54672ac97cdSTom Musta     /* 0-999999999 'digit' at offset 0.				      */
54772ac97cdSTom Musta 
54872ac97cdSTom Musta     /* Decode the declets.  After extracting each one, it is decoded  */
54972ac97cdSTom Musta     /* to binary using a table lookup.	Three tables are used; one    */
55072ac97cdSTom Musta     /* the usual DPD to binary, the other two pre-multiplied by 1000  */
55172ac97cdSTom Musta     /* and 1000000 to avoid multiplication during decode.  These      */
55272ac97cdSTom Musta     /* tables can also be used for multiplying up the MSD as the DPD  */
55372ac97cdSTom Musta     /* code for 0 through 9 is the identity.			      */
55472ac97cdSTom Musta     #define DPD2BIN0 DPD2BIN	     /* for prettier code	      */
55572ac97cdSTom Musta 
55672ac97cdSTom Musta     #if DECPMAX==7
55772ac97cdSTom Musta     #define GETCOEFFBILL(df, buf) {			      \
55872ac97cdSTom Musta       uInt sourhi=DFWORD(df, 0);			      \
55972ac97cdSTom Musta       (buf)[0]=DPD2BIN0[sourhi&0x3ff]			      \
56072ac97cdSTom Musta 	      +DPD2BINK[(sourhi>>10)&0x3ff]		      \
56172ac97cdSTom Musta 	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
56272ac97cdSTom Musta 
56372ac97cdSTom Musta     #elif DECPMAX==16
56472ac97cdSTom Musta     #define GETCOEFFBILL(df, buf) {			      \
56572ac97cdSTom Musta       uInt sourhi, sourlo;				      \
56672ac97cdSTom Musta       sourlo=DFWORD(df, 1);				      \
56772ac97cdSTom Musta       (buf)[0]=DPD2BIN0[sourlo&0x3ff]			      \
56872ac97cdSTom Musta 	      +DPD2BINK[(sourlo>>10)&0x3ff]		      \
56972ac97cdSTom Musta 	      +DPD2BINM[(sourlo>>20)&0x3ff];		      \
57072ac97cdSTom Musta       sourhi=DFWORD(df, 0);				      \
57172ac97cdSTom Musta       (buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff]   \
57272ac97cdSTom Musta 	      +DPD2BINK[(sourhi>>8)&0x3ff]		      \
57372ac97cdSTom Musta 	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
57472ac97cdSTom Musta 
57572ac97cdSTom Musta     #elif DECPMAX==34
57672ac97cdSTom Musta     #define GETCOEFFBILL(df, buf) {			      \
57772ac97cdSTom Musta       uInt sourhi, sourmh, sourml, sourlo;		      \
57872ac97cdSTom Musta       sourlo=DFWORD(df, 3);				      \
57972ac97cdSTom Musta       (buf)[0]=DPD2BIN0[sourlo&0x3ff]			      \
58072ac97cdSTom Musta 	      +DPD2BINK[(sourlo>>10)&0x3ff]		      \
58172ac97cdSTom Musta 	      +DPD2BINM[(sourlo>>20)&0x3ff];		      \
58272ac97cdSTom Musta       sourml=DFWORD(df, 2);				      \
58372ac97cdSTom Musta       (buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff]   \
58472ac97cdSTom Musta 	      +DPD2BINK[(sourml>>8)&0x3ff]		      \
58572ac97cdSTom Musta 	      +DPD2BINM[(sourml>>18)&0x3ff];		      \
58672ac97cdSTom Musta       sourmh=DFWORD(df, 1);				      \
58772ac97cdSTom Musta       (buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff]   \
58872ac97cdSTom Musta 	      +DPD2BINK[(sourmh>>6)&0x3ff]		      \
58972ac97cdSTom Musta 	      +DPD2BINM[(sourmh>>16)&0x3ff];		      \
59072ac97cdSTom Musta       sourhi=DFWORD(df, 0);				      \
59172ac97cdSTom Musta       (buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff]   \
59272ac97cdSTom Musta 	      +DPD2BINK[(sourhi>>4)&0x3ff]		      \
59372ac97cdSTom Musta 	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
59472ac97cdSTom Musta 
59572ac97cdSTom Musta     #endif
59672ac97cdSTom Musta 
59772ac97cdSTom Musta     /* Macros to decode the coefficient in a finite decFloat *df into */
59872ac97cdSTom Musta     /* a base-thousand uInt array, with the least-significant 0-999   */
59972ac97cdSTom Musta     /* 'digit' at offset 0.					      */
60072ac97cdSTom Musta 
60172ac97cdSTom Musta     /* Decode the declets.  After extracting each one, it is decoded  */
60272ac97cdSTom Musta     /* to binary using a table lookup.				      */
60372ac97cdSTom Musta     #if DECPMAX==7
60472ac97cdSTom Musta     #define GETCOEFFTHOU(df, buf) {			      \
60572ac97cdSTom Musta       uInt sourhi=DFWORD(df, 0);			      \
60672ac97cdSTom Musta       (buf)[0]=DPD2BIN[sourhi&0x3ff];			      \
60772ac97cdSTom Musta       (buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff];		      \
60872ac97cdSTom Musta       (buf)[2]=DECCOMBMSD[sourhi>>26];}
60972ac97cdSTom Musta 
61072ac97cdSTom Musta     #elif DECPMAX==16
61172ac97cdSTom Musta     #define GETCOEFFTHOU(df, buf) {			      \
61272ac97cdSTom Musta       uInt sourhi, sourlo;				      \
61372ac97cdSTom Musta       sourlo=DFWORD(df, 1);				      \
61472ac97cdSTom Musta       (buf)[0]=DPD2BIN[sourlo&0x3ff];			      \
61572ac97cdSTom Musta       (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff];		      \
61672ac97cdSTom Musta       (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff];		      \
61772ac97cdSTom Musta       sourhi=DFWORD(df, 0);				      \
61872ac97cdSTom Musta       (buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff];   \
61972ac97cdSTom Musta       (buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff];		      \
62072ac97cdSTom Musta       (buf)[5]=DECCOMBMSD[sourhi>>26];}
62172ac97cdSTom Musta 
62272ac97cdSTom Musta     #elif DECPMAX==34
62372ac97cdSTom Musta     #define GETCOEFFTHOU(df, buf) {			      \
62472ac97cdSTom Musta       uInt sourhi, sourmh, sourml, sourlo;		      \
62572ac97cdSTom Musta       sourlo=DFWORD(df, 3);				      \
62672ac97cdSTom Musta       (buf)[0]=DPD2BIN[sourlo&0x3ff];			      \
62772ac97cdSTom Musta       (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff];		      \
62872ac97cdSTom Musta       (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff];		      \
62972ac97cdSTom Musta       sourml=DFWORD(df, 2);				      \
63072ac97cdSTom Musta       (buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff];   \
63172ac97cdSTom Musta       (buf)[4]=DPD2BIN[(sourml>>8)&0x3ff];		      \
63272ac97cdSTom Musta       (buf)[5]=DPD2BIN[(sourml>>18)&0x3ff];		      \
63372ac97cdSTom Musta       sourmh=DFWORD(df, 1);				      \
63472ac97cdSTom Musta       (buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff];   \
63572ac97cdSTom Musta       (buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff];		      \
63672ac97cdSTom Musta       (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff];		      \
63772ac97cdSTom Musta       sourhi=DFWORD(df, 0);				      \
63872ac97cdSTom Musta       (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff];   \
63972ac97cdSTom Musta       (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff];		      \
64072ac97cdSTom Musta       (buf)[11]=DECCOMBMSD[sourhi>>26];}
64172ac97cdSTom Musta 
64272ac97cdSTom Musta     #endif
64372ac97cdSTom Musta 
64472ac97cdSTom Musta     /* Set a decFloat to the maximum positive finite number (Nmax)    */
64572ac97cdSTom Musta     #if DECPMAX==7
64672ac97cdSTom Musta     #define DFSETNMAX(df)	     \
64772ac97cdSTom Musta       {DFWORD(df, 0)=0x77f3fcff;}
64872ac97cdSTom Musta     #elif DECPMAX==16
64972ac97cdSTom Musta     #define DFSETNMAX(df)	     \
65072ac97cdSTom Musta       {DFWORD(df, 0)=0x77fcff3f;     \
65172ac97cdSTom Musta        DFWORD(df, 1)=0xcff3fcff;}
65272ac97cdSTom Musta     #elif DECPMAX==34
65372ac97cdSTom Musta     #define DFSETNMAX(df)	     \
65472ac97cdSTom Musta       {DFWORD(df, 0)=0x77ffcff3;     \
65572ac97cdSTom Musta        DFWORD(df, 1)=0xfcff3fcf;     \
65672ac97cdSTom Musta        DFWORD(df, 2)=0xf3fcff3f;     \
65772ac97cdSTom Musta        DFWORD(df, 3)=0xcff3fcff;}
65872ac97cdSTom Musta     #endif
65972ac97cdSTom Musta 
66072ac97cdSTom Musta   /* [end of format-dependent macros and constants]		      */
66172ac97cdSTom Musta   #endif
66272ac97cdSTom Musta 
66372ac97cdSTom Musta #endif
664