summaryrefslogtreecommitdiff
path: root/gcc/double-int.h
diff options
context:
space:
mode:
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-07 09:23:32 +0000
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-07 09:23:32 +0000
commit796b6678b7a5be26e44d64a3b299ac5a8f0877e2 (patch)
tree4e81b82b3b3a04b8f3a48aa7c3dc3d336f8a185c /gcc/double-int.h
parente02d19d4264184dbf4aec0a7f1a31db9a6471ff4 (diff)
downloadgcc-796b6678b7a5be26e44d64a3b299ac5a8f0877e2.tar.gz
Reorganise wide-int classes so that they are all instantiations of a
generic_wide_int class, parameterised by storage. Move all real work outside the main wide_int classes into separate functions. Add a wi:: namespace. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/wide-int@202354 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/double-int.h')
-rw-r--r--gcc/double-int.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/double-int.h b/gcc/double-int.h
index 650520ba052..50ca182b83c 100644
--- a/gcc/double-int.h
+++ b/gcc/double-int.h
@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see
#ifndef DOUBLE_INT_H
#define DOUBLE_INT_H
+#include "wide-int.h"
+
/* A large integer is currently represented as a pair of HOST_WIDE_INTs.
It therefore represents a number with precision of
2 * HOST_BITS_PER_WIDE_INT bits (it is however possible that the
@@ -435,4 +437,36 @@ void mpz_set_double_int (mpz_t, double_int, bool);
double_int mpz_get_double_int (const_tree, mpz_t, bool);
#endif
+namespace wi
+{
+ template <>
+ struct int_traits <double_int>
+ {
+ static const enum precision_type precision_type = CONST_PRECISION;
+ static const bool host_dependent_precision = true;
+ static const unsigned int precision = HOST_BITS_PER_DOUBLE_INT;
+ static unsigned int get_precision (const double_int &);
+ static wi::storage_ref decompose (HOST_WIDE_INT *, unsigned int,
+ const double_int &);
+ };
+}
+
+inline unsigned int
+wi::int_traits <double_int>::get_precision (const double_int &)
+{
+ return precision;
+}
+
+inline wi::storage_ref
+wi::int_traits <double_int>::decompose (HOST_WIDE_INT *scratch, unsigned int p,
+ const double_int &x)
+{
+ gcc_checking_assert (precision == p);
+ scratch[0] = x.low;
+ if ((x.high == 0 && scratch[0] >= 0) || (x.high == -1 && scratch[0] < 0))
+ return wi::storage_ref (scratch, 1, precision);
+ scratch[1] = x.high;
+ return wi::storage_ref (scratch, 2, precision);
+}
+
#endif /* DOUBLE_INT_H */