Function no_std_compat::arch::x86_64::_mm256_shuffle_epi8

1.27.0 · source ·
pub unsafe fn _mm256_shuffle_epi8(a: __m256i, b: __m256i) -> __m256i
Available on x86-64 only.
Expand description

Shuffles bytes from a according to the content of b.

For each of the 128-bit low and high halves of the vectors, the last 4 bits of each byte of b are used as addresses into the respective low or high 16 bytes of a. That is, the halves are shuffled separately.

In addition, if the highest significant bit of a byte of b is set, the respective destination byte is set to 0.

Picturing a and b as [u8; 32], _mm256_shuffle_epi8 is logically equivalent to:

fn mm256_shuffle_epi8(a: [u8; 32], b: [u8; 32]) -> [u8; 32] {
    let mut r = [0; 32];
    for i in 0..16 {
        // if the most significant bit of b is set,
        // then the destination byte is set to 0.
        if b[i] & 0x80 == 0u8 {
            r[i] = a[(b[i] % 16) as usize];
        }
        if b[i + 16] & 0x80 == 0u8 {
            r[i + 16] = a[(b[i + 16] % 16 + 16) as usize];
        }
    }
    r
}

Intel’s documentation