From d66dac0ab297e0e51c226a1b76a6e09d276d6985 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 19 May 2021 18:29:50 +0200 Subject: [PATCH] Added bit sequence state apply --- lib/include/srsran/phy/common/sequence.h | 3 +++ lib/src/phy/common/sequence.c | 26 ++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/include/srsran/phy/common/sequence.h b/lib/include/srsran/phy/common/sequence.h index 6d8bfeaf9..cf9f5f12d 100644 --- a/lib/include/srsran/phy/common/sequence.h +++ b/lib/include/srsran/phy/common/sequence.h @@ -38,6 +38,9 @@ SRSRAN_API void srsran_sequence_state_gen_f(srsran_sequence_state_t* s, float va SRSRAN_API void srsran_sequence_state_apply_f(srsran_sequence_state_t* s, const float* in, float* out, uint32_t length); +SRSRAN_API void +srsran_sequence_state_apply_bit(srsran_sequence_state_t* s, const uint8_t* in, uint8_t* out, uint32_t length); + SRSRAN_API void srsran_sequence_state_advance(srsran_sequence_state_t* s, uint32_t length); typedef struct SRSRAN_API { diff --git a/lib/src/phy/common/sequence.c b/lib/src/phy/common/sequence.c index c0a47667a..95e0c1089 100644 --- a/lib/src/phy/common/sequence.c +++ b/lib/src/phy/common/sequence.c @@ -611,16 +611,13 @@ void srsran_sequence_apply_c(const int8_t* in, int8_t* out, uint32_t length, uin } } -void srsran_sequence_apply_bit(const uint8_t* in, uint8_t* out, uint32_t length, uint32_t seed) +void srsran_sequence_state_apply_bit(srsran_sequence_state_t* s, const uint8_t* in, uint8_t* out, uint32_t length) { - uint32_t x1 = sequence_x1_init; // X1 initial state is fix - uint32_t x2 = sequence_get_x2_init(seed); // loads x2 initial state - uint32_t i = 0; if (length >= SEQUENCE_PAR_BITS) { for (; i < length - (SEQUENCE_PAR_BITS - 1); i += SEQUENCE_PAR_BITS) { - uint32_t c = (uint32_t)(x1 ^ x2); + uint32_t c = (uint32_t)(s->x1 ^ s->x2); uint32_t j = 0; #ifdef LV_HAVE_SSE @@ -656,20 +653,27 @@ void srsran_sequence_apply_bit(const uint8_t* in, uint8_t* out, uint32_t length, } // Step sequences - x1 = sequence_gen_LTE_pr_memless_step_par_x1(x1); - x2 = sequence_gen_LTE_pr_memless_step_par_x2(x2); + s->x1 = sequence_gen_LTE_pr_memless_step_par_x1(s->x1); + s->x2 = sequence_gen_LTE_pr_memless_step_par_x2(s->x2); } } for (; i < length; i++) { - out[i] = in[i] ^ ((x1 ^ x2) & 1U); + out[i] = in[i] ^ ((s->x1 ^ s->x2) & 1U); // Step sequences - x1 = sequence_gen_LTE_pr_memless_step_x1(x1); - x2 = sequence_gen_LTE_pr_memless_step_x2(x2); + s->x1 = sequence_gen_LTE_pr_memless_step_x1(s->x1); + s->x2 = sequence_gen_LTE_pr_memless_step_x2(s->x2); } } +void srsran_sequence_apply_bit(const uint8_t* in, uint8_t* out, uint32_t length, uint32_t seed) +{ + srsran_sequence_state_t sequence_state = {}; + srsran_sequence_state_init(&sequence_state, seed); + srsran_sequence_state_apply_bit(&sequence_state, in, out, length); +} + void srsran_sequence_apply_packed(const uint8_t* in, uint8_t* out, uint32_t length, uint32_t seed) { uint32_t x1 = sequence_x1_init; // X1 initial state is fix @@ -750,7 +754,7 @@ void srsran_sequence_apply_packed(const uint8_t* in, uint8_t* out, uint32_t leng out[i] = in[i] ^ reverse_lut[buffer & ((1U << rem8) - 1U) & 255U]; } -#else // SEQUENCE_PAR_BITS % 8 == 0 +#else // SEQUENCE_PAR_BITS % 8 == 0 while (i < (length / 8 - (SEQUENCE_PAR_BITS - 1) / 8)) { uint32_t c = (uint32_t)(x1 ^ x2);