<b>(a) </b> if(foo & 1) bar = a; else bar = b; <b>(b) </b> bar = (foo & 1) ? a : b; <b>(c) </b> bar = b + (a - b)*(foo & 1); <b>(d) </b> /* -(foo & 1) is either all zeros or all ones */ bar = b + ((a - b) & -(foo & 1));
Example 4: (a) Conditional that requires two branch instructions; (b) a less-obvious conditional; (c) using arithmetic to avoid branches; (d) using logical operations to avoid branches.