From: David Laight <David.Laight@ACULAB.COM>
To: 'Linus Torvalds' <torvalds@linux-foundation.org>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Vasily Gorbik <gor@linux.ibm.com>,
Niklas Schnelle <schnelle@linux.ibm.com>,
"kernel@collabora.com" <kernel@collabora.com>
Subject: RE: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW
Date: Thu, 26 Oct 2023 08:41:47 +0000 [thread overview]
Message-ID: <2873863a22f441c9889ba405d8a71d97@AcuMS.aculab.com> (raw)
In-Reply-To: <CAHk-=whrytmsiaLS=rn==qrYw81y2Qiv6dAZxvGzwgX=dMFxng@mail.gmail.com>
From: Linus Torvalds
> Sent: 25 October 2023 18:41
>
> On Tue, 24 Oct 2023 at 22:38, David Laight <David.Laight@aculab.com> wrote:
> >
> > From: Linus Torvalds
> > > > - we can't even use a statement expression and __auto_type, because
> > > > these things are used in type definitions etc and need to be constant
> > > > expressions
> >
> > Doesn't min() get around that by using is_constexpr() and
> > __builtin_choose_exptr() - the same could be done here.
>
> Nope. I wanted to do it that way - it would have made things much
> simpler and avoid the whole _Generic() thing, but try it - you cannot
> use statement expressions in a non-function context even with
> __builtin_choose_expr().
_Generic() has exactly the same issues as __builtin_choose_expr().
All the code has to be valid for all types.
Makes testing for negative constants a PITA.
Something like this worked:
(__buitin_choose_expr(__is_constexpr((x) && is_signed_type(__typeof(x)), x, 1) < 0)
Although our is_signed_type() isn't constant (enough) for pointer types.
So you need another check for (typeof(x))1 being constant.
> And no, min/max have never been usable in that context
I've clearly not tested it and assumed the comment implied
that was ok.
It'd probably work in C++ - which is perfectly willing to
add functions to initialise static data - even when you'd
rather have a compile time error.
David
>
> Linus
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-10-26 8:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 16:18 [PATCH v4 0/3] Fix clock division overflow problem Sebastian Reichel
2023-10-24 16:18 ` [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW Sebastian Reichel
2023-10-24 16:26 ` David Laight
2023-10-24 19:32 ` Linus Torvalds
2023-10-24 22:53 ` Linus Torvalds
2023-10-25 8:03 ` Rasmus Villemoes
2023-10-25 17:37 ` Linus Torvalds
2023-10-25 8:38 ` David Laight
2023-10-25 17:41 ` Linus Torvalds
2023-10-26 8:41 ` David Laight [this message]
2023-10-25 15:05 ` Vasily Gorbik
2023-10-25 17:43 ` Linus Torvalds
2023-10-26 8:57 ` David Laight
2023-10-26 16:54 ` Linus Torvalds
2023-10-27 7:24 ` David Laight
2023-10-25 17:36 ` Sebastian Reichel
2023-10-25 17:28 ` Sebastian Reichel
2023-10-24 16:18 ` [PATCH v4 2/3] clk: divider: Fix divisor masking on 64 bit platforms Sebastian Reichel
2023-10-24 16:18 ` [PATCH v4 3/3] clk: composite: replace open-coded abs_diff() Sebastian Reichel
2023-10-24 16:23 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2873863a22f441c9889ba405d8a71d97@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gor@linux.ibm.com \
--cc=kernel@collabora.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@kernel.org \
--cc=schnelle@linux.ibm.com \
--cc=sebastian.reichel@collabora.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox