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
(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