Re: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW

From: Linus Torvalds
Date: Wed Oct 25 2023 - 13:44:00 EST


On Wed, 25 Oct 2023 at 05:05, Vasily Gorbik <gor@xxxxxxxxxxxxx> wrote:
>
> You probably want
>
> #define __div_round_up(n,d) _Generic((n)+(d), \
> unsigned long long: __div_round_up_ull, \
> long long: __div_round_up_ll, \
> unsigned long: __div_round_up_ul, \
> long: __div_round_up_l, \
> unsigned int: __div_round_up_u, \
> int: __div_round_up_i)(n,d)
>
> to avoid early type-checking for expressions that will be discarded
> and prevent errors like:

Ack. I noticed that later when I tried to do a bigger config build -
the compiler would warn about the implicit truncation of the integer
arguments (for the cases where they weren't used).

> Plus typos fixes below passes allyesconfig for s390, 32-bit x86 and arm.

Lovely.

It would have been even better if somebody told me that I was stupid
and there was some nice trick to it, but at least the _Generic()
approach doesn't seem broken - just a few tweaks needed.

Linus