Predefined Version expansion

Don Clugston dac at nospam.com.au
Tue Apr 3 23:33:52 PDT 2007


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.



More information about the Digitalmars-d mailing list