News for hackers. Stuff that matters.
Re:Unsigned comparisons in AVX2/SSE: a quick note by dzaima on Friday August 26, 2022 @05:36AM (#32605121)
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

[1]: https://godbolt.org/z/xhj3WTnxv

Re:Unsigned comparisons in AVX2/SSE: a quick note by moonchild on Friday August 26, 2022 @05:47AM (#32605218)
That'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