Skip to content

Commit

Permalink
Trim some redundant Arm feature detection files
Browse files Browse the repository at this point in the history
cpu_arm_openbsd.c is the same as OPENSSL_STATIC_ARMCAP.
cpu_aarch64_freebsd.c is the same as cpu_aarch64_sysreg.c. (The FreeBSD
one was using the macros in their headers, but those macros expand to
the same inline assembly.)

Also send ANDROID_BAREMETAL + 32-bit Arm to OPENSSL_STATIC_ARMCAP. This
way we can remove OPENSSL_STATIC_ARMCAP from the Android baremetal build
without having to chase down constraining it to aarch64. See
b/291106677#comment6

Update-Note: This is a slight change to the OpenBSD build. Previously,
we assumed OpenBSD on 32-bit Arm implies NEON. Now, we pick it up from
the __ARM_NEON define from ACLE, i.e. whether the compiler has been told
that NEON is available. (This comes from -march or other options.) Doing
that is desirable anyway: if NEON is in your baseline, you should tell
your compiler so it can vectorize loops.

Change-Id: Icd43a2b56bb6e3f04f0fed996ae750fba65e3312
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62066
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
(cherry picked from commit d95b03c315bac8c44d3ce062053d3a5817915d91)
  • Loading branch information
davidben authored and andrewhop committed Jan 20, 2024
1 parent 5a4a7d1 commit d36bf85
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 126 deletions.
2 changes: 0 additions & 2 deletions crypto/fipsmodule/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
#include "cpucap/cpu_aarch64.c"
#include "cpucap/cpu_aarch64_sysreg.c"
#include "cpucap/cpu_aarch64_apple.c"
#include "cpucap/cpu_aarch64_freebsd.c"
#include "cpucap/cpu_aarch64_fuchsia.c"
#include "cpucap/cpu_aarch64_linux.c"
#include "cpucap/cpu_aarch64_openbsd.c"
#include "cpucap/cpu_aarch64_win.c"
#include "cpucap/cpu_arm_freebsd.c"
#include "cpucap/cpu_arm_linux.c"
Expand Down
61 changes: 0 additions & 61 deletions crypto/fipsmodule/cpucap/cpu_aarch64_freebsd.c

This file was deleted.

58 changes: 0 additions & 58 deletions crypto/fipsmodule/cpucap/cpu_aarch64_openbsd.c

This file was deleted.

8 changes: 6 additions & 2 deletions crypto/fipsmodule/cpucap/cpu_aarch64_sysreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

#include "../../internal.h"

// While Arm system registers are normally not available to userspace, FreeBSD
// expects userspace to simply read them. It traps the reads and fills in CPU
// capabilities.
#if defined(OPENSSL_AARCH64) && !defined(OPENSSL_STATIC_ARMCAP) && \
defined(ANDROID_BAREMETAL)
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD))

#include <openssl/arm_arch.h>

Expand Down Expand Up @@ -86,4 +89,5 @@ static uint32_t read_armcap(void) {

void OPENSSL_cpuid_setup(void) { OPENSSL_armcap_P |= read_armcap(); }

#endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP && ANDROID_BAREMETAL
#endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP &&
// (ANDROID_BAREMETAL || OPENSSL_FREEBSD)
10 changes: 7 additions & 3 deletions crypto/fipsmodule/cpucap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ OPENSSL_INLINE int CRYPTO_is_VBMI2_capable(void) {

#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)

#if defined(OPENSSL_APPLE) && defined(OPENSSL_ARM)
// We do not detect any features at runtime for Apple's 32-bit ARM platforms. On
// 64-bit ARM, we detect some post-ARMv8.0 features.
// We do not detect any features at runtime on several 32-bit Arm platforms.
// Apple platforms and OpenBSD require NEON and moved to 64-bit to pick up Armv8
// extensions. Android baremetal does not aim to support 32-bit Arm at all, but
// it simplifies things to make it build.
#if defined(OPENSSL_ARM) && !defined(OPENSSL_STATIC_ARMCAP) && \
(defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || \
defined(ANDROID_BAREMETAL))
#define OPENSSL_STATIC_ARMCAP
#endif

Expand Down

0 comments on commit d36bf85

Please sign in to comment.