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