mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
lib/msun amd64: use AVX FMA instructions for fma(3) and fmaf(3) when available
Utilize the ARCHLEVEL framework from libc/amd64/string to provide the way for runtime selection of the implementation, if wanted. Reviewed by: fuz, kfv Discussed with: kargl Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D59462
This commit is contained in:
1 parent
b45fd24a3c
commit
18a5549bcb
5 files changed
+76
-3
No files matched your search
@@ -1,8 +1,15 @@
|
||||
ARCH_SRCS = e_fmod.S e_fmodf.S e_fmodl.S \
|
||||
.PATH: ${LIBC_SRCTOP}/amd64/string
|
||||
|
||||
ARCH_SRCS = amd64_archlevel.c \
|
||||
e_fmod.S e_fmodf.S e_fmodl.S \
|
||||
e_remainder.S e_remainderf.S e_remainderl.S \
|
||||
e_sqrt.S e_sqrtf.S e_sqrtl.S \
|
||||
s_fma_avx.S s_fmaf_avx.S \
|
||||
s_llrint.S s_llrintf.S s_llrintl.S \
|
||||
s_logbl.S s_lrint.S s_lrintf.S s_lrintl.S \
|
||||
s_remquo.S s_remquof.S s_remquol.S \
|
||||
s_rintl.S s_scalbn.S s_scalbnf.S s_scalbnl.S
|
||||
LDBL_PREC = 64
|
||||
|
||||
CFLAGS+=-D_RENAME_FMA
|
||||
CFLAGS+=-D_RENAME_FMAF
|
||||
@@ -0,0 +1,24 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright 2026 The FreeBSD Foundation
|
||||
*
|
||||
* This software were developed by
|
||||
* Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*/
|
||||
|
||||
#include "amd64_archlevel.h"
|
||||
|
||||
.text
|
||||
ARCHENTRY(fma, avx)
|
||||
vfmadd132sd %xmm1, %xmm2, %xmm0
|
||||
ret
|
||||
ARCHEND(fma, avx)
|
||||
|
||||
ARCHFUNCS(fma)
|
||||
ARCHFUNC(fma, sw)
|
||||
NOARCHFUNC
|
||||
NOARCHFUNC
|
||||
ARCHFUNC(fma, avx)
|
||||
ENDARCHFUNCS(fma)
|
||||
@@ -0,0 +1,24 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright 2026 The FreeBSD Foundation
|
||||
*
|
||||
* This software were developed by
|
||||
* Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*/
|
||||
|
||||
#include "amd64_archlevel.h"
|
||||
|
||||
.text
|
||||
ARCHENTRY(fmaf, avx):
|
||||
vfmadd132ss %xmm1, %xmm2, %xmm0
|
||||
ret
|
||||
ARCHEND(fmaf, avx):
|
||||
|
||||
ARCHFUNCS(fmaf)
|
||||
ARCHFUNC(fmaf, sw)
|
||||
NOARCHFUNC
|
||||
NOARCHFUNC
|
||||
ARCHFUNC(fmaf, avx)
|
||||
ENDARCHFUNCS(fmaf)
|
||||
+10
-1
@@ -163,6 +163,10 @@ dd_mul(double a, double b)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#ifdef _RENAME_FMA
|
||||
double fma_sw(double, double, double);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Fused multiply-add: Compute x * y + z with a single rounding error.
|
||||
*
|
||||
@@ -181,7 +185,12 @@ dd_mul(double a, double b)
|
||||
* since this implementation will likely be several times slower.
|
||||
*/
|
||||
double
|
||||
fma(double x, double y, double z)
|
||||
#ifdef _RENAME_FMA
|
||||
fma_sw
|
||||
#else
|
||||
fma
|
||||
#endif
|
||||
(double x, double y, double z)
|
||||
{
|
||||
double xs, ys, zs, adj;
|
||||
struct dd xy, r;
|
||||
|
||||
+10
-1
@@ -38,6 +38,10 @@ fmaf(float x, float y, float z)
|
||||
return (__builtin_fmaf(x, y, z));
|
||||
}
|
||||
#else
|
||||
#ifdef _RENAME_FMAF
|
||||
float fmaf_sw(float, float, float);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Fused multiply-add: Compute x * y + z with a single rounding error.
|
||||
*
|
||||
@@ -46,7 +50,12 @@ fmaf(float x, float y, float z)
|
||||
* rounding occurs.
|
||||
*/
|
||||
float
|
||||
fmaf(float x, float y, float z)
|
||||
#ifdef _RENAME_FMAF
|
||||
fmaf_sw
|
||||
#else
|
||||
fmaf
|
||||
#endif
|
||||
(float x, float y, float z)
|
||||
{
|
||||
double xy, result;
|
||||
uint32_t hr, lr;
|
||||
|
||||
Reference in new issue
Block a user