From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 2F6D9385DC33 for ; Thu, 24 Jun 2021 12:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F6D9385DC33 Received: by mail-ej1-x62c.google.com with SMTP id bg14so9299398ejb.9 for ; Thu, 24 Jun 2021 05:47:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GLFcxL7CUNfEBvqhURQD/hOQud/yDf0KhOnRzkRaQi8=; b=YjluoZVOO/k++dB2mlnAvqoRLBejUQ/wiFrNkAKksb8c69VOUlVswtHGAgME5p/1Dl OWNmTdA7T1kbJhWxprAjKmhcFtpUIlQlt+SCn9zmLSrZBa3Vzxtrg3XP/b9otN4+b+1I j1jHFl+dtvlrB5raf0qdmmbTxvDtmYyGw4273A/FB4WxyxfJnCyknEn1a61SWQrlfimL 4wjiRg5V5CaXoXfVmAhSiWexg5SizzfZNVB9O1u3Mh5kD/s6WwNYomt6wotdY+IuvqWI M4XCKlzy8LJIzZ7OaJu9RuFueqN1uMsofYKXnJ8Kgx1AxVBT9AB7pieB6KOLzgKO0rub pyHg== X-Gm-Message-State: AOAM532VMW9yl59J2ZQa194NK0R9j6+b4WYylvsv9MigVYm+73igsrIV MkX9N3WQG1iZBAdr/TGJf7pTDTuBsJ4TazpSpH0= X-Google-Smtp-Source: ABdhPJw1dw7C+h65rYmTsDZD/3uJUZc3ZtJSQg1PjHMiibiw07FNSQAUWFcFRx0ciGCBr05YKlBMnOTppzW74u0neiM= X-Received: by 2002:a17:906:64d1:: with SMTP id p17mr5238807ejn.138.1624538836224; Thu, 24 Jun 2021 05:47:16 -0700 (PDT) MIME-Version: 1.0 References: <20210624121213.3469943-1-hjl.tools@gmail.com> In-Reply-To: From: Richard Biener Date: Thu, 24 Jun 2021 14:47:05 +0200 Message-ID: Subject: Re: [PATCH] x86: Compile CPUID functions with -mgeneral-regs-only To: "H.J. Lu" Cc: GCC Patches , Hongtao Liu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 12:47:18 -0000 On Thu, Jun 24, 2021 at 2:42 PM H.J. Lu wrote: > > On Thu, Jun 24, 2021 at 5:35 AM Richard Biener > wrote: > > > > On Thu, Jun 24, 2021 at 2:13 PM H.J. Lu via Gcc-patches > > wrote: > > > > > > CPUID functions are used to detect CPU features. If vector ISAs > > > are enabled, compiler is free to use them in these functions. Add > > > __attribute__ ((target("general-regs-only"))) to CPUID functions > > > to avoid vector instructions. > > > > But there are GPR instructions not in x86_64, so shouldn't > > we use target("march=x86_64") or so? Note doing either will > > of course prevent inlining of those "inlines". > > Does -march=x86_64, which enables CMOV and other GPR > ISAs, work for -m32? I don't think so. I'm also not sure whether -march=xyz in a target attribute overrides -mavx512f on the command-line ;) > > So I'm not sure how much of a fix this is ... the error will almost > > always be visible in the caller as well. > > I think _attribute__ ((target("general-regs-only"))) is a step > forward. That I agree to, but then the cpuid code is likely written the way it is to allow inlining. But code using CPUID should best compile functions under the check with additional target attribute (or in a separate TU) rather than compiling everything with extra -mXYZ and trying to "disable" things in the dispatching code (and the code leading to it!). Richard. > > > gcc/ > > > > > > PR target/101185 > > > * config/i386/cpuid.h (__get_cpuid_max): Add > > > __attribute__ ((target("general-regs-only"))). > > > (__get_cpuid): Likewise. > > > (__get_cpuid_count): Likewise. > > > (__cpuidex): Likewise. > > > > > > gcc/testsuite/ > > > > > > PR target/101185 > > > * gcc.target/i386/avx512-check.h (check_osxsave): Add > > > __attribute__ ((target("general-regs-only"))). > > > (main): Likewise. > > > --- > > > gcc/config/i386/cpuid.h | 4 ++++ > > > gcc/testsuite/gcc.target/i386/avx512-check.h | 2 ++ > > > 2 files changed, 6 insertions(+) > > > > > > diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h > > > index aebc17c6827..74881ee91e5 100644 > > > --- a/gcc/config/i386/cpuid.h > > > +++ b/gcc/config/i386/cpuid.h > > > @@ -243,6 +243,7 @@ > > > pointer is non-null, then first four bytes of the signature > > > (as found in ebx register) are returned in location pointed by sig. */ > > > > > > +__attribute__ ((target("general-regs-only"))) > > > static __inline unsigned int > > > __get_cpuid_max (unsigned int __ext, unsigned int *__sig) > > > { > > > @@ -298,6 +299,7 @@ __get_cpuid_max (unsigned int __ext, unsigned int *__sig) > > > supported and returns 1 for valid cpuid information or 0 for > > > unsupported cpuid leaf. All pointers are required to be non-null. */ > > > > > > +__attribute__ ((target("general-regs-only"))) > > > static __inline int > > > __get_cpuid (unsigned int __leaf, > > > unsigned int *__eax, unsigned int *__ebx, > > > @@ -315,6 +317,7 @@ __get_cpuid (unsigned int __leaf, > > > > > > /* Same as above, but sub-leaf can be specified. */ > > > > > > +__attribute__ ((target("general-regs-only"))) > > > static __inline int > > > __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf, > > > unsigned int *__eax, unsigned int *__ebx, > > > @@ -330,6 +333,7 @@ __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf, > > > return 1; > > > } > > > > > > +__attribute__ ((target("general-regs-only"))) > > > static __inline void > > > __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf) > > > { > > > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h > > > index 0a377dba1d5..406faf8fe03 100644 > > > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h > > > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h > > > @@ -25,6 +25,7 @@ do_test (void) > > > } > > > #endif > > > > > > +__attribute__ ((target("general-regs-only"))) > > > static int > > > check_osxsave (void) > > > { > > > @@ -34,6 +35,7 @@ check_osxsave (void) > > > return (ecx & bit_OSXSAVE) != 0; > > > } > > > > > > +__attribute__ ((target("general-regs-only"))) > > > int > > > main () > > > { > > > -- > > > 2.31.1 > > > > > > > -- > H.J.