From patchwork Thu Dec 24 23:02:56 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: 41553 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 6C9E83938C1F; Thu, 24 Dec 2020 23:03:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C9E83938C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608850984; bh=BtsMwhI1KtgPMzfYCalekTQM2oOR437mbCiC0JX7fng=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gmrf6D6dtrroOKlCVVw+mditZxJt4uIhoWCNyQjRINO6w3Rq/tBGQx0Qc75VIoo/u Wvuohy/Ij/hpmiFE9FOTRNAbRzhaxD80J+z4mlXlTN3fKm+oin1eWI99Ze44ciAClL SNhsSYu1bxCh7ysuBgwDBjVAlGWFFh1zRbQ0bEIE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 233DE3938C1E for ; Thu, 24 Dec 2020 23:03:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 233DE3938C1E Received: by mail-pl1-x62f.google.com with SMTP id b8so1848143plx.0 for ; Thu, 24 Dec 2020 15:03:01 -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:subject:date:message-id:mime-version :content-transfer-encoding; bh=BtsMwhI1KtgPMzfYCalekTQM2oOR437mbCiC0JX7fng=; b=M63qdSar/Kvm5DXI2dd7vDMQhNsPGECqZmIaPluDCFQOYlBmYOjb1K+APUiaVlXKHI y3tEcp023lL1S2wpPazItekIH2lcjLQJ/RQoCCJGTtDn1p83cL9P3emFVUinFUQRAHUf luyZu4MdBZuCrX7trz5XsdO+OsamZJZb+eCi8SyEETxm9wdY0gkIoGvfXE7h3WQtl6i+ 6wCLIa4A1a6m0EdbjVomNbI3lh5EKZlXtrL0aheClfgGVBA/ZJEQPsIHrWpWxPBFAwBs JTCX8pDc5q370dqrafW269wCoZO34IW02CPBW5C5lJknBp4Tv2tnuIHqCr45C/EfJVev wlvA== X-Gm-Message-State: AOAM533KjalDkBC5Um4fq3E0K9SpccZAxYnIzW5tyYNUycPTgcwRabxR 2BiwhZRMp6aelAeQy7DUG7fv4FiAKl0= X-Google-Smtp-Source: ABdhPJwCGMV/XYiHrP6IWdr6qwjrwspGJGXc+vlYO/wzBoI+Y4/S4P+7nbWc6HLCZBubQXe180EbGw== X-Received: by 2002:a17:90b:80d:: with SMTP id bk13mr6126803pjb.41.1608850979899; Thu, 24 Dec 2020 15:02:59 -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 o1sm4243181pgq.1.2020.12.24.15.02.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Dec 2020 15:02:59 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 1B7C21A013E for ; Thu, 24 Dec 2020 15:02:58 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE Date: Thu, 24 Dec 2020 15:02:56 -0800 Message-Id: <20201224230256.2646417-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.9 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" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without lazy binding. --- sysdeps/x86/Makefile | 22 +++++- sysdeps/x86/tst-ifunc-platform-1-bindnow.c | 1 + sysdeps/x86/tst-ifunc-platform-1-lazy.c | 89 ++++++++++++++++++++++ sysdeps/x86/tst-ifunc-platform-1-static.c | 1 + sysdeps/x86/tst-ifunc-platform-2-bindnow.c | 1 + sysdeps/x86/tst-ifunc-platform-2-lazy.c | 52 +++++++++++++ sysdeps/x86/tst-ifunc-platform-mod-2.c | 65 ++++++++++++++++ 7 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 sysdeps/x86/tst-ifunc-platform-1-bindnow.c create mode 100644 sysdeps/x86/tst-ifunc-platform-1-lazy.c create mode 100644 sysdeps/x86/tst-ifunc-platform-1-static.c create mode 100644 sysdeps/x86/tst-ifunc-platform-2-bindnow.c create mode 100644 sysdeps/x86/tst-ifunc-platform-2-lazy.c create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-2.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 00109ded11..441e11687b 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -7,8 +7,26 @@ sysdep-dl-routines += dl-get-cpu-features sysdep_headers += bits/platform/x86.h 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 + tst-cpu-features-cpuinfo tst-cpu-features-supports \ + tst-ifunc-platform-1-bindnow \ + tst-ifunc-platform-1-lazy \ + tst-ifunc-platform-1-static \ + tst-ifunc-platform-2-bindnow \ + tst-ifunc-platform-2-lazy +tests-static += tst-get-cpu-features-static \ + tst-ifunc-platform-1-static + +modules-names += tst-ifunc-platform-mod-2 + +LDFLAGS-tst-ifunc-platform-1-lazy = -Wl,-z,lazy +LDFLAGS-tst-ifunc-platform-1-bindnow = -Wl,-z,now +tst-ifunc-platform-1-bindnow-ENV = LD_BIND_NOW=1 +LDFLAGS-tst-ifunc-platform-2-lazy = -Wl,-z,lazy +LDFLAGS-tst-ifunc-platform-2-bindnow = -Wl,-z,now +tst-ifunc-platform-2-bindnow-ENV = LD_BIND_NOW=1 + +$(objpfx)tst-ifunc-platform-2-bindnow: $(objpfx)tst-ifunc-platform-mod-2.so +$(objpfx)tst-ifunc-platform-2-lazy: $(objpfx)tst-ifunc-platform-mod-2.so endif ifeq ($(subdir),math) diff --git a/sysdeps/x86/tst-ifunc-platform-1-bindnow.c b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c new file mode 100644 index 0000000000..f8391048ae --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-1-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-1-lazy.c b/sysdeps/x86/tst-ifunc-platform-1-lazy.c new file mode 100644 index 0000000000..fcb192d68d --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-lazy.c @@ -0,0 +1,89 @@ +/* Program with local IFUNC resolver and . + 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 + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +static enum isa +none (void) +{ + return has_none; +} + +static enum isa +sse2 (void) +{ + return has_sse2; +} + +static enum isa +avx2 (void) +{ + return has_avx2; +} + +static enum isa +avx512f (void) +{ + return has_avx512f; +} + +static __typeof__ (avx2) * +resolver (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + else if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + else if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +static enum isa cpuid (void) __attribute__ ((ifunc ("resolver"))); + +static int +do_test (void) +{ + enum isa has_isa = cpuid (); + switch (has_isa) + { + case has_none: + break; + case has_sse2: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("sse2")); + break; + case has_avx2: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx2")); + break; + case has_avx512f: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx512f")); + break; + } + return 0; +} + +#include diff --git a/sysdeps/x86/tst-ifunc-platform-1-static.c b/sysdeps/x86/tst-ifunc-platform-1-static.c new file mode 100644 index 0000000000..f8391048ae --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-static.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-1-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-2-bindnow.c b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c new file mode 100644 index 0000000000..7c2455c2a0 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-2-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-2-lazy.c b/sysdeps/x86/tst-ifunc-platform-2-lazy.c new file mode 100644 index 0000000000..65b5f5e314 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-2-lazy.c @@ -0,0 +1,52 @@ +/* Program with local IFUNC resolver and . + 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 + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +extern enum isa cpuid (void); + +static int +do_test (void) +{ + enum isa has_isa = cpuid (); + switch (has_isa) + { + case has_none: + break; + case has_sse2: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("sse2")); + break; + case has_avx2: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx2")); + break; + case has_avx512f: + TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx512f")); + break; + } + return 0; +} + +#include diff --git a/sysdeps/x86/tst-ifunc-platform-mod-2.c b/sysdeps/x86/tst-ifunc-platform-mod-2.c new file mode 100644 index 0000000000..c302277be4 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-mod-2.c @@ -0,0 +1,65 @@ +/* Shared object with local IFUNC resolver and . + 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 + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +static enum isa +none (void) +{ + return has_none; +} + +static enum isa +sse2 (void) +{ + return has_sse2; +} + +static enum isa +avx2 (void) +{ + return has_avx2; +} + +static enum isa +avx512f (void) +{ + return has_avx512f; +} + +static __typeof__ (avx2) * +resolver (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + else if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + else if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +enum isa cpuid (void) __attribute__ ((ifunc ("resolver")));