Commit 171d9950 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/perf_improv_polar_encoder' into integration_2024_w14

parents 5f652b17 a0e77330
......@@ -32,6 +32,7 @@
#include <stdint.h>
#include "assertions.h"
#include "common/utils/assertions.h"
#include "nr_common.h"
#include <complex.h>
......@@ -52,6 +53,15 @@ static const uint8_t bit_reverse_table_256[] = {
0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF};
void reverse_bits_u8(uint8_t const* in, size_t sz, uint8_t* out)
{
DevAssert(in != NULL);
DevAssert(out != NULL);
for(size_t i = 0; i < sz; ++i)
out[i] = bit_reverse_table_256[in[i]];
}
// Reverse bits implementation based on http://graphics.stanford.edu/~seander/bithacks.html
uint64_t reverse_bits(uint64_t in, int n_bits)
{
......
......@@ -34,6 +34,7 @@
#define __COMMON_UTILS_NR_NR_COMMON__H__
#include <stdint.h>
#include <stdlib.h>
#include "assertions.h"
#include "PHY/defs_common.h"
......@@ -175,8 +176,11 @@ static inline int get_num_dmrs(uint16_t dmrs_mask ) {
}
uint64_t reverse_bits(uint64_t in, int n_bits);
void reverse_bits_u8(uint8_t const* in, size_t sz, uint8_t* out);
uint64_t from_nrarfcn(int nr_bandP, uint8_t scs_index, uint32_t dl_nrarfcn);
uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint8_t scs_index, uint32_t bw);
int get_first_ul_slot(int nrofDownlinkSlots, int nrofDownlinkSymbols, int nrofUplinkSymbols);
int cce_to_reg_interleaving(const int R, int k, int n_shift, const int C, int L, const int N_regs);
int get_SLIV(uint8_t S, uint8_t L);
......
......@@ -282,7 +282,7 @@ void nr_polar_generate_u(uint64_t *u,
uint16_t N,
uint8_t n_pc);
void nr_polar_uxG(uint64_t *D, const uint64_t *u, const fourDimArray_t *G_N_tab, uint16_t N);
void nr_polar_uxG(uint8_t const* u, size_t N, uint8_t* D);
void nr_polar_info_extraction_from_u(uint64_t *Cprime,
const uint8_t *u,
......
......@@ -485,6 +485,7 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
polarParams->rm_tab[tcnt] = polarParams->rate_matching_pattern[outpos] >> shift;
}
void polar_encoder_fast(uint64_t *A,
void *out,
int32_t crcmask,
......@@ -687,8 +688,8 @@ void polar_encoder_fast(uint64_t *A,
printf("\n");
#endif
uint64_t D[8] = {0};
nr_polar_uxG(D, u, polarParams->G_N_tab, polarParams->N);
uint64_t D[8];
nr_polar_uxG((uint8_t *)u, polarParams->N, (uint8_t *)D);
#ifdef POLAR_CODING_DEBUG
printf("d: ");
......@@ -701,6 +702,7 @@ void polar_encoder_fast(uint64_t *A,
printf("%lu", (D[n1] >> n2) & 1);
}
printf("\n");
fflush(stdout);
#endif
memset((void*)out,0,polarParams->encoderLength>>3);
......
......@@ -30,8 +30,12 @@
* \warning
*/
#include "common/utils/nr/nr_common.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
// TS 38.212 - Section 5.3.1.2 Polar encoding
void nr_polar_generate_u(uint64_t *u,
......@@ -119,23 +123,71 @@ void nr_polar_info_extraction_from_u(uint64_t *Cprime,
}
}
void nr_polar_uxG(uint64_t *D, const uint64_t *u, const fourDimArray_t *G_N_tab, uint16_t N)
static
void encode_packed_byte(uint8_t* in_out)
{
const int N64 = N / 64;
cast2Darray(g_n, uint64_t, G_N_tab);
for (int n = 0; n < N; n++) {
const uint64_t *Gn = g_n[N - 1 - n];
// *in_out ^= 0xAA & (*in_out << 1);
// *in_out ^= 0xCC & (*in_out << 2);
// *in_out ^= *in_out in_out << 4;
//
*in_out ^= 0x55 & (*in_out >> 1);
*in_out ^= 0x33 & (*in_out >> 2);
*in_out ^= *in_out >> 4;
}
int n_ones = 0;
for (int a = 0; a < N64; a++)
n_ones += count_bits_set(u[a] & Gn[a]);
static
void polar_encode_bits(uint8_t* in_out, size_t N)
{
size_t const num_bytes_per_block = N >> 3;
for(size_t i = 0; i < num_bytes_per_block; ++i){
encode_packed_byte(&in_out[i]);
}
}
int n1 = n / 64;
int n2 = n - (n1 * 64);
D[n1] |= ((uint64_t)n_ones & 1) << n2;
static
uint32_t log2_floor(uint32_t x)
{
if(x == 0)
return 0;
uint32_t clz = __builtin_clz(x);
return 31U - clz;
}
static
void polar_encode_bytes(uint8_t* in_out, size_t N)
{
size_t brnch_sz = 1;
size_t n_brnch = N >> 4;
size_t const blck_pwr = log2_floor(N);
for (size_t stage = 3; stage < blck_pwr; ++stage) {
for (size_t brnch = 0; brnch < n_brnch; ++brnch) {
for(size_t byte = 0; byte < brnch_sz; ++byte){
size_t const dst = 2*brnch_sz*brnch + byte;
in_out[dst] ^= in_out[dst + brnch_sz];
}
}
n_brnch >>= 1;
brnch_sz <<= 1;
}
}
void nr_polar_uxG(uint8_t const *u, size_t N, uint8_t *D2)
{
assert(N > 7);
uint8_t tmp[N/8];
for(int i = 0; i < N/8; ++i)
tmp[i] = u[N/8 - 1 - i];
reverse_bits_u8(tmp, N/8, D2);
// Do the encoding/xor for the bottom 3 levels of the tree.
// Thus, data remaining to encode, is in 2^3 type.
polar_encode_bits(D2, N);
// Xor the remaining tree levels. Use bytes for it
polar_encode_bytes(D2, N);
}
void nr_polar_bit_insertion(uint8_t *input,
uint8_t *output,
uint16_t N,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment