HappenLee commented on code in PR #70754:
URL: https://github.com/apache/doris/pull/70754#discussion_r4639292914


##########
be/src/util/md5.cpp:
##########
@@ -142,6 +158,55 @@ struct AVX2MD5Ops {
     }
 };
 
+using NativeMD5Ops = AVX2MD5Ops;
+#elif defined(__aarch64__)
+struct NeonMD5Ops {
+    using Vec = uint32x4_t;
+    static constexpr size_t LANES = 4;
+
+    static bool prefer_serial(size_t total_blocks, size_t max_blocks) {
+        // A long message keeps both SIMD groups running after shorter lanes 
finish.
+        return max_blocks > total_blocks / LANES;
+    }
+
+    static Vec add(Vec a, Vec b) { return vaddq_u32(a, b); }
+    static Vec set1(uint32_t v) { return vdupq_n_u32(v); }
+    static void storeu(void* p, Vec v) {
+        vst1q_u8(static_cast<uint8_t*>(p), vreinterpretq_u8_u32(v));
+    }
+

Review Comment:
   The current expression computes the intended rotate-left. For each 32-bit 
lane, `vsriq_n_u32(a, b, k)` preserves the top `k` bits of `a` and fills the 
low `32 - k` bits with `b >> k`. With `a = x << N` and `k = 32 - N`, those low 
`N` bits are already zero, so the result is exactly `(x << N) | (x >> (32 - 
N))`. [Arm NEON intrinsics 
reference](https://arm-software.github.io/acle/neon_intrinsics/advsimd.html#vector-shift-right-and-insert)
   
   For example, rotating `0x80000001` left by 7 gives `0x000000c0` with the 
current expression. The suggested `vsriq_n_u32(x, x, 25)` gives `0x80000040` 
because it preserves the high bits of the unshifted input.
   
   The existing `Md5Test.batch_known_vectors` exercises the NEON kernel with 
seven inputs. Its block counts are `[1, 1, 1, 1, 1, 2, 2]`, so the maximum of 2 
fits the dispatch threshold of `9 / 4 = 2` and the batch stays on the SIMD 
path. It checks each digest against a known MD5 value. All seven tests passed 
under ASAN/UBSAN on native AArch64 with both GCC 14 and Clang 20 using the same 
implementation and test sources as this PR head. [Native ARM test 
run](https://github.com/HappenLee/incubator-doris/actions/runs/44500133646)
   



-- 
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]

Reply via email to