lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

 

This patch introduces bitwise operators to lua_Number. It was porting/extending Doug Rogers’ patch for lua 5.1.1.

 

Here are the operators (metaoperator):

A|B : or (__bor)

A&B : and

A^|B : xor, (__band) Doug was using #, because ^ is used for power, I preferred to define a 2 signs token closer to usual notation

A<<s: left shift, (__blshift)

B>>s: right shift, (__brshift)

~A : not, (__bnot)

 

It isn’t backward compatible with lua because it introduced some new opcodes.

 

To disable these operators, just turn off LUA_BITWISE_OPERATORS in luaconf.h and you are back to standard lua.

 

Well, it also includes the patch for direct threaded code in virtual machine for gcc, which isn’t enabled on x86, and can be discarded in luaconf.h

 

% uname -a

Linux 2.4.21-37.ELsmp #1 SMP Wed Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux

%gcc --version

gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-53)

Copyright (C) 2002 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

[lua-5.1.1 ]                       % size src/lua

   text    data     bss     dec     hex filename

 114770     644      16  115430   1c2e6 src/lua

[lua-5.1.1 ]                       % size src/luac

   text    data     bss     dec     hex filename

  78504     456      16   78976   13480 src/luac

 

[lua-5.1.1.patched ]               % size src/lua

   text    data     bss     dec     hex filename

 117330     644      16  117990   1cce6 src/lua

[lua-5.1.1.patched ]               % size src/luac

   text    data     bss     dec     hex filename

  81140     456      16   81612   13ecc src/luac

 

So the overhead is roughly 2,5Ko

 

I post it here for Comments/Suggestion (how to check the boundaries, …)/Deeper testing…

 

And would be interested to know if something similar would be included in lua 5.2…

 

Thierry

 

 

Attachment: bitwise_directthreaded.patch.gz
Description: bitwise_directthreaded.patch.gz