Message ID | CAFULd4Yg3k2h+2ke0=ypGVy16OobD_2Uvft6fFz7+jffwq_c4w@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | [libgcc] : Use type-generic fpclassify builtins in libgcc2.c | expand |
On 10/2/18 9:41 AM, Uros Bizjak wrote: > Nowadays, we have these type-generic builtins always available. > > 2018-10-02 Uros Bizjak <ubizjak@gmail.com> > > * libgcc2.c (isnan): Use __builtin_isnan. > (isfinite): Use __builtin_isfinite. > (isinf): Use __builtin_isinf. > > Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. > > OK for mainline? Presumably the justification is that we default to C99 these days and thus the compiler handles these all internally without calling out to the library? But what if the user explicitly asks for C89 rather than C99 or newer? Jeff
On Wed, Oct 3, 2018 at 6:53 PM Jeff Law <law@redhat.com> wrote: > > On 10/2/18 9:41 AM, Uros Bizjak wrote: > > Nowadays, we have these type-generic builtins always available. > > > > 2018-10-02 Uros Bizjak <ubizjak@gmail.com> > > > > * libgcc2.c (isnan): Use __builtin_isnan. > > (isfinite): Use __builtin_isfinite. > > (isinf): Use __builtin_isinf. > > > > Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. > > > > OK for mainline? > Presumably the justification is that we default to C99 these days and > thus the compiler handles these all internally without calling out to > the library? But what if the user explicitly asks for C89 rather than > C99 or newer? These defines are only used to build complex mul and div functions of libgcc library. The library is built with its default flags. Builtins are -std= agnostic, as shown in the following example: --cut here-- int test (double x) { return __builtin_isinf (x); } --cut here-- gcc -O2 -std=c89 results in a compare insn: test: andpd .LC0(%rip), %xmm0 xorl %eax, %eax ucomisd .LC1(%rip), %xmm0 seta %al ret (BTW: using isinf would depend on -std= flag, resulting in a call when -std=c89 is used). Uros.
On 10/3/18 12:48 PM, Uros Bizjak wrote: > On Wed, Oct 3, 2018 at 6:53 PM Jeff Law <law@redhat.com> wrote: >> >> On 10/2/18 9:41 AM, Uros Bizjak wrote: >>> Nowadays, we have these type-generic builtins always available. >>> >>> 2018-10-02 Uros Bizjak <ubizjak@gmail.com> >>> >>> * libgcc2.c (isnan): Use __builtin_isnan. >>> (isfinite): Use __builtin_isfinite. >>> (isinf): Use __builtin_isinf. >>> >>> Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. >>> >>> OK for mainline? >> Presumably the justification is that we default to C99 these days and >> thus the compiler handles these all internally without calling out to >> the library? But what if the user explicitly asks for C89 rather than >> C99 or newer? > > These defines are only used to build complex mul and div functions of > libgcc library. The library is built with its default flags. Builtins > are -std= agnostic, as shown in the following example: > > --cut here-- > int > test (double x) > { > return __builtin_isinf (x); > } > --cut here-- > > gcc -O2 -std=c89 results in a compare insn: > > test: > andpd .LC0(%rip), %xmm0 > xorl %eax, %eax > ucomisd .LC1(%rip), %xmm0 > seta %al > ret > > (BTW: using isinf would depend on -std= flag, resulting in a call when > -std=c89 is used). Thanks for explaining things. The patch is OK for the trunk. Jeff
diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index f418f3a354de..8ac2025f7af6 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -1939,15 +1939,9 @@ NAME (TYPE x, int m) #define CONCAT2(A,B) _CONCAT2(A,B) #define _CONCAT2(A,B) A##B -/* All of these would be present in a full C99 implementation of <math.h> - and <complex.h>. Our problem is that only a few systems have such full - implementations. Further, libgcc_s.so isn't currently linked against - libm.so, and even for systems that do provide full C99, the extra overhead - of all programs using libgcc having to link against libm. So avoid it. */ - -#define isnan(x) __builtin_expect ((x) != (x), 0) -#define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1) -#define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0) +#define isnan(x) __builtin_isnan (x) +#define isfinite(x) __builtin_isfinite (x) +#define isinf(x) __builtin_isinf (x) #define INFINITY CONCAT2(__builtin_huge_val, CEXT) () #define I 1i