aboutsummaryrefslogtreecommitdiff
path: root/gcc/wide-int.h
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2023-02-10 12:52:24 +0100
committerAldy Hernandez <aldyh@redhat.com>2023-04-18 09:43:49 +0200
commit5baf2cccd0345a7ac3d4467343414f8b7ff1724b (patch)
tree048b9af6b6c3f5e92f9b7c19d223b99b35b6dee1 /gcc/wide-int.h
parent603fc926fee69ab3c7169af8a9c0918611a75d92 (diff)
downloadgcc-5baf2cccd0345a7ac3d4467343414f8b7ff1724b.zip
gcc-5baf2cccd0345a7ac3d4467343414f8b7ff1724b.tar.gz
gcc-5baf2cccd0345a7ac3d4467343414f8b7ff1724b.tar.bz2
Abstract out calculation of max HWIs per wide int.
I'm about to add one more use of the same snippet of code, for a total of 4 identical calculations in the code base. gcc/ChangeLog: * wide-int.h (WIDE_INT_MAX_HWIS): New. (class fixed_wide_int_storage): Use it. (trailing_wide_ints <N>::set_precision): Use it. (trailing_wide_ints <N>::extra_size): Use it.
Diffstat (limited to 'gcc/wide-int.h')
-rw-r--r--gcc/wide-int.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/wide-int.h b/gcc/wide-int.h
index a450a74..6be343c 100644
--- a/gcc/wide-int.h
+++ b/gcc/wide-int.h
@@ -264,6 +264,10 @@ along with GCC; see the file COPYING3. If not see
/* The number of HWIs needed to store an offset_int. */
#define OFFSET_INT_ELTS (ADDR_MAX_PRECISION / HOST_BITS_PER_WIDE_INT)
+/* The max number of HWIs needed to store a wide_int of PRECISION. */
+#define WIDE_INT_MAX_HWIS(PRECISION) \
+ ((PRECISION + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
+
/* The type of result produced by a binary operation on types T1 and T2.
Defined purely for brevity. */
#define WI_BINARY_RESULT(T1, T2) \
@@ -1214,7 +1218,7 @@ template <int N>
class GTY(()) fixed_wide_int_storage
{
private:
- HOST_WIDE_INT val[(N + HOST_BITS_PER_WIDE_INT + 1) / HOST_BITS_PER_WIDE_INT];
+ HOST_WIDE_INT val[WIDE_INT_MAX_HWIS (N)];
unsigned int len;
public:
@@ -1475,8 +1479,7 @@ trailing_wide_ints <N>::set_precision (unsigned int precision,
gcc_checking_assert (num_elements <= N);
m_num_elements = num_elements;
m_precision = precision;
- m_max_len = ((precision + HOST_BITS_PER_WIDE_INT - 1)
- / HOST_BITS_PER_WIDE_INT);
+ m_max_len = WIDE_INT_MAX_HWIS (precision);
}
/* Return a reference to element INDEX. */
@@ -1505,8 +1508,7 @@ inline size_t
trailing_wide_ints <N>::extra_size (unsigned int precision,
unsigned int num_elements)
{
- unsigned int max_len = ((precision + HOST_BITS_PER_WIDE_INT - 1)
- / HOST_BITS_PER_WIDE_INT);
+ unsigned int max_len = WIDE_INT_MAX_HWIS (precision);
gcc_checking_assert (num_elements <= N);
return (num_elements * max_len - 1) * sizeof (HOST_WIDE_INT);
}