From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by sourceware.org (Postfix) with ESMTPS id 65E9B3858D37 for ; Tue, 30 Jun 2020 04:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E9B3858D37 Received: by mail-pj1-x1042.google.com with SMTP id h22so8947123pjf.1 for ; Mon, 29 Jun 2020 21:35:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/2LYR9OTazu/MqmHQElhSNiq45MU7T8pVgRIef5uGCc=; b=Sd2ArWlne2EeYUsFQZtF5bNf7zodpjXdWF7iV83ANkhnrbsyae6dooHc6IRSU2UYig BKYmbtrp4F16mwFK1S8tApIerXqYHEe5Ii1x+zfPkjZNKgk3CqdRK0U0O0ySpCHNRaFT aXkAPdkPkgiWKu1ALYbrLm0iARAn+rPnPFT3covXFoUiQd4yqlMKOUfmxibNR7S7Aly2 BKoCUTKOvIkdLfPzPHTldhqy2qP1WL3t/15yGnC9LCW9V89WUYZA6+Gx8k4nCi22kdzT HWfC9pF0Tj5mvaxvSHZsbDLM6lJTo8cWgWVQtlRP3Bt5dtXvM/TRl/PSxTyRDUw0qyeA OTRA== X-Gm-Message-State: AOAM531J6Lp0ktNeiz7AKlA+d08uYT+EnjO7fbJOpxNsQCeLcI9D6Z4P XVhKAO8c1WNwU5O7xxZBrqc= X-Google-Smtp-Source: ABdhPJyNRU5y36cqR4YcFxYgXOpOvbhzauH/umicu1nw51rtzjqyq/QyHPAvcZ4RSNPlJjBAaZ2rJw== X-Received: by 2002:a17:90b:488:: with SMTP id bh8mr18295974pjb.49.1593491730413; Mon, 29 Jun 2020 21:35:30 -0700 (PDT) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id c141sm1046799pfc.167.2020.06.29.21.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 21:35:30 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 30C471A00D6; Mon, 29 Jun 2020 21:35:29 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: V7: [PATCH 0/2] x86: Install Date: Mon, 29 Jun 2020 21:35:27 -0700 Message-Id: <20200630043529.739181-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2020 04:35:33 -0000 Support usable check for all CPU features with the following changes: 1. Change struct cpu_features to struct cpuid_features { struct cpuid_registers cpuid; struct cpuid_registers usable; }; struct cpu_features { struct cpu_features_basic basic; struct cpuid_features features[COMMON_CPUID_INDEX_MAX]; unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX]; ... }; so that there is a usable bit for each cpuid bit. 2. After the cpuid bits have been initialized, copy them to the usable bits. 3. Clear the usable bits which require OS support. 4. If the feature is supported by OS, copy its cpuid bit to its usable bit. The results are a. If the feature doesn't requre OS support, its usable bit is copied from the cpuid bit. b. Otherwise, its usable bit is copied from the cpuid bit only if the feature is supported by OS. Install so that programmers can do #if __has_include() #include #endif ... if (CPU_FEATURE_USABLE (SSE2)) ... if (CPU_FEATURE_USABLE (AVX2)) ... exports only: enum { COMMON_CPUID_INDEX_1 = 0, COMMON_CPUID_INDEX_7, COMMON_CPUID_INDEX_80000001, COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007, COMMON_CPUID_INDEX_80000008, COMMON_CPUID_INDEX_7_ECX_1, /* Keep the following line at the end. */ COMMON_CPUID_INDEX_MAX }; struct cpuid_features { struct cpuid_registers cpuid; struct cpuid_registers usable; }; struct cpu_features { struct cpu_features_basic basic; struct cpuid_features features[COMMON_CPUID_INDEX_MAX]; }; /* Get a pointer to the CPU features structure. */ extern const struct cpu_features *__x86_get_cpu_features (unsigned int max) __attribute__ ((const)); Since all feature checks are done through macros, programs compiled with a newer are compatible with the older glibc binaries as long as the layout of struct cpu_features is identical. The features array can be expanded with backward binary compatibility for both .o and .so files. When COMMON_CPUID_INDEX_MAX is increased to support new processor features, __x86_get_cpu_features in the older glibc binaries returns NULL and HAS_CPU_FEATURE/CPU_FEATURE_USABLE return falses on the new processor feature. No new symbol version is neeeded. Both CPU_FEATURE_USABLE and HAS_CPU_FEATURE are provided. HAS_CPU_FEATURE can be used to identify processor features. Note: Although GCC has __builtin_cpu_supports, it only supports a subset of and it is equivalent to CPU_FEATURE_USABLE. It doesn't support HAS_CPU_FEATURE. H.J. Lu (2): x86: Support usable check for all CPU features x86: Install [BZ #26124] NEWS | 2 + manual/platform.texi | 24 ++ sysdeps/i386/i686/multiarch/s_fma.c | 2 +- sysdeps/i386/i686/multiarch/s_fmaf.c | 2 +- sysdeps/unix/sysv/linux/i386/ld.abilist | 1 + sysdeps/unix/sysv/linux/x86_64/64/ld.abilist | 1 + sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist | 1 + sysdeps/x86/Makefile | 1 + sysdeps/x86/Versions | 4 +- sysdeps/x86/cacheinfo.c | 2 +- sysdeps/x86/cpu-features.c | 341 +++++++++--------- sysdeps/x86/cpu-tunables.c | 170 ++++----- sysdeps/x86/dl-get-cpu-features.c | 6 +- sysdeps/x86/include/cpu-features.h | 179 +++++++++ .../{cpu-features.h => sys/platform/x86.h} | 275 ++------------ sysdeps/x86/tst-get-cpu-features.c | 125 ++++++- sysdeps/x86_64/Makefile | 6 +- sysdeps/x86_64/dl-machine.h | 6 +- sysdeps/x86_64/fpu/math-tests-arch.h | 8 +- sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h | 8 +- sysdeps/x86_64/fpu/multiarch/ifunc-fma.h | 4 +- sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h | 6 +- .../x86_64/fpu/multiarch/ifunc-mathvec-avx2.h | 4 +- .../fpu/multiarch/ifunc-mathvec-avx512.h | 4 +- sysdeps/x86_64/fpu/multiarch/s_fma.c | 4 +- sysdeps/x86_64/fpu/multiarch/s_fmaf.c | 4 +- sysdeps/x86_64/multiarch/ifunc-avx2.h | 2 +- sysdeps/x86_64/multiarch/ifunc-impl-list.c | 146 ++++---- sysdeps/x86_64/multiarch/ifunc-memcmp.h | 2 +- sysdeps/x86_64/multiarch/ifunc-memmove.h | 2 +- sysdeps/x86_64/multiarch/ifunc-memset.h | 4 +- sysdeps/x86_64/multiarch/ifunc-strcasecmp.h | 2 +- sysdeps/x86_64/multiarch/ifunc-strcpy.h | 2 +- sysdeps/x86_64/multiarch/ifunc-wmemset.h | 4 +- sysdeps/x86_64/multiarch/strchr.c | 2 +- sysdeps/x86_64/multiarch/strcmp.c | 2 +- sysdeps/x86_64/multiarch/strncmp.c | 2 +- sysdeps/x86_64/multiarch/test-multiarch.c | 10 +- sysdeps/x86_64/multiarch/wcsnlen.c | 2 +- 39 files changed, 721 insertions(+), 651 deletions(-) create mode 100644 sysdeps/x86/include/cpu-features.h rename sysdeps/x86/{cpu-features.h => sys/platform/x86.h} (64%) -- 2.26.2