From 3034f5d2c49d80c9a054a6520225a9c27da37d7e Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Mon, 3 Mar 2025 06:59:09 +0100 Subject: [PATCH 1/2] declare lo and hi in div64_32() as volatile Fixes #2219 --- src/m_fixed.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_fixed.h b/src/m_fixed.h index bb6f24815..7859e3e2b 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -38,8 +38,8 @@ { return a / b; } - int32_t lo = a; - int32_t hi = a >> 32; + volatile int32_t lo = a; + volatile int32_t hi = a >> 32; asm("idivl %[divisor]" : "+a" (lo), "+d" (hi) : [divisor] "r" (b)); return lo; } From 1b0b2f759916e6d73f66fa4a93833f017df7f288 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Tue, 4 Mar 2025 10:02:57 +0100 Subject: [PATCH 2/2] remove ASM div64_32() implementation * Prone to miscompilation * Only helps with very old PCs * Really only helps with voxel rendering --- src/m_fixed.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/m_fixed.h b/src/m_fixed.h index 7859e3e2b..86a0468c0 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -30,20 +30,6 @@ #define div64_32(a, b) _div64((a), (b), NULL) -#elif defined(__GNUC__) && defined(__x86_64__) - - inline static int32_t div64_32(int64_t a, int32_t b) - { - if (__builtin_constant_p(b)) - { - return a / b; - } - volatile int32_t lo = a; - volatile int32_t hi = a >> 32; - asm("idivl %[divisor]" : "+a" (lo), "+d" (hi) : [divisor] "r" (b)); - return lo; - } - #else #define div64_32(a, b) ((fixed_t)((a) / (b)))