From: Taylor R Campbell Date: Fri, 6 Aug 2010 01:18:01 +0000 (+0000) Subject: Emulate C99 fenv.h on amd64 through the MXCSR. X-Git-Tag: 20101212-Gtk~118 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=e28c5496ebba30194cf110a5157e62e57af34406;p=mit-scheme.git Emulate C99 fenv.h on amd64 through the MXCSR. --- diff --git a/src/microcode/cmpauxmd/x86-64.m4 b/src/microcode/cmpauxmd/x86-64.m4 index fedb3e2ea..ff2238c57 100644 --- a/src/microcode/cmpauxmd/x86-64.m4 +++ b/src/microcode/cmpauxmd/x86-64.m4 @@ -966,6 +966,20 @@ asm_fixnum_rsh_overflow_negative: OP(mov,q) TW(IMM_DETAGGED_FIXNUM_MINUS_ONE,REG(rax)) ret +define_c_label(x86_64_read_mxcsr) + enter IMM(8),IMM(0) + stmxcsr IND(REG(rsp)) + OP(mov,l) TW(IND(REG(rsp)),REG(eax)) + leave + ret + +define_c_label(x86_64_write_mxcsr) + enter IMM(8),IMM(0) + OP(mov,l) TW(REG(eax),IND(REG(rsp))) + ldmxcsr IND(REG(rsp)) + leave + ret + IFDASM(`end') # Mark the stack nonexecutable. If we ever put code (e.g., diff --git a/src/microcode/cmpintmd/x86-64.h b/src/microcode/cmpintmd/x86-64.h index 55090c953..d2e3bc55b 100644 --- a/src/microcode/cmpintmd/x86-64.h +++ b/src/microcode/cmpintmd/x86-64.h @@ -239,6 +239,37 @@ extern void asm_trampoline_to_interface (void); extern insn_t * read_compiled_closure_target (insn_t *); extern insn_t * read_uuo_target (SCHEME_OBJECT *); extern void x86_64_reset_hook (void); - +extern int x86_64_read_mxcsr (void); +extern void x86_64_write_mxcsr (int); + +#ifndef HAVE_FENV_H + +# define FE_TONEAREST 0 +# define FE_DOWNWARD 1 +# define FE_UPWARD 2 +# define FE_TOWARDZERO 3 + +# define HAVE_FEGETROUND +# define HAVE_FESETROUND + +static inline int +fegetround (void) +{ + return (3 & ((x86_64_read_mxcsr ()) >> 13)); +} + +static inline void +fesetround (int mode) +{ + switch (mode) + { + case 0: case 1: case 2: case 3: break; + default: return (1); + } + x86_64_write_mxcsr ((mode << 13) | (0xffff9fff & (x86_64_read_mxcsr ()))); + return (0); +} + +#endif /* HAVE_FENV_H */ #endif /* !SCM_CMPINTMD_H_INCLUDED */