Re: helping the compiler with asserts-hints to optimize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The obvious improvement is to make your asserts use
__builtin_unreachable in "release" mode.  So you have something like this:

#ifdef DEBUG
#define assert(expr) \
	if (!(expr)) assertFailed(__FILE__, __LINE__)

#else
#define assert(expr) \
	if (!(expr)) __builtin_unreachable()
#endif

mvh.,
David
	

On 23/04/14 19:10, Agustin Perez Paladini wrote:
> Hi Jonathan,
> Yes, that should work, assuming that the compiler will understand what
> I'm trying to say!
> 
> Thanks a lot! I will try that and see if there are any improvement.
> Regards
> 
> 2014-04-23 13:56 GMT-03:00 Jonathan Wakely <jwakely.gcc@xxxxxxxxx>:
>> On 23 April 2014 17:50, Jonathan Wakely wrote:
>>> On 23 April 2014 17:24, Agustin Perez Paladini wrote:
>>>> Basically I was thinking in something like asserts, but that are only
>>>> visible for the compiler and don't affect the code. Something like
>>>>
>>>> __builtin_assume(x > 0);
>>>> __builtin_assume(x < 10);
>>>>
>>>> where x is a variable. That way the compiler can do better optimizations.
>>>
>>> You can use __buitlin_expect and __builtin_unreachable to do that.
>>
>> Or just __builtin_unreachable alone
>>
>> #define ASSUME(X) if (!(X)) __builtin_unreachable()
>>
>> This tells the compiler X is always true. Isn't that what you want?
> 





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux