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

@@ -1559,43 +1559,24 @@ static void build_subroutines(BuildCtx *ctx)
|
|//-- Base library: iterators -------------------------------------------
|
|.ffunc next
| cmplwi NARGS8:RC, 8
| lwz CARG1, 0(BASE)
| lwz TAB:CARG2, 4(BASE)
| blt ->fff_fallback
|.ffunc_1 next
| stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil.
| checktab CARG1
| checktab CARG3
| lwz PC, FRAME_PC(BASE)
| bne ->fff_fallback
| stp BASE, L->base // Add frame since C call can throw.
| mr CARG1, L
| stp BASE, L->top // Dummy frame length is ok.
| la CARG3, 8(BASE)
| stw PC, SAVE_PC
| bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
| // Returns 0 at end of traversal.
| cmplwi CRET1, 0
| la CARG2, 8(BASE)
| la CARG3, -8(BASE)
| bl extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o)
| // Returns 1=found, 0=end, -1=error.
| cmpwi CRET1, 0
| la RA, -8(BASE)
| li RD, (2+1)*8
| bgt ->fff_res // Found key/value.
| li CARG3, LJ_TNIL
| beq ->fff_restv // End of traversal: return nil.
| la RA, -8(BASE)
|.if FPU
| lfd f0, 8(BASE) // Copy key and value to results.
| lfd f1, 16(BASE)
| stfd f0, 0(RA)
| stfd f1, 8(RA)
|.else
| lwz CARG1, 8(BASE)
| lwz CARG2, 12(BASE)
| lwz CARG3, 16(BASE)
| lwz CARG4, 20(BASE)
| stw CARG1, 0(RA)
| stw CARG2, 4(RA)
| stw CARG3, 8(RA)
| stw CARG4, 12(RA)
|.endif
| li RD, (2+1)*8
| b ->fff_res
| lwz CFUNC:RB, FRAME_FUNC(BASE)
| li NARGS8:RC, 2*8
| b ->fff_fallback // Invalid key.
|
|.ffunc_1 pairs
| checktab CARG3
@@ -5251,8 +5232,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
| add TMP3, PC, TMP0
| bne cr0, >5
| lus TMP1, 0xfffe
| ori TMP1, TMP1, 0x7fff
| lus TMP1, (LJ_KEYINDEX >> 16)
| ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)
| stw ZERO, -4(RA) // Initialize control var.
| stw TMP1, -8(RA)
| addis PC, TMP3, -(BCBIAS_J*4 >> 16)