Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Documentation for __assume() statement?

McCalpinJohn
Honored Contributor III
1,103 Views

I have seen the "__assume()" statement used in Intel examples, such as "__assume(n1%16==0)" used in the recommendations in the article at https://software.intel.com/en-us/articles/data-alignment-to-assist-vectorization

I have not been able to find any discussion of this function in the compiler documentation.   I can find a description of "__assume_aligned()", but not for  "__assume()".    This may be because the search function for the compiler documentation ignores leading punctuation.   So searching for "assume_aligned" returns useful results, while searching for "__assume" returns any page that contains the word "assume"  -- 71 matches in the Intel version 16 compiler docs.  The web-browser-based documentation portal is too slow to look through that many results one at a time, so if anyone knows if there is documentation for this statement, I would appreciate a pointer!

0 Kudos
7 Replies
Judith_W_Intel
Employee
1,103 Views

 

This is a Microsoft invention (although we support it on Linux too):

See documentation at:

https://msdn.microsoft.com/en-us/library/1b3fsfxw.aspx

http://stackoverflow.com/questions/9504206/are-measurable-performance-gains-possible-from-using-vcs-assume

Judy

 

 

 

 

0 Kudos
McCalpinJohn
Honored Contributor III
1,103 Views

Thanks!  

Not many answers there, but at least some ideas that I can play with....

0 Kudos
SergeyKostrov
Valued Contributor II
1,103 Views
Did you see that C example? // // 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. } }
0 Kudos
SergeyKostrov
Valued Contributor II
1,103 Views
>>...I can find a description of "__assume_aligned()", but not for "__assume()"... These are two different functions, 1st is a true intrinsic and 2nd one is not, however it depends on a C++ compiler. __assume_aligned() helps with aligning of data, and __assume() is a hit to an optimizer ( I think you already know it ).
0 Kudos
McCalpinJohn
Honored Contributor III
1,103 Views

The Microsoft web page just says that the argument to the __assume() statement can be "any statement that is assumed to evaluate to true".    The only example provided -- "__assume(0)" means that the compiler can assume that this code will never be reached.  

The Intel web page gives only one example -- "__assume (n1%16==0)", and uses it as a way to provide information about the alignment of array references with constant offsets.

I guess I was hoping for some documentation of what types of statements the compiler might be likely to take advantage of.   Since there does not appear to be any such documentation, I will __assume() that this is not a feature of the compiler that is likely to be useful....

0 Kudos
SergeyKostrov
Valued Contributor II
1,103 Views
>>... >>The Intel web page gives only one example -- "__assume (n1%16==0)", and uses it as a way to provide information >>about the alignment of array references with constant offsets. Even if Intel's example is valid, to some degree, I think a developer ( possibly intern and there is nothing wrong with that... ), who created that example, misunderstood the true purpose of that function. I use a strictly dedicated macros, like: ... #define _RTISALIGNED( p, n ) ( ( ( RTusize_t )( p ) % ( n ) == 0 ) ? 0 : 1 ) #define _RTASSERT_ISALIGNED( p, n ) \ { \ if( ( ( RTusize_t )( p ) ) % ( n ) != 0 ) \ { \ CrtPrintfA( "Pointer is Not aligned on %ld-byte boundary\n", ( RTint )n ); \ } \ } \
0 Kudos
SergeyKostrov
Valued Contributor II
1,103 Views
>>... software.intel.com/en-us/articles/branch-and-loop-reorganization-to-prevent-mispredicts >>... software.intel.com/en-us/articles/data-alignment-to-assist-vectorization I wish I would have more time to read all these articles you've read already... :)
0 Kudos
Reply