I’m doing some GPGPU’ing. The algorithm I am converting has some small, really rather trivial if-else/branching.

To avoid warp divergence, I have come up with several alternatives to troublesome if-else statements, but I am unsure which alternatives are best/fastest.

**Context:**

```
int myspecialID;
int a, x;
int b, y;
int c, z;
```

**Problem:** What is the best way to set a = b or c, and x = y or z, according to myspecialID, i.e.

```
if (myspecialID == 1)
{ a = b; x = y; }
else
{ a = c; x = z; }
```

**Solution 1:**

```
a = myspecialID == 1 ? b : c;
x = myspecialID == 1 ? y : z;
```

**Solution 2:**

```
a = b; x = y;
if (myspecialID != 1)
{a = c; x = z;}
```

**Solution 3:**

```
bool is_ID_1 = (myspecialID == 1);
a = (b * is_ID_1) + (c * (!is_ID_1));
x = (y * is_ID_1) + (z * (!is_ID_1));
```

I was leaning towards Solutons 2 and 3. But I can’t decide which one is better because I don’t know if “Overhead time of warp divergence” is greater than “multiplication by bool (i.e. 1 or 0)”.

Does anybody know? Since the “multiplication” is restricted to 1 or 0, can this be optimized in any way? Indeed, it is not a typical multiplication operation - it is so trivial in either case.