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

H.J. Lu hjl.tools@gmail.com
Fri Sep 12 12:43:26 GMT 2025


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.


> > diff --git a/sysdeps/x86_64/configure.ac b/sysdeps/x86_64/configure.ac
> > index a00958e219..a3651f7f5d 100644
> > --- a/sysdeps/x86_64/configure.ac
> > +++ b/sysdeps/x86_64/configure.ac
> > @@ -104,6 +104,37 @@ if test $libc_cv_x86_have_apx = yes; then
> >  fi
> >  LIBC_CONFIG_VAR([have-x86-apx], [$libc_cv_x86_have_apx])
> >
> > +conftest_code="
> > +extern float truncf (float __x) __attribute__ ((__nothrow__,__const__));
> > +
> > +float
> > +tf (float x)
> > +{
> > +  return truncf (x);
> > +}
> > +"
> > +dnl Check if CC inlines trunc with -Os.
> > +LIBC_TRY_CC_COMMAND([if -Os inlines trunc],
> > +  [$conftest_code],
> > +  [-S -Os -mavx],
> > +  libc_cv_cc_x86_inline_trunc,
> > +  [
>
> The configure probe uses -mavx.
>
> This is inconsistent.  I don't know in which direction the
> inconsistency should be resolved.
>


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


More information about the Libc-alpha mailing list