2
0

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.

vplzcntd

Last updated at Posted at 2014-12-21

clz が SIMD になりました。16並列で 32bit clz します。

clz は上のほうから見ます。0 の場合は32になります。

僕はいつまでたっても、clz, ctz どっちがどっちで、bsr, bsf がどっちなのか忘れますね。(どうでもいい情報。)

http://en.wikipedia.org/wiki/Find_first_set#Hardware_support なるほど?

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

unsigned int in[16] = {
    1,
    1<<31,
    (1<<31) | 1,
    (1<<16),

    0xaaaaaaaa,
    0x55555555,

    ~0,
    0,
};

unsigned int out[16];

void
dump_bits32(unsigned int a)
{
    for (int i=0; i<32; i++) {
        if (a & (1<<(31-i))) {
            putchar('1');
        } else {
            putchar('0');
        }
    }
    putchar(':');
}



int
main()
{
    __m512i v0 = _mm512_loadu_si512(in);
    v0 = _mm512_lzcnt_epi32(v0);

    _mm512_storeu_si512(out, v0);

    for (int i=0; i<8; i++) {
        dump_bits32(in[i]);
        printf("%d\n", out[i]);
    }
}
00000000000000000000000000000001:31
10000000000000000000000000000000:0
10000000000000000000000000000001:0
00000000000000010000000000000000:15
10101010101010101010101010101010:0
01010101010101010101010101010101:1
11111111111111111111111111111111:0
00000000000000000000000000000000:32

何故か、AVX-512CD(conflict detection)拡張です。

明日は、@tanakmura が vrangeps について書きます。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?