Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1275531

Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines

From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines
Date 2015-11-23 17:20 +0100
Message-ID <qy20p-4cV-9@gated-at.bofh.it> (permalink)
References <qvDfP-6Ck-15@gated-at.bofh.it> <qy0KZ-3aB-7@gated-at.bofh.it> <qy1QN-48K-73@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-17 02:30 +0100
  Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-19 17:30 +0100
    Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-20 01:30 +0100
      Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-20 13:30 +0100
        Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-20 14:30 +0100
  Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-22 23:20 +0100
    Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-22 23:30 +0100
      Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-23 09:00 +0100
        Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-23 16:00 +0100
          Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-23 17:10 +0100
            Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-23 17:20 +0100
              Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-23 17:40 +0100
              Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-24 06:40 +0100
                Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on 32-bit machines Arnd Bergmann <arnd@arndb.de> - 2015-11-24 14:30 +0100
                Re: [GIT PULL] optimize 64-by-32 ddivision for constant divisors on  32-bit machines Nicolas Pitre <nicolas.pitre@linaro.org> - 2015-11-24 17:50 +0100

csiph-web