From 6c6fdec7339426b50f926e097ac391c152ff3185 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 23 Oct 2016 19:47:36 +0000 Subject: [PATCH] To avoid potential compiler bugs when inlining inline assembly, remove the asm variants of msqrtasm and always use the C version. Compilers generate equivalent or better assembly, and the function is used exactly once, in a routine called during startup. git-svn-id: https://svn.eduke32.com/eduke32@5909 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 21 ++++++++ polymer/eduke32/build/src/engine_priv.h | 70 ------------------------- 2 files changed, 21 insertions(+), 70 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 831809efe..cde65d8a5 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -7013,6 +7013,27 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t }*/ } +static uint32_t msqrtasm(uint32_t c) +{ + uint32_t a = 0x40000000l, b = 0x20000000l; + + do + { + if (c >= a) + { + c -= a; + a += b*4; + } + a -= b; + a >>= 1; + b >>= 2; + } while (b); + + if (c >= a) + a++; + + return a >> 1; +} // // initksqrt (internal) diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index 11e49c7b4..17baa25ba 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -61,31 +61,6 @@ extern uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[409 } } - static inline int32_t msqrtasm(int32_t c) - { - _asm - { - push ebx - mov ecx, c - mov eax, 0x40000000 - mov ebx, 0x20000000 - begit: - cmp ecx, eax - jl skip - sub ecx, eax - lea eax, [eax+ebx*4] - skip : - sub eax, ebx - shr eax, 1 - shr ebx, 2 - jnz begit - cmp ecx, eax - sbb eax, -1 - shr eax, 1 - pop ebx - } - } - static inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d) { _asm @@ -154,28 +129,6 @@ extern uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[409 : "=a" (__r) : "a" (__a) : "ebx", "ecx", "cc"); \ __r; }) - // edx is blown by this code somehow?! -#define msqrtasm(c) \ - ({ int32_t __r, __c=(c); \ - __asm__ __volatile__ ( \ - "movl $0x40000000, %%eax\n\t" \ - "movl $0x20000000, %%ebx\n\t" \ - "0:\n\t" \ - "cmpl %%eax, %%ecx\n\t" \ - "jl 1f\n\t" \ - "subl %%eax, %%ecx\n\t" \ - "leal (%%eax,%%ebx,4), %%eax\n\t" \ - "1:\n\t" \ - "subl %%ebx, %%eax\n\t" \ - "shrl $1, %%eax\n\t" \ - "shrl $2, %%ebx\n\t" \ - "jnz 0b\n\t" \ - "cmpl %%eax, %%ecx\n\t" \ - "sbbl $-1, %%eax\n\t" \ - "shrl $1, %%eax" \ - : "=a" (__r) : "c" (__c) : "edx","ebx", "cc"); \ - __r; }) - #define getclipmask(a,b,c,d) \ ({ int32_t __a=(a), __b=(b), __c=(c), __d=(d); \ __asm__ __volatile__ ("sarl $31, %%eax; addl %%ebx, %%ebx; adcl %%eax, %%eax; " \ @@ -229,29 +182,6 @@ extern uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[409 return a; } - static inline int32_t msqrtasm(uint32_t c) - { - uint32_t a, b; - - a = 0x40000000l; // mov eax, 0x40000000 - b = 0x20000000l; // mov ebx, 0x20000000 - do // begit: - { - if (c >= a) // cmp ecx, eax / jl skip - { - c -= a; // sub ecx, eax - a += b*4; // lea eax, [eax+ebx*4] - } // skip: - a -= b; // sub eax, ebx - a >>= 1; // shr eax, 1 - b >>= 2; // shr ebx, 2 - } while (b); // jnz begit - if (c >= a) // cmp ecx, eax - a++; // sbb eax, -1 - a >>= 1; // shr eax, 1 - return a; - } - static inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d) { // Ken did this