[PATCH] x86-64: Don't use asm statement for trunc/truncf

H.J. Lu hjl.tools@gmail.com
Fri Sep 12 14:48:50 GMT 2025


On Fri, Sep 12, 2025 at 7:16 AM Florian Weimer <fw@deneb.enyo.de> wrote:

> * H. J. Lu:
>
> > On Thu, Sep 11, 2025 at 10:47 PM Florian Weimer <fw@deneb.enyo.de>
> wrote:
> >
> >> * H. J. Lu:
> >>
> >> > diff --git a/sysdeps/x86/fpu/math_private.h
> >> b/sysdeps/x86/fpu/math_private.h
> >> > index d30d580cea..610ae364f3 100644
> >> > --- a/sysdeps/x86/fpu/math_private.h
> >> > +++ b/sysdeps/x86/fpu/math_private.h
> >> > @@ -33,27 +33,35 @@ __NTH (__ieee754_atan2l (long double y, long
> double
> >> x))
> >> >  __extern_always_inline double
> >> >  __trunc (double x)
> >> >  {
> >> > +#if HAVE_X86_OS_INLINE_TRUNC
> >> > +  return trunc (x);
> >> > +#else
> >> > +# ifdef __AVX__
> >> >    asm ("vroundsd $11, %1, %1, %0" : "=v" (x) : "v" (x));
> >> > +# elif defined __SSE4_1__
> >> >    asm ("roundsd $11, %1, %0" : "=x" (x) : "x" (x));
> >> > +# else
> >> >    x = trunc (x);
> >> > +# endif
> >> >    return x;
> >> > +#endif
> >> >  }
> >>
> >> The HAVE_X86_OS_INLINE_TRUNC preprocessor conditional is checked
> >> outside of __AVX__.
> >>
> >
> > The compiler enables roundsX for SSE4.1.   We have AVX and SSE4.1
> > since they have different numbers of operands.  I can change -mavx to
> > -msse4.1 in configure.ac.
>
> I think the configure check must match the condition you use in the
> source code if you pass explicit flags.
>

On x86, AVX implies SSE4.1,  if -msse4.1 can inline trunc/truncf, AVX
can also inline them.  We don't need separate checks.

-- 
H.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250912/01c30bfa/attachment.htm>


More information about the Libc-alpha mailing list