Get the latest tech news

Vectorized CLZ and CTZ


clz and ctz are instructions that compute the number of leading (trailing) zero bits in a fixed-size integer. They are natively supported by modern CPUs, though they are not always fast, e.g. tzcnt has a latency of 3 on Arrow Lake. I used ctz in an FPU emulator I’m working on, but figured out how to avoid it with floating-point trickery, and I just realized that this generalizes to a vectorizable ctz polyfill in a round-about way. I also implemented clz for completeness.

None

Get the Android app

Or read this on Hacker News

Read more on:

Photo of CTZ

CTZ

Photo of Vectorized CLZ

Vectorized CLZ

Photo of CLZ

CLZ