Skip to content

Commit f91a223

Browse files
committed
feature detection
1 parent 9fb45e7 commit f91a223

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

Diff for: crates/core_arch/src/aarch64/tme.rs

+26-28
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,50 @@ use stdarch_test::assert_instr;
1919

2020
extern "C" {
2121
#[link_name = "llvm.aarch64.tstart"]
22-
fn aarch64_tstart() -> i32;
22+
fn aarch64_tstart() -> i64;
2323
#[link_name = "llvm.aarch64.tcommit"]
2424
fn aarch64_tcommit() -> ();
2525
#[link_name = "llvm.aarch64.tcancel"]
2626
fn aarch64_tcancel(imm0: i64) -> ();
2727
#[link_name = "llvm.aarch64.ttest"]
28-
fn aarch64_ttest() -> i32;
28+
fn aarch64_ttest() -> i64;
2929
}
3030

3131
/// Transaction successfully started.
32-
pub const _TMSTART_SUCCESS: u32 = 0x00_u32;
32+
pub const _TMSTART_SUCCESS: i64 = 0x00_i64;
3333

3434
/// Extraction mask for failure reason
35-
pub const _TMFAILURE_REASON: u32 = 0x00007FFF_u32;
35+
pub const _TMFAILURE_REASON: i64 = 0x00007FFF_i64;
3636

3737
/// Transaction retry is possible.
38-
pub const _TMFAILURE_RTRY: u32 = 1 << 15;
38+
pub const _TMFAILURE_RTRY: i64 = 1 << 15;
3939

4040
/// Transaction executed a TCANCEL instruction
41-
pub const _TMFAILURE_CNCL: u32 = 1 << 16;
41+
pub const _TMFAILURE_CNCL: i64 = 1 << 16;
4242

4343
/// Transaction aborted because a conflict occurred
44-
pub const _TMFAILURE_MEM: u32 = 1 << 17;
44+
pub const _TMFAILURE_MEM: i64 = 1 << 17;
4545

4646
/// Fallback error type for any other reason
47-
pub const _TMFAILURE_IMP: u32 = 1 << 18;
47+
pub const _TMFAILURE_IMP: i64 = 1 << 18;
4848

4949
/// Transaction aborted because a non-permissible operation was attempted
50-
pub const _TMFAILURE_ERR: u32 = 1 << 19;
50+
pub const _TMFAILURE_ERR: i64 = 1 << 19;
5151

5252
/// Transaction aborted due to read or write set limit was exceeded
53-
pub const _TMFAILURE_SIZE: u32 = 1 << 20;
53+
pub const _TMFAILURE_SIZE: i64 = 1 << 20;
5454

5555
/// Transaction aborted due to transactional nesting level was exceeded
56-
pub const _TMFAILURE_NEST: u32 = 1 << 21;
56+
pub const _TMFAILURE_NEST: i64 = 1 << 21;
5757

5858
/// Transaction aborted due to a debug trap.
59-
pub const _TMFAILURE_DBG: u32 = 1 << 22;
59+
pub const _TMFAILURE_DBG: i64 = 1 << 22;
6060

6161
/// Transaction failed from interrupt
62-
pub const _TMFAILURE_INT: u32 = 1 << 23;
62+
pub const _TMFAILURE_INT: i64 = 1 << 23;
6363

6464
/// Indicates a TRIVIAL version of TM is available
65-
pub const _TMFAILURE_TRIVIAL: u32 = 1 << 24;
65+
pub const _TMFAILURE_TRIVIAL: i64 = 1 << 24;
6666

