aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2009-12-15 05:40:44 +0100
committerMike Pall <mike>2009-12-15 05:40:44 +0100
commit1eedc6d2f153f7d68f49282732b17f9a4d35698a (patch)
tree5d79ba7ba9552306e909d57241b0dbb85fa7ca04 /src
parent267d7152abbb99f2fdd69e6ece40958589c25d6f (diff)
downloadluajit-1eedc6d2f153f7d68f49282732b17f9a4d35698a.tar.gz
luajit-1eedc6d2f153f7d68f49282732b17f9a4d35698a.tar.bz2
luajit-1eedc6d2f153f7d68f49282732b17f9a4d35698a.zip
First bunch of register definitions for x64 interpreter.
Diffstat (limited to 'src')
-rw-r--r--src/buildvm_x86.dasc84
1 files changed, 70 insertions, 14 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc
index e857a6be..4b406754 100644
--- a/src/buildvm_x86.dasc
+++ b/src/buildvm_x86.dasc
@@ -2,7 +2,11 @@
2|// Bytecode interpreter, fast functions and helper functions. 2|// Bytecode interpreter, fast functions and helper functions.
3|// Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h 3|// Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h
4| 4|
5|.if X64
6|.arch x64
7|.else
5|.arch x86 8|.arch x86
9|.endif
6|.section code_op, code_sub 10|.section code_op, code_sub
7| 11|
8|.actionlist build_actionlist 12|.actionlist build_actionlist
@@ -30,8 +34,32 @@
30|.define RD, RC 34|.define RD, RC
31|.define RDL, RCL 35|.define RDL, RCL
32| 36|
33|.define FCARG1, ecx // Fastcall arguments. 37|.if not X64
38|.define FCARG1, ecx // x86 fastcall arguments.
34|.define FCARG2, edx 39|.define FCARG2, edx
40|.elif X64WIN
41|.define CARG1, rcx // x64/WIN64 C call arguments.
42|.define CARG2, rdx
43|.define CARG3, r8
44|.define CARG4, r9
45|.define CARG1d, ecx
46|.define CARG2d, edx
47|.define CARG3d, r8d
48|.define CARG4d, r9d
49|.else
50|.define CARG1, rsi // x64/POSIX C call arguments.
51|.define CARG2, rdi
52|.define CARG3, rdx
53|.define CARG4, rcx
54|.define CARG5, r8
55|.define CARG6, r9
56|.define CARG1d, esi
57|.define CARG2d, edi
58|.define CARG3d, edx
59|.define CARG4d, ecx
60|.define CARG5d, r8d
61|.define CARG6d, r9d
62|.endif
35| 63|
36|// Type definitions. Some of these are only used for documentation. 64|// Type definitions. Some of these are only used for documentation.
37|.type L, lua_State 65|.type L, lua_State
@@ -49,12 +77,26 @@
49|.type TRACE, Trace 77|.type TRACE, Trace
50|.type EXITINFO, ExitInfo 78|.type EXITINFO, ExitInfo
51| 79|
80|// x86/x64 portability macros
81|.macro push_eax; .if X64; push rax; .else; push eax; .endif; .endmacro
82|.macro pop_eax; .if X64; pop rax; .else; pop eax; .endif; .endmacro
83|
52|// Stack layout while in interpreter. Must match with lj_frame.h. 84|// Stack layout while in interpreter. Must match with lj_frame.h.
53|.macro saveregs 85|.macro saveregs
54| push ebp; push edi; push esi; push ebx 86| .if X64
87| .if X64WIN; push rdi; push rsi; .endif
88| push rbp; push rbx; push r12; push r13; push r14; push r15
89| .else
90| push ebp; push edi; push esi; push ebx
91| .endif
55|.endmacro 92|.endmacro
56|.macro restoreregs 93|.macro restoreregs
57| pop ebx; pop esi; pop edi; pop ebp 94| .if X64
95| pop r15; pop r14; pop r13; pop r12; pop rbx; pop rbp
96| .if X64WIN; pop rsi; pop rdi; .endif
97| .else
98| pop ebx; pop esi; pop edi; pop ebp
99| .endif
58|.endmacro 100|.endmacro
59|.define CFRAME_SPACE, aword*7 // Delta for esp (see <--). 101|.define CFRAME_SPACE, aword*7 // Delta for esp (see <--).
60| 102|
@@ -1567,9 +1609,9 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
1567 ||if (cmov) { 1609 ||if (cmov) {
1568 | fucomi st1; cmovop st1; fpop1 1610 | fucomi st1; cmovop st1; fpop1
1569 ||} else { 1611 ||} else {
1570 | push eax 1612 | push_eax
1571 | fucom st1; fnstsw ax; test ah, 1; nocmovop >2; fxch; 2: ; fpop 1613 | fucom st1; fnstsw ax; test ah, 1; nocmovop >2; fxch; 2: ; fpop
1572 | pop eax 1614 | pop_eax
1573 ||} 1615 ||}
1574 | add RB, 1 1616 | add RB, 1
1575 | jmp <1 1617 | jmp <1
@@ -2135,7 +2177,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2135 ||if (cmov) { 2177 ||if (cmov) {
2136 | fucomip st1 2178 | fucomip st1
2137 ||} else { 2179 ||} else {
2138 | push eax; fucomp st1; fnstsw ax; sahf; pop eax 2180 | push_eax; fucomp st1; fnstsw ax; sahf; pop_eax
2139 ||} 2181 ||}
2140 | jnz >8 // Branch for FP exponents. 2182 | jnz >8 // Branch for FP exponents.
2141 | jp >9 // Branch for NaN exponent. 2183 | jp >9 // Branch for NaN exponent.
@@ -2145,7 +2187,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2145 |// Arg2 (int) on C stack. No int/xmm regs modified. 2187 |// Arg2 (int) on C stack. No int/xmm regs modified.
2146 |// Caveat: needs 2 slots on x87 stack! 2188 |// Caveat: needs 2 slots on x87 stack!
2147 |->vm_powi: 2189 |->vm_powi:
2148 | push eax 2190 | push_eax
2149 | mov eax, [esp+8] 2191 | mov eax, [esp+8]
2150 | cmp eax, 1; jle >6 // i<=1? 2192 | cmp eax, 1; jle >6 // i<=1?
2151 | // Now 1 < (unsigned)i <= 0x80000000. 2193 | // Now 1 < (unsigned)i <= 0x80000000.
@@ -2166,7 +2208,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2166 |4: 2208 |4:
2167 | fmulp st1 2209 | fmulp st1
2168 |5: 2210 |5:
2169 | pop eax 2211 | pop_eax
2170 | ret 2212 | ret
2171 |6: 2213 |6:
2172 | je <5 // x^1 ==> x 2214 | je <5 // x^1 ==> x
@@ -2177,11 +2219,11 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2177 | jmp <1 // x^-i ==> (1/x)^i 2219 | jmp <1 // x^-i ==> (1/x)^i
2178 |7: 2220 |7:
2179 | fpop; fld1 // x^0 ==> 1 2221 | fpop; fld1 // x^0 ==> 1
2180 | pop eax 2222 | pop_eax
2181 | ret 2223 | ret
2182 | 2224 |
2183 |8: // FP/FP power function x^y. 2225 |8: // FP/FP power function x^y.
2184 | push eax 2226 | push_eax
2185 | fst dword [esp+8] 2227 | fst dword [esp+8]
2186 | fxch 2228 | fxch
2187 | fst dword [esp+12] 2229 | fst dword [esp+12]
@@ -2189,7 +2231,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2189 | cmp eax, 0xff000000; je >2 // x^+-Inf? 2231 | cmp eax, 0xff000000; je >2 // x^+-Inf?
2190 | mov eax, [esp+12]; shl eax, 1; je >4 // +-0^y? 2232 | mov eax, [esp+12]; shl eax, 1; je >4 // +-0^y?
2191 | cmp eax, 0xff000000; je >4 // +-Inf^y? 2233 | cmp eax, 0xff000000; je >4 // +-Inf^y?
2192 | pop eax 2234 | pop_eax
2193 | fyl2x 2235 | fyl2x
2194 | jmp ->vm_exp2raw 2236 | jmp ->vm_exp2raw
2195 | 2237 |
@@ -2198,7 +2240,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2198 ||if (cmov) { 2240 ||if (cmov) {
2199 | fucomip st2 2241 | fucomip st2
2200 ||} else { 2242 ||} else {
2201 | push eax; fucomp st2; fnstsw ax; sahf; pop eax 2243 | push_eax; fucomp st2; fnstsw ax; sahf; pop_eax
2202 ||} 2244 ||}
2203 | je >1 // 1^NaN ==> 1 2245 | je >1 // 1^NaN ==> 1
2204 | fxch // x^NaN ==> NaN 2246 | fxch // x^NaN ==> NaN
@@ -2219,13 +2261,13 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2219 | ror eax, 1; xor eax, [esp+8]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0 2261 | ror eax, 1; xor eax, [esp+8]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0
2220 | fxch 2262 | fxch
2221 |3: 2263 |3:
2222 | fpop1; fabs; pop eax 2264 | fpop1; fabs; pop_eax
2223 | ret 2265 | ret
2224 | 2266 |
2225 |4: // Handle +-0^y or +-Inf^y. 2267 |4: // Handle +-0^y or +-Inf^y.
2226 | cmp dword [esp+8], 0; jge <3 // y >= 0, x^y ==> |x| 2268 | cmp dword [esp+8], 0; jge <3 // y >= 0, x^y ==> |x|
2227 | fpop; fpop 2269 | fpop; fpop
2228 | test eax, eax; pop eax; jz >5 // y < 0, +-0^y ==> +Inf 2270 | test eax, eax; pop_eax; jz >5 // y < 0, +-0^y ==> +Inf
2229 | fldz // y < 0, +-Inf^y ==> 0 2271 | fldz // y < 0, +-Inf^y ==> 0
2230 | ret 2272 | ret
2231 |5: 2273 |5:
@@ -2289,6 +2331,19 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2289 | 2331 |
2290 |// int lj_vm_cpuid(uint32_t f, uint32_t res[4]) 2332 |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])
2291 |->vm_cpuid: 2333 |->vm_cpuid:
2334 |.if X64
2335 | mov eax, CARG1d
2336 | .if X64WIN; push rsi; mov rsi, CARG2; .endif
2337 | push rbx
2338 | cpuid
2339 | mov [rsi], eax
2340 | mov [rsi+4], ebx
2341 | mov [rsi+8], ecx
2342 | mov [rsi+12], edx
2343 | pop rbx
2344 | .if X64WIN; pop rsi; .endif
2345 | ret
2346 |.else
2292 | pushfd 2347 | pushfd
2293 | pop edx 2348 | pop edx
2294 | mov ecx, edx 2349 | mov ecx, edx
@@ -2313,6 +2368,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
2313 | pop edi 2368 | pop edi
2314 |1: 2369 |1:
2315 | ret 2370 | ret
2371 |.endif
2316 | 2372 |
2317 |//----------------------------------------------------------------------- 2373 |//-----------------------------------------------------------------------
2318} 2374}