core/stdarch/crates/core_arch/src/aarch64/
mte.rs1extern "unadjusted" {
6 #[cfg_attr(
7 any(target_arch = "aarch64", target_arch = "arm64ec"),
8 link_name = "llvm.aarch64.irg"
9 )]
10 fn irg_(ptr: *const (), exclude: i64) -> *const ();
11 #[cfg_attr(
12 any(target_arch = "aarch64", target_arch = "arm64ec"),
13 link_name = "llvm.aarch64.gmi"
14 )]
15 fn gmi_(ptr: *const (), exclude: i64) -> i64;
16 #[cfg_attr(
17 any(target_arch = "aarch64", target_arch = "arm64ec"),
18 link_name = "llvm.aarch64.ldg"
19 )]
20 fn ldg_(ptr: *const (), tag_ptr: *const ()) -> *const ();
21 #[cfg_attr(
22 any(target_arch = "aarch64", target_arch = "arm64ec"),
23 link_name = "llvm.aarch64.stg"
24 )]
25 fn stg_(tagged_ptr: *const (), addr_to_tag: *const ());
26 #[cfg_attr(
27 any(target_arch = "aarch64", target_arch = "arm64ec"),
28 link_name = "llvm.aarch64.addg"
29 )]
30 fn addg_(ptr: *const (), value: i64) -> *const ();
31 #[cfg_attr(
32 any(target_arch = "aarch64", target_arch = "arm64ec"),
33 link_name = "llvm.aarch64.subp"
34 )]
35 fn subp_(ptr_a: *const (), ptr_b: *const ()) -> i64;
36}
37
38#[inline]
53#[target_feature(enable = "mte")]
54#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
55pub unsafe fn __arm_mte_create_random_tag<T>(src: *const T, mask: u64) -> *const T {
56 irg_(src as *const (), mask as i64) as *const T
57}
58
59#[inline]
69#[target_feature(enable = "mte")]
70#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
71pub unsafe fn __arm_mte_increment_tag<const OFFSET: i64, T>(src: *const T) -> *const T {
72 addg_(src as *const (), OFFSET) as *const T
73}
74
75#[inline]
84#[target_feature(enable = "mte")]
85#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
86pub unsafe fn __arm_mte_exclude_tag<T>(src: *const T, excluded: u64) -> u64 {
87 gmi_(src as *const (), excluded as i64) as u64
88}
89
90#[inline]
98#[target_feature(enable = "mte")]
99#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
100pub unsafe fn __arm_mte_set_tag<T>(tag_address: *const T) {
101 stg_(tag_address as *const (), tag_address as *const ());
102}
103
104#[inline]
110#[target_feature(enable = "mte")]
111#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
112pub unsafe fn __arm_mte_get_tag<T>(address: *const T) -> *const T {
113 ldg_(address as *const (), address as *const ()) as *const T
114}
115
116#[inline]
119#[target_feature(enable = "mte")]
120#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
121pub unsafe fn __arm_mte_ptrdiff<T, U>(a: *const T, b: *const U) -> i64 {
122 subp_(a as *const (), b as *const ())
123}
124
125#[cfg(test)]
126mod test {
127 use super::*;
128 use stdarch_test::assert_instr;
129
130 #[cfg_attr(test, assert_instr(irg))]
131 #[allow(dead_code)]
132 #[target_feature(enable = "mte")]
133 unsafe fn test_arm_mte_create_random_tag(src: *const (), mask: u64) -> *const () {
134 __arm_mte_create_random_tag(src, mask)
135 }
136
137 #[cfg_attr(test, assert_instr(addg))]
138 #[allow(dead_code)]
139 #[target_feature(enable = "mte")]
140 unsafe fn test_arm_mte_increment_tag(src: *const ()) -> *const () {
141 __arm_mte_increment_tag::<1, _>(src)
142 }
143
144 #[cfg_attr(test, assert_instr(gmi))]
145 #[allow(dead_code)]
146 #[target_feature(enable = "mte")]
147 unsafe fn test_arm_mte_exclude_tag(src: *const (), excluded: u64) -> u64 {
148 __arm_mte_exclude_tag(src, excluded)
149 }
150
151 #[cfg_attr(test, assert_instr(stg))]
152 #[allow(dead_code)]
153 #[target_feature(enable = "mte")]
154 unsafe fn test_arm_mte_set_tag(src: *const ()) {
155 __arm_mte_set_tag(src)
156 }
157
158 #[cfg_attr(test, assert_instr(ldg))]
159 #[allow(dead_code)]
160 #[target_feature(enable = "mte")]
161 unsafe fn test_arm_mte_get_tag(src: *const ()) -> *const () {
162 __arm_mte_get_tag(src)
163 }
164
165 #[cfg_attr(test, assert_instr(subp))]
166 #[allow(dead_code)]
167 #[target_feature(enable = "mte")]
168 unsafe fn test_arm_mte_ptrdiff(a: *const (), b: *const ()) -> i64 {
169 __arm_mte_ptrdiff(a, b)
170 }
171}