Skip to content

Commit 2e854a9

Browse files
committed
Auto merge of rust-lang#150357 - ZuseZ4:zusez4-stdarch-push, r=sayantan
stdarch subtree update Subtree update of `stdarch` to rust-lang/stdarch@6111906. Created using https://github.com/rust-lang/josh-sync. r? `@sayantn` My first josh sync, it lgtm, but let me know if I missed something. I'm especially looking forward to the amd GPU module, which we want to use for the offload project.
2 parents 4c383cd + 6f06d38 commit 2e854a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+13945
-9668
lines changed

library/compiler-builtins/libm/src/math/arch/x86/detect.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn load_x86_features() -> Flags {
5757
// (in that order)
5858
let mut vendor_id = [0u8; 12];
5959
let max_basic_leaf;
60-
unsafe {
60+
{
6161
let CpuidResult { eax, ebx, ecx, edx } = __cpuid(0);
6262
max_basic_leaf = eax;
6363
vendor_id[0..4].copy_from_slice(&ebx.to_ne_bytes());
@@ -72,7 +72,7 @@ fn load_x86_features() -> Flags {
7272

7373
// EAX = 1, ECX = 0: Queries "Processor Info and Feature Bits";
7474
// Contains information about most x86 features.
75-
let CpuidResult { ecx, edx, .. } = unsafe { __cpuid(0x0000_0001_u32) };
75+
let CpuidResult { ecx, edx, .. } = __cpuid(0x0000_0001_u32);
7676
let proc_info_ecx = Flags::from_bits(ecx);
7777
let proc_info_edx = Flags::from_bits(edx);
7878

@@ -82,23 +82,23 @@ fn load_x86_features() -> Flags {
8282
let mut extended_features_edx = Flags::empty();
8383
let mut extended_features_eax_leaf_1 = Flags::empty();
8484
if max_basic_leaf >= 7 {
85-
let CpuidResult { ebx, edx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
85+
let CpuidResult { ebx, edx, .. } = __cpuid(0x0000_0007_u32);
8686
extended_features_ebx = Flags::from_bits(ebx);
8787
extended_features_edx = Flags::from_bits(edx);
8888

89-
let CpuidResult { eax, .. } = unsafe { __cpuid_count(0x0000_0007_u32, 0x0000_0001_u32) };
89+
let CpuidResult { eax, .. } = __cpuid_count(0x0000_0007_u32, 0x0000_0001_u32);
9090
extended_features_eax_leaf_1 = Flags::from_bits(eax)
9191
}
9292

9393
// EAX = 0x8000_0000, ECX = 0: Get Highest Extended Function Supported
9494
// - EAX returns the max leaf value for extended information, that is,
9595
// `cpuid` calls in range [0x8000_0000; u32::MAX]:
96-
let extended_max_basic_leaf = unsafe { __cpuid(0x8000_0000_u32) }.eax;
96+
let extended_max_basic_leaf = __cpuid(0x8000_0000_u32).eax;
9797

9898
// EAX = 0x8000_0001, ECX=0: Queries "Extended Processor Info and Feature Bits"
9999
let mut extended_proc_info_ecx = Flags::empty();
100100
if extended_max_basic_leaf >= 1 {
101-
let CpuidResult { ecx, .. } = unsafe { __cpuid(0x8000_0001_u32) };
101+
let CpuidResult { ecx, .. } = __cpuid(0x8000_0001_u32);
102102
extended_proc_info_ecx = Flags::from_bits(ecx);
103103
}
104104

library/std/src/sys/pal/uefi/time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub(crate) mod instant_internal {
356356
// Inspired by [`edk2/UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c`](https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c)
357357
let freq = FREQUENCY
358358
.get_or_try_init(|| {
359-
let cpuid = unsafe { crate::arch::x86_64::__cpuid(0x15) };
359+
let cpuid = crate::arch::x86_64::__cpuid(0x15);
360360
if cpuid.eax == 0 || cpuid.ebx == 0 || cpuid.ecx == 0 {
361361
return Err(());
362362
}
@@ -375,7 +375,7 @@ pub(crate) mod instant_internal {
375375

376376
let freq = FREQUENCY
377377
.get_or_try_init(|| {
378-
let cpuid = unsafe { crate::arch::x86::__cpuid(0x15) };
378+
let cpuid = crate::arch::x86::__cpuid(0x15);
379379
if cpuid.eax == 0 || cpuid.ebx == 0 || cpuid.ecx == 0 {
380380
return Err(());
381381
}

library/std/src/sys/random/uefi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ mod rdrand {
107107
{
108108
// SAFETY: All Rust x86 targets are new enough to have CPUID, and we
109109
// check that leaf 1 is supported before using it.
110-
let cpuid0 = unsafe { arch::__cpuid(0) };
110+
let cpuid0 = arch::__cpuid(0);
111111
if cpuid0.eax < 1 {
112112
return false;
113113
}
114-
let cpuid1 = unsafe { arch::__cpuid(1) };
114+
let cpuid1 = arch::__cpuid(1);
115115

116116
let vendor_id =
117117
[cpuid0.ebx.to_le_bytes(), cpuid0.edx.to_le_bytes(), cpuid0.ecx.to_le_bytes()];

library/std_detect/src/detect/os/x86.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ pub(crate) fn detect_features() -> cache::Initializer {
4040
// leaf value for subsequent calls of `cpuinfo` in range [0,
4141
// 0x8000_0000]. - The vendor ID is stored in 12 u8 ascii chars,
4242
// returned in EBX, EDX, and ECX (in that order):
43-
let (max_basic_leaf, vendor_id) = unsafe {
43+
let (max_basic_leaf, vendor_id) = {
4444
let CpuidResult { eax: max_basic_leaf, ebx, ecx, edx } = __cpuid(0);
4545
let vendor_id: [[u8; 4]; 3] = [ebx.to_ne_bytes(), edx.to_ne_bytes(), ecx.to_ne_bytes()];
46-
let vendor_id: [u8; 12] = mem::transmute(vendor_id);
46+
let vendor_id: [u8; 12] = unsafe { mem::transmute(vendor_id) };
4747
(max_basic_leaf, vendor_id)
4848
};
4949

@@ -54,8 +54,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
5454

5555
// EAX = 1, ECX = 0: Queries "Processor Info and Feature Bits";
5656
// Contains information about most x86 features.
57-
let CpuidResult { ecx: proc_info_ecx, edx: proc_info_edx, .. } =
58-
unsafe { __cpuid(0x0000_0001_u32) };
57+
let CpuidResult { ecx: proc_info_ecx, edx: proc_info_edx, .. } = __cpuid(0x0000_0001_u32);
5958

6059
// EAX = 7: Queries "Extended Features";
6160
// Contains information about bmi,bmi2, and avx2 support.
@@ -66,9 +65,9 @@ pub(crate) fn detect_features() -> cache::Initializer {
6665
extended_features_eax_leaf_1,
6766
extended_features_edx_leaf_1,
6867
) = if max_basic_leaf >= 7 {
69-
let CpuidResult { ebx, ecx, edx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
68+
let CpuidResult { ebx, ecx, edx, .. } = __cpuid(0x0000_0007_u32);
7069
let CpuidResult { eax: eax_1, edx: edx_1, .. } =
71-
unsafe { __cpuid_count(0x0000_0007_u32, 0x0000_0001_u32) };
70+
__cpuid_count(0x0000_0007_u32, 0x0000_0001_u32);
7271
(ebx, ecx, edx, eax_1, edx_1)
7372
} else {
7473
(0, 0, 0, 0, 0) // CPUID does not support "Extended Features"
@@ -77,12 +76,12 @@ pub(crate) fn detect_features() -> cache::Initializer {
7776
// EAX = 0x8000_0000, ECX = 0: Get Highest Extended Function Supported
7877
// - EAX returns the max leaf value for extended information, that is,
7978
// `cpuid` calls in range [0x8000_0000; u32::MAX]:
80-
let CpuidResult { eax: extended_max_basic_leaf, .. } = unsafe { __cpuid(0x8000_0000_u32) };
79+
let CpuidResult { eax: extended_max_basic_leaf, .. } = __cpuid(0x8000_0000_u32);
8180

8281
// EAX = 0x8000_0001, ECX=0: Queries "Extended Processor Info and Feature
8382
// Bits"
8483
let extended_proc_info_ecx = if extended_max_basic_leaf >= 1 {
85-
let CpuidResult { ecx, .. } = unsafe { __cpuid(0x8000_0001_u32) };
84+
let CpuidResult { ecx, .. } = __cpuid(0x8000_0001_u32);
8685
ecx
8786
} else {
8887
0
@@ -132,7 +131,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
132131

133132
// Detect if CPUID.19h available
134133
if bit::test(extended_features_ecx as usize, 23) {
135-
let CpuidResult { ebx, .. } = unsafe { __cpuid(0x19) };
134+
let CpuidResult { ebx, .. } = __cpuid(0x19);
136135
enable(ebx, 0, Feature::kl);
137136
enable(ebx, 2, Feature::widekl);
138137
}
@@ -223,7 +222,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
223222
// ECX = 1):
224223
if max_basic_leaf >= 0xd {
225224
let CpuidResult { eax: proc_extended_state1_eax, .. } =
226-
unsafe { __cpuid_count(0xd_u32, 1) };
225+
__cpuid_count(0xd_u32, 1);
227226
enable(proc_extended_state1_eax, 0, Feature::xsaveopt);
228227
enable(proc_extended_state1_eax, 1, Feature::xsavec);
229228
enable(proc_extended_state1_eax, 3, Feature::xsaves);
@@ -282,7 +281,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
282281

283282
if max_basic_leaf >= 0x1e {
284283
let CpuidResult { eax: amx_feature_flags_eax, .. } =
285-
unsafe { __cpuid_count(0x1e_u32, 1) };
284+
__cpuid_count(0x1e_u32, 1);
286285

287286
enable(amx_feature_flags_eax, 4, Feature::amx_fp8);
288287
enable(amx_feature_flags_eax, 6, Feature::amx_tf32);
@@ -297,7 +296,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
297296

298297
let avx10_1 = enable(extended_features_edx_leaf_1, 19, Feature::avx10_1);
299298
if avx10_1 {
300-
let CpuidResult { ebx, .. } = unsafe { __cpuid(0x24) };
299+
let CpuidResult { ebx, .. } = __cpuid(0x24);
301300
let avx10_version = ebx & 0xff;
302301
if avx10_version >= 2 {
303302
value.set(Feature::avx10_2 as u32);

library/stdarch/.github/workflows/main.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ jobs:
8484
os: ubuntu-latest
8585
- tuple: nvptx64-nvidia-cuda
8686
os: ubuntu-latest
87+
- tuple: amdgcn-amd-amdhsa
88+
os: ubuntu-latest
8789
- tuple: thumbv6m-none-eabi
8890
os: ubuntu-latest
8991
- tuple: thumbv7m-none-eabi
@@ -201,6 +203,10 @@ jobs:
201203
tuple: aarch64-apple-ios-macabi
202204
os: macos-15
203205
norun: true # https://github.com/rust-lang/stdarch/issues/1206
206+
- target:
207+
tuple: amdgcn-amd-amdhsa
208+
os: ubuntu-latest
209+
norun: true
204210

205211
steps:
206212
- uses: actions/checkout@v4
@@ -212,15 +218,20 @@ jobs:
212218

213219
- run: rustup target add ${{ matrix.target.tuple }}
214220
shell: bash
215-
if: matrix.build_std == ''
221+
if: matrix.build_std == '' && matrix.target.tuple != 'amdgcn-amd-amdhsa'
216222
- run: |
217223
rustup component add rust-src
218224
echo "CARGO_UNSTABLE_BUILD_STD=std" >> $GITHUB_ENV
219225
shell: bash
220226
if: matrix.build_std != ''
227+
- run: |
228+
rustup component add rust-src
229+
echo "CARGO_UNSTABLE_BUILD_STD=core,alloc" >> $GITHUB_ENV
230+
shell: bash
231+
if: matrix.target.tuple == 'amdgcn-amd-amdhsa'
221232
222233
# Configure some env vars based on matrix configuration
223-
- run: echo "PROFILE=--profile=${{matrix.profile}}" >> $GITHUB_ENV
234+
- run: echo "PROFILE=${{matrix.profile}}" >> $GITHUB_ENV
224235
shell: bash
225236
- run: echo "NORUN=1" >> $GITHUB_ENV
226237
shell: bash
@@ -233,7 +244,7 @@ jobs:
233244
if: matrix.disable_assert_instr != ''
234245
- run: echo "NOSTD=1" >> $GITHUB_ENV
235246
shell: bash
236-
if: startsWith(matrix.target.tuple, 'thumb') || matrix.target.tuple == 'nvptx64-nvidia-cuda'
247+
if: startsWith(matrix.target.tuple, 'thumb') || matrix.target.tuple == 'nvptx64-nvidia-cuda' || matrix.target.tuple == 'amdgcn-amd-amdhsa'
237248

238249
# Windows & OSX go straight to `run.sh` ...
239250
- run: ./ci/run.sh
@@ -280,7 +291,7 @@ jobs:
280291
if: ${{ matrix.build_std }}
281292
282293
# Configure some env vars based on matrix configuration
283-
- run: echo "PROFILE=--profile=${{ matrix.profile }}" >> $GITHUB_ENV
294+
- run: echo "PROFILE=${{ matrix.profile }}" >> $GITHUB_ENV
284295
- run: ./ci/intrinsic-test-docker.sh ${{ matrix.target }}
285296
if: ${{ !startsWith(matrix.target, 'thumb') }}
286297
env:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ubuntu:25.10
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
gcc \
4+
libc6-dev \
5+
ca-certificates

library/stdarch/ci/docker/wasm32-wasip1/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ ENV VERSION=v38.0.3
1111

1212
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/${VERSION}/wasmtime-${VERSION}-x86_64-linux.tar.xz | tar xJf -
1313
ENV PATH=$PATH:/wasmtime-${VERSION}-x86_64-linux
14-
15-
ENV CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime -Wexceptions --dir /checkout/target/wasm32-wasip1/release/deps::."

library/stdarch/ci/dox.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ dox() {
1515

1616
cargo clean --target "${1}"
1717

18+
if [ "${1}" == "amdgcn-amd-amdhsa" ]; then
19+
if [ "$CI" != "" ]; then
20+
rustup component add rust-src
21+
fi
22+
export CARGO_UNSTABLE_BUILD_STD=core
23+
# amdgpu needs a target-cpu, any is fine
24+
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-cpu=gfx900"
25+
fi
26+
1827
cargo build --verbose --target "${1}" --manifest-path crates/core_arch/Cargo.toml
1928
cargo doc --verbose --target "${1}" --manifest-path crates/core_arch/Cargo.toml
2029
}
@@ -33,6 +42,7 @@ if [ -z "$1" ]; then
3342
#dox mips64-unknown-linux-gnuabi64
3443
dox wasm32-unknown-unknown
3544
dox nvptx64-nvidia-cuda
45+
dox amdgcn-amd-amdhsa
3646
else
3747
dox "${1}"
3848
fi

library/stdarch/ci/intrinsic-test-docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ run() {
3030
--env CARGO_HOME=/cargo \
3131
--env CARGO_TARGET_DIR=/checkout/target \
3232
--env TARGET="${1}" \
33+
--env PROFILE \
3334
--env "${HOST_LINKER}"="cc" \
3435
--env STDARCH_DISABLE_ASSERT_INSTR \
3536
--env NOSTD \

library/stdarch/ci/intrinsic-test.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -ex
66

77
export RUSTFLAGS="${RUSTFLAGS} -D warnings -Z merge-functions=disabled -Z verify-llvm-ir"
88
export HOST_RUSTFLAGS="${RUSTFLAGS}"
9-
export PROFILE="${PROFILE:="--profile=release"}"
9+
export PROFILE="${PROFILE:="release"}"
1010

1111
case ${TARGET} in
1212
# On 32-bit use a static relocation model which avoids some extra
@@ -56,7 +56,7 @@ case ${TARGET} in
5656

5757
aarch64_be-unknown-linux-gnu*)
5858
TEST_CPPFLAGS="-fuse-ld=lld"
59-
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
59+
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64_be.txt
6060
TEST_CXX_COMPILER="clang++"
6161
TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}"
6262
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=100}"
@@ -75,7 +75,7 @@ case ${TARGET} in
7575
TEST_CXX_COMPILER="clang++"
7676
TEST_RUNNER="${CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER}"
7777
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_x86.txt
78-
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=5}"
78+
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=20}"
7979
;;
8080
*)
8181
;;
@@ -85,27 +85,29 @@ esac
8585
# Arm specific
8686
case "${TARGET}" in
8787
aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*)
88-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=info \
89-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
88+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
89+
cargo run "${INTRINSIC_TEST}" --release \
9090
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
9191
--runner "${TEST_RUNNER}" \
9292
--cppcompiler "${TEST_CXX_COMPILER}" \
9393
--skip "${TEST_SKIP_INTRINSICS}" \
9494
--target "${TARGET}" \
95+
--profile "${PROFILE}" \
9596
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
9697
;;
9798

9899
aarch64_be-unknown-linux-gnu*)
99-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=info \
100-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
100+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
101+
cargo run "${INTRINSIC_TEST}" --release \
101102
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
102103
--runner "${TEST_RUNNER}" \
103104
--cppcompiler "${TEST_CXX_COMPILER}" \
104105
--skip "${TEST_SKIP_INTRINSICS}" \
105106
--target "${TARGET}" \
106-
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}" \
107+
--profile "${PROFILE}" \
107108
--linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \
108-
--cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}"
109+
--cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}" \
110+
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
109111
;;
110112

111113
x86_64-unknown-linux-gnu*)
@@ -114,13 +116,14 @@ case "${TARGET}" in
114116
# Hence the use of `env -u`.
115117
env -u CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER \
116118
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" \
117-
RUST_LOG=info RUST_BACKTRACE=1 \
118-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
119+
RUST_LOG=warn RUST_BACKTRACE=1 \
120+
cargo run "${INTRINSIC_TEST}" --release \
119121
--bin intrinsic-test -- intrinsics_data/x86-intel.xml \
120122
--runner "${TEST_RUNNER}" \
121123
--skip "${TEST_SKIP_INTRINSICS}" \
122124
--cppcompiler "${TEST_CXX_COMPILER}" \
123125
--target "${TARGET}" \
126+
--profile "${PROFILE}" \
124127
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
125128
;;
126129
*)

0 commit comments

Comments
 (0)