On 12/11/25 20:11, Richard Henderson wrote:
On 12/10/25 07:16, Paolo Bonzini wrote:
This is more efficient both when generating code and when testing
flags.

I guess sbb x,x appears quite frequently in x86 setcc computation, and the testing of the flags is much less important than the straight line code generation?

Yes. And to be honest, in the most common idioms generated for a modern processor the whole computation ends up being dead, so it doesn't really matter to have this vs. CC_OP_SBB or CC_OP_SUB. For example memcmp uses it for "(x < y) ? -1 : 1":

                 subq     %rcx, %rax
                 sbbl     %eax, %eax
                 orl      $1, %eax

and this is also common, for "(x < y) ? VALUE : 0"

                 subq     %rcx, %rax
                 sbbq     %rax, %rax     ; could be sbbl :)
                 andl     $0x1234, %eax

In old hand-written assembly it is used more creatively, and having simpler generated code can matter if there are memory operations after the sbb. I did this just because it's silly to compute both negsetcond and setcond...

Paolo


Reply via email to