Skip to content
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
6 changes: 6 additions & 0 deletions .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
abiv
amocas
amoswap
amswap
Expand All @@ -18,10 +19,12 @@ ccmp
cdsg
CDSY
clrex
cmpne
cmpw
cmpxchg
csel
cset
cskyv
dbar
distro
DWCAS
Expand All @@ -44,6 +47,7 @@ ldar
ldarx
ldaxp
ldclrp
ldex
ldiapp
ldrex
ldrexd
Expand Down Expand Up @@ -83,6 +87,7 @@ opensbi
orrs
partword
pstq
pthread
qbsp
quadword
rcpc
Expand All @@ -106,6 +111,7 @@ sreg
srlv
stbar
stdcx
stex
stilp
stlxp
stpq
Expand Down
55 changes: 53 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,29 @@ jobs:
target: armeb-unknown-linux-gnueabi
os: ubuntu-22.04
# ------------------------------------------------------------
# csky-unknown-linux-gnuabiv2
- rust: nightly-2025-02-14 # Rust 1.86, LLVM 19 (oldest version we can use asm_experimental_arch on this target)
target: csky-unknown-linux-gnuabiv2
# +crt-static: Workaround for C-SKY QEMU issue
# ldex/stex requires ck860*
flags: -C target-feature=+crt-static -C target-cpu=ck860
- rust: nightly
target: csky-unknown-linux-gnuabiv2
# +crt-static: Workaround for C-SKY QEMU issue
# ldex/stex requires ck860*
flags: -C target-feature=+crt-static -C target-cpu=ck860
# ------------------------------------------------------------
# csky-unknown-linux-gnuabiv2hf
# TODO: relocations in generic ELF (EM: 252)
# - rust: nightly-2025-02-14 # Rust 1.86, LLVM 19 (oldest version we can use asm_experimental_arch on this target)
# target: csky-unknown-linux-gnuabiv2hf
# # +crt-static: Workaround for C-SKY QEMU issue
# flags: -C target-feature=+crt-static
# - rust: nightly
# target: csky-unknown-linux-gnuabiv2hf
# # +crt-static: Workaround for C-SKY QEMU issue
# flags: -C target-feature=+crt-static
# ------------------------------------------------------------
# hexagon-unknown-linux-musl
- rust: nightly-2024-11-29 # Rust 1.85, LLVM 19 (oldest version we can use asm_experimental_arch on this target)
target: hexagon-unknown-linux-musl
Expand Down Expand Up @@ -510,7 +533,34 @@ jobs:
- uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
if: steps.prepare.outputs.target-not-host == 'true'
if: steps.prepare.outputs.target-not-host == 'true' && !startsWith(matrix.target, 'csky-')
# TODO: not yet supported in setup-cross-toolchain-action
- run: |
retry() {
for i in {1..10}; do
if "$@"; then
return 0
else
sleep "${i}"
fi
done
"$@"
}
target="${{ matrix.target }}"
# https://github.com/taiki-e/rust-cross-toolchain/pkgs/container/rust-cross-toolchain
retry docker create --name gcc-csky-linux-gnuabiv2 "ghcr.io/taiki-e/rust-cross-toolchain:${target}-dev-amd64"
docker cp -- "gcc-csky-linux-gnuabiv2:/${target}" "${HOME}"/gcc-csky-linux-gnuabiv2
docker rm -f -- gcc-csky-linux-gnuabiv2 >/dev/null
printf '%s\n' "${HOME}"/gcc-csky-linux-gnuabiv2/bin >>"${GITHUB_PATH}"
printf '%s\n' "CARGO_TARGET_CSKY_UNKNOWN_LINUX_GNUABIV2_LINKER=csky-abiv2-linux-gcc" >>"${GITHUB_ENV}"
case "${target}" in
*hf) qemu_cpu=ck860fv ;;
# https://github.com/taiki-e/atomic-maybe-uninit/pull/32#issuecomment-3341287749
*) qemu_cpu=ck860 ;;
esac
printf '%s\n' "CARGO_TARGET_CSKY_UNKNOWN_LINUX_GNUABIV2_RUNNER=qemu-cskyv2 -cpu ${qemu_cpu}" >>"${GITHUB_ENV}"
printf 'BUILD_STD=-Z''build-std\n' >>"${GITHUB_ENV}"
if: startsWith(matrix.target, 'csky-')
- run: |
target="${{ matrix.target }}"
target_lower="${target//-/_}"
Expand All @@ -525,7 +575,8 @@ jobs:
if: matrix.flags != ''
- run: printf '%s\n' "RUSTFLAGS=${RUSTFLAGS} -D linker_messages" >>"${GITHUB_ENV}"
# TODO(macos): error: linker stderr: ld: ignoring duplicate libraries: '-lc', '-lm'
if: matrix.rust == 'nightly' && !contains(matrix.target, '-darwin')
# TODO(csky): error: linker stderr: /home/runner/gcc-csky-linux-gnuabiv2/bin/../lib/gcc/csky-linux-gnuabiv2/6.3.0/../../../../csky-linux-gnuabiv2/bin/ld: file ....o's arch flag ck860 conflict with target ck810,set target arch flag to ck860
if: matrix.rust == 'nightly' && !(contains(matrix.target, '-darwin') || matrix.target == 'csky-unknown-linux-gnuabiv2')
# Old LLVM bug: Undefined temporary symbol error when building std.
- name: Workaround for old LLVM bug about MIPS32
run: printf 'RELEASE=--release\n' >>"${GITHUB_ENV}"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ doc-scrape-examples = false
[dev-dependencies]
fastrand = "2"
paste = "1"
quickcheck = { version = "1", default-features = false, git = "https://github.com/taiki-e/quickcheck.git", rev = "83b1d59" } # https://github.com/BurntSushi/quickcheck/pull/304 + https://github.com/BurntSushi/quickcheck/pull/282 + https://github.com/BurntSushi/quickcheck/pull/296 + f16/f128 support + lower MSRV
quickcheck = { version = "1", default-features = false, git = "https://github.com/taiki-e/quickcheck.git", rev = "f0c7237" } # https://github.com/BurntSushi/quickcheck/pull/304 + https://github.com/BurntSushi/quickcheck/pull/282 + https://github.com/BurntSushi/quickcheck/pull/296 + rand -> fastrand + lower MSRV

