From 367485b5c511e044c1d44146056bd2fcae9b944b Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Fri, 23 Jul 2010 01:28:59 +0000 Subject: [PATCH] Unmask IEEE 754 floating-point exceptions on x86-64. Should this instead be part of Scheme's dynamic environment, like the floating-point rounding mode? --- src/microcode/cmpauxmd/x86-64.m4 | 18 ++++++++++++++++++ src/microcode/cmpintmd/x86-64.c | 2 ++ src/microcode/cmpintmd/x86-64.h | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/microcode/cmpauxmd/x86-64.m4 b/src/microcode/cmpauxmd/x86-64.m4 index 5524b9a11..6d5a523c1 100644 --- a/src/microcode/cmpauxmd/x86-64.m4 +++ b/src/microcode/cmpauxmd/x86-64.m4 @@ -356,6 +356,24 @@ define_double(flonum_one,1.0) DECLARE_CODE_SEGMENT() declare_alignment(2) +define_c_label(x86_64_fpe_reset_traps) + OP(push,q) REG(rbp) + OP(mov,q) TW(REG(rsp),REG(rbp)) + OP(sub,q) TW(IMM(8),REG(rsp)) + stmxcsr IND(REG(rsp)) + # Clear 7 (invalid operation mask) + # 8 (denormalized operand mask) + # 9 (zero-divide exception mask) + # 10 (overflow exception mask) + # 11 (underflow exception mask) + # 15 (flush-to-zero (if set, gives non-IEEE semantics)) + OP(and,l) TW(IMM(HEX(ffff707f)),IND(REG(rsp))) + # Set 12 (precision exception mask) + OP(or,l) TW(IMM(HEX(1000)),IND(REG(rsp))) + ldmxcsr IND(REG(rsp)) + leave + ret + # C_to_interface passes control from C into Scheme. To C it is a # unary procedure; its one argument is passed in rdi. It saves the # state of the C world (the C frame pointer and stack pointer) and diff --git a/src/microcode/cmpintmd/x86-64.c b/src/microcode/cmpintmd/x86-64.c index 404abd402..86144a79a 100644 --- a/src/microcode/cmpintmd/x86-64.c +++ b/src/microcode/cmpintmd/x86-64.c @@ -223,6 +223,8 @@ x86_64_reset_hook (void) int offset = (COMPILER_REGBLOCK_N_FIXED * (sizeof (SCHEME_OBJECT))); unsigned char * rsi_value = ((unsigned char *) Registers); + x86_64_fpe_reset_traps (); + /* These must match machines/x86-64/lapgen.scm */ SETUP_REGISTER (asm_scheme_to_interface); /* 0 */ diff --git a/src/microcode/cmpintmd/x86-64.h b/src/microcode/cmpintmd/x86-64.h index f296eab47..0a7548fce 100644 --- a/src/microcode/cmpintmd/x86-64.h +++ b/src/microcode/cmpintmd/x86-64.h @@ -117,6 +117,7 @@ entry 0 MOV AL,code 0xB0, code-byte */ #define ASM_RESET_HOOK x86_64_reset_hook +#define FPE_RESET_TRAPS x86_64_fpe_reset_traps #define CMPINT_USE_STRUCS 1 @@ -173,7 +174,7 @@ typedef byte_t insn_t; # define ASM_ENTRY_POINT(name) name #endif -extern int ASM_ENTRY_POINT (x86_64_interface_initialize) (void); +extern void ASM_ENTRY_POINT (x86_64_fpe_reset_traps) (void); extern void asm_assignment_trap (void); extern void asm_dont_serialize_cache (void); -- 2.25.1