I have this C code I would like to try out in Zig.
while (1) {
__m128i xmm_str1 = _mm_loadu_si128((__m128i*)(str1 + i));
__m128i xmm_str2 = _mm_loadu_si128((__m128i*)(str2 + i));
uint32_t result = _mm_cmpistri(xmm_str1, xmm_str2, 0b11000);
i += result;
if (result != 16) return i; // Found a mismatch
}
Unfortunately, the _mm_cmpistri C intrinsic is not yet supported by Zig, so I have to come up with another way to do _mm_cmpistri. I tried to do this with inline assembly. Here is what I have so far:
pub fn mm_cmpistri(noalias str1: []const u8, noalias str2: []const u8) u32 {
return asm ("pcmpistri %[str1], %[str2], 0b11000" // I just hardcoded the flags I want
: [out] "=x" (-> u32),
: [str1] "x" (@as(@Vector(16, u8), str1[0..16].*)),
[str2] "x" (@as(@Vector(16, u8), str2[0..16].*)),
);
}
Unfortunately, I am not sure how to get the data written to the ECX register out and return it. I also keep getting an error that says error: <inline asm>:1:12: invalid operand for instruction. Is there any cheatsheet for inline assembly that could help me figure stuff like this out?