softfloat: enforce softfloat if the host's FMA is broken
PATCH 1/1 softfloat: enforce softfloat if the host's FMA is broken
The added branch to the FMA ops is marked as unlikely and therefore its impact on performance (measured with fp-bench) is within noise range when measured on an Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz.
In addition, when the host doesn't have a hardware FMA instruction we force the use of softfloat, since whatever the libc does (e.g. checking the host's FP flags) is unlikely to be faster than our softfloat implementation. For instance, on an i386 machine with no hardware support for FMA, we get:
$ for precision in single double; do
./fp-bench -o mulAdd -p $precision
done- before:
5.07 MFlops
1.85 MFlops
- after:
12.65 MFlops
10.05 MFlops
--- include/qemu/cpuid.h | 6 ++++ fpu/softfloat.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+)
include/qemu/cpuid.h +6 -0
@@ -25,6 +25,9 @@#endif /* Leaf 1, %ecx */ +#ifndef bit_FMA3 +#define bit_FMA3 (1 << 12) +#endif #ifndef bit_SSE4_1#define bit_SSE4_1 (1 << 19)#endif
@@ -53,5 +56,8 @@#ifndef bit_LZCNT#define bit_LZCNT (1 << 5)#endif +#ifndef bit_FMA4 +#define bit_FMA4 (1 << 16) +#endif #endif /* QEMU_CPUID_H */
fpu/softfloat.c +85 -0
106 lines not on this page · raw message
Signature · 1 line
2.17.1
fpu/softfloat.c float128 float128_scalbn(float128 a, int n, float_status *status) · line 8014
Quoted 13 lines · Emilio G. Cota
The added branch to the FMA ops is marked as unlikely and therefore its impact on performance (measured with fp-bench) is within noise range when measured on an Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz.
fpu/softfloat.c +9
-0+/* check whether avx is usable */ +if (c & bit_OSXSAVE) { +int bv; + + __asm("xgetbv" :"=a" (bv),"=d" (d) :"c" (0 )); +if ((bv &6 ) ==6 ) { + has_avx = c & bit_AVX; + } + }
I note that the code in tcg/i386/tcg-target.inc.c
that does something similar has the note:
/* The xgetbv instruction is not available to older versions of
* the assembler, so we encode the instruction manually.
*/-- does that concern apply here?
This will also be the fourth piece of code that has an inline xgetbv asm insn to try to query a property of the CPU (the other 3 are target/i386/hvf/x86_cpuid.c, util/bufferiszero.c and tcg/i386/tcg-target.inc.c), which strongly suggests that we should abstract this out a bit better. That also might help avoid bugs which exist in one version but not the other:
see for instance https://bugs.launchpad.net/bugs/1758819
thanks
-- PMM
Quoted 15 lines · Peter Maydell
fpu/softfloat.c float128 float128_scalbn(float128 a, int n, float_status *status) · line 8014
Quoted 13 lines · Emilio G. Cota
The added branch to the FMA ops is marked as unlikely and therefore its impact on performance (measured with fp-bench) is within noise range when measured on an Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz.
fpu/softfloat.c +9
-0+/* check whether avx is usable */ +if (c & bit_OSXSAVE) { +int bv; + + __asm("xgetbv" :"=a" (bv),"=d" (d) :"c" (0 )); +if ((bv &6 ) ==6 ) { + has_avx = c & bit_AVX; + } + }
Quoted 6 lines
I note that the code in
tcg/i386/tcg-target.inc.c
that does something similar has the note:/* The xgetbv instruction is not available to older versions of * the assembler, so we encode the instruction manually. */-- does that concern apply here?
Yes.
Quoted 7 lines
This will also be the fourth piece of code that has an inline xgetbv asm insn to try to query a property of the CPU (the other 3 are
target/i386/hvf/x86_cpuid.c,util/bufferiszero.candtcg/i386/tcg-target.inc.c), which strongly suggests that we should abstract this out a bit better. That also might help avoid bugs which exist in one version but not the other:
see for instance https://bugs.launchpad.net/bugs/1758819
Agreed.
I'll be away until mid-January starting tomorrow, so I'll send a v2 with the cpuid bits removed, which aren't needed to fix the bug that Laurent hit.
We can later on address cpuid consolidation.
Thanks,
Emilio