Boost logo

Boost :

From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2005-09-13 17:22:29


Hi All,

Have you considered modifying BOOST_ASSERT to use __assume on MSVC?

Briefly speaking __assume(expr) is a hint for optimizer that 'expr'
evaluates to nonzero. It can help optimize the code. Standalone use of
__assume is not recommended because compiler does not check if the
assumption is correct, and if it isn't the program is ill formed. But it
fits perfectly in ASSERT macro. This way putting many ASSERTs will not only
help to verify the code - it will also help the optimizer. Wow!

To be sure I did a small test with MSVC:

int f(int n)
{
  // __assume(n == 0);
  if (n == 1) return 1; else return 0;
}

produces:

  xor eax, eax
  cmp DWORD PTR _n$[esp-4], 1
  sete al
  ret 0

with __assume uncommented:

  xor eax, eax
  ret 0

And the comparison is gone.

Microsoft docs for __assume are here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_36.asp

cheers,
Marcin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk