Predefined Version expansion

Pragma ericanderton at yahoo.removeme.com
Wed Apr 4 07:14:17 PDT 2007


Don Clugston wrote:
> Daniel Keep wrote:
>>
>> Walter Bright wrote:
>>> Don Clugston wrote:
>>>> Yes, it's possible to detect the CPU type at runtime, but the
>>>> performance penalty is appalling for very short functions.
>>> If it is, then one should put the switch at an enclosing level.
>>
>> Out of interest, which is faster: a branch at the start of a function
>> (say, just a comparison with a bool), or using function pointers that
>> are set up to point to the correct implementation at start-up?
>>
>>     -- Daniel
> 
> I suspect the bool comparison would be *much* quicker, since the branch 
> is trivially predictable, and will only cost a single clock cycle. 
> AFAIK, it's only in the past two years that any CPUs have had branch 
> prediction for indirect branches. OTOH, the version involving branches 
> would probably be less code-cache efficient.
> The fastest option would be to patch the CALL instructions directly, 
> just as a linker does. DDL will probably be able to do it eventually.

I'm starting to see what you mean.  If DDL kept generalized fixup data around during runtime, it would be trivial to 
swap one function address for another.  The only catch is that this technique would only be available to dynamic modules 
- the pre-linked .exe code can't be modified this way.

I'll keep this in mind.

-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list