From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id 878013860C35; Wed, 25 Nov 2020 18:38:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 878013860C35 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-5386] Improve abs with overflow implementations X-Act-Checkin: gcc X-Git-Author: Stefan Kanthak X-Git-Refname: refs/heads/master X-Git-Oldrev: dfc537e554afa98b42a4b203ffd08c0eddba746e X-Git-Newrev: 4919ed711c1d02845f2843f6b0a70c27f9e6d434 Message-Id: <20201125183854.878013860C35@sourceware.org> Date: Wed, 25 Nov 2020 18:38:54 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2020 18:38:54 -0000 https://gcc.gnu.org/g:4919ed711c1d02845f2843f6b0a70c27f9e6d434 commit r11-5386-g4919ed711c1d02845f2843f6b0a70c27f9e6d434 Author: Stefan Kanthak Date: Wed Nov 25 11:36:51 2020 -0700 Improve abs with overflow implementations libgcc/ * libgcc2.c (absvSI2): Simplify/improve implementation by using builtin_add_overflow. (absvsi2, absvDI2): Likewise. Diff: --- 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