|
Boost : |
From: Simon Buchan (simon_at_[hidden])
Date: 2005-09-15 00:02:11
Felipe Magno de Almeida wrote:
> On 9/15/05, Simon Buchan <simon_at_[hidden]> 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_005f_005fbuiltin_005fexpect-2279
> 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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk