0

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?

user1715122
  • 947
  • 1
  • 11
  • 26

1 Answers1

2

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).

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
  • 1
    Intel moved the 128-bit integer SSE ops into 128-bit AVX instructions (with the 3-operand encoding), but otherwise left them alone. The only 256-bit integer ops are for int<->float conversion. AVX2 is where the good stuff is coming. – Cory Nelson Dec 13 '12 at 22:30
  • @Stephen:Could you elaborate on why typecasting won't work i.e when will an integer map to a NaN or how ordering of negative values is reserved? – user1715122 Dec 13 '12 at 23:19
  • @user1715122 I think Stephen misread that and thought you meant to reinterpret the bit pattern. When you do an ordinary type cast, your problems are a) it's slow, probably slower than a conditional move, b) loss of precision, `integer -> floating -> integer` doesn't necessarily round-trip. – Daniel Fischer Dec 13 '12 at 23:33
  • But why will there be a loss in precision, for min, max or shuffle operations? – user1715122 Dec 13 '12 at 23:37
  • @danielfischer: to be honest, I assumed that it was so obvious that doing a conversion wouldn't work and would have terrible performance even if it did that I didn't even consider that the questioner might be asking about it. – Stephen Canon Dec 14 '12 at 00:20