libgcc/
* libgcc2.c (absvSI2): Simplify/improve implementation by using
builtin_add_overflow.
(absvsi2, absvDI2): Likewise.
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
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
\f