When is OP_LOADKX used?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

When is OP_LOADKX used?

Thomas Jericke
Hi,
I have a small question. In my project I will do some modifications to
the Lua 5.2 interpreter to implement some things more efficient for our
purposes.
As most changes are in the lvm.c luaV_execute function I wanted to have
a full coverage unit test of that function. Unfortunately I haven't
managed to provoke a OP_LOADKX. Maybe someone has an idea, or even
better sample lua code that will compile and run a OP_LOADKX operation?

Thanks

--
Thomas


Reply | Threaded
Open this post in threaded view
|

Re: When is OP_LOADKX used?

Tony Finch
Thomas Jericke <[hidden email]> wrote:

> Unfortunately I haven't managed to provoke a OP_LOADKX. Maybe someone
> has an idea, or even better sample lua code that will compile and run a
> OP_LOADKX operation?

It is used when a function has a very large number of constants, more than
2^18.

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
North Utsire, South Utsire: Variable 3 or 4, becoming northerly or
northwesterly 4 or 5. Slight or moderate. Occasional drizzle, fog patches.
Moderate or good, occasionally very poor.

Reply | Threaded
Open this post in threaded view
|

Re: When is OP_LOADKX used?

Roberto Ierusalimschy
In reply to this post by Thomas Jericke
> I have a small question. In my project I will do some modifications
> to the Lua 5.2 interpreter to implement some things more efficient
> for our purposes.
> As most changes are in the lvm.c luaV_execute function I wanted to
> have a full coverage unit test of that function. Unfortunately I
> haven't managed to provoke a OP_LOADKX. Maybe someone has an idea,
> or even better sample lua code that will compile and run a OP_LOADKX
> operation?

local a = {"return {0"}
for i = 1,2^18 + 10 do
  a[#a + 1] = i
end
a[#a + 1] = "}"
local f = assert(loadstring(table.concat(a, ",")))

Function 'f' should have 11 occurences of 'OP_LOADKX'.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: When is OP_LOADKX used?

liam mail
On 22 March 2012 16:29, Roberto Ierusalimschy <[hidden email]> wrote:

>> I have a small question. In my project I will do some modifications
>> to the Lua 5.2 interpreter to implement some things more efficient
>> for our purposes.
>> As most changes are in the lvm.c luaV_execute function I wanted to
>> have a full coverage unit test of that function. Unfortunately I
>> haven't managed to provoke a OP_LOADKX. Maybe someone has an idea,
>> or even better sample lua code that will compile and run a OP_LOADKX
>> operation?
>
> local a = {"return {0"}
> for i = 1,2^18 + 10 do
>  a[#a + 1] = i
> end
> a[#a + 1] = "}"
> local f = assert(loadstring(table.concat(a, ",")))
>
> Function 'f' should have 11 occurences of 'OP_LOADKX'.
>
> -- Roberto
>

I thought 2^16 -1 was the maximum default array size?

Liam

Reply | Threaded
Open this post in threaded view
|

Re: When is OP_LOADKX used?

liam mail
On 22 March 2012 16:39, liam mail <[hidden email]> wrote:

> On 22 March 2012 16:29, Roberto Ierusalimschy <[hidden email]> wrote:
>>> I have a small question. In my project I will do some modifications
>>> to the Lua 5.2 interpreter to implement some things more efficient
>>> for our purposes.
>>> As most changes are in the lvm.c luaV_execute function I wanted to
>>> have a full coverage unit test of that function. Unfortunately I
>>> haven't managed to provoke a OP_LOADKX. Maybe someone has an idea,
>>> or even better sample lua code that will compile and run a OP_LOADKX
>>> operation?
>>
>> local a = {"return {0"}
>> for i = 1,2^18 + 10 do
>>  a[#a + 1] = i
>> end
>> a[#a + 1] = "}"
>> local f = assert(loadstring(table.concat(a, ",")))
>>
>> Function 'f' should have 11 occurences of 'OP_LOADKX'.
>>
>> -- Roberto
>>
>
> I thought 2^16 -1 was the maximum default array size?
>
> Liam


Hmm serves me right for looking at the online soure[1] but it means I
need to change some code as I see 2^MAXBITS (5.1 26 and 5.2 30) is the
default max size.

[1] http://www.lua.org/source/5.1/luaconf.h.html#LUAI_BITSINT

Reply | Threaded
Open this post in threaded view
|

Re: When is OP_LOADKX used?

Thomas Jericke
In reply to this post by Roberto Ierusalimschy

>> I have a small question. In my project I will do some modifications
>> to the Lua 5.2 interpreter to implement some things more efficient
>> for our purposes.
>> As most changes are in the lvm.c luaV_execute function I wanted to
>> have a full coverage unit test of that function. Unfortunately I
>> haven't managed to provoke a OP_LOADKX. Maybe someone has an idea,
>> or even better sample lua code that will compile and run a OP_LOADKX
>> operation?
> local a = {"return {0"}
> for i = 1,2^18 + 10 do
>    a[#a + 1] = i
> end
> a[#a + 1] = "}"
> local f = assert(loadstring(table.concat(a, ",")))
>
> Function 'f' should have 11 occurences of 'OP_LOADKX'.
>
> -- Roberto
>

Thank you very much, the code works well. The OP_LOADKX case in lvm.c is
executed 11 times. I replaced "loadstring" by "load" I don't have any
compatibility defines active ;)

I added this two lines to the code:
local b = f()
return b[#b]

Then I can check the last element of the table by the result of my test
code. I suppose that OP_LOADKX was involved in loading the last element.

-- Thomas