Skip to content

Commit 3fd6dd1

Browse files
authored
[DRAFT] intrinsics for all architectures appear in rustdoc (#1104)
1 parent 96f0066 commit 3fd6dd1

35 files changed

+1676
-1619
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! ARM compiler specific intrinsics
2+
//!
3+
//! # References
4+
//!
5+
//! - [ARM Compiler v 6.10 - armclang Reference Guide][arm_comp_ref]
6+
//!
7+
//! [arm_comp_ref]: https://developer.arm.com/docs/100067/0610
8+
9+
#[cfg(test)]
10+
use stdarch_test::assert_instr;
11+
12+
/// Inserts a breakpoint instruction.
13+
///
14+
/// `VAL` is a compile-time constant integer in range `[0, 65535]`.
15+
///
16+
/// The breakpoint instruction inserted is `BRK` on A64.
17+
#[cfg_attr(test, assert_instr(brk, VAL = 0))]
18+
#[inline(always)]
19+
#[rustc_legacy_const_generics(0)]
20+
pub unsafe fn __breakpoint<const VAL: i32>() {
21+
static_assert_imm16!(VAL);
22+
asm!("brk {}", const VAL);
23+
}

crates/core_arch/src/aarch64/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ pub use self::crc::*;
2121
mod prefetch;
2222
pub use self::prefetch::*;
2323

24-
pub use super::acle::*;
24+
pub use super::arm_shared::*;
25+
26+
mod armclang;
27+
28+
pub use self::armclang::*;
2529

2630
#[cfg(test)]
2731
use stdarch_test::assert_instr;

crates/core_arch/src/aarch64/neon/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::generated::*;
1010
// FIXME: replace neon with asimd
1111

1212
use crate::{
13-
core_arch::{arm::*, simd::*, simd_llvm::*},
13+
core_arch::{arm_shared::*, simd::*, simd_llvm::*},
1414
hint::unreachable_unchecked,
1515
mem::{transmute, zeroed},
1616
};
@@ -2812,7 +2812,7 @@ pub unsafe fn vsriq_n_p16<const N: i32>(a: poly16x8_t, b: poly16x8_t) -> poly16x
28122812
#[cfg(test)]
28132813
mod tests {
28142814
use crate::core_arch::aarch64::test_support::*;
2815-
use crate::core_arch::arm::test_support::*;
2815+
use crate::core_arch::arm_shared::test_support::*;
28162816
use crate::core_arch::{aarch64::neon::*, aarch64::*, simd::*};
28172817
use std::mem::transmute;
28182818
use stdarch_test::simd_test;
@@ -4261,13 +4261,13 @@ mod tests {
42614261

42624262
#[cfg(test)]
42634263
#[cfg(target_endian = "little")]
4264-
#[path = "../../arm/neon/table_lookup_tests.rs"]
4264+
#[path = "../../arm_shared/neon/table_lookup_tests.rs"]
42654265
mod table_lookup_tests;
42664266

42674267
#[cfg(test)]
4268-
#[path = "../../arm/neon/shift_and_insert_tests.rs"]
4268+
#[path = "../../arm_shared/neon/shift_and_insert_tests.rs"]
42694269
mod shift_and_insert_tests;
42704270

42714271
#[cfg(test)]
4272-
#[path = "../../arm/neon/load_tests.rs"]
4272+
#[path = "../../arm_shared/neon/load_tests.rs"]
42734273
mod load_tests;

crates/core_arch/src/aarch64/test_support.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::core_arch::{aarch64::neon::*, arm::*, simd::*};
1+
use crate::core_arch::{aarch64::neon::*, arm_shared::*, simd::*};
22
use std::{i16, i32, i8, mem::transmute, u16, u32, u8, vec::Vec};
33

44
macro_rules! V_u64 {

crates/core_arch/src/arm/armclang.rs

-16
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@
99
#[cfg(test)]
1010
use stdarch_test::assert_instr;
1111

12-
/// Inserts a breakpoint instruction.
13-
///
14-
/// `VAL` is a compile-time constant integer in range `[0, 65535]`.
15-
///
16-
/// The breakpoint instruction inserted is `BRK` on A64.
17-
#[cfg(all(target_arch = "aarch64", not(doc)))]
18-
#[cfg_attr(test, assert_instr(brk, VAL = 0))]
19-
#[inline(always)]
20-
#[rustc_legacy_const_generics(0)]
21-
pub unsafe fn __breakpoint<const VAL: i32>() {
22-
static_assert_imm16!(VAL);
23-
asm!("brk {}", const VAL);
24-
}
25-
2612
/// Inserts a breakpoint instruction.
2713
///
2814
/// `VAL` is a compile-time constant integer in range `[0, 255]`.
@@ -40,8 +26,6 @@ pub unsafe fn __breakpoint<const VAL: i32>() {
4026
/// The current implementation only accepts values in range `[0, 255]`.
4127
///
4228
/// [arm_docs]: https://developer.arm.com/docs/100067/latest/compiler-specific-intrinsics/__breakpoint-intrinsic
43-
#[cfg(any(target_arch = "arm", doc))]
44-
#[doc(cfg(target_arch = "arm"))]
4529
#[cfg_attr(test, assert_instr(bkpt, VAL = 0))]
4630
#[inline(always)]
4731
#[rustc_legacy_const_generics(0)]
File renamed without changes.

crates/core_arch/src/acle/ex.rs renamed to crates/core_arch/src/arm/ex.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#[cfg(any(
99
all(target_feature = "v6k", not(target_feature = "mclass")), // excludes v6-M
1010
all(target_feature = "v7", target_feature = "mclass"), // v7-M
11+
doc
1112
))]
1213
pub unsafe fn __clrex() {
1314
extern "C" {
@@ -21,9 +22,10 @@ pub unsafe fn __clrex() {
2122
/// Executes a exclusive LDR instruction for 8 bit value.
2223
// Supported: v6K, v7-M, v7-A, v7-R
2324
// Not supported: v5, v6, v6-M
24-
#[cfg(
25+
#[cfg(any(
2526
target_feature = "v6k", // includes v7-M but excludes v6-M
26-
)]
27+
doc
28+
))]
2729
pub unsafe fn __ldrexb(p: *const u8) -> u8 {
2830
extern "C" {
2931
#[link_name = "llvm.arm.ldrex.p0i8"]
@@ -36,9 +38,10 @@ pub unsafe fn __ldrexb(p: *const u8) -> u8 {
3638
/// Executes a exclusive LDR instruction for 16 bit value.
3739
// Supported: v6K, v7-M, v7-A, v7-R, v8
3840
// Not supported: v5, v6, v6-M
39-
#[cfg(
41+
#[cfg(any(
4042
target_feature = "v6k", // includes v7-M but excludes v6-M
41-
)]
43+
doc
44+
))]
4245
pub unsafe fn __ldrexh(p: *const u16) -> u16 {
4346
extern "C" {
4447
#[link_name = "llvm.arm.ldrex.p0i16"]
@@ -54,6 +57,7 @@ pub unsafe fn __ldrexh(p: *const u16) -> u16 {
5457
#[cfg(any(
5558
all(target_feature = "v6", not(target_feature = "mclass")), // excludes v6-M
5659
all(target_feature = "v7", target_feature = "mclass"), // v7-M
60+
doc
5761
))]
5862
pub unsafe fn __ldrex(p: *const u32) -> u32 {
5963
extern "C" {
@@ -69,9 +73,10 @@ pub unsafe fn __ldrex(p: *const u32) -> u32 {
6973
/// Returns `0` if the operation succeeded, or `1` if it failed
7074
// supported: v6K, v7-M, v7-A, v7-R
7175
// Not supported: v5, v6, v6-M
72-
#[cfg(
76+
#[cfg(any(
7377
target_feature = "v6k", // includes v7-M but excludes v6-M
74-
)]
78+
doc
79+
))]
7580
pub unsafe fn __strexb(value: u32, addr: *mut u8) -> u32 {
7681
extern "C" {
7782
#[link_name = "llvm.arm.strex.p0i8"]
@@ -86,9 +91,11 @@ pub unsafe fn __strexb(value: u32, addr: *mut u8) -> u32 {
8691
/// Returns `0` if the operation succeeded, or `1` if it failed
8792
// Supported: v6K, v7-M, v7-A, v7-R, v8
8893
// Not supported: v5, v6, v6-M
89-
#[cfg(
94+
#[cfg(target_feature = "aarch64")]
95+
#[cfg(any(
9096
target_feature = "v6k", // includes v7-M but excludes v6-M
91-
)]
97+
doc
98+
))]
9299
pub unsafe fn __strexh(value: u16, addr: *mut u16) -> u32 {
93100
extern "C" {
94101
#[link_name = "llvm.arm.strex.p0i16"]
@@ -106,6 +113,7 @@ pub unsafe fn __strexh(value: u16, addr: *mut u16) -> u32 {
106113
#[cfg(any(
107114
all(target_feature = "v6", not(target_feature = "mclass")), // excludes v6-M
108115
all(target_feature = "v7", target_feature = "mclass"), // v7-M
116+
doc
109117
))]
110118
pub unsafe fn __strex(value: u32, addr: *mut u32) -> u32 {
111119
extern "C" {

crates/core_arch/src/arm/mod.rs

+83-22
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,81 @@
55
//!
66
//! [arm_ref]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0073a/IHI0073A_arm_neon_intrinsics_ref.pdf
77
//! [arm_dat]: https://developer.arm.com/technologies/neon/intrinsics
8-
#![allow(non_camel_case_types)]
98
109
mod armclang;
11-
1210
pub use self::armclang::*;
1311

1412
mod v6;
1513
pub use self::v6::*;
1614

17-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
18-
mod v7;
19-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
20-
pub use self::v7::*;
15+
// Supported arches: 6, 7-M. See Section 10.1 of ACLE (e.g. SSAT)
16+
#[cfg(any(target_feature = "v6", doc))]
17+
mod sat;
18+
19+
#[cfg(any(target_feature = "v6", doc))]
20+
pub use self::sat::*;
21+
22+
// Supported arches: 5TE, 7E-M. See Section 10.1 of ACLE (e.g. QADD)
23+
// We also include the A profile even though DSP is deprecated on that profile as of ACLE 2.0 (see
24+
// section 5.4.7)
25+
// Here we workaround the difference between LLVM's +dsp and ACLE's __ARM_FEATURE_DSP by gating on
26+
// '+v5te' rather than on '+dsp'
27+
#[cfg(any(
28+
// >= v5TE but excludes v7-M
29+
all(target_feature = "v5te", not(target_feature = "mclass")),
30+
// v7E-M
31+
all(target_feature = "mclass", target_feature = "dsp"),
32+
doc,
33+
))]
34+
pub mod dsp;
35+
36+
#[cfg(any(
37+
// >= v5TE but excludes v7-M
38+
all(target_feature = "v5te", not(target_feature = "mclass")),
39+
// v7E-M
40+
all(target_feature = "mclass", target_feature = "dsp"),
41+
doc,
42+
))]
43+
pub use self::dsp::*;
44+
45+
// Deprecated in ACLE 2.0 for the A profile but fully supported on the M and R profiles, says
46+
// Section 5.4.9 of ACLE. We'll expose these for the A profile even if deprecated
47+
#[cfg(any(
48+
// v7-A, v7-R
49+
all(target_feature = "v6", not(target_feature = "mclass")),
50+
// v7E-M
51+
all(target_feature = "mclass", target_feature = "dsp"),
52+
doc,
53+
))]
54+
mod simd32;
2155

