From patchwork Mon Jan 18 16:25:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 41751 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 C2A07388C011; Mon, 18 Jan 2021 16:26:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2A07388C011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610987170; bh=5OVDezr3l+N/AdHBcKN09mbGUiBlkM7sM1TI8QaqTKc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=COPJFHVNVsZpYZJ5+geSgrxmQdC9sLzCYq8xc0A1nGENWbwFs2QEdMcSwn/DHgC81 CK2cEWaVY8stHIs1bug67Vn2d7M5q0bn2IjR4EsKNJd/+MGL/jgNYA1HuTM7Z7VdFw IhJjAFNEuE5/3GhwJEkZo/RSs8VK+U6IzLOI1my4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04hn0219.outbound.protection.outlook.com [52.100.17.219]) by sourceware.org (Postfix) with ESMTPS id 69563388C011 for ; Mon, 18 Jan 2021 16:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 69563388C011 Received: from DB3PR06CA0013.eurprd06.prod.outlook.com (2603:10a6:8:1::26) by VE1PR08MB4816.eurprd08.prod.outlook.com (2603:10a6:802:a1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12; Mon, 18 Jan 2021 16:26:04 +0000 Received: from DB5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:8:1:cafe::30) by DB3PR06CA0013.outlook.office365.com (2603:10a6:8:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Mon, 18 Jan 2021 16:26:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT060.mail.protection.outlook.com (10.152.21.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Mon, 18 Jan 2021 16:26:04 +0000 Received: ("Tessian outbound 8418c949a3fa:v71"); Mon, 18 Jan 2021 16:26:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5733c8db3015ce4b X-CR-MTA-TID: 64aa7808 Received: from 35e2a6aad8cd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3EE6D85F-5B52-48A4-9EA9-374E2C56E2B3.1; Mon, 18 Jan 2021 16:25:58 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 35e2a6aad8cd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Jan 2021 16:25:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iF+HqSPosrMKeinlxClz2A+gIaHPWiW4JviGjwzmbnAFbv2tFrhPz9mSS0zo/UHrwEXzVjo6VTM7pxJ7s9z7NzDzopRNRHqWqQlrlAC0ujEh3L9rQvkBEHWeSAo5p+wZth+5uaWylePT8A3F/rDeQ6AU+OZUBL8bbSsHg/C0NEtXOOk8y9jOWLT69aROVUH5DmFa0i/YS85SfWqCWHClKm2YVmVTaH75doxI7jiL4pDyhdK9v0M1w/nkuUcLqGDFavlN8vwsCyo2OpAvaATkJ2koYlHHNXi5XcTbpV6wYZoeHrU4NQSMRhK3ZLutyToIlPWZoLrUOwhLGhGFcZhCOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5OVDezr3l+N/AdHBcKN09mbGUiBlkM7sM1TI8QaqTKc=; b=S3e6dRxm3RuU7dw+BlVeZ6BUj5mdkXrqMMRVLodS8xuFiiVYHeN1EsJdP7PCAQVMeu65eGmDMg3VY5USWoWMXel0U7gO6ZcH5T/GorOi1kvyLyAQnOaFd2dQIPPEVpJvBelosnorwfQhx2z3CGPPcNWV6RCihBDe76YxmohKryclqidKG5lXEYMw1y9ILVFI3HGXcoCVVtcyp1RDKNlW8yqV1M2U8IWyCwvMEWRb4FJfwOez5x30U8gIUKu1p7CclvErv6Aqr//rjzKNA05oHcD92/f7gB2y8A6yWBIk2cezbaKyc+ddA7QoHoHXw7QCZelDucxtmQ3CY/Nm9E+/5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PA4PR08MB6238.eurprd08.prod.outlook.com (2603:10a6:102:e8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.11; Mon, 18 Jan 2021 16:25:57 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f%7]) with mapi id 15.20.3763.014; Mon, 18 Jan 2021 16:25:57 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v4 09/10] x86: Check ifunc resolver with CPU_FEATURE_USABLE [BZ #27072] Date: Mon, 18 Jan 2021 16:25:50 +0000 Message-Id: <9d9d859c0eb4060d631832291f927a9d8d9b52ba.1610986541.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0226.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::22) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.54) by LO2P265CA0226.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Mon, 18 Jan 2021 16:25:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6a6afbe4-2f0c-4529-1cea-08d8bbcdc032 X-MS-TrafficTypeDiagnostic: PA4PR08MB6238:|VE1PR08MB4816: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7691;OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: KIwH1ku7w/5S7e0QVEM4xOklF1CQ1jPYlBw1W3dqQGFTl6ER5hIkq3EhIhvue3MX7FT5lTkEpzXSHUusWkt0hXRpMRx+P3i4PUHCNuukyztbmqg++h4zavjlwCIFGtMERlZrHbjfRqj8pzYpUFmXs/s6+oimXThwQWx/fCd6s5UnKoN8plTcLL01xAdCQX/iwR9kJ0A2YaBFFu0Qv3xF+PvKuwjzIkC9BYqdcARypkDfPiWIXbxQdTT+ujRr+PYaHlVp5D5YY5/8DFYFpCM6HxlKOGnctjDTxc+0xhjUbql3qUbrWR4oymZYMolJQuLzdmwn/JxIXprx95SQNcDqLa20y5b4AW6BRfAHjISyJmIEsSWVT/IC94Cg4XhgtVmuhuBAnlvT0FVsZm3OpH4k2jBaI//PDWRlk/EiyuiNY/vtiZ3m2aTP+h7dkqT1y5KIJ+47tNPRpY83YdFmWw2m5SODHJ0jPOWDaeQXWQtOkCI7luJFL1s1mJV2We7E1aR/k0Nb2b4pCmTvgqZPBv72eoC1QOJdp3l0YHt42IiNQZTA4Eus7cPEvd2CthrRbXTqdObPpGa8sS3irPRXuuL9HPwK9b52mke1OZKjHvon+Ja9iDiT3T0i3tLBpP5WQV/BcbEZgIc7KRDd53l3/OfET6Gpn+RM+6v7szC7bCfWTcqbthyvzBOnt2RHfLrAr3Po X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39850400004)(376002)(396003)(136003)(346002)(83380400001)(6486002)(8676002)(4326008)(69590400011)(478600001)(6666004)(52116002)(6916009)(316002)(8936002)(66476007)(66556008)(66946007)(5660300002)(86362001)(16526019)(26005)(6512007)(2906002)(186003)(6506007)(956004)(2616005)(36756003)(44832011)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: XVicQYAPCgDL6+x4whpQORSPsHljw87FOrBLJm28ub78taqMayiq37aqgBbK32RXADZMGBPhKCHiLa5fPLRPqa+QHMwc8vDEqaK0KJoZ7cJG7cojnGDeN6/ki2P6ydnB6zITUNMSmA2uJ/C7go3kdBlC/IcTPqPsfSz67Jx7UYfl4KoYi51EFcTU1BiQQ7LL6X/EYZO74qu1+Zo7oEIwtGMhYHeeKyj7UMbklagtHYyHJ4jYydOHciPI2IPxbGxdUsQt2e1ElH/xlt4Dsb15YDP1TtQQb6o4sp0pKHmA0QjKskRl3h3qXqg0Z7LialArlZR2reRHFU8Dryze5HhEqt2No2l3SHVPqciAbW/xAKb7YGHbVp6wpHRlR8Yj89SZpAM2rFap5TB2IxINz54l23E7k8KQ4hriQ5jAviatp3w0dH/c+tuho3PWKEKPXdEeEvtRSLBG0sHOnxQuvDyXMfiFtgFl6LkzRXKDSbNC+QxXtq9+k2K6elajOL6lxQ4mf+vSTvdK089Ekj1Q+r5yUpDDqlxxxbFZE6aRfIUVcwHqBvIIBRV/Z+7HnsQwYLlW8Ygo7/CJzwoneTK281mSH18qLtNMjgpzTSCoMzq+hNzCCaZOTLMO82DeKPC4VSOLIjsNOIdm88wPnGQEcX71AKsHhV4L3NqxJKLiQ09MkQkgD8JpUvURjGJFYjHGxt8Fd813p2N+1ZkVflTtEd248xdixo6Y8xtBFimA4ztewtP/15ya7hqmzo2++xTaBCMvFNTYhdffG3T5PwDqhRFABseaRFi55q4Nyj7bIqf8pXT8bH15pbhC7/LS//DLEOiEkRMkVe7e0TY+Ygxu7wgyQ9L1SM9IArXQ99eASRtzVfcPpNJUBCKH2kHvwbx6YIMBv4lU8IHNiPBtPUn4g/45mDu+4c1MnR6TKZ/OI7SOUdKUpTGevDA6LmeL3serL29EvV2cH65WkaA7kXzJMTqaaSyTuKQpQSY3vbB3IdmLKcPXMyOBkJ0nopbPClQ603ms X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6238 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: d38fa198-7201-4a19-e5a0-08d8bbcdbbaa X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /55fX7goKbeDBswSm3OneNq5/28CBIfFt4Oo+2cDF3aXFA4J4pIB2GhQdNnRXM9dOxNVVQ0/uraXmSExJP/KqjGBDTBHZzmbEcHMAUr6tRyLNUZcN2Tsy5Hkx8zfoDsLWa5rhPEvoP+UaELkgdIoiNMz8OrDlHC4eGkyrn4Xb9myuPBfx5KVlv7D5FbRFgjgsD7uKeUr3jbsUIVt/zMelCFC1ww4kMMmDD7x1f5jPIwlXxERXU1kzDqYlRSYIelMuM0zvDBJ2SDUkcuRmQk8YzND9dMN3zgVLRSyq/dKFecFivRNU9eJ04nOIpvbwzXUssstmQXGqvfzYtyzRzc275MyEgVJfbc+4UCX3XHBFqJJvmqXJwes6Se+mOPZ3KDqff6a8YEw4mdbvcqGstfYN6yCHn0spFCL6KGLl6VIbatxLYO6rMIsceT3PD0QGsonFQ77KAFhQJVyiqT5//hTWsaYc90e8OMWFn5FQGgko2bE6dPRX8C2g4Z4/GqDuaoz3a4vnGVsnZ+iwP0uWq1PFpknUHcDQepqS0xHtRZlKxJ6949duoH6axmmlHykgEnAVoPlRsyPVWrii0S7zui7K8wP1+BeF72boMJmQMaEpVo= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(396003)(346002)(136003)(39860400002)(376002)(46966006)(6512007)(82310400003)(316002)(26005)(336012)(186003)(16526019)(107886003)(478600001)(69590400011)(356005)(2906002)(6506007)(36756003)(81166007)(34010700045)(4326008)(86362001)(47076005)(44832011)(83380400001)(70586007)(6486002)(8936002)(82740400003)(6666004)(6916009)(2616005)(956004)(70206006)(8676002)(5660300002)(2004002); DIR:OUT; SFP:1501; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2021 16:26:04.0054 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a6afbe4-2f0c-4529-1cea-08d8bbcdc032 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4816 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY 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: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: "H.J. Lu" Check ifunc resolver with CPU_FEATURE_USABLE and tunables in dynamic and static executables to verify that CPUID features are initialized early in static PIE. Reviewed-by: Adhemerval Zanella --- sysdeps/x86/Makefile | 14 ++++ sysdeps/x86/tst-ifunc-isa-1-static.c | 1 + sysdeps/x86/tst-ifunc-isa-1.c | 115 ++++++++++++++++++++++++++ sysdeps/x86/tst-ifunc-isa-2-static.c | 1 + sysdeps/x86/tst-ifunc-isa-2.c | 119 +++++++++++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 sysdeps/x86/tst-ifunc-isa-1-static.c create mode 100644 sysdeps/x86/tst-ifunc-isa-1.c create mode 100644 sysdeps/x86/tst-ifunc-isa-2-static.c create mode 100644 sysdeps/x86/tst-ifunc-isa-2.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index adaa2a92cd..f7969309bc 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -9,6 +9,16 @@ 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 +ifeq (yes,$(have-ifunc)) +tests += \ + tst-ifunc-isa-1 \ + tst-ifunc-isa-1-static \ + tst-ifunc-isa-2 \ + tst-ifunc-isa-2-static +tests-static += \ + tst-ifunc-isa-1-static \ + tst-ifunc-isa-2-static +endif ifeq (yes,$(enable-x86-isa-level)) tests += tst-isa-level-1 modules-names += tst-isa-level-mod-1-baseline \ @@ -39,6 +49,10 @@ $(objpfx)tst-isa-level-1.out: $(objpfx)tst-isa-level-mod-1-baseline.so \ $(objpfx)tst-isa-level-mod-1-v3.so \ $(objpfx)tst-isa-level-mod-1-v4.so endif +ifneq ($(have-tunables),no) +tst-ifunc-isa-2-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-SSE4_2,-AVX,-AVX2,-AVX512F +tst-ifunc-isa-2-static-ENV = $(tst-ifunc-isa-2-ENV) +endif endif ifeq ($(subdir),math) diff --git a/sysdeps/x86/tst-ifunc-isa-1-static.c b/sysdeps/x86/tst-ifunc-isa-1-static.c new file mode 100644 index 0000000000..0e94f6119b --- /dev/null +++ b/sysdeps/x86/tst-ifunc-isa-1-static.c @@ -0,0 +1 @@ +#include "tst-ifunc-isa-1.c" diff --git a/sysdeps/x86/tst-ifunc-isa-1.c b/sysdeps/x86/tst-ifunc-isa-1.c new file mode 100644 index 0000000000..b3bc2a55a2 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-isa-1.c @@ -0,0 +1,115 @@ +/* Check ifunc with CPU_FEATURE_USABLE. + Copyright (C) 2021 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 + +enum isa +{ + none, + sse2, + sse4_2, + avx, + avx2, + avx512f +}; + +enum isa +get_isa (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + if (CPU_FEATURE_USABLE (AVX)) + return avx; + if (CPU_FEATURE_USABLE (SSE4_2)) + return sse4_2; + if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +static int +isa_sse2 (void) +{ + return sse2; +} + +static int +isa_sse4_2 (void) +{ + return sse4_2; +} + +static int +isa_avx (void) +{ + return avx; +} + +static int +isa_avx2 (void) +{ + return avx2; +} + +static int +isa_avx512f (void) +{ + return avx512f; +} + +static int +isa_none (void) +{ + return none; +} + +int foo (void) __attribute__ ((ifunc ("foo_ifunc"))); + +void * +foo_ifunc (void) +{ + switch (get_isa ()) + { + case avx512f: + return isa_avx512f; + case avx2: + return isa_avx2; + case avx: + return isa_avx; + case sse4_2: + return isa_sse4_2; + case sse2: + return isa_sse2; + default: + break; + } + return isa_none; +} + +static int +do_test (void) +{ + enum isa value = foo (); + enum isa expected = get_isa (); + return value == expected ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#include diff --git a/sysdeps/x86/tst-ifunc-isa-2-static.c b/sysdeps/x86/tst-ifunc-isa-2-static.c new file mode 100644 index 0000000000..4a5af9a270 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-isa-2-static.c @@ -0,0 +1 @@ +#include "tst-ifunc-isa-2.c" diff --git a/sysdeps/x86/tst-ifunc-isa-2.c b/sysdeps/x86/tst-ifunc-isa-2.c new file mode 100644 index 0000000000..bb0f76c3e4 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-isa-2.c @@ -0,0 +1,119 @@ +/* Check ifunc with CPU_FEATURE_USABLE and tunables. + Copyright (C) 2021 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 +#include + +enum isa +{ + none, + sse2, + sse4_2, + avx, + avx2, + avx512f +}; + +enum isa +get_isa (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + if (CPU_FEATURE_USABLE (AVX)) + return avx; + if (CPU_FEATURE_USABLE (SSE4_2)) + return sse4_2; + if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +static int +isa_sse2 (void) +{ + return sse2; +} + +static int +isa_sse4_2 (void) +{ + return sse4_2; +} + +static int +isa_avx (void) +{ + return avx; +} + +static int +isa_avx2 (void) +{ + return avx2; +} + +static int +isa_avx512f (void) +{ + return avx512f; +} + +static int +isa_none (void) +{ + return none; +} + +int foo (void) __attribute__ ((ifunc ("foo_ifunc"))); + +void * +foo_ifunc (void) +{ + switch (get_isa ()) + { + case avx512f: + return isa_avx512f; + case avx2: + return isa_avx2; + case avx: + return isa_avx; + case sse4_2: + return isa_sse4_2; + case sse2: + return isa_sse2; + default: + break; + } + return isa_none; +} + +static int +do_test (void) +{ + /* CPU must support SSE2. */ + if (!__builtin_cpu_supports ("sse2")) + return EXIT_UNSUPPORTED; + enum isa value = foo (); + /* All ISAs, but SSE2, are disabled by tunables. */ + return value == sse2 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#include