aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/pop_count/popcount.cpp
blob: 4d34575ffb4c94a2bcd77095e76b5e1026acd632 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "popcount.h"

#include <util/system/defaults.h> 
#include <util/system/yassert.h>
 
#include <string.h>

static const ui8 PopCountLUT8Impl[1 << 8] = {
#define B2(n) n, n + 1, n + 1, n + 2
#define B4(n) B2(n), B2(n + 1), B2(n + 1), B2(n + 2)
#define B6(n) B4(n), B4(n + 1), B4(n + 1), B4(n + 2)
    B6(0), B6(1), B6(1), B6(2)};
 
ui8 const* PopCountLUT8 = PopCountLUT8Impl;

#if !defined(_MSC_VER)
//ICE here for msvc

static const ui8 PopCountLUT16Impl[1 << 16] = {
#define B2(n) n, n + 1, n + 1, n + 2
#define B4(n) B2(n), B2(n + 1), B2(n + 1), B2(n + 2)
#define B6(n) B4(n), B4(n + 1), B4(n + 1), B4(n + 2)
#define B8(n) B6(n), B6(n + 1), B6(n + 1), B6(n + 2)
#define B10(n) B8(n), B8(n + 1), B8(n + 1), B8(n + 2)
#define B12(n) B10(n), B10(n + 1), B10(n + 1), B10(n + 2)
#define B14(n) B12(n), B12(n + 1), B12(n + 1), B12(n + 2)
    B14(0), B14(1), B14(1), B14(2)};
 
ui8 const* PopCountLUT16 = PopCountLUT16Impl;
#endif