Skip to content

Commit

Permalink
sysutils/dua-cli: make this build on aarch64eb.
Browse files Browse the repository at this point in the history
This is done by avoiding attempts at using neon / SIMD in
big-endian mode by patching some of the vendored crates.
Neon / SIMD is known to be problematical in rust, ref.
rust-lang/stdarch#1484, even
though the CPU itself supports it.

I've also tried reporting the memchr fixes upstream, ref.
BurntSushi/memchr#162
So far not yet adopted.

Zerocopy has also received a pull request:
google/zerocopy#1795
  • Loading branch information
he32 committed Oct 2, 2024
1 parent 219c38d commit beeaa88
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sysutils/dua-cli/distinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.37 2024/08/10 15:24:44 pin Exp $
$NetBSD: distinfo,v 1.38 2024/10/02 17:49:02 he Exp $

BLAKE2s (addr2line-0.22.0.crate) = 834589b7006b3b8d1e40e66abf813d18a5e9d6fac9433c24b0b18920c435a58e
SHA512 (addr2line-0.22.0.crate) = b334f51bd369348b4446805b4f624ec9b4cc8eefcc53ceb57b523ff55bf018d1dfe23259daf48d1878170ad4fcb44181d4738456eb5e35ede6932ff29686268e
Expand Down Expand Up @@ -525,3 +525,8 @@ Size (zerocopy-0.7.35.crate) = 152645 bytes
BLAKE2s (zerocopy-derive-0.7.35.crate) = b80899d1b7a843a5225638171775a0c9643052c9e96f7b88a825150d0725505e
SHA512 (zerocopy-derive-0.7.35.crate) = dbe23573b62a6267d7bc8c744320b75b2fbda03b908c1d175211f7394374fe182bce58021e25485c10671d726b2007f250565dfe53134d51c89293bb607e9feb
Size (zerocopy-derive-0.7.35.crate) = 37829 bytes
SHA1 (patch-.._vendor_memchr-2.7.4_src_arch_aarch64_mod.rs) = ca83fcd3a2c7aff1828d18a5ca4df1e3ae3557fb
SHA1 (patch-.._vendor_memchr-2.7.4_src_memchr.rs) = b964579dd7ea479e2f4be41843b5b8161dbc2eae
SHA1 (patch-.._vendor_memchr-2.7.4_src_memmem_searcher.rs) = 2317e98578bf30ead561a1af1974db454e88a11c
SHA1 (patch-.._vendor_memchr-2.7.4_src_vector.rs) = 8acec8d16fad3cf64fc66c97cc7717549069ee0e
SHA1 (patch-.._vendor_zerocopy-0.7.35_src_lib.rs) = 908bf1ca2244c4ca1af6d7c75cbad250fac5ea9c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$NetBSD: patch-.._vendor_memchr-2.7.4_src_arch_aarch64_mod.rs,v 1.1 2024/10/02 17:49:02 he Exp $

Make this build on big-endian aarch64.

--- ../vendor/memchr-2.7.4/src/arch/aarch64/mod.rs.orig 2024-10-01 22:42:20.721140485 +0000
+++ ../vendor/memchr-2.7.4/src/arch/aarch64/mod.rs
@@ -2,6 +2,8 @@
Vector algorithms for the `aarch64` target.
*/

+#[cfg(target_endian = "little")]
pub mod neon;

+#[cfg(target_endian = "little")]
pub(crate) mod memchr;
128 changes: 128 additions & 0 deletions sysutils/dua-cli/patches/patch-.._vendor_memchr-2.7.4_src_memchr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
$NetBSD: patch-.._vendor_memchr-2.7.4_src_memchr.rs,v 1.1 2024/10/02 17:49:02 he Exp $

Make this build on big-endian aarch64.

