64-bit and SSE

Rainer Deyke rainerd at eldwood.com
Tue Mar 2 20:01:01 PST 2010


On 3/2/2010 14:28, Don wrote:
> retard wrote:
>> Why not dynamic code path selection:
>>
>> if (cpu_capabilities && SSE4_2)
>>   run_fast_method();
>> else if (cpu_capabilities && SSE2)
>>   run_medium_fast_method();
>> else
>>   run_slow_method();
>>
>> One could also use higher level design patterns like abstract
>> factories here.
> 
> The method needs to be fairly large for that to be beneficial. For
> fine-grained stuff, like basic operations on 3D vectors, it doesn't work
> at all. And that's one of the primary use cases for SSE.

Why not do it at the largest possible level of granularity?

int main() {
  if (cpu_capabilities && SSE4_2) {
    return run_fast_main();
  } else if (cpu_capabilities && SSE2) {
    return run_medium_fast_main();
  } else {
    return run_slow_main();
  }
}

The compiler should be able to do this automatically by compiling every
single function in the program N times with N different code generation
setting.  Executable size will skyrocket, but it won't matter because
executable size is rarely a significant concern.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list