4 ms·
Everything in this post applies to C too, so it's not C++ specific. And the same gotchas apply for every case when you use inline assembly. I wouldn't call it a
by hifromwork 2y ago
Everything in this post applies to C too, so it's not C++ specific. And the same gotchas apply for every case when you use inline assembly. I wouldn't call it a trick... Just an interesting workaround for a performance bug in Clang.
The post can be boiled down to "Clang doesn't compile this intrinsic nicely, so just use inline asm directly. But remember that you need to have a non-asm special case to optimize constants too, and you can achieve this with __builtin_constant_p".
- GrantMoyer 2y agoI wouldn't call this a performance bug in clang. It's an optimization working as intended.
- dooglius 2y agoI would challenge you to find a processor on which the rsqrt plus two newton-raphson iterations is not slower than plain sqrt. (We don't know what mtune the author used)
- pclmulqdq 2y agoThe author probably didn't use any mtune setting, which is likely the problem. If you look at older cores on Agner's instruction tables, SQRT has been getting steadily faster over time. This implementation is slightly faster on old Intel machines, for example.
- GrantMoyer 2y agoAccording to Intel, any processor before Skylake (section 15.12 from [1]). [1]: https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=248966-Optimization-Reference-Manual-V1-050.pdf#G16.92586 https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=24...