[target.'cfg(valgrind)'.dev-dependencies]
crabgrind = "0.1"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This crate provides a way to soundly perform such operations.

## Platform Support

Currently, x86, x86_64, Arm, AArch64, RISC-V, LoongArch, Arm64EC, s390x, MIPS, PowerPC, MSP430, AVR, SPARC, Hexagon, M68k, and Xtensa are supported.
Currently, x86, x86_64, Arm, AArch64, RISC-V, LoongArch, Arm64EC, s390x, MIPS, PowerPC, MSP430, AVR, SPARC, Hexagon, M68k, C-SKY, and Xtensa are supported.
(You can use `cfg_{has,no}_*` macros to write code based on whether or not which size of primitives is available.)

| target_arch | primitives | load/store | swap/CAS |
Expand Down Expand Up @@ -50,9 +50,10 @@ Currently, x86, x86_64, Arm, AArch64, RISC-V, LoongArch, Arm64EC, s390x, MIPS, P
| hexagon \[9] (experimental) | isize,usize,i8,u8,i16,u16,i32,u32,i64,u64 | ✓ | ✓ |
| m68k \[9] (experimental) | isize,usize,i8,u8,i16,u16,i32,u32 | ✓ | ✓\[1] |
| m68k (+isa-68020) \[9] \[10] (experimental) | i64,u64 | ✓ | ✓ |
| csky \[9] (experimental) | isize,usize,i8,u8,i16,u16,i32,u32 | ✓ | ✓\[1] |
| xtensa \[9] (experimental) | isize,usize,i8,u8,i16,u16,i32,u32 | ✓ | ✓\[1] |

