Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753426AbdLHKLK (ORCPT ); Fri, 8 Dec 2017 05:11:10 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:44672 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753439AbdLHKJM (ORCPT ); Fri, 8 Dec 2017 05:09:12 -0500 X-Google-Smtp-Source: AGs4zMZWEJAcEgN/i0INlDwIwwkoa8ffmylzZQSATqt7WGnW29f9gKrxX5yXIZwlHPmK0Skwev7Y8L9PA6dYA6ufFjU= MIME-Version: 1.0 In-Reply-To: <0c30f6b9-d614-8244-54bd-1e12cee51a23@zytor.com> References: <20171207224154.4687-1-adobriyan@gmail.com> <20171207224154.4687-2-adobriyan@gmail.com> <0c30f6b9-d614-8244-54bd-1e12cee51a23@zytor.com> From: Alexey Dobriyan Date: Fri, 8 Dec 2017 12:09:11 +0200 Message-ID: Subject: Re: [PATCH 2/5] -march=native: POPCNT support To: "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, mingo@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1626 Lines: 41 On 12/8/17, H. Peter Anvin 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