From patchwork Tue Dec 22 11:39:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 41512 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAFB03836C5D; Tue, 22 Dec 2020 11:39:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAFB03836C5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608637187; bh=vvdY4h5Geg/FgXaC0zuERxNMW3q/xM7rp1xrwFihiHU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hkL3zYMsTuhb9BsULEqU5xBoIwZkCaWl/hv510YA0Z8MhwdS7HR76/AM9qfh/Ac/p uz36izfb2jVJ/93IAi7bqXEoMcAxivGrr8n/d7okeoIf3WZVSbZrMHM44xceGbhy6s 5B8VWDlHwxS+e39UoNB4jJrQK2UGnJabMtVrveHY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 1ED393877015 for ; Tue, 22 Dec 2020 11:39:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1ED393877015 Received: by mail-pj1-x1031.google.com with SMTP id m5so1203557pjv.5 for ; Tue, 22 Dec 2020 03:39:45 -0800 (PST) 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=vvdY4h5Geg/FgXaC0zuERxNMW3q/xM7rp1xrwFihiHU=; b=WcN239wvjgGnFccDFE+BlnawQaMLodZj9oDFNDbIuXUX8UelWPYV8oS2cb2ak9Gj4/ GxPstgWzJVEQVDD8uc9mchkLvRdSE5u6UpsM6YjacYgG8mLKmeXVE+KULlsip+o7vwxf eczFnfQwS0cWzeDZCXgYQI4JEjQM9hZA5VgNF61IzepIdwpZEZUQ0HIhEJqiV5uvMRKu FNFOXI0VzrDJ4icxD/XXPL3slrBSPZSI4tkz4dwzuaUMBVi8mGUOAAlDhr8BsWQE9eo7 19qanbAZgm8qJhZufeTfxSfVfnxhBY1ushOrhri5QDquPi35hGwThGkK4wdlPF7waMTi ShwA== X-Gm-Message-State: AOAM5308SGWTTt8453B+MuEWokI9hV3nc5xkeOwXL0boOXWiEUigUTAN kP/36WxWWJ330OTucVrXAws+84gM1qI= X-Google-Smtp-Source: ABdhPJwhOIgmK8f+kbw6BSrglYIv1KuvrQxcEGVs7WfFD7g6AmXcGUQOoz+t3lCN9Sv/L4g70PUikQ== X-Received: by 2002:a17:902:ed11:b029:da:3137:2695 with SMTP id b17-20020a170902ed11b02900da31372695mr21046944pld.1.1608637184223; Tue, 22 Dec 2020 03:39:44 -0800 (PST) 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 k125sm17007402pga.57.2020.12.22.03.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 03:39:43 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 7224A1A00EA; Tue, 22 Dec 2020 03:39:42 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] : Pass index_cpu_##name [BZ #27104] Date: Tue, 22 Dec 2020 03:39:40 -0800 Message-Id: <20201222113940.2828450-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3040.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Pass index_cpu_##name to __x86_get_cpu_features in HAS_CPU_FEATURE and CPU_FEATURE_USABLE so that applications compiled against the glibc header files with a larger COMMON_CPUID_INDEX_MAX work with an older glibc binary with a smaller COMMON_CPUID_INDEX_MAX. --- sysdeps/x86/Makefile | 13 +++++-- sysdeps/x86/sys/platform/x86.h | 4 +-- sysdeps/x86/tst-get-cpu-features-2-static.c | 1 + sysdeps/x86/tst-get-cpu-features-2.c | 38 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 sysdeps/x86/tst-get-cpu-features-2-static.c create mode 100644 sysdeps/x86/tst-get-cpu-features-2.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 081cc72e93..e50db29f31 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -6,9 +6,16 @@ ifeq ($(subdir),elf) sysdep-dl-routines += dl-get-cpu-features sysdep_headers += sys/platform/x86.h -tests += tst-get-cpu-features tst-get-cpu-features-static \ - tst-cpu-features-cpuinfo tst-cpu-features-supports -tests-static += tst-get-cpu-features-static +tests += \ + tst-get-cpu-features-2 \ + tst-get-cpu-features-2-static \ + tst-get-cpu-features \ + tst-get-cpu-features-static \ + tst-cpu-features-cpuinfo \ + tst-cpu-features-supports +tests-static += \ + tst-get-cpu-features-2-static \ + tst-get-cpu-features-static endif ifeq ($(subdir),math) diff --git a/sysdeps/x86/sys/platform/x86.h b/sysdeps/x86/sys/platform/x86.h index 3ef92b04e8..e0baf357ad 100644 --- a/sysdeps/x86/sys/platform/x86.h +++ b/sysdeps/x86/sys/platform/x86.h @@ -87,13 +87,13 @@ extern const struct cpu_features *__x86_get_cpu_features (unsigned int) #define HAS_CPU_FEATURE(name) \ (__extension__ \ ({ const struct cpu_features *__ptr = \ - __x86_get_cpu_features (COMMON_CPUID_INDEX_MAX); \ + __x86_get_cpu_features (index_cpu_##name); \ __ptr && CPU_FEATURE_CPU_P (__ptr, name); })) /* CPU_FEATURE_USABLE evaluates to true if the feature is usable. */ #define CPU_FEATURE_USABLE(name) \ (__extension__ \ ({ const struct cpu_features *__ptr = \ - __x86_get_cpu_features (COMMON_CPUID_INDEX_MAX); \ + __x86_get_cpu_features (index_cpu_##name); \ __ptr && CPU_FEATURE_USABLE_P (__ptr, name); })) /* CPU features. */ diff --git a/sysdeps/x86/tst-get-cpu-features-2-static.c b/sysdeps/x86/tst-get-cpu-features-2-static.c new file mode 100644 index 0000000000..a86383ab62 --- /dev/null +++ b/sysdeps/x86/tst-get-cpu-features-2-static.c @@ -0,0 +1 @@ +#include "tst-get-cpu-features-2.c" diff --git a/sysdeps/x86/tst-get-cpu-features-2.c b/sysdeps/x86/tst-get-cpu-features-2.c new file mode 100644 index 0000000000..2c8cc1bf19 --- /dev/null +++ b/sysdeps/x86/tst-get-cpu-features-2.c @@ -0,0 +1,38 @@ +/* Forward compatibility test case for __x86_get_cpu_features interface + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#define COMMON_CPUID_INDEX_MAX __rename_COMMON_CPUID_INDEX_MAX +#include +#undef COMMON_CPUID_INDEX_MAX +#define COMMON_CPUID_INDEX_MAX (__rename_COMMON_CPUID_INDEX_MAX + 1) +#include + +static int +do_test (void) +{ +#ifdef __SSE2__ + TEST_VERIFY_EXIT (HAS_CPU_FEATURE (SSE2)); + TEST_VERIFY_EXIT (CPU_FEATURE_USABLE (SSE2)); +#endif + + return 0; +} + +#include