Mercurial > hg > CbC > CbC_gcc
annotate gcc/hwint.h @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 1830386684a0 |
children |
rev | line source |
---|---|
0 | 1 /* HOST_WIDE_INT definitions for the GNU compiler. |
145 | 2 Copyright (C) 1998-2020 Free Software Foundation, Inc. |
0 | 3 |
4 This file is part of GCC. | |
5 | |
6 Provide definitions for macros which depend on HOST_BITS_PER_INT | |
7 and HOST_BITS_PER_LONG. */ | |
8 | |
9 #ifndef GCC_HWINT_H | |
10 #define GCC_HWINT_H | |
11 | |
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) | |
131 | 17 #define HOST_BITS_PER_PTR (CHAR_BIT * SIZEOF_VOID_P) |
0 | 18 |
19 /* The string that should be inserted into a printf style format to | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
20 indicate a "long" operand. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
21 #ifndef HOST_LONG_FORMAT |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
22 #define HOST_LONG_FORMAT "l" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
23 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
24 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
25 /* The string that should be inserted into a printf style format to |
0 | 26 indicate a "long long" operand. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
27 #ifndef HOST_LONG_LONG_FORMAT |
0 | 28 #define HOST_LONG_LONG_FORMAT "ll" |
29 #endif | |
30 | |
31 /* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but | |
32 GCC_VERSION >= 3000, assume this is the second or later stage of a | |
33 bootstrap, we do have long long, and it's 64 bits. (This is | |
34 required by C99; we do have some ports that violate that assumption | |
35 but they're all cross-compile-only.) Just in case, force a | |
36 constraint violation if that assumption is incorrect. */ | |
37 #if !defined HAVE_LONG_LONG | |
38 # if GCC_VERSION >= 3000 | |
39 # define HAVE_LONG_LONG 1 | |
40 # define SIZEOF_LONG_LONG 8 | |
111 | 41 extern char sizeof_long_long_must_be_8[sizeof (long long) == 8 ? 1 : -1]; |
0 | 42 # endif |
43 #endif | |
44 | |
45 #ifdef HAVE_LONG_LONG | |
46 # define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG) | |
47 #endif | |
111 | 48 |
49 /* Set HOST_WIDE_INT, this should be always 64 bits. | |
50 The underlying type is matched to that of int64_t and assumed | |
51 to be either long or long long. */ | |
52 | |
53 #define HOST_BITS_PER_WIDE_INT 64 | |
54 #if INT64_T_IS_LONG | |
55 # define HOST_WIDE_INT long | |
56 # define HOST_WIDE_INT_C(X) X ## L | |
57 #else | |
58 # if HOST_BITS_PER_LONGLONG == 64 | |
59 # define HOST_WIDE_INT long long | |
60 # define HOST_WIDE_INT_C(X) X ## LL | |
61 # else | |
62 #error "Unable to find a suitable type for HOST_WIDE_INT" | |
63 # endif | |
0 | 64 #endif |
65 | |
111 | 66 #define HOST_WIDE_INT_UC(X) HOST_WIDE_INT_C (X ## U) |
67 #define HOST_WIDE_INT_0 HOST_WIDE_INT_C (0) | |
68 #define HOST_WIDE_INT_0U HOST_WIDE_INT_UC (0) | |
69 #define HOST_WIDE_INT_1 HOST_WIDE_INT_C (1) | |
70 #define HOST_WIDE_INT_1U HOST_WIDE_INT_UC (1) | |
71 #define HOST_WIDE_INT_M1 HOST_WIDE_INT_C (-1) | |
72 #define HOST_WIDE_INT_M1U HOST_WIDE_INT_UC (-1) | |
0 | 73 |
111 | 74 /* This is a magic identifier which allows GCC to figure out the type |
75 of HOST_WIDE_INT for %wd specifier checks. You must issue this | |
76 typedef before using the __asm_fprintf__ format attribute. */ | |
77 typedef HOST_WIDE_INT __gcc_host_wide_int__; | |
0 | 78 |
111 | 79 /* Provide C99 <inttypes.h> style format definitions for 64bits. */ |
80 #ifndef HAVE_INTTYPES_H | |
81 #if INT64_T_IS_LONG | |
82 # define GCC_PRI64 HOST_LONG_FORMAT | |
0 | 83 #else |
111 | 84 # define GCC_PRI64 HOST_LONG_LONG_FORMAT |
85 #endif | |
86 #undef PRId64 | |
87 #define PRId64 GCC_PRI64 "d" | |
88 #undef PRIi64 | |
89 #define PRIi64 GCC_PRI64 "i" | |
90 #undef PRIo64 | |
91 #define PRIo64 GCC_PRI64 "o" | |
92 #undef PRIu64 | |
93 #define PRIu64 GCC_PRI64 "u" | |
94 #undef PRIx64 | |
95 #define PRIx64 GCC_PRI64 "x" | |
96 #undef PRIX64 | |
97 #define PRIX64 GCC_PRI64 "X" | |
0 | 98 #endif |
99 | |
100 /* Various printf format strings for HOST_WIDE_INT. */ | |
101 | |
111 | 102 #if INT64_T_IS_LONG |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
103 # define HOST_WIDE_INT_PRINT HOST_LONG_FORMAT |
0 | 104 # define HOST_WIDE_INT_PRINT_C "L" |
105 #else | |
106 # define HOST_WIDE_INT_PRINT HOST_LONG_LONG_FORMAT | |
107 # define HOST_WIDE_INT_PRINT_C "LL" | |
111 | 108 #endif |
0 | 109 |
111 | 110 #define HOST_WIDE_INT_PRINT_DEC "%" PRId64 |
111 #define HOST_WIDE_INT_PRINT_DEC_C "%" PRId64 HOST_WIDE_INT_PRINT_C | |
112 #define HOST_WIDE_INT_PRINT_UNSIGNED "%" PRIu64 | |
113 #define HOST_WIDE_INT_PRINT_HEX "%#" PRIx64 | |
114 #define HOST_WIDE_INT_PRINT_HEX_PURE "%" PRIx64 | |
115 #define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%" PRIx64 "%016" PRIx64 | |
116 #define HOST_WIDE_INT_PRINT_PADDED_HEX "%016" PRIx64 | |
0 | 117 |
118 /* Define HOST_WIDEST_FAST_INT to the widest integer type supported | |
119 efficiently in hardware. (That is, the widest integer type that fits | |
120 in a hardware register.) Normally this is "long" but on some hosts it | |
121 should be "long long" or "__int64". This is no convenient way to | |
122 autodetect this, so such systems must set a flag in config.host; see there | |
123 for details. */ | |
124 | |
125 #ifdef USE_LONG_LONG_FOR_WIDEST_FAST_INT | |
126 # ifdef HAVE_LONG_LONG | |
127 # define HOST_WIDEST_FAST_INT long long | |
128 # define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONGLONG | |
129 # else | |
111 | 130 # error "Your host said it wanted to use long long but that does not exist" |
0 | 131 # endif |
132 #else | |
133 # define HOST_WIDEST_FAST_INT long | |
134 # define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONG | |
135 #endif | |
136 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
137 /* Inline functions operating on HOST_WIDE_INT. */ |
111 | 138 |
139 /* Return X with all but the lowest bit masked off. */ | |
140 | |
141 static inline unsigned HOST_WIDE_INT | |
142 least_bit_hwi (unsigned HOST_WIDE_INT x) | |
143 { | |
144 return (x & -x); | |
145 } | |
146 | |
147 /* True if X is zero or a power of two. */ | |
148 | |
149 static inline bool | |
150 pow2_or_zerop (unsigned HOST_WIDE_INT x) | |
151 { | |
152 return least_bit_hwi (x) == x; | |
153 } | |
154 | |
155 /* True if X is a power of two. */ | |
156 | |
157 static inline bool | |
158 pow2p_hwi (unsigned HOST_WIDE_INT x) | |
159 { | |
160 return x && pow2_or_zerop (x); | |
161 } | |
162 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
163 #if GCC_VERSION < 3004 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
164 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
165 extern int clz_hwi (unsigned HOST_WIDE_INT x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
166 extern int ctz_hwi (unsigned HOST_WIDE_INT x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
167 extern int ffs_hwi (unsigned HOST_WIDE_INT x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
168 |
111 | 169 /* Return the number of set bits in X. */ |
170 extern int popcount_hwi (unsigned HOST_WIDE_INT x); | |
171 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
172 /* Return log2, or -1 if not exact. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
173 extern int exact_log2 (unsigned HOST_WIDE_INT); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
174 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
175 /* Return floor of log2, with -1 for zero. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
176 extern int floor_log2 (unsigned HOST_WIDE_INT); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
177 |
111 | 178 /* Return the smallest n such that 2**n >= X. */ |
179 extern int ceil_log2 (unsigned HOST_WIDE_INT); | |
180 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
181 #else /* GCC_VERSION >= 3004 */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
182 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
183 /* For convenience, define 0 -> word_size. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
184 static inline int |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
185 clz_hwi (unsigned HOST_WIDE_INT x) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
186 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
187 if (x == 0) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
188 return HOST_BITS_PER_WIDE_INT; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
189 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
190 return __builtin_clzl (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
191 # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
192 return __builtin_clzll (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
193 # else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
194 return __builtin_clz (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
195 # endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
196 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
197 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
198 static inline int |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
199 ctz_hwi (unsigned HOST_WIDE_INT x) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
200 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
201 if (x == 0) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
202 return HOST_BITS_PER_WIDE_INT; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
203 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
204 return __builtin_ctzl (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
205 # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
206 return __builtin_ctzll (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
207 # else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
208 return __builtin_ctz (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
209 # endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
210 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
211 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
212 static inline int |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
213 ffs_hwi (unsigned HOST_WIDE_INT x) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
214 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
215 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
216 return __builtin_ffsl (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
217 # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
218 return __builtin_ffsll (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
219 # else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
220 return __builtin_ffs (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
221 # endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
222 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
223 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
224 static inline int |
111 | 225 popcount_hwi (unsigned HOST_WIDE_INT x) |
226 { | |
227 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG | |
228 return __builtin_popcountl (x); | |
229 # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG | |
230 return __builtin_popcountll (x); | |
231 # else | |
232 return __builtin_popcount (x); | |
233 # endif | |
234 } | |
235 | |
236 static inline int | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
237 floor_log2 (unsigned HOST_WIDE_INT x) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
238 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
239 return HOST_BITS_PER_WIDE_INT - 1 - clz_hwi (x); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
240 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
241 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
242 static inline int |
111 | 243 ceil_log2 (unsigned HOST_WIDE_INT x) |
244 { | |
131 | 245 return x == 0 ? 0 : floor_log2 (x - 1) + 1; |
111 | 246 } |
247 | |
248 static inline int | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
249 exact_log2 (unsigned HOST_WIDE_INT x) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
250 { |
111 | 251 return pow2p_hwi (x) ? ctz_hwi (x) : -1; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
252 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
253 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
254 #endif /* GCC_VERSION >= 3004 */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
255 |
111 | 256 #define HOST_WIDE_INT_MIN (HOST_WIDE_INT) \ |
257 (HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1)) | |
258 #define HOST_WIDE_INT_MAX (~(HOST_WIDE_INT_MIN)) | |
259 | |
260 extern HOST_WIDE_INT abs_hwi (HOST_WIDE_INT); | |
261 extern unsigned HOST_WIDE_INT absu_hwi (HOST_WIDE_INT); | |
262 extern HOST_WIDE_INT gcd (HOST_WIDE_INT, HOST_WIDE_INT); | |
263 extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT); | |
264 extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT); | |
265 extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT); | |
266 | |
267 /* Like ctz_hwi, except 0 when x == 0. */ | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
268 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
269 static inline int |
111 | 270 ctz_or_zero (unsigned HOST_WIDE_INT x) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
271 { |
111 | 272 return ffs_hwi (x) - 1; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
273 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
274 |
111 | 275 /* Sign extend SRC starting from PREC. */ |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
276 |
111 | 277 static inline HOST_WIDE_INT |
278 sext_hwi (HOST_WIDE_INT src, unsigned int prec) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
279 { |
111 | 280 if (prec == HOST_BITS_PER_WIDE_INT) |
281 return src; | |
282 else | |
283 #if defined (__GNUC__) | |
284 { | |
285 /* Take the faster path if the implementation-defined bits it's relying | |
286 on are implemented the way we expect them to be. Namely, conversion | |
287 from unsigned to signed preserves bit pattern, and right shift of | |
288 a signed value propagates the sign bit. | |
289 We have to convert from signed to unsigned and back, because when left | |
290 shifting signed values, any overflow is undefined behavior. */ | |
291 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); | |
292 int shift = HOST_BITS_PER_WIDE_INT - prec; | |
293 return ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) src << shift)) >> shift; | |
294 } | |
295 #else | |
296 { | |
297 /* Fall back to the slower, well defined path otherwise. */ | |
298 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); | |
299 HOST_WIDE_INT sign_mask = HOST_WIDE_INT_1 << (prec - 1); | |
300 HOST_WIDE_INT value_mask = (HOST_WIDE_INT_1U << prec) - HOST_WIDE_INT_1U; | |
301 return (((src & value_mask) ^ sign_mask) - sign_mask); | |
302 } | |
303 #endif | |
304 } | |
305 | |
306 /* Zero extend SRC starting from PREC. */ | |
307 static inline unsigned HOST_WIDE_INT | |
308 zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) | |
309 { | |
310 if (prec == HOST_BITS_PER_WIDE_INT) | |
311 return src; | |
312 else | |
313 { | |
314 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); | |
315 return src & ((HOST_WIDE_INT_1U << prec) - 1); | |
316 } | |
317 } | |
318 | |
319 /* Compute the absolute value of X. */ | |
320 | |
321 inline HOST_WIDE_INT | |
322 abs_hwi (HOST_WIDE_INT x) | |
323 { | |
324 gcc_checking_assert (x != HOST_WIDE_INT_MIN); | |
325 return x >= 0 ? x : -x; | |
326 } | |
327 | |
328 /* Compute the absolute value of X as an unsigned type. */ | |
329 | |
330 inline unsigned HOST_WIDE_INT | |
331 absu_hwi (HOST_WIDE_INT x) | |
332 { | |
333 return x >= 0 ? (unsigned HOST_WIDE_INT)x : -(unsigned HOST_WIDE_INT)x; | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
334 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
335 |
0 | 336 #endif /* ! GCC_HWINT_H */ |