1 ---------------------------------
5 ---------------------------------
7 local
ffi = require
"ffi"
14 struct mg_bitmask * mg_bitmask_create(uint16_t size);
15 void mg_bitmask_free(
struct mg_bitmask * mask);
16 void mg_bitmask_set_n_one(
struct mg_bitmask * mask, uint16_t
n);
17 void mg_bitmask_set_all_one(
struct mg_bitmask * mask);
18 void mg_bitmask_clear_all(
struct mg_bitmask * mask);
19 uint8_t mg_bitmask_get_bit(
struct mg_bitmask * mask, uint16_t
n);
20 void mg_bitmask_set_bit(
struct mg_bitmask * mask, uint16_t
n);
21 void mg_bitmask_clear_bit(
struct mg_bitmask * mask, uint16_t
n);
22 void mg_bitmask_and(
struct mg_bitmask * mask1,
struct mg_bitmask * mask2,
struct mg_bitmask * result);
23 void mg_bitmask_xor(
struct mg_bitmask * mask1,
struct mg_bitmask * mask2,
struct mg_bitmask * result);
24 void mg_bitmask_or(
struct mg_bitmask * mask1,
struct mg_bitmask * mask2,
struct mg_bitmask * result);
25 void mg_bitmask_not(
struct mg_bitmask * mask1,
struct mg_bitmask * result);
32 --mg_bitMask.__index = mg_bitMask
35 --- The mask is internally built from blocks of 64bit integers. Hence a Bitmask
36 --- of a size <<64 yields significant overhead
37 --- @param size Size of the bitmask in number of bits
38 --- @
return Wrapper table around the bitmask
39 function mod.createBitMask(size)
41 bitmask =
ffi.gc(
ffi.C.mg_bitmask_create(size),
function (
self)
42 print(
"I HAVE BEEN DESTRUCTED")
43 ffi.C.mg_bitmask_free(
self)
50 --- @todo TODO: think of a better solution - meh
52 array =
ffi.
new("struct mg_bitmask*[?]",
#bitmasks)
54 for _,m in pairs(bitmasks) do
61 --- sets the first
n bits in a bitmask to 1
62 --- other bits remain unchanged
64 function mg_bitMask:
setN(
n)
65 ffi.C.mg_bitmask_set_n_one(self.bitmask,
n)
69 --- sets all bits in a bitmask to 0
71 ffi.C.mg_bitmask_clear_all(self.bitmask)
75 --- sets all bits in a bitmask to 1
76 function mg_bitMask:
setAll()
77 ffi.C.mg_bitmask_set_all_one(self.bitmask)
81 --- Index metamethod for mg_bitMask
82 --- @param x Bit index. Index starts at 1 according to the LUA standard (1 indexes the first bit in the bitmask)
83 --- @return For numeric indices: true, when corresponding bit is 1, false otherwise.
86 --print(" bit access")
87 --print(" type " .. type(x))
88 --print(" x = " .. tostring(x))
89 if(type(x) == "number") then
90 return (
ffi.C.mg_bitmask_get_bit(self.bitmask, x - 1) ~= 0)
96 --- Newindex metamethod for mg_bitMask
97 --- @param x Bit index. Index starts at 1 according to the LUA standard (1 indexes the first bit in the bitmask)
98 --- @param y Assigned value to the index (bit is cleared for y==0 and
set otherwise)
100 --print ("
new index")
104 return
ffi.C.mg_bitmask_clear_bit(self.bitmask, x - 1)
108 return
ffi.C.mg_bitmask_set_bit(self.bitmask, x - 1)
113 local function it(self, i)
114 if i >= self.bitmask.size then
117 return i + 1, self[i+1]
120 function mg_bitMask.__ipairs(self)
129 --- result = mask1
band mask2
130 function
mod.
band(mask1, mask2, result)
131 ffi.C.mg_bitmask_and(mask1.bitmask, mask2.bitmask, result.bitmask)
138 --- result = mask1
bor mask2
139 function
mod.
bor(mask1, mask2, result)
140 ffi.C.mg_bitmask_or(mask1.bitmask, mask2.bitmask, result.bitmask)
147 --- result = bask1
bxor mask2
148 function
mod.
bxor(mask1, mask2, result)
149 ffi.C.mg_bitmask_xor(mask1.bitmask, mask2.bitmask, result.bitmask)
155 --- result = not mask
156 function
mod.
bnot(mask, result)
157 ffi.C.mg_bitmask_not(mask.bitmask, result.bitmask)
local ffi
low-level dpdk wrapper
function mg_bitMask clearAll()
sets all bits in a bitmask to 0
function mod band(mask1, mask2, result)
Bitwise and.
function ipsecICV set(icv)
Set the IPsec ICV.
function mod bor(mask1, mask2, result)
Bitwise or.
function mod bxor(mask1, mask2, result)
Bitwise xor.
function mg_bitMask setAll()
sets all bits in a bitmask to 1
local mod
high-level dpdk wrapper
function mg_bitMask __index(x)
Index metamethod for mg_bitMask.
function mod linkToArray(bitmasks)
function mg_bitMask __newindex(x, y)
Newindex metamethod for mg_bitMask.
function mod bnot(mask, result)
Bitwise not.
n
Create a new array of memory buffers (initialized to nil).
function mg_bitMask setN(n)
sets the first n bits in a bitmask to 1 other bits remain unchanged