diff options
Diffstat (limited to '')
-rw-r--r-- | src/vm_mips64.dasc | 237 |
1 files changed, 225 insertions, 12 deletions
diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc index c518c306..f0c22a74 100644 --- a/src/vm_mips64.dasc +++ b/src/vm_mips64.dasc | |||
@@ -327,7 +327,13 @@ | |||
327 | |.macro jmp_extern; jr CFUNCADDR; .endmacro | 327 | |.macro jmp_extern; jr CFUNCADDR; .endmacro |
328 | | | 328 | | |
329 | |.macro hotcheck, delta, target | 329 | |.macro hotcheck, delta, target |
330 | | NYI | 330 | | dsrl TMP1, PC, 1 |
331 | | andi TMP1, TMP1, 126 | ||
332 | | daddu TMP1, TMP1, DISPATCH | ||
333 | | lhu TMP2, GG_DISP2HOT(TMP1) | ||
334 | | addiu TMP2, TMP2, -delta | ||
335 | | bltz TMP2, target | ||
336 | |. sh TMP2, GG_DISP2HOT(TMP1) | ||
331 | |.endmacro | 337 | |.endmacro |
332 | | | 338 | | |
333 | |.macro hotloop | 339 | |.macro hotloop |
@@ -2150,7 +2156,21 @@ static void build_subroutines(BuildCtx *ctx) | |||
2150 | |//----------------------------------------------------------------------- | 2156 | |//----------------------------------------------------------------------- |
2151 | | | 2157 | | |
2152 | |->vm_record: // Dispatch target for recording phase. | 2158 | |->vm_record: // Dispatch target for recording phase. |
2153 | | NYI | 2159 | |.if JIT |
2160 | | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) | ||
2161 | | andi AT, TMP3, HOOK_VMEVENT // No recording while in vmevent. | ||
2162 | | bnez AT, >5 | ||
2163 | | // Decrement the hookcount for consistency, but always do the call. | ||
2164 | |. lw TMP2, DISPATCH_GL(hookcount)(DISPATCH) | ||
2165 | | andi AT, TMP3, HOOK_ACTIVE | ||
2166 | | bnez AT, >1 | ||
2167 | |. addiu TMP2, TMP2, -1 | ||
2168 | | andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT | ||
2169 | | beqz AT, >1 | ||
2170 | |. nop | ||
2171 | | b >1 | ||
2172 | |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH) | ||
2173 | |.endif | ||
2154 | | | 2174 | | |
2155 | |->vm_rethook: // Dispatch target for return hooks. | 2175 | |->vm_rethook: // Dispatch target for return hooks. |
2156 | | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) | 2176 | | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) |
@@ -2201,7 +2221,25 @@ static void build_subroutines(BuildCtx *ctx) | |||
2201 | |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins. | 2221 | |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins. |
2202 | | | 2222 | | |
2203 | |->vm_hotloop: // Hot loop counter underflow. | 2223 | |->vm_hotloop: // Hot loop counter underflow. |
2204 | | NYI | 2224 | |.if JIT |
2225 | | ld LFUNC:TMP1, FRAME_FUNC(BASE) | ||
2226 | | daddiu CARG1, DISPATCH, GG_DISP2J | ||
2227 | | cleartp LFUNC:TMP1 | ||
2228 | | sd PC, SAVE_PC | ||
2229 | | ld TMP1, LFUNC:TMP1->pc | ||
2230 | | move CARG2, PC | ||
2231 | | sd L, DISPATCH_J(L)(DISPATCH) | ||
2232 | | lbu TMP1, PC2PROTO(framesize)(TMP1) | ||
2233 | | load_got lj_trace_hot | ||
2234 | | sd BASE, L->base | ||
2235 | | dsll TMP1, TMP1, 3 | ||
2236 | | daddu TMP1, BASE, TMP1 | ||
2237 | | call_intern lj_trace_hot // (jit_State *J, const BCIns *pc) | ||
2238 | |. sd TMP1, L->top | ||
2239 | | b <3 | ||
2240 | |. nop | ||
2241 | |.endif | ||
2242 | | | ||
2205 | | | 2243 | | |
2206 | |->vm_callhook: // Dispatch target for call hooks. | 2244 | |->vm_callhook: // Dispatch target for call hooks. |
2207 | |.if JIT | 2245 | |.if JIT |
@@ -2235,21 +2273,69 @@ static void build_subroutines(BuildCtx *ctx) | |||
2235 | | | 2273 | | |
2236 | |->cont_stitch: // Trace stitching. | 2274 | |->cont_stitch: // Trace stitching. |
2237 | |.if JIT | 2275 | |.if JIT |
2238 | | NYI | 2276 | | // RA = resultptr, RB = meta base |
2277 | | lw INS, -4(PC) | ||
2278 | | ld TRACE:TMP2, -40(RB) // Save previous trace. | ||
2279 | | decode_RA8a RC, INS | ||
2280 | | daddiu AT, MULTRES, -8 | ||
2281 | | cleartp TRACE:TMP2 | ||
2282 | | decode_RA8b RC | ||
2283 | | beqz AT, >2 | ||
2284 | |. daddu RC, BASE, RC // Call base. | ||
2285 | |1: // Move results down. | ||
2286 | | ld CARG1, 0(RA) | ||
2287 | | daddiu AT, AT, -8 | ||
2288 | | daddiu RA, RA, 8 | ||
2289 | | sd CARG1, 0(RC) | ||
2290 | | bnez AT, <1 | ||
2291 | |. daddiu RC, RC, 8 | ||
2292 | |2: | ||
2293 | | decode_RA8a RA, INS | ||
2294 | | decode_RB8a RB, INS | ||
2295 | | decode_RA8b RA | ||
2296 | | decode_RB8b RB | ||
2297 | | daddu RA, RA, RB | ||
2298 | | daddu RA, BASE, RA | ||
2299 | |3: | ||
2300 | | sltu AT, RC, RA | ||
2301 | | bnez AT, >9 // More results wanted? | ||
2302 | |. nop | ||
2303 | | | ||
2304 | | lhu TMP3, TRACE:TMP2->traceno | ||
2305 | | lhu RD, TRACE:TMP2->link | ||
2306 | | beq RD, TMP3, ->cont_nop // Blacklisted. | ||
2307 | |. load_got lj_dispatch_stitch | ||
2308 | | bnez RD, =>BC_JLOOP // Jump to stitched trace. | ||
2309 | |. sll RD, RD, 3 | ||
2310 | | | ||
2311 | | // Stitch a new trace to the previous trace. | ||
2312 | | sw TMP3, DISPATCH_J(exitno)(DISPATCH) | ||
2313 | | sd L, DISPATCH_J(L)(DISPATCH) | ||
2314 | | sd BASE, L->base | ||
2315 | | daddiu CARG1, DISPATCH, GG_DISP2J | ||
2316 | | call_intern lj_dispatch_stitch // (jit_State *J, const BCIns *pc) | ||
2317 | |. move CARG2, PC | ||
2318 | | b ->cont_nop | ||
2319 | |. ld BASE, L->base | ||
2320 | | | ||
2321 | |9: | ||
2322 | | sd TISNIL, 0(RC) | ||
2323 | | b <3 | ||
2324 | |. daddiu RC, RC, 8 | ||
2239 | |.endif | 2325 | |.endif |
2240 | | | 2326 | | |
2241 | |->vm_profhook: // Dispatch target for profiler hook. | 2327 | |->vm_profhook: // Dispatch target for profiler hook. |
2242 | #if LJ_HASPROFILE | 2328 | #if LJ_HASPROFILE |
2243 | | load_got lj_dispatch_profile | 2329 | | load_got lj_dispatch_profile |
2244 | | sw MULTRES, SAVE_MULTRES | 2330 | | sd MULTRES, SAVE_MULTRES |
2245 | | move CARG2, PC | 2331 | | move CARG2, PC |
2246 | | sw BASE, L->base | 2332 | | sd BASE, L->base |
2247 | | call_intern lj_dispatch_profile // (lua_State *L, const BCIns *pc) | 2333 | | call_intern lj_dispatch_profile // (lua_State *L, const BCIns *pc) |
2248 | |. move CARG1, L | 2334 | |. move CARG1, L |
2249 | | // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction. | 2335 | | // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction. |
2250 | | daddiu PC, PC, -4 | 2336 | | daddiu PC, PC, -4 |
2251 | | b ->cont_nop | 2337 | | b ->cont_nop |
2252 | |. lw BASE, L->base | 2338 | |. ld BASE, L->base |
2253 | #endif | 2339 | #endif |
2254 | | | 2340 | | |
2255 | |//----------------------------------------------------------------------- | 2341 | |//----------------------------------------------------------------------- |
@@ -2259,6 +2345,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
2259 | |.macro savex_, a, b | 2345 | |.macro savex_, a, b |
2260 | |.if FPU | 2346 | |.if FPU |
2261 | | sdc1 f..a, a*8(sp) | 2347 | | sdc1 f..a, a*8(sp) |
2348 | | sdc1 f..b, b*8(sp) | ||
2262 | | sd r..a, 32*8+a*8(sp) | 2349 | | sd r..a, 32*8+a*8(sp) |
2263 | | sd r..b, 32*8+b*8(sp) | 2350 | | sd r..b, 32*8+b*8(sp) |
2264 | |.else | 2351 | |.else |
@@ -2269,11 +2356,124 @@ static void build_subroutines(BuildCtx *ctx) | |||
2269 | | | 2356 | | |
2270 | |->vm_exit_handler: | 2357 | |->vm_exit_handler: |
2271 | |.if JIT | 2358 | |.if JIT |
2272 | | NYI | 2359 | |.if FPU |
2360 | | daddiu sp, sp, -(32*8+32*8) | ||
2361 | |.else | ||
2362 | | daddiu sp, sp, -(32*8) | ||
2363 | |.endif | ||
2364 | | savex_ 0, 1 | ||
2365 | | savex_ 2, 3 | ||
2366 | | savex_ 4, 5 | ||
2367 | | savex_ 6, 7 | ||
2368 | | savex_ 8, 9 | ||
2369 | | savex_ 10, 11 | ||
2370 | | savex_ 12, 13 | ||
2371 | | savex_ 14, 15 | ||
2372 | | savex_ 16, 17 | ||
2373 | | savex_ 18, 19 | ||
2374 | | savex_ 20, 21 | ||
2375 | | savex_ 22, 23 | ||
2376 | | savex_ 24, 25 | ||
2377 | | savex_ 26, 27 | ||
2378 | | savex_ 28, 30 | ||
2379 | |.if FPU | ||
2380 | | sdc1 f29, 29*8(sp) | ||
2381 | | sdc1 f31, 31*8(sp) | ||
2382 | | sd r0, 32*8+31*8(sp) // Clear RID_TMP. | ||
2383 | | daddiu TMP2, sp, 32*8+32*8 // Recompute original value of sp. | ||
2384 | | sd TMP2, 32*8+29*8(sp) // Store sp in RID_SP | ||
2385 | |.else | ||
2386 | | sd r0, 31*8(sp) // Clear RID_TMP. | ||
2387 | | daddiu TMP2, sp, 32*8 // Recompute original value of sp. | ||
2388 | | sd TMP2, 29*8(sp) // Store sp in RID_SP | ||
2389 | |.endif | ||
2390 | | li_vmstate EXIT | ||
2391 | | daddiu DISPATCH, JGL, -GG_DISP2G-32768 | ||
2392 | | lw TMP1, 0(TMP2) // Load exit number. | ||
2393 | | st_vmstate | ||
2394 | | ld L, DISPATCH_GL(cur_L)(DISPATCH) | ||
2395 | | ld BASE, DISPATCH_GL(jit_base)(DISPATCH) | ||
2396 | | load_got lj_trace_exit | ||
2397 | | sd L, DISPATCH_J(L)(DISPATCH) | ||
2398 | | sw ra, DISPATCH_J(parent)(DISPATCH) // Store trace number. | ||
2399 | | sd BASE, L->base | ||
2400 | | sw TMP1, DISPATCH_J(exitno)(DISPATCH) // Store exit number. | ||
2401 | | daddiu CARG1, DISPATCH, GG_DISP2J | ||
2402 | | sd r0, DISPATCH_GL(jit_base)(DISPATCH) | ||
2403 | | call_intern lj_trace_exit // (jit_State *J, ExitState *ex) | ||
2404 | |. move CARG2, sp | ||
2405 | | // Returns MULTRES (unscaled) or negated error code. | ||
2406 | | ld TMP1, L->cframe | ||
2407 | | li AT, -4 | ||
2408 | | ld BASE, L->base | ||
2409 | | and sp, TMP1, AT | ||
2410 | | ld PC, SAVE_PC // Get SAVE_PC. | ||
2411 | | b >1 | ||
2412 | |. sd L, SAVE_L // Set SAVE_L (on-trace resume/yield). | ||
2273 | |.endif | 2413 | |.endif |
2274 | |->vm_exit_interp: | 2414 | |->vm_exit_interp: |
2275 | |.if JIT | 2415 | |.if JIT |
2276 | | NYI | 2416 | | // CRET1 = MULTRES or negated error code, BASE, PC and JGL set. |
2417 | | ld L, SAVE_L | ||
2418 | | daddiu DISPATCH, JGL, -GG_DISP2G-32768 | ||
2419 | | sd BASE, L->base | ||
2420 | |1: | ||
2421 | | bltz CRET1, >9 // Check for error from exit. | ||
2422 | |. ld LFUNC:RB, FRAME_FUNC(BASE) | ||
2423 | | .FPU lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). | ||
2424 | | dsll MULTRES, CRET1, 3 | ||
2425 | | cleartp LFUNC:RB | ||
2426 | | sd MULTRES, SAVE_MULTRES | ||
2427 | | li TISNIL, LJ_TNIL | ||
2428 | | li TISNUM, LJ_TISNUM // Setup type comparison constants. | ||
2429 | | .FPU mtc1 TMP3, TOBIT | ||
2430 | | ld TMP1, LFUNC:RB->pc | ||
2431 | | sd r0, DISPATCH_GL(jit_base)(DISPATCH) | ||
2432 | | ld KBASE, PC2PROTO(k)(TMP1) | ||
2433 | | .FPU cvt.d.s TOBIT, TOBIT | ||
2434 | | // Modified copy of ins_next which handles function header dispatch, too. | ||
2435 | | lw INS, 0(PC) | ||
2436 | | daddiu PC, PC, 4 | ||
2437 | | // Assumes TISNIL == ~LJ_VMST_INTERP == -1 | ||
2438 | | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) | ||
2439 | | decode_OP8a TMP1, INS | ||
2440 | | decode_OP8b TMP1 | ||
2441 | | sltiu TMP2, TMP1, BC_FUNCF*8 | ||
2442 | | daddu TMP0, DISPATCH, TMP1 | ||
2443 | | decode_RD8a RD, INS | ||
2444 | | ld AT, 0(TMP0) | ||
2445 | | decode_RA8a RA, INS | ||
2446 | | beqz TMP2, >2 | ||
2447 | |. decode_RA8b RA | ||
2448 | | jr AT | ||
2449 | |. decode_RD8b RD | ||
2450 | |2: | ||
2451 | | sltiu TMP2, TMP1, (BC_FUNCC+2)*8 // Fast function? | ||
2452 | | bnez TMP2, >3 | ||
2453 | |. ld TMP1, FRAME_PC(BASE) | ||
2454 | | // Check frame below fast function. | ||
2455 | | andi TMP0, TMP1, FRAME_TYPE | ||
2456 | | bnez TMP0, >3 // Trace stitching continuation? | ||
2457 | |. nop | ||
2458 | | // Otherwise set KBASE for Lua function below fast function. | ||
2459 | | lw TMP2, -4(TMP1) | ||
2460 | | decode_RA8a TMP0, TMP2 | ||
2461 | | decode_RA8b TMP0 | ||
2462 | | dsubu TMP1, BASE, TMP0 | ||
2463 | | ld LFUNC:TMP2, -32(TMP1) | ||
2464 | | cleartp LFUNC:TMP2 | ||
2465 | | ld TMP1, LFUNC:TMP2->pc | ||
2466 | | ld KBASE, PC2PROTO(k)(TMP1) | ||
2467 | |3: | ||
2468 | | daddiu RC, MULTRES, -8 | ||
2469 | | jr AT | ||
2470 | |. daddu RA, RA, BASE | ||
2471 | | | ||
2472 | |9: // Rethrow error from the right C frame. | ||
2473 | | load_got lj_err_throw | ||
2474 | | negu CARG2, CRET1 | ||
2475 | | call_intern lj_err_throw // (lua_State *L, int errcode) | ||
2476 | |. move CARG1, L | ||
2277 | |.endif | 2477 | |.endif |
2278 | | | 2478 | | |
2279 | |//----------------------------------------------------------------------- | 2479 | |//----------------------------------------------------------------------- |
@@ -4013,7 +4213,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4013 | | ins_next2 | 4213 | | ins_next2 |
4014 | | | 4214 | | |
4015 | |7: // Possible table write barrier for the value. Skip valiswhite check. | 4215 | |7: // Possible table write barrier for the value. Skip valiswhite check. |
4016 | | barrierback TAB:RB, TMP3, TMP0, <2 | 4216 | | barrierback TAB:CARG2, TMP3, TMP0, <2 |
4017 | break; | 4217 | break; |
4018 | 4218 | ||
4019 | case BC_TSETM: | 4219 | case BC_TSETM: |
@@ -4632,7 +4832,18 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4632 | 4832 | ||
4633 | case BC_JLOOP: | 4833 | case BC_JLOOP: |
4634 | |.if JIT | 4834 | |.if JIT |
4635 | | NYI | 4835 | | // RA = base*8 (ignored), RD = traceno*8 |
4836 | | ld TMP1, DISPATCH_J(trace)(DISPATCH) | ||
4837 | | li AT, 0 | ||
4838 | | daddu TMP1, TMP1, RD | ||
4839 | | // Traces on MIPS don't store the trace number, so use 0. | ||
4840 | | sd AT, DISPATCH_GL(vmstate)(DISPATCH) | ||
4841 | | ld TRACE:TMP2, 0(TMP1) | ||
4842 | | sd BASE, DISPATCH_GL(jit_base)(DISPATCH) | ||
4843 | | ld TMP2, TRACE:TMP2->mcode | ||
4844 | | sd L, DISPATCH_GL(tmpbuf.L)(DISPATCH) | ||
4845 | | jr TMP2 | ||
4846 | |. daddiu JGL, DISPATCH, GG_DISP2G+32768 | ||
4636 | |.endif | 4847 | |.endif |
4637 | break; | 4848 | break; |
4638 | 4849 | ||
@@ -4694,10 +4905,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4694 | 4905 | ||
4695 | case BC_IFUNCV: | 4906 | case BC_IFUNCV: |
4696 | | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 | 4907 | | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8 |
4908 | | li TMP0, LJ_TFUNC | ||
4697 | | daddu TMP1, BASE, RC | 4909 | | daddu TMP1, BASE, RC |
4698 | | ld TMP2, L->maxstack | 4910 | | ld TMP2, L->maxstack |
4911 | | settp LFUNC:RB, TMP0 | ||
4699 | | daddu TMP0, RA, RC | 4912 | | daddu TMP0, RA, RC |
4700 | | sd LFUNC:RB, 0(TMP1) // Store (untagged) copy of LFUNC. | 4913 | | sd LFUNC:RB, 0(TMP1) // Store (tagged) copy of LFUNC. |
4701 | | daddiu TMP3, RC, 16+FRAME_VARG | 4914 | | daddiu TMP3, RC, 16+FRAME_VARG |
4702 | | sltu AT, TMP0, TMP2 | 4915 | | sltu AT, TMP0, TMP2 |
4703 | | ld KBASE, -4+PC2PROTO(k)(PC) | 4916 | | ld KBASE, -4+PC2PROTO(k)(PC) |