
Felipe Magno de Almeida wrote:
On 9/15/05, Simon Buchan <simon@hand-multimedia.co.nz> wrote:
Marcin Kalicinski wrote:
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!
<snip> I don't get it, isn't the point of assert that it DOES check them? Or did you mean something like GCC's __builtin_expect? http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Other-Builtins.html#index-g_t_00... For what I know, the point of assert is that it checks in the debug build. But has no cost in the release builds. In this case it is even possible to optimize.
I think this __assume is different from GCC's __builtin_expect because it still believes it will happens, but the __assume will simply assume that the case is impossible to happen, just like what an assertion assumes. So... you want asserts to assure the compiler that the expression should be impossible? I can't think of too many times that would actually generate better code, and may be a source of unexpected behaviour, but better minds than I should think about it, I guess.