Fix pow() optimization inconsistencies.

This commit is contained in:
Mike Pall
2022-01-24 14:37:50 +01:00
parent c18acfe756
commit 9512d5c1ac
15 changed files with 114 additions and 205 deletions

View File

@@ -1755,13 +1755,16 @@ static void build_subroutines(BuildCtx *ctx)
| jmp ->fff_resxmm0
|.endmacro
|
|.macro math_extern2, func
| .ffunc_nn math_ .. func
|.macro math_extern2, name, func
| .ffunc_nn math_ .. name
| mov RB, BASE
| call extern func
| mov BASE, RB
| jmp ->fff_resxmm0
|.endmacro
|.macro math_extern2, func
| math_extern2 func, func
|.endmacro
|
| math_extern log10
| math_extern exp
@@ -1774,7 +1777,7 @@ static void build_subroutines(BuildCtx *ctx)
| math_extern sinh
| math_extern cosh
| math_extern tanh
| math_extern2 pow
| math_extern2 pow, lj_vm_pow
| math_extern2 atan2
| math_extern2 fmod
|
@@ -2579,41 +2582,6 @@ static void build_subroutines(BuildCtx *ctx)
| subsd xmm0, xmm1
| ret
|
|// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.
|->vm_powi_sse:
| cmp eax, 1; jle >6 // i<=1?
| // Now 1 < (unsigned)i <= 0x80000000.
|1: // Handle leading zeros.
| test eax, 1; jnz >2
| mulsd xmm0, xmm0
| shr eax, 1
| jmp <1
|2:
| shr eax, 1; jz >5
| movaps xmm1, xmm0
|3: // Handle trailing bits.
| mulsd xmm0, xmm0
| shr eax, 1; jz >4
| jnc <3
| mulsd xmm1, xmm0
| jmp <3
|4:
| mulsd xmm0, xmm1
|5:
| ret
|6:
| je <5 // x^1 ==> x
| jb >7 // x^0 ==> 1
| neg eax
| call <1
| sseconst_1 xmm1, RD
| divsd xmm1, xmm0
| movaps xmm0, xmm1
| ret
|7:
| sseconst_1 xmm0, RD
| ret
|
|//-----------------------------------------------------------------------
|//-- Miscellaneous functions --------------------------------------------
|//-----------------------------------------------------------------------