Skip to content

Commit

Permalink
Add cpucap.h header and detect AArch64 systems
Browse files Browse the repository at this point in the history
Also, allow `FORCE_AARCH64` to double-check that a system is recognized
as AArch64. Use this in all AArch64-based CI builds.

Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Sep 9, 2024
1 parent 580c136 commit 157c445
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ jobs:
name: Arm Cortex-A72 (Raspberry Pi 4) benchmarks
bench_pmu: PMU
archflags: -mcpu=cortex-a72
cflags:
cflags: -DFORCE_AARCH64
bench_extra_args:
- system: rpi5
name: Arm Cortex-A76 (Raspberry Pi 5) benchmarks
bench_pmu: PERF
archflags: "-mcpu=cortex-a76 -march=armv8.2-a"
cflags:
cflags: -DFORCE_AARCH64
bench_extra_args:
- system: a55
name: Arm Cortex-A55 (Snapdragon 888) benchmarks
bench_pmu: PERF
archflags: "-mcpu=cortex-a55 -march=armv8.2-a"
cflags: -static
cflags: "-static -DFORCE_AARCH64"
bench_extra_args: -w exec-on-a55
runs-on: self-hosted-${{ matrix.target.system }}
defaults:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/bench_ec2_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
ec2_instance_type: t4g.small
ec2_ami_id: ami-096ea6a12ea24a797
archflags: -mcpu=cortex-a76 -march=armv8.2-a
cflags: -DFORCE_AARCH64
store_results: 'true'
name: Graviton2
secrets: inherit
Expand All @@ -32,6 +33,7 @@ jobs:
ec2_instance_type: c7g.medium
ec2_ami_id: ami-096ea6a12ea24a797
archflags: -mcpu=neoverse-v1 -march=armv8.4-a
cflags: -DFORCE_AARCH64
store_results: 'true'
name: Graviton3
secrets: inherit
2 changes: 1 addition & 1 deletion mk/schemes.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
SOURCES = $(wildcard mlkem/*.c)

CPPFLAGS += -Imlkem
CPPFLAGS += -Imlkem -Imlkem/sys
TESTS = test_kyber bench_kyber gen_NISTKAT gen_KAT

MLKEM512_DIR = $(BUILD_DIR)/mlkem512
Expand Down
2 changes: 2 additions & 0 deletions mlkem/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef PARAMS_H
#define PARAMS_H

#include "cpucap.h"

#ifndef KYBER_K
#define KYBER_K 3 /* Change this for different security strengths */
#endif
Expand Down
16 changes: 16 additions & 0 deletions mlkem/sys/cpucap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0

#ifndef CPUCAP_H
#define CPUCAP_H

/* Check if we're running on an AArch64 system. _M_ARM64 is set by MSVC. */
#if defined(__aarch64__) || defined(_M_ARM64)
#define SYS_AARCH64
#endif

/* If FORCE_AARCH64 is set, assert that we're indeed on an AArch64 system. */
#if defined(FORCE_AARCH64) && !defined(SYS_AARCH64)
#error "FORCE_AARCH64 is set, but we don't seem to be on an AArch64 system.
#endif

#endif

0 comments on commit 157c445

Please sign in to comment.