Refactor string.rep().

This commit is contained in:
Mike Pall
2013-04-26 19:57:25 +02:00
parent a98e6a70c1
commit 9b8db403f2
8 changed files with 39 additions and 184 deletions

View File

@@ -1716,41 +1716,6 @@ static void build_subroutines(BuildCtx *ctx)
| b ->fff_restv
|. li CARG3, LJ_TSTR
|
|.ffunc string_rep // Only handle the 1-char case inline.
| ffgccheck
| lw TMP0, HI(BASE)
| addiu AT, NARGS8:RC, -16 // Exactly 2 arguments.
| lw CARG4, 8+HI(BASE)
| lw STR:CARG1, LO(BASE)
| addiu TMP0, TMP0, -LJ_TSTR
| ldc1 f0, 8(BASE)
| or AT, AT, TMP0
| bnez AT, ->fff_fallback
|. sltiu AT, CARG4, LJ_TISNUM
| trunc.w.d f0, f0
| beqz AT, ->fff_fallback
|. lw TMP0, STR:CARG1->len
| mfc1 CARG3, f0
| lw CARG2, DISPATCH_GL(tmpbuf.b)(DISPATCH)
| lw TMP1, DISPATCH_GL(tmpbuf.e)(DISPATCH)
| li AT, 1
| blez CARG3, ->fff_emptystr // Count <= 0?
|. sltu AT, AT, TMP0
| beqz TMP0, ->fff_emptystr // Zero length string?
|. addu TMP3, CARG2, CARG3
| sltu TMP0, TMP1, TMP3
| or AT, AT, TMP0
| bnez AT, ->fff_fallback // Fallback for > 1-char strings.
|. lbu TMP0, STR:CARG1[1]
| addu TMP2, CARG2, CARG3
|1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
| addiu TMP2, TMP2, -1
| sltu AT, CARG2, TMP2
| bnez AT, <1
|. sb TMP0, 0(TMP2)
| b ->fff_newstr
|. nop
|
|.macro ffstring_op, name
| .ffunc string_ .. name
| ffgccheck