RE: [PATCH 02/25] tracing: Improve "if" macro code generation
From: David Laight
Date: Wed Mar 20 2019 - 13:36:52 EST
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@xxxxxxxxxx> 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++ : ______f.miss_hit++;\
> ______r; \
Actually you can avoid double evaluation by doing:
(cond) ? (______f.miss_hit++, 1) : (______f.miss_hit++, 0)
With luck the compiler will move the increment to after the branch target.
for (_____ = ____; _____ < ______; _____++) :-)
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)