diff options
author | Mike Pall <mike> | 2021-09-19 17:38:49 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2021-09-19 17:38:49 +0200 |
commit | c6f5ef649b645db9cf3d11d1b5c63602c49c6411 (patch) | |
tree | 4d299528ff4e77c2f9059b8e24c50755ff638d2d /src/vm_x64.dasc | |
parent | 4e0ea654a81e68b1bcd20ddc2026ff1bc9288b84 (diff) | |
download | luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.tar.gz luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.tar.bz2 luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.zip |
Refactor table traversal.
Sponsored by OpenResty Inc.
Diffstat (limited to 'src/vm_x64.dasc')
-rw-r--r-- | src/vm_x64.dasc | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc index 76ce071d..d2119bc4 100644 --- a/src/vm_x64.dasc +++ b/src/vm_x64.dasc | |||
@@ -1346,44 +1346,28 @@ static void build_subroutines(BuildCtx *ctx) | |||
1346 | |.ffunc_1 next | 1346 | |.ffunc_1 next |
1347 | | je >2 // Missing 2nd arg? | 1347 | | je >2 // Missing 2nd arg? |
1348 | |1: | 1348 | |1: |
1349 | |.if X64WIN | 1349 | | mov CARG1, [BASE] |
1350 | | mov RA, [BASE] | ||
1351 | | checktab RA, ->fff_fallback | ||
1352 | |.else | ||
1353 | | mov CARG2, [BASE] | ||
1354 | | checktab CARG2, ->fff_fallback | ||
1355 | |.endif | ||
1356 | | mov L:RB, SAVE_L | ||
1357 | | mov L:RB->base, BASE // Add frame since C call can throw. | ||
1358 | | mov L:RB->top, BASE // Dummy frame length is ok. | ||
1359 | | mov PC, [BASE-8] | 1350 | | mov PC, [BASE-8] |
1351 | | checktab CARG1, ->fff_fallback | ||
1352 | | mov RB, BASE // Save BASE. | ||
1360 | |.if X64WIN | 1353 | |.if X64WIN |
1361 | | lea CARG3, [BASE+8] | 1354 | | lea CARG3, [BASE-16] |
1362 | | mov CARG2, RA // Caveat: CARG2 == BASE. | 1355 | | lea CARG2, [BASE+8] // Caveat: CARG2 == BASE. |
1363 | | mov CARG1, L:RB | ||
1364 | |.else | 1356 | |.else |
1365 | | lea CARG3, [BASE+8] // Caveat: CARG3 == BASE. | 1357 | | lea CARG2, [BASE+8] |
1366 | | mov CARG1, L:RB | 1358 | | lea CARG3, [BASE-16] // Caveat: CARG3 == BASE. |
1367 | |.endif | 1359 | |.endif |
1368 | | mov SAVE_PC, PC // Needed for ITERN fallback. | 1360 | | call extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o) |
1369 | | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) | 1361 | | // 1=found, 0=end, -1=error returned in eax (RD). |
1370 | | // Flag returned in eax (RD). | 1362 | | mov BASE, RB // Restore BASE. |
1371 | | mov BASE, L:RB->base | 1363 | | test RDd, RDd; jg ->fff_res2 // Found key/value. |
1372 | | test RDd, RDd; jz >3 // End of traversal? | 1364 | | js ->fff_fallback_2 // Invalid key. |
1373 | | // Copy key and value to results. | 1365 | | // End of traversal: return nil. |
1374 | | mov RB, [BASE+8] | 1366 | | mov aword [BASE-16], LJ_TNIL |
1375 | | mov RD, [BASE+16] | 1367 | | jmp ->fff_res1 |
1376 | | mov [BASE-16], RB | ||
1377 | | mov [BASE-8], RD | ||
1378 | |->fff_res2: | ||
1379 | | mov RDd, 1+2 | ||
1380 | | jmp ->fff_res | ||
1381 | |2: // Set missing 2nd arg to nil. | 1368 | |2: // Set missing 2nd arg to nil. |
1382 | | mov aword [BASE+8], LJ_TNIL | 1369 | | mov aword [BASE+8], LJ_TNIL |
1383 | | jmp <1 | 1370 | | jmp <1 |
1384 | |3: // End of traversal: return nil. | ||
1385 | | mov aword [BASE-16], LJ_TNIL | ||
1386 | | jmp ->fff_res1 | ||
1387 | | | 1371 | | |
1388 | |.ffunc_1 pairs | 1372 | |.ffunc_1 pairs |
1389 | | mov TAB:RB, [BASE] | 1373 | | mov TAB:RB, [BASE] |
@@ -1432,7 +1416,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
1432 | | // Copy array slot. | 1416 | | // Copy array slot. |
1433 | | mov RB, [RD] | 1417 | | mov RB, [RD] |
1434 | | mov [BASE-8], RB | 1418 | | mov [BASE-8], RB |
1435 | | jmp ->fff_res2 | 1419 | |->fff_res2: |
1420 | | mov RDd, 1+2 | ||
1421 | | jmp ->fff_res | ||
1436 | |2: // Check for empty hash part first. Otherwise call C function. | 1422 | |2: // Check for empty hash part first. Otherwise call C function. |
1437 | | cmp dword TAB:RB->hmask, 0; je ->fff_res0 | 1423 | | cmp dword TAB:RB->hmask, 0; je ->fff_res0 |
1438 | |.if X64WIN | 1424 | |.if X64WIN |
@@ -4125,7 +4111,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4125 | | cmp aword [BASE+RA*8-8], LJ_TNIL; jne >5 | 4111 | | cmp aword [BASE+RA*8-8], LJ_TNIL; jne >5 |
4126 | | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 | 4112 | | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 |
4127 | | branchPC RD | 4113 | | branchPC RD |
4128 | | mov64 TMPR, U64x(fffe7fff, 00000000) | 4114 | | mov64 TMPR, ((uint64_t)LJ_KEYINDEX << 32) |
4129 | | mov [BASE+RA*8-8], TMPR // Initialize control var. | 4115 | | mov [BASE+RA*8-8], TMPR // Initialize control var. |
4130 | |1: | 4116 | |1: |
4131 | | ins_next | 4117 | | ins_next |