I store a variable amount of bits in a list. I need to look up the bits in the range of [i,j]. Currently I'm storing the bits in a vector of unsigned 32 bit integers.
This is how I do the lookup:
std::uint32_t
Data::findInt3(const std::vector<std::uint32_t>& input, int size, int pos) {
pos = pos*size;
int firstc = pos >> 5;
int ipos = pos & 31;
int end = ipos+size;
std::uint64_t t = input[firstc];
std::uint64_t num = (t << 32) | input[firstc+1];
std::uint64_t number = num >> (64-end);
number = number & ((1 << size)-1);
return number;
}
This piece of code is called A LOT of times. I guess just small speed-ups will be very beneficial. Can anyone see anything which could be made better? Like shifting something instead of or'ing. Or which is faster?
Thanks
Aucun commentaire:
Enregistrer un commentaire