简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM