DMD 1.005 release

Walter Bright newshound at digitalmars.com
Wed Feb 7 13:35:24 PST 2007


BCS wrote:
> Walter Bright wrote:
>> The function gets inlined.
> 
> The equivalent of this doesn't
> 
> version(RowMajor)
> {
>     x = 0
>     for(i=0;i<max;i++)
>     x+=table[i][j];
> }
> else // RowMinor
> {
>     x = 0
>     for(i=0;i<max;i++)
>     x+=table[j][i];
> }
> and IIRC this doesn't ether
> 
> version(X86) // avoid overflow in midpoint calculations
> {
>     asm
>     {
>         MOV low EAX;
>         ADD EAX hi;
>         RCR EAX 1;
>         MOV EAX mid;
>     }
> }
> else
> {
>     mid = (hi-low)/2 + low;
> }

I agree the inlining isn't perfect. But in the small number of cases 
where this matters, you can use the version=XXX command line switch.

>>>
>>> ====You can't break across function calls
>>>
>>> switch(i)
>>> {
>>>     case 1:
>>>         version(Baz)
>>>             if(baz) break;
>>>         else
>>>             break;
>>>     case 2:
>>>
>>>     ...// lots of un versioned code
>>> }
>>
>>     if (globalversion.baz && baz)
>>         break;
> 
> The point is to have all of the versioning done by the time you link, 
> that leaves a runtime check for version info.

Not if it's a const.


>>> ====lots of version combinations
>>>
>>> version(Foo) i = foo(i);
>>> version(Boo) i = boo(i);
>>> version(Fig) i = fig(i);
>>> version(Baz) i = baz(i);
>>> version(Bar) i = bar(i);    //32 options???
>>
>>
>> i = abc(i);    // a different abc is implemented for each version.
> 
> All 32 possibilities??? What if there are 16 independent versions? 
> that's 64K functions! And no that is not an unlikely case, say "i" is a 
> parse tree and we want to add different types of annotation depending on 
> what features are enabled.

I'd use bit flags instead of versions for such things. If I had a 
situation with 32*16 version combinations, I think I'd seriously 
consider reengineering what the program considers as a "version". After 
all, do you really want to generate 64,000 binaries? How are you going 
to test them <g>?



More information about the Digitalmars-d-announce mailing list