←back to thread

103 points vortex_ape | 1 comments | | HN request time: 0.224s | source
Show context
xeeeeeeeeeeenu ◴[] No.42742731[source]
> So on x86_64 processors, we have to branch to say “a 32-bit zero value has 32 leading zeros”.

Not if you're targeting x86-64-v3 or higher. Haswell (Intel) and Piledriver (AMD) introduced the LZCNT instruction that doesn't have this problem.

replies(2): >>42742835 #>>42742859 #
1. sltkr ◴[] No.42742835[source]
You can also very trivially do (codepoint | 1).leading_zeros(), then you can also shave one byte off the LEN table. (This doesn't affect the result because LEN[32] == LEN[33] == 1).