I am finding difficulties in creating a code for this seemingly easy problem.
Given a packed 8 bits integer, substitute one byte with another if present.
For instance, I want to substitute 0x06
with 0x01
, so I can do the following with res
as the input to find 0x06
:
// Bytes to be manipulated
res = _mm_set_epi8(0x00, 0x03, 0x02, 0x06, 0x0F, 0x02, 0x02, 0x06, 0x0A, 0x03, 0x02, 0x06, 0x00, 0x00, 0x02, 0x06);
// Target value and substitution
val = _mm_set1_epi8(0x06);
sub = _mm_set1_epi8(0x01);
// Find the target
sse = _mm_cmpeq_epi8(res, val);
// Isolate target
sse = _mm_and_si128(res, sse);
// Isolate remaining bytes
adj = _mm_andnot_si128(sse, res);
Now I don't know how to proceed to or
those two parts, I need to remove the target and substitute it with the replaced byte.
What SIMD instruction am I missing here?
As with other questions, I am limited to AVX, I have no better processor.