Loads and stores for different sizes

This commit is contained in:
Krzosa Karol
2022-06-23 00:03:02 +02:00
parent ce46eb5a8f
commit f7e03e5d2a
2 changed files with 125 additions and 60 deletions

View File

@@ -143,13 +143,25 @@ typedef S32 Register_Index;
union Register{
F64 f64;
S64 s64;
U64 *pointer_u64;
U64 u64;
S64 *pointer_s64;
F64 *pointer_f64;
U64 *pointer64;
U8 *pointer;
U64 *pointer64;
U64 *pointer_u64;
U32 *pointer_u32;
U16 *pointer_u16;
U8 *pointer_u8;
U64 u64;
U32 u32;
U16 u16;
U8 u8;
};
static_assert(sizeof(Register) == 8, "not 8 bytes");
struct Instruction{
Operation operation;
@@ -368,17 +380,6 @@ run_bytecode_interp(Bc *b){
bc_log("i%u[0x%llx] %s ", instr->di, instr, op_name[instr->operation]);
switch(instr->operation){
invalid_default_case;
case BC_LOAD_FROM_MEMORY64:{
U64 *load_address = b->registers[instr->index_a].pointer64;
b->registers[instr->index_c].u64 = *load_address;
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64);
}break;
case BC_STORE_TO_MEMORY64:{
U64 *store_address = b->registers[instr->index_c].pointer64;
*store_address = b->registers[instr->index_a].u64;
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
}break;
case BC_PUSH_STACK:{
U64 *stack = b->stack_pointer++;
@@ -415,6 +416,54 @@ run_bytecode_interp(Bc *b){
// *Begin* of switch_cases generated using code_generating_script.py
//
case BC_LOAD_FROM_MEMORY64:{
U64 *load_address = b->registers[instr->index_a].pointer_u64;
b->registers[instr->index_c].u64 = *load_address;
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64);
}break;
case BC_STORE_TO_MEMORY64:{
U64 *store_address = b->registers[instr->index_c].pointer_u64;
*store_address = b->registers[instr->index_a].u64;
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
}break;
case BC_LOAD_FROM_MEMORY32:{
U32 *load_address = b->registers[instr->index_a].pointer_u32;
b->registers[instr->index_c].u32 = *load_address;
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u32, b->registers[instr->index_c].u32, b->registers[instr->index_c].u32);
}break;
case BC_STORE_TO_MEMORY32:{
U32 *store_address = b->registers[instr->index_c].pointer_u32;
*store_address = b->registers[instr->index_a].u32;
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
}break;
case BC_LOAD_FROM_MEMORY16:{
U16 *load_address = b->registers[instr->index_a].pointer_u16;
b->registers[instr->index_c].u16 = *load_address;
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u16, b->registers[instr->index_c].u16, b->registers[instr->index_c].u16);
}break;
case BC_STORE_TO_MEMORY16:{
U16 *store_address = b->registers[instr->index_c].pointer_u16;
*store_address = b->registers[instr->index_a].u16;
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
}break;
case BC_LOAD_FROM_MEMORY8:{
U8 *load_address = b->registers[instr->index_a].pointer_u8;
b->registers[instr->index_c].u8 = *load_address;
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u8, b->registers[instr->index_c].u8, b->registers[instr->index_c].u8);
}break;
case BC_STORE_TO_MEMORY8:{
U8 *store_address = b->registers[instr->index_c].pointer_u8;
*store_address = b->registers[instr->index_a].u8;
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
}break;
case BC_ADD_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -422,7 +471,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] + [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SUB_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -430,7 +479,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] - [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_DIV_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -438,7 +487,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] / [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_MUL_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -446,7 +495,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] * [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_MOD_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -454,7 +503,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] % [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SHR_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -462,7 +511,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] >> [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SHL_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -470,7 +519,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] << [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITAND_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -478,7 +527,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] & [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITOR_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -486,7 +535,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] | [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITXOR_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -494,7 +543,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] ^ [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITNOT_S64:{
S64 left = (S64)b->registers[instr->index_a].s64;
S64 result = ~left;
@@ -502,7 +551,7 @@ run_bytecode_interp(Bc *b){
*dst = result;
bc_log("~ [%lld] = [%lld]", left, result);
}break;
case BC_EQ_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -510,7 +559,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] == [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_NEQ_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -518,7 +567,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] != [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GT_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -526,7 +575,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] > [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LT_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -534,7 +583,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] < [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_OR_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -542,7 +591,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] || [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GTE_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -550,7 +599,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] >= [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LTE_S64:{
S64 left = b->registers[instr->index_a].s64;
S64 right = b->registers[instr->index_b].s64;
@@ -558,7 +607,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].s64 = result;
bc_log("[r%s, %lld] <= [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_ADD_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -566,7 +615,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] + [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SUB_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -574,7 +623,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] - [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_DIV_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -582,7 +631,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] / [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_MUL_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -590,7 +639,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] * [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_MOD_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -598,7 +647,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] % [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SHR_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -606,7 +655,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] >> [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SHL_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -614,7 +663,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] << [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITAND_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -622,7 +671,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] & [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITOR_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -630,7 +679,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] | [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITXOR_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -638,7 +687,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] ^ [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_BITNOT_U64:{
U64 left = (U64)b->registers[instr->index_a].u64;
U64 result = ~left;
@@ -646,7 +695,7 @@ run_bytecode_interp(Bc *b){
*dst = result;
bc_log("~ [%llu] = [%llu]", left, result);
}break;
case BC_EQ_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -654,7 +703,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] == [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_NEQ_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -662,7 +711,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] != [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GT_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -670,7 +719,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] > [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LT_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -678,7 +727,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] < [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_OR_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -686,7 +735,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] || [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GTE_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -694,7 +743,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] >= [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LTE_U64:{
U64 left = b->registers[instr->index_a].u64;
U64 right = b->registers[instr->index_b].u64;
@@ -702,7 +751,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].u64 = result;
bc_log("[r%s, %llu] <= [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_ADD_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -710,7 +759,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] + [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_SUB_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -718,7 +767,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] - [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_DIV_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -726,7 +775,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] / [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_MUL_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -734,7 +783,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] * [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_EQ_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -742,7 +791,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] == [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_NEQ_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -750,7 +799,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] != [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GT_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -758,7 +807,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] > [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LT_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -766,7 +815,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] < [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_GTE_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -774,7 +823,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] >= [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
case BC_LTE_F64:{
F64 left = b->registers[instr->index_a].f64;
F64 right = b->registers[instr->index_b].f64;
@@ -782,7 +831,7 @@ run_bytecode_interp(Bc *b){
b->registers[instr->index_c].f64 = result;
bc_log("[r%s, %f] <= [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
}break;
//
// *End* of switch_cases generated using code_generating_script.py
//