[PATCH] i386: Fix fmod/fmof/remainder/remainderf for gcc-12
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Nov 24 14:31:33 GMT 2025
On 20/11/25 21:01, H.J. Lu wrote:
> On Fri, Nov 21, 2025 at 7:23 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> On Thu, Nov 20, 2025 at 8:21 PM Adhemerval Zanella
>> <adhemerval.zanella@linaro.org> wrote:
>>>
>>> The __builtin_fmod{f} and __builtin_remainder{f} were added on gcc 13,
>>> and the minimum supported gcc is 12. This patch adds a configure test
>>> to check whether the compiler enables inlining for fmod/remainder, and
>>> uses inline assembly if not.
>>>
>>> Checked on i686-linux-gnu wih gcc-12.
>>> ---
>>> config.h.in | 3 +++
>>> sysdeps/i386/fpu/e_fmod.c | 14 ++++++++++
>>> sysdeps/i386/fpu/e_fmodf.c | 14 ++++++++++
>>> sysdeps/i386/fpu/e_remainder.c | 14 ++++++++++
>>> sysdeps/i386/fpu/e_remainderf.c | 14 ++++++++++
>>> sysdeps/x86/configure | 48 +++++++++++++++++++++++++++++++++
>>> sysdeps/x86/configure.ac | 27 +++++++++++++++++++
>>> 7 files changed, 134 insertions(+)
>>>
>>> diff --git a/config.h.in b/config.h.in
>>> index a7cc17df8e..bfcd29bcdf 100644
>>> --- a/config.h.in
>>> +++ b/config.h.in
>>> @@ -317,6 +317,9 @@
>>> /* Define if trunc is inlined on x86. */
>>> #undef HAVE_X86_INLINE_TRUNC
>>>
>>> +/* Define if __builtin_fmod/__builtin_remainder is inlined on x86. */
>>> +#undef HAVE_X86_INLINE_FMOD
>>> +
>>> /* Define if compiler allows add attribute after function declaration. */
>>> #undef ATTR_AFTER_FUNC_DECL
>>>
>>> diff --git a/sysdeps/i386/fpu/e_fmod.c b/sysdeps/i386/fpu/e_fmod.c
>>> index 281b23dffc..93b6f9d698 100644
>>> --- a/sysdeps/i386/fpu/e_fmod.c
>>> +++ b/sysdeps/i386/fpu/e_fmod.c
>>> @@ -33,7 +33,21 @@ __fmod (double x, double y)
>>> && !is_nan (hx)))
>>> return __math_invalid (x);
>>>
>>> +#if HAVE_X86_INLINE_FMOD
>>
>> Does __has_builtin (__builtin_fmod) work? Can you define
>> __builtin_fmod in x86/fpu/math-inline-asm.h
>
> __has_builtin (__builtin_fmod) doesn't work since GCC 12 just
> calls the C function. But it is still a good idea to put them in
> x86/fpu/math-inline-asm.h.
What do we gain by using __has_builtin here? I coded in the manner that
if/when we raise the minimum required gcc to 13 we can just remove this
support.
More information about the Libc-alpha
mailing list