diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-04-19 13:22:13 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-04-19 13:22:13 -0300 |
| commit | 4758113043b6c362a0fdce77715c711332d909dc (patch) | |
| tree | deea8a795161332bb1579f201f8a7eb5e4b102b9 | |
| parent | a4e644add264b6bac3171a03aa6febcf61e89ae6 (diff) | |
| download | lua-4758113043b6c362a0fdce77715c711332d909dc.tar.gz lua-4758113043b6c362a0fdce77715c711332d909dc.tar.bz2 lua-4758113043b6c362a0fdce77715c711332d909dc.zip | |
change in opcode OP_LOADNIL: B is used as a counter instead of a
register. (Avoids an assignment to R(B), not present in any other
instruction.)
| -rw-r--r-- | lcode.c | 18 | ||||
| -rw-r--r-- | ldebug.c | 6 | ||||
| -rw-r--r-- | lopcodes.c | 4 | ||||
| -rw-r--r-- | lopcodes.h | 4 | ||||
| -rw-r--r-- | lvm.c | 8 |
5 files changed, 22 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) { | |||
| 35 | 35 | ||
| 36 | void luaK_nil (FuncState *fs, int from, int n) { | 36 | void luaK_nil (FuncState *fs, int from, int n) { |
| 37 | Instruction *previous; | 37 | Instruction *previous; |
| 38 | int l = from + n - 1; /* last register to set nil */ | ||
| 38 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ | 39 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ |
| 39 | previous = &fs->f->code[fs->pc-1]; | 40 | previous = &fs->f->code[fs->pc-1]; |
| 40 | if (GET_OPCODE(*previous) == OP_LOADNIL) { | 41 | if (GET_OPCODE(*previous) == OP_LOADNIL) { |
| 41 | int pfrom = GETARG_A(*previous); | 42 | int pfrom = GETARG_A(*previous); |
| 42 | int pto = GETARG_B(*previous); | 43 | int pl = pfrom + GETARG_B(*previous); |
| 43 | if (pfrom <= from && from <= pto+1) { /* can connect both? */ | 44 | if ((pfrom <= from && from <= pl + 1) || |
| 44 | if (from+n-1 > pto) | 45 | (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ |
| 45 | SETARG_B(*previous, from+n-1); | 46 | if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ |
| 47 | if (pl > l) l = pl; /* l = max(l, pl) */ | ||
| 48 | SETARG_A(*previous, from); | ||
| 49 | SETARG_B(*previous, l - from); | ||
| 46 | return; | 50 | return; |
| 47 | } | 51 | } |
| 48 | } | 52 | } /* else go through */ |
| 49 | } | 53 | } |
| 50 | luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ | 54 | luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | 57 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.78 2011/04/18 15:02:37 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -355,8 +355,8 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
| 355 | break; | 355 | break; |
| 356 | } | 356 | } |
| 357 | case OP_LOADNIL: { | 357 | case OP_LOADNIL: { |
| 358 | int b = GETARG_B(i); /* move from 'b' to 'a' */ | 358 | int b = GETARG_B(i); |
| 359 | if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */ | 359 | if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */ |
| 360 | what = NULL; | 360 | what = NULL; |
| 361 | break; | 361 | break; |
| 362 | } | 362 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.c,v 1.46 2011/04/07 18:14:12 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.47 2011/04/12 17:27:35 roberto Exp roberto $ |
| 3 | ** See Copyright Notice in lua.h | 3 | ** See Copyright Notice in lua.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -66,7 +66,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
| 66 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ | 66 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ |
| 67 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ | 67 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ |
| 68 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ | 68 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ |
| 69 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ | 69 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ |
| 70 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ | 70 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ |
| 71 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ | 71 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ |
| 72 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ | 72 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.139 2011/02/07 12:24:42 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.140 2011/04/07 18:14:12 roberto Exp roberto $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -170,7 +170,7 @@ OP_MOVE,/* A B R(A) := R(B) */ | |||
| 170 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ | 170 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ |
| 171 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ | 171 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ |
| 172 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | 172 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ |
| 173 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ | 173 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ |
| 174 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ | 174 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ |
| 175 | 175 | ||
| 176 | OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ | 176 | OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.134 2011/04/07 18:14:12 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.135 2011/04/18 19:48:53 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -541,10 +541,10 @@ void luaV_execute (lua_State *L) { | |||
| 541 | if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */ | 541 | if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */ |
| 542 | ) | 542 | ) |
| 543 | vmcase(OP_LOADNIL, | 543 | vmcase(OP_LOADNIL, |
| 544 | TValue *rb = RB(i); | 544 | int b = GETARG_B(i); |
| 545 | do { | 545 | do { |
| 546 | setnilvalue(rb--); | 546 | setnilvalue(ra++); |
| 547 | } while (rb >= ra); | 547 | } while (b--); |
| 548 | ) | 548 | ) |
| 549 | vmcase(OP_GETUPVAL, | 549 | vmcase(OP_GETUPVAL, |
| 550 | int b = GETARG_B(i); | 550 | int b = GETARG_B(i); |
