At the moment there are two copies of sext_hwi and zext_hwi, one inline for !ENABLE_CHECKING and one out-of-line for ENABLE_CHECKING. However, there are several wide-int callers where it's obvious from context that the precision is <= HOST_BITS_PER_WIDE_INT, so if the functions are inline for ENABLE_CHECKING, the assert can often be compiled away.
This improves the ENABLE_CHECKING code for some query functions on wide-int branch. Tested on x86_64-linux-gnu. OK for mainline? Thanks, Richard gcc/ * system.h: Move hwint.h include further down. * hwint.h (sext_hwi, zext_hwi): Define unconditionally. Add gcc_checking_asserts. * hwint.c (sext_hwi, zext_hwi): Delete ENABLE_CHECKING versions. Index: gcc/hwint.c =================================================================== --- gcc/hwint.c 2013-08-21 19:28:49.560621645 +0100 +++ gcc/hwint.c 2013-10-19 20:05:43.399978400 +0100 @@ -204,35 +204,3 @@ least_common_multiple (HOST_WIDE_INT a, { return mul_hwi (abs_hwi (a) / gcd (a, b), abs_hwi (b)); } - -#ifdef ENABLE_CHECKING -/* Sign extend SRC starting from PREC. */ - -HOST_WIDE_INT -sext_hwi (HOST_WIDE_INT src, unsigned int prec) -{ - gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT); - - if (prec == HOST_BITS_PER_WIDE_INT) - return src; - else - { - int shift = HOST_BITS_PER_WIDE_INT - prec; - return (src << shift) >> shift; - } -} - -/* Zero extend SRC starting from PREC. */ - -unsigned HOST_WIDE_INT -zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) -{ - gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT); - - if (prec == HOST_BITS_PER_WIDE_INT) - return src; - else - return src & (((HOST_WIDE_INT)1 << prec) - 1); -} - -#endif Index: gcc/hwint.h =================================================================== --- gcc/hwint.h 2013-09-05 20:55:31.192518091 +0100 +++ gcc/hwint.h 2013-10-19 20:05:23.469855942 +0100 @@ -322,9 +322,6 @@ extern HOST_WIDE_INT least_common_multip /* Sign extend SRC starting from PREC. */ -#ifdef ENABLE_CHECKING -extern HOST_WIDE_INT sext_hwi (HOST_WIDE_INT, unsigned int); -#else static inline HOST_WIDE_INT sext_hwi (HOST_WIDE_INT src, unsigned int prec) { @@ -332,24 +329,23 @@ sext_hwi (HOST_WIDE_INT src, unsigned in return src; else { + gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); int shift = HOST_BITS_PER_WIDE_INT - prec; return (src << shift) >> shift; } } -#endif /* Zero extend SRC starting from PREC. */ -#ifdef ENABLE_CHECKING -extern unsigned HOST_WIDE_INT zext_hwi (unsigned HOST_WIDE_INT, unsigned int); -#else static inline unsigned HOST_WIDE_INT zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) { if (prec == HOST_BITS_PER_WIDE_INT) return src; else - return src & (((HOST_WIDE_INT)1 << prec) - 1); + { + gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); + return src & (((HOST_WIDE_INT) 1 << prec) - 1); + } } -#endif #endif /* ! GCC_HWINT_H */ Index: gcc/system.h =================================================================== --- gcc/system.h 2013-09-07 10:19:22.797432289 +0100 +++ gcc/system.h 2013-10-19 20:06:14.417170260 +0100 @@ -272,9 +272,6 @@ #define ICE_EXIT_CODE 4 # include <limits.h> #endif -/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */ -#include "hwint.h" - /* A macro to determine whether a VALUE lies inclusively within a certain range without evaluating the VALUE more than once. This macro won't warn if the VALUE is unsigned and the LOWER bound is @@ -1066,4 +1063,7 @@ #define DEBUG_FUNCTION #define DEBUG_VARIABLE #endif +/* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT. */ +#include "hwint.h" + #endif /* ! GCC_SYSTEM_H */