fix(imscope): fix build for imscope

This commit moves certain functions and structs around to prevent including
functions taking VLA arguments in imscope C++ source files.

Signed-off-by: Bartosz Podrygajlo <bartosz.podrygajlo@openairinterface.org>
This commit is contained in:
Bartosz Podrygajlo
2026-04-29 07:53:01 +02:00
committed by Robert Schmidt
parent abb7cbe2bd
commit e518e96fbe
7 changed files with 83 additions and 86 deletions

View File

@@ -3,6 +3,7 @@
*/
#include "bits.h"
#include "utils.h"
// we avoid assertions.h as it necessitates othe dependencies (e.g., exit_function)
#include <assert.h>
#include <simde/x86/gfni.h>
@@ -73,3 +74,70 @@ uint64_t reverse_bits(uint64_t in, int n_bits)
return rev_bits;
}
/**
* Finds the next contiguous block of set bits.
* @param bitmap The bit buffer
* @param size Total bits in the buffer
* @param pos Pointer to current bit index (updated by function)
* @param start Output: Start index of the found block
* @param end Output: End index of the found block
* @return true if a block was found, false if no more bits are set
*/
bool find_next_rb_block(const uint32_t *bitmap, int size, int *pos, int *start, int *end)
{
const int words = (size + 31) / 32;
// Find start of next block
int idx = get_first_bit_index_mask(bitmap, words, *pos, size - *pos);
if (idx < 0)
return false;
*start = idx;
// Find end of block: first zero bit after idx
// Reuse get_first_bit_index_from on the inverted bitmap
idx++;
int word_idx = idx / 32;
int n = words - word_idx;
uint32_t inv[n];
for (int i = 0; i < n; i++)
inv[i] = ~bitmap[word_idx + i];
if (size % 32 != 0)
inv[n - 1] &= (1u << (size % 32)) - 1;
int end_off = get_first_bit_index_mask(inv, n, idx - word_idx * 32, size - idx);
idx = (end_off < 0) ? size : word_idx * 32 + end_off;
*end = (idx > size) ? size - 1 : idx - 1;
*pos = idx; // Update position for the next call
return true;
}
bool check_rb_in_bitmap(const freq_alloc_bitmap_t *alloc, int rb)
{
return (alloc->bitmap[rb / 32] >> (rb % 32)) & 0x01;
}
freq_alloc_bitmap_t set_start_end_from_bitmap(int size, int alloc_size, const uint8_t *bitmap)
{
freq_alloc_bitmap_t alloc = {0};
int num_words = (size + 31) / 32;
memcpy(alloc.bitmap, bitmap, alloc_size);
alloc.num_rbs = count_bits(alloc.bitmap, num_words);
alloc.first_rb = get_first_bit_index(alloc.bitmap, num_words);
alloc.last_rb = get_last_bit_index(alloc.bitmap, num_words);
AssertFatal(alloc.first_rb >= 0 && alloc.last_rb >=0 , "No valid RB set, no bit set in bitmap\n");
return alloc;
}
freq_alloc_bitmap_t set_bitmap_from_start_size(int start, int size)
{
freq_alloc_bitmap_t alloc = {
.num_rbs = size,
.first_rb = start,
.last_rb = start + size - 1
};
memset(alloc.bitmap, 0, sizeof(alloc.bitmap));
for (int i = start; i < size + start; i++)
alloc.bitmap[i / 32] |= (1U << (i % 32));
return alloc;
}

View File

@@ -73,4 +73,16 @@ static __attribute__((always_inline)) inline int count_bits64_with_mask(uint64_t
uint64_t mask = ((1LL << num) - 1) << start;
return count_bits64(v & mask);
}
bool find_next_rb_block(const uint32_t *bitmap, int size, int *pos, int *start, int *end);
typedef struct {
int first_rb;
int last_rb;
int num_rbs;
uint32_t bitmap[9];
} freq_alloc_bitmap_t;
bool check_rb_in_bitmap(const freq_alloc_bitmap_t *alloc, int rb);
freq_alloc_bitmap_t set_start_end_from_bitmap(int size, int alloc_size, const uint8_t *bitmap);
freq_alloc_bitmap_t set_bitmap_from_start_size(int start, int size);
#endif /* BITS_H_ */

View File

