From 794d1b5c4bd323326a7f37c1e9207578c92fe4fa Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Fri, 6 Nov 2020 19:22:17 +0100 Subject: [PATCH] Added LDPC decoder RM interface --- .../srslte/phy/fec/ldpc/ldpc_decoder.h | 19 +++++++- lib/src/phy/fec/ldpc/ldpc_decoder.c | 13 ++++-- lib/src/phy/fec/ldpc/ldpc_rm.c | 44 ++++++++++++++----- lib/src/phy/fec/ldpc/test/ldpc_chain_test.c | 9 ++-- .../phy/fec/ldpc/test/ldpc_dec_avx2_test.c | 2 +- lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c | 2 +- .../phy/fec/ldpc/test/ldpc_rm_chain_test.c | 9 ++-- 7 files changed, 71 insertions(+), 27 deletions(-) diff --git a/lib/include/srslte/phy/fec/ldpc/ldpc_decoder.h b/lib/include/srslte/phy/fec/ldpc/ldpc_decoder.h index bc363c370..0674308cb 100644 --- a/lib/include/srslte/phy/fec/ldpc/ldpc_decoder.h +++ b/lib/include/srslte/phy/fec/ldpc/ldpc_decoder.h @@ -132,6 +132,19 @@ srslte_ldpc_decoder_decode_f(srslte_ldpc_decoder_t* q, const float* llrs, uint8_ SRSLTE_API int srslte_ldpc_decoder_decode_s(srslte_ldpc_decoder_t* q, const int16_t* llrs, uint8_t* message, uint32_t cdwd_rm_length); +/*! + * Carries out the actual decoding with 8-bit integer-valued LLRs. It is + * recommended to use a 7-bit representation for the LLRs, given that all + * values exceeding \f$ 2^{7}-1 \f$ (in magnitude) will be considered as infinity. + * \param[in] q A pointer to the LDPC decoder (a srslte_ldpc_decoder_t structure + * instance) that carries out the decoding. + * \param[in] llrs The LLRs obtained from the channel samples that correspond to + * the codeword to be decoded. + * \param[out] message The message (uncoded bits) resulting from the decoding + * operation. + */ +SRSLTE_API int srslte_ldpc_decoder_decode_c(srslte_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message); + /*! * Carries out the actual decoding with 8-bit integer-valued LLRs. It is * recommended to use a 7-bit representation for the LLRs, given that all @@ -144,7 +157,9 @@ srslte_ldpc_decoder_decode_s(srslte_ldpc_decoder_t* q, const int16_t* llrs, uint * operation. * \param[in] cdwd_rm_length The number of bits forming the codeword (after rate matching). */ -SRSLTE_API int -srslte_ldpc_decoder_decode_c(srslte_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message, uint32_t cdwd_rm_length); +SRSLTE_API int srslte_ldpc_decoder_decode_rm_c(srslte_ldpc_decoder_t* q, + const int8_t* llrs, + uint8_t* message, + uint32_t cdwd_rm_length); #endif // SRSLTE_LDPCDECODER_H diff --git a/lib/src/phy/fec/ldpc/ldpc_decoder.c b/lib/src/phy/fec/ldpc/ldpc_decoder.c index 0f411afb4..062630b2e 100644 --- a/lib/src/phy/fec/ldpc/ldpc_decoder.c +++ b/lib/src/phy/fec/ldpc/ldpc_decoder.c @@ -776,10 +776,15 @@ int srslte_ldpc_decoder_decode_s(srslte_ldpc_decoder_t* q, return q->decode_s(q, llrs, message, cdwd_rm_length); } -int srslte_ldpc_decoder_decode_c(srslte_ldpc_decoder_t* q, - const int8_t* llrs, - uint8_t* message, - uint32_t cdwd_rm_length) +int srslte_ldpc_decoder_decode_c(srslte_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message) +{ + return q->decode_c(q, llrs, message, q->liftN - 2 * q->ls); +} + +int srslte_ldpc_decoder_decode_rm_c(srslte_ldpc_decoder_t* q, + const int8_t* llrs, + uint8_t* message, + uint32_t cdwd_rm_length) { return q->decode_c(q, llrs, message, cdwd_rm_length); } diff --git a/lib/src/phy/fec/ldpc/ldpc_rm.c b/lib/src/phy/fec/ldpc/ldpc_rm.c index c8ecaba80..f2faf3daf 100644 --- a/lib/src/phy/fec/ldpc/ldpc_rm.c +++ b/lib/src/phy/fec/ldpc/ldpc_rm.c @@ -526,8 +526,12 @@ void srslte_ldpc_rm_tx_free(srslte_ldpc_rm_t* q) { if (q != NULL) { struct pRM_tx* qq = q->ptr; - free(qq->tmp_rm_codeword); - free(qq); + if (qq != NULL) { + if (qq->tmp_rm_codeword != NULL) { + free(qq->tmp_rm_codeword); + } + free(qq); + } } } @@ -535,9 +539,15 @@ void srslte_ldpc_rm_rx_free_f(srslte_ldpc_rm_t* q) { if (q != NULL) { struct pRM_rx_f* qq = q->ptr; - free(qq->tmp_rm_symbol); - free(qq->indices); - free(qq); + if (qq != NULL) { + if (qq->tmp_rm_symbol != NULL) { + free(qq->tmp_rm_symbol); + } + if (qq->indices != NULL) { + free(qq->indices); + } + free(qq); + } } } @@ -545,9 +555,15 @@ void srslte_ldpc_rm_rx_free_s(srslte_ldpc_rm_t* q) { if (q != NULL) { struct pRM_rx_s* qq = q->ptr; - free(qq->tmp_rm_symbol); - free(qq->indices); - free(qq); + if (qq != NULL) { + if (qq->tmp_rm_symbol != NULL) { + free(qq->tmp_rm_symbol); + } + if (qq->indices != NULL) { + free(qq->indices); + } + free(qq); + } } } @@ -555,9 +571,15 @@ void srslte_ldpc_rm_rx_free_c(srslte_ldpc_rm_t* q) { if (q != NULL) { struct pRM_rx_c* qq = q->ptr; - free(qq->tmp_rm_symbol); - free(qq->indices); - free(qq); + if (qq != NULL) { + if (qq->tmp_rm_symbol != NULL) { + free(qq->tmp_rm_symbol); + } + if (qq->indices != NULL) { + free(qq->indices); + } + free(qq); + } } } diff --git a/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c b/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c index 579f71005..d051ac205 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c @@ -399,7 +399,8 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c(&decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, n_useful_symbols); + srslte_ldpc_decoder_decode_rm_c( + &decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -420,7 +421,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c( + srslte_ldpc_decoder_decode_rm_c( &decoder_c_flood, symbols_c + j * finalN, messages_sim_c_flood + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -443,7 +444,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c( + srslte_ldpc_decoder_decode_rm_c( &decoder_avx, symbols_c + j * finalN, messages_sim_avx + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -465,7 +466,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c( + srslte_ldpc_decoder_decode_rm_c( &decoder_avx_flood, symbols_c + j * finalN, messages_sim_avx_flood + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c index a8597ec59..17162fd7b 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c @@ -206,7 +206,7 @@ int main(int argc, char** argv) gettimeofday(&t[1], NULL); for (j = 0; j < NOF_MESSAGES; j++) { printf(" codeword %d\n", j); - srslte_ldpc_decoder_decode_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); + srslte_ldpc_decoder_decode_rm_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c b/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c index d778e1f75..2d2fbfba7 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c @@ -205,7 +205,7 @@ int main(int argc, char** argv) gettimeofday(&t[1], NULL); for (j = 0; j < NOF_MESSAGES; j++) { printf(" codeword %d\n", j); - srslte_ldpc_decoder_decode_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); + srslte_ldpc_decoder_decode_rm_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c b/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c index 701da6e38..7179e226d 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c @@ -505,7 +505,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c(&decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, finalN); + srslte_ldpc_decoder_decode_rm_c(&decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -526,7 +526,8 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c(&decoder_c_flood, symbols_c + j * finalN, messages_sim_c_flood + j * finalK, finalN); + srslte_ldpc_decoder_decode_rm_c( + &decoder_c_flood, symbols_c + j * finalN, messages_sim_c_flood + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -548,7 +549,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c(&decoder_avx, symbols_c + j * finalN, messages_sim_avx + j * finalK, finalN); + srslte_ldpc_decoder_decode_rm_c(&decoder_avx, symbols_c + j * finalN, messages_sim_avx + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -569,7 +570,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srslte_ldpc_decoder_decode_c( + srslte_ldpc_decoder_decode_rm_c( &decoder_avx_flood, symbols_c + j * finalN, messages_sim_avx_flood + j * finalK, finalN); } gettimeofday(&t[2], NULL);