[PATCH] hwint: Simplify sext_hwi.
Kael Andrew Franco <[email protected]> Sun, 2 Aug 2026 07:46:40 -0400
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <CACAb0qcOtSNb-q8V=Uf+6HDHyRdMfoPns4U0dhZyMPyEEyFVhQ@mail.gmail.com> |
From 6bc1a3044e6fe1803c27b185d9e08e48ab995f04 Mon Sep 17 00:00:00 2001 From: Kael Andrew Alonzo Franco <[email protected]> Date: Sat, 1 Aug 2026 16:30:49 -0400 Subject: [PATCH] hwint: Simplify sext_hwi. This combines duplicated C++ code so any C++ compiler compiles this header file faster. Bootstrapped and tested on x86_64-pc-linux-gnu. gcc/ChangeLog: * hwint.h (sext_hwi): Combine duplicated C++ code. Signed-off-by: Kael Andrew Franco <[email protected]> --- gcc/hwint.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gcc/hwint.h b/gcc/hwint.h index dfe646cf980..454ee0efdcb 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -302,27 +302,24 @@ sext_hwi (HOST_WIDE_INT src, unsigned int prec) if (prec == HOST_BITS_PER_WIDE_INT) return src; else -#if defined (__GNUC__) { + gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); +#if defined (__GNUC__) /* Take the faster path if the implementation-defined bits it's relying on are implemented the way we expect them to be. Namely, conversion from unsigned to signed preserves bit pattern, and right shift of a signed value propagates the sign bit. We have to convert from signed to unsigned and back, because when left shifting signed values, any overflow is undefined behavior. */ - gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); int shift = HOST_BITS_PER_WIDE_INT - prec; return ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) src << shift)) >> shift; - } #else - { /* Fall back to the slower, well defined path otherwise. */ - gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT); HOST_WIDE_INT sign_mask = HOST_WIDE_INT_1 << (prec - 1); HOST_WIDE_INT value_mask = (HOST_WIDE_INT_1U << prec) - HOST_WIDE_INT_1U; return (((src & value_mask) ^ sign_mask) - sign_mask); - } #endif + } } /* Zero extend SRC starting from PREC. */ -- 2.55.0