title: How does branch masking work in CryENGINE 3?
body: <p>This part of the CryENGINE SDK headers caught my attention:</p>
  
  <p><em><strong>branchmask.h</em></strong></p>
  
  <pre><code>#ifndef __BRANCHLESS_MASK__
  #define __BRANCHLESS_MASK__
  
  ///////////////////////////////////////////
  // helper functions for branch elimination
  //
  // msb/lsb - most/less significant byte
  //
  // mask - 0xFFFFFFFF
  // nz   - not zero
  // zr   - is zero
  
  ILINE const uint32 nz2msb(const uint32 x)
  {
      return -(int32)x | x;
  }
  
  ILINE const uint32 msb2mask(const uint32 x)
  {
      return (int32)(x) &gt;&gt; 31;
  }
  
  ILINE const uint32 nz2one(const uint32 x)
  {
      return nz2msb(x) &gt;&gt; 31; // int((bool)x);
  }
  
  ILINE const uint32 nz2mask(const uint32 x)
  {
      return (int32)msb2mask(nz2msb(x)); // -(int32)(bool)x;
  }
  
  
  ILINE const uint32 iselmask(const uint32 mask, uint32 x, const uint32 y)// select integer with mask (0xFFFFFFFF or 0x0 only!!!)
  {
      return (x &amp; mask) | (y &amp; ~mask);
  }
  
  
  ILINE const uint32 mask_nz_nz(const uint32 x, const uint32 y)// mask if( x != 0 &amp;&amp; y != 0)
  {
      return msb2mask(nz2msb(x) &amp; nz2msb(y));
  }
  
  ILINE const uint32 mask_nz_zr(const uint32 x, const uint32 y)// mask if( x != 0 &amp;&amp; y == 0)
  {
      return msb2mask(nz2msb(x) &amp; ~nz2msb(y));
  }
  
  
  ILINE const uint32 mask_zr_zr(const uint32 x, const uint32 y)// mask if( x == 0 &amp;&amp; y == 0)
  {
      return ~nz2mask(x | y);
  }
  
  #endif//__BRANCHLESS_MASK__
  </code></pre>
  
  <p>Could someone throw a short explanation how exactly are these functions intended to be used to reduce branches? ILINE I suppose is predefined force inline or something like that. I searched Google about it, but all I found were copies of the CryENGINE headers uploaded in different sites, but no discussions about this specific one.</p>