From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by sourceware.org (Postfix) with ESMTPS id 913AC38515EC for ; Fri, 25 Jun 2021 02:51:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 913AC38515EC Received: by mail-vk1-xa29.google.com with SMTP id b64so1564655vkh.12 for ; Thu, 24 Jun 2021 19:51:56 -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=+APMjI+IODpw02bIFkhBUkexuYISpP6WFdveFDbEKeo=; b=fFZaHTEgRYGdTSFQ5YiUERm+BCKrn4AGigAta7z2k6F+s5gMBj0VVf1j8vLfFE4031 Cc4rQQdbxKo2BdNVfB6NY5qpfXlhsPlbymcvfImWTT0os07JJNPCQnMqtF4MN8wdMKT0 XUx2GkuG84K29V6YTGWpxM4ONKtbnAYEycSA3oAc9sbrSOklQfNJc/PY2QQTrf8ATg2Q AKYFwE7tkd54EtYjlBLA2mYXGjgNyU9Ms2nYtbdU2Z7K5k67nOCvg4bLiQA6F1bHTtOh FBOCqDYN3ew5pfhiozc8yzVjH8neziulafZZ/jV6Ur7m2c9v4UWI8Z2wfVEJB3FHf7n0 phRA== X-Gm-Message-State: AOAM530tjcsQn0kLUC5lCSNbdfXJEEy715mBhHBT+618CghcNL8bvd7j ZSueHS+lzGNGnfnTdeUMf4TXdF86yEqcrowUzmU= X-Google-Smtp-Source: ABdhPJzCYAWe4PkRaS1jRpuhzawESYugBojf37a5PMjpyYa6pB3/3/bRJ+Ll0gFKFNJ9s4wUM8nehn+hLQh5dqSnIRU= X-Received: by 2002:ac5:c8a1:: with SMTP id o1mr6202756vkl.24.1624589516173; Thu, 24 Jun 2021 19:51:56 -0700 (PDT) MIME-Version: 1.0 References: <20210624121213.3469943-1-hjl.tools@gmail.com> In-Reply-To: From: Hongtao Liu Date: Fri, 25 Jun 2021 10:56:43 +0800 Message-ID: Subject: Re: [PATCH] x86: Compile CPUID functions with -mgeneral-regs-only To: Uros Bizjak Cc: "H.J. Lu" , Hongtao Liu , "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.0 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: Fri, 25 Jun 2021 02:51:58 -0000 On Fri, Jun 25, 2021 at 12:13 AM Uros Bizjak via Gcc-patches wrote: > > On Thu, Jun 24, 2021 at 2:12 PM H.J. Lu 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. > > These functions are intended to be inlined, so how does target > attribute affect inlining? I guess w/ -O0. they may not be inlined, that's why H.J adds those attributes to those functions. pr96814.dump: 0804aa40
: 804aa40: 8d 4c 24 04 lea 0x4(%esp),%ecx ... 804aa63: 6a 07 push $0x7 804aa65: e8 e0 e7 ff ff call 804924a <__get_cpuid_count> Also we need to add a target attribute to avx512f_os_support (), and that would be enough to fix the AVX512 part. Moreover, all check functions in below files may also need to deal with: adx-check.h aes-avx-check.h aes-check.h amx-check.h attr-nocf-check-1a.c attr-nocf-check-3a.c avx2-check.h avx2-vpop-check.h avx512bw-check.h avx512-check.h avx512dq-check.h avx512er-check.h avx512f-check.h avx512vl-check.h avx-check.h bmi2-check.h bmi-check.h cf_check-1.c cf_check-2.c cf_check-3.c cf_check-4.c cf_check-5.c f16c-check.h fma4-check.h fma-check.h isa-check.h lzcnt-check.h m128-check.h m256-check.h m512-check.h mmx-3dnow-check.h mmx-check.h pclmul-avx-check.h pclmul-check.h pr39315-check.c rtm-check.h sha-check.h spellcheck-options-1.c spellcheck-options-2.c spellcheck-options-3.c spellcheck-options-4.c spellcheck-options-5.c sse2-check.h sse3-check.h sse4_1-check.h sse4_2-check.h sse4a-check.h sse-check.h ssse3-check.h stack-check-11.c stack-check-12.c stack-check-17.c stack-check-18.c stack-check-19.c xop-check.h > > Uros. > > > > > 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 > > -- BR, Hongtao