Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/arm/cpu_features: simplify ifdefs for runtime detection #359

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
5 changes: 3 additions & 2 deletions lib/arm/cpu_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
#include "../cpu_features_common.h" /* must be included first */
#include "cpu_features.h"

#if HAVE_DYNAMIC_ARM_CPU_FEATURES
#ifdef ARM_CPU_FEATURES_KNOWN
/* Runtime ARM CPU feature detection is supported. */

#ifdef __linux__
/*
Expand Down Expand Up @@ -220,4 +221,4 @@ void libdeflate_init_arm_cpu_features(void)
libdeflate_arm_cpu_features = features | ARM_CPU_FEATURES_KNOWN;
}

#endif /* HAVE_DYNAMIC_ARM_CPU_FEATURES */
#endif /* ARM_CPU_FEATURES_KNOWN */
24 changes: 9 additions & 15 deletions lib/arm/cpu_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@

#include "../lib_common.h"

#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0

#if defined(ARCH_ARM32) || defined(ARCH_ARM64)

#if !defined(FREESTANDING) && \
(defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)) && \
(defined(__linux__) || \
(defined(__APPLE__) && defined(ARCH_ARM64)) || \
(defined(_WIN32) && defined(ARCH_ARM64)))
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1
#endif

#define ARM_CPU_FEATURE_NEON (1 << 0)
#define ARM_CPU_FEATURE_PMULL (1 << 1)
/*
Expand All @@ -55,8 +44,13 @@
#define ARM_CPU_FEATURE_SHA3 (1 << 4)
#define ARM_CPU_FEATURE_DOTPROD (1 << 5)

#if HAVE_DYNAMIC_ARM_CPU_FEATURES
#define ARM_CPU_FEATURES_KNOWN (1U << 31)
#if !defined(FREESTANDING) && \
(defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)) && \
(defined(__linux__) || \
(defined(__APPLE__) && defined(ARCH_ARM64)) || \
(defined(_WIN32) && defined(ARCH_ARM64)))
/* Runtime ARM CPU feature detection is supported. */
# define ARM_CPU_FEATURES_KNOWN (1U << 31)
extern volatile u32 libdeflate_arm_cpu_features;

void libdeflate_init_arm_cpu_features(void);
Expand All @@ -67,9 +61,9 @@ static inline u32 get_arm_cpu_features(void)
libdeflate_init_arm_cpu_features();
return libdeflate_arm_cpu_features;
}
#else /* HAVE_DYNAMIC_ARM_CPU_FEATURES */
#else
static inline u32 get_arm_cpu_features(void) { return 0; }
#endif /* !HAVE_DYNAMIC_ARM_CPU_FEATURES */
#endif

/* NEON */
#if defined(__ARM_NEON) || (defined(_MSC_VER) && defined(ARCH_ARM64))
Expand Down
Loading