mirror of
https://github.com/pound-emu/ballistic.git
synced 2026-01-31 01:15:21 +01:00
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:
@@ -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.
|
||||
///
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user