]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/hwint.h
re PR tree-optimization/56799 (Runfail after r197060+r197082.)
[thirdparty/gcc.git] / gcc / hwint.h
CommitLineData
cce4a958 1/* HOST_WIDE_INT definitions for the GNU compiler.
d1e082c2 2 Copyright (C) 1998-2013 Free Software Foundation, Inc.
cce4a958 3
1322177d 4 This file is part of GCC.
cce4a958
KG
5
6 Provide definitions for macros which depend on HOST_BITS_PER_INT
19eb1ad7 7 and HOST_BITS_PER_LONG. */
cce4a958 8
88657302
RH
9#ifndef GCC_HWINT_H
10#define GCC_HWINT_H
cce4a958 11
75e93faa
ZW
12/* This describes the machine the compiler is hosted on. */
13#define HOST_BITS_PER_CHAR CHAR_BIT
14#define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT)
15#define HOST_BITS_PER_INT (CHAR_BIT * SIZEOF_INT)
16#define HOST_BITS_PER_LONG (CHAR_BIT * SIZEOF_LONG)
17
edb89024
DR
18/* The string that should be inserted into a printf style format to
19 indicate a "long" operand. */
b8698a0f 20#ifndef HOST_LONG_FORMAT
edb89024
DR
21#define HOST_LONG_FORMAT "l"
22#endif
23
be6601c3
MM
24/* The string that should be inserted into a printf style format to
25 indicate a "long long" operand. */
b8698a0f 26#ifndef HOST_LONG_LONG_FORMAT
be6601c3
MM
27#define HOST_LONG_LONG_FORMAT "ll"
28#endif
29
4977bab6
ZW
30/* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but
31 GCC_VERSION >= 3000, assume this is the second or later stage of a
32 bootstrap, we do have long long, and it's 64 bits. (This is
33 required by C99; we do have some ports that violate that assumption
34 but they're all cross-compile-only.) Just in case, force a
35 constraint violation if that assumption is incorrect. */
36#if !defined HAVE_LONG_LONG
37# if GCC_VERSION >= 3000
38# define HAVE_LONG_LONG 1
39# define SIZEOF_LONG_LONG 8
40extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1];
41# endif
42#endif
43
75e93faa
ZW
44#ifdef HAVE_LONG_LONG
45# define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG)
4977bab6 46#endif
964b104a 47#ifdef HAVE___INT64
4977bab6 48# define HOST_BITS_PER___INT64 (CHAR_BIT * SIZEOF___INT64)
6d08665a 49#endif
cce4a958 50
4977bab6
ZW
51/* Set HOST_WIDE_INT. This should be the widest efficient host
52 integer type. It can be 32 or 64 bits, except that if we are
53 targeting a machine with 64-bit size_t then it has to be 64 bits.
cce4a958 54
4977bab6
ZW
55 With a sane ABI, 'long' is the largest efficient host integer type.
56 Thus, we use that unless we have to use 'long long' or '__int64'
57 because we're targeting a 64-bit machine from a 32-bit host. */
4abe9f62 58
4977bab6
ZW
59#if HOST_BITS_PER_LONG >= 64 || !defined NEED_64BIT_HOST_WIDE_INT
60# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
61# define HOST_WIDE_INT long
fd2d9121 62# define HOST_WIDE_INT_C(X) X ## L
4977bab6
ZW
63#else
64# if HOST_BITS_PER_LONGLONG >= 64
4abe9f62
AO
65# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
66# define HOST_WIDE_INT long long
fd2d9121 67# define HOST_WIDE_INT_C(X) X ## LL
cce4a958 68# else
4977bab6
ZW
69# if HOST_BITS_PER___INT64 >= 64
70# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER___INT64
71# define HOST_WIDE_INT __int64
fd2d9121 72# define HOST_WIDE_INT_C(X) X ## i64
cce4a958 73# else
4977bab6 74 #error "Unable to find a suitable type for HOST_WIDE_INT"
cce4a958
KG
75# endif
76# endif
4977bab6 77#endif
cce4a958 78
fd2d9121
RH
79#define HOST_WIDE_INT_1 HOST_WIDE_INT_C(1)
80
be7a421e
SB
81/* This is a magic identifier which allows GCC to figure out the type
82 of HOST_WIDE_INT for %wd specifier checks. You must issue this
83 typedef before using the __asm_fprintf__ format attribute. */
84typedef HOST_WIDE_INT __gcc_host_wide_int__;
85
4977bab6
ZW
86/* Various printf format strings for HOST_WIDE_INT. */
87
88#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
edb89024 89# define HOST_WIDE_INT_PRINT HOST_LONG_FORMAT
85f015e1 90# define HOST_WIDE_INT_PRINT_C "L"
4977bab6
ZW
91 /* 'long' might be 32 or 64 bits, and the number of leading zeroes
92 must be tweaked accordingly. */
93# if HOST_BITS_PER_WIDE_INT == 64
edb89024 94# define HOST_WIDE_INT_PRINT_DOUBLE_HEX \
34a47f6f 95 "0x%" HOST_LONG_FORMAT "x%016" HOST_LONG_FORMAT "x"
cce4a958 96# else
edb89024 97# define HOST_WIDE_INT_PRINT_DOUBLE_HEX \
34a47f6f 98 "0x%" HOST_LONG_FORMAT "x%08" HOST_LONG_FORMAT "x"
cce4a958 99# endif
4977bab6 100#else
6194fd98 101# define HOST_WIDE_INT_PRINT HOST_LONG_LONG_FORMAT
85f015e1 102# define HOST_WIDE_INT_PRINT_C "LL"
4977bab6 103 /* We can assume that 'long long' is at least 64 bits. */
be6601c3 104# define HOST_WIDE_INT_PRINT_DOUBLE_HEX \
34a47f6f 105 "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x"
85f015e1
KG
106#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */
107
108#define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d"
109#define HOST_WIDE_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC HOST_WIDE_INT_PRINT_C
110#define HOST_WIDE_INT_PRINT_UNSIGNED "%" HOST_WIDE_INT_PRINT "u"
35c59d9c 111#define HOST_WIDE_INT_PRINT_HEX "%#" HOST_WIDE_INT_PRINT "x"
dde8b360 112#define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x"
cce4a958 113
44f9a8e4
ZW
114/* Set HOST_WIDEST_INT. This is a 64-bit type unless the compiler
115 in use has no 64-bit type at all; in that case it's 32 bits. */
4977bab6 116
44f9a8e4
ZW
117#if HOST_BITS_PER_WIDE_INT >= 64 \
118 || (HOST_BITS_PER_LONGLONG < 64 && HOST_BITS_PER___INT64 < 64)
4977bab6
ZW
119# define HOST_WIDEST_INT HOST_WIDE_INT
120# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_WIDE_INT
e2d87023 121# define HOST_WIDEST_INT_PRINT HOST_WIDE_INT_PRINT
4977bab6
ZW
122# define HOST_WIDEST_INT_PRINT_DEC HOST_WIDE_INT_PRINT_DEC
123# define HOST_WIDEST_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC_C
4977bab6 124# define HOST_WIDEST_INT_PRINT_UNSIGNED HOST_WIDE_INT_PRINT_UNSIGNED
4977bab6
ZW
125# define HOST_WIDEST_INT_PRINT_HEX HOST_WIDE_INT_PRINT_HEX
126# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX HOST_WIDE_INT_PRINT_DOUBLE_HEX
fd2d9121 127# define HOST_WIDEST_INT_C(X) HOST_WIDE_INT(X)
4977bab6
ZW
128#else
129# if HOST_BITS_PER_LONGLONG >= 64
130# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
131# define HOST_WIDEST_INT long long
fd2d9121 132# define HOST_WIDEST_INT_C(X) X ## LL
cce4a958 133# else
4977bab6
ZW
134# if HOST_BITS_PER___INT64 >= 64
135# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER___INT64
136# define HOST_WIDEST_INT __int64
fd2d9121 137# define HOST_WIDEST_INT_C(X) X ## i64
cce4a958 138# else
44f9a8e4 139 #error "This line should be impossible to reach"
cce4a958
KG
140# endif
141# endif
e2d87023 142# define HOST_WIDEST_INT_PRINT HOST_LONG_LONG_FORMAT
be6601c3
MM
143# define HOST_WIDEST_INT_PRINT_DEC "%" HOST_LONG_LONG_FORMAT "d"
144# define HOST_WIDEST_INT_PRINT_DEC_C "%" HOST_LONG_LONG_FORMAT "dLL"
145# define HOST_WIDEST_INT_PRINT_UNSIGNED "%" HOST_LONG_LONG_FORMAT "u"
35c59d9c 146# define HOST_WIDEST_INT_PRINT_HEX "%#" HOST_LONG_LONG_FORMAT "x"
be6601c3 147# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX \
34a47f6f 148 "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x"
4977bab6 149#endif
75e93faa 150
99fa8911
AP
151/* Define HOST_WIDEST_FAST_INT to the widest integer type supported
152 efficiently in hardware. (That is, the widest integer type that fits
153 in a hardware register.) Normally this is "long" but on some hosts it
154 should be "long long" or "__int64". This is no convenient way to
9f5ed61a 155 autodetect this, so such systems must set a flag in config.host; see there
99fa8911
AP
156 for details. */
157
158#ifdef USE_LONG_LONG_FOR_WIDEST_FAST_INT
159# ifdef HAVE_LONG_LONG
160# define HOST_WIDEST_FAST_INT long long
161# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONGLONG
162# elif defined (HAVE___INT64)
163# define HOST_WIDEST_FAST_INT __int64
164# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER___INT64
165# else
fa10beec 166# error "Your host said it wanted to use long long or __int64 but neither"
99fa8911
AP
167# error "exist"
168# endif
169#else
170# define HOST_WIDEST_FAST_INT long
171# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONG
172#endif
173
c59ffc41
JM
174/* Inline functions operating on HOST_WIDE_INT. */
175#if GCC_VERSION < 3004
176
177extern int clz_hwi (unsigned HOST_WIDE_INT x);
178extern int ctz_hwi (unsigned HOST_WIDE_INT x);
179extern int ffs_hwi (unsigned HOST_WIDE_INT x);
180
440b6d59
TV
181/* Return the number of set bits in X. */
182extern int popcount_hwi (unsigned HOST_WIDE_INT x);
183
c59ffc41
JM
184/* Return log2, or -1 if not exact. */
185extern int exact_log2 (unsigned HOST_WIDE_INT);
186
187/* Return floor of log2, with -1 for zero. */
188extern int floor_log2 (unsigned HOST_WIDE_INT);
189
46d33ae9
SB
190/* Return the smallest n such that 2**n >= X. */
191extern int ceil_log2 (unsigned HOST_WIDE_INT);
192
c59ffc41
JM
193#else /* GCC_VERSION >= 3004 */
194
195/* For convenience, define 0 -> word_size. */
196static inline int
197clz_hwi (unsigned HOST_WIDE_INT x)
198{
199 if (x == 0)
200 return HOST_BITS_PER_WIDE_INT;
201# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
202 return __builtin_clzl (x);
203# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
204 return __builtin_clzll (x);
205# else
206 return __builtin_clz (x);
207# endif
208}
209
210static inline int
211ctz_hwi (unsigned HOST_WIDE_INT x)
212{
213 if (x == 0)
214 return HOST_BITS_PER_WIDE_INT;
215# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
216 return __builtin_ctzl (x);
217# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
218 return __builtin_ctzll (x);
219# else
220 return __builtin_ctz (x);
221# endif
222}
223
224static inline int
225ffs_hwi (unsigned HOST_WIDE_INT x)
226{
227# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
228 return __builtin_ffsl (x);
229# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
230 return __builtin_ffsll (x);
231# else
232 return __builtin_ffs (x);
233# endif
234}
235
440b6d59
TV
236static inline int
237popcount_hwi (unsigned HOST_WIDE_INT x)
238{
239# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
240 return __builtin_popcountl (x);
241# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
242 return __builtin_popcountll (x);
243# else
244 return __builtin_popcount (x);
245# endif
246}
247
c59ffc41
JM
248static inline int
249floor_log2 (unsigned HOST_WIDE_INT x)
250{
251 return HOST_BITS_PER_WIDE_INT - 1 - clz_hwi (x);
252}
253
46d33ae9
SB
254static inline int
255ceil_log2 (unsigned HOST_WIDE_INT x)
256{
257 return floor_log2 (x - 1) + 1;
258}
259
c59ffc41
JM
260static inline int
261exact_log2 (unsigned HOST_WIDE_INT x)
262{
263 return x == (x & -x) && x ? ctz_hwi (x) : -1;
264}
265
266#endif /* GCC_VERSION >= 3004 */
267
3c67fd9c
SP
268#define HOST_WIDE_INT_MIN (HOST_WIDE_INT) \
269 ((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1))
270#define HOST_WIDE_INT_MAX (~(HOST_WIDE_INT_MIN))
271
272extern HOST_WIDE_INT abs_hwi (HOST_WIDE_INT);
4c9cf7af 273extern unsigned HOST_WIDE_INT absu_hwi (HOST_WIDE_INT);
3c67fd9c
SP
274extern HOST_WIDE_INT gcd (HOST_WIDE_INT, HOST_WIDE_INT);
275extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
276extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
277extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT);
b305e3da 278
88657302 279#endif /* ! GCC_HWINT_H */