From d8764bf84022397ff9d22310f78fcd78d801e2bf Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 18 Aug 2013 15:34:07 +0000 Subject: optimize x86 feclearexcept: only use save/restore x87 fenv if needed the x87 exception summary (ES) and stack fault (SF) flags may be spuriously cleared by feclearexcept using the fnclex instruction, but these flags are not observable through libc hence maintaining their state is not critical. --- src/fenv/x86_64/fenv.s | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/fenv/x86_64/fenv.s') diff --git a/src/fenv/x86_64/fenv.s b/src/fenv/x86_64/fenv.s index c48dade3..dda6b61a 100644 --- a/src/fenv/x86_64/fenv.s +++ b/src/fenv/x86_64/fenv.s @@ -1,25 +1,21 @@ .global feclearexcept .type feclearexcept,@function feclearexcept: + # maintain exceptions in the sse mxcsr, clear x87 exceptions mov %edi,%ecx + fnstsw %ax + test %eax,%ecx + jz 1f + fnclex +1: stmxcsr -8(%rsp) + and $0x3f,%eax + or %eax,-8(%rsp) + test %ecx,-8(%rsp) + jz 1f not %ecx - stmxcsr -8(%rsp) and %ecx,-8(%rsp) ldmxcsr -8(%rsp) - test $0x3f,%ecx - jnz 2f -1: fnclex - xor %eax,%eax - ret -2: fnstsw %ax - and %ecx,%eax - jz 1b - sub $32,%rsp - fnstenv (%rsp) - mov %al,4(%rsp) - fldenv (%rsp) - add $32,%rsp - xor %eax,%eax +1: xor %eax,%eax ret .global feraiseexcept -- cgit v1.2.1