This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC PATCH] Add AVX2 capability
- From: Victor Rodriguez <victor dot rodriguez dot bahena at intel dot com>
- To: libc-alpha at sourceware dot org
- Cc: Victor Rodriguez <victor dot rodriguez dot bahena at intel dot com>, Dimitri John Ledkov <dimitri dot j dot ledkov at intel dot com>
- Date: Tue, 17 Jan 2017 13:45:40 +0000
- Subject: [RFC PATCH] Add AVX2 capability
- Authentication-results: sourceware.org; auth=none
CPU architectures often gain interesting new instructions as they evolve, but
application developers often find it difficult to take advantage of those
instructions. The idea of this patch is to help distributions to use the AVX2
instructions. In this patch AVX2 capability is provided to glibc, like tls was
implemented.
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
Signed-off-by: Victor Rodriguez <victor.rodriguez.bahena@intel.com>
---
elf/dl-cache.c | 6 +++++-
elf/dl-hwcaps.c | 17 +++++++++++++++++
elf/ldconfig.c | 1 +
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index cfa335e..ae50470 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -259,8 +259,9 @@ _dl_load_cache_lookup (const char *name)
platform = 1ULL << platform;
#define _DL_HWCAP_TLS_MASK (1LL << 63)
+#define _DL_HWCAP_AVX2_MASK (1LL << 62)
uint64_t hwcap_exclude = ~((GLRO(dl_hwcap) & GLRO(dl_hwcap_mask))
- | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK);
+ | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK | _DL_HWCAP_AVX2_MASK);
/* Only accept hwcap if it's for the right platform. */
#define HWCAP_CHECK \
@@ -271,6 +272,9 @@ _dl_load_cache_lookup (const char *name)
if (_DL_PLATFORMS_COUNT \
&& (lib->hwcap & _DL_HWCAP_PLATFORM) != 0 \
&& (lib->hwcap & _DL_HWCAP_PLATFORM) != platform) \
+ continue; \
+ if (!HAS_ARCH_FEATURE (AVX2_Usable) && \
+ (lib->hwcap & _DL_HWCAP_AVX2_MASK)) \
continue
SEARCH_CACHE (cache_new);
}
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
index 6004ff2..4e46b75 100644
--- a/elf/dl-hwcaps.c
+++ b/elf/dl-hwcaps.c
@@ -111,6 +111,9 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
/* For TLS enabled builds always add 'tls'. */
++cnt;
+ /* Add 'avx2' capability on x86_64 */
+ ++cnt;
+
/* Create temporary data structure to generate result table. */
struct r_strlenpair temp[cnt];
m = 0;
@@ -163,6 +166,20 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
temp[m].len = 3;
++m;
+ if (HAS_ARCH_FEATURE (AVX2_Usable))
+ {
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
+ _dl_debug_printf (" adding avx2 cap support\n");
+ temp[m].str = "avx2";
+ temp[m].len = 4;
+ ++m;
+ }
+ else {
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
+ _dl_debug_printf (" not adding avx2 cap support\n");
+ --cnt;
+ }
+
assert (m == cnt);
/* Determine the total size of all strings together. */
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 467ca82..ee21217 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -1298,6 +1298,7 @@ main (int argc, char **argv)
under which TLS support was optional. The entry is no longer needed, but
must remain for compatibility. */
hwcap_extra[63 - _DL_FIRST_EXTRA] = "tls";
+ hwcap_extra[62 - _DL_FIRST_EXTRA] = "avx2";
set_hwcap ();
--
2.11.0