Anton Ertl wrote:
> Terje Mathisen <terj…@tmsw.no> writes:
>> Anton Ertl wrote:
>>> Terje Mathisen <terj…@tmsw.no> writes:
>>>> Also, every switch between a sequence of inner core double-speed opcodes
>>>> and anything else caused a significant bubble.
>>>
>>> This is the first time I read about that. And I have not seen it in
>>> my own measurements, but then, maybe I did not measure the right
>>> things. Can you elaborate: E.g., give a sequence, and explain how big
>>> the bubble for that sequence is.
>>
>> I don't remember exactly, but believe it was on the order of 1-3
>> (external) clock cycles either way. Even at the lower limit, this meant
>> losing 4 double-clocked ops in overhead to execute a single slow opcode
>> like SHR.
>
> AFAIK SHR was not just slow because it was not executed in the
> double-clocked ALU, but because it was executed in the mmxsh subunit
> according to Agner Fog's instruction tables. His tables list latency
> 4+1 for shifts by immediate values and 6+0 for shifts by cl; the +1 or
> +0 happens if the execution unit of the next instruction is different
> from the current one.
>
> From what I read, shift and multiply shipped the operands over to
> functional units elsewhere (mmxsh in this case), losing a cycles or so
> each time a clock domain is crossed. So let's see how fast the MMX
> shifts are: An instruction like PSRLD with a mmx register operand and
> an immediate operand costs 2+1 cycles. So apparently shipping the GPR
> value over to the MMX shift unit costs 1 cycle there and 1 cycle back.
> For PSRLD xmm, xmm the cost is also 2+1; apparently SHR reg, CL has to
> do something extra.
>
>> All the fast opcodes did half the register (16 bits) in each half-cycle,
>> so any instruction like shift right which needed access to the high bits
>> before it could start had to wait for that before the full-size result
>> could be sent out of the inner core, then do the intended instruction,
>> then move the result back into the inner core.
>
> The most common instructions that are not in the double-speed ALU are
> loads, and for MOV r32,m Agner Fog lists 2+0 cycles of latency. For
> an ALU instruction like ADD r,r Agner Fog lists 0.5 + 0.5..1 cycles of
> latency.
>
> So for sequences of n repetitions of ADD r,r; MOV r,(r) the total
> latency is 3*n cycles.
>
> And for sequences of n repetitions of ADD r,r; ADD r,r; MOV r,(r) the
> total latency of n*4 cycles. Neither is worse than if there was no
> double-clocked ALU.
>
> Looking up Prescott (later Pentium 4s without double-clocked ALU and
> partially with AMD64 support) numbers, Agner Fog lists 1+0 cycles
> latency for SHR r32,imm and 2+0 for SHR r32,CL, and alu1 as the unit,
> so the integer ALU now can shift. ADD r,r has a latency of 1+0, and
> MOV r32,m has a latency of 2+0. So for Prescott these latencies are
> quite ok. What is strange is that the LEA latencies are listed as 2.5
> and 3.5.
Did I make a typo, or just didn't remember?
You are correct, it was both MUL and LEA which got much slower at the same time, taking away most ways to calculate addresses quickly.
Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"