Skip to content

Commit d219ad6

Browse files
authored
Import the asm! macro from core::arch (rust-lang#1265)
1 parent b70ae88 commit d219ad6

File tree

16 files changed

+38
-9
lines changed

16 files changed

+38
-9
lines changed

.github/workflows/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ jobs:
168168
os: ubuntu-latest
169169
- target: thumbv7em-none-eabihf
170170
os: ubuntu-latest
171+
- target: riscv64gc-unknown-linux-gnu
172+
os: ubuntu-latest
171173

172174
steps:
173175
- uses: actions/checkout@master
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ubuntu:21.10
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
gcc libc6-dev qemu-user ca-certificates \
5+
gcc-riscv64-linux-gnu libc6-dev-riscv64-cross \
6+
qemu-user
7+
8+
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \
9+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64 -L /usr/riscv64-linux-gnu" \
10+
OBJDUMP=riscv64-linux-gnu-objdump

ci/run.sh

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ case ${TARGET} in
4444
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon"
4545
export TARGET_CFLAGS="-mfpu=vfpv3-d16"
4646
;;
47+
# Some of our test dependencies use the deprecated `gcc` crates which
48+
# doesn't detect RISC-V compilers automatically, so do it manually here.
49+
riscv64*)
50+
export TARGET_CC="riscv64-linux-gnu-gcc"
51+
;;
4752
esac
4853

4954
echo "RUSTFLAGS=${RUSTFLAGS}"

crates/core_arch/src/aarch64/armclang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ use stdarch_test::assert_instr;
1919
#[rustc_legacy_const_generics(0)]
2020
pub unsafe fn __breakpoint<const VAL: i32>() {
2121
static_assert_imm16!(VAL);
22-
asm!("brk {}", const VAL);
22+
crate::arch::asm!("brk {}", const VAL);
2323
}

crates/core_arch/src/arm/armclang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ use stdarch_test::assert_instr;
3131
#[rustc_legacy_const_generics(0)]
3232
pub unsafe fn __breakpoint<const VAL: i32>() {
3333
static_assert_imm8!(VAL);
34-
asm!("bkpt #{}", const VAL);
34+
crate::arch::asm!("bkpt #{}", const VAL);
3535
}

crates/core_arch/src/arm_shared/barrier/cp15.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Reference: ARM11 MPCore Processor Technical Reference Manual (ARM DDI 0360E) Section 3.5 "Summary
22
// of CP15 instructions"
33

4+
use crate::arch::asm;
5+
46
/// Full system is the required shareability domain, reads and writes are the
57
/// required access types
68
pub struct SY;

crates/core_arch/src/arm_shared/hints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub unsafe fn __yield() {
7777
/// will increase execution time.
7878
#[inline(always)]
7979
pub unsafe fn __nop() {
80-
asm!("nop", options(nomem, nostack, preserves_flags));
80+
crate::arch::asm!("nop", options(nomem, nostack, preserves_flags));
8181
}
8282

8383
extern "unadjusted" {

crates/core_arch/src/arm_shared/registers/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ macro_rules! rsr {
44
impl super::super::sealed::Rsr for $R {
55
unsafe fn __rsr(&self) -> u32 {
66
let r: u32;
7-
asm!(concat!("mrs {},", stringify!($R)), out(reg) r, options(nomem, nostack));
7+
crate::arch::asm!(concat!("mrs {},", stringify!($R)), out(reg) r, options(nomem, nostack));
88
r
99
}
1010
}
@@ -17,7 +17,7 @@ macro_rules! rsrp {
1717
impl super::super::sealed::Rsrp for $R {
1818
unsafe fn __rsrp(&self) -> *const u8 {
1919
let r: *const u8;
20-
asm!(concat!("mrs {},", stringify!($R)), out(reg) r, options(nomem, nostack));
20+
crate::arch::asm!(concat!("mrs {},", stringify!($R)), out(reg) r, options(nomem, nostack));
2121
r
2222
}
2323
}
@@ -29,7 +29,7 @@ macro_rules! wsr {
2929
($R:ident) => {
3030
impl super::super::sealed::Wsr for $R {
3131
unsafe fn __wsr(&self, value: u32) {
32-
asm!(concat!("msr ", stringify!($R), ", {}"), in(reg) value, options(nomem, nostack));
32+
crate::arch::asm!(concat!("msr ", stringify!($R), ", {}"), in(reg) value, options(nomem, nostack));
3333
}
3434
}
3535
};
@@ -40,7 +40,7 @@ macro_rules! wsrp {
4040
($R:ident) => {
4141
impl super::super::sealed::Wsrp for $R {
4242
unsafe fn __wsrp(&self, value: *const u8) {
43-
asm!(concat!("msr ", stringify!($R), ", {}"), in(reg) value, options(nomem, nostack));
43+
crate::arch::asm!(concat!("msr ", stringify!($R), ", {}"), in(reg) value, options(nomem, nostack));
4444
}
4545
}
4646
};

crates/core_arch/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ extern crate std_detect;
6868
#[path = "mod.rs"]
6969
mod core_arch;
7070

71-
pub use self::core_arch::arch;
71+
pub mod arch {
72+
pub use crate::core_arch::arch::*;
73+
pub use core::arch::asm;
74+
}
7275

7376
#[allow(unused_imports)]
7477
use core::{convert, ffi, hint, intrinsics, marker, mem, ops, ptr, sync};

crates/core_arch/src/riscv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/// should be temporarily reduced or paused. The duration of its effect must be bounded and may be zero.
77
#[inline]
88
pub fn pause() {
9-
unsafe { asm!(".word 0x0100000F", options(nomem, nostack)) }
9+
unsafe { crate::arch::asm!(".word 0x0100000F", options(nomem, nostack)) }
1010
}

crates/core_arch/src/x86/avx512bw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
arch::asm,
23
core_arch::{simd::*, simd_llvm::*, x86::*},
34
mem::{self, transmute},
45
ptr,

crates/core_arch/src/x86/avx512f.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
arch::asm,
23
core_arch::{simd::*, simd_llvm::*, x86::*},
34
mem::{self, transmute},
45
ptr,

crates/core_arch/src/x86/bt.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::arch::asm;
12
#[cfg(test)]
23
use stdarch_test::assert_instr;
34

crates/core_arch/src/x86/cpuid.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! `cpuid` intrinsics
22
#![allow(clippy::module_name_repetitions)]
33

4+
use crate::arch::asm;
45
#[cfg(test)]
56
use stdarch_test::assert_instr;
67

crates/core_arch/src/x86/eflags.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! `i386` intrinsics
22
3+
use crate::arch::asm;
4+
35
/// Reads EFLAGS.
46
///
57
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=__readeflags)

crates/core_arch/src/x86_64/bt.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::arch::asm;
12
#[cfg(test)]
23
use stdarch_test::assert_instr;
34

0 commit comments

Comments
 (0)