I was wrong.

Jb jb at nowhere.com
Thu Aug 14 12:50:45 PDT 2008


"superdan" <super at dan.org> wrote in message 
news:g81o61$21bs$1 at digitalmars.com...
> Jb Wrote:
>
>>
>> "superdan" <super at dan.org> wrote in message
>> news:g81e1l$18js$1 at digitalmars.com...
>> > downs Wrote:
>>
>> >> Null: 729908
>> >> Naive: 1615314
>> >> Speculative for B: 1692860
>> >> Speculative for B/C: 1664040
>> >
>> > the whole premise of speculation is it oils the common path. you have
>> > uniform probabilities.
>> > what you gain on speculating for B you lose in the extra test when
>> > misspeculating on others.
>> > so to really test speculation make B like 90% of cases and retry.
>>
>> To speculate localy you still have to lookup the class info, compare it 
>> to
>> the speculated object type, and then conditionaly branch. You cant avoid 
>> a
>> conditional branch, and as it will share the same pattern as the indirect
>> jump, and (in most cases) the same prediction mechanism, neither will be
>> better predicted than the other.
>
> no that's wrong. conditional branch is better speculated than indirect 
> jump.
> they share no other hardware than the instruction fetching pipe.

Sorry but you dont know what you are talking about. Indirect jumps get a 
slot in the branch target buffer (BTB) the same as conditional branches. 
They both share the same target prediction hardware. It's not only a fact 
it's also common sense that they would do so.

http://www.agner.org/optimize/microarchitecture.pdf

Read the chapter on branch prediction.

http://www.intel.com/design/processor/manuals/248966.pdf

Read Chapter 3.4.1.6


> the mechanism for conditional branch speculation is that stuff is executed 
> in parallel
> on both branches inside the pipeline. the branch that makes it is 
> committed. the other
>  is retired without getting to write to the register file or memory.

Actualy AFAIK no current x86 processor *execute* both branches. What does 
happen is the instruction cache will *prefetch* both branches, so that when 
the BTB decides which way to go it has the instruction data ready.

But it will still cost you a whole pipeline flush if the prediction was 
wrong.


>> So the point is that you cant make the common path any faster unless you
>> actualy *inline* the speculated method. In fact if you dont inline you 
>> are
>> most probably making the situation worse because you are replacing 
>> this...
>
> you are right here tho for the wrong reasons :) yeah speculation is good 
> if there are
> a few good chunky instructions to eat while speculating. if it's a 
> function call that in
> turn is just a ret... the results are nothing to write home about. as it's 
> been shown.

No.. erm NO... and NOOooOOOO!!!!

;-)

Speculation is good if it allows you to inline the method and chop out a 
whole bunch of register shuffling, stack setup, and entry / exit code.

It's got naff all to do with "having shit to do" while you're speculating. 
Just like it's got naff all to do with conditional branches being faster / 
better predicted than indirect calls.





More information about the Digitalmars-d mailing list