annotate gcc/double-int.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 /* Operations with long integers.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2006-2020 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
3
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
5
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #ifndef DOUBLE_INT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #define DOUBLE_INT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 /* A large integer is currently represented as a pair of HOST_WIDE_INTs.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 It therefore represents a number with precision of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 2 * HOST_BITS_PER_WIDE_INT bits (it is however possible that the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 internal representation will change, if numbers with greater precision
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 are needed, so the users should not rely on it). The representation does
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 not contain any information about signedness of the represented value, so
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 it can be used to represent both signed and unsigned numbers. For
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 operations where the results depend on signedness (division, comparisons),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 it must be specified separately. For each such operation, there are three
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 versions of the function -- double_int_op, that takes an extra UNS argument
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 giving the signedness of the values, and double_int_sop and double_int_uop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 that stand for its specializations for signed and unsigned values.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 You may also represent with numbers in smaller precision using double_int.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 You however need to use double_int_ext (that fills in the bits of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 number over the prescribed precision with zeros or with the sign bit) before
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 operations that do not perform arithmetics modulo 2^precision (comparisons,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 division), and possibly before storing the results, if you want to keep
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 them in some canonical form). In general, the signedness of double_int_ext
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 should match the signedness of the operation.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ??? The components of double_int differ in signedness mostly for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 historical reasons (they replace an older structure used to represent
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 numbers with precision higher than HOST_WIDE_INT). It might be less
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 confusing to have them both signed or both unsigned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
111
kono
parents: 67
diff changeset
49 struct double_int
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {
111
kono
parents: 67
diff changeset
51 /* Normally, we would define constructors to create instances.
kono
parents: 67
diff changeset
52 Two things prevent us from doing so.
kono
parents: 67
diff changeset
53 First, defining a constructor makes the class non-POD in C++03,
kono
parents: 67
diff changeset
54 and we certainly want double_int to be a POD.
kono
parents: 67
diff changeset
55 Second, the GCC conding conventions prefer explicit conversion,
kono
parents: 67
diff changeset
56 and explicit conversion operators are not available until C++11. */
kono
parents: 67
diff changeset
57
kono
parents: 67
diff changeset
58 static double_int from_uhwi (unsigned HOST_WIDE_INT cst);
kono
parents: 67
diff changeset
59 static double_int from_shwi (HOST_WIDE_INT cst);
kono
parents: 67
diff changeset
60 static double_int from_pair (HOST_WIDE_INT high, unsigned HOST_WIDE_INT low);
kono
parents: 67
diff changeset
61
kono
parents: 67
diff changeset
62 /* Construct from a fuffer of length LEN. BUFFER will be read according
kono
parents: 67
diff changeset
63 to byte endianness and word endianness. */
kono
parents: 67
diff changeset
64 static double_int from_buffer (const unsigned char *buffer, int len);
kono
parents: 67
diff changeset
65
kono
parents: 67
diff changeset
66 /* No copy assignment operator or destructor to keep the type a POD. */
kono
parents: 67
diff changeset
67
kono
parents: 67
diff changeset
68 /* There are some special value-creation static member functions. */
kono
parents: 67
diff changeset
69
kono
parents: 67
diff changeset
70 static double_int mask (unsigned prec);
kono
parents: 67
diff changeset
71 static double_int max_value (unsigned int prec, bool uns);
kono
parents: 67
diff changeset
72 static double_int min_value (unsigned int prec, bool uns);
kono
parents: 67
diff changeset
73
kono
parents: 67
diff changeset
74 /* The following functions are mutating operations. */
kono
parents: 67
diff changeset
75
kono
parents: 67
diff changeset
76 double_int &operator ++ (); // prefix
kono
parents: 67
diff changeset
77 double_int &operator -- (); // prefix
kono
parents: 67
diff changeset
78 double_int &operator *= (double_int);
kono
parents: 67
diff changeset
79 double_int &operator += (double_int);
kono
parents: 67
diff changeset
80 double_int &operator -= (double_int);
kono
parents: 67
diff changeset
81 double_int &operator &= (double_int);
kono
parents: 67
diff changeset
82 double_int &operator ^= (double_int);
kono
parents: 67
diff changeset
83 double_int &operator |= (double_int);
kono
parents: 67
diff changeset
84
kono
parents: 67
diff changeset
85 /* The following functions are non-mutating operations. */
kono
parents: 67
diff changeset
86
kono
parents: 67
diff changeset
87 /* Conversion functions. */
kono
parents: 67
diff changeset
88
kono
parents: 67
diff changeset
89 HOST_WIDE_INT to_shwi () const;
kono
parents: 67
diff changeset
90 unsigned HOST_WIDE_INT to_uhwi () const;
kono
parents: 67
diff changeset
91
kono
parents: 67
diff changeset
92 /* Conversion query functions. */
kono
parents: 67
diff changeset
93
kono
parents: 67
diff changeset
94 bool fits_uhwi () const;
kono
parents: 67
diff changeset
95 bool fits_shwi () const;
kono
parents: 67
diff changeset
96 bool fits_hwi (bool uns) const;
kono
parents: 67
diff changeset
97
kono
parents: 67
diff changeset
98 /* Attribute query functions. */
kono
parents: 67
diff changeset
99
kono
parents: 67
diff changeset
100 int trailing_zeros () const;
kono
parents: 67
diff changeset
101 int popcount () const;
kono
parents: 67
diff changeset
102
kono
parents: 67
diff changeset
103 /* Arithmetic query operations. */
kono
parents: 67
diff changeset
104
kono
parents: 67
diff changeset
105 bool multiple_of (double_int, bool, double_int *) const;
kono
parents: 67
diff changeset
106
kono
parents: 67
diff changeset
107 /* Arithmetic operation functions. */
kono
parents: 67
diff changeset
108
kono
parents: 67
diff changeset
109 /* The following operations perform arithmetics modulo 2^precision, so you
kono
parents: 67
diff changeset
110 do not need to call .ext between them, even if you are representing
kono
parents: 67
diff changeset
111 numbers with precision less than HOST_BITS_PER_DOUBLE_INT bits. */
kono
parents: 67
diff changeset
112
kono
parents: 67
diff changeset
113 double_int set_bit (unsigned) const;
kono
parents: 67
diff changeset
114 double_int mul_with_sign (double_int, bool unsigned_p, bool *overflow) const;
kono
parents: 67
diff changeset
115 double_int wide_mul_with_sign (double_int, bool unsigned_p,
kono
parents: 67
diff changeset
116 double_int *higher, bool *overflow) const;
kono
parents: 67
diff changeset
117 double_int add_with_sign (double_int, bool unsigned_p, bool *overflow) const;
kono
parents: 67
diff changeset
118 double_int sub_with_overflow (double_int, bool *overflow) const;
kono
parents: 67
diff changeset
119 double_int neg_with_overflow (bool *overflow) const;
kono
parents: 67
diff changeset
120
kono
parents: 67
diff changeset
121 double_int operator * (double_int) const;
kono
parents: 67
diff changeset
122 double_int operator + (double_int) const;
kono
parents: 67
diff changeset
123 double_int operator - (double_int) const;
kono
parents: 67
diff changeset
124 double_int operator - () const;
kono
parents: 67
diff changeset
125 double_int operator ~ () const;
kono
parents: 67
diff changeset
126 double_int operator & (double_int) const;
kono
parents: 67
diff changeset
127 double_int operator | (double_int) const;
kono
parents: 67
diff changeset
128 double_int operator ^ (double_int) const;
kono
parents: 67
diff changeset
129 double_int and_not (double_int) const;
kono
parents: 67
diff changeset
130
kono
parents: 67
diff changeset
131 double_int lshift (HOST_WIDE_INT count) const;
kono
parents: 67
diff changeset
132 double_int lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
kono
parents: 67
diff changeset
133 double_int rshift (HOST_WIDE_INT count) const;
kono
parents: 67
diff changeset
134 double_int rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const;
kono
parents: 67
diff changeset
135 double_int alshift (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
136 double_int arshift (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
137 double_int llshift (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
138 double_int lrshift (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
139 double_int lrotate (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
140 double_int rrotate (HOST_WIDE_INT count, unsigned int prec) const;
kono
parents: 67
diff changeset
141
kono
parents: 67
diff changeset
142 /* You must ensure that double_int::ext is called on the operands
kono
parents: 67
diff changeset
143 of the following operations, if the precision of the numbers
kono
parents: 67
diff changeset
144 is less than HOST_BITS_PER_DOUBLE_INT bits. */
kono
parents: 67
diff changeset
145
kono
parents: 67
diff changeset
146 double_int div (double_int, bool, unsigned) const;
kono
parents: 67
diff changeset
147 double_int sdiv (double_int, unsigned) const;
kono
parents: 67
diff changeset
148 double_int udiv (double_int, unsigned) const;
kono
parents: 67
diff changeset
149 double_int mod (double_int, bool, unsigned) const;
kono
parents: 67
diff changeset
150 double_int smod (double_int, unsigned) const;
kono
parents: 67
diff changeset
151 double_int umod (double_int, unsigned) const;
kono
parents: 67
diff changeset
152 double_int divmod_with_overflow (double_int, bool, unsigned,
kono
parents: 67
diff changeset
153 double_int *, bool *) const;
kono
parents: 67
diff changeset
154 double_int divmod (double_int, bool, unsigned, double_int *) const;
kono
parents: 67
diff changeset
155 double_int sdivmod (double_int, unsigned, double_int *) const;
kono
parents: 67
diff changeset
156 double_int udivmod (double_int, unsigned, double_int *) const;
kono
parents: 67
diff changeset
157
kono
parents: 67
diff changeset
158 /* Precision control functions. */
kono
parents: 67
diff changeset
159
kono
parents: 67
diff changeset
160 double_int ext (unsigned prec, bool uns) const;
kono
parents: 67
diff changeset
161 double_int zext (unsigned prec) const;
kono
parents: 67
diff changeset
162 double_int sext (unsigned prec) const;
kono
parents: 67
diff changeset
163
kono
parents: 67
diff changeset
164 /* Comparative functions. */
kono
parents: 67
diff changeset
165
kono
parents: 67
diff changeset
166 bool is_zero () const;
kono
parents: 67
diff changeset
167 bool is_one () const;
kono
parents: 67
diff changeset
168 bool is_minus_one () const;
kono
parents: 67
diff changeset
169 bool is_negative () const;
kono
parents: 67
diff changeset
170
kono
parents: 67
diff changeset
171 int cmp (double_int b, bool uns) const;
kono
parents: 67
diff changeset
172 int ucmp (double_int b) const;
kono
parents: 67
diff changeset
173 int scmp (double_int b) const;
kono
parents: 67
diff changeset
174
kono
parents: 67
diff changeset
175 bool ult (double_int b) const;
kono
parents: 67
diff changeset
176 bool ule (double_int b) const;
kono
parents: 67
diff changeset
177 bool ugt (double_int b) const;
kono
parents: 67
diff changeset
178 bool slt (double_int b) const;
kono
parents: 67
diff changeset
179 bool sle (double_int b) const;
kono
parents: 67
diff changeset
180 bool sgt (double_int b) const;
kono
parents: 67
diff changeset
181
kono
parents: 67
diff changeset
182 double_int max (double_int b, bool uns);
kono
parents: 67
diff changeset
183 double_int smax (double_int b);
kono
parents: 67
diff changeset
184 double_int umax (double_int b);
kono
parents: 67
diff changeset
185
kono
parents: 67
diff changeset
186 double_int min (double_int b, bool uns);
kono
parents: 67
diff changeset
187 double_int smin (double_int b);
kono
parents: 67
diff changeset
188 double_int umin (double_int b);
kono
parents: 67
diff changeset
189
kono
parents: 67
diff changeset
190 bool operator == (double_int cst2) const;
kono
parents: 67
diff changeset
191 bool operator != (double_int cst2) const;
kono
parents: 67
diff changeset
192
kono
parents: 67
diff changeset
193 /* Please migrate away from using these member variables publicly. */
kono
parents: 67
diff changeset
194
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 unsigned HOST_WIDE_INT low;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 HOST_WIDE_INT high;
111
kono
parents: 67
diff changeset
197
kono
parents: 67
diff changeset
198 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
200 #define HOST_BITS_PER_DOUBLE_INT (2 * HOST_BITS_PER_WIDE_INT)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 /* Constructors and conversions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 /* Constructs double_int from integer CST. The bits over the precision of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 HOST_WIDE_INT are filled with the sign bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
111
kono
parents: 67
diff changeset
207 inline double_int
kono
parents: 67
diff changeset
208 double_int::from_shwi (HOST_WIDE_INT cst)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 double_int r;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 r.low = (unsigned HOST_WIDE_INT) cst;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 r.high = cst < 0 ? -1 : 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 return r;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 /* Some useful constants. */
111
kono
parents: 67
diff changeset
217 /* FIXME(crowl): Maybe remove after converting callers?
kono
parents: 67
diff changeset
218 The problem is that a named constant would not be as optimizable,
kono
parents: 67
diff changeset
219 while the functional syntax is more verbose. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
111
kono
parents: 67
diff changeset
221 #define double_int_minus_one (double_int::from_shwi (-1))
kono
parents: 67
diff changeset
222 #define double_int_zero (double_int::from_shwi (0))
kono
parents: 67
diff changeset
223 #define double_int_one (double_int::from_shwi (1))
kono
parents: 67
diff changeset
224 #define double_int_two (double_int::from_shwi (2))
kono
parents: 67
diff changeset
225 #define double_int_ten (double_int::from_shwi (10))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 /* Constructs double_int from unsigned integer CST. The bits over the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 precision of HOST_WIDE_INT are filled with zeros. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
111
kono
parents: 67
diff changeset
230 inline double_int
kono
parents: 67
diff changeset
231 double_int::from_uhwi (unsigned HOST_WIDE_INT cst)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 double_int r;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 r.low = cst;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 r.high = 0;
111
kono
parents: 67
diff changeset
236 return r;
kono
parents: 67
diff changeset
237 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
111
kono
parents: 67
diff changeset
239 inline double_int
kono
parents: 67
diff changeset
240 double_int::from_pair (HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
kono
parents: 67
diff changeset
241 {
kono
parents: 67
diff changeset
242 double_int r;
kono
parents: 67
diff changeset
243 r.low = low;
kono
parents: 67
diff changeset
244 r.high = high;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 return r;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
111
kono
parents: 67
diff changeset
248 inline double_int &
kono
parents: 67
diff changeset
249 double_int::operator ++ ()
kono
parents: 67
diff changeset
250 {
kono
parents: 67
diff changeset
251 *this += double_int_one;
kono
parents: 67
diff changeset
252 return *this;
kono
parents: 67
diff changeset
253 }
kono
parents: 67
diff changeset
254
kono
parents: 67
diff changeset
255 inline double_int &
kono
parents: 67
diff changeset
256 double_int::operator -- ()
kono
parents: 67
diff changeset
257 {
kono
parents: 67
diff changeset
258 *this -= double_int_one;
kono
parents: 67
diff changeset
259 return *this;
kono
parents: 67
diff changeset
260 }
kono
parents: 67
diff changeset
261
kono
parents: 67
diff changeset
262 inline double_int &
kono
parents: 67
diff changeset
263 double_int::operator &= (double_int b)
kono
parents: 67
diff changeset
264 {
kono
parents: 67
diff changeset
265 *this = *this & b;
kono
parents: 67
diff changeset
266 return *this;
kono
parents: 67
diff changeset
267 }
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
111
kono
parents: 67
diff changeset
269 inline double_int &
kono
parents: 67
diff changeset
270 double_int::operator ^= (double_int b)
kono
parents: 67
diff changeset
271 {
kono
parents: 67
diff changeset
272 *this = *this ^ b;
kono
parents: 67
diff changeset
273 return *this;
kono
parents: 67
diff changeset
274 }
kono
parents: 67
diff changeset
275
kono
parents: 67
diff changeset
276 inline double_int &
kono
parents: 67
diff changeset
277 double_int::operator |= (double_int b)
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
kono
parents: 67
diff changeset
279 *this = *this | b;
kono
parents: 67
diff changeset
280 return *this;
kono
parents: 67
diff changeset
281 }
kono
parents: 67
diff changeset
282
kono
parents: 67
diff changeset
283 /* Returns value of CST as a signed number. CST must satisfy
kono
parents: 67
diff changeset
284 double_int::fits_signed. */
kono
parents: 67
diff changeset
285
kono
parents: 67
diff changeset
286 inline HOST_WIDE_INT
kono
parents: 67
diff changeset
287 double_int::to_shwi () const
kono
parents: 67
diff changeset
288 {
kono
parents: 67
diff changeset
289 return (HOST_WIDE_INT) low;
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
290 }
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
291
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
292 /* Returns value of CST as an unsigned number. CST must satisfy
111
kono
parents: 67
diff changeset
293 double_int::fits_unsigned. */
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
294
111
kono
parents: 67
diff changeset
295 inline unsigned HOST_WIDE_INT
kono
parents: 67
diff changeset
296 double_int::to_uhwi () const
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
297 {
111
kono
parents: 67
diff changeset
298 return low;
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
299 }
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
300
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
301 /* Returns true if CST fits in 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
302
111
kono
parents: 67
diff changeset
303 inline bool
kono
parents: 67
diff changeset
304 double_int::fits_uhwi () const
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
305 {
111
kono
parents: 67
diff changeset
306 return high == 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
307 }
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
308
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
309 /* Logical operations. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
310
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
311 /* Returns ~A. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
312
111
kono
parents: 67
diff changeset
313 inline double_int
kono
parents: 67
diff changeset
314 double_int::operator ~ () const
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
315 {
111
kono
parents: 67
diff changeset
316 double_int result;
kono
parents: 67
diff changeset
317 result.low = ~low;
kono
parents: 67
diff changeset
318 result.high = ~high;
kono
parents: 67
diff changeset
319 return result;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
320 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
321
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
322 /* Returns A | B. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
323
111
kono
parents: 67
diff changeset
324 inline double_int
kono
parents: 67
diff changeset
325 double_int::operator | (double_int b) const
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
326 {
111
kono
parents: 67
diff changeset
327 double_int result;
kono
parents: 67
diff changeset
328 result.low = low | b.low;
kono
parents: 67
diff changeset
329 result.high = high | b.high;
kono
parents: 67
diff changeset
330 return result;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
331 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
332
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 /* Returns A & B. */
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
111
kono
parents: 67
diff changeset
335 inline double_int
kono
parents: 67
diff changeset
336 double_int::operator & (double_int b) const
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
337 {
111
kono
parents: 67
diff changeset
338 double_int result;
kono
parents: 67
diff changeset
339 result.low = low & b.low;
kono
parents: 67
diff changeset
340 result.high = high & b.high;
kono
parents: 67
diff changeset
341 return result;
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
342 }
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
343
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
344 /* Returns A & ~B. */
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
345
111
kono
parents: 67
diff changeset
346 inline double_int
kono
parents: 67
diff changeset
347 double_int::and_not (double_int b) const
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
348 {
111
kono
parents: 67
diff changeset
349 double_int result;
kono
parents: 67
diff changeset
350 result.low = low & ~b.low;
kono
parents: 67
diff changeset
351 result.high = high & ~b.high;
kono
parents: 67
diff changeset
352 return result;
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
353 }
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
354
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
355 /* Returns A ^ B. */
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
356
111
kono
parents: 67
diff changeset
357 inline double_int
kono
parents: 67
diff changeset
358 double_int::operator ^ (double_int b) const
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
359 {
111
kono
parents: 67
diff changeset
360 double_int result;
kono
parents: 67
diff changeset
361 result.low = low ^ b.low;
kono
parents: 67
diff changeset
362 result.high = high ^ b.high;
kono
parents: 67
diff changeset
363 return result;
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
364 }
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
365
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 void dump_double_int (FILE *, double_int, bool);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
111
kono
parents: 67
diff changeset
368 #define ALL_ONES HOST_WIDE_INT_M1U
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 /* The operands of the following comparison functions must be processed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 with double_int_ext, if their precision is less than
111
kono
parents: 67
diff changeset
372 HOST_BITS_PER_DOUBLE_INT bits. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 /* Returns true if CST is zero. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
111
kono
parents: 67
diff changeset
376 inline bool
kono
parents: 67
diff changeset
377 double_int::is_zero () const
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 {
111
kono
parents: 67
diff changeset
379 return low == 0 && high == 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 /* Returns true if CST is one. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383
111
kono
parents: 67
diff changeset
384 inline bool
kono
parents: 67
diff changeset
385 double_int::is_one () const
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 {
111
kono
parents: 67
diff changeset
387 return low == 1 && high == 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 /* Returns true if CST is minus one. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391
111
kono
parents: 67
diff changeset
392 inline bool
kono
parents: 67
diff changeset
393 double_int::is_minus_one () const
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 {
111
kono
parents: 67
diff changeset
395 return low == ALL_ONES && high == -1;
kono
parents: 67
diff changeset
396 }
kono
parents: 67
diff changeset
397
kono
parents: 67
diff changeset
398 /* Returns true if CST is negative. */
kono
parents: 67
diff changeset
399
kono
parents: 67
diff changeset
400 inline bool
kono
parents: 67
diff changeset
401 double_int::is_negative () const
kono
parents: 67
diff changeset
402 {
kono
parents: 67
diff changeset
403 return high < 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 /* Returns true if CST1 == CST2. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
111
kono
parents: 67
diff changeset
408 inline bool
kono
parents: 67
diff changeset
409 double_int::operator == (double_int cst2) const
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 {
111
kono
parents: 67
diff changeset
411 return low == cst2.low && high == cst2.high;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413
111
kono
parents: 67
diff changeset
414 /* Returns true if CST1 != CST2. */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
415
111
kono
parents: 67
diff changeset
416 inline bool
kono
parents: 67
diff changeset
417 double_int::operator != (double_int cst2) const
kono
parents: 67
diff changeset
418 {
kono
parents: 67
diff changeset
419 return low != cst2.low || high != cst2.high;
kono
parents: 67
diff changeset
420 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
421
111
kono
parents: 67
diff changeset
422 /* Return number of set bits of CST. */
kono
parents: 67
diff changeset
423
kono
parents: 67
diff changeset
424 inline int
kono
parents: 67
diff changeset
425 double_int::popcount () const
kono
parents: 67
diff changeset
426 {
kono
parents: 67
diff changeset
427 return popcount_hwi (high) + popcount_hwi (low);
kono
parents: 67
diff changeset
428 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
429
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
430
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 #ifndef GENERATOR_FILE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 /* Conversion to and from GMP integer representations. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 void mpz_set_double_int (mpz_t, double_int, bool);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 double_int mpz_get_double_int (const_tree, mpz_t, bool);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437
111
kono
parents: 67
diff changeset
438 namespace wi
kono
parents: 67
diff changeset
439 {
kono
parents: 67
diff changeset
440 template <>
kono
parents: 67
diff changeset
441 struct int_traits <double_int>
kono
parents: 67
diff changeset
442 {
kono
parents: 67
diff changeset
443 static const enum precision_type precision_type = CONST_PRECISION;
kono
parents: 67
diff changeset
444 static const bool host_dependent_precision = true;
kono
parents: 67
diff changeset
445 static const unsigned int precision = HOST_BITS_PER_DOUBLE_INT;
kono
parents: 67
diff changeset
446 static unsigned int get_precision (const double_int &);
kono
parents: 67
diff changeset
447 static wi::storage_ref decompose (HOST_WIDE_INT *, unsigned int,
kono
parents: 67
diff changeset
448 const double_int &);
kono
parents: 67
diff changeset
449 };
kono
parents: 67
diff changeset
450 }
kono
parents: 67
diff changeset
451
kono
parents: 67
diff changeset
452 inline unsigned int
kono
parents: 67
diff changeset
453 wi::int_traits <double_int>::get_precision (const double_int &)
kono
parents: 67
diff changeset
454 {
kono
parents: 67
diff changeset
455 return precision;
kono
parents: 67
diff changeset
456 }
kono
parents: 67
diff changeset
457
kono
parents: 67
diff changeset
458 inline wi::storage_ref
kono
parents: 67
diff changeset
459 wi::int_traits <double_int>::decompose (HOST_WIDE_INT *scratch, unsigned int p,
kono
parents: 67
diff changeset
460 const double_int &x)
kono
parents: 67
diff changeset
461 {
kono
parents: 67
diff changeset
462 gcc_checking_assert (precision == p);
kono
parents: 67
diff changeset
463 scratch[0] = x.low;
kono
parents: 67
diff changeset
464 if ((x.high == 0 && scratch[0] >= 0) || (x.high == -1 && scratch[0] < 0))
kono
parents: 67
diff changeset
465 return wi::storage_ref (scratch, 1, precision);
kono
parents: 67
diff changeset
466 scratch[1] = x.high;
kono
parents: 67
diff changeset
467 return wi::storage_ref (scratch, 2, precision);
kono
parents: 67
diff changeset
468 }
kono
parents: 67
diff changeset
469
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 #endif /* DOUBLE_INT_H */