diff options
Diffstat (limited to 'src/buildvm_ppc.dasc')
-rw-r--r-- | src/buildvm_ppc.dasc | 186 |
1 files changed, 175 insertions, 11 deletions
diff --git a/src/buildvm_ppc.dasc b/src/buildvm_ppc.dasc index bbe5c741..bc2382ac 100644 --- a/src/buildvm_ppc.dasc +++ b/src/buildvm_ppc.dasc | |||
@@ -16,7 +16,7 @@ | |||
16 | |//----------------------------------------------------------------------- | 16 | |//----------------------------------------------------------------------- |
17 | | | 17 | | |
18 | |// Fixed register assignments for the interpreter. | 18 | |// Fixed register assignments for the interpreter. |
19 | |// Don't use: r1 = sp, r2 and r13 = reserved and/or small data area ptr | 19 | |// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA) |
20 | | | 20 | | |
21 | |// The following must be C callee-save (but BASE is often refetched). | 21 | |// The following must be C callee-save (but BASE is often refetched). |
22 | |.define BASE, r14 // Base of current Lua stack frame. | 22 | |.define BASE, r14 // Base of current Lua stack frame. |
@@ -25,6 +25,8 @@ | |||
25 | |.define DISPATCH, r17 // Opcode dispatch table. | 25 | |.define DISPATCH, r17 // Opcode dispatch table. |
26 | |.define LREG, r18 // Register holding lua_State (also in SAVE_L). | 26 | |.define LREG, r18 // Register holding lua_State (also in SAVE_L). |
27 | |.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. | 27 | |.define MULTRES, r19 // Size of multi-result: (nresults+1)*8. |
28 | |.define JGL, r30 // On-trace: global_State + 32768. | ||
29 | |.define JTR, r31 // On-trace: trace number. | ||
28 | | | 30 | | |
29 | |// Constants for type-comparisons, stores and conversions. C callee-save. | 31 | |// Constants for type-comparisons, stores and conversions. C callee-save. |
30 | |.define TISNUM, r22 | 32 | |.define TISNUM, r22 |
@@ -267,12 +269,21 @@ | |||
267 | | | 269 | | |
268 | #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) | 270 | #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) |
269 | | | 271 | | |
272 | |.macro hotcheck, delta, target | ||
273 | | rlwinm TMP1, PC, 31, 25, 30 | ||
274 | | addi TMP1, TMP1, GG_DISP2HOT | ||
275 | | lhzx TMP2, DISPATCH, TMP1 | ||
276 | | addic. TMP2, TMP2, -delta | ||
277 | | sthx TMP2, DISPATCH, TMP1 | ||
278 | | blt target | ||
279 | |.endmacro | ||
280 | | | ||
270 | |.macro hotloop | 281 | |.macro hotloop |
271 | | NYI | 282 | | hotcheck HOTCOUNT_LOOP, ->vm_hotloop |
272 | |.endmacro | 283 | |.endmacro |
273 | | | 284 | | |
274 | |.macro hotcall | 285 | |.macro hotcall |
275 | | NYI | 286 | | hotcheck HOTCOUNT_CALL, ->vm_hotcall |
276 | |.endmacro | 287 | |.endmacro |
277 | | | 288 | | |
278 | |// Set current VM state. Uses TMP0. | 289 | |// Set current VM state. Uses TMP0. |
@@ -2202,7 +2213,18 @@ static void build_subroutines(BuildCtx *ctx) | |||
2202 | | | 2213 | | |
2203 | |->vm_record: // Dispatch target for recording phase. | 2214 | |->vm_record: // Dispatch target for recording phase. |
2204 | #if LJ_HASJIT | 2215 | #if LJ_HASJIT |
2205 | | NYI | 2216 | | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH) |
2217 | | andi. TMP0, TMP3, HOOK_VMEVENT // No recording while in vmevent. | ||
2218 | | bne >5 | ||
2219 | | // Decrement the hookcount for consistency, but always do the call. | ||
2220 | | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH) | ||
2221 | | andi. TMP0, TMP3, HOOK_ACTIVE | ||
2222 | | bne >1 | ||
2223 | | subi TMP2, TMP2, 1 | ||
2224 | | andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT | ||
2225 | | beqy >1 | ||
2226 | | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH) | ||
2227 | | b >1 | ||
2206 | #endif | 2228 | #endif |
2207 | | | 2229 | | |
2208 | |->vm_rethook: // Dispatch target for return hooks. | 2230 | |->vm_rethook: // Dispatch target for return hooks. |
@@ -2256,7 +2278,19 @@ static void build_subroutines(BuildCtx *ctx) | |||
2256 | | | 2278 | | |
2257 | |->vm_hotloop: // Hot loop counter underflow. | 2279 | |->vm_hotloop: // Hot loop counter underflow. |
2258 | #if LJ_HASJIT | 2280 | #if LJ_HASJIT |
2259 | | NYI | 2281 | | lwz LFUNC:TMP1, FRAME_FUNC(BASE) |
2282 | | addi CARG1, DISPATCH, GG_DISP2J | ||
2283 | | stw PC, SAVE_PC | ||
2284 | | lwz TMP1, LFUNC:TMP1->pc | ||
2285 | | mr CARG2, PC | ||
2286 | | stw L, DISPATCH_J(L)(DISPATCH) | ||
2287 | | lbz TMP1, PC2PROTO(framesize)(TMP1) | ||
2288 | | stw BASE, L->base | ||
2289 | | slwi TMP1, TMP1, 3 | ||
2290 | | add TMP1, BASE, TMP1 | ||
2291 | | stw TMP1, L->top | ||
2292 | | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) | ||
2293 | | b <3 | ||
2260 | #endif | 2294 | #endif |
2261 | | | 2295 | | |
2262 | |->vm_callhook: // Dispatch target for call hooks. | 2296 | |->vm_callhook: // Dispatch target for call hooks. |
@@ -2291,13 +2325,111 @@ static void build_subroutines(BuildCtx *ctx) | |||
2291 | |//-- Trace exit handler ------------------------------------------------- | 2325 | |//-- Trace exit handler ------------------------------------------------- |
2292 | |//----------------------------------------------------------------------- | 2326 | |//----------------------------------------------------------------------- |
2293 | | | 2327 | | |
2328 | |.macro savex_, a, b, c, d | ||
2329 | | stfd f..a, 16+a*8(sp) | ||
2330 | | stfd f..b, 16+b*8(sp) | ||
2331 | | stfd f..c, 16+c*8(sp) | ||
2332 | | stfd f..d, 16+d*8(sp) | ||
2333 | |.endmacro | ||
2334 | | | ||
2294 | |->vm_exit_handler: | 2335 | |->vm_exit_handler: |
2295 | #if LJ_HASJIT | 2336 | #if LJ_HASJIT |
2296 | | NYI | 2337 | | addi sp, sp, -(16+32*8+32*4) |
2338 | | stmw r2, 16+32*8+2*4(sp) | ||
2339 | | addi DISPATCH, JGL, -GG_DISP2G-32768 | ||
2340 | | li CARG2, ~LJ_VMST_EXIT | ||
2341 | | lwz CARG1, 16+32*8+32*4(sp) // Get stack chain. | ||
2342 | | stw CARG2, DISPATCH_GL(vmstate)(DISPATCH) | ||
2343 | | savex_ 0,1,2,3 | ||
2344 | | stw CARG1, 0(sp) // Store extended stack chain. | ||
2345 | | mcrxr cr0 // Clear SO flag. | ||
2346 | | savex_ 4,5,6,7 | ||
2347 | | addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp. | ||
2348 | | savex_ 8,9,10,11 | ||
2349 | | stw CARG2, 16+32*8+1*4(sp) // Store sp in RID_SP. | ||
2350 | | savex_ 12,13,14,15 | ||
2351 | | mflr CARG3 | ||
2352 | | li TMP1, 0 | ||
2353 | | savex_ 16,17,18,19 | ||
2354 | | stw TMP1, 16+32*8+0*4(sp) // Clear RID_TMP. | ||
2355 | | savex_ 20,21,22,23 | ||
2356 | | lwz CARG4, 0(CARG3) // Load exit stub group offset. | ||
2357 | | savex_ 24,25,26,27 | ||
2358 | | lwz L, DISPATCH_GL(jit_L)(DISPATCH) | ||
2359 | | savex_ 28,29,30,31 | ||
2360 | | sub CARG3, TMP0, CARG3 // Compute exit number. | ||
2361 | | lwz BASE, DISPATCH_GL(jit_base)(DISPATCH) | ||
2362 | | srwi CARG3, CARG3, 2 | ||
2363 | | stw L, DISPATCH_J(L)(DISPATCH) | ||
2364 | | subi CARG3, CARG3, 2 | ||
2365 | | stw TMP1, DISPATCH_GL(jit_L)(DISPATCH) | ||
2366 | | add CARG3, CARG4, CARG3 | ||
2367 | | stw BASE, L->base | ||
2368 | | addi CARG1, DISPATCH, GG_DISP2J | ||
2369 | | stw CARG3, DISPATCH_J(exitno)(DISPATCH) | ||
2370 | | addi CARG2, sp, 16 | ||
2371 | | stw JTR, DISPATCH_J(parent)(DISPATCH) | ||
2372 | | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) | ||
2373 | | // Returns MULTRES (unscaled) or negated error code. | ||
2374 | | lwz TMP1, L->cframe | ||
2375 | | lwz TMP2, 0(sp) | ||
2376 | | lwz BASE, L->base | ||
2377 | | rlwinm sp, TMP1, 0, 0, 29 | ||
2378 | | lwz PC, SAVE_PC // Get SAVE_PC. | ||
2379 | | stw TMP2, 0(sp) | ||
2380 | | stw L, SAVE_L // Set SAVE_L (on-trace resume/yield). | ||
2381 | | b >1 | ||
2297 | #endif | 2382 | #endif |
2298 | |->vm_exit_interp: | 2383 | |->vm_exit_interp: |
2299 | #if LJ_HASJIT | 2384 | #if LJ_HASJIT |
2300 | | NYI | 2385 | | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set. |
2386 | | lwz L, SAVE_L | ||
2387 | | addi DISPATCH, JGL, -GG_DISP2G-32768 | ||
2388 | |1: | ||
2389 | | cmpwi CARG1, 0 | ||
2390 | | blt >3 // Check for error from exit. | ||
2391 | | lwz LFUNC:TMP1, FRAME_FUNC(BASE) | ||
2392 | | slwi MULTRES, CARG1, 3 | ||
2393 | | li TMP2, 0 | ||
2394 | | stw MULTRES, SAVE_MULTRES | ||
2395 | | lwz TMP1, LFUNC:TMP1->pc | ||
2396 | | stw TMP2, DISPATCH_GL(jit_L)(DISPATCH) | ||
2397 | | lwz KBASE, PC2PROTO(k)(TMP1) | ||
2398 | | // Setup type comparison constants. | ||
2399 | | li TISNUM, LJ_TISNUM | ||
2400 | | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). | ||
2401 | | stw TMP3, TMPD | ||
2402 | | li ZERO, 0 | ||
2403 | | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float). | ||
2404 | | lfs TOBIT, TMPD | ||
2405 | | stw TMP3, TMPD | ||
2406 | | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double) | ||
2407 | | li TISNIL, LJ_TNIL | ||
2408 | | stw TMP0, TONUM_HI | ||
2409 | | lfs TONUM, TMPD | ||
2410 | | // Modified copy of ins_next which handles function header dispatch, too. | ||
2411 | | lwz INS, 0(PC) | ||
2412 | | addi PC, PC, 4 | ||
2413 | | // Assumes TISNIL == ~LJ_VMST_INTERP == -1. | ||
2414 | | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) | ||
2415 | | decode_OP4 TMP1, INS | ||
2416 | | decode_RA8 RA, INS | ||
2417 | | lwzx TMP0, DISPATCH, TMP1 | ||
2418 | | mtctr TMP0 | ||
2419 | | cmpwi TMP1, BC_FUNCF*4 // Function header? | ||
2420 | | beq >2 | ||
2421 | | decode_RB8 RB, INS | ||
2422 | | decode_RD8 RD, INS | ||
2423 | | decode_RC8 RC, INS | ||
2424 | | bctr | ||
2425 | |2: | ||
2426 | | add RA, RA, BASE | ||
2427 | | bctr | ||
2428 | | | ||
2429 | |3: // Rethrow error from the right C frame. | ||
2430 | | neg CARG2, CARG1 | ||
2431 | | mr CARG1, L | ||
2432 | | bl extern lj_err_throw // (lua_State *L, int errcode) | ||
2301 | #endif | 2433 | #endif |
2302 | | | 2434 | | |
2303 | |//----------------------------------------------------------------------- | 2435 | |//----------------------------------------------------------------------- |
@@ -2368,7 +2500,24 @@ static void build_subroutines(BuildCtx *ctx) | |||
2368 | |1: | 2500 | |1: |
2369 | | fabs FARG1, FARG1; blr | 2501 | | fabs FARG1, FARG1; blr |
2370 | |2: | 2502 | |2: |
2503 | #if LJ_HASJIT | ||
2504 | | cmplwi CARG1, 9; beq >9; bgt >2 | ||
2505 | | b extern atan2 | ||
2506 | | // No support needed for IR_LDEXP. | ||
2507 | |2: | ||
2508 | | cmplwi CARG1, 11; bgt >9 | ||
2509 | | fsub f0, FARG1, FARG2 | ||
2510 | | beq >1 | ||
2511 | | fsel FARG1, f0, FARG2, FARG1 // IR_MAX | ||
2512 | | blr | ||
2513 | |1: | ||
2514 | | fsel FARG1, f0, FARG1, FARG2 // IR_MIN | ||
2515 | | blr | ||
2516 | |9: | ||
2517 | | NYI // Bad op. | ||
2518 | #else | ||
2371 | | NYI // Other operations only needed by JIT compiler. | 2519 | | NYI // Other operations only needed by JIT compiler. |
2520 | #endif | ||
2372 | | | 2521 | | |
2373 | |//----------------------------------------------------------------------- | 2522 | |//----------------------------------------------------------------------- |
2374 | |//-- Miscellaneous functions -------------------------------------------- | 2523 | |//-- Miscellaneous functions -------------------------------------------- |
@@ -4309,7 +4458,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4309 | | lwz TMP2, 4(RA) | 4458 | | lwz TMP2, 4(RA) |
4310 | | checknil TMP1; beq >1 // Stop if iterator returned nil. | 4459 | | checknil TMP1; beq >1 // Stop if iterator returned nil. |
4311 | if (op == BC_JITERL) { | 4460 | if (op == BC_JITERL) { |
4312 | | NYI | 4461 | | stw TMP1, -8(RA) |
4462 | | stw TMP2, -4(RA) | ||
4463 | | b =>BC_JLOOP | ||
4313 | } else { | 4464 | } else { |
4314 | | branch_RD // Otherwise save control var + branch. | 4465 | | branch_RD // Otherwise save control var + branch. |
4315 | | stw TMP1, -8(RA) | 4466 | | stw TMP1, -8(RA) |
@@ -4336,7 +4487,17 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4336 | 4487 | ||
4337 | case BC_JLOOP: | 4488 | case BC_JLOOP: |
4338 | #if LJ_HASJIT | 4489 | #if LJ_HASJIT |
4339 | | NYI | 4490 | | // RA = base*8 (ignored), RD = traceno*8 |
4491 | | lwz TMP1, DISPATCH_J(trace)(DISPATCH) | ||
4492 | | srwi RD, RD, 1 | ||
4493 | | lwzx TRACE:TMP2, TMP1, RD | ||
4494 | | mcrxr cr0 // Clear SO flag. | ||
4495 | | lwz TMP2, TRACE:TMP2->mcode | ||
4496 | | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) | ||
4497 | | mtctr TMP2 | ||
4498 | | stw L, DISPATCH_GL(jit_L)(DISPATCH) | ||
4499 | | addi JGL, DISPATCH, GG_DISP2G+32768 | ||
4500 | | bctr | ||
4340 | #endif | 4501 | #endif |
4341 | break; | 4502 | break; |
4342 | 4503 | ||
@@ -4368,12 +4529,15 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4368 | | cmplw RA, TMP2 | 4529 | | cmplw RA, TMP2 |
4369 | | slwi TMP1, TMP1, 3 | 4530 | | slwi TMP1, TMP1, 3 |
4370 | | bgt ->vm_growstack_l | 4531 | | bgt ->vm_growstack_l |
4371 | | ins_next1 | 4532 | if (op != BC_JFUNCF) { |
4533 | | ins_next1 | ||
4534 | } | ||
4372 | |2: | 4535 | |2: |
4373 | | cmplw NARGS8:RC, TMP1 // Check for missing parameters. | 4536 | | cmplw NARGS8:RC, TMP1 // Check for missing parameters. |
4374 | | ble >3 | 4537 | | ble >3 |
4375 | if (op == BC_JFUNCF) { | 4538 | if (op == BC_JFUNCF) { |
4376 | | NYI | 4539 | | decode_RD8 RD, INS |
4540 | | b =>BC_JLOOP | ||
4377 | } else { | 4541 | } else { |
4378 | | ins_next2 | 4542 | | ins_next2 |
4379 | } | 4543 | } |