mirror of https://gerrit.osmocom.org/libosmocore
bitvec_read_field(): optimize by expanding bytenum_from_bitnum()
The bitvec_read_field() is used in performance critical places, such as the CSN.1 decoder in osmo-pcu. Thus the less conditional statements we have in the parsing loop, the better. The bitvec_get_bit_pos() alone is quite a complex function, which does check the boundaries and even supports the L/H syntax. Even if it gets inlined by the compiler, we don't really want to run redundant checks and run bitval2mask() on each iteration. Change-Id: I438fc82d33ab2edbabd4215ec7bc46afb07d50ab
This commit is contained in:
parent
8a55a6c571
commit
49b6040048
|
@ -491,8 +491,10 @@ uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned
|
|||
errno = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
int bit = bitvec_get_bit_pos((const struct bitvec *)bv, bv->cur_bit);
|
||||
if (bit)
|
||||
unsigned int bytenum = bytenum_from_bitnum(bv->cur_bit);
|
||||
unsigned int bitnum = 7 - (bv->cur_bit % 8);
|
||||
|
||||
if (bv->data[bytenum] & (1 << bitnum))
|
||||
ui |= ((uint64_t)1 << (len - i - 1));
|
||||
bv->cur_bit++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue