Optimised random bit (unpacked) and byte (packed) generator

This commit is contained in:
Xavier Arteaga 2021-06-15 11:03:05 +02:00 committed by Xavier Arteaga
parent d2a19c3043
commit cf09044453
4 changed files with 36 additions and 4 deletions

View File

@ -26,6 +26,10 @@
#include "srsran/config.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint32_t nof_bits;
uint16_t* interleaver;
@ -78,4 +82,8 @@ SRSRAN_API uint32_t srsran_bit_diff(const uint8_t* x, const uint8_t* y, int nbit
SRSRAN_API uint32_t srsran_bit_count(uint32_t n);
#ifdef __cplusplus
}
#endif
#endif // SRSRAN_BIT_H

View File

@ -39,6 +39,8 @@ SRSRAN_API float srsran_random_gauss_dist(srsran_random_t q, float std_dev);
SRSRAN_API bool srsran_random_bool(srsran_random_t q, float prob_true);
SRSRAN_API void srsran_random_byte_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples);
SRSRAN_API void srsran_random_bit_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples);
SRSRAN_API void srsran_random_free(srsran_random_t q);

View File

@ -11,6 +11,7 @@
*/
#include "srsran/phy/utils/random.h"
#include "srsran/phy/utils/bit.h"
#include <complex>
#include <random>
@ -53,6 +54,20 @@ public:
}
}
void bit_vector(uint8_t* buffer, uint32_t n)
{
if (buffer == NULL || n == 0) {
return;
}
uint32_t i = 0;
uint8_t* ptr = buffer;
for (; i < n / 32; i++) {
srsran_bit_unpack((uint32_t)(*mt19937)(), &ptr, 32);
}
srsran_bit_unpack((uint32_t)(*mt19937)(), &ptr, n - i * 32);
}
float gauss_dist(float sigma)
{
std::normal_distribution<float> dist(sigma);
@ -130,7 +145,7 @@ bool srsran_random_bool(srsran_random_t q, float prob_true)
return srsran_random_uniform_real_dist(q, 0, 1) < prob_true;
}
void srsran_random_bit_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples)
void srsran_random_byte_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples)
{
if (q == nullptr) {
return;
@ -139,6 +154,15 @@ void srsran_random_bit_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples)
h->byte_vector(c, nsamples);
}
void srsran_random_bit_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples)
{
if (q == nullptr) {
return;
}
auto* h = (random_wrap*)q;
h->bit_vector(c, nsamples);
}
void srsran_random_free(srsran_random_t q)
{
if (q) {

View File

@ -524,9 +524,7 @@ int main(int argc, char** argv)
for (uint32_t sf_idx = 0; sf_idx < nof_subframes; sf_idx++) {
/* Generate random data */
for (int j = 0; j < SRSRAN_MAX_TB; j++) {
for (int i = 0; i < MAX_DATABUFFER_SIZE; i++) {
data_tx[j][i] = (uint8_t)srsran_random_uniform_int_dist(random, 0, 255);
}
srsran_random_byte_vector(random, data_tx[j], MAX_DATABUFFER_SIZE);
}
/*