C++: Mysteriously huge speedup from keeping one operand in a register

后端 未结 3 2267
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 19:39

I have been trying to get an idea of the impact of having an array in L1 cache versus memory by timing a routine that scales and sums the elements of an array using the foll

3条回答
  •  盖世英雄少女心
    2020-12-22 20:27

    I can't actually reproduce this because my compiler (gcc 4.7.2) keeps total in a register.

    I suspect the main reason for the slowness doesn't have to do with the L1 cache, but rather is due to the data dependency between the store in

    movsd   %xmm0, -72(%rbp)
    

    and the load on the subsequent iteration:

    addsd   -72(%rbp), %xmm0
    

提交回复
热议问题