--- ../vendor/memchr-2.7.4/src/memchr.rs.orig 2024-10-01 22:37:24.143489357 +0000
+++ ../vendor/memchr-2.7.4/src/memchr.rs
@@ -518,14 +518,14 @@ unsafe fn memchr_raw(
{
crate::arch::wasm32::memchr::memchr_raw(needle, start, end)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memchr_raw(needle, start, end)
}
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::One::new(needle).find_raw(start, end)
@@ -551,14 +551,14 @@ unsafe fn memrchr_raw(
{
crate::arch::wasm32::memchr::memrchr_raw(needle, start, end)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memrchr_raw(needle, start, end)
}
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::One::new(needle).rfind_raw(start, end)
@@ -585,14 +585,14 @@ unsafe fn memchr2_raw(
{
crate::arch::wasm32::memchr::memchr2_raw(needle1, needle2, start, end)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memchr2_raw(needle1, needle2, start, end)
}
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::Two::new(needle1, needle2)
@@ -620,7 +620,7 @@ unsafe fn memrchr2_raw(
{
crate::arch::wasm32::memchr::memrchr2_raw(needle1, needle2, start, end)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memrchr2_raw(
needle1, needle2, start, end,
@@ -629,7 +629,7 @@ unsafe fn memrchr2_raw(
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::Two::new(needle1, needle2)
@@ -662,7 +662,7 @@ unsafe fn memchr3_raw(
needle1, needle2, needle3, start, end,
)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memchr3_raw(
needle1, needle2, needle3, start, end,
@@ -671,7 +671,7 @@ unsafe fn memchr3_raw(
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::Three::new(needle1, needle2, needle3)
@@ -704,7 +704,7 @@ unsafe fn memrchr3_raw(
needle1, needle2, needle3, start, end,
)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::memrchr3_raw(
needle1, needle2, needle3, start, end,
@@ -713,7 +713,7 @@ unsafe fn memrchr3_raw(
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::Three::new(needle1, needle2, needle3)
@@ -736,14 +736,14 @@ unsafe fn count_raw(needle: u8, start: *
{
crate::arch::wasm32::memchr::count_raw(needle, start, end)
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
crate::arch::aarch64::memchr::count_raw(needle, start, end)
}
#[cfg(not(any(
target_arch = "x86_64",
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
crate::arch::all::memchr::One::new(needle).count_raw(start, end)
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
$NetBSD: patch-.._vendor_memchr-2.7.4_src_memmem_searcher.rs,v 1.1 2024/10/02 17:49:02 he Exp $

Make this build on big-endian aarch64.

--- ../vendor/memchr-2.7.4/src/memmem/searcher.rs.orig 2024-10-01 22:46:23.364125524 +0000
+++ ../vendor/memchr-2.7.4/src/memmem/searcher.rs
@@ -3,7 +3,7 @@ use crate::arch::all::{
rabinkarp, twoway,
};

-#[cfg(target_arch = "aarch64")]
+#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
use crate::arch::aarch64::neon::packedpair as neon;
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
use crate::arch::wasm32::simd128::packedpair as simd128;
@@ -129,7 +129,7 @@ impl Searcher {
Searcher::twoway(needle, rabinkarp, prestrat)
}
}
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
{
if let Some(pp) = neon::Finder::with_pair(needle, pair) {
if do_packed_search(needle) {
@@ -152,7 +152,7 @@ impl Searcher {
#[cfg(not(any(
all(target_arch = "x86_64", target_feature = "sse2"),
all(target_arch = "wasm32", target_feature = "simd128"),
- target_arch = "aarch64"
+ all(target_arch = "aarch64", target_endian = "little")
)))]
{
if prefilter.is_none() {
@@ -253,7 +253,7 @@ union SearcherKind {
avx2: crate::arch::x86_64::avx2::packedpair::Finder,
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
simd128: crate::arch::wasm32::simd128::packedpair::Finder,
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
neon: crate::arch::aarch64::neon::packedpair::Finder,
}

@@ -421,7 +421,7 @@ unsafe fn searcher_kind_simd128(
/// # Safety
///
/// Callers must ensure that the `searcher.kind.neon` union field is set.
-#[cfg(target_arch = "aarch64")]
+#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
unsafe fn searcher_kind_neon(
searcher: &Searcher,
_prestate: &mut PrefilterState,
@@ -686,7 +686,7 @@ impl Prefilter {
}

/// Return a prefilter using a aarch64 neon vector algorithm.
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
#[inline]
fn neon(finder: neon::Finder, needle: &[u8]) -> Prefilter {
trace!("building aarch64 neon prefilter");
@@ -763,7 +763,7 @@ union PrefilterKind {
avx2: crate::arch::x86_64::avx2::packedpair::Finder,
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
simd128: crate::arch::wasm32::simd128::packedpair::Finder,
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
neon: crate::arch::aarch64::neon::packedpair::Finder,
}

@@ -852,7 +852,7 @@ unsafe fn prefilter_kind_simd128(
/// # Safety
///
/// Callers must ensure that the `strat.kind.neon` union field is set.
-#[cfg(target_arch = "aarch64")]
+#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
unsafe fn prefilter_kind_neon(
strat: &Prefilter,
haystack: &[u8],
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$NetBSD: patch-.._vendor_memchr-2.7.4_src_vector.rs,v 1.1 2024/10/02 17:49:02 he Exp $

Make this build on big-endian aarch64.

--- ../vendor/memchr-2.7.4/src/vector.rs.orig 2024-10-01 22:43:45.510956667 +0000
+++ ../vendor/memchr-2.7.4/src/vector.rs
@@ -289,7 +289,7 @@ mod x86avx2 {
}
}

-#[cfg(target_arch = "aarch64")]
+#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
mod aarch64neon {
use core::arch::aarch64::*;

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$NetBSD: patch-.._vendor_zerocopy-0.7.35_src_lib.rs,v 1.1 2024/10/02 17:49:02 he Exp $

Make this build on big-endian aarch64.

--- ../vendor/zerocopy-0.7.35/src/lib.rs.orig 2024-10-01 22:31:58.027833427 +0000
+++ ../vendor/zerocopy-0.7.35/src/lib.rs
@@ -3736,7 +3736,7 @@ mod simd {
powerpc64, powerpc64, vector_bool_long, vector_double, vector_signed_long, vector_unsigned_long
);
simd_arch_mod!(
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
aarch64, aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
int8x8x3_t, int8x8x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int16x4_t,
int16x8_t, int32x2_t, int32x4_t, int64x1_t, int64x2_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t,
@@ -8026,7 +8026,7 @@ mod tests {
vector_signed_long,
vector_unsigned_long
);
- #[cfg(target_arch = "aarch64")]
+ #[cfg(all(target_arch = "aarch64", target_endian = "little"))]
#[rustfmt::skip]
test_simd_arch_mod!(
aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,

0 comments on commit beeaa88

Please sign in to comment.