From 6313b96084ed50e315cbdb67e7b1ddd1bd81e3d7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 12 Oct 2026 18:53:34 +0200 Subject: [PATCH 1/2] Fix v2 F/E mixing on big-endian PPC64 with VSX Co-authored-by: cyrozap --- src/intrin_portable.h | 8 ++++++++ src/tests/tests.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/intrin_portable.h b/src/intrin_portable.h index 10530656..e1a06b12 100644 --- a/src/intrin_portable.h +++ b/src/intrin_portable.h @@ -277,11 +277,19 @@ FORCE_INLINE rx_vec_f128 rx_set1_vec_f128(uint64_t x) { } FORCE_INLINE rx_vec_f128 rx_cast_vec_i2f(rx_vec_i128 a) { +#if defined(NATIVE_LITTLE_ENDIAN) return (rx_vec_f128)a; +#else + return (rx_vec_f128)vec_perm((__m128i)a, (__m128i)a, (__m128i){4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11}); +#endif } FORCE_INLINE rx_vec_i128 rx_cast_vec_f2i(rx_vec_f128 a) { +#if defined(NATIVE_LITTLE_ENDIAN) return (rx_vec_i128)a; +#else + return (rx_vec_i128)vec_perm((__m128i)a, (__m128i)a, (__m128i){4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11}); +#endif } FORCE_INLINE rx_vec_f128 rx_xor_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index dee37d24..72fce194 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -175,6 +175,16 @@ int main() { assert(equalsHex(state, "fa89397dd6ca422513aeadba3f124b5540324c4ad4b6db434394307a17c833ab")); }); + runTest("rx_cast_vec_f2i / rx_cast_vec_i2f", true, []() { + alignas(16) uint8_t in[16], out[16]; + for (int i = 0; i < 16; ++i) + in[i] = (uint8_t)(0x11 * i + 1); + rx_store_vec_i128((rx_vec_i128*)out, rx_cast_vec_f2i(rx_load_vec_f128((const double*)in))); + assert(memcmp(in, out, sizeof(in)) == 0); + rx_store_vec_f128((double*)out, rx_cast_vec_i2f(rx_load_vec_i128((const rx_vec_i128*)in))); + assert(memcmp(in, out, sizeof(in)) == 0); + }); + randomx::NativeRegisterFile reg; randomx::BytecodeMachine decoder; randomx::InstructionByteCode ibc; From d6a4911507424fa3115b346e716afba036bd5990 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 12 Oct 2026 18:53:35 +0200 Subject: [PATCH 2/2] Remove unused vector helpers that are wrong on big-endian --- src/intrin_portable.h | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/intrin_portable.h b/src/intrin_portable.h index e1a06b12..98d265aa 100644 --- a/src/intrin_portable.h +++ b/src/intrin_portable.h @@ -260,14 +260,6 @@ FORCE_INLINE rx_vec_f128 rx_sqrt_vec_f128(rx_vec_f128 a) { return (rx_vec_f128)vec_sqrt(a); } -FORCE_INLINE rx_vec_i128 rx_set1_long_vec_i128(uint64_t a) { - return (rx_vec_i128)vec_splat2sd(a); -} - -FORCE_INLINE rx_vec_f128 rx_vec_i128_vec_f128(rx_vec_i128 a) { - return (rx_vec_f128)a; -} - FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { return (rx_vec_f128)(__m128ll){x0,x1}; } @@ -640,19 +632,6 @@ FORCE_INLINE rx_vec_f128 rx_sqrt_vec_f128(rx_vec_f128 a) { return x; } -FORCE_INLINE rx_vec_i128 rx_set1_long_vec_i128(uint64_t a) { - rx_vec_i128 x; - x.u64[0] = a; - x.u64[1] = a; - return x; -} - -FORCE_INLINE rx_vec_f128 rx_vec_i128_vec_f128(rx_vec_i128 a) { - rx_vec_f128 x; - x.i = a; - return x; -} - FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { rx_vec_f128 v; v.i.u64[0] = x0;