|
48 | 48 |
|
49 | 49 | # define fopen_for_append(filename) fopen(filename,"a+t") |
50 | 50 |
|
51 | | -/* default fpu control word: |
52 | | - _RC_NEAR: round to nearest |
53 | | - _PC_53 : double precision arithmetic (instead of extended) |
54 | | - _EM_XXX: silent operations (no signals please) |
| 51 | +/* default fpu control word: |
| 52 | + _MCW_RC: Rounding control |
| 53 | + _RC_NEAR: round to nearest |
| 54 | + _MCW_PC: Precision control |
| 55 | + _PC_53: double precision arithmetic (instead of extended) |
| 56 | + _MCW_EM: Interupt exception mask |
| 57 | + _EM_XXX: silent operations (no signals please) |
| 58 | + https://docs.microsoft.com/en-us/previous-versions/e9b52ceh%28v%3dvs.140%29 |
55 | 59 | */ |
| 60 | +#if !defined(_MCW_PC) // x64 does not support _MCW_PC |
| 61 | +# define _MCW_PC 0 |
| 62 | +#endif |
| 63 | +#define FPU_MASK (_MCW_EM | _MCW_RC | _MCW_PC) |
56 | 64 | #define FPU_DEFAULT (_RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL) |
57 | 65 |
|
58 | 66 | #define MAXFRAMES 64 |
|
116 | 124 | ioInitPlatformSpecific(void) |
117 | 125 | { |
118 | 126 | /* Setup the FPU */ |
119 | | - _controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); |
| 127 | + _controlfp(FPU_DEFAULT, FPU_MASK); |
120 | 128 |
|
121 | 129 | /* Create the wake up event. */ |
122 | 130 | vmWakeUpEvent = CreateEvent(NULL, 1, 0, NULL); |
@@ -363,8 +371,9 @@ static LONG CALLBACK squeakExceptionHandler(LPEXCEPTION_POINTERS exp) |
363 | 371 | DWORD code = exp->ExceptionRecord->ExceptionCode; |
364 | 372 | if((code >= EXCEPTION_FLT_DENORMAL_OPERAND) && (code <= EXCEPTION_FLT_UNDERFLOW)) |
365 | 373 | { |
366 | | - /* turn on the default masking of exceptions in the FPU and proceed */ |
367 | | - _controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); |
| 374 | + /* in case FFI callout to foreign code changed FP mode */ |
| 375 | + /* restore our default masking of exceptions in the FPU and proceed */ |
| 376 | + _controlfp(FPU_DEFAULT, FP_MASK); |
368 | 377 | result = EXCEPTION_CONTINUE_EXECUTION; |
369 | 378 | } |
370 | 379 | } |
@@ -799,3 +808,4 @@ void *os_exports[][3] = |
799 | 808 | { |
800 | 809 | { 0, 0, 0 } |
801 | 810 | }; |
| 811 | + |
0 commit comments