Skip to content

Commit 3997ecc

Browse files
committed
Auto detect apple m2+ chip
1 parent 6a059bc commit 3997ecc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,23 @@ pub fn escape<S: AsRef<str>>(input: S) -> String {
150150

151151
#[cfg(target_arch = "aarch64")]
152152
{
153+
use std::arch::is_aarch64_feature_detected;
154+
153155
#[cfg(feature = "force_aarch64_generic")]
154156
{
155157
return escape_generic(input);
156158
}
157159
#[cfg(not(feature = "force_aarch64_generic"))]
158160
{
159-
return aarch64::escape_neon(input);
161+
// on Apple M2 and later, the `bf16` feature is available
162+
// it means they have more registers and can significantly benefit from the SIMD path
163+
// TODO: add support for sve2 chips with wider registers
164+
// github actions ubuntu-24.04-arm runner has 128 bits sve2 registers, it's not enough for the SIMD path
165+
if cfg!(target_os = "macos") && is_aarch64_feature_detected!("bf16") {
166+
return aarch64::escape_neon(input);
167+
} else {
168+
return escape_generic(input);
169+
}
160170
}
161171
}
162172

0 commit comments

Comments
 (0)