goankur commented on code in PR #13572:
URL: https://github.com/apache/lucene/pull/13572#discussion_r1720493763
##########
lucene/core/src/c/dotProduct.c:
##########
@@ -0,0 +1,143 @@
+// dotProduct.c
+
+#include <stdio.h>
+#include <arm_neon.h>
+
+#ifdef __ARM_ACLE
+#include <arm_acle.h>
+#endif
+
+#if (defined(__ARM_FEATURE_SVE) && !defined(__APPLE__))
+#include <arm_sve.h>
+/*
+ * Unrolled and vectorized int8 dotProduct implementation using SVE
instructions
+ * NOTE: Clang 15.0 compiler on Apple M3 Max compiles the code below
sucessfully
+ * with '-march=native+sve' option but throws "Illegal Hardware Instruction"
error
+ * Looks like Apple M3 does not implement SVE and Apple's official
documentation
+ * is not explicit about this or at least I could not find it.
+ *
+ */
+int32_t vdot8s_sve(int8_t *vec1, int8_t *vec2, int32_t limit) {
+ int32_t result = 0;
+ int32_t i = 0;
+ // Vectors of 8-bit signed integers
+ svint8_t va1, va2, va3, va4;
+ svint8_t vb1, vb2, vb3, vb4;
+ // Init accumulators
+ svint32_t acc1 = svdup_n_s32(0);
+ svint32_t acc2 = svdup_n_s32(0);
+ svint32_t acc3 = svdup_n_s32(0);
+ svint32_t acc4 = svdup_n_s32(0);
+
+ // Number of 8-bits elements in the SVE vector
+ int32_t vec_length = svcntb();
+
+ // Manually unroll the loop
+ for (i = 0; i + 4 * vec_length <= limit; i += 4 * vec_length) {
+ // Load vectors into the Z registers which can range from 128-bit to
2048-bit wide
+ // The predicate register - P determines which bytes are active
+ // svptrue_b8() returns a predictae in which every element is true
Review Comment:
@rmuir -- I tried using `svwhilelt_b8_u32(i, limit)` intrinsic for
generating the predicate in both the unrolled-loop and vector tail but the
performance was actually worse :-(.
To give you an idea of what I did, here is link to the ARM documentation
with code sample
https://developer.arm.com/documentation/102699/0100/Optimizing-with-intrinsics
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]