Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/fil-c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ jobs:
# says nothing about them. The C implementations of the same
# algorithms are covered by the other legs.
#
# There is no aarch64 counterpart to the 'default, asm' leg either.
# Leaving assembly on for an aarch64 host makes configure define
# WOLFSSL_AARCH64_BUILD, so cpuid.h defines HAVE_CPUID_AARCH64 and
# cpuid.c includes <asm/hwcap.h>, a Linux kernel header that Fil-C's
# sysroot does not ship. That is a property of the sysroot, not of
# wolfSSL, and there is no way to keep the assembly while dropping the
# CPU id, so the aarch64 legs stay on --disable-asm.
# No aarch64 'default, asm' leg, since Fil-C panics on the inline
# assembly of sp_div_word in sp_int.c.
include:
- name: 'default'
config: ''
Expand Down
46 changes: 39 additions & 7 deletions wolfcrypt/src/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,44 @@
* posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu */

#include <sys/auxv.h>
#include <asm/hwcap.h>

/* Kernel <asm/hwcap.h> values, for C libraries that lack them. */
#ifndef AT_HWCAP2
#define AT_HWCAP2 26
#endif
#ifndef HWCAP_ASIMD
#define HWCAP_ASIMD (1 << 1)
#endif
#ifndef HWCAP_AES
#define HWCAP_AES (1 << 3)
#endif
#ifndef HWCAP_PMULL
#define HWCAP_PMULL (1 << 4)
#endif
#ifndef HWCAP_SHA2
#define HWCAP_SHA2 (1 << 6)
#endif
#ifndef HWCAP_ASIMDRDM
#define HWCAP_ASIMDRDM (1 << 12)
#endif
#ifndef HWCAP_SHA3
#define HWCAP_SHA3 (1 << 17)
#endif
#ifndef HWCAP_SM3
#define HWCAP_SM3 (1 << 18)
#endif
#ifndef HWCAP_SM4
#define HWCAP_SM4 (1 << 19)
#endif
#ifndef HWCAP_SHA512
#define HWCAP_SHA512 (1 << 21)
#endif
#ifndef HWCAP_SVE
#define HWCAP_SVE (1 << 22)
#endif
#ifndef HWCAP2_SME
#define HWCAP2_SME (1 << 23)
#endif

static WC_INLINE void cpuid_set_flags(void)
{
Expand All @@ -364,7 +401,7 @@
if (hwcaps & HWCAP_SHA512)
new_cpuid_flags |= CPUID_SHA512;
#endif
#if defined(HWCAP_ASIMDRDM) && !defined(WOLFSSL_AARCH64_NO_SQRDMLSH)
#ifndef WOLFSSL_AARCH64_NO_SQRDMLSH
if (hwcaps & HWCAP_ASIMDRDM)
new_cpuid_flags |= CPUID_RDM;
#endif
Expand All @@ -380,17 +417,12 @@
if (hwcaps & HWCAP_SM4)
new_cpuid_flags |= CPUID_SM4;
#endif
#ifdef HWCAP_SVE
if (hwcaps & HWCAP_SVE)
new_cpuid_flags |= CPUID_SVE;
#endif
#ifdef HWCAP2_SME
/* SME is reported in the second HWCAP word. */
if (getauxval(AT_HWCAP2) & HWCAP2_SME)
new_cpuid_flags |= CPUID_SME;
#endif

(void)hwcaps;
(void)wolfSSL_Atomic_Uint_CompareExchange
(&cpuid_flags, &old_cpuid_flags, new_cpuid_flags);
}
Expand Down
Loading