<p>Yes ( with 50% of the FMA 32b throughput on nVIDIA Maxwell).</p>

<p>See 
<a href="https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions">https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions</a></p>

CC BY-SA 3.0
2016-03-04T20:43:42.453Z
2016-03-04T21:03:29.910Z
2016-03-04T21:03:29.910Z
Fabrice NEYRET
<p>I'm aware that most modern GPUs, although designed for floating point, are more or less equivalent in integer performance these days, with a few caveats like the lack of a fused multiply add. I'm not sure how this applies to shift operations though. I'm doing Marching Cubes on GPU, initially writing out a 32-bit packed position for each surface cube then unpacking these in a later pass to the actual vertices in that cube, like this : </p>

<pre><code>ivec3 unpackedPos = ivec3( packedPos &gt;&gt; 20 &amp; 0x3FF,
                         packedPos &gt;&gt; 10 &amp; 0x3FF,
                         packedPos &amp; 0x3FF);
</code></pre>

<p>It just occurred to me to wonder if shader units have barrel shifters in them these days? Am I doing 2 shifts here or 30?</p>

<p>EDIT>>
I'm an idiot... Thanks for the answers guys, useful to know, but I've been going about this all wrong. I should just be using the RGB10_A2UI texture format then packing/ unpacking with a single image load/store instruction instead of messing around with bitshifts myself. </p>

<p>RE_EDIT>> Or not... This method apparently works on red boxes but not on green ones, so it's back to bit-shifts.</p>

<gpu><performance>
Do modern GPUs contain barrel shifters?
russ
# Do modern GPUs contain barrel shifters?

(Asked by: username_0 on 2016-03-03)

I'm aware that most modern GPUs, although designed for floating point, are more or less equivalent in integer performance these days, with a few caveats like the lack of a fused multiply add. I'm not sure how this applies to shift operations though. I'm doing Marching Cubes on GPU, initially writing out a 32-bit packed position for each surface cube then unpacking these in a later pass to the actual vertices in that cube, like this :

```
ivec3 unpackedPos = ivec3( packedPos >> 20 & 0x3FF,
                         packedPos >> 10 & 0x3FF,
                         packedPos & 0x3FF);

```

It just occurred to me to wonder if shader units have barrel shifters in them these days? Am I doing 2 shifts here or 30?

EDIT>>
I'm an idiot... Thanks for the answers guys, useful to know, but I've been going about this all wrong. I should just be using the RGB10\_A2UI texture format then packing/ unpacking with a single image load/store instruction instead of messing around with bitshifts myself.

RE\_EDIT>> Or not... This method apparently works on red boxes but not on green ones, so it's back to bit-shifts.

**Tags:** gpu, performance


---

## 1 answers

### Answer by username_1 on 2016-03-04. Score: 5 | Accepted answer

Yes ( with 50% of the FMA 32b throughput on nVIDIA Maxwell).

See
<https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions>


---

