Refactor table traversal.

Sponsored by OpenResty Inc.
This commit is contained in:
Mike Pall
2021-09-19 17:38:49 +02:00
parent 4e0ea654a8
commit c6f5ef649b
12 changed files with 156 additions and 210 deletions

View File

@@ -1322,27 +1322,24 @@ static void build_subroutines(BuildCtx *ctx)
|//-- Base library: iterators -------------------------------------------
|
|.ffunc_1 next
| checktp CARG2, CARG1, -LJ_TTAB, ->fff_fallback
| checktp CARG1, -LJ_TTAB, ->fff_fallback
| daddu TMP2, BASE, NARGS8:RC
| sd TISNIL, 0(TMP2) // Set missing 2nd arg to nil.
| ld PC, FRAME_PC(BASE)
| load_got lj_tab_next
| sd BASE, L->base // Add frame since C call can throw.
| sd BASE, L->top // Dummy frame length is ok.
| daddiu CARG3, BASE, 8
| sd PC, SAVE_PC
| call_intern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
|. move CARG1, L
| // Returns 0 at end of traversal.
| ld PC, FRAME_PC(BASE)
| daddiu CARG2, BASE, 8
| call_intern lj_tab_next // (GCtab *t, cTValue *key, TValue *o)
|. daddiu CARG3, BASE, -16
| // Returns 1=found, 0=end, -1=error.
| daddiu RA, BASE, -16
| bgtz CRET1, ->fff_res // Found key/value.
|. li RD, (2+1)*8
| beqz CRET1, ->fff_restv // End of traversal: return nil.
|. move CARG1, TISNIL
| ld TMP0, 8(BASE)
| daddiu RA, BASE, -16
| ld TMP2, 16(BASE)
| sd TMP0, 0(RA)
| sd TMP2, 8(RA)
| b ->fff_res
|. li RD, (2+1)*8
| ld CFUNC:RB, FRAME_FUNC(BASE)
| cleartp CFUNC:RB
| b ->fff_fallback // Invalid key.
|. li RC, 2*8
|
|.ffunc_1 pairs
| checktp TAB:TMP1, CARG1, -LJ_TTAB, ->fff_fallback
@@ -4727,11 +4724,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|. addiu RC, RC, 1
| sd TMP2, 0(RA)
| sd CARG1, 8(RA)
| or TMP0, RC, CARG3
| lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
| decode_RD4b RD
| daddu RD, RD, TMP3
| sw TMP0, -8+LO(RA) // Update control var.
| sw RC, -8+LO(RA) // Update control var.
| daddu PC, PC, RD
|3:
| ins_next
@@ -4781,9 +4777,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| daddiu TMP1, TMP1, -FF_next_N
| or AT, AT, TMP1
| bnez AT, >5
|. lui TMP1, 0xfffe
|. lui TMP1, (LJ_KEYINDEX >> 16)
| daddu PC, TMP0, TMP2
| ori TMP1, TMP1, 0x7fff
| ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)
| dsll TMP1, TMP1, 32
| sd TMP1, -8(RA)
|1: