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