Dual CPU code

BCS ao at pathlink.com
Mon Feb 2 14:10:56 PST 2009


Reply to bearophile,

> Walter Bright:
> 
>> import std.cpuid;
>> import sse;
>> import nosse;
>> ...
>> if (std.cpuid.sse2())
>> sse2.foo();
>> else
>> nosse2.foo();
> I think that solves my problem, thank you. It's a simple solution
> (maybe I didn't think of it because I use bud that compiles all the
> program in one go).
> 
> I presume that usually the D code in the sse and nosse modules is the
> same, it's just compiled in two different ways, so the two modules may
> just contain two lines of code as:
> 
> module sse;
> mixin(import("shared_module_code.dd"));
> Bye,
> bearophile

my first thought would be to play games with the linker:

define a function EnterA() that calls code
define a function EnterB() that calls code
compile needed code for CPU A to A.obj
Compile needed code for CPU B to B.obj
make a lib with EnterA and A.obj forcing internal linking
make a lib with EnterB and B.obj forcing internal linking
link common code and both libs

making the libs becomes the fun part





More information about the Digitalmars-d mailing list