3 * Program to find appropriate types for multiprecision integer stuff.
9 #if __STDC_VERSION__ >= 199900l
13 /* --- Hack for GCC --- *
15 * WG14 in their infinite wisdom decided not to use the GCC constant name.
18 #if defined(ULONG_LONG_MAX) && !defined(ULLONG_MAX)
19 # define ULLONG_MAX ULONG_LONG_MAX
22 /* --- Choose the largest integer type --- */
24 #if defined(UINTMAX_MAX)
25 typedef uintmax_t umax
;
26 # define P_UMAX PRIuMAX
27 #elif defined(ULLONG_MAX)
28 typedef unsigned long long umax
;
29 # define P_UMAX "%llu"
31 typedef unsigned long umax
;
35 /* --- Table of interesting types --- *
37 * These are in preference order.
50 { "unsigned int", UINT_MAX
, 0 },
51 { "unsigned short", USHRT_MAX
, 0 },
52 { "unsigned long", ULONG_MAX
, 0 },
54 { "unsigned long long", ULLONG_MAX
, 0 },
57 { "uintmax_t", UINTMAX_MAX
, f_stdint
},
62 typedef struct itype itype
;
64 /* --- Main program --- */
66 int main(int argc
, char *argv
[])
69 itype
*largest
, *mpw
, *mpd
;
71 /* --- Find the bitcounts --- */
73 for (i
= tytab
; i
->name
; i
++) {
76 for (bits
= 0; u
; bits
++)
81 /* --- Now try to find the interesting types --- *
83 * The first thing to do is to find the largest type. Then I find the
84 * `best' type which is less than half that size, and then the `best' type
85 * which is twice as big as that one.
89 for (i
= tytab
; i
->name
; i
++) {
90 if (i
->bits
> largest
->bits
)
93 for (mpw
= 0, i
= tytab
; i
->name
; i
++) {
94 if (i
->bits
* 2 <= largest
->bits
&& (!mpw
|| i
->bits
> mpw
->bits
))
99 for (mpd
= 0, i
= tytab
; i
->name
; i
++) {
100 if (i
->bits
>= mpw
->bits
* 2 && (!mpd
|| i
->bits
< mpd
->bits
))
106 w
.bits
/= 2; w
.max
= ~(~((umax
)0) << w
.bits
);
107 d
.bits
= w
.bits
* 2; d
.max
= ~(~((umax
)0) << d
.bits
);
111 /* --- Output time --- */
116 * mptypes.h [generated]\n\
122 if ((mpd
->flags
| mpw
->flags
) & f_stdint
) {
124 #if __STDC_VERSION__ >= 199900l\n\
125 # include <stdint.h>\n\
131 #define MPW_BITS %u\n\
132 #define MPW_MAX " P_UMAX
"\n\
135 #define MPD_BITS %u\n\
136 #define MPD_MAX " P_UMAX
"\n\
140 mpw
->name
, mpw
->bits
, mpw
->max
,
141 mpd
->name
, mpd
->bits
, mpd
->max
);