From 4919ed711c1d02845f2843f6b0a70c27f9e6d434 Mon Sep 17 00:00:00 2001 From: Stefan Kanthak Date: Wed, 25 Nov 2020 11:36:51 -0700 Subject: [PATCH] Improve abs with overflow implementations libgcc/ * libgcc2.c (absvSI2): Simplify/improve implementation by using builtin_add_overflow. (absvsi2, absvDI2): Likewise. --- libgcc/libgcc2.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index cf0ca299c72..1921d80f612 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -214,37 +214,25 @@ __negvDI2 (DWtype a) Wtype __absvSI2 (Wtype a) { - Wtype w = a; - - if (a < 0) -#ifdef L_negvsi2 - w = __negvSI2 (a); -#else - w = -(UWtype) a; + const Wtype v = 0 - (a < 0); + Wtype w; - if (w < 0) + if (__builtin_add_overflow (a, v, &w)) abort (); -#endif - return w; + return v ^ w; } #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC SItype __absvsi2 (SItype a) { - SItype w = a; - - if (a < 0) -#ifdef L_negvsi2 - w = __negvsi2 (a); -#else - w = -(USItype) a; + const SItype v = 0 - (a < 0); + SItype w; - if (w < 0) + if (__builtin_add_overflow (a, v, &w)) abort (); -#endif - return w; + return v ^ w; } #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ #endif @@ -253,19 +241,13 @@ __absvsi2 (SItype a) DWtype __absvDI2 (DWtype a) { - DWtype w = a; - - if (a < 0) -#ifdef L_negvdi2 - w = __negvDI2 (a); -#else - w = -(UDWtype) a; + const DWtype v = 0 - (a < 0); + DWtype w; - if (w < 0) + if (__builtin_add_overflow (a, v, &w)) abort (); -#endif - return w; + return v ^ w; } #endif -- 2.30.2