@@ -996,7 +996,10 @@ impl<'b> Pattern for &'b str {
996
996
return haystack. as_bytes ( ) . contains ( & self . as_bytes ( ) [ 0 ] ) ;
997
997
}
998
998
999
- #[ cfg( all( target_arch = "x86_64" , target_feature = "sse2" ) ) ]
999
+ #[ cfg( any(
1000
+ all( target_arch = "x86_64" , target_feature = "sse2" ) ,
1001
+ all( target_arch = "loongarch64" , target_feature = "lsx" )
1002
+ ) ) ]
1000
1003
if self . len ( ) <= 32 {
1001
1004
if let Some ( result) = simd_contains ( self , haystack) {
1002
1005
return result;
@@ -1770,11 +1773,18 @@ impl TwoWayStrategy for RejectAndMatch {
1770
1773
/// If we ever ship std with for x86-64-v3 or adapt this for other platforms then wider vectors
1771
1774
/// should be evaluated.
1772
1775
///
1776
+ /// Similarly, on LoongArch the 128-bit LSX vector extension is the baseline,
1777
+ /// so we also use `u8x16` there. Wider vector widths may be considered
1778
+ /// for future LoongArch extensions (e.g., LASX).
1779
+ ///
1773
1780
/// For haystacks smaller than vector-size + needle length it falls back to
1774
1781
/// a naive O(n*m) search so this implementation should not be called on larger needles.
1775
1782
///
1776
1783
/// [0]: http://0x80.pl/articles/simd-strfind.html#sse-avx2
1777
- #[ cfg( all( target_arch = "x86_64" , target_feature = "sse2" ) ) ]
1784
+ #[ cfg( any(
1785
+ all( target_arch = "x86_64" , target_feature = "sse2" ) ,
1786
+ all( target_arch = "loongarch64" , target_feature = "lsx" )
1787
+ ) ) ]
1778
1788
#[ inline]
1779
1789
fn simd_contains ( needle : & str , haystack : & str ) -> Option < bool > {
1780
1790
let needle = needle. as_bytes ( ) ;
@@ -1906,7 +1916,10 @@ fn simd_contains(needle: &str, haystack: &str) -> Option<bool> {
1906
1916
/// # Safety
1907
1917
///
1908
1918
/// Both slices must have the same length.
1909
- #[ cfg( all( target_arch = "x86_64" , target_feature = "sse2" ) ) ] // only called on x86
1919
+ #[ cfg( any(
1920
+ all( target_arch = "x86_64" , target_feature = "sse2" ) ,
1921
+ all( target_arch = "loongarch64" , target_feature = "lsx" )
1922
+ ) ) ]
1910
1923
#[ inline]
1911
1924
unsafe fn small_slice_eq ( x : & [ u8 ] , y : & [ u8 ] ) -> bool {
1912
1925
debug_assert_eq ! ( x. len( ) , y. len( ) ) ;
0 commit comments