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_ */