Skip to content

Commit 742eff5

Browse files
mkannwischerhanno-becker
authored andcommitted
CI: Add RISC-V runners to base CI (via RISE project)
Port of mlkem-native#1643. Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
1 parent abda243 commit 742eff5

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

.github/workflows/base.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
name: 'aarch64'
3636
- runner: ubuntu-latest
3737
name: 'x86_64'
38+
# via https://riseproject-dev.github.io/riscv-runner/
39+
- runner: ubuntu-24.04-riscv
40+
name: 'riscv'
3841
- runner: macos-latest
3942
name: 'macos (aarch64)'
4043
- runner: macos-15-intel
@@ -69,6 +72,9 @@ jobs:
6972
name: 'aarch64'
7073
- runner: ubuntu-latest
7174
name: 'x86_64'
75+
# via https://riseproject-dev.github.io/riscv-runner/
76+
- runner: ubuntu-24.04-riscv
77+
name: 'riscv'
7278
acvp-version: [v1.1.0.39, v1.1.0.40, v1.1.0.41]
7379
exclude:
7480
- {external: true,
@@ -215,7 +221,7 @@ jobs:
215221
simpasm:
216222
strategy:
217223
fail-fast: false
218-
matrix:
224+
matrix:
219225
backend:
220226
- arg: '--aarch64-clean'
221227
name: Clean

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ ifeq ($(ARCH),x86_64)
261261
else ifeq ($(ARCH),aarch64)
262262
@echo "=== AArch64 Feature Support ==="
263263
@echo "SHA3: Host $(if $(filter 1,$(MK_HOST_SUPPORTS_SHA3)),✅,❌) Compiler $(if $(filter 1,$(MK_COMPILER_SUPPORTS_SHA3)),✅,❌)"
264+
else ifeq ($(ARCH),riscv64)
265+
@echo "=== RISC-V 64-bit Feature Support ==="
266+
@echo "RVV: Host $(if $(filter 1,$(MK_HOST_SUPPORTS_RVV)),✅,❌) Compiler $(if $(filter 1,$(MK_COMPILER_SUPPORTS_RVV)),✅,❌)"
264267
else
265268
@echo "=== Architecture Not Supported ==="
266269
@echo "No specific feature detection available for $(ARCH)"

test/mk/auto.mk

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ MK_COMPILER_SUPPORTS_SHA3 ?= $(shell echo 'int main() { __asm__("eor3 v0.16b, v1
6868

6969
endif # aarch64 compiler detection
7070

71+
# RISC-V 64-bit compiler feature detection
72+
ifeq ($(ARCH),riscv64)
73+
74+
# Test RVV support using C with inline assembly
75+
MK_COMPILER_SUPPORTS_RVV ?= $(shell echo 'int main() { __asm__("vadd.vv v0, v1, v2"); return 0; }' | $(CC) -march=rv64gcv -x c - -c -o /dev/null 2>/dev/null && echo 1 || echo 0)
76+
77+
endif # riscv64 compiler detection
78+
7179
# Define HOST_PLATFORM if not already defined
7280
HOST_PLATFORM ?= $(shell uname -s)-$(shell uname -m)
7381

@@ -125,6 +133,25 @@ endif # HOST_PLATFORM aarch64
125133

126134
endif # aarch64
127135

136+
# RISC-V 64-bit architecture detection
137+
ifeq ($(ARCH),riscv64)
138+
139+
# Host CPU feature detection for RISC-V 64-bit
140+
ifeq ($(HOST_PLATFORM),Linux-riscv64)
141+
# Linux: Parse ISA string from /proc/cpuinfo
142+
# Format: rv64imafdcv_sscofpmf_... -- extract single-letter extensions
143+
# (before first '_') and check for 'v'
144+
MK_HOST_SUPPORTS_RVV := $(shell sed -n '/^isa/{s/.*rv64//;s/_.*//;p;q}' /proc/cpuinfo 2>/dev/null | grep -q v && echo 1 || echo 0)
145+
else ifneq ($(CROSS_PREFIX),)
146+
# Cross-compilation: assume all features are supported
147+
MK_HOST_SUPPORTS_RVV := 1
148+
else
149+
# Other platforms: assume no support
150+
MK_HOST_SUPPORTS_RVV := 0
151+
endif # HOST_PLATFORM riscv64
152+
153+
endif # riscv64
154+
128155
# Only apply CFLAGS modifications if AUTO=1
129156
ifeq ($(AUTO),1)
130157

@@ -160,7 +187,11 @@ endif # aarch64_be
160187
# RISC-V 64-bit CFLAGS configuration
161188
ifeq ($(ARCH),riscv64)
162189
CFLAGS += -DMLD_FORCE_RISCV64
190+
191+
# Add RVV flags only if both compiler and host support it
192+
ifeq ($(MK_COMPILER_SUPPORTS_RVV)$(MK_HOST_SUPPORTS_RVV),11)
163193
CFLAGS += -march=rv64gcv
194+
endif
164195
endif # riscv64
165196

166197
# RISC-V 32-bit CFLAGS configuration

0 commit comments

Comments
 (0)