INC instruction vs ADD 1: Does it matter?

前端 未结 2 1038
予麋鹿
予麋鹿 2020-11-22 02:25

From Ira Baxter answer on, Why do the INC and DEC instructions not affect the Carry Flag (CF)?

Mostly, I stay away from INC and DEC

2条回答
  •  爱一瞬间的悲伤
    2020-11-22 03:18

    Depending on the CPU implementation of the instructions, a partial register update may cause a stall. According to Agner Fog's optimization guide, page 62,

    For historical reasons, the INC and DEC instructions leave the carry flag unchanged, while the other arithmetic flags are written to. This causes a false dependence on the previous value of the flags and costs an extra μop. To avoid these problems, it is recommended that you always use ADD and SUB instead of INC and DEC. For example, INC EAX should be replaced by ADD EAX,1.

    See also page 83 on "Partial flags stalls" and page 100 on "Partial flags stall".

提交回复
热议问题