[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: native code for bitwise operators in LUA
- From: "Ing. Jan Supuka SBM" <sbmintegral@...>
- Date: Thu, 03 Nov 2011 09:21:40 +0100
Dňa 2011-11-02 21:27, liam mail wrote / napísal(a):
On 2 November 2011 20:24, liam mail<email@example.com> wrote:
Thanks it looks interesting although on first try to compile I get an
error about luaopen_mathx being undefined, is this a private maths
library?* So I have not yet run the speed tests but I would recommend
some changes in both Rio Lua usage and your own.
Don't use io operations inside a profile test
Use locals instead of globals
Be nice to Rio Lua and cache bit32.band et al to locals ie local band
* also a warning is generated for lvm.c:380 suggest parentheses around
&& within ||
Oh, I forgot to say did you have a Lua Uppercase Accident :)
Lua != LUA
Thanks a lot of trying .
readme.txt and project description ... Lua Uppercase Accident ... CORRECTED
lmathx .... sorry, mistake in (manually changed) makefile (I use
CodeLite) ... CORRECTED
lvm.c ... suggested parantheses ... CORRECTED
testluabit.lua ... using locals ... PROVIDED as third test
Some explanation for using "special" bitwise operators
I'm working on SCADA project, where I need scripting language for
'conditioning' raw values from IO devices
Now 8 500 "upper level" values assigned by "Lua user defined conditioing
script" to app. 14 000 raw values
(now like in testcalc.lua, but offered possibility for more desribed and
more complicated scripts) .
App. 10 000 raw values are updated in half of second !. And scripts must
be calculated practically immediately.
And most of them need bitwise operations.
Near future ... 30 000 "upper level" values conditioned from app. 50 000
raw values from IO devices.
SPEED is CRITICAL.
Setting/reseting bit signal in STATUS(long int) like M_ALARM_MIN,
M_ALARM_MAX, OUT_OF_ORDER, ERROR_STATE .... ,
conditional calculation based on these and others bit signals
(f.e. archiving M_ARCH_10sec, M_ARCH_1minute, M_ARCH_1hour,
all need fastest possible bitwise calculations (min. 20 bitwise opers /
1 value / 0.5sec ==> 340000 opers/sec min.) .
Very nice will be "totally scripted system" with none specially compiled
I tried write SCADA_calcul_core in PHP (native bitwise) ... 2 seconds
per cycle ... slow
I tried write SCADA_calcul_core in Lua (bit32 lib local defined bxxx
functions) ... 3 !!!! seconds per cycle ... slower than PHP !!!
That's why I start working on lualubit project.
For now it must be C compiled SCADA_calcul_core with Lua conditional
scripts (in-time USER DEFINITION strictly required),
fast bitwise operators are needed, otherwise using Lua language is
practically impossible in my case.
Dňa 2011-11-02 22:43, Patrick Rapin wrote / napísal(a):
I do use quite a lot bitwise operators in C++.
In Lua 5.1, bit operations missed me a lot so I wrote a bit library
(instead of searching for an existent one).
So I am happy that a standard bit32 library now appears in Lua 5.2.
However, I am clearly against introducing new operators and new VM op
codes for bit operations:
- Lua has very few punctuation operators, privileging key words.
- Lua lacked bitwise operations during 18 years; I doubt that they
became suddenly so important to change the grammar for them
- Lua always favors small implementation code when possible. New
opcodes and operators are harder to introduce, and cannot be
- Even MATLAB doesn't have operators for bit operations
- If you want speed, use LuaJIT
Completely rewrite all long time succesfully worked code logics to
achieve strict actual Lua compatibility ?
What reason ? ONLY argument ... lacked bitwise operators during 18 years ?
In Lua 5.2 beta are introduced UNSIGNED INT (again thanks !) ... maybe
signal to faster work without double/int conversion,
implementing bitwise library into core code ... signal, that bitwise
operators are 'good to have',
I hope, signal for possible introducing (not new, but missing, I thing)
native bitwise operators too.
In lualubit Lua variant implemented bitwise operators may or may not be
Changing grammar is very low price for performance improvement.
Sizes (Windows 7 MinGW CodeLite ):
source code Lua 5.2 beta 537,072 bytes LuaLubit 553,650 bytes
release lua.exe Lua 5.2 beta 252 KB LuaLubit 276 KB
I am relative newbie in Lua language, and I have doubts, if lualubit is
especially in 'allow treat booleans as number in arithmetical operations
(for new/all operators)' ,
need help with testing
PS: lubit ... ľúbiť === to love (in Slovak)