Skip to content

Commit 94f1c49

Browse files
authored
fix(simd.h): Address NEON issues (#4143)
Primarily, recent changes (PR #4071) to vint4::store for the NEON case appear to have some type mismatches, which apple clang on ARM-based Mac (including our CI) seems ok with, but which is generating type errors on other ARM Linux platforms. I think the types were weird here, so I tightened it up to get the types right for temporary variables in that function. That's the primary fix here. Secondarily, I modified simd.h and the CMake setup so that build option USE_SIMD=0 will disable NEON in the same way that it disables SSE. (I realized that USE_SIMD=0 was not disabling NEON, so there was no way for a NEON platform to completely disable SIMD if they needed to.) Fixes #4111 Signed-off-by: Larry Gritz <[email protected]>
1 parent 5d83697 commit 94f1c49

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/cmake/compiler.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ set (SIMD_COMPILE_FLAGS "")
303303
if (NOT USE_SIMD STREQUAL "")
304304
message (STATUS "Compiling with SIMD level ${USE_SIMD}")
305305
if (USE_SIMD STREQUAL "0")
306-
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "-DOIIO_NO_SSE=1")
306+
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "-DOIIO_NO_SIMD=1")
307307
else ()
308308
string (REPLACE "," ";" SIMD_FEATURE_LIST ${USE_SIMD})
309309
foreach (feature ${SIMD_FEATURE_LIST})

src/include/OpenImageIO/simd.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
// OIIO_SIMD_HAS_SIMD8 : nonzero if vfloat8, vint8, vbool8 are defined
7878
// OIIO_SIMD_HAS_SIMD16 : nonzero if vfloat16, vint16, vbool16 are defined
7979

80+
#ifdef OIIO_NO_SIMD /* Request to disable all SIMD */
81+
# define OIIO_NO_SSE 1
82+
# define OIIO_NO_AVX 1
83+
# define OIIO_NO_AVX2 1
84+
# define OIIO_NO_NEON 1
85+
#endif
86+
8087
#if defined(_M_ARM64) || defined(__aarch64__) || defined(__aarch64)
8188
# ifndef __ARM_NEON__
8289
# define __ARM_NEON__
@@ -4788,9 +4795,9 @@ OIIO_FORCEINLINE void vint4::store (unsigned char *values) const {
47884795
_mm_store_ss((float*)values, _mm_castsi128_ps(val8));
47894796
#elif OIIO_SIMD_NEON
47904797
vint4 clamped = m_simd & vint4(0xff);
4791-
simd_t val16 = vcombine_s16(vqmovn_s32(clamped), vdup_n_s16(0));
4792-
simd_t val8 = vcombine_u8(vqmovun_s16(val16), vdup_n_u8(0));
4793-
vst1q_lane_u32((uint32_t*)values, val8, 0);
4798+
int16x8_t val16 = vcombine_s16(vqmovn_s32(clamped), vdup_n_s16(0));
4799+
uint8x16_t val8 = vcombine_u8(vqmovun_s16(val16), vdup_n_u8(0));
4800+
vst1q_lane_u32((uint32_t*)values, vreinterpretq_u32_u8(val8), 0);
47944801
#else
47954802
SIMD_DO (values[i] = m_val[i]);
47964803
#endif

0 commit comments

Comments
 (0)