Cartesius00
Cartesius00

Reputation: 24414

SSE ints vs. floats practice

When dealing with both ints and floats in SSE (AVX) is it a good practice to convert all ints to floats and work only with floats? Because we need only a few SIMD instructions after that, and all we need to use is addition and compare instructions (<, <=, ==) which this conversion, I hope, should retain completely.

Upvotes: 2

Views: 2049

Answers (1)

Mysticial
Mysticial

Reputation: 471569

Expand my comments into an answer.

Basically you weighing the following trade-off:

Stick with integer:

  • Integer SSE is low-latency, high throughput. (dual issue on Sandy Bridge)
  • Limited to 128-bit SIMD width.

Convert to floating-point:

  • Benefit from 256-bit AVX.
  • Higher latencies, and only single-issue addition/subtraction (on Sandy Bridge)
  • Incurs initial conversion overhead.
  • Restricts input to those that fit into a float without precision loss.

I'd say stick with integer for now. If you don't want to duplicate code with the float versions, then that's your call.

The only times I've seen where emulating integers with floating-point becomes faster are when you have to do divisions.


Note that I've made no mention of readability as diving into manual vectorization probably implies that performance is more important.

Upvotes: 6

Related Questions