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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* HOST_WIDE_INT definitions for the GNU compiler.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1998-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Provide definitions for macros which depend on HOST_BITS_PER_INT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 and HOST_BITS_PER_LONG. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #ifndef GCC_HWINT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define GCC_HWINT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 /* This describes the machine the compiler is hosted on. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #define HOST_BITS_PER_CHAR CHAR_BIT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #define HOST_BITS_PER_INT (CHAR_BIT * SIZEOF_INT)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #define HOST_BITS_PER_LONG (CHAR_BIT * SIZEOF_LONG)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
17 #define HOST_BITS_PER_PTR (CHAR_BIT * SIZEOF_VOID_P)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #define HOST_LONG_LONG_FORMAT "ll"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 /* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 GCC_VERSION >= 3000, assume this is the second or later stage of a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 bootstrap, we do have long long, and it's 64 bits. (This is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 required by C99; we do have some ports that violate that assumption
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 but they're all cross-compile-only.) Just in case, force a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 constraint violation if that assumption is incorrect. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #if !defined HAVE_LONG_LONG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 # if GCC_VERSION >= 3000
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 # define HAVE_LONG_LONG 1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 # define SIZEOF_LONG_LONG 8
111
kono
parents: 67
diff changeset
41 extern char sizeof_long_long_must_be_8[sizeof (long long) == 8 ? 1 : -1];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 #ifdef HAVE_LONG_LONG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 # define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 #endif
111
kono
parents: 67
diff changeset
48
kono
parents: 67
diff changeset
49 /* Set HOST_WIDE_INT, this should be always 64 bits.
kono
parents: 67
diff changeset
50 The underlying type is matched to that of int64_t and assumed
kono
parents: 67
diff changeset
51 to be either long or long long. */
kono
parents: 67
diff changeset
52
kono
parents: 67
diff changeset
53 #define HOST_BITS_PER_WIDE_INT 64
kono
parents: 67
diff changeset
54 #if INT64_T_IS_LONG
kono
parents: 67
diff changeset
55 # define HOST_WIDE_INT long
kono
parents: 67
diff changeset
56 # define HOST_WIDE_INT_C(X) X ## L
kono
parents: 67
diff changeset
57 #else
kono
parents: 67
diff changeset
58 # if HOST_BITS_PER_LONGLONG == 64
kono
parents: 67
diff changeset
59 # define HOST_WIDE_INT long long
kono
parents: 67
diff changeset
60 # define HOST_WIDE_INT_C(X) X ## LL
kono
parents: 67
diff changeset
61 # else
kono
parents: 67
diff changeset
62 #error "Unable to find a suitable type for HOST_WIDE_INT"
kono
parents: 67
diff changeset
63 # endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
111
kono
parents: 67
diff changeset
66 #define HOST_WIDE_INT_UC(X) HOST_WIDE_INT_C (X ## U)
kono
parents: 67
diff changeset
67 #define HOST_WIDE_INT_0 HOST_WIDE_INT_C (0)
kono
parents: 67
diff changeset
68 #define HOST_WIDE_INT_0U HOST_WIDE_INT_UC (0)
kono
parents: 67
diff changeset
69 #define HOST_WIDE_INT_1 HOST_WIDE_INT_C (1)
kono
parents: 67
diff changeset
70 #define HOST_WIDE_INT_1U HOST_WIDE_INT_UC (1)
kono
parents: 67
diff changeset
71 #define HOST_WIDE_INT_M1 HOST_WIDE_INT_C (-1)
kono
parents: 67
diff changeset
72 #define HOST_WIDE_INT_M1U HOST_WIDE_INT_UC (-1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
111
kono
parents: 67
diff changeset
74 /* This is a magic identifier which allows GCC to figure out the type
kono
parents: 67
diff changeset
75 of HOST_WIDE_INT for %wd specifier checks. You must issue this
kono
parents: 67
diff changeset
76 typedef before using the __asm_fprintf__ format attribute. */
kono
parents: 67
diff changeset
77 typedef HOST_WIDE_INT __gcc_host_wide_int__;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
111
kono
parents: 67
diff changeset
79 /* Provide C99 <inttypes.h> style format definitions for 64bits. */
kono
parents: 67
diff changeset
80 #ifndef HAVE_INTTYPES_H
kono
parents: 67
diff changeset
81 #if INT64_T_IS_LONG
kono
parents: 67
diff changeset
82 # define GCC_PRI64 HOST_LONG_FORMAT
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 #else
111
kono
parents: 67
diff changeset
84 # define GCC_PRI64 HOST_LONG_LONG_FORMAT
kono
parents: 67
diff changeset
85 #endif
kono
parents: 67
diff changeset
86 #undef PRId64
kono
parents: 67
diff changeset
87 #define PRId64 GCC_PRI64 "d"
kono
parents: 67
diff changeset
88 #undef PRIi64
kono
parents: 67
diff changeset
89 #define PRIi64 GCC_PRI64 "i"
kono
parents: 67
diff changeset
90 #undef PRIo64
kono
parents: 67
diff changeset
91 #define PRIo64 GCC_PRI64 "o"
kono
parents: 67
diff changeset
92 #undef PRIu64
kono
parents: 67
diff changeset
93 #define PRIu64 GCC_PRI64 "u"
kono
parents: 67
diff changeset
94 #undef PRIx64
kono
parents: 67
diff changeset
95 #define PRIx64 GCC_PRI64 "x"
kono
parents: 67
diff changeset
96 #undef PRIX64
kono
parents: 67
diff changeset
97 #define PRIX64 GCC_PRI64 "X"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 /* Various printf format strings for HOST_WIDE_INT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
111
kono
parents: 67
diff changeset
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 # define HOST_WIDE_INT_PRINT_C "L"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 # define HOST_WIDE_INT_PRINT HOST_LONG_LONG_FORMAT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 # define HOST_WIDE_INT_PRINT_C "LL"
111
kono
parents: 67
diff changeset
108 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
111
kono
parents: 67
diff changeset
110 #define HOST_WIDE_INT_PRINT_DEC "%" PRId64
kono
parents: 67
diff changeset
111 #define HOST_WIDE_INT_PRINT_DEC_C "%" PRId64 HOST_WIDE_INT_PRINT_C
kono
parents: 67
diff changeset
112 #define HOST_WIDE_INT_PRINT_UNSIGNED "%" PRIu64
kono
parents: 67
diff changeset
113 #define HOST_WIDE_INT_PRINT_HEX "%#" PRIx64
kono
parents: 67
diff changeset
114 #define HOST_WIDE_INT_PRINT_HEX_PURE "%" PRIx64
kono
parents: 67
diff changeset
115 #define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%" PRIx64 "%016" PRIx64
kono
parents: 67
diff changeset
116 #define HOST_WIDE_INT_PRINT_PADDED_HEX "%016" PRIx64
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 /* Define HOST_WIDEST_FAST_INT to the widest integer type supported
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 efficiently in hardware. (That is, the widest integer type that fits
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 in a hardware register.) Normally this is "long" but on some hosts it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 should be "long long" or "__int64". This is no convenient way to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 autodetect this, so such systems must set a flag in config.host; see there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 for details. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 #ifdef USE_LONG_LONG_FOR_WIDEST_FAST_INT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 # ifdef HAVE_LONG_LONG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 # define HOST_WIDEST_FAST_INT long long
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 # define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONGLONG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 # else
111
kono
parents: 67
diff changeset
130 # error "Your host said it wanted to use long long but that does not exist"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 # define HOST_WIDEST_FAST_INT long
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 # define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
kono
parents: 67
diff changeset
138
kono
parents: 67
diff changeset
139 /* Return X with all but the lowest bit masked off. */
kono
parents: 67
diff changeset
140
kono
parents: 67
diff changeset
141 static inline unsigned HOST_WIDE_INT
kono
parents: 67
diff changeset
142 least_bit_hwi (unsigned HOST_WIDE_INT x)
kono
parents: 67
diff changeset
143 {
kono
parents: 67
diff changeset
144 return (x & -x);
kono
parents: 67
diff changeset
145 }
kono
parents: 67
diff changeset
146
kono
parents: 67
diff changeset
147 /* True if X is zero or a power of two. */
kono
parents: 67
diff changeset
148
kono
parents: 67
diff changeset
149 static inline bool
kono
parents: 67
diff changeset
150 pow2_or_zerop (unsigned HOST_WIDE_INT x)
kono
parents: 67
diff changeset
151 {
kono
parents: 67
diff changeset
152 return least_bit_hwi (x) == x;
kono
parents: 67
diff changeset
153 }
kono
parents: 67
diff changeset
154
kono
parents: 67
diff changeset
155 /* True if X is a power of two. */
kono
parents: 67
diff changeset
156
kono
parents: 67
diff changeset
157 static inline bool
kono
parents: 67
diff changeset
158 pow2p_hwi (unsigned HOST_WIDE_INT x)
kono
parents: 67
diff changeset
159 {
kono
parents: 67
diff changeset
160 return x && pow2_or_zerop (x);
kono
parents: 67
diff changeset
161 }
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
169 /* Return the number of set bits in X. */
kono
parents: 67
diff changeset
170 extern int popcount_hwi (unsigned HOST_WIDE_INT x);
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
178 /* Return the smallest n such that 2**n >= X. */
kono
parents: 67
diff changeset
179 extern int ceil_log2 (unsigned HOST_WIDE_INT);
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
225 popcount_hwi (unsigned HOST_WIDE_INT x)
kono
parents: 67
diff changeset
226 {
kono
parents: 67
diff changeset
227 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
kono
parents: 67
diff changeset
228 return __builtin_popcountl (x);
kono
parents: 67
diff changeset
229 # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
kono
parents: 67
diff changeset
230 return __builtin_popcountll (x);
kono
parents: 67
diff changeset
231 # else
kono
parents: 67
diff changeset
232 return __builtin_popcount (x);
kono
parents: 67
diff changeset
233 # endif
kono
parents: 67
diff changeset
234 }
kono
parents: 67
diff changeset
235
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
243 ceil_log2 (unsigned HOST_WIDE_INT x)
kono
parents: 67
diff changeset
244 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
245 return x == 0 ? 0 : floor_log2 (x - 1) + 1;
111
kono
parents: 67
diff changeset
246 }
kono
parents: 67
diff changeset
247
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
256 #define HOST_WIDE_INT_MIN (HOST_WIDE_INT) \
kono
parents: 67
diff changeset
257 (HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1))
kono
parents: 67
diff changeset
258 #define HOST_WIDE_INT_MAX (~(HOST_WIDE_INT_MIN))
kono
parents: 67
diff changeset
259
kono
parents: 67
diff changeset
260 extern HOST_WIDE_INT abs_hwi (HOST_WIDE_INT);
kono
parents: 67
diff changeset
261 extern unsigned HOST_WIDE_INT absu_hwi (HOST_WIDE_INT);
kono
parents: 67
diff changeset
262 extern HOST_WIDE_INT gcd (HOST_WIDE_INT, HOST_WIDE_INT);
kono
parents: 67
diff changeset
263 extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
kono
parents: 67
diff changeset
264 extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
kono
parents: 67
diff changeset
265 extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT);
kono
parents: 67
diff changeset
266
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
277 static inline HOST_WIDE_INT
kono
parents: 67
diff changeset
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
kono
parents: 67
diff changeset
280 if (prec == HOST_BITS_PER_WIDE_INT)
kono
parents: 67
diff changeset
281 return src;
kono
parents: 67
diff changeset
282 else
kono
parents: 67
diff changeset
283 #if defined (__GNUC__)
kono
parents: 67
diff changeset
284 {
kono
parents: 67
diff changeset
285 /* Take the faster path if the implementation-defined bits it's relying
kono
parents: 67
diff changeset
286 on are implemented the way we expect them to be. Namely, conversion
kono
parents: 67
diff changeset
287 from unsigned to signed preserves bit pattern, and right shift of
kono
parents: 67
diff changeset
288 a signed value propagates the sign bit.
kono
parents: 67
diff changeset
289 We have to convert from signed to unsigned and back, because when left
kono
parents: 67
diff changeset
290 shifting signed values, any overflow is undefined behavior. */
kono
parents: 67
diff changeset
291 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
kono
parents: 67
diff changeset
292 int shift = HOST_BITS_PER_WIDE_INT - prec;
kono
parents: 67
diff changeset
293 return ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) src << shift)) >> shift;
kono
parents: 67
diff changeset
294 }
kono
parents: 67
diff changeset
295 #else
kono
parents: 67
diff changeset
296 {
kono
parents: 67
diff changeset
297 /* Fall back to the slower, well defined path otherwise. */
kono
parents: 67
diff changeset
298 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
kono
parents: 67
diff changeset
299 HOST_WIDE_INT sign_mask = HOST_WIDE_INT_1 << (prec - 1);
kono
parents: 67
diff changeset
300 HOST_WIDE_INT value_mask = (HOST_WIDE_INT_1U << prec) - HOST_WIDE_INT_1U;
kono
parents: 67
diff changeset
301 return (((src & value_mask) ^ sign_mask) - sign_mask);
kono
parents: 67
diff changeset
302 }
kono
parents: 67
diff changeset
303 #endif
kono
parents: 67
diff changeset
304 }
kono
parents: 67
diff changeset
305
kono
parents: 67
diff changeset
306 /* Zero extend SRC starting from PREC. */
kono
parents: 67
diff changeset
307 static inline unsigned HOST_WIDE_INT
kono
parents: 67
diff changeset
308 zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec)
kono
parents: 67
diff changeset
309 {
kono
parents: 67
diff changeset
310 if (prec == HOST_BITS_PER_WIDE_INT)
kono
parents: 67
diff changeset
311 return src;
kono
parents: 67
diff changeset
312 else
kono
parents: 67
diff changeset
313 {
kono
parents: 67
diff changeset
314 gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
kono
parents: 67
diff changeset
315 return src & ((HOST_WIDE_INT_1U << prec) - 1);
kono
parents: 67
diff changeset
316 }
kono
parents: 67
diff changeset
317 }
kono
parents: 67
diff changeset
318
kono
parents: 67
diff changeset
319 /* Compute the absolute value of X. */
kono
parents: 67
diff changeset
320
kono
parents: 67
diff changeset
321 inline HOST_WIDE_INT
kono
parents: 67
diff changeset
322 abs_hwi (HOST_WIDE_INT x)
kono
parents: 67
diff changeset
323 {
kono
parents: 67
diff changeset
324 gcc_checking_assert (x != HOST_WIDE_INT_MIN);
kono
parents: 67
diff changeset
325 return x >= 0 ? x : -x;
kono
parents: 67
diff changeset
326 }
kono
parents: 67
diff changeset
327
kono
parents: 67
diff changeset
328 /* Compute the absolute value of X as an unsigned type. */
kono
parents: 67
diff changeset
329
kono
parents: 67
diff changeset
330 inline unsigned HOST_WIDE_INT
kono
parents: 67
diff changeset
331 absu_hwi (HOST_WIDE_INT x)
kono
parents: 67
diff changeset
332 {
kono
parents: 67
diff changeset
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 #endif /* ! GCC_HWINT_H */