lkml.org 
[lkml]   [2019]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH 02/25] tracing: Improve "if" macro code generation
Date
From: Linus Torvalds 
> Sent: 20 March 2019 17:26
> To: David Laight
> On Wed, Mar 20, 2019 at 4:17 AM David Laight <David.Laight@aculab.com> wrote:
> >
> > > ______r = !!(cond); \
> >
> > Is that (or maybe just the !!) needed any more??
>
> It is, because the 'cond' expression might not be an int, it could be
> a test for a pointer being non-NULL, or an u64 being non-zero, and not
> having the "!!" would mean that you'd get a warning or drop bits when
> assigning to 'int'.
>
> And you do need the new temporary variable to avoid double evaluation
> the way that code is written.

As usual I'd opened my mouth before checking the full context :-)

> ______r = !!(cond);
> - ______f.miss_hit[______r]++; \
> + ______r ? ______f.miss_hit[1]++ : ______f.miss_hit[0]++;\
> ______r; \

Actually you can avoid double evaluation by doing:

(cond) ? (______f.miss_hit[1]++, 1) : (______f.miss_hit[0]++, 0)

With luck the compiler will move the increment to after the branch target.

for (_____ = ____; _____ < ______; _____++) :-)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
\
 
 \ /
  Last update: 2019-03-20 18:37    [W:0.181 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site