Is there a ffs() equivalent for std::bitset?

Viewed 622

I want to find the index of the first set bit in a bitset. Most modern CPU's can make use of the FFS instruction to speed this up on normal sized numerical types. Can I make use of this instruction when I want to find the first set bit in a C++ std::bitset?

1 Answers

The goal here is to write clear code such that the optimizer recognises the operation. It probably knows about ffs and when to use it.

A fixed-size array helps, it gives constants in the loop which facilitates unrolling. Alignment also looks in your favour.

Related