Commit 5dbfc4b6 authored by laurent's avatar laurent

ldpc check based on crc

parent dae79d1f
...@@ -399,8 +399,8 @@ unsigned int crc8 (unsigned char * inptr, int bitlen); ...@@ -399,8 +399,8 @@ unsigned int crc8 (unsigned char * inptr, int bitlen);
@param bitlen length of inputs in bits*/ @param bitlen length of inputs in bits*/
unsigned int crc6 (unsigned char * inptr, int bitlen); unsigned int crc6 (unsigned char * inptr, int bitlen);
int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type); int check_crc(uint8_t *decoded_bytes, uint32_t n, uint8_t crc_type);
/*!\fn void phy_viterbi_dot11_sse2(int8_t *y, uint8_t *decoded_bytes, uint16_t n,int offset,int traceback) /*!\fn void phy_viterbi_dot11_sse2(int8_t *y, uint8_t *decoded_bytes, uint16_t n,int offset,int traceback)
\brief This routine performs a SIMD optmized Viterbi decoder for the 802.11 64-state convolutional code. It can be \brief This routine performs a SIMD optmized Viterbi decoder for the 802.11 64-state convolutional code. It can be
run in segments with final trace back after last segment. run in segments with final trace back after last segment.
......
...@@ -313,7 +313,7 @@ uint32_t crc6(unsigned char* inptr, int bitlen) ...@@ -313,7 +313,7 @@ uint32_t crc6(unsigned char* inptr, int bitlen)
return crc; return crc;
} }
int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) int check_crc(uint8_t* decoded_bytes, uint32_t n, uint8_t crc_type)
{ {
uint32_t crc=0,oldcrc=0; uint32_t crc=0,oldcrc=0;
uint8_t crc_len=0; uint8_t crc_len=0;
......
...@@ -2728,41 +2728,25 @@ static inline void nrLDPC_bnProc(t_nrLDPC_lut* p_lut, int8_t* bnProcBuf, int8_t* ...@@ -2728,41 +2728,25 @@ static inline void nrLDPC_bnProc(t_nrLDPC_lut* p_lut, int8_t* bnProcBuf, int8_t*
*/ */
static inline void nrLDPC_llr2bit(int8_t* out, int8_t* llrOut, uint16_t numLLR) static inline void nrLDPC_llr2bit(int8_t* out, int8_t* llrOut, uint16_t numLLR)
{ {
__m256i* p_llrOut = (__m256i*) llrOut; __m256i* p_llrOut = (__m256i*)llrOut;
__m256i* p_out = (__m256i*) out; __m256i* p_out = (__m256i*)out;
int8_t* p_llrOut8; const int M = numLLR >> 5;
int8_t* p_out8; const int Mr = numLLR & 31;
uint32_t i;
uint32_t M = numLLR>>5;
uint32_t Mr = numLLR&31;
const __m256i* p_zeros = (__m256i*) zeros256_epi8; const __m256i* p_zeros = (__m256i*)zeros256_epi8;
const __m256i* p_ones = (__m256i*) ones256_epi8; const __m256i* p_ones = (__m256i*)ones256_epi8;
for (i=0; i<M; i++) for (int i = 0; i < M; i++) {
{ *p_out++ = simde_mm256_and_si256(*p_ones, simde_mm256_cmpgt_epi8(*p_zeros, *p_llrOut));
*p_out++ = simde_mm256_and_si256(*p_ones, simde_mm256_cmpgt_epi8(*p_zeros, *p_llrOut)); p_llrOut++;
p_llrOut++; }
}
if (Mr > 0) // Remaining LLRs that do not fit in multiples of 32 bytes
{ int8_t* p_llrOut8 = (int8_t*)p_llrOut;
// Remaining LLRs that do not fit in multiples of 32 bytes int8_t* p_out8 = (int8_t*)p_out;
p_llrOut8 = (int8_t*) p_llrOut;
p_out8 = (int8_t*) p_out;
for (i=0; i<Mr; i++) for (int i = 0; i < Mr; i++)
{ p_out8[i] = p_llrOut8[i] < 0;
if (p_llrOut8[i] < 0)
{
p_out8[i] = 1;
}
else
{
p_out8[i] = 0;
}
}
}
} }
/** /**
...@@ -2778,44 +2762,29 @@ static inline void nrLDPC_llr2bitPacked(int8_t* out, int8_t* llrOut, uint16_t nu ...@@ -2778,44 +2762,29 @@ static inline void nrLDPC_llr2bitPacked(int8_t* out, int8_t* llrOut, uint16_t nu
{ {
/** Vector of indices for shuffling input */ /** Vector of indices for shuffling input */
const uint8_t constShuffle_256_epi8[32] __attribute__ ((aligned(32))) = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8}; const uint8_t constShuffle_256_epi8[32] __attribute__ ((aligned(32))) = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
const __m256i* p_shuffle = (__m256i*)constShuffle_256_epi8;
__m256i* p_llrOut = (__m256i*) llrOut; __m256i* p_llrOut = (__m256i*) llrOut;
uint32_t* p_bits = (uint32_t*) out; uint32_t* p_bits = (uint32_t*) out;
__m256i inPerm; const uint32_t M = numLLR >> 5;
int8_t* p_llrOut8; const uint32_t Mr = numLLR & 31;
uint32_t bitsTmp = 0;
uint32_t i; for (uint32_t i = 0; i < M; i++) {
uint32_t M = numLLR>>5; // Move LSB to MSB on 8 bits
uint32_t Mr = numLLR&31; const __m256i inPerm = simde_mm256_shuffle_epi8(*p_llrOut, *p_shuffle);
const __m256i* p_shuffle = (__m256i*) constShuffle_256_epi8; // Hard decision
*p_bits++ = simde_mm256_movemask_epi8(inPerm);
for (i=0; i<M; i++) p_llrOut++;
{
// Move LSB to MSB on 8 bits
inPerm = simde_mm256_shuffle_epi8(*p_llrOut,*p_shuffle);
// Hard decision
*p_bits++ = simde_mm256_movemask_epi8(inPerm);
p_llrOut++;
} }
if (Mr > 0) // Remaining LLRs that do not fit in multiples of 32 bytes
{ if (Mr) {
// Remaining LLRs that do not fit in multiples of 32 bytes const int8_t* p_llrOut8 = (int8_t*)p_llrOut;
p_llrOut8 = (int8_t*) p_llrOut; uint32_t bitsTmp = 0;
for (uint32_t i = 0; i < Mr; i++)
for (i=0; i<Mr; i++) bitsTmp |= (p_llrOut8[i] < 0) << ((7 - i) + (16 * (i / 8)));
{ *p_bits = bitsTmp;
if (p_llrOut8[i] < 0)
{
bitsTmp |= (1<<((7-i) + (16*(i/8))));
}
else
{
bitsTmp |= (0<<((7-i) + (16*(i/8))));
}
}
} }
*p_bits = bitsTmp;
} }
#endif #endif
...@@ -88,6 +88,7 @@ typedef struct nrLDPC_dec_params { ...@@ -88,6 +88,7 @@ typedef struct nrLDPC_dec_params {
uint8_t numMaxIter; /**< Maximum number of iterations */ uint8_t numMaxIter; /**< Maximum number of iterations */
int block_length; int block_length;
e_nrLDPC_outMode outMode; /**< Output format */ e_nrLDPC_outMode outMode; /**< Output format */
int crc_type;
} t_nrLDPC_dec_params; } t_nrLDPC_dec_params;
/** /**
......
...@@ -551,7 +551,8 @@ int nr_rate_matching_ldpc_rx(uint32_t Tbslbrm, ...@@ -551,7 +551,8 @@ int nr_rate_matching_ldpc_rx(uint32_t Tbslbrm,
printf("nr_rate_matching_ldpc_rx: Clear %d, E %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", clear, E, ind, Ncb, rvidx, Tbslbrm); printf("nr_rate_matching_ldpc_rx: Clear %d, E %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", clear, E, ind, Ncb, rvidx, Tbslbrm);
#endif #endif
if (clear==1) memset(w,0,Ncb*sizeof(int16_t)); if (clear == 1)
memset(w, 0, Ncb * sizeof(int16_t));
k=0; k=0;
......
...@@ -243,21 +243,9 @@ static void nr_processULSegment(void *arg) ...@@ -243,21 +243,9 @@ static void nr_processULSegment(void *arg)
////////////////////////////////// pl =====> llrProcBuf ////////////////////////////////// ////////////////////////////////// pl =====> llrProcBuf //////////////////////////////////
p_decoderParms->block_length = length_dec; p_decoderParms->block_length = length_dec;
p_decoderParms->crc_type = crc_type;
rdata->decodeIterations = nrLDPC_decoder(p_decoderParms, (int8_t *)&pl[0], llrProcBuf, p_procTime, &ulsch_harq->abort_decode); rdata->decodeIterations = nrLDPC_decoder(p_decoderParms, (int8_t *)&pl[0], llrProcBuf, p_procTime, &ulsch_harq->abort_decode);
if (rdata->decodeIterations == p_decoderParms->numMaxIter+1 ) {
// We have not decoded succesfully and we have not aborted
// We check the CRC, itf it is ok, let's assume the payload is correctly decoded
// (so the remaining errors are only in the redundancy (parity) bits)
if (check_crc((uint8_t *)llrProcBuf, length_dec, ulsch_harq->F, crc_type)) {
PRINT_CRC_CHECK(LOG_I(PHY,"Segment %d CRC OK, iterations %d/%d\n",r,rdata->decodeIterations,max_ldpc_iterations));
rdata->decodeIterations = p_decoderParms->numMaxIter;
} else {
PRINT_CRC_CHECK(LOG_I(PHY,"CRC NOK\n"));
rdata->decodeIterations = max_ldpc_iterations + 1;
}
}
if (rdata->decodeIterations <= p_decoderParms->numMaxIter) if (rdata->decodeIterations <= p_decoderParms->numMaxIter)
memcpy(ulsch_harq->c[r],llrProcBuf, Kr>>3); memcpy(ulsch_harq->c[r],llrProcBuf, Kr>>3);
//stop_meas(&phy_vars_gNB->ulsch_ldpc_decoding_stats); //stop_meas(&phy_vars_gNB->ulsch_ldpc_decoding_stats);
...@@ -273,14 +261,20 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, ...@@ -273,14 +261,20 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
uint8_t harq_pid, uint8_t harq_pid,
uint32_t G) uint32_t G)
{ {
if (!ulsch_llr) {
LOG_E(PHY, "ulsch_decoding.c: NULL ulsch_llr pointer\n");
return -1;
}
NR_gNB_ULSCH_t *ulsch = &phy_vars_gNB->ulsch[ULSCH_id]; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_gNB_ULSCH_DECODING, 1);
NR_gNB_PUSCH *pusch = &phy_vars_gNB->pusch_vars[ULSCH_id];
NR_UL_gNB_HARQ_t *harq_process = ulsch->harq_process;
if (!harq_process) { NR_gNB_ULSCH_t *ulsch = &phy_vars_gNB->ulsch[ULSCH_id];
LOG_E(PHY,"ulsch_decoding.c: NULL harq_process pointer\n"); NR_gNB_PUSCH *pusch = &phy_vars_gNB->pusch_vars[ULSCH_id];
return -1; NR_UL_gNB_HARQ_t *harq_process = ulsch->harq_process;
if (!harq_process) {
LOG_E(PHY, "ulsch_decoding.c: NULL harq_process pointer\n");
return -1;
} }
uint8_t dtx_det = 0; uint8_t dtx_det = 0;
...@@ -296,12 +290,6 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, ...@@ -296,12 +290,6 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
uint8_t n_layers = pusch_pdu->nrOfLayers; uint8_t n_layers = pusch_pdu->nrOfLayers;
// ------------------------------------------------------------------ // ------------------------------------------------------------------
if (!ulsch_llr) {
LOG_E(PHY,"ulsch_decoding.c: NULL ulsch_llr pointer\n");
return -1;
}
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_gNB_ULSCH_DECODING,1);
harq_process->TBS = pusch_pdu->pusch_data.tb_size; harq_process->TBS = pusch_pdu->pusch_data.tb_size;
dtx_det = 0; dtx_det = 0;
...@@ -493,13 +481,13 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, ...@@ -493,13 +481,13 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
harq_process->c[r][m] = (uint8_t)llrProcBuf[m]; harq_process->c[r][m] = (uint8_t)llrProcBuf[m];
} }
if (check_crc((uint8_t *)llrProcBuf, length_dec, harq_process->F, crc_type)) { if (check_crc((uint8_t *)llrProcBuf, length_dec, crc_type)) {
PRINT_CRC_CHECK(LOG_I(PHY, "Segment %d CRC OK\n", r)); PRINT_CRC_CHECK(LOG_I(PHY, "Segment %d CRC OK\n", r));
decodeIterations = 2; decodeIterations = 2;
} else { } else {
PRINT_CRC_CHECK(LOG_I(PHY, "segment %d CRC NOK\n", r)); PRINT_CRC_CHECK(LOG_I(PHY, "segment %d CRC NOK\n", r));
decodeIterations = ulsch->max_ldpc_iterations + 1; decodeIterations = ulsch->max_ldpc_iterations + 1;
} }
//} //}
r_offset += E; r_offset += E;
......
...@@ -113,7 +113,7 @@ static bool nr_ue_postDecode(PHY_VARS_NR_UE *phy_vars_ue, ...@@ -113,7 +113,7 @@ static bool nr_ue_postDecode(PHY_VARS_NR_UE *phy_vars_ue,
int A = dlsch->dlsch_config.TBS; int A = dlsch->dlsch_config.TBS;
int crc_length = A > 3824 ? 3 : 2; int crc_length = A > 3824 ? 3 : 2;
int crc_type = A > 3824 ? CRC24_A : CRC16; int crc_type = A > 3824 ? CRC24_A : CRC16;
if (!check_crc(b, A + crc_length*8, 0 /* F - unused */, crc_type)) { if (!check_crc(b, A + crc_length * 8, crc_type)) {
harq_process->ack = 0; harq_process->ack = 0;
dlsch->last_iteration_cnt = dlsch->max_ldpc_iterations + 1; dlsch->last_iteration_cnt = dlsch->max_ldpc_iterations + 1;
LOG_E(PHY, " Frame %d.%d LDPC global CRC fails, but individual LDPC CRC succeeded. %d segs\n", proc->frame_rx, proc->nr_slot_rx, harq_process->C); LOG_E(PHY, " Frame %d.%d LDPC global CRC fails, but individual LDPC CRC succeeded. %d segs\n", proc->frame_rx, proc->nr_slot_rx, harq_process->C);
...@@ -269,24 +269,11 @@ static void nr_processDLSegment(void *arg) ...@@ -269,24 +269,11 @@ static void nr_processDLSegment(void *arg)
//VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_LDPC, VCD_FUNCTION_IN); //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_LDPC, VCD_FUNCTION_IN);
p_decoderParms->block_length=length_dec; p_decoderParms->block_length=length_dec;
nrLDPC_initcall(p_decoderParms, (int8_t*)&pl[0], LDPCoutput); nrLDPC_initcall(p_decoderParms, (int8_t*)&pl[0], LDPCoutput);
p_decoderParms->crc_type = crc_type;
rdata->decodeIterations = nrLDPC_decoder(p_decoderParms, (int8_t *)&pl[0], LDPCoutput, &procTime, &harq_process->abort_decode); rdata->decodeIterations = nrLDPC_decoder(p_decoderParms, (int8_t *)&pl[0], LDPCoutput, &procTime, &harq_process->abort_decode);
//VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_LDPC, VCD_FUNCTION_OUT); //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_LDPC, VCD_FUNCTION_OUT);
LOG_W(PHY,"rdata->decodeIterations = %d\n", rdata->decodeIterations); LOG_W(PHY,"rdata->decodeIterations = %d\n", rdata->decodeIterations);
if (rdata->decodeIterations < dlsch->max_ldpc_iterations + 2) {
// We have not aborted the decoding
if (check_crc((uint8_t *)LDPCoutput, length_dec, harq_process->F, crc_type)) {
LOG_D(PHY, "Segment %u CRC OK\n", r);
if (rdata->decodeIterations > dlsch->max_ldpc_iterations) {
LOG_W(PHY, "force ok\n");
rdata->decodeIterations = dlsch->max_ldpc_iterations;
}
} else {
LOG_D(PHY, "%d.%d CRC NOT OK, iter %d\n", rdata->proc->frame_rx, rdata->proc->nr_slot_rx, rdata->decodeIterations);
rdata->decodeIterations = dlsch->max_ldpc_iterations + 1;
}
} else
LOG_D(PHY, "%d.%d another segment failure aborted this decode\n", rdata->proc->frame_rx, rdata->proc->nr_slot_rx);
if (rdata->decodeIterations <= dlsch->max_ldpc_iterations) if (rdata->decodeIterations <= dlsch->max_ldpc_iterations)
memcpy(harq_process->c[r], LDPCoutput, Kr >> 3); memcpy(harq_process->c[r], LDPCoutput, Kr >> 3);
......
...@@ -424,10 +424,8 @@ static int nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue, ...@@ -424,10 +424,8 @@ static int nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue,
*/ */
} }
return ret;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_OUT);
return ret;
} }
......
...@@ -680,7 +680,7 @@ int main(int argc, char **argv) ...@@ -680,7 +680,7 @@ int main(int argc, char **argv)
c16_t **rxdata; c16_t **rxdata;
rxdata = malloc(n_rx * sizeof(*rxdata)); rxdata = malloc(n_rx * sizeof(*rxdata));
for (int i = 0; i < n_rx; ++i) for (int i = 0; i < n_rx; ++i)
rxdata[i] = calloc(gNB->frame_parms.samples_per_frame * sizeof(**rxdata),1); rxdata[i] = calloc(gNB->frame_parms.samples_per_frame, sizeof(**rxdata));
NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[0]; NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[0];
...@@ -1042,7 +1042,7 @@ int main(int argc, char **argv) ...@@ -1042,7 +1042,7 @@ int main(int argc, char **argv)
pusch_pdu->maintenance_parms_v3.tbSizeLbrmBytes = tbslbrm; pusch_pdu->maintenance_parms_v3.tbSizeLbrmBytes = tbslbrm;
pusch_pdu->pusch_data.rv_index = rv_index; pusch_pdu->pusch_data.rv_index = rv_index;
pusch_pdu->pusch_data.harq_process_id = 0; pusch_pdu->pusch_data.harq_process_id = 0;
pusch_pdu->pusch_data.new_data_indicator = round == 0 ? 1 : 0; pusch_pdu->pusch_data.new_data_indicator = round == 0 ? true : false;
pusch_pdu->pusch_data.num_cb = 0; pusch_pdu->pusch_data.num_cb = 0;
pusch_pdu->pusch_ptrs.ptrs_time_density = ptrs_time_density; pusch_pdu->pusch_ptrs.ptrs_time_density = ptrs_time_density;
pusch_pdu->pusch_ptrs.ptrs_freq_density = ptrs_freq_density; pusch_pdu->pusch_ptrs.ptrs_freq_density = ptrs_freq_density;
......
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