summaryrefslogtreecommitdiff
path: root/src/vm_x86.dasc
diff options
context:
space:
mode:
authorMike Pall <mike>2012-10-07 15:47:11 +0200
committerMike Pall <mike>2012-10-07 15:47:11 +0200
commit0561a5693884d76db5b75f7cc746478b325b311b (patch)
treebeef0d8674adf5b0f24a101e4e92613ee85e996e /src/vm_x86.dasc
parent0d62e2e1ab450a2d2d2291dc9da43606bd573bf7 (diff)
downloadluajit2-0561a5693884d76db5b75f7cc746478b325b311b.tar.gz
From Lua 5.2: Add math.log(x, base).
Diffstat (limited to 'src/vm_x86.dasc')
-rw-r--r--src/vm_x86.dasc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index 67984c6c..75683225 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -2045,7 +2045,12 @@ static void build_subroutines(BuildCtx *ctx)
|.else
|.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn
|.endif
- |.ffunc_n math_log, fldln2; fyl2x; jmp ->fff_resn
+ |
+ |.ffunc math_log
+ | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn
+ |
|.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn
|.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn
|
@@ -3157,6 +3162,29 @@ static void build_subroutines(BuildCtx *ctx)
| ret
|.endif
|
+ |// FP log2(x). Called by math.log(x, base).
+ |->vm_log2:
+ |.if X64WIN
+ | movsd qword [rsp+8], xmm0 // Use scratch area.
+ | fld1
+ | fld qword [rsp+8]
+ | fyl2x
+ | fstp qword [rsp+8]
+ | movsd xmm0, qword [rsp+8]
+ |.elif X64
+ | movsd qword [rsp-8], xmm0 // Use red zone.
+ | fld1
+ | fld qword [rsp-8]
+ | fyl2x
+ | fstp qword [rsp-8]
+ | movsd xmm0, qword [rsp-8]
+ |.else
+ | fld1
+ | fld qword [esp+4]
+ | fyl2x
+ |.endif
+ | ret
+ |
|// FP exponentiation e^x and 2^x. Called by math.exp fast function and
|// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified.
|// Caveat: needs 3 slots on x87 stack!