engine: add operand bit extraction

Also tracks the current position in the constants array.

Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
Ronald Caesar
2026-01-23 19:08:44 -04:00
parent fd080b323c
commit 6a7db3db18
3 changed files with 30 additions and 9 deletions

View File

@@ -59,8 +59,10 @@ BAL_ALIGNED(64) typedef struct
/// arrays.
bal_instruction_count_t instruction_count;
/// Padding to maintain 64 byte alignment.
char _padding[2];
/// The number of constants emiited.
///
/// This tracks the current position in the `constants` array.
bal_constant_count_t constant_count;
/// The current error state of the Engine.
///

View File

@@ -13,6 +13,7 @@ typedef uint64_t bal_guest_address_t;
typedef uint64_t bal_instruction_t;
typedef uint32_t bal_constant_t;
typedef uint16_t bal_instruction_count_t;
typedef uint16_t bal_constant_count_t;
typedef uint16_t bal_ssa_id_t;
typedef uint8_t bal_bit_width_t;

View File

@@ -1,4 +1,5 @@
#include "bal_engine.h"
#include "bal_decoder.h"
#include <stddef.h>
#include <string.h>
@@ -57,7 +58,8 @@ bal_engine_init (bal_allocator_t *allocator, bal_engine_t *engine)
engine->instructions = (bal_instruction_t *)(data + offset_instructions);
engine->ssa_bit_widths = (bal_bit_width_t *)(data + offset_ssa_bit_widths);
engine->constants = (bal_constant_t *)(data + offset_constants);
engine->source_variables_size = source_variables_size / sizeof(bal_source_variable_t);
engine->source_variables_size
= source_variables_size / sizeof(bal_source_variable_t);
engine->instructions_size = instructions_size / sizeof(bal_instruction_t);
engine->constants_size = constants_size / sizeof(bal_constant_t);
engine->instruction_count = 0;
@@ -106,6 +108,8 @@ bal_engine_translate (bal_engine_t *BAL_RESTRICT engine,
bal_source_variable_t *BAL_RESTRICT source_variables_base
= engine->source_variables;
bal_constant_t constant_count = engine->constant_count;
bal_instruction_count_t instruction_count = engine->instruction_count;
const uint32_t *BAL_RESTRICT arm_instruction_cursor = arm_entry_point;
while (ir_instruction_cursor < ir_instruction_end)
@@ -150,3 +154,17 @@ bal_engine_destroy (bal_allocator_t *allocator, bal_engine_t *engine)
engine->instructions = NULL;
engine->ssa_bit_widths = NULL;
}
BAL_HOT static uint32_t
extract_operand_value (bal_instruction_t instruction,
bal_decoder_operand_t *operand)
{
if (BAL_OPERAND_TYPE_NONE == operand->type)
{
return 0;
}
uint32_t mask = (1U << (uint32_t)operand->bit_width) - 1;
uint32_t bits = (instruction >> (uint32_t)operand->bit_position) & mask;
return bits;
}