user1715122
user1715122

Reputation: 967

Minimum of signed/unsigned integers using AVX

I was looking through the AVX instruction guide and though there are load, store and permute operations for 32-bit integer values, other operations such as determining minimum or maximum values, or shuffle operations are present only for floats and doubles.

So, if I wanted to use these operations for 32-bit integers, do I need to typecast it to floats, and then typecast it back or is there some other instruction that I'm missing?

Also, do the shuffle masks remain the same, as they were for floats, if I wanted to use it on 32-bit integers?

Upvotes: 0

Views: 1294

Answers (1)

Stephen Canon
Stephen Canon

Reputation: 106317

The bulk of the integer operations for 32B vectors are in the AVX2 extension (not the initial AVX extension, which is almost entirely floating-point operations). Intel's most recent AVX Programming Reference has the complete details; you may also want to look at Intel's blog post announcing some of the details.

Unfortunately, you cannot use the floating-point min or max operations to simulate those operations on integer data, as a significant number of integers map to NaN values when interpreted as floating-point data, and the semantics for NaN comparisons don't do what you would want for integer comparisons (you also would need to deal with the fact that floating-point encodings are sign-magnitude, so the ordering of negative values is "reversed", and that +0 and -0 compare equal).

Upvotes: 2

Related Questions