@@ -5,7 +5,7 @@
#ifndef __NR_ESTIMATION_DEFS__H__
#define __NR_ESTIMATION_DEFS__H__
#include "PHY/nr_phy_common/inc/nr_phy_common.h"
#include "common/utils/bits.h"
#include "PHY/defs_nr_UE.h"
/** @addtogroup _PHY_PARAMETER_ESTIMATION_BLOCKS_

View File

@@ -13,6 +13,7 @@
#include <math.h>
#include "PHY/nr_phy_common/inc/nr_phy_common.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_psbch_defs.h"
#include "common/utils/bits.h"
#define NR_PUSCH_x 2 // UCI placeholder bit TS 38.212 V15.4.0 subclause 5.3.3.1
#define NR_PUSCH_y 3 // UCI placeholder bit

View File

@@ -11,7 +11,7 @@
#include "common/platform_constants.h"
#include "defs_nr_common.h"
#include "PHY/nr_phy_common/inc/nr_phy_common.h"
#include "common/utils/bits.h"
#include "CODING/nrPolar_tools/nr_polar_pbch_defs.h"
#include "openair2/NR_PHY_INTERFACE/NR_IF_Module.h"
#include "PHY/CODING/nrLDPC_coding/nrLDPC_coding_interface.h"

View File

@@ -376,15 +376,4 @@ int nr_get_ssb_start_sc(int scs,
int ssb_offset_point_a,
int ssb_sco,
frequency_range_t freq_range);
bool find_next_rb_block(const uint32_t *bitmap, int size, int *pos, int *start, int *end);
typedef struct {
int first_rb;
int last_rb;
int num_rbs;
uint32_t bitmap[9];
} freq_alloc_bitmap_t;
bool check_rb_in_bitmap(const freq_alloc_bitmap_t *alloc, int rb);
freq_alloc_bitmap_t set_start_end_from_bitmap(int size, int alloc_size, const uint8_t bitmap[alloc_size]);
freq_alloc_bitmap_t set_bitmap_from_start_size(int start, int size);
#endif

View File

@@ -428,79 +428,6 @@ void nr_scale_channel(int size, int ch_estimates_ext[][size], int symb, uint32_t
}
}
freq_alloc_bitmap_t set_start_end_from_bitmap(int size, int alloc_size, const uint8_t bitmap[alloc_size])
{
freq_alloc_bitmap_t alloc = {0};
int num_words = (size + 31) / 32;
AssertFatal(num_words <= sizeofArray(alloc.bitmap),
"freq_alloc_bitmap.bitmap %lu words < %d\n",
sizeofArray(alloc.bitmap),
num_words);
memcpy(alloc.bitmap, bitmap, alloc_size);
alloc.num_rbs = count_bits(alloc.bitmap, num_words);
alloc.first_rb = get_first_bit_index(alloc.bitmap, num_words);
alloc.last_rb = get_last_bit_index(alloc.bitmap, num_words);
AssertFatal(alloc.first_rb >= 0 && alloc.last_rb >=0 , "No valid RB set, no bit set in bitmap\n");
return alloc;
}
freq_alloc_bitmap_t set_bitmap_from_start_size(int start, int size)
{
freq_alloc_bitmap_t alloc = {
.num_rbs = size,
.first_rb = start,
.last_rb = start + size - 1
};
memset(alloc.bitmap, 0, sizeof(alloc.bitmap));
for (int i = start; i < size + start; i++)
alloc.bitmap[i / 32] |= (1U << (i % 32));
return alloc;
}
bool check_rb_in_bitmap(const freq_alloc_bitmap_t *alloc, int rb)
{
return (alloc->bitmap[rb / 32] >> (rb % 32)) & 0x01;
}
/**
* Finds the next contiguous block of set bits.
* @param bitmap The bit buffer
* @param size Total bits in the buffer
* @param pos Pointer to current bit index (updated by function)
* @param start Output: Start index of the found block
* @param end Output: End index of the found block
* @return true if a block was found, false if no more bits are set
*/
bool find_next_rb_block(const uint32_t *bitmap, int size, int *pos, int *start, int *end)
{
AssertFatal(*pos >= 0 && *pos <= size, "Invalid combination of bit index %d and size %d\n", *pos, size);
const int words = (size + 31) / 32;
// Find start of next block
int idx = get_first_bit_index_mask(bitmap, words, *pos, size - *pos);
if (idx < 0)
return false;
*start = idx;
// Find end of block: first zero bit after idx
// Reuse get_first_bit_index_from on the inverted bitmap
idx++;
int word_idx = idx / 32;
int n = words - word_idx;
uint32_t inv[n];
for (int i = 0; i < n; i++)
inv[i] = ~bitmap[word_idx + i];
if (size % 32 != 0)
inv[n - 1] &= (1u << (size % 32)) - 1;
int end_off = get_first_bit_index_mask(inv, n, idx - word_idx * 32, size - idx);
idx = (end_off < 0) ? size : word_idx * 32 + end_off;
*end = (idx > size) ? size - 1 : idx - 1;
*pos = idx; // Update position for the next call
return true;
}
void nr_fo_compensation(double fo_Hz, int samples_per_ms, int sample_offset, const c16_t *rxdata_in, c16_t *rxdata_out, int size)
{
const double phase_inc = -fo_Hz / (samples_per_ms * 1000);