I was wrong.

Jb jb at nowhere.com
Thu Aug 14 09:39:25 PDT 2008


"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.

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...

(ignoring parameter setup which will be identical)

MOV   EAX.[objptr.vtable+offset]
CALL  EAX

With this...

MOV   EAX,[objptr.classinfo]
CMP    EAX,expectedclasstype
JNE      @wrongtype
CALL   @expectedtypemethod
JMP     @done
@wrongtype
// normal vtable code here
@done

And there's no way that will be faster imo. Unless perhaps you have a 486 or 
P1. ;-)






More information about the Digitalmars-d mailing list