Skip to content

Commit bcb83bf

Browse files
committed
riscv32: Support 64-bit atomics (Zacas extension)
1 parent d0fcef1 commit bcb83bf

File tree

11 files changed

+823
-35
lines changed

11 files changed

+823
-35
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ jobs:
253253
# target: powerpc64le-unknown-linux-gnu
254254
- rust: nightly
255255
target: powerpc64le-unknown-linux-gnu
256+
- rust: nightly-2024-02-13 # Rust 1.78, LLVM 17
257+
target: riscv32gc-unknown-linux-gnu
258+
- rust: nightly-2024-07-31 # Rust 1.82, LLVM 18
259+
target: riscv32gc-unknown-linux-gnu
256260
- rust: nightly
257261
target: riscv32gc-unknown-linux-gnu
258262
- rust: nightly-2021-08-21 # Rust 1.56, LLVM 12
@@ -317,6 +321,9 @@ jobs:
317321
# TODO: LLVM bug: Undefined temporary symbol error when building std.
318322
- run: printf 'RELEASE=--release\n' >>"${GITHUB_ENV}"
319323
if: startsWith(matrix.target, 'mips-') || startsWith(matrix.target, 'mipsel-')
324+
# for serde
325+
- run: printf '%s\n' "RUSTFLAGS=${RUSTFLAGS} --cfg no_diagnostic_namespace" >>"${GITHUB_ENV}"
326+
if: matrix.rust == 'nightly-2024-02-13'
320327

321328
- run: tools/test.sh -vv ${TARGET:-} ${DOCTEST_XCOMPILE:-} ${BUILD_STD:-} ${RELEASE:-}
322329
# We test doctest only once with the default build conditions because doctest is slow. Both api-test
@@ -388,21 +395,21 @@ jobs:
388395
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-cpu=pwr8
389396
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-cpu=pwr8
390397
if: startsWith(matrix.target, 'powerpc64-')
391-
# riscv64 +zabha
398+
# riscv +zabha
392399
- run: tools/test.sh -vv --tests ${TARGET:-} ${BUILD_STD:-} ${RELEASE:-}
393400
env:
394401
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+zabha
395402
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+zabha
396403
QEMU_CPU: max
397404
# TODO: cranelift doesn't support cfg(target_feature): https://github.com/rust-lang/rustc_codegen_cranelift/issues/1400
398-
if: startsWith(matrix.target, 'riscv64') && !contains(matrix.flags, 'codegen-backend=cranelift')
399-
# riscv64 +experimental-zacas
405+
if: startsWith(matrix.target, 'riscv') && !contains(matrix.flags, 'codegen-backend=cranelift')
406+
# riscv +experimental-zacas
400407
- run: tools/test.sh -vv --tests ${TARGET:-} ${BUILD_STD:-} ${RELEASE:-}
401408
env:
402409
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+experimental-zacas
403410
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+experimental-zacas
404411
# TODO: cranelift doesn't support cfg(target_feature): https://github.com/rust-lang/rustc_codegen_cranelift/issues/1400
405-
if: startsWith(matrix.target, 'riscv64') && !contains(matrix.flags, 'codegen-backend=cranelift')
412+
if: startsWith(matrix.target, 'riscv') && !contains(matrix.flags, 'codegen-backend=cranelift')
406413
# s390x z196 (arch9)
407414
- run: tools/test.sh -vv --tests ${TARGET:-} ${BUILD_STD:-} ${RELEASE:-}
408415
env:

src/cfgs.rs

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,36 @@ mod atomic_32_macros {
154154
),
155155
target_has_atomic = "64",
156156
not(any(target_pointer_width = "16", target_pointer_width = "32")),
157+
all(
158+
target_arch = "riscv32",
159+
not(any(miri, portable_atomic_sanitize_thread)),
160+
not(portable_atomic_no_asm),
161+
any(
162+
target_feature = "experimental-zacas",
163+
portable_atomic_target_feature = "experimental-zacas",
164+
// TODO(riscv)
165+
// all(
166+
// feature = "fallback",
167+
// not(portable_atomic_no_outline_atomics),
168+
// any(test, portable_atomic_outline_atomics), // TODO(riscv): currently disabled by default
169+
// any(
170+
// all(
171+
// target_os = "linux",
172+
// any(
173+
// target_env = "gnu",
174+
// all(
175+
// any(target_env = "musl", target_env = "ohos"),
176+
// not(target_feature = "crt-static"),
177+
// ),
178+
// portable_atomic_outline_atomics,
179+
// ),
180+
// ),
181+
// target_os = "android",
182+
// ),
183+
// not(any(miri, portable_atomic_sanitize_thread)),
184+
// ),
185+
),
186+
),
157187
))
158188
)]
159189
#[macro_use]
@@ -201,6 +231,36 @@ mod atomic_64_macros {
201231
),
202232
target_has_atomic = "64",
203233
not(any(target_pointer_width = "16", target_pointer_width = "32")),
234+
all(
235+
target_arch = "riscv32",
236+
not(any(miri, portable_atomic_sanitize_thread)),
237+
not(portable_atomic_no_asm),
238+
any(
239+
target_feature = "experimental-zacas",
240+
portable_atomic_target_feature = "experimental-zacas",
241+
// TODO(riscv)
242+
// all(
243+
// feature = "fallback",
244+
// not(portable_atomic_no_outline_atomics),
245+
// any(test, portable_atomic_outline_atomics), // TODO(riscv): currently disabled by default
246+
// any(
247+
// all(
248+
// target_os = "linux",
249+
// any(
250+
// target_env = "gnu",
251+
// all(
252+
// any(target_env = "musl", target_env = "ohos"),
253+
// not(target_feature = "crt-static"),
254+
// ),
255+
// portable_atomic_outline_atomics,
256+
// ),
257+
// ),
258+
// target_os = "android",
259+
// ),
260+
// not(any(miri, portable_atomic_sanitize_thread)),
261+
// ),
262+
),
263+
),
204264
)))
205265
)]
206266
#[macro_use]
@@ -247,11 +307,11 @@ mod atomic_64_macros {
247307
any(
248308
target_feature = "experimental-zacas",
249309
portable_atomic_target_feature = "experimental-zacas",
250-
// TODO(riscv64)
310+
// TODO(riscv)
251311
// all(
252312
// feature = "fallback",
253313
// not(portable_atomic_no_outline_atomics),
254-
// any(test, portable_atomic_outline_atomics), // TODO(riscv64): currently disabled by default
314+
// any(test, portable_atomic_outline_atomics), // TODO(riscv): currently disabled by default
255315
// any(
256316
// all(
257317
// target_os = "linux",
@@ -366,11 +426,11 @@ mod atomic_128_macros {
366426
any(
367427
target_feature = "experimental-zacas",
368428
portable_atomic_target_feature = "experimental-zacas",
369-
// TODO(riscv64)
429+
// TODO(riscv)
370430
// all(
371431
// feature = "fallback",
372432
// not(portable_atomic_no_outline_atomics),
373-
// any(test, portable_atomic_outline_atomics), // TODO(riscv64): currently disabled by default
433+
// any(test, portable_atomic_outline_atomics), // TODO(riscv): currently disabled by default
374434
// any(
375435
// all(
376436
// target_os = "linux",

src/imp/atomic128/riscv64.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Generated asm:
1818
- riscv64 (+experimental-zacas) https://godbolt.org/z/crdhjKPdq
1919
*/
2020

21-
// TODO: 64-bit atomic using amocas.d for riscv32
22-
2321
include!("macros.rs");
2422

2523
// TODO
@@ -31,7 +29,7 @@ include!("macros.rs");
3129
// See detect/auxv.rs for more.
3230
#[cfg(test)] // TODO
3331
#[cfg(not(portable_atomic_no_outline_atomics))]
34-
#[cfg(any(test, portable_atomic_outline_atomics))] // TODO(riscv64): currently disabled by default
32+
#[cfg(any(test, portable_atomic_outline_atomics))] // TODO(riscv): currently disabled by default
3533
#[cfg(any(
3634
test,
3735
not(any(

0 commit comments

Comments
 (0)