22-
#[cfg(any(target_arch = "aarch64", target_feature = "v7", doc))]
23-
mod neon;
24-
#[cfg(any(target_arch = "aarch64", target_feature = "v7", doc))]
25-
pub use self::neon::*;
56+
#[cfg(any(
57+
// v7-A, v7-R
58+
all(target_feature = "v6", not(target_feature = "mclass")),
59+
// v7E-M
60+
all(target_feature = "mclass", target_feature = "dsp"),
61+
doc,
62+
))]
63+
pub use self::simd32::*;
2664

27-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
28-
mod crc;
29-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
30-
pub use self::crc::*;
65+
#[cfg(any(target_feature = "v7", doc))]
66+
mod v7;
67+
#[cfg(any(target_feature = "v7", doc))]
68+
pub use self::v7::*;
3169

32-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
33-
mod crypto;
34-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
35-
pub use self::crypto::*;
70+
mod ex;
71+
pub use self::ex::*;
3672

37-
pub use crate::core_arch::acle::*;
73+
pub use crate::core_arch::arm_shared::*;
3874

3975
#[cfg(test)]
4076
use stdarch_test::assert_instr;
4177

78+
#[cfg(any(target_feature = "v7", doc))]
79+
pub(crate) mod neon;
80+
#[cfg(any(target_feature = "v7", doc))]
81+
pub use neon::*;
82+
4283
/// Generates the trap instruction `UDF`
4384
#[cfg(target_arch = "arm")]
4485
#[cfg_attr(test, assert_instr(udf))]
@@ -47,6 +88,26 @@ pub unsafe fn udf() -> ! {
4788
crate::intrinsics::abort()
4889
}
4990

50-
#[cfg(test)]
51-
#[cfg(any(target_arch = "aarch64", target_feature = "v7"))]
52-
pub(crate) mod test_support;
91+
/// Generates a DBG instruction.
92+
///
93+
/// This provides a hint to debugging and related systems. The argument must be
94+
/// a constant integer from 0 to 15 inclusive. See implementation documentation
95+
/// for the effect (if any) of this instruction and the meaning of the
96+
/// argument. This is available only when compliling for AArch32.
97+
// Section 10.1 of ACLE says that the supported arches are: 7, 7-M
98+
// "The DBG hint instruction is added in ARMv7. It is UNDEFINED in the ARMv6 base architecture, and
99+
// executes as a NOP instruction in ARMv6K and ARMv6T2." - ARM Architecture Reference Manual ARMv7-A
100+
// and ARMv7-R edition (ARM DDI 0406C.c) sections D12.4.1 "ARM instruction set support" and D12.4.2
101+
// "Thumb instruction set support"
102+
#[cfg(any(target_feature = "v7", doc))]
103+
#[inline(always)]
104+
#[rustc_legacy_const_generics(0)]
105+
pub unsafe fn __dbg<const IMM4: i32>() {
106+
static_assert_imm4!(IMM4);
107+
dbg(IMM4);
108+
}
109+
110+
extern "C" {
111+
#[link_name = "llvm.arm.dbg"]
112+
fn dbg(_: i32);
113+
}

0 commit comments

Comments
 (0)