title: gcc inline assembly - operand type mismatch for `add', trying to create branchless code
body: <p>I'm trying to do some Code Optimization to Eliminate Branches, the original c code is</p>
  
  <pre><code>if( a &lt; b ) 
     k = (k&lt;&lt;1) + 1;
  else
     k = (k&lt;&lt;1)
  </code></pre>
  
  <p>I intend to replace it with assembly code like below</p>
  
  <pre><code>mov a, %rax 
  mov b, %rbx
  mov k, %rcx
  xor %rdx %rdx
  shl 1, %rcx
  cmp %rax, %rax
  setb %rdx
  add %rdx,%rcx
  mov %rcx, k 
  </code></pre>
  
  <p>so I write c inline assembly code like blow, </p>
  
  <pre><code>#define next(a, b, k)\
   __asm__("shl $0x1, %0; \
           xor %%rbx, %%rbx; \
           cmp %1, %2; \
           setb %%rbx; \
           addl  %%rbx,%0;":"+c"(k) :"g"(a),"g"(b))
  </code></pre>
  
  <p>when I compile the code below i got error:</p>
  
  <pre><code>operand type mismatch for `add'
  operand type mismatch for `setb'
  </code></pre>
  
  <p>How can I fix it?</p>