typedef __m128i Vector8;
typedef __m128i Vector32;
+#elif defined(__aarch64__) && defined(__ARM_NEON)
+/*
+ * We use the Neon instructions if the compiler provides access to them (as
+ * indicated by __ARM_NEON) and we are on aarch64. While Neon support is
+ * technically optional for aarch64, it appears that all available 64-bit
+ * hardware does have it. Neon exists in some 32-bit hardware too, but we
+ * could not realistically use it there without a run-time check, which seems
+ * not worth the trouble for now.
+ */
+#include <arm_neon.h>
+#define USE_NEON
+typedef uint8x16_t Vector8;
+typedef uint32x4_t Vector32;
+
#else
/*
* If no SIMD instructions are available, we can in some cases emulate vector
{
#if defined(USE_SSE2)
*v = _mm_loadu_si128((const __m128i *) s);
+#elif defined(USE_NEON)
+ *v = vld1q_u8(s);
#else
memcpy(v, s, sizeof(Vector8));
#endif
{
#ifdef USE_SSE2
*v = _mm_loadu_si128((const __m128i *) s);
+#elif defined(USE_NEON)
+ *v = vld1q_u32(s);
#endif
}
#endif /* ! USE_NO_SIMD */
{
#if defined(USE_SSE2)
return _mm_set1_epi8(c);
+#elif defined(USE_NEON)
+ return vdupq_n_u8(c);
#else
return ~UINT64CONST(0) / 0xFF * c;
#endif
{
#ifdef USE_SSE2
return _mm_set1_epi32(c);
+#elif defined(USE_NEON)
+ return vdupq_n_u32(c);
#endif
}
#endif /* ! USE_NO_SIMD */
#if defined(USE_NO_SIMD)
/* any bytes in v equal to c will evaluate to zero via XOR */
result = vector8_has_zero(v ^ vector8_broadcast(c));
-#elif defined(USE_SSE2)
+#else
result = vector8_is_highbit_set(vector8_eq(v, vector8_broadcast(c)));
#endif
* circular definition.
*/
return vector8_has_le(v, 0);
-#elif defined(USE_SSE2)
+#else
return vector8_has(v, 0);
#endif
}
}
}
}
-#elif defined(USE_SSE2)
+#else
/*
* Use saturating subtraction to find bytes <= c, which will present as
{
#ifdef USE_SSE2
return _mm_movemask_epi8(v) != 0;
+#elif defined(USE_NEON)
+ return vmaxvq_u8(v) > 0x7F;
#else
return v & vector8_broadcast(0x80);
#endif
{
#ifdef USE_SSE2
return _mm_or_si128(v1, v2);
+#elif defined(USE_NEON)
+ return vorrq_u8(v1, v2);
#else
return v1 | v2;
#endif
{
#ifdef USE_SSE2
return _mm_or_si128(v1, v2);
+#elif defined(USE_NEON)
+ return vorrq_u32(v1, v2);
#endif
}
#endif /* ! USE_NO_SIMD */
{
#ifdef USE_SSE2
return _mm_subs_epu8(v1, v2);
+#elif defined(USE_NEON)
+ return vqsubq_u8(v1, v2);
#endif
}
#endif /* ! USE_NO_SIMD */
{
#ifdef USE_SSE2
return _mm_cmpeq_epi8(v1, v2);
+#elif defined(USE_NEON)
+ return vceqq_u8(v1, v2);
#endif
}
#endif /* ! USE_NO_SIMD */
{
#ifdef USE_SSE2
return _mm_cmpeq_epi32(v1, v2);
+#elif defined(USE_NEON)
+ return vceqq_u32(v1, v2);
#endif
}
#endif /* ! USE_NO_SIMD */