Is integer multiplication really done at the same speed as addition on a modern CPU?

后端 未结 11 759
梦谈多话
梦谈多话 2020-12-23 13:31

I hear this statement quite often, that multiplication on modern hardware is so optimized that it actually is at the same speed as addition. Is that true?

I never ca

11条回答
  •  醉话见心
    2020-12-23 14:20

    No, they're not the same speed. Who told you that?

    Agner Fog's instruction tables show that when using 32-bit integer registers, Haswell's ADD/SUB take 0.25–1 cycles (depending on how well pipelined your instructions are) while MUL takes 2–4 cycles. Floating-point is the other way around: ADDSS/SUBSS take 1–3 cycles while MULSS takes 0.5–5 cycles.

提交回复
热议问题