From: Arnd Bergmann <arnd@arndb.de>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines
Date: Mon, 23 Nov 2015 17:11:20 +0100 [thread overview]
Message-ID: <4277009.MDAEAbRExl@wuerfel> (raw)
In-Reply-To: <alpine.LFD.2.20.1511231053450.22569@knanqh.ubzr>
On Monday 23 November 2015 11:04:33 Nicolas Pitre wrote:
>
> OK... I'm able to "fix" the build with:
>
> diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
> index 163f77999e..d246c4c801 100644
> --- a/include/asm-generic/div64.h
> +++ b/include/asm-generic/div64.h
> @@ -206,7 +206,7 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
> uint32_t __rem; \
> (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
> if (__builtin_constant_p(__base) && \
> - is_power_of_2(__base)) { \
> + is_power_of_2(__base) && __base != 0) { \
> __rem = (n) & (__base - 1); \
> (n) >>= ilog2(__base); \
> } else if (__div64_const32_is_OK && \
>
> What doesn't make sense to me is the fact that is_power_of_2() is
> defined as:
>
> static inline __attribute__((const))
> bool is_power_of_2(unsigned long n)
> {
> return (n != 0 && ((n & (n - 1)) == 0));
> }
>
> So the test for zero is already in there.
>
> And adding BUILD_BUG_ON(__builtin_constant_p(__base) && __base == 0)
> before the if doesn't trig either.
I've seen similarly messed up situations with PROFILE_ALL_BRANCHES
before, I think it's got something to do with how __builtin_constant_p()
is used inside of the __trace_if() macro, and how gcc sometimes falls
back to treating variables as not-really-constant based on context.
To gcc, __builtin_constant_p is just best-effort, and they don't care
about returning false sometimes if they catch most cases in practice.
Note that llvm will always return false for __builtin_constant_p on
non-pointer arguments, which breaks a lot of optimizations.
Arnd
next prev parent reply other threads:[~2015-11-23 16:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 1:20 [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Nicolas Pitre
2015-11-17 1:20 ` Nicolas Pitre
2015-11-19 16:28 ` Arnd Bergmann
2015-11-19 16:28 ` Arnd Bergmann
2015-11-20 0:29 ` Nicolas Pitre
2015-11-20 12:27 ` Arnd Bergmann
2015-11-20 13:24 ` Nicolas Pitre
2015-11-20 13:24 ` Nicolas Pitre
2015-11-22 22:18 ` Arnd Bergmann
2015-11-22 22:18 ` Arnd Bergmann
2015-11-22 22:28 ` Nicolas Pitre
2015-11-23 7:59 ` Arnd Bergmann
2015-11-23 14:59 ` Nicolas Pitre
2015-11-23 14:59 ` Nicolas Pitre
2015-11-23 16:04 ` Nicolas Pitre
2015-11-23 16:11 ` Arnd Bergmann [this message]
2015-11-23 16:11 ` Arnd Bergmann
2015-11-23 16:38 ` Nicolas Pitre
2015-11-24 5:37 ` Nicolas Pitre
2015-11-24 13:28 ` Arnd Bergmann
2015-11-24 13:28 ` Arnd Bergmann
2015-11-24 16:44 ` Nicolas Pitre
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=4277009.MDAEAbRExl@wuerfel \
--to=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=nicolas.pitre@linaro.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