From 758c1ef445ab27d89bace746111add04083a8e20 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 15 Jul 2019 14:59:35 -0300 Subject: Unification of size representation in OP_NEWTABLE and OP_SETLIST Opcodes OP_NEWTABLE and OP_SETLIST use the same representation to store the size of the array part of a table. This new representation can go up to 2^33 (8 + 25 bits). --- lopcodes.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'lopcodes.h') diff --git a/lopcodes.h b/lopcodes.h index 0b23fa6f..371cb3ae 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -214,7 +214,7 @@ OP_SETTABLE,/* A B C R(A)[R(B)] := RK(C) */ OP_SETI,/* A B C R(A)[B] := RK(C) */ OP_SETFIELD,/* A B C R(A)[K(B):string] := RK(C) */ -OP_NEWTABLE,/* A B C R(A) := {} (size = B,C) */ +OP_NEWTABLE,/* A B C R(A) := {} */ OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C):string] */ @@ -321,12 +321,17 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ (*) In OP_RETURN, if (B == 0) then return up to 'top'. - (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if (C == 0) then - next 'instruction' is EXTRAARG(real C). - - (*) In OP_LOADKX and OP_NEWTABLE, the next 'instruction' is always + (*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always EXTRAARG. + (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then + real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the + bits of C). + + (*) In OP_NEWTABLE, B is log2 of the hash size (which is always a + power of 2) plus 1, or zero for size zero. If not k, the array size + is C. Otherwise, the array size is EXTRAARG _ C. + (*) For comparisons, k specifies what condition the test should accept (true or false). @@ -375,12 +380,4 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) /* number of list items to accumulate before a SETLIST instruction */ #define LFIELDS_PER_FLUSH 50 - -/* -** In OP_NEWTABLE, array sizes smaller than LIMTABSZ are represented -** directly in R(B). Otherwise, array size is given by -** (R(B) - LIMTABSZ) + EXTRAARG * LFIELDS_PER_FLUSH -*/ -#define LIMTABSZ (MAXARG_B - LFIELDS_PER_FLUSH) - #endif -- cgit v1.2.3-55-g6feb