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_x86.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_x86.dasc')
-rw-r--r-- | src/vm_x86.dasc | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 81b899fa..718cb8f0 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc | |||
@@ -1673,55 +1673,35 @@ static void build_subroutines(BuildCtx *ctx) | |||
1673 | | je >2 // Missing 2nd arg? | 1673 | | je >2 // Missing 2nd arg? |
1674 | |1: | 1674 | |1: |
1675 | | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback | 1675 | | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback |
1676 | | mov L:RB, SAVE_L | ||
1677 | | mov L:RB->base, BASE // Add frame since C call can throw. | ||
1678 | | mov L:RB->top, BASE // Dummy frame length is ok. | ||
1679 | | mov PC, [BASE-4] | 1676 | | mov PC, [BASE-4] |
1677 | | mov RB, BASE // Save BASE. | ||
1680 | |.if X64WIN | 1678 | |.if X64WIN |
1681 | | lea CARG3d, [BASE+8] | 1679 | | mov CARG1d, [BASE] |
1682 | | mov CARG2d, [BASE] // Caveat: CARG2d == BASE. | 1680 | | lea CARG3d, [BASE-8] |
1683 | | mov CARG1d, L:RB | 1681 | | lea CARG2d, [BASE+8] // Caveat: CARG2d == BASE. |
1684 | |.elif X64 | 1682 | |.elif X64 |
1685 | | mov CARG2d, [BASE] | 1683 | | mov CARG1d, [BASE] |
1686 | | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE. | 1684 | | lea CARG2d, [BASE+8] |
1687 | | mov CARG1d, L:RB | 1685 | | lea CARG3d, [BASE-8] // Caveat: CARG3d == BASE. |
1688 | |.else | 1686 | |.else |
1689 | | mov TAB:RD, [BASE] | 1687 | | mov TAB:RD, [BASE] |
1690 | | mov ARG2, TAB:RD | 1688 | | mov ARG1, TAB:RD |
1691 | | mov ARG1, L:RB | ||
1692 | | add BASE, 8 | 1689 | | add BASE, 8 |
1690 | | mov ARG2, BASE | ||
1691 | | sub BASE, 8+8 | ||
1693 | | mov ARG3, BASE | 1692 | | mov ARG3, BASE |
1694 | |.endif | 1693 | |.endif |
1695 | | mov SAVE_PC, PC // Needed for ITERN fallback. | 1694 | | call extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o) |
1696 | | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) | 1695 | | // 1=found, 0=end, -1=error returned in eax (RD). |
1697 | | // Flag returned in eax (RD). | 1696 | | mov BASE, RB // Restore BASE. |
1698 | | mov BASE, L:RB->base | 1697 | | test RD, RD; jg ->fff_res2 // Found key/value. |
1699 | | test RD, RD; jz >3 // End of traversal? | 1698 | | js ->fff_fallback_2 // Invalid key. |
1700 | | // Copy key and value to results. | 1699 | | // End of traversal: return nil. |
1701 | |.if X64 | 1700 | | mov dword [BASE-4], LJ_TNIL |
1702 | | mov RBa, [BASE+8] | 1701 | | jmp ->fff_res1 |
1703 | | mov RDa, [BASE+16] | ||
1704 | | mov [BASE-8], RBa | ||
1705 | | mov [BASE], RDa | ||
1706 | |.else | ||
1707 | | mov RB, [BASE+8] | ||
1708 | | mov RD, [BASE+12] | ||
1709 | | mov [BASE-8], RB | ||
1710 | | mov [BASE-4], RD | ||
1711 | | mov RB, [BASE+16] | ||
1712 | | mov RD, [BASE+20] | ||
1713 | | mov [BASE], RB | ||
1714 | | mov [BASE+4], RD | ||
1715 | |.endif | ||
1716 | |->fff_res2: | ||
1717 | | mov RD, 1+2 | ||
1718 | | jmp ->fff_res | ||
1719 | |2: // Set missing 2nd arg to nil. | 1702 | |2: // Set missing 2nd arg to nil. |
1720 | | mov dword [BASE+12], LJ_TNIL | 1703 | | mov dword [BASE+12], LJ_TNIL |
1721 | | jmp <1 | 1704 | | jmp <1 |
1722 | |3: // End of traversal: return nil. | ||
1723 | | mov dword [BASE-4], LJ_TNIL | ||
1724 | | jmp ->fff_res1 | ||
1725 | | | 1705 | | |
1726 | |.ffunc_1 pairs | 1706 | |.ffunc_1 pairs |
1727 | | mov TAB:RB, [BASE] | 1707 | | mov TAB:RB, [BASE] |
@@ -1775,7 +1755,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
1775 | | mov [BASE], RB | 1755 | | mov [BASE], RB |
1776 | | mov [BASE+4], RD | 1756 | | mov [BASE+4], RD |
1777 | |.endif | 1757 | |.endif |
1778 | | jmp ->fff_res2 | 1758 | |->fff_res2: |
1759 | | mov RD, 1+2 | ||
1760 | | jmp ->fff_res | ||
1779 | |2: // Check for empty hash part first. Otherwise call C function. | 1761 | |2: // Check for empty hash part first. Otherwise call C function. |
1780 | | cmp dword TAB:RB->hmask, 0; je ->fff_res0 | 1762 | | cmp dword TAB:RB->hmask, 0; je ->fff_res0 |
1781 | | mov FCARG1, TAB:RB | 1763 | | mov FCARG1, TAB:RB |
@@ -4880,7 +4862,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4880 | | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 | 4862 | | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5 |
4881 | | branchPC RD | 4863 | | branchPC RD |
4882 | | mov dword [BASE+RA*8-8], 0 // Initialize control var. | 4864 | | mov dword [BASE+RA*8-8], 0 // Initialize control var. |
4883 | | mov dword [BASE+RA*8-4], 0xfffe7fff | 4865 | | mov dword [BASE+RA*8-4], LJ_KEYINDEX |
4884 | |1: | 4866 | |1: |
4885 | | ins_next | 4867 | | ins_next |
4886 | |5: // Despecialize bytecode if any of the checks fail. | 4868 | |5: // Despecialize bytecode if any of the checks fail. |