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

Florian Weimer fw@deneb.enyo.de
Fri Sep 12 05:47:18 GMT 2025


* 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__.

> 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.


More information about the Libc-alpha mailing list