\[1] Arm's atomic RMW operations are not available on Armv6-M (thumbv6m). RISC-V's atomic RMW operations are not available on targets without the A (or G which means IMAFD) or Zalrsc or Zacas extension, such as riscv32i, riscv32imc, etc. M68k's atomic RMW operations requires target-cpu M68020+ (enabled by default on Linux). Xtensa's atomic RMW operations are not available on esp32s2.<br>
\[1] Arm's atomic RMW operations are not available on Armv6-M (thumbv6m). RISC-V's atomic RMW operations are not available on targets without the A (or G which means IMAFD) or Zalrsc or Zacas extension, such as riscv32i, riscv32imc, etc. M68k's atomic RMW operations requires target-cpu M68020+ (enabled by default on Linux). C-SKY's atomic RMW operations requires target-cpu ck860\* (enabled by default on the hard-float target). Xtensa's atomic RMW operations are not available on esp32s2.<br>
\[2] Requires `cmpxchg16b` target feature (enabled by default on Apple, Windows (except Windows 7), and Fuchsia targets).<br>
\[3] Armv6+ or Linux/Android, except for M-profile architecture such as thumbv6m, thumbv7m, etc.<br>
\[4] Requires `zacas` target feature.<br>
Expand Down
28 changes: 27 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
// Custom cfgs set by build script. Not public API.
// grep -F 'cargo:rustc-cfg=' build.rs | grep -Ev '^ *//' | sed -E 's/^.*cargo:rustc-cfg=//; s/(=\\)?".*$//' | LC_ALL=C sort -u | tr '\n' ',' | sed -E 's/,$/\n/'
println!(
"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_no_asm,atomic_maybe_uninit_no_cmpxchg,atomic_maybe_uninit_no_cmpxchg8b,atomic_maybe_uninit_no_const_mut_refs,atomic_maybe_uninit_no_diagnostic_namespace,atomic_maybe_uninit_no_strict_provenance,atomic_maybe_uninit_no_sync,atomic_maybe_uninit_pre_llvm_20,atomic_maybe_uninit_target_feature,atomic_maybe_uninit_unstable_asm_experimental_arch)"
"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_no_asm,atomic_maybe_uninit_no_cmpxchg,atomic_maybe_uninit_no_cmpxchg8b,atomic_maybe_uninit_no_const_mut_refs,atomic_maybe_uninit_no_diagnostic_namespace,atomic_maybe_uninit_no_ldex_stex,atomic_maybe_uninit_no_strict_provenance,atomic_maybe_uninit_no_sync,atomic_maybe_uninit_pre_llvm_20,atomic_maybe_uninit_target_feature,atomic_maybe_uninit_unstable_asm_experimental_arch)"
);
// TODO: handle multi-line target_feature_fallback
// grep -F 'target_feature_fallback("' build.rs | grep -Ev '^ *//' | sed -E 's/^.*target_feature_fallback\(//; s/",.*$/"/' | LC_ALL=C sort -u | tr '\n' ',' | sed -E 's/,$/\n/'
Expand Down Expand Up @@ -118,6 +118,15 @@ fn main() {
println!("cargo:rustc-cfg=atomic_maybe_uninit_unstable_asm_experimental_arch");
}
}
"csky" => {
// https://github.com/rust-lang/rust/pull/136217 merged in Rust 1.86 (nightly-2025-02-14).
if version.nightly
&& version.probe(86, 2025, 2, 13)
&& is_allowed_feature("asm_experimental_arch")
{
println!("cargo:rustc-cfg=atomic_maybe_uninit_unstable_asm_experimental_arch");
}
}
"hexagon" => {
// https://github.com/rust-lang/rust/pull/133452 merged in Rust 1.85 (nightly-2024-11-29).
if version.nightly
Expand Down Expand Up @@ -501,6 +510,23 @@ fn main() {
}
target_feature_fallback("rmw", xmegau);
}
"csky" => {
let mut no_ldex_stex = true;
if let Some(cpu) = target_cpu() {
// https://github.com/llvm/llvm-project/blob/llvmorg-21.1.0/llvm/lib/Target/CSKY/CSKY.td#L373
if cpu.starts_with("ck860") {
no_ldex_stex = false;
}
} else {
// https://github.com/rust-lang/rust/blob/1.90.0/compiler/rustc_target/src/spec/targets/csky_unknown_linux_gnuabiv2hf.rs#L20
if target == "csky-unknown-linux-gnuabiv2hf" {
no_ldex_stex = false;
}
}
if no_ldex_stex {
println!("cargo:rustc-cfg=atomic_maybe_uninit_no_ldex_stex");
}
}
_ => {}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/arch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This document describes the operations that are considered atomic by architectur
- [AArch64](#aarch64)
- [Arm](#arm)
- [AVR](#avr)
- [C-SKY](#c-sky)
- [Hexagon](#hexagon)
- [LoongArch](#loongarch)
- [M68k](#m68k)
Expand Down Expand Up @@ -61,6 +62,13 @@ This architecture is always single-core and the following operations are atomic:
disabling and restoring implementation must imply compiler fences, e.g., asm without nomem/readonly)
may be moved out of the critical section by compiler optimizations.

## C-SKY

target_arch: csky<br>
Implementation: [csky.rs](csky.rs)<br>

TODO: reference and overview

## Hexagon

target_arch: hexagon<br>
Expand Down
Loading
Loading