Kroma
Kroma

Reputation: 1151

assembly - x86_64 - predicates

I am coding some assembly for x86_64 and arm.

I would like to know whether x86_64 has some ways to define branch predicates.

I searched in Intel documentation but failed to find relevant info.

We have cmov but it is rather slow and a cmp jmp combo tends to be faster.

Upvotes: 0

Views: 800

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 364160

ARM predicates are an alternative to branches. IDK what you mean by "branch predicates". Maybe you mean "predicate conditions"?

cmov is often worth it compared to a branch that only skips over one or two instructions, if it's at all unpredictable. Broadwell and Skylake run cmov as a single uop, but previous microarchitectures need 2 uops since it has 3 input dependencies. It also creates a data dependency instead of a control dependency. Branch prediction, when it works, can be better. Also, cmov can't take an immediate operand, which is frustrating in many cases.

Another instruction that can use a condition as an input is setcc. Use xor reg,reg / set flags / setcc low-byte-of-reg, to avoid partial-reg stalls when reading the full register.

For the carry condition, sbb same,same will produce 0 or -1 (useful as an AND mask), or adc reg, 0 will do reg += CF.

Upvotes: 2

Related Questions