6767
/// Starts a new transaction. When the transaction starts successfully the return value is 0.
6868
/// If the transaction fails, all state modifications are discarded and a cause of the failure
@@ -72,7 +72,7 @@ pub const _TMFAILURE_TRIVIAL: u32 = 1 << 24;
7272
#[inline]
7373
#[target_feature(enable = "tme")]
7474
#[cfg_attr(test, assert_instr(tstart))]
75-
pub unsafe fn __tstart() -> u32 {
75+
pub unsafe fn __tstart() -> i64 {
7676
aarch64_tstart() as _
7777
}
7878

@@ -95,7 +95,7 @@ pub unsafe fn __tcommit() {
9595
#[target_feature(enable = "tme")]
9696
#[cfg_attr(test, assert_instr(tcancel, imm0 = 0x0))]
9797
#[rustc_args_required_const(0)]
98-
pub unsafe fn __tcancel(imm0: u32) {
98+
pub unsafe fn __tcancel(imm0: i64) {
9999
macro_rules! call {
100100
($imm0:expr) => {
101101
aarch64_tcancel($imm0)
@@ -111,7 +111,7 @@ pub unsafe fn __tcancel(imm0: u32) {
111111
#[inline]
112112
#[target_feature(enable = "tme")]
113113
#[cfg_attr(test, assert_instr(ttest))]
114-
pub unsafe fn __ttest() -> u32 {
114+
pub unsafe fn __ttest() -> i64 {
115115
aarch64_ttest() as _
116116
}
117117

@@ -121,14 +121,16 @@ mod tests {
121121

122122
use crate::core_arch::aarch64::*;
123123

124+
const CANCEL_CODE: i64 = (0 | (0x123 & _TMFAILURE_REASON) as i64) as i64;
125+
124126
#[simd_test(enable = "tme")]
125127
unsafe fn test_tstart() {
126128
let mut x = 0;
127129
for i in 0..10 {
128130
let code = tme::__tstart();
129131
if code == _TMSTART_SUCCESS {
130132
x += 1;
131-
assert_eq!(x, i+1);
133+
assert_eq!(x, i + 1);
132134
break;
133135
}
134136
assert_eq!(x, 0);
@@ -142,25 +144,23 @@ mod tests {
142144
let code = tme::__tstart();
143145
if code == _TMSTART_SUCCESS {
144146
x += 1;
145-
assert_eq!(x, i+1);
147+
assert_eq!(x, i + 1);
146148
tme::__tcommit();
147149
}
148-
assert_eq!(x, i+1);
150+
assert_eq!(x, i + 1);
149151
}
150152
}
151153

152154
#[simd_test(enable = "tme")]
153155
unsafe fn test_tcancel() {
154-
let reason = 0x123;
155-
let cancel_code = (0 | (reason & _TMFAILURE_REASON) as i32) as u32;
156156
let mut x = 0;
157157

158158
for i in 0..10 {
159159
let code = tme::__tstart();
160160
if code == _TMSTART_SUCCESS {
161161
x += 1;
162-
assert_eq!(x, i+1);
163-
tme::__tcancel(cancel_code);
162+
assert_eq!(x, i + 1);
163+
tme::__tcancel(CANCEL_CODE);
164164
break;
165165
}
166166
}
@@ -170,14 +170,12 @@ mod tests {
170170

171171
#[simd_test(enable = "tme")]
172172
unsafe fn test_ttest() {
173-
let reason = 0x123;
174-
let cancel_code = (0 | (reason & _TMFAILURE_REASON) as i32) as u32;
175173
for _ in 0..10 {
176174
let code = tme::__tstart();
177175
if code == _TMSTART_SUCCESS {
178176
if tme::__ttest() == 2 {
179-
tme::__tcancel(cancel_code);
180-
break;
177+
tme::__tcancel(CANCEL_CODE);
178+
break;
181179
}
182180
}
183181
}

Diff for: crates/simd-test-macro/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,8 @@ fn find_name(item: TokenStream) -> Ident {
156156
}
157157
}
158158

159-
tokens.next().and_then(get_ident).expect("failed to find function name")
159+
tokens
160+
.next()
161+
.and_then(get_ident)
162+
.expect("failed to find function name")
160163
}

Diff for: crates/std_detect/src/detect/arch/aarch64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ features! {
3333
/// Release consistent Processor consistent (RcPc)
3434
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] dotprod: "dotprod";
3535
/// Vector Dot-Product (ASIMDDP)
36+
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] tme: "tme";
37+
/// Transactional Memory Extensions (TME)
3638
}

Diff for: crates/std_detect/src/detect/os/aarch64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
4444
enable_feature(Feature::pmull, pmull);
4545
// Crypto is specified as AES + PMULL + SHA1 + SHA2 per LLVM/hosts.cpp
4646
enable_feature(Feature::crypto, aes && pmull && sha1 && sha2);
47+
enable_feature(Feature::tme, bits_shift(aa64isar0, 27, 24) == 1);
4748
enable_feature(Feature::lse, bits_shift(aa64isar0, 23, 20) >= 1);
4849
enable_feature(Feature::crc, bits_shift(aa64isar0, 19, 16) >= 1);
4950

Diff for: crates/std_detect/src/detect/os/freebsd/aarch64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ mod tests {
1717
println!("rdm: {:?}", is_aarch64_feature_detected!("rdm"));
1818
println!("rcpc: {:?}", is_aarch64_feature_detected!("rcpc"));
1919
println!("dotprod: {:?}", is_aarch64_feature_detected!("dotprod"));
20+
println!("tme: {:?}", is_aarch64_feature_detected!("tme"));
2021
}
2122
}

0 commit comments

Comments
 (0)