6 ms·
Trying to understand this. Using latencies from Zen 1 instruction table (see https://www.agner.org/optimize/instruction_tables.pdf https://www.agner.org/optimi
by abainbridge 6y ago
Trying to understand this.
Using latencies from Zen 1 instruction table (see https://www.agner.org/optimize/instruction_tables.pdf https://www.agner.org/optimize/instruction_tables.pdf):
mov dword [rsi], eax ; MOV m,r latency is 4
add dword [rsi], 5 ; ADD m,i latency is 6
mov ebx, dword [rsi] ; MOV r,m latency is 4
Total = 14
Each instruction depends on the result of the previous, so we need to sum all the latency figures to get the total cycle count. Is this right? How does Agner make it add up to 15?
Then for Zen 2:
mov dword [rsi], eax ; MOV m,r latency is 0 (rather than 4,
; because it is mirrored)
add dword [rsi], 5 ; ADD m,i cannot find an entry for this.
; Looks like there's a typo in the doc.
; I guess the latency is 1.
mov ebx, dword [rsi] ; MOV r,m latency is 0
Total = 1
Again, how does Agner make it add up to 2?
And for Intel Skylake:
mov dword [rsi], eax ; MOV m,r latency is 2
add dword [rsi], 5 ; ADD m,i - latency is 5
mov ebx, dword [rsi] ; MOV r,m latency is 2
Total = 9
- CalChris 6y agoI think the Zen 2 reasons about the operations and operands and converts them into something like these micro-ops and then schedules them for a functional unit and the renamer: functional unit renamer add tmp_reg, eax, 5 st [rsi], tmp_reg mov ebx, temp_reg Consequently, I don't think you can use the latency tables directly to get "2". I think Agner probably got those 15 and 2 aggregate numbers from measuring them directly rather than calculating them from the latency tables. BTW, I'm hand waving on the micro-ops and FUs. There's probably some address generation, ... going on that I'm leaving out. I don't even think the renamer requires a translated micro-op. You could replace tmp_reg with renamed(ebx). Now the downside. What happens at an exception? You have to back all of this optimization out.
- vardump 6y ago> Now the downside. What happens at an exception? You have to back all of this optimization out. Just what always happens at an exception. You just replay everything up until the exception occurred.