https://stackoverflow.com/questions/34478328/the-best-way-to-shift-a-m128i/34482688#34482688
逻辑右移__m128i reg
b
比特
(逻辑右移reg >> b
)
__m128i right_shift_128i(__m128i reg, int b){
assert(b>=0 && b<128);
// __m128i _mm_bsrli_si128 (__m128i a, int imm8): Shift a right by imm8 bytes while shifting in zeros
__m128i high64 = _mm_bsrli_si128(reg, 8); // high 64 bits of reg shifting to starting from 0th bit
if (b < 64)
{
// high64:low64 -> high64>>b:high64[0:b):low64>>b
// _mm_srli_epi64(reg,b) == high64>>b:low64>>b
// _mm_slli_epi64(high64,64-b) == 0:high64[0:b):(64-b)bits
return _mm_or_si128(_mm_srli_epi64(reg, b), _mm_slli_epi64(high64, 64 - b));
}
else // high64bits are shifted to low64bits
return _mm_srli_epi64(high64, b - 64);
}