3 ms·
I would have expected the Go compiler to emit the POPCNT instruction on it's own. Most current C compilers will even detect if you implement a popcount in softw
by pantalaimon 6y ago
I would have expected the Go compiler to emit the POPCNT instruction on it's own.
Most current C compilers will even detect if you implement a popcount in software and replace it with a single POPCNT instruction - why does Go not do something like that as well?
- smartisch 6y agoBecause Go Gc amd64 target supports CPUs that do not have support for the popcnt instruction and runtime detection + checking a bool around each popcnt instruction is a big overhead. There is no mtune or march for Go Gc amd64 like (Go) gcc does.
- pantalaimon 6y agoHuh, TIL. I always assumed this to be a rather old instruction, but turns out it was only added fairly recently on x86 https://vaibhavsagar.com/blog/2019/09/08/popcount/ https://vaibhavsagar.com/blog/2019/09/08/popcount/
- saagarjha 6y agoGo's compiler values being fast over potential optimizations, I believe, so this might be something that they don't think is something the compiler should do.
- loeg 6y agoGo's compiler is not particularly sophisticated.
- saagarjha 6y ago(By design.)
- deleted 6y ago[deleted]