__assume
Visual Studio 2005
The __assume intrinsic function passes a hint to the optimizer.
__assume(expression)
Parameters
- expression
- Condition to be tested.
//
// A common use of __assume tests the default case of a switch statement.
//
#ifdef DEGUG
# define ASSERT(e) ( ((e) || assert(__FILE__, __LINE__) )
#else
# define ASSERT(e) ( __assume(e) )
#endif
void gloo(int p)
{
switch(p){
case 1:
blah(1);
break;
case 2:
blah(-1);
break;
default:
__assume(0);
// This tells the optimizer that the default
// cannot be reached. Hence, no extra code
// is generated to check that 'p' has a value
// not represented by a case arm. This makes the switch
// run faster.
}
}