__assume
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

__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

Show:
© 2016 Microsoft