07-27-2022, 09:03 PM
bit-array access functions
Code: (Select All)
' bit-array access functions (note: used to be included through 'bit.cpp')
proc SYSTEM_BUS_T.getubits(bsize as uint32, _base as uint8 ptr, i as ptrszint) as uint64
static as int64 bmask, n=1
bmask = not (-((peek(int64,@n))) shl bsize)
i *= bsize
return ((*cptr(uint64 ptr,(_base + (i shr 3)))) shr (i and 7)) and bmask
end proc
proc SYSTEM_BUS_T.getbits(bsize as uint32, _base as uint8 ptr, i as ptrszint) as int64
static as int64 bmask, bval64, n=1
bmask = not (-((peek(int64,@n)) shl bsize))
i *= bsize
bval64 = ((*cptr(uint64 ptr,(_base + (i shr 3))) shr (i and 7))) and bmask
if (bval64 and ((peek(int64,@n)) shl (bsize - 1))) then
return bval64 or (not bmask)
end if
return bval64
end proc
def SYSTEM_BUS_T.setbits(bsize as uint32, _base as uint8 ptr, i as ptrszint, _val as int64)
static as int64 bmask,n=1
static as uint64 ptr bptr64
bmask = ((peek(uint64,@n)) shl bsize) - 1
i *= bsize
bptr64 = peek(uint64 ptr,(_base + (i shr 3)))
*bptr64 = (*cptr(uint64 ptr,bptr64) and (((bmask shl (i and 7)) xor -1))) or ((_val and bmask) shl (i and 7))
end def