3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SSEのpand, AVXのvpandとほぼ同じで長さが512bitになりました。

512bit内の各bitの論理積をとります。

対応するintrinsicsは、_mm512_and_epi32 です。

#include <immintrin.h>
#include <stdio.h>

int in0[16] = {~0,~0,~0,~0,
               ~0,~0,~0,~0,
               ~0,~0,~0,~0,
               ~0,~0,~0,~0};

int and_bits[16] = {0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555,
                    0xaaaaaaaa,
                    0x55555555};

int out[16];

int
main()
{
    __m512i a;
    __m512i b;
    __m512i c;
    int i;

    a = _mm512_loadu_si512(in0);
    b = _mm512_loadu_si512(and_bits);

    c = _mm512_and_epi32(a, b);

    _mm512_storeu_si512(out, c);

    for (i=0; i<16; i++) {
        printf("%2d:%08x\n", i, out[i]);
    }
}
 $ gcc -mavx512f vpand.cpp
 $ sde -skx -- ./a.out
 0:aaaaaaaa
 1:55555555
 2:aaaaaaaa
 3:55555555
 4:aaaaaaaa
 5:55555555
 6:aaaaaaaa
 7:55555555
 8:aaaaaaaa
 9:55555555
10:aaaaaaaa
11:55555555
12:aaaaaaaa
13:55555555
14:aaaaaaaa
15:55555555

SSE, AVXでは、_mm_and_si128(pand), _mm256_and_si256(vpand) のように、全bitの論理積を取る命令しかなく、不便な場合がたくさんありましたが、AVX512になって、これが、_mm512_and_epi32(vpandd) と _mm512_and_epi64(vpandq) に分かれ、32bit内の各bitの論理積、64bit内の各bitの論理積を取れるようになり、大変便利になりました。

次回、@tanakmura が vpandd の補足を書きます(何を補足するか予測できるぐらいちゃんと読んでる人がいたらありがとうございます)

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?