From patchwork Thu May 18 20:42:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 20497 Received: (qmail 72865 invoked by alias); 18 May 2017 20:43:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 72826 invoked by uid 89); 18 May 2017 20:43:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: homiemail-a68.g.dreamhost.com From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org Subject: [PATCH] Consolidate code to get hwcap_mask into GET_HWCAP_MASK macro Date: Fri, 19 May 2017 02:12:49 +0530 Message-Id: <1495140169-32707-1-git-send-email-siddhesh@sourceware.org> Consolidate the preprocessor conditionals to get the HWCAP_MASK with or without tunables into a single macro defined in a new header file dl-hwcaps.h. * elf/dl-hwcaps.h: New file. * elf/dl-hwcaps.c: Include dl-hwcaps.h. (_dl_important_hwcaps) Use new GET_HWCAP_MASK macro. * sysdeps/sparc/sparc32/dl-machine.h: Likewise. * sysdeps/unix/sysv/linux/aarch64/cpu-features.c: Likewise. --- elf/dl-hwcaps.c | 7 ++----- elf/dl-hwcaps.h | 25 +++++++++++++++++++++++++ sysdeps/sparc/sparc32/dl-machine.h | 9 ++------- sysdeps/unix/sysv/linux/aarch64/cpu-features.c | 9 ++------- 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 elf/dl-hwcaps.h diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c index 2b9f7f1..a37a3ff 100644 --- a/elf/dl-hwcaps.c +++ b/elf/dl-hwcaps.c @@ -25,6 +25,7 @@ #include #include +#include #ifdef _DL_FIRST_PLATFORM # define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT) @@ -38,11 +39,7 @@ internal_function _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, size_t *max_capstrlen) { -#if HAVE_TUNABLES - uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t); -#else - uint64_t hwcap_mask = GLRO(dl_hwcap_mask); -#endif + uint64_t hwcap_mask = GET_HWCAP_MASK(); /* Determine how many important bits are set. */ uint64_t masked = GLRO(dl_hwcap) & hwcap_mask; size_t cnt = platform != NULL; diff --git a/elf/dl-hwcaps.h b/elf/dl-hwcaps.h new file mode 100644 index 0000000..0fd05ac --- /dev/null +++ b/elf/dl-hwcaps.h @@ -0,0 +1,25 @@ +/* Hardware capability support for run-time dynamic loader. + Copyright (C) 2017 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 + +#if HAVE_TUNABLES +# define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t) +#else +# define GET_HWCAP_MASK() GLRO(dl_hwcap_mask) +#endif diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h index f5e8078..620cd2e 100644 --- a/sysdeps/sparc/sparc32/dl-machine.h +++ b/sysdeps/sparc/sparc32/dl-machine.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include /* Return nonzero iff ELF header is compatible with the running host. */ static inline int @@ -39,12 +39,7 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr) { /* XXX The following is wrong! Dave Miller rejected to implement it correctly. If this causes problems shoot *him*! */ -#ifdef SHARED -# if HAVE_TUNABLES - uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t); -# else - uint64_t hwcap_mask = GLRO(dl_hwcap_mask); -# endif + uint64_t hwcap_mask = GET_HWCAP_MASK(); return GLRO(dl_hwcap) & hwcap_mask & HWCAP_SPARC_V9; #else return GLRO(dl_hwcap) & HWCAP_SPARC_V9; diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c index 0478fcc..ef6eecd 100644 --- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c +++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c @@ -18,17 +18,12 @@ #include #include -#include +#include static inline void init_cpu_features (struct cpu_features *cpu_features) { -#if HAVE_TUNABLES - uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t); -#else - uint64_t hwcap_mask = GLRO (dl_hwcap_mask); -#endif - + uint64_t hwcap_mask = GET_HWCAP_MASK(); uint64_t hwcap = GLRO (dl_hwcap) & hwcap_mask; if (hwcap & HWCAP_CPUID)