compare-fp-4.x: Add an XFAIL for ARM VxWorks kernels.
[official-gcc.git] / gcc / double-int.h
blob33641bd06dc366e3fe97bc778f9e47391f3eb12a
1 /* Operations with long integers.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #ifndef DOUBLE_INT_H
22 #define DOUBLE_INT_H
24 #include <gmp.h>
25 #include "coretypes.h"
27 /* A large integer is currently represented as a pair of HOST_WIDE_INTs.
28 It therefore represents a number with precision of
29 2 * HOST_BITS_PER_WIDE_INT bits (it is however possible that the
30 internal representation will change, if numbers with greater precision
31 are needed, so the users should not rely on it). The representation does
32 not contain any information about signedness of the represented value, so
33 it can be used to represent both signed and unsigned numbers. For
34 operations where the results depend on signedness (division, comparisons),
35 it must be specified separately. For each such operation, there are three
36 versions of the function -- double_int_op, that takes an extra UNS argument
37 giving the signedness of the values, and double_int_sop and double_int_uop
38 that stand for its specializations for signed and unsigned values.
40 You may also represent with numbers in smaller precision using double_int.
41 You however need to use double_int_ext (that fills in the bits of the
42 number over the prescribed precision with zeros or with the sign bit) before
43 operations that do not perform arithmetics modulo 2^precision (comparisons,
44 division), and possibly before storing the results, if you want to keep
45 them in some canonical form). In general, the signedness of double_int_ext
46 should match the signedness of the operation.
48 ??? The components of double_int differ in signedness mostly for
49 historical reasons (they replace an older structure used to represent
50 numbers with precision higher than HOST_WIDE_INT). It might be less
51 confusing to have them both signed or both unsigned. */
53 typedef struct
55 unsigned HOST_WIDE_INT low;
56 HOST_WIDE_INT high;
57 } double_int;
59 union tree_node;
61 /* Constructors and conversions. */
63 union tree_node *double_int_to_tree (union tree_node *, double_int);
64 bool double_int_fits_to_tree_p (union tree_node *, double_int);
65 double_int tree_to_double_int (union tree_node *);
67 /* Constructs double_int from integer CST. The bits over the precision of
68 HOST_WIDE_INT are filled with the sign bit. */
70 static inline double_int
71 shwi_to_double_int (HOST_WIDE_INT cst)
73 double_int r;
75 r.low = (unsigned HOST_WIDE_INT) cst;
76 r.high = cst < 0 ? -1 : 0;
78 return r;
81 /* Some useful constants. */
83 #define double_int_minus_one (shwi_to_double_int (-1))
84 #define double_int_zero (shwi_to_double_int (0))
85 #define double_int_one (shwi_to_double_int (1))
86 #define double_int_two (shwi_to_double_int (2))
87 #define double_int_ten (shwi_to_double_int (10))
89 /* Constructs double_int from unsigned integer CST. The bits over the
90 precision of HOST_WIDE_INT are filled with zeros. */
92 static inline double_int
93 uhwi_to_double_int (unsigned HOST_WIDE_INT cst)
95 double_int r;
97 r.low = cst;
98 r.high = 0;
100 return r;
103 /* The following operations perform arithmetics modulo 2^precision,
104 so you do not need to call double_int_ext between them, even if
105 you are representing numbers with precision less than
106 2 * HOST_BITS_PER_WIDE_INT bits. */
108 double_int double_int_mul (double_int, double_int);
109 double_int double_int_add (double_int, double_int);
110 double_int double_int_neg (double_int);
112 /* You must ensure that double_int_ext is called on the operands
113 of the following operations, if the precision of the numbers
114 is less than 2 * HOST_BITS_PER_WIDE_INT bits. */
115 bool double_int_fits_in_hwi_p (double_int, bool);
116 bool double_int_fits_in_shwi_p (double_int);
117 bool double_int_fits_in_uhwi_p (double_int);
118 HOST_WIDE_INT double_int_to_shwi (double_int);
119 unsigned HOST_WIDE_INT double_int_to_uhwi (double_int);
120 double_int double_int_div (double_int, double_int, bool, unsigned);
121 double_int double_int_sdiv (double_int, double_int, unsigned);
122 double_int double_int_udiv (double_int, double_int, unsigned);
123 double_int double_int_mod (double_int, double_int, bool, unsigned);
124 double_int double_int_smod (double_int, double_int, unsigned);
125 double_int double_int_umod (double_int, double_int, unsigned);
126 double_int double_int_divmod (double_int, double_int, bool, unsigned, double_int *);
127 double_int double_int_sdivmod (double_int, double_int, unsigned, double_int *);
128 double_int double_int_udivmod (double_int, double_int, unsigned, double_int *);
129 bool double_int_negative_p (double_int);
130 int double_int_cmp (double_int, double_int, bool);
131 int double_int_scmp (double_int, double_int);
132 int double_int_ucmp (double_int, double_int);
133 void dump_double_int (FILE *, double_int, bool);
135 /* Zero and sign extension of numbers in smaller precisions. */
137 double_int double_int_ext (double_int, unsigned, bool);
138 double_int double_int_sext (double_int, unsigned);
139 double_int double_int_zext (double_int, unsigned);
140 double_int double_int_mask (unsigned);
142 #define ALL_ONES (~((unsigned HOST_WIDE_INT) 0))
144 /* The operands of the following comparison functions must be processed
145 with double_int_ext, if their precision is less than
146 2 * HOST_BITS_PER_WIDE_INT bits. */
148 /* Returns true if CST is zero. */
150 static inline bool
151 double_int_zero_p (double_int cst)
153 return cst.low == 0 && cst.high == 0;
156 /* Returns true if CST is one. */
158 static inline bool
159 double_int_one_p (double_int cst)
161 return cst.low == 1 && cst.high == 0;
164 /* Returns true if CST is minus one. */
166 static inline bool
167 double_int_minus_one_p (double_int cst)
169 return (cst.low == ALL_ONES && cst.high == -1);
172 /* Returns true if CST1 == CST2. */
174 static inline bool
175 double_int_equal_p (double_int cst1, double_int cst2)
177 return cst1.low == cst2.low && cst1.high == cst2.high;
180 /* Conversion to and from GMP integer representations. */
182 void mpz_set_double_int (mpz_t, double_int, bool);
183 double_int mpz_get_double_int (tree, mpz_t, bool);
186 #endif /* DOUBLE_INT_H */