From c697496364ec488a7effacae7c6c0701c8d50e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 4 Jun 2026 10:03:29 +0200 Subject: [PATCH] Other fixes --- Common/Math/CrossSIMD.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Common/Math/CrossSIMD.h b/Common/Math/CrossSIMD.h index a79f242835..91f8bd4d2b 100644 --- a/Common/Math/CrossSIMD.h +++ b/Common/Math/CrossSIMD.h @@ -1169,7 +1169,19 @@ struct Vec4F32 { } // NOTE: May be slow. - float operator[](size_t index) const { return ((float *)&v)[index]; } + float operator[](size_t index) const { + // index is a compile-time constant parameter to the intrinsic. + int ival; + switch (index) { + case 0: ival = __lsx_vpickve2gr_w((__m128i)v, 0); + case 1: ival = __lsx_vpickve2gr_w((__m128i)v, 1); + case 2: ival = __lsx_vpickve2gr_w((__m128i)v, 2); + default: ival = __lsx_vpickve2gr_w((__m128i)v, 3); + } + float fval; + memcpy(&fval, &ival, sizeof(float)); + return fval; + } Vec4F32 operator +(Vec4F32 other) const { return Vec4F32{ (__m128)__lsx_vfadd_s(v, other.v) }; } Vec4F32 operator -(Vec4F32 other) const { return Vec4F32{ (__m128)__lsx_vfsub_s(v, other.v) }; }