Improve abs with overflow implementations

libgcc/

	* libgcc2.c (absvSI2): Simplify/improve implementation by using
	builtin_add_overflow.
	(absvsi2, absvDI2): Likewise.
This commit is contained in:
Stefan Kanthak 2020-11-25 11:36:51 -07:00 committed by Jeff Law
parent dfc537e554
commit 4919ed711c
1 changed files with 12 additions and 30 deletions

View File

@ -214,37 +214,25 @@ __negvDI2 (DWtype a)
Wtype Wtype
__absvSI2 (Wtype a) __absvSI2 (Wtype a)
{ {
Wtype w = a; const Wtype v = 0 - (a < 0);
Wtype w;
if (a < 0) if (__builtin_add_overflow (a, v, &w))
#ifdef L_negvsi2
w = __negvSI2 (a);
#else
w = -(UWtype) a;
if (w < 0)
abort (); abort ();
#endif
return w; return v ^ w;
} }
#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
SItype SItype
__absvsi2 (SItype a) __absvsi2 (SItype a)
{ {
SItype w = a; const SItype v = 0 - (a < 0);
SItype w;
if (a < 0) if (__builtin_add_overflow (a, v, &w))
#ifdef L_negvsi2
w = __negvsi2 (a);
#else
w = -(USItype) a;
if (w < 0)
abort (); abort ();
#endif
return w; return v ^ w;
} }
#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
#endif #endif
@ -253,19 +241,13 @@ __absvsi2 (SItype a)
DWtype DWtype
__absvDI2 (DWtype a) __absvDI2 (DWtype a)
{ {
DWtype w = a; const DWtype v = 0 - (a < 0);
DWtype w;
if (a < 0) if (__builtin_add_overflow (a, v, &w))
#ifdef L_negvdi2
w = __negvDI2 (a);
#else
w = -(UDWtype) a;
if (w < 0)
abort (); abort ();
#endif
return w; return v ^ w;
} }
#endif #endif