public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5386] Improve abs with overflow implementations
@ 2020-11-25 18:38 Jeff Law
0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2020-11-25 18:38 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4919ed711c1d02845f2843f6b0a70c27f9e6d434
commit r11-5386-g4919ed711c1d02845f2843f6b0a70c27f9e6d434
Author: Stefan Kanthak <stefan.kanthak@nexgo.de>
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-25 18:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 18:38 [gcc r11-5386] Improve abs with overflow implementations Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).