Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

__assume 

Visual Studio 2005

The __assume intrinsic function passes a hint to the optimizer.


__assume(expression)

Parameters

expression

Condition to be tested.

The optimizer assumes that the condition represented by expression is true at the point where the keyword appears and remains true until expression is altered (for example, by assignment to a variable). Selective use of hints passed to the optimizer by __assume can improve optimization.

//  
// 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.
  }
}

Routine Required header Architecture

__assume

<cmnintrin.h>

x86, ARM, SH-4, MIPS

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.