Skip to content

Commit e63bc00

Browse files
authored
Merge 82878b3 into ea59155
2 parents ea59155 + 82878b3 commit e63bc00

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

platforms/Cross/plugins/IA32ABI/x64win64abicc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ extern
3838
#endif
3939
struct VirtualMachine* interpreterProxy;
4040

41+
#ifdef _MSC_VER
42+
# define alloca _alloca
43+
#endif
4144
#if __GNUC__
4245
# define setsp(sp) __asm__ volatile ("movq %0,%%rsp" : : "m"(sp))
4346
# define getsp() ({ void *sp; __asm__ volatile ("movq %%rsp,%0" : "=r"(sp) : ); sp;})

platforms/minheadless/windows/sqPlatformSpecific-Win32.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,27 @@
4848

4949
# define fopen_for_append(filename) fopen(filename,"a+t")
5050

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 and mask:
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
5559
*/
60+
61+
#if !defined(_MCW_PC)
62+
// x64 does not support _MCW_PC
63+
// The x64 CPU hardware default is 64-bit precision mode (80-bit long double);
64+
// Microsoft expects software to set 53-bit mode before any user mode x87 instructions
65+
// are reached. Microsoft made a change in responsibility for initializing precision mode
66+
// in the X64 OS. The X64 OS sets 53-bit mode prior to starting your .exe, where the 32-bit OS
67+
// expected the program to make that initialization.
68+
# define _MCW_PC 0
69+
#endif
70+
71+
#define FPU_MASK (_MCW_EM | _MCW_RC | _MCW_PC)
5672
#define FPU_DEFAULT (_RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)
5773

5874
#define MAXFRAMES 64
@@ -116,7 +132,7 @@ void
116132
ioInitPlatformSpecific(void)
117133
{
118134
/* Setup the FPU */
119-
_controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC);
135+
_controlfp(FPU_DEFAULT, FPU_MASK);
120136

121137
/* Create the wake up event. */
122138
vmWakeUpEvent = CreateEvent(NULL, 1, 0, NULL);
@@ -363,8 +379,9 @@ static LONG CALLBACK squeakExceptionHandler(LPEXCEPTION_POINTERS exp)
363379
DWORD code = exp->ExceptionRecord->ExceptionCode;
364380
if((code >= EXCEPTION_FLT_DENORMAL_OPERAND) && (code <= EXCEPTION_FLT_UNDERFLOW))
365381
{
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);
382+
/* in case FFI callout to foreign code changed FP mode */
383+
/* restore our default masking of exceptions in the FPU and proceed */
384+
_controlfp(FPU_DEFAULT, FPU_MASK);
368385
result = EXCEPTION_CONTINUE_EXECUTION;
369386
}
370387
}
@@ -799,3 +816,4 @@ void *os_exports[][3] =
799816
{
800817
{ 0, 0, 0 }
801818
};
819+

platforms/minheadless/windows/sqPlatformSpecific-Win32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ size_t sqImageFileWrite(const void *ptr, size_t sz, size_t count, sqImageFile h)
114114
error "Not Win32!"
115115
#endif /* WIN32 */
116116

117-
int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt x, sqInt y);
117+
sqInt ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt x, sqInt y);
118118

119119
/* poll and profile thread priorities. The stack vm uses a thread to cause the
120120
* VM to poll for I/O, check for delay expiry et al at regular intervals. Both
@@ -185,4 +185,4 @@ extern const unsigned long tltiIndex;
185185
#define TRY
186186
#define EXCEPT(filter) if (0)
187187
#define FINALLY
188-
#endif
188+
#endif

0 commit comments

Comments
 (0)