use uint32_t for the frozen bits

This commit is contained in:
Ahmet Inan 2021-07-12 19:11:15 +02:00
commit 631ec8beef
6 changed files with 312 additions and 44 deletions

View file

@ -16,26 +16,135 @@ struct PolarTree
{ {
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
static const int N = 1 << M; static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, const uint8_t *frozen) static void decode(TYPE **message, TYPE *hard, TYPE *soft, const uint32_t *frozen)
{ {
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]); soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen); PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen);
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]); soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen+N/2); PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen+N/2/32);
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]); hard[i] = PH::qmul(hard[i], hard[i+N/2]);
} }
}; };
template <typename TYPE>
struct PolarTree<TYPE, 6>
{
typedef PolarHelper<TYPE> PH;
static const int M = 6;
static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, const uint32_t *frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen[0]);
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen[1]);
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]);
}
};
template <typename TYPE>
struct PolarTree<TYPE, 5>
{
typedef PolarHelper<TYPE> PH;
static const int M = 5;
static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]);
}
};
template <typename TYPE>
struct PolarTree<TYPE, 4>
{
typedef PolarHelper<TYPE> PH;
static const int M = 4;
static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]);
}
};
template <typename TYPE>
struct PolarTree<TYPE, 3>
{
typedef PolarHelper<TYPE> PH;
static const int M = 3;
static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]);
}
};
template <typename TYPE>
struct PolarTree<TYPE, 2>
{
typedef PolarHelper<TYPE> PH;
static const int M = 2;
static const int N = 1 << M;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], soft[i+N], soft[i+N/2+N]);
PolarTree<TYPE, M-1>::decode(message, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(hard[i], hard[i+N/2]);
}
};
template <typename TYPE>
struct PolarTree<TYPE, 1>
{
typedef PolarHelper<TYPE> PH;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{
soft[1] = PH::prod(soft[2], soft[3]);
PolarTree<TYPE, 0>::decode(message, hard, soft, frozen & 1);
soft[1] = PH::madd(hard[0], soft[2], soft[3]);
PolarTree<TYPE, 0>::decode(message, hard+1, soft, frozen >> 1);
hard[0] = PH::qmul(hard[0], hard[1]);
}
};
template <typename TYPE> template <typename TYPE>
struct PolarTree<TYPE, 0> struct PolarTree<TYPE, 0>
{ {
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
static void decode(TYPE **message, TYPE *hard, TYPE *soft, const uint8_t *frozen) static void decode(TYPE **message, TYPE *hard, TYPE *soft, uint32_t frozen)
{ {
if (*frozen) { if (frozen) {
*hard = PH::one(); *hard = PH::one();
} else { } else {
*hard = PH::signum(soft[1]); *hard = PH::signum(soft[1]);
@ -47,12 +156,13 @@ struct PolarTree<TYPE, 0>
template <typename TYPE, int MAX_M> template <typename TYPE, int MAX_M>
class PolarDecoder class PolarDecoder
{ {
static_assert(MAX_M >= 5 && MAX_M <= 29);
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
static const int MAX_N = 1 << MAX_M; static const int MAX_N = 1 << MAX_M;
TYPE soft[2*MAX_N]; TYPE soft[2*MAX_N];
TYPE hard[MAX_N]; TYPE hard[MAX_N];
public: public:
void operator()(TYPE *message, const TYPE *codeword, const uint8_t *frozen, int level) void operator()(TYPE *message, const TYPE *codeword, const uint32_t *frozen, int level)
{ {
assert(level <= MAX_M); assert(level <= MAX_M);
int length = 1 << level; int length = 1 << level;
@ -60,12 +170,7 @@ public:
soft[length+i] = codeword[i]; soft[length+i] = codeword[i];
switch (level) { switch (level) {
case 0: PolarTree<TYPE, 0>::decode(&message, hard, soft, frozen); break; case 5: PolarTree<TYPE, 5>::decode(&message, hard, soft, *frozen); break;
case 1: PolarTree<TYPE, 1>::decode(&message, hard, soft, frozen); break;
case 2: PolarTree<TYPE, 2>::decode(&message, hard, soft, frozen); break;
case 3: PolarTree<TYPE, 3>::decode(&message, hard, soft, frozen); break;
case 4: PolarTree<TYPE, 4>::decode(&message, hard, soft, frozen); break;
case 5: PolarTree<TYPE, 5>::decode(&message, hard, soft, frozen); break;
case 6: PolarTree<TYPE, 6>::decode(&message, hard, soft, frozen); break; case 6: PolarTree<TYPE, 6>::decode(&message, hard, soft, frozen); break;
case 7: PolarTree<TYPE, 7>::decode(&message, hard, soft, frozen); break; case 7: PolarTree<TYPE, 7>::decode(&message, hard, soft, frozen); break;
case 8: PolarTree<TYPE, 8>::decode(&message, hard, soft, frozen); break; case 8: PolarTree<TYPE, 8>::decode(&message, hard, soft, frozen); break;

View file

@ -14,13 +14,17 @@ template <typename TYPE>
class PolarEncoder class PolarEncoder
{ {
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
static bool get(const uint32_t *bits, int idx)
{
return (bits[idx/32] >> (idx%32)) & 1;
}
public: public:
void operator()(TYPE *codeword, const TYPE *message, const uint8_t *frozen, int level) void operator()(TYPE *codeword, const TYPE *message, const uint32_t *frozen, int level)
{ {
int length = 1 << level; int length = 1 << level;
for (int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : *message++; TYPE msg0 = get(frozen, i) ? PH::one() : *message++;
TYPE msg1 = frozen[i+1] ? PH::one() : *message++; TYPE msg1 = get(frozen, i+1) ? PH::one() : *message++;
codeword[i] = PH::qmul(msg0, msg1); codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1; codeword[i+1] = msg1;
} }
@ -35,13 +39,17 @@ template <typename TYPE>
class PolarSysEnc class PolarSysEnc
{ {
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
static bool get(const uint32_t *bits, int idx)
{
return (bits[idx/32] >> (idx%32)) & 1;
}
public: public:
void operator()(TYPE *codeword, const TYPE *message, const uint8_t *frozen, int level) void operator()(TYPE *codeword, const TYPE *message, const uint32_t *frozen, int level)
{ {
int length = 1 << level; int length = 1 << level;
for (int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : *message++; TYPE msg0 = get(frozen, i) ? PH::one() : *message++;
TYPE msg1 = frozen[i+1] ? PH::one() : *message++; TYPE msg1 = get(frozen, i+1) ? PH::one() : *message++;
codeword[i] = PH::qmul(msg0, msg1); codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1; codeword[i+1] = msg1;
} }
@ -50,8 +58,8 @@ public:
for (int j = i; j < i + h; ++j) for (int j = i; j < i + h; ++j)
codeword[j] = PH::qmul(codeword[j], codeword[j+h]); codeword[j] = PH::qmul(codeword[j], codeword[j+h]);
for (int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : codeword[i]; TYPE msg0 = get(frozen, i) ? PH::one() : codeword[i];
TYPE msg1 = frozen[i+1] ? PH::one() : codeword[i+1]; TYPE msg1 = get(frozen, i+1) ? PH::one() : codeword[i+1];
codeword[i] = PH::qmul(msg0, msg1); codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1; codeword[i+1] = msg1;
} }

View file

@ -12,23 +12,32 @@ namespace CODE {
class PolarFreezer class PolarFreezer
{ {
static void freeze(uint8_t *bits, long double pe, long double th, int i, int h) static bool get_bit(const uint32_t *bits, int idx)
{
return (bits[idx/32] >> (idx%32)) & 1;
}
static void set_bit(uint32_t *bits, int idx, bool val)
{
bits[idx/32] &= ~(1 << (idx%32));
bits[idx/32] |= (uint32_t)val << (idx%32);
}
static void freeze(uint32_t *bits, long double pe, long double th, int i, int h)
{ {
if (h) { if (h) {
freeze(bits, pe * (2-pe), th, i, h/2); freeze(bits, pe * (2-pe), th, i, h/2);
freeze(bits, pe * pe, th, i+h, h/2); freeze(bits, pe * pe, th, i+h, h/2);
} else { } else {
bits[i] = pe > th; set_bit(bits, i, pe > th);
} }
} }
public: public:
int operator()(uint8_t *frozen_bits, int level, long double erasure_probability = 0.5L, long double freezing_threshold = 0.5L) int operator()(uint32_t *frozen_bits, int level, long double erasure_probability = 0.5L, long double freezing_threshold = 0.5L)
{ {
int length = 1 << level; int length = 1 << level;
freeze(frozen_bits, erasure_probability, freezing_threshold, 0, length / 2); freeze(frozen_bits, erasure_probability, freezing_threshold, 0, length / 2);
int K = 0; int K = length;
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
K += !frozen_bits[i]; K -= (frozen_bits[i/32] >> (i%32)) & 1;
return K; return K;
} }
}; };
@ -36,6 +45,14 @@ public:
template <int MAX_M> template <int MAX_M>
class PolarCodeConst0 class PolarCodeConst0
{ {
static void inform_bit(uint32_t *bits, int idx)
{
bits[idx/32] &= ~(1 << (idx%32));
}
static void frozen_bit(uint32_t *bits, int idx)
{
bits[idx/32] |= 1 << (idx%32);
}
void compute(long double pe, int i, int h) void compute(long double pe, int i, int h)
{ {
if (h) { if (h) {
@ -48,7 +65,7 @@ class PolarCodeConst0
long double prob[1<<MAX_M]; long double prob[1<<MAX_M];
int index[1<<MAX_M]; int index[1<<MAX_M];
public: public:
void operator()(uint8_t *frozen_bits, int level, int K, long double erasure_probability = std::exp(-1.L)) void operator()(uint32_t *frozen_bits, int level, int K, long double erasure_probability = std::exp(-1.L))
{ {
assert(level <= MAX_M); assert(level <= MAX_M);
int length = 1 << level; int length = 1 << level;
@ -57,9 +74,9 @@ public:
index[i] = i; index[i] = i;
std::nth_element(index, index+K, index+length, [this](int a, int b){ return prob[a] < prob[b]; }); std::nth_element(index, index+K, index+length, [this](int a, int b){ return prob[a] < prob[b]; });
for (int i = 0; i < K; ++i) for (int i = 0; i < K; ++i)
frozen_bits[index[i]] = 0; inform_bit(frozen_bits, index[i]);
for (int i = K; i < length; ++i) for (int i = K; i < length; ++i)
frozen_bits[index[i]] = 1; frozen_bit(frozen_bits, index[i]);
} }
}; };

View file

@ -18,14 +18,146 @@ struct PolarListTree
typedef typename PH::PATH PATH; typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP; typedef typename PH::MAP MAP;
static const int N = 1 << M; static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, const uint8_t *frozen) static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, const uint32_t *frozen)
{ {
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]); soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen); MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen);
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap)); soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen+N/2); MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen+N/2/32);
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 6>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 6;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, const uint32_t *frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen[0]);
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen[1]);
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 5>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 5;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 4>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 4;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 3>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 3;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 2>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 2;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap);
}
};
template <typename TYPE>
struct PolarListTree<TYPE, 1>
{
typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP;
static const int M = 1;
static const int N = 1 << M;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::prod(soft[i+N], soft[i+N/2+N]);
MAP lmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard, soft, frozen & ((1<<(1<<(M-1)))-1));
for (int i = 0; i < N/2; ++i)
soft[i+N/2] = PH::madd(hard[i], vshuf(soft[i+N], lmap), vshuf(soft[i+N/2+N], lmap));
MAP rmap = PolarListTree<TYPE, M-1>::decode(metric, message, maps, count, hard+N/2, soft, frozen >> (N/2));
for (int i = 0; i < N/2; ++i) for (int i = 0; i < N/2; ++i)
hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]); hard[i] = PH::qmul(vshuf(hard[i], rmap), hard[i+N/2]);
return vshuf(lmap, rmap); return vshuf(lmap, rmap);
@ -38,11 +170,11 @@ struct PolarListTree<TYPE, 0>
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
typedef typename PH::PATH PATH; typedef typename PH::PATH PATH;
typedef typename PH::MAP MAP; typedef typename PH::MAP MAP;
static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, const uint8_t *frozen) static MAP decode(PATH *metric, TYPE *message, MAP *maps, int *count, TYPE *hard, TYPE *soft, uint32_t frozen)
{ {
MAP map; MAP map;
TYPE hrd, sft = soft[1]; TYPE hrd, sft = soft[1];
if (*frozen) { if (frozen) {
for (int k = 0; k < TYPE::SIZE; ++k) for (int k = 0; k < TYPE::SIZE; ++k)
if (sft.v[k] < 0) if (sft.v[k] < 0)
metric[k] -= sft.v[k]; metric[k] -= sft.v[k];
@ -80,6 +212,7 @@ struct PolarListTree<TYPE, 0>
template <typename TYPE, int MAX_M> template <typename TYPE, int MAX_M>
class PolarListDecoder class PolarListDecoder
{ {
static_assert(MAX_M >= 5 && MAX_M <= 29);
typedef PolarHelper<TYPE> PH; typedef PolarHelper<TYPE> PH;
typedef typename TYPE::value_type VALUE; typedef typename TYPE::value_type VALUE;
typedef typename PH::PATH PATH; typedef typename PH::PATH PATH;
@ -89,7 +222,7 @@ class PolarListDecoder
TYPE hard[MAX_N]; TYPE hard[MAX_N];
MAP maps[MAX_N]; MAP maps[MAX_N];
public: public:
void operator()(PATH *metric, TYPE *message, const VALUE *codeword, const uint8_t *frozen, int level) void operator()(PATH *metric, TYPE *message, const VALUE *codeword, const uint32_t *frozen, int level)
{ {
assert(level <= MAX_M); assert(level <= MAX_M);
int count = 0; int count = 0;
@ -101,12 +234,7 @@ public:
soft[length+i] = vdup<TYPE>(codeword[i]); soft[length+i] = vdup<TYPE>(codeword[i]);
switch (level) { switch (level) {
case 0: PolarListTree<TYPE, 0>::decode(metric, message, maps, &count, hard, soft, frozen); break; case 5: PolarListTree<TYPE, 5>::decode(metric, message, maps, &count, hard, soft, *frozen); break;
case 1: PolarListTree<TYPE, 1>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 2: PolarListTree<TYPE, 2>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 3: PolarListTree<TYPE, 3>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 4: PolarListTree<TYPE, 4>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 5: PolarListTree<TYPE, 5>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 6: PolarListTree<TYPE, 6>::decode(metric, message, maps, &count, hard, soft, frozen); break; case 6: PolarListTree<TYPE, 6>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 7: PolarListTree<TYPE, 7>::decode(metric, message, maps, &count, hard, soft, frozen); break; case 7: PolarListTree<TYPE, 7>::decode(metric, message, maps, &count, hard, soft, frozen); break;
case 8: PolarListTree<TYPE, 8>::decode(metric, message, maps, &count, hard, soft, frozen); break; case 8: PolarListTree<TYPE, 8>::decode(metric, message, maps, &count, hard, soft, frozen); break;

View file

@ -17,6 +17,11 @@ Copyright 2020 Ahmet Inan <inan@aicodix.de>
#include "polar_encoder.hh" #include "polar_encoder.hh"
#include "polar_freezer.hh" #include "polar_freezer.hh"
bool get_bit(const uint32_t *bits, int idx)
{
return (bits[idx/32] >> (idx%32)) & 1;
}
int main() int main()
{ {
const int M = 16; const int M = 16;
@ -42,7 +47,7 @@ int main()
typedef std::default_random_engine generator; typedef std::default_random_engine generator;
typedef std::uniform_int_distribution<int> distribution; typedef std::uniform_int_distribution<int> distribution;
auto data = std::bind(distribution(0, 1), generator(rd())); auto data = std::bind(distribution(0, 1), generator(rd()));
auto frozen = new uint8_t[N]; auto frozen = new uint32_t[(N+31)/32];
auto codeword = new code_type[N]; auto codeword = new code_type[N];
auto temp = new simd_type[N]; auto temp = new simd_type[N];
@ -101,7 +106,7 @@ int main()
CODE::PolarSysEnc<code_type> sysenc; CODE::PolarSysEnc<code_type> sysenc;
sysenc(codeword, message, frozen, M); sysenc(codeword, message, frozen, M);
for (int i = 0, j = 0; i < N; ++i) for (int i = 0, j = 0; i < N; ++i)
if (!frozen[i]) if (!get_bit(frozen, i))
assert(codeword[i] == message[j++]); assert(codeword[i] == message[j++]);
} else { } else {
CODE::PolarEncoder<code_type> encode; CODE::PolarEncoder<code_type> encode;
@ -138,7 +143,7 @@ int main()
CODE::PolarEncoder<simd_type> encode; CODE::PolarEncoder<simd_type> encode;
encode(temp, decoded, frozen, M); encode(temp, decoded, frozen, M);
for (int i = 0, j = 0; i < N; ++i) for (int i = 0, j = 0; i < N; ++i)
if (!frozen[i]) if (!get_bit(frozen, i))
decoded[j++] = temp[i]; decoded[j++] = temp[i];
} }

View file

@ -17,6 +17,11 @@ Copyright 2020 Ahmet Inan <inan@aicodix.de>
#include "polar_encoder.hh" #include "polar_encoder.hh"
#include "polar_freezer.hh" #include "polar_freezer.hh"
bool get_bit(const uint32_t *bits, int idx)
{
return (bits[idx/32] >> (idx%32)) & 1;
}
int main() int main()
{ {
const int M = 20; const int M = 20;
@ -34,7 +39,7 @@ int main()
typedef std::default_random_engine generator; typedef std::default_random_engine generator;
typedef std::uniform_int_distribution<int> distribution; typedef std::uniform_int_distribution<int> distribution;
auto data = std::bind(distribution(0, 1), generator(rd())); auto data = std::bind(distribution(0, 1), generator(rd()));
auto frozen = new uint8_t[N]; auto frozen = new uint32_t[(N+31)/32];
auto codeword = new code_type[N]; auto codeword = new code_type[N];
auto temp = new code_type[N]; auto temp = new code_type[N];
@ -92,7 +97,7 @@ int main()
CODE::PolarSysEnc<code_type> sysenc; CODE::PolarSysEnc<code_type> sysenc;
sysenc(codeword, message, frozen, M); sysenc(codeword, message, frozen, M);
for (int i = 0, j = 0; i < N; ++i) for (int i = 0, j = 0; i < N; ++i)
if (!frozen[i]) if (!get_bit(frozen, i))
assert(codeword[i] == message[j++]); assert(codeword[i] == message[j++]);
} else { } else {
CODE::PolarEncoder<code_type> encode; CODE::PolarEncoder<code_type> encode;
@ -129,7 +134,7 @@ int main()
CODE::PolarEncoder<code_type> encode; CODE::PolarEncoder<code_type> encode;
encode(temp, decoded, frozen, M); encode(temp, decoded, frozen, M);
for (int i = 0, j = 0; i < N; ++i) for (int i = 0, j = 0; i < N; ++i)
if (!frozen[i]) if (!get_bit(frozen, i))
decoded[j++] = temp[i]; decoded[j++] = temp[i];
} }