Feature request: First class labels

janderson askme at me.com
Sun May 6 22:16:19 PDT 2007


Daniel Keep wrote:
> 
> janderson wrote:
>> Daniel Keep wrote:
>>>> void padd(ubyte[] a, ubyte[] b)
>>>> {
>>>> selectSSE2:
>>>>     invariant if( cpuid.hasSSE2 )
>>>>     {
>>>>         // SSE2 implementation
>>>>     }
>>>>     else
>>>>     {
>>>>         // Software implementation
>>>>     }
>>>> }
>>>>
>>>> void reset_padd()
>>>> {
>>>>     break padd.selectSSE2;
>>>> }
>> What about if the compiler just detected the use of a constant, and you
>> didn't have to do anything be specify the variables as const.  Also the
>> compiler could do a better optimisation on those loops by taking the
>> jump out all together and having 4 separate loops.
>>
>> -Joel
> 
> If the contents of the conditional were constant, you could just use
> static if and remove the branch altogether.
> 
> 	-- Daniel
> 

I apologies for not being clear, I was talking about the C++ kind.  They 
can be initiated once every time the function is called.

For instance in C++ you can do:

void foo()
{
	const Y = rand();
	printf("%d\n", Y);
}

...

foo()
foo();

Any you'll get different numbers each time.  You can also do this:

void foo(const int X) ...

Clearly the compiler should be able to figure out that X never changes 
if its a simple type.

-Joel



More information about the Digitalmars-d mailing list