3 ms·
For what it's worth, clang[0] compiles to the vpminu[bwd] + vpcmpeq[bwd] version even from manually written intrinsics of the addition-based version, and has si
by dzaima 4y ago
For what it's worth, clang[0] compiles to the vpminu[bwd] + vpcmpeq[bwd] version even from manually written intrinsics of the addition-based version, and has since clang 7. Though, interestingly enough, it fails to cancel out a following xor.
(and, for completeness, a regular C loop[1], with some massaging to make it more readable)
[0]: https://godbolt.org/z/e7TE5P73Y https://godbolt.org/z/e7TE5P73Y
[1]: https://godbolt.org/z/xhj3WTnxv https://godbolt.org/z/xhj3WTnxv
- moonchild 4y agoThat's unfortunate. The solution with min actually does equal work in this case--it just has a lesser startup cost, hence my mention of a 'hostile environment'--but with greater span, because the high-bit toggling can be done for both inputs in parallel. If you switch to a loop, at the very least, it ought to use the traditional solution, but it doesn't. Also it doesn't use the trick with the saturating subtract. https://godbolt.org/z/76qKs49eW https://godbolt.org/z/76qKs49eW