←back to thread

170 points judicious | 2 comments | | HN request time: 0.434s | source
Show context
mwkaufma ◴[] No.45408552[source]
Is cmov branchless, or just branching by another name?
replies(3): >>45409160 #>>45409795 #>>45410660 #
1. senfiaj ◴[] No.45409160[source]
From my understanding branches are about conditional jump instructions. Here are some of them:

  JZ, JE - Jump if Zero, Jump if Equal
  JNZ, JNE - Jump if Not Zero, Jump if Not Equal
  JC - Jump if Carry
  JNC - Jump if No Carry
  JO - Jump if Overflow
  JNO - Jump if No Overflow
  JS - Jump if Signed (Negative)
  JNS - Jump if Not Signed (Positive or Zero)
  JP, JPE - Jump if Parity, Jump if Parity is Even
  JNP, JPO - Jump if Not Parity, Jump if Parity is Odd
replies(1): >>45409380 #
2. mwkaufma ◴[] No.45409380[source]
The article's claim is that branchless code avoids branch-prediction, and therefore optimizes better on speculative CPUs for certain workloads. Jump instructions obviously incur branch-prediction; my question is is CMOV incurs branch prediction, also? Certainly the internal micro-ops behind the instructions will still need to make a prediction or stall?