0

I have the following sequence of instructions:

Address     instr  Operands
4357128L    cmp  {"x1", "#16"}
4357132L    bne  {"4356768"}
4357136L    add  {"w19", "w6","#16"}
4357140L    add  {"x0", "x0", "#16"}
4357144L    bhi  {"4387895"}

after cmp is executed, the nzcv as well as the conditional flags are updated (eq_ne, hi_ls, cs_cc etc..). So in an out of order architecture, how is this executed? Lets consider ARM Cortex A77 for example. It has multiple integer execution units. So cmp and add instructions could be issued in the same cycle. So are the conditional flags only updated after the inorder commit? or since conditional flags are required to be updated, are they all not issued in the same cycle? Also the conditional branches cannot be issued until the inorder commit for the instruction prior to it is completed right? So they will be blocked in the issue stage ie.. 4357132L bne can be only issued to its execution unit only after 4357128L cmp gets commited. And 4356772L bhi can only be issued to its execution unit only after 4357140L add gets commited. Is my understanding right? Any input would be appreciated. Regards, Tom

Tom Jose
  • 33
  • 4
  • 3
    Same way as data dependencies between two insns like `add`; the flags register is renamed and can be an input and/or output. – Peter Cordes Mar 29 '22 at 09:14
  • 1
    The conditions like `eq` and `ne` just specify what to do with nzcv, they're not actually stored separately. Branches can execute (to check the prediction made by the front-end) as soon as their nzcv input is ready, not having to wait for retirement. I thought I'd written an answer specifically about what a branch instruction does when it executes, but I can't find it now; maybe see [How does the branch predictor know if it is not correct?](https://stackoverflow.com/q/24852649) / [What exactly happens when a skylake CPU mispredicts a branch?](https://stackoverflow.com/q/50984007) – Peter Cordes Mar 29 '22 at 10:31
  • 1
    Or near duplicate: [is the branch instruction data dependent?](https://stackoverflow.com/q/40116948) – Peter Cordes Mar 29 '22 at 10:31
  • @PeterCordes Thank you very much for your response. I will check the links shared. – Tom Jose Mar 29 '22 at 10:56

0 Answers0