From d213bcf7350dbeab443f44ca1e7254344acdeb61 Mon Sep 17 00:00:00 2001 From: darkstar Date: Wed, 21 Feb 2018 20:22:36 +0100 Subject: [PATCH] MSVC: Try to fix inline assembly for MSVC This is untested and will probably crash :) --- src/cpu/codegen_x86.c | 7 +++++++ src/cpu/x87_ops.h | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/cpu/codegen_x86.c b/src/cpu/codegen_x86.c index da99018..e318643 100644 --- a/src/cpu/codegen_x86.c +++ b/src/cpu/codegen_x86.c @@ -1236,10 +1236,17 @@ void codegen_init() block_pos = (block_pos + 15) & ~15; mem_check_write_l = (uint32_t)gen_MEM_CHECK_WRITE_L(); +#ifndef _MSC_VER asm( "fstcw %0\n" : "=m" (cpu_state.old_npxc) ); +#else + __asm + { + fstcw cpu_state.old_npxc + } +#endif } void codegen_reset() diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index 3f75e4a..d5e6f7a 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -38,6 +38,9 @@ */ #include #include +#ifdef _MSC_VER +#include +#endif #define fplog 0 @@ -270,7 +273,7 @@ static __inline uint16_t x87_compare(double a, double b) if (((a == INFINITY) || (a == -INFINITY)) && ((b == INFINITY) || (b == -INFINITY))) { /* pclog("Comparing infinity\n"); */ - +#ifndef _MSC_VER __asm volatile ("" : : : "memory"); __asm( @@ -282,11 +285,23 @@ static __inline uint16_t x87_compare(double a, double b) : "=m" (out) : "m" (a), "m" (a) ); +#else + _ReadWriteBarrier(); + __asm + { + fld a + fld a + fclex + fcompp + fnstsw out + } +#endif return out & (C0|C2|C3); } } +#ifndef _MSC_VER /* Memory barrier, to force GCC to write to the input parameters * before the compare rather than after */ __asm volatile ("" : : : "memory"); @@ -300,6 +315,17 @@ static __inline uint16_t x87_compare(double a, double b) : "=m" (out) : "m" (a), "m" (b) ); +#else + _ReadWriteBarrier(); + _asm + { + fld b + fld a + fclex + fcompp + fnstsw out + } +#endif return out & (C0|C2|C3); #else @@ -337,6 +363,7 @@ static __inline uint16_t x87_ucompare(double a, double b) #if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _WIN32 uint32_t out; +#ifndef _MSC_VER /* Memory barrier, to force GCC to write to the input parameters * before the compare rather than after */ __asm volatile ("" : : : "memory"); @@ -350,6 +377,17 @@ static __inline uint16_t x87_ucompare(double a, double b) : "=m" (out) : "m" (a), "m" (b) ); +#else + _ReadWriteBarrier(); + _asm + { + fld b + fld a + fclex + fcompp + fnstsw out + } +#endif return out & (C0|C2|C3); #else