core/stdarch/crates/core_arch/src/aarch64/
tme.rs1#[cfg(test)]
18use stdarch_test::assert_instr;
19
20extern "unadjusted" {
21 #[link_name = "llvm.aarch64.tstart"]
22 fn aarch64_tstart() -> u64;
23 #[link_name = "llvm.aarch64.tcommit"]
24 fn aarch64_tcommit();
25 #[link_name = "llvm.aarch64.tcancel"]
26 fn aarch64_tcancel(imm0: u64);
27 #[link_name = "llvm.aarch64.ttest"]
28 fn aarch64_ttest() -> u64;
29}
30
31#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
33pub const _TMSTART_SUCCESS: u64 = 0x00_u64;
34
35#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
37pub const _TMFAILURE_REASON: u64 = 0x00007FFF_u64;
38
39#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
41pub const _TMFAILURE_RTRY: u64 = 1 << 15;
42
43#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
45pub const _TMFAILURE_CNCL: u64 = 1 << 16;
46
47#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
49pub const _TMFAILURE_MEM: u64 = 1 << 17;
50
51#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
53pub const _TMFAILURE_IMP: u64 = 1 << 18;
54
55#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
57pub const _TMFAILURE_ERR: u64 = 1 << 19;
58
59#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
61pub const _TMFAILURE_SIZE: u64 = 1 << 20;
62
63#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
65pub const _TMFAILURE_NEST: u64 = 1 << 21;
66
67#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
69pub const _TMFAILURE_DBG: u64 = 1 << 22;
70
71#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
73pub const _TMFAILURE_INT: u64 = 1 << 23;
74
75#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
77pub const _TMFAILURE_TRIVIAL: u64 = 1 << 24;
78
79#[inline]
88#[target_feature(enable = "tme")]
89#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(tstart))]
90#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
91pub unsafe fn __tstart() -> u64 {
92 aarch64_tstart()
93}
94
95#[inline]
101#[target_feature(enable = "tme")]
102#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(tcommit))]
103#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
104pub unsafe fn __tcommit() {
105 aarch64_tcommit()
106}
107
108#[inline]
112#[target_feature(enable = "tme")]
113#[cfg_attr(
114 all(test, not(target_env = "msvc")),
115 assert_instr(tcancel, IMM16 = 0x0)
116)]
117#[rustc_legacy_const_generics(0)]
118#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
119pub unsafe fn __tcancel<const IMM16: u64>() {
120 static_assert!(IMM16 <= 65535);
121 aarch64_tcancel(IMM16);
122}
123
124#[inline]
129#[target_feature(enable = "tme")]
130#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(ttest))]
131#[unstable(feature = "stdarch_aarch64_tme", issue = "117216")]
132pub unsafe fn __ttest() -> u64 {
133 aarch64_ttest()
134}
135
136#[cfg(test)]
137mod tests {
138 use stdarch_test::simd_test;
139
140 use crate::core_arch::aarch64::*;
141
142 const CANCEL_CODE: u64 = (0 | (0x123 & _TMFAILURE_REASON) as u64) as u64;
143
144 #[simd_test(enable = "tme")]
145 unsafe fn test_tstart() {
146 let mut x = 0;
147 for i in 0..10 {
148 let code = tme::__tstart();
149 if code == _TMSTART_SUCCESS {
150 x += 1;
151 assert_eq!(x, i + 1);
152 break;
153 }
154 assert_eq!(x, 0);
155 }
156 }
157
158 #[simd_test(enable = "tme")]
159 unsafe fn test_tcommit() {
160 let mut x = 0;
161 for i in 0..10 {
162 let code = tme::__tstart();
163 if code == _TMSTART_SUCCESS {
164 x += 1;
165 assert_eq!(x, i + 1);
166 tme::__tcommit();
167 }
168 assert_eq!(x, i + 1);
169 }
170 }
171
172 #[simd_test(enable = "tme")]
173 unsafe fn test_tcancel() {
174 let mut x = 0;
175
176 for i in 0..10 {
177 let code = tme::__tstart();
178 if code == _TMSTART_SUCCESS {
179 x += 1;
180 assert_eq!(x, i + 1);
181 tme::__tcancel::<CANCEL_CODE>();
182 break;
183 }
184 }
185
186 assert_eq!(x, 0);
187 }
188
189 #[simd_test(enable = "tme")]
190 unsafe fn test_ttest() {
191 for _ in 0..10 {
192 let code = tme::__tstart();
193 if code == _TMSTART_SUCCESS {
194 if tme::__ttest() == 2 {
195 tme::__tcancel::<CANCEL_CODE>();
196 break;
197 }
198 }
199 }
200 }
201}