xref: /openbsd/gnu/usr.bin/gcc/gcc/hwint.h (revision c87b03e5)
1*c87b03e5Sespie /* HOST_WIDE_INT definitions for the GNU compiler.
2*c87b03e5Sespie    Copyright (C) 1998, 2002 Free Software Foundation, Inc.
3*c87b03e5Sespie 
4*c87b03e5Sespie    This file is part of GCC.
5*c87b03e5Sespie 
6*c87b03e5Sespie    Provide definitions for macros which depend on HOST_BITS_PER_INT
7*c87b03e5Sespie    and HOST_BITS_PER_LONG.  */
8*c87b03e5Sespie 
9*c87b03e5Sespie #ifndef GCC_HWINT_H
10*c87b03e5Sespie #define GCC_HWINT_H
11*c87b03e5Sespie 
12*c87b03e5Sespie /* This describes the machine the compiler is hosted on.  */
13*c87b03e5Sespie #define HOST_BITS_PER_CHAR  CHAR_BIT
14*c87b03e5Sespie #define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT)
15*c87b03e5Sespie #define HOST_BITS_PER_INT   (CHAR_BIT * SIZEOF_INT)
16*c87b03e5Sespie #define HOST_BITS_PER_LONG  (CHAR_BIT * SIZEOF_LONG)
17*c87b03e5Sespie 
18*c87b03e5Sespie #ifdef HAVE_LONG_LONG
19*c87b03e5Sespie # define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG)
20*c87b03e5Sespie #else
21*c87b03e5Sespie #ifdef HAVE___INT64
22*c87b03e5Sespie # define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF___INT64)
23*c87b03e5Sespie #else
24*c87b03e5Sespie /* If we're here and we're GCC, assume this is stage 2+ of a bootstrap
25*c87b03e5Sespie    and 'long long' has the width of the *target*'s long long.  */
26*c87b03e5Sespie # if GCC_VERSION > 3000
27*c87b03e5Sespie #  define HOST_BITS_PER_LONGLONG LONG_LONG_TYPE_SIZE
28*c87b03e5Sespie # endif /* gcc */
29*c87b03e5Sespie #endif
30*c87b03e5Sespie #endif /* no long long */
31*c87b03e5Sespie 
32*c87b03e5Sespie /* Find the largest host integer type and set its size and type.  */
33*c87b03e5Sespie 
34*c87b03e5Sespie /* Use long long on the host if the target has a wider long type than
35*c87b03e5Sespie    the host.  */
36*c87b03e5Sespie 
37*c87b03e5Sespie #if ! defined HOST_BITS_PER_WIDE_INT \
38*c87b03e5Sespie     && defined HOST_BITS_PER_LONGLONG \
39*c87b03e5Sespie     && (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) \
40*c87b03e5Sespie     && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) \
41*c87b03e5Sespie         || defined (LLONG_MAX) || defined (__GNUC__))
42*c87b03e5Sespie 
43*c87b03e5Sespie # ifdef MAX_LONG_TYPE_SIZE
44*c87b03e5Sespie #  if MAX_LONG_TYPE_SIZE > HOST_BITS_PER_LONG
45*c87b03e5Sespie #   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
46*c87b03e5Sespie #   define HOST_WIDE_INT long long
47*c87b03e5Sespie #  endif
48*c87b03e5Sespie # else
49*c87b03e5Sespie #  if LONG_TYPE_SIZE > HOST_BITS_PER_LONG
50*c87b03e5Sespie #   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
51*c87b03e5Sespie #   define HOST_WIDE_INT long long
52*c87b03e5Sespie #  endif
53*c87b03e5Sespie # endif
54*c87b03e5Sespie 
55*c87b03e5Sespie #endif
56*c87b03e5Sespie 
57*c87b03e5Sespie #ifndef HOST_BITS_PER_WIDE_INT
58*c87b03e5Sespie 
59*c87b03e5Sespie # if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
60*c87b03e5Sespie #  define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
61*c87b03e5Sespie #  define HOST_WIDE_INT long
62*c87b03e5Sespie # else
63*c87b03e5Sespie #  define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
64*c87b03e5Sespie #  define HOST_WIDE_INT int
65*c87b03e5Sespie # endif
66*c87b03e5Sespie 
67*c87b03e5Sespie #endif /* ! HOST_BITS_PER_WIDE_INT */
68*c87b03e5Sespie 
69*c87b03e5Sespie /* Provide defaults for the way to print a HOST_WIDE_INT
70*c87b03e5Sespie    in various manners.  */
71*c87b03e5Sespie 
72*c87b03e5Sespie #ifndef HOST_WIDE_INT_PRINT_DEC
73*c87b03e5Sespie # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
74*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_DEC "%d"
75*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_DEC_C "%d"
76*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_DEC_SPACE "% *d"
77*c87b03e5Sespie # else
78*c87b03e5Sespie #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
79*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC "%ld"
80*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC_C "%ldL"
81*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC_SPACE "% *ld"
82*c87b03e5Sespie #  else
83*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC "%lld"
84*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC_C "%lldLL"
85*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DEC_SPACE "% *lld"
86*c87b03e5Sespie #  endif
87*c87b03e5Sespie # endif
88*c87b03e5Sespie #endif /* ! HOST_WIDE_INT_PRINT_DEC */
89*c87b03e5Sespie 
90*c87b03e5Sespie #ifndef HOST_WIDE_INT_PRINT_UNSIGNED
91*c87b03e5Sespie # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
92*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_UNSIGNED "%u"
93*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_UNSIGNED_SPACE "% *u"
94*c87b03e5Sespie # else
95*c87b03e5Sespie #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
96*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_UNSIGNED "%lu"
97*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_UNSIGNED_SPACE "% *lu"
98*c87b03e5Sespie #  else
99*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_UNSIGNED "%llu"
100*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_UNSIGNED_SPACE "% *llu"
101*c87b03e5Sespie #  endif
102*c87b03e5Sespie # endif
103*c87b03e5Sespie #endif /* ! HOST_WIDE_INT_PRINT_UNSIGNED */
104*c87b03e5Sespie 
105*c87b03e5Sespie #ifndef HOST_WIDE_INT_PRINT_HEX
106*c87b03e5Sespie # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
107*c87b03e5Sespie #  define HOST_WIDE_INT_PRINT_HEX "0x%x"
108*c87b03e5Sespie # else
109*c87b03e5Sespie #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
110*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_HEX "0x%lx"
111*c87b03e5Sespie #  else
112*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_HEX "0x%llx"
113*c87b03e5Sespie #  endif
114*c87b03e5Sespie # endif
115*c87b03e5Sespie #endif /* ! HOST_WIDE_INT_PRINT_HEX */
116*c87b03e5Sespie 
117*c87b03e5Sespie #ifndef HOST_WIDE_INT_PRINT_DOUBLE_HEX
118*c87b03e5Sespie # if HOST_BITS_PER_WIDE_INT == 64
119*c87b03e5Sespie #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
120*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%x%016x"
121*c87b03e5Sespie #  else
122*c87b03e5Sespie #   if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
123*c87b03e5Sespie #    define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%016lx"
124*c87b03e5Sespie #   else
125*c87b03e5Sespie #    define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%llx%016llx"
126*c87b03e5Sespie #   endif
127*c87b03e5Sespie #  endif
128*c87b03e5Sespie # else
129*c87b03e5Sespie #  if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
130*c87b03e5Sespie #   define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%x%08x"
131*c87b03e5Sespie #  else
132*c87b03e5Sespie #   if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
133*c87b03e5Sespie #    define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%08lx"
134*c87b03e5Sespie #   else
135*c87b03e5Sespie #    define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%llx%08llx"
136*c87b03e5Sespie #   endif
137*c87b03e5Sespie #  endif
138*c87b03e5Sespie # endif
139*c87b03e5Sespie #endif /* ! HOST_WIDE_INT_PRINT_DOUBLE_HEX */
140*c87b03e5Sespie 
141*c87b03e5Sespie /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
142*c87b03e5Sespie    It will be the largest integer mode supported by the host which may
143*c87b03e5Sespie    (or may not) be larger than HOST_WIDE_INT.  */
144*c87b03e5Sespie 
145*c87b03e5Sespie #ifndef HOST_WIDEST_INT
146*c87b03e5Sespie #if defined HOST_BITS_PER_LONGLONG \
147*c87b03e5Sespie     && HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG
148*c87b03e5Sespie #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
149*c87b03e5Sespie #   define HOST_WIDEST_INT long long
150*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_DEC "%lld"
151*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_DEC_SPACE "% *lld"
152*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
153*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_UNSIGNED_SPACE "% *llu"
154*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
155*c87b03e5Sespie #  else
156*c87b03e5Sespie #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
157*c87b03e5Sespie #   define HOST_WIDEST_INT long
158*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_DEC "%ld"
159*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_DEC_SPACE "% *ld"
160*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
161*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_UNSIGNED_SPACE "% *lu"
162*c87b03e5Sespie #   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
163*c87b03e5Sespie # endif /* long long wider than long */
164*c87b03e5Sespie #endif /* ! HOST_WIDEST_INT */
165*c87b03e5Sespie 
166*c87b03e5Sespie #endif /* ! GCC_HWINT_H */
167