May 07, 2007

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

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
May 07, 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
1 2
Next ›   Last »