l-macro-imp-optimize.lua /size: 1783 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
l-macro-imp-optimize
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to luat-lib.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- This is for ConTeXt only and used in development. Only in rare cases we
10
-- will use this to gain a bit of performance or adapt to specific versions
11
-- of Lua.
12 13
-- There is no real gain as we hardly use these:
14
--
15
-- lua.macros.resolvestring [[
16
-- #define div(a,b) floor(a/b)
17
-- #define mod(a,b) (a % b)
18
-- #define odd(a) (a % 2 ~= 0)
19
-- #define even(a) (a % 2 == 0)
20
-- #define pow(x,y) (x^y)
21
-- ]]
22 23
if
LUAVERSION
>
=
5
.
3
and
lua
.
macros
then
24 25
-- For the moment we only optimize in Lua 5.3:
26 27
lua
.
macros
.
enabled
=
true
28 29
-- This indirect method makes it possible to use both the functions
30
-- and the inline variant (which often looks better). Also, a mixed
31
-- 5,2 and 5.3 source is not possible because the 5.2 doesn't deal
32
-- with the newer 5.3 syntax.
33 34
-- We need to check for 64 usage: 0xFFFFFFFFFFFFFFFF (-1)
35 36
lua
.
macros
.
resolvestring
[[
37#define band(a,b) ((a)&(b)) 38#define bnot(a) (~(a)&0xFFFFFFFF) 39#define bor(a,b) (((a)|(b))&0xFFFFFFFF) 40#define btest(a,b) (((a)&(b))~=0) 41#define bxor(a,b) (((a)~(b))&0xFFFFFFFF) 42#define extract(a,b,c) (((a)>>(b))&~(-1<<(c))) 43#define extract(a,b) (((a)>>(b))&0x1) 44#define extract1(a,b) ((a >> b) & 0x01) 45#define extract2(a,b) ((a >> b) & 0x03) 46#define extract4(a,b) ((a >> b) & 0x0F) 47#define lshift(a,b) (((a)<<(b))&0xFFFFFFFF) 48#define rshift(a,b) (((a)>>(b))&0xFFFFFFFF) 49#define intdiv(a,b) ((a)//(b)) 50#define idiv(a,b) ((a)//(b)) 51
]]
52 53
end
54