[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACVxJT9n2N2YNCFL8s3tOuAv7Qtqj9+g_rrjxqaGbUCa_2OYtg@mail.gmail.com>
Date: Fri, 8 Dec 2017 12:09:11 +0200
From: Alexey Dobriyan <adobriyan@...il.com>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, tglx@...utronix.de,
mingo@...hat.com
Subject: Re: [PATCH 2/5] -march=native: POPCNT support
On 12/8/17, H. Peter Anvin <hpa@...or.com> wrote:
> On 12/07/17 14:41, Alexey Dobriyan wrote:
>> Mainline kernel can only generate "popcnt rax, rdi" instruction
>> with alternative masquareading as function call. Patch allows
>> to generate all POPCNT variations and inlines hweigth*() family of
>> functions.
> -march=native really would be better implemented by examining the macros
> generated by gcc which correspond to the selected -m options
> (-march=native really just selects a combination of -m options.) It
> seems bizarre to just reimplement the mechanism that already exists.
This mechanism can do feature detection part only.
Code generation tweaks (uop fusing etc) require passing -march=native,
and hardly can be expressed through defines.
Some things aren't recorded in defines (--param l1-cache-size),
it is not clear how and what to optimize base on cache sizes,
but if kernel controls CPU detection code there is no need to wait
when someone smart comes up with an idea.
Again, clang emits slightly different defines.
> Now, this specific case would be better done with alternatives; we can
> patch in a JMP to an out-of-line stub to mangle the arguments. Then you
> get the benefit on all systems and don't need to decide at compile time.
>
> The reason to use -m options for this would be to be able to use the
> __builtin_popcount() and __builtin_popcountl() intrinsics, which would
> allow gcc to schedule it and optimize arbitrarily.
>
> So, much more something like:
>
> #ifdef __POPCNT__
>
> static inline unsigned int __arch_hweight64(uint64_t x)
> {
> return __builtin_popcountll(x);
OK
Powered by blists - more mailing lists