This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[wide-int 3/8] Add and use udiv_ceil
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: zadeck at naturalbridge dot com, mikestump at comcast dot net
- Date: Tue, 22 Apr 2014 20:51:46 +0100
- Subject: [wide-int 3/8] Add and use udiv_ceil
- Authentication-results: sourceware.org; auth=none
Just a minor tweak to avoid several calculations when one would do.
Since we have a function for rounded-up division, we might as well
use it instead of the (X + Y - 1) / Y idiom.
Tested on x86_64-linux-gnu. OK to install?
Thanks,
Richard
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c 2014-04-22 20:31:25.187000808 +0100
+++ gcc/dwarf2out.c 2014-04-22 20:31:26.374009366 +0100
@@ -14824,7 +14824,7 @@ simple_decl_align_in_bits (const_tree de
static inline offset_int
round_up_to_align (const offset_int &t, unsigned int align)
{
- return wi::udiv_trunc (t + align - 1, align) * align;
+ return wi::udiv_ceil (t, align) * align;
}
/* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
Index: gcc/wide-int.h
===================================================================
--- gcc/wide-int.h 2014-04-22 20:31:25.842005530 +0100
+++ gcc/wide-int.h 2014-04-22 20:31:26.375009373 +0100
@@ -521,6 +521,7 @@ #define SHIFT_FUNCTION \
BINARY_FUNCTION udiv_floor (const T1 &, const T2 &);
BINARY_FUNCTION sdiv_floor (const T1 &, const T2 &);
BINARY_FUNCTION div_ceil (const T1 &, const T2 &, signop, bool * = 0);
+ BINARY_FUNCTION udiv_ceil (const T1 &, const T2 &);
BINARY_FUNCTION div_round (const T1 &, const T2 &, signop, bool * = 0);
BINARY_FUNCTION divmod_trunc (const T1 &, const T2 &, signop,
WI_BINARY_RESULT (T1, T2) *);
@@ -2566,6 +2567,13 @@ wi::div_ceil (const T1 &x, const T2 &y,
return quotient;
}
+template <typename T1, typename T2>
+inline WI_BINARY_RESULT (T1, T2)
+wi::udiv_ceil (const T1 &x, const T2 &y)
+{
+ return div_ceil (x, y, UNSIGNED);
+}
+
/* Return X / Y, rouding towards nearest with ties away from zero.
Treat X and Y as having the signedness given by SGN. Indicate
in *OVERFLOW if the result overflows. */