From 5daa1ddea915250ed00f5c76094875ac478a3ed8 Mon Sep 17 00:00:00 2001 From: suraj_4g5g Date: Fri, 15 Sep 2023 00:15:53 +0530 Subject: [PATCH 1/2] LBRM/nref patch --- include/armral.h | 106 ++++++++++++----------- simulation/ldpc_awgn/ldpc_awgn.cpp | 12 ++- src/UpperPHY/LDPC/ldpc_rate_matching.cpp | 29 ++++--- src/UpperPHY/LDPC/ldpc_rate_recovery.cpp | 32 ++++--- test/LDPC/rate_matching/main.cpp | 61 +++++++++---- test/LDPC/rate_recovery/main.cpp | 62 +++++++++---- 6 files changed, 187 insertions(+), 115 deletions(-) diff --git a/include/armral.h b/include/armral.h index 16f5da2..c483633 100644 --- a/include/armral.h +++ b/include/armral.h @@ -3503,6 +3503,8 @@ uint32_t armral_ldpc_decode_block_noalloc_buffer_size(armral_ldpc_graph_t bg, * @param[in] e The number of bits in the rate-matched message. This is * assumed to be a multiple of the number of bits per * modulation symbol. + * @param[in] nref The soft buffer size for limited buffer rate matching. + * `nref` is defined in TS 38.212 Section 5.4.2.1. * @param[in] rv Redundancy version used in rate matching. Must be in the * set `{0, 1, 2, 3}`. The effect of choosing different * redundancy versions is described in table 5.4.2.1-2 of TS @@ -3519,7 +3521,7 @@ uint32_t armral_ldpc_decode_block_noalloc_buffer_size(armral_ldpc_graph_t bg, * @return An `armral_status` value that indicates success or failure. */ armral_status armral_ldpc_rate_matching(armral_ldpc_graph_t bg, uint32_t z, - uint32_t e, uint32_t rv, + uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const uint8_t *src, uint8_t *dst); @@ -3547,31 +3549,33 @@ armral_status armral_ldpc_rate_matching(armral_ldpc_graph_t bg, uint32_t z, * * The buffer must be at least `e * sizeof(uint8_t)` bytes. * - * @param[in] bg The type of base graph for which rate matching is to be - * performed. - * @param[in] z The lifting size. Valid values of the lifting size are - * described in table 5.3.2-1 in TS 38.212. - * @param[in] e The number of bits in the rate-matched message. This is - * assumed to be a multiple of the number of bits per - * modulation symbol. - * @param[in] rv Redundancy version used in rate matching. Must be in the - * set `{0, 1, 2, 3}`. The effect of choosing different - * redundancy versions is described in table 5.4.2.1-2 of TS - * 38.212. - * @param[in] mod The type of modulation to perform. Required to perform - * bit-interleaving, as described in section 5.4.2 of TS - * 38.212. - * @param[in] src Input array. This is assumed to be the output of LDPC - * encoding. This contains `66 * z` bits in the case that - * base graph 1 is used, and `50 * z` bits in the case that - * base graph 2 is used. - * @param[out] dst Contains `e` bits of data, which is the rate-matched data - * ready to be passed to modulation. - * @param[in] buffer Workspace buffer to be used internally. + * @param[in] bg The type of base graph for which rate matching is to be + * performed. + * @param[in] z The lifting size. Valid values of the lifting size are + * described in table 5.3.2-1 in TS 38.212. + * @param[in] e The number of bits in the rate-matched message. This is + * assumed to be a multiple of the number of bits per + * modulation symbol. + * @param[in] nref The soft buffer size for limited buffer rate matching. + * `nref` is defined in TS 38.212 Section 5.4.2.1. + * @param[in] rv Redundancy version used in rate matching. Must be in the + * set `{0, 1, 2, 3}`. The effect of choosing different + * redundancy versions is described in table 5.4.2.1-2 of TS + * 38.212. + * @param[in] mod The type of modulation to perform. Required to perform + * bit-interleaving, as described in section 5.4.2 of TS + * 38.212. + * @param[in] src Input array. This is assumed to be the output of LDPC + * encoding. This contains `66 * z` bits in the case that + * base graph 1 is used, and `50 * z` bits in the case that + * base graph 2 is used. + * @param[out] dst Contains `e` bits of data, which is the rate-matched data + * ready to be passed to modulation. + * @param[in] buffer Workspace buffer to be used internally. * @return An `armral_status` value that indicates success or failure. */ armral_status armral_ldpc_rate_matching_noalloc( - armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t rv, + armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const uint8_t *src, uint8_t *dst, void *buffer); /** @@ -3598,33 +3602,35 @@ armral_status armral_ldpc_rate_matching_noalloc( * approximation to LLRs. The LLRs calculated from the rate-recovery are summed * to existing LLRs in the output array. * - * @param[in] bg The type of base graph for which rate recovery is to be - * performed. - * @param[in] z The lifting size. Valid values of the lifting size are - * described in table 5.3.2-1 in TS 38.212. - * @param[in] e The number of LLRs in the demodulated message. Assumed - * to be a multiple of the number of bits per modulation - * symbol. - * @param[in] rv Redundancy version used in rate recovery. Must be in the - * set `{0, 1, 2, 3}`. The effect of choosing different - * redundancy versions is described in table 5.4.2.1-2 of - * TS 38.212. - * @param[in] mod The type of modulation which was performed. Required to - * perform bit-deinterleaving as the inverse of the - * bit-interleaving described in section 5.4.2 of TS - * 38.212. - * @param[in] src Input array of a total of `e` 8-bit LLRs. This is the - * output after demodulation. - * @param[in,out] dst On entry, contains the current approximation to LLRs. - * If no approximation of the LLRs is known, all entries - * must be set to zero. The array has length `66 * z` for - * base graph 1, and `50 * z` for base graph 2. On exit, - * updated rate-recovered 8-bit LLRs, which are ready to be - * passed to decoding. + * @param[in] bg The type of base graph for which rate recovery is to be + * performed. + * @param[in] z The lifting size. Valid values of the lifting size are + * described in table 5.3.2-1 in TS 38.212. + * @param[in] e The number of LLRs in the demodulated message. Assumed + * to be a multiple of the number of bits per modulation + * symbol. + * @param[in] nref The soft buffer size for limited buffer rate matching. + * `nref` is defined in TS 38.212 Section 5.4.2.1. + * @param[in] rv Redundancy version used in rate recovery. Must be in the + * set `{0, 1, 2, 3}`. The effect of choosing different + * redundancy versions is described in table 5.4.2.1-2 of + * TS 38.212. + * @param[in] mod The type of modulation which was performed. Required to + * perform bit-deinterleaving as the inverse of the + * bit-interleaving described in section 5.4.2 of TS + * 38.212. + * @param[in] src Input array of a total of `e` 8-bit LLRs. This is the + * output after demodulation. + * @param[in,out] dst On entry, contains the current approximation to LLRs. + * If no approximation of the LLRs is known, all entries + * must be set to zero. The array has length `66 * z` for + * base graph 1, and `50 * z` for base graph 2. On exit, + * updated rate-recovered 8-bit LLRs, which are ready to be + * passed to decoding. * @return An `armral_status` value that indicates success or failure. */ armral_status armral_ldpc_rate_recovery(armral_ldpc_graph_t bg, uint32_t z, - uint32_t e, uint32_t rv, + uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const int8_t *src, int8_t *dst); @@ -3666,6 +3672,8 @@ armral_status armral_ldpc_rate_recovery(armral_ldpc_graph_t bg, uint32_t z, * @param[in] e The number of LLRs in the demodulated message. Assumed * to be a multiple of the number of bits per modulation * symbol. + * @param[in] nref The soft buffer size for limited buffer rate matching. + * `nref` is defined in TS 38.212 Section 5.4.2.1. * @param[in] rv Redundancy version used in rate recovery. Must be in the * set `{0, 1, 2, 3}`. The effect of choosing different * redundancy versions is described in table 5.4.2.1-2 of @@ -3686,8 +3694,8 @@ armral_status armral_ldpc_rate_recovery(armral_ldpc_graph_t bg, uint32_t z, * @return An `armral_status` value that indicates success or failure. */ armral_status armral_ldpc_rate_recovery_noalloc( - armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t rv, - armral_modulation_type mod, const int8_t *src, int8_t *dst, void *buffer); + armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t nref, + uint32_t rv, armral_modulation_type mod, const int8_t *src, int8_t *dst, void *buffer); /** @} end ldpc */ /** diff --git a/simulation/ldpc_awgn/ldpc_awgn.cpp b/simulation/ldpc_awgn/ldpc_awgn.cpp index 20c2e55..1b284fa 100644 --- a/simulation/ldpc_awgn/ldpc_awgn.cpp +++ b/simulation/ldpc_awgn/ldpc_awgn.cpp @@ -110,6 +110,7 @@ struct ldpc_example_data { uint32_t len_encoded; uint32_t len_rate_matched; uint32_t len_out; + uint32_t nref; armral_modulation_type mod_type; uint32_t num_mod_symbols; uint8_t bit_per_symbol; @@ -135,6 +136,7 @@ struct ldpc_example_data { data_encoded = SNEW(uint8_t, (len_encoded + 7) / 8); data_encoded_bytes = SNEW(uint8_t, len_encoded); bit_per_symbol = armral_simulation::bits_per_symbol(mod_type); + nref = 0; len_rate_matched = bit_per_symbol * ((len_encoded + bit_per_symbol - 1) / bit_per_symbol); data_matched = SNEW(uint8_t, len_rate_matched); @@ -185,8 +187,9 @@ int run_check(random_state *state, uint32_t z, armral_ldpc_graph_t bg, // Rate match data_encoded to create an array of length e bits from // num_mod_symbols * bit_per_symbol bits. - armral_ldpc_rate_matching(bg, z, data->len_rate_matched, rv, data->mod_type, - data->data_encoded, data->data_matched); + armral_ldpc_rate_matching(bg, z, data->len_rate_matched, data->nref, rv, + data->mod_type, data->data_encoded, + data->data_matched); // Run modulation armral_modulation(data->num_mod_symbols * data->bit_per_symbol, @@ -205,8 +208,9 @@ int run_check(random_state *state, uint32_t z, armral_ldpc_graph_t bg, memset(data->data_recovered, 0, data->len_encoded); // Rate recovery inverses rate matching - armral_ldpc_rate_recovery(bg, z, data->len_rate_matched, rv, data->mod_type, - data->data_demod_soft, data->data_recovered); + armral_ldpc_rate_recovery(bg, z, data->len_rate_matched, data->nref, rv, + data->mod_type, data->data_demod_soft, + data->data_recovered); // Run LDPC decoding for a single block armral_ldpc_decode_block(data->data_recovered, bg, z, ARMRAL_LDPC_NO_CRC, 10, diff --git a/src/UpperPHY/LDPC/ldpc_rate_matching.cpp b/src/UpperPHY/LDPC/ldpc_rate_matching.cpp index 6484fde..afeb98b 100644 --- a/src/UpperPHY/LDPC/ldpc_rate_matching.cpp +++ b/src/UpperPHY/LDPC/ldpc_rate_matching.cpp @@ -49,26 +49,27 @@ static void bit_interleave(uint32_t e, uint32_t qm, const uint8_t *in, } static int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, - uint32_t z) { + uint32_t ncb, uint32_t z) { // Starting position k0 of different redundancy versions // given as Table 5.4.2.1-2 in 3GPP TS 38.212. if (rv == 0) { return 0; } if (rv == 1) { - return 17 * z - (int)bg * 4 * z; + return ((17 * z - (int)bg * 4 * z) * (ncb / n)); } if (rv == 2) { - return 33 * z - (int)bg * 8 * z; + return ((33 * z - (int)bg * 8 * z) * (ncb / n)); } if (rv == 3) { - return 56 * z - (int)bg * 13 * z; + return ((56 * z - (int)bg * 13 * z) * (ncb / n)); } return 0; } template -armral_status rate_matching(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, +armral_status rate_matching(armral_ldpc_graph_t bg, uint32_t z, + uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const uint8_t *src, uint8_t *dst, Allocator &allocator) { @@ -76,9 +77,15 @@ armral_status rate_matching(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, // Map the modulation type onto the modulation order. uint32_t qm = 2 + (uint32_t)mod * 2; uint32_t n = z; + uint32_t ncb = 0; bg == LDPC_BASE_GRAPH_2 ? n *= 50 : n *= 66; - uint32_t k0 = starting_position(bg, rv, n, z); - bit_selection(n, e, k0, src, selected.get()); + if (nref != 0) { + ncb = (n > nref) ? nref : n; + } else { + ncb = n; + } + uint32_t k0 = starting_position(bg, rv, n, ncb, z); + bit_selection(ncb, e, k0, src, selected.get()); bit_interleave(e, qm, selected.get(), dst); return ARMRAL_SUCCESS; } @@ -86,19 +93,19 @@ armral_status rate_matching(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, } // namespace ldpc armral_status armral_ldpc_rate_matching(armral_ldpc_graph_t bg, uint32_t z, - uint32_t e, uint32_t rv, + uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const uint8_t *src, uint8_t *dst) { heap_allocator allocator{}; - return ldpc::rate_matching(bg, z, e, rv, mod, src, dst, allocator); + return ldpc::rate_matching(bg, z, e, nref, rv, mod, src, dst, allocator); } armral_status armral_ldpc_rate_matching_noalloc(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, - uint32_t rv, + uint32_t nref, uint32_t rv, armral_modulation_type mod, const uint8_t *src, uint8_t *dst, void *buffer) { buffer_bump_allocator allocator{buffer}; - return ldpc::rate_matching(bg, z, e, rv, mod, src, dst, allocator); + return ldpc::rate_matching(bg, z, e, nref, rv, mod, src, dst, allocator); } diff --git a/src/UpperPHY/LDPC/ldpc_rate_recovery.cpp b/src/UpperPHY/LDPC/ldpc_rate_recovery.cpp index 6e1547d..b263629 100644 --- a/src/UpperPHY/LDPC/ldpc_rate_recovery.cpp +++ b/src/UpperPHY/LDPC/ldpc_rate_recovery.cpp @@ -49,7 +49,7 @@ void undo_interleave(uint32_t e, uint32_t qm, const int8_t *in, int8_t *out) { } static int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, - uint32_t z) { + uint32_t ncb, uint32_t z) { // Duplicate of routine of the same name in ldpc_rate_matching.cpp // Starting position k0 of different redundancy versions // given as Table 5.4.2.1-2 in 3GPP TS 38.212. @@ -57,44 +57,50 @@ static int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, return 0; } if (rv == 1) { - return 17 * z - (int)bg * 4 * z; + return ((17 * z - (int)bg * 4 * z) * (ncb / n)); } if (rv == 2) { - return 33 * z - (int)bg * 8 * z; + return ((33 * z - (int)bg * 8 * z) * (ncb / n)); } if (rv == 3) { - return 56 * z - (int)bg * 13 * z; + return ((56 * z - (int)bg * 13 * z) * (ncb / n)); } return 0; } template armral_status rate_recovery(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, - uint32_t rv, armral_modulation_type mod, - const int8_t *src, int8_t *dst, - Allocator &allocator) { + uint32_t nref, uint32_t rv, + armral_modulation_type mod, const int8_t *src, + int8_t *dst, Allocator &allocator) { auto llrs = allocate_uninitialized(allocator, e); uint32_t n = (bg == LDPC_BASE_GRAPH_2) ? 50 * z : 66 * z; - uint32_t k0 = starting_position(bg, rv, n, z); + uint32_t ncb = 0; + if (nref != 0) { + ncb = (n > nref) ? nref : n; + } else { + ncb = n; + } + uint32_t k0 = starting_position(bg, rv, n, ncb, z); uint32_t qm = 2 + (uint32_t)mod * 2; undo_interleave(e, qm, src, llrs.get()); - undo_selection(n, e, k0, llrs.get(), dst); + undo_selection(ncb, e, k0, llrs.get(), dst); return ARMRAL_SUCCESS; } } // namespace ldpc armral_status armral_ldpc_rate_recovery(armral_ldpc_graph_t bg, uint32_t z, - uint32_t e, uint32_t rv, + uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const int8_t *src, int8_t *dst) { heap_allocator allocator{}; - return ldpc::rate_recovery(bg, z, e, rv, mod, src, dst, allocator); + return ldpc::rate_recovery(bg, z, e, nref, rv, mod, src, dst, allocator); } armral_status armral_ldpc_rate_recovery_noalloc( - armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t rv, + armral_ldpc_graph_t bg, uint32_t z, uint32_t e, uint32_t nref, uint32_t rv, armral_modulation_type mod, const int8_t *src, int8_t *dst, void *buffer) { buffer_bump_allocator allocator{buffer}; - return ldpc::rate_recovery(bg, z, e, rv, mod, src, dst, allocator); + return ldpc::rate_recovery(bg, z, e, nref, rv, mod, src, dst, allocator); } diff --git a/test/LDPC/rate_matching/main.cpp b/test/LDPC/rate_matching/main.cpp index 4727ffa..e0ed5af 100644 --- a/test/LDPC/rate_matching/main.cpp +++ b/test/LDPC/rate_matching/main.cpp @@ -5,6 +5,7 @@ #include "armral.h" #include "int8_utils.hpp" +#include #include #include #include @@ -178,7 +179,7 @@ bool test_ref_rate_matching() { } int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, - uint32_t z) { + uint32_t ncb, uint32_t z) { // Starting position k0 of different redundancy versions // given as Table 5.4.2.1-2 in 3GPP TS 38.212, simplified // using the assumption N_cb = 66 * Z_c (base graph 1) or @@ -191,25 +192,25 @@ int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 17 * z; + return 17 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 13 * z; + return 13 * z * (ncb / n); } case 2: switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 33 * z; + return 33 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 25 * z; + return 25 * z * (ncb / n); } case 3: switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 56 * z; + return 56 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 43 * z; + return 43 * z * (ncb / n); } } } @@ -243,13 +244,21 @@ uint32_t num_bit_per_symbol(armral_modulation_type mod_type) { } void armral_ref_rate_matching(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, - uint32_t rv, armral_modulation_type mod, - const uint8_t *src, uint8_t *dst) { + uint32_t nref, uint32_t rv, + armral_modulation_type mod, const uint8_t *src, + uint8_t *dst) { + uint32_t ncb; uint32_t qm = num_bit_per_symbol(mod); uint32_t n = src_length(bg, z); - uint32_t k0 = starting_position(bg, rv, n, z); + + if (nref != 0) { + ncb = (n > nref) ? nref : n; + } else { + ncb = n; + } + uint32_t k0 = starting_position(bg, rv, n, ncb, z); std::vector selected(e); - ref_bit_selection(n, e, k0, src, selected.data()); + ref_bit_selection(ncb, e, k0, src, selected.data()); ref_bit_interleave(e, qm, selected.data(), dst); } @@ -263,9 +272,20 @@ bool test_ldpc_rate_matching( // Arbitrary subset of lifting sizes given in Table 5.3.2-1. const uint32_t lifting_size_list[] = {2, 3, 5, 11, 28, 32, 104}; const uint32_t rv_list[] = {0, 1, 2, 3}; + uint32_t lifting_size_list_len = + sizeof(lifting_size_list) / sizeof(lifting_size_list[0]); + uint32_t lifting_size_min = *std::min_element( + lifting_size_list, lifting_size_list + lifting_size_list_len); + uint32_t lifting_size_max = *std::max_element( + lifting_size_list, lifting_size_list + lifting_size_list_len); + // Prepare nref_list for both BG1 and BG2 using lifting_size_list + const uint32_t nref_list[2][3] = { + {0, (66 * lifting_size_min), (66 * lifting_size_max)}, //BG1 + {0, (50 * lifting_size_min), (50 * lifting_size_max)}, //BG2 + }; + // Arbitrary subset of modulation schemes. const armral_modulation_type mod_list[] = {ARMRAL_MOD_QPSK, ARMRAL_MOD_16QAM}; - for (auto z : lifting_size_list) { for (auto bg : base_graph_list) { // Default to base graph 1 @@ -288,13 +308,16 @@ bool test_ldpc_rate_matching( uint32_t e = qm * ((g + qm - 1) / qm); num_bytes = (e + 7) / 8; for (auto rv : rv_list) { - std::vector ref = std::vector(num_bytes); - std::vector dst = std::vector(num_bytes); - ldpc_rate_matching_under_test(bg, z, e, rv, mod, src.data(), - dst.data()); - armral_ref_rate_matching(bg, z, e, rv, mod, src.data(), ref.data()); - passed &= - check_results_u8(test_name, dst.data(), ref.data(), num_bytes); + for (auto nref : nref_list[bg]) { + std::vector ref = std::vector(num_bytes); + std::vector dst = std::vector(num_bytes); + ldpc_rate_matching_under_test(bg, z, e, nref, rv, mod, src.data(), + dst.data()); + armral_ref_rate_matching(bg, z, e, nref, rv, mod, src.data(), + ref.data()); + passed &= + check_results_u8(test_name, dst.data(), ref.data(), num_bytes); + } } } } diff --git a/test/LDPC/rate_recovery/main.cpp b/test/LDPC/rate_recovery/main.cpp index b7da7f6..0fdd2a6 100644 --- a/test/LDPC/rate_recovery/main.cpp +++ b/test/LDPC/rate_recovery/main.cpp @@ -6,6 +6,7 @@ #include "int8_utils.hpp" #include +#include #include #include #include @@ -56,7 +57,7 @@ void ref_undo_interleave(uint32_t e, uint32_t qm, const int8_t *in, } int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, - uint32_t z) { + uint32_t ncb, uint32_t z) { // Duplicate of function with same name in rate_matching // Starting position k0 of different redundancy versions @@ -71,25 +72,25 @@ int starting_position(armral_ldpc_graph_t bg, uint32_t rv, uint32_t n, switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 17 * z; + return 17 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 13 * z; + return 13 * z * (ncb / n); } case 2: switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 33 * z; + return 33 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 25 * z; + return 25 * z * (ncb / n); } case 3: switch (bg) { case LDPC_BASE_GRAPH_1: default: - return 56 * z; + return 56 * z * (ncb / n); case LDPC_BASE_GRAPH_2: - return 43 * z; + return 43 * z * (ncb / n); } } } @@ -112,14 +113,23 @@ uint32_t num_bit_per_symbol(armral_modulation_type mod_type) { } void armral_ref_rate_recovery(armral_ldpc_graph_t bg, uint32_t z, uint32_t e, - uint32_t rv, armral_modulation_type mod, - const int8_t *src, int8_t *dst) { + uint32_t nref, uint32_t rv, + armral_modulation_type mod, const int8_t *src, + int8_t *dst) { + uint32_t ncb = 0; uint32_t n = (bg == LDPC_BASE_GRAPH_2) ? 50 * z : 66 * z; - uint32_t k0 = starting_position(bg, rv, n, z); + + if (nref != 0) { + ncb = (n > nref) ? nref : n; + } else { + ncb = n; + } + + uint32_t k0 = starting_position(bg, rv, n, ncb, z); uint32_t qm = num_bit_per_symbol(mod); std::vector llrs(e); ref_undo_interleave(e, qm, src, llrs.data()); - ref_undo_selection(n, e, k0, llrs.data(), dst); + ref_undo_selection(ncb, e, k0, llrs.data(), dst); } bool test_ref_rate_recovery() { @@ -193,6 +203,18 @@ bool test_ldpc_rate_recovery( LDPC_BASE_GRAPH_2}; // Arbitrary subset of lifting sizes given in Table 5.3.2-1. const uint32_t lifting_size_list[] = {2, 3, 8}; + uint32_t lifting_size_list_len = + sizeof(lifting_size_list) / sizeof(lifting_size_list[0]); + uint32_t lifting_size_min = *std::min_element( + lifting_size_list, lifting_size_list + lifting_size_list_len); + uint32_t lifting_size_max = *std::max_element( + lifting_size_list, lifting_size_list + lifting_size_list_len); + // Prepare nref_list for both BG1 and BG2 using lifting_size_list + const uint32_t nref_list[2][3] = { + {0, (66 * lifting_size_min), (66 * lifting_size_max)}, //BG1 + {0, (50 * lifting_size_min), (50 * lifting_size_max)}, //BG2 + }; + // Arbitrary subset of modulation schemes. const armral_modulation_type mod_list[] = {ARMRAL_MOD_QPSK, ARMRAL_MOD_256QAM}; @@ -207,14 +229,16 @@ bool test_ldpc_rate_recovery( uint32_t g = (bg == LDPC_BASE_GRAPH_2) ? 11 * z : 22 * z; uint32_t e = qm * ((g + qm - 1) / qm); for (auto rv : rv_list) { - std::vector llrs_in = allocate_random_i8(e); - std::vector llrs_out(n); - std::vector llrs_ref(n); - armral_ref_rate_recovery(bg, z, e, rv, mod, llrs_in.data(), - llrs_ref.data()); - ldpc_rate_recovery_under_test(bg, z, e, rv, mod, llrs_in.data(), - llrs_out.data()); - passed &= (llrs_ref == llrs_out); + for (auto nref : nref_list[bg]) { + std::vector llrs_in = allocate_random_i8(e); + std::vector llrs_out(n); + std::vector llrs_ref(n); + armral_ref_rate_recovery(bg, z, e, nref, rv, mod, llrs_in.data(), + llrs_ref.data()); + ldpc_rate_recovery_under_test(bg, z, e, nref, rv, mod, + llrs_in.data(), llrs_out.data()); + passed &= (llrs_ref == llrs_out); + } } } } -- GitLab From cbeafe4dde5f3b1039b35d3f69ecfe4393e5010c Mon Sep 17 00:00:00 2001 From: suraj_4g5g Date: Tue, 19 Sep 2023 18:49:12 +0530 Subject: [PATCH 2/2] refactor: Update header includes in main.cpp files Removed unnecessary header and added the required header in the main.cpp files for LDPC rate matching and rate recovery. --- test/LDPC/rate_matching/main.cpp | 2 +- test/LDPC/rate_recovery/main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/LDPC/rate_matching/main.cpp b/test/LDPC/rate_matching/main.cpp index e0ed5af..3f695a1 100644 --- a/test/LDPC/rate_matching/main.cpp +++ b/test/LDPC/rate_matching/main.cpp @@ -5,7 +5,7 @@ #include "armral.h" #include "int8_utils.hpp" -#include +#include #include #include #include diff --git a/test/LDPC/rate_recovery/main.cpp b/test/LDPC/rate_recovery/main.cpp index 0fdd2a6..5d7eb46 100644 --- a/test/LDPC/rate_recovery/main.cpp +++ b/test/LDPC/rate_recovery/main.cpp @@ -6,7 +6,6 @@ #include "int8_utils.hpp" #include -#include #include #include #include -- GitLab