Storing a global variable
This commit is contained in:
@@ -1,33 +1,4 @@
|
|||||||
|
|
||||||
function Register_Index
|
|
||||||
allocate_register(Bc *b){
|
|
||||||
if(b->free_registers.len == 0){
|
|
||||||
Register_Index result = b->registers.addi({});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Register_Index index = b->free_registers.pop();
|
|
||||||
b->used_registers.add(index);
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
function void
|
|
||||||
release_register(Bc *b, Register_Index reg){
|
|
||||||
if(reg == 0) return;
|
|
||||||
|
|
||||||
B32 found = false;
|
|
||||||
For(b->used_registers){
|
|
||||||
if(it == reg){
|
|
||||||
b->used_registers.unordered_remove(&it);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_msg(found, "Trying to release register that is not used");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function Register_Index
|
function Register_Index
|
||||||
bc_emit_expr(Bc *b, Ast *ast){
|
bc_emit_expr(Bc *b, Ast *ast){
|
||||||
if(!ast) return REG_NULL;
|
if(!ast) return REG_NULL;
|
||||||
@@ -66,11 +37,13 @@ compile_to_bc(){
|
|||||||
}
|
}
|
||||||
CASE(VAR, Decl){
|
CASE(VAR, Decl){
|
||||||
node->bytecode_data_position = exp_alloc(&b->memory, node->type->size, AF_ZeroMemory);
|
node->bytecode_data_position = exp_alloc(&b->memory, node->type->size, AF_ZeroMemory);
|
||||||
Register_Index index = bc_emit_expr(b, node->expr);
|
if(node->expr){
|
||||||
if(index!=REG_NULL){
|
Register_Index expression_index = bc_emit_expr(b, node->expr);
|
||||||
// bc_emit_store(b, )
|
Register_Index address_index = allocate_register(b);
|
||||||
|
emit_load_constant_address(b, address_index, node->bytecode_data_position);
|
||||||
|
emit_memory(b, BC_STORE_TO_MEMORY64, address_index, expression_index);
|
||||||
|
release_register(b, expression_index);
|
||||||
}
|
}
|
||||||
release_register(b, index);
|
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
default: {}
|
default: {}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ enum Operation: S32{
|
|||||||
BC_POP_STACK,
|
BC_POP_STACK,
|
||||||
BC_PUSH_STACK,
|
BC_PUSH_STACK,
|
||||||
BC_LOAD_CONSTANT,
|
BC_LOAD_CONSTANT,
|
||||||
BC_STORE_CONSTANT,
|
|
||||||
BC_LOAD_FROM_MEMORY64,
|
BC_LOAD_FROM_MEMORY64,
|
||||||
BC_LOAD_FROM_MEMORY32,
|
BC_LOAD_FROM_MEMORY32,
|
||||||
BC_LOAD_FROM_MEMORY16,
|
BC_LOAD_FROM_MEMORY16,
|
||||||
@@ -71,7 +70,6 @@ const char *op_name[] = {
|
|||||||
"BC_POP_STACK",
|
"BC_POP_STACK",
|
||||||
"BC_PUSH_STACK",
|
"BC_PUSH_STACK",
|
||||||
"BC_LOAD_CONSTANT",
|
"BC_LOAD_CONSTANT",
|
||||||
"BC_STORE_CONSTANT",
|
|
||||||
"BC_LOAD_FROM_MEMORY64",
|
"BC_LOAD_FROM_MEMORY64",
|
||||||
"BC_LOAD_FROM_MEMORY32",
|
"BC_LOAD_FROM_MEMORY32",
|
||||||
"BC_LOAD_FROM_MEMORY16",
|
"BC_LOAD_FROM_MEMORY16",
|
||||||
@@ -147,18 +145,17 @@ union Register{
|
|||||||
enum{
|
enum{
|
||||||
REG_NULL,
|
REG_NULL,
|
||||||
REG_STACK_POINTER,
|
REG_STACK_POINTER,
|
||||||
REG_STACK_BOTTOM,
|
|
||||||
REG_INSTRUCTION_POINTER,
|
REG_INSTRUCTION_POINTER,
|
||||||
REG_SPECIAL_COUNT,
|
REG_SPECIAL_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Instruction{
|
struct Instruction{
|
||||||
Operation operation;
|
Operation operation;
|
||||||
S32 dst;
|
S32 index_c;
|
||||||
union{
|
union{
|
||||||
struct{
|
struct{
|
||||||
union{S32 src; S32 a;};
|
S32 index_a;
|
||||||
S32 b;
|
S32 index_b;
|
||||||
};
|
};
|
||||||
Register constant;
|
Register constant;
|
||||||
};
|
};
|
||||||
@@ -184,6 +181,35 @@ struct Bc{
|
|||||||
// accidently overshoot the stack by 2 gigabytes woo yeee
|
// accidently overshoot the stack by 2 gigabytes woo yeee
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allocating and releasing is for codegen !
|
||||||
|
//
|
||||||
|
function Register_Index
|
||||||
|
allocate_register(Bc *b){
|
||||||
|
Register_Index result = 0;
|
||||||
|
if(b->free_registers.len == 0)
|
||||||
|
result = b->registers.addi({});
|
||||||
|
else
|
||||||
|
result = b->free_registers.pop();
|
||||||
|
|
||||||
|
b->used_registers.add(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function void
|
||||||
|
release_register(Bc *b, Register_Index reg){
|
||||||
|
B32 found = false;
|
||||||
|
For(b->used_registers){
|
||||||
|
if(it == reg){
|
||||||
|
b->used_registers.unordered_remove(&it);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_msg(found, "Trying to release register that is not used");
|
||||||
|
}
|
||||||
|
|
||||||
function Bc
|
function Bc
|
||||||
create_bytecode_interp(){
|
create_bytecode_interp(){
|
||||||
Bc b = {};
|
Bc b = {};
|
||||||
@@ -192,17 +218,19 @@ create_bytecode_interp(){
|
|||||||
b.free_registers = array_make<Register_Index>(pctx->heap, 1024);
|
b.free_registers = array_make<Register_Index>(pctx->heap, 1024);
|
||||||
b.used_registers = array_make<Register_Index>(pctx->heap, 1024);
|
b.used_registers = array_make<Register_Index>(pctx->heap, 1024);
|
||||||
|
|
||||||
|
for(S32 i = 0; i < REG_SPECIAL_COUNT; i++){
|
||||||
|
allocate_register(&b);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
arena_init(&b.instructions, "Bytecode instructions"_s);
|
arena_init(&b.instructions, "Bytecode instructions"_s);
|
||||||
arena_push_size(&b.instructions, 16); // Commit
|
arena_push_size(&b.instructions, 16); // Commit
|
||||||
arena_clear(&b.instructions);
|
arena_clear(&b.instructions);
|
||||||
b.registers[REG_INSTRUCTION_POINTER].pointer = b.instructions.memory.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
arena_init(&b.stack, "Bytecode stack"_s);
|
arena_init(&b.stack, "Bytecode stack"_s);
|
||||||
arena_push_size(&b.stack, kib(4)); // Setup a 4 kilobyte stack
|
arena_push_size(&b.stack, kib(4)); // Setup a 4 kilobyte stack
|
||||||
b.registers[REG_STACK_POINTER].pointer = b.stack_bottom = b.stack.memory.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arena_init(&b.memory, "Bytecode memory"_s);
|
arena_init(&b.memory, "Bytecode memory"_s);
|
||||||
@@ -225,69 +253,70 @@ new_instruction(Bc *b){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_load_constant_f64(Bc *b, U8 dst, F64 constant){
|
emit_load_constant_f64(Bc *b, Register_Index dst, F64 constant){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_LOAD_CONSTANT;
|
i->operation = BC_LOAD_CONSTANT;
|
||||||
i->constant.f64 = constant;
|
i->constant.f64 = constant;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
i->debug_type_flag = TYPE_F64;
|
i->debug_type_flag = TYPE_F64;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_load_constant_s64(Bc *b, U8 dst, S64 constant){
|
emit_load_constant_s64(Bc *b, Register_Index dst, S64 constant){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_LOAD_CONSTANT;
|
i->operation = BC_LOAD_CONSTANT;
|
||||||
i->constant.s64 = constant;
|
i->constant.s64 = constant;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
i->debug_type_flag = TYPE_S64;
|
i->debug_type_flag = TYPE_S64;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_load_constant_u64(Bc *b, U8 dst, U64 constant){
|
emit_load_constant_u64(Bc *b, Register_Index dst, U64 constant){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_LOAD_CONSTANT;
|
i->operation = BC_LOAD_CONSTANT;
|
||||||
i->constant.u64 = constant;
|
i->constant.u64 = constant;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
i->debug_type_flag = TYPE_U64;
|
i->debug_type_flag = TYPE_U64;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_constant_store(Bc *b, U8 *address, Register_Index src){
|
emit_load_constant_address(Bc *b, Register_Index dst, void *address){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_STORE_CONSTANT;
|
i->operation = BC_LOAD_CONSTANT;
|
||||||
i->constant.pointer = address;
|
i->constant.pointer = (U8 *)address;
|
||||||
i->src = src;
|
i->index_c = dst;
|
||||||
|
i->debug_type_flag = TYPE_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_push(Bc *b, U8 src){
|
emit_push(Bc *b, Register_Index src){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_PUSH_STACK;
|
i->operation = BC_PUSH_STACK;
|
||||||
i->src = src;
|
i->index_a = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_pop(Bc *b, U8 dst){
|
emit_pop(Bc *b, Register_Index dst){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = BC_POP_STACK;
|
i->operation = BC_POP_STACK;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_memory(Bc *b, Operation ins, U8 dst, U8 src){
|
emit_memory(Bc *b, Operation ins, Register_Index dst, Register_Index src){
|
||||||
auto i = new_instruction(b);
|
auto i = new_instruction(b);
|
||||||
i->operation = ins;
|
i->operation = ins;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
i->src = src;
|
i->index_a = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
emit_arithmetic(Bc *b, Operation ins, U8 left, U8 right, U8 dst){
|
emit_arithmetic(Bc *b, Operation ins, Register_Index left, Register_Index right, Register_Index dst){
|
||||||
Instruction *i = new_instruction(b);
|
Instruction *i = new_instruction(b);
|
||||||
i->operation = ins;
|
i->operation = ins;
|
||||||
i->a = left;
|
i->index_a = left;
|
||||||
i->b = right;
|
i->index_b = right;
|
||||||
i->dst = dst;
|
i->index_c = dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
@@ -306,36 +335,40 @@ emit_end(Bc *b){
|
|||||||
|
|
||||||
function void
|
function void
|
||||||
run_bytecode_interp(Bc *b){
|
run_bytecode_interp(Bc *b){
|
||||||
|
// Setup registers
|
||||||
|
b->registers[REG_INSTRUCTION_POINTER].pointer = b->instructions.memory.data;
|
||||||
|
b->registers[REG_STACK_POINTER].pointer = b->stack_bottom = b->stack.memory.data;
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
auto instr = (Instruction *)b->registers[REG_INSTRUCTION_POINTER].pointer64;
|
auto instr = (Instruction *)b->registers[REG_INSTRUCTION_POINTER].pointer64;
|
||||||
bc_log("%llu.[%llx] - %s ", instr->di, b->registers[REG_INSTRUCTION_POINTER].pointer64, op_name[instr->operation]);
|
bc_log("%llu.[0x%llx] - %s ", instr->di, b->registers[REG_INSTRUCTION_POINTER].pointer64, op_name[instr->operation]);
|
||||||
b->registers[REG_INSTRUCTION_POINTER].pointer += sizeof(Instruction);
|
b->registers[REG_INSTRUCTION_POINTER].pointer += sizeof(Instruction);
|
||||||
|
|
||||||
switch(instr->operation){
|
switch(instr->operation){
|
||||||
default:{}
|
default:{}
|
||||||
case BC_LOAD_FROM_MEMORY64:{
|
case BC_LOAD_FROM_MEMORY64:{
|
||||||
U64 *load_address = b->registers[instr->src].pointer64;
|
U64 *load_address = b->registers[instr->index_a].pointer64;
|
||||||
b->registers[instr->dst].u64 = *load_address;
|
b->registers[instr->index_c].u64 = *load_address;
|
||||||
bc_log("r%u(dst) [%llx|%lld|%f]", instr->dst, b->registers[instr->dst].u64, b->registers[instr->dst].u64, b->registers[instr->dst].u64);
|
bc_log("r%u(dst) [0x%llx|%lld|%f]", instr->index_c, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_STORE_TO_MEMORY64:{
|
case BC_STORE_TO_MEMORY64:{
|
||||||
U64 *store_address = b->registers[instr->dst].pointer64;
|
U64 *store_address = b->registers[instr->index_c].pointer64;
|
||||||
*store_address = b->registers[instr->src].u64;
|
*store_address = b->registers[instr->index_a].u64;
|
||||||
bc_log("r%u(src) [%llx|%lld|%f]", instr->src, *store_address, *store_address, *store_address);
|
bc_log("r%u(src) [0x%llx|%lld|%f]", instr->index_a, *store_address, *store_address, *store_address);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_PUSH_STACK:{
|
case BC_PUSH_STACK:{
|
||||||
U64 *stack = b->registers[REG_STACK_POINTER].pointer64++;
|
U64 *stack = b->registers[REG_STACK_POINTER].pointer64++;
|
||||||
U64 src = b->registers[instr->src].u64;
|
U64 src = b->registers[instr->index_a].u64;
|
||||||
bc_log("r%u(src) [%llx|%lld|%f]", instr->src, src, src, src);
|
bc_log("r%u(src) [0x%llx|%lld|%f]", instr->index_a, src, src, src);
|
||||||
*stack = src;
|
*stack = src;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_POP_STACK:{
|
case BC_POP_STACK:{
|
||||||
U64 *stack = --b->registers[REG_STACK_POINTER].pointer64;
|
U64 *stack = --b->registers[REG_STACK_POINTER].pointer64;
|
||||||
bc_log("r%u(dst) [%llx|%lld|%f]", instr->dst, *stack, *stack, *stack);
|
bc_log("r%u(dst) [0x%llx|%lld|%f]", instr->index_c, *stack, *stack, *stack);
|
||||||
b->registers[instr->dst].u64 = *stack;
|
b->registers[instr->index_c].u64 = *stack;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_END_OF_INSTRUCTIONS:{
|
case BC_END_OF_INSTRUCTIONS:{
|
||||||
@@ -343,12 +376,13 @@ run_bytecode_interp(Bc *b){
|
|||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LOAD_CONSTANT: {
|
case BC_LOAD_CONSTANT: {
|
||||||
b->registers[instr->dst] = instr->constant;
|
b->registers[instr->index_c] = instr->constant;
|
||||||
#if BC_LOG
|
#if BC_LOG
|
||||||
switch(instr->debug_type_flag){
|
switch(instr->debug_type_flag){
|
||||||
case TYPE_S64: bc_log("r%u(dst) [%lld]", instr->dst, instr->constant.s64); break;
|
case TYPE_S64: bc_log("r%u(dst) [%lld]", instr->index_c, instr->constant.s64); break;
|
||||||
case TYPE_U64: bc_log("r%u(dst) [%llu]", instr->dst, instr->constant.u64); break;
|
case TYPE_U64: bc_log("r%u(dst) [%llu]", instr->index_c, instr->constant.u64); break;
|
||||||
case TYPE_F64: bc_log("r%u(dst) [%f]" , instr->dst, instr->constant.f64); break;
|
case TYPE_F64: bc_log("r%u(dst) [%f]" , instr->index_c, instr->constant.f64); break;
|
||||||
|
case TYPE_POINTER: bc_log("r%u(dst) [0x%llx]" , instr->index_c, instr->constant.pointer64); break;
|
||||||
invalid_default_case;
|
invalid_default_case;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -359,371 +393,371 @@ run_bytecode_interp(Bc *b){
|
|||||||
//
|
//
|
||||||
|
|
||||||
case BC_ADD_S64:{
|
case BC_ADD_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left + right;
|
S64 result = left + right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] + [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] + [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SUB_S64:{
|
case BC_SUB_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left - right;
|
S64 result = left - right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] - [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] - [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_DIV_S64:{
|
case BC_DIV_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left / right;
|
S64 result = left / right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] / [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] / [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_MUL_S64:{
|
case BC_MUL_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left * right;
|
S64 result = left * right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] * [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] * [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_MOD_S64:{
|
case BC_MOD_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left % right;
|
S64 result = left % right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] % [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] % [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SHR_S64:{
|
case BC_SHR_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left >> right;
|
S64 result = left >> right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] >> [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] >> [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SHL_S64:{
|
case BC_SHL_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left << right;
|
S64 result = left << right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] << [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] << [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITAND_S64:{
|
case BC_BITAND_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left & right;
|
S64 result = left & right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] & [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] & [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITOR_S64:{
|
case BC_BITOR_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left | right;
|
S64 result = left | right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] | [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] | [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITXOR_S64:{
|
case BC_BITXOR_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left ^ right;
|
S64 result = left ^ right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] ^ [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] ^ [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITNOT_S64:{
|
case BC_BITNOT_S64:{
|
||||||
S64 left = (S64)b->registers[instr->a].s64;
|
S64 left = (S64)b->registers[instr->index_a].s64;
|
||||||
S64 result = ~left;
|
S64 result = ~left;
|
||||||
S64 *dst = b->registers[instr->dst].pointer_s64;
|
S64 *dst = b->registers[instr->index_c].pointer_s64;
|
||||||
*dst = result;
|
*dst = result;
|
||||||
bc_log("~ [%lld] = [%lld]", left, result);
|
bc_log("~ [%lld] = [%lld]", left, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_EQ_S64:{
|
case BC_EQ_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left == right;
|
S64 result = left == right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] == [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] == [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_NEQ_S64:{
|
case BC_NEQ_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left != right;
|
S64 result = left != right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] != [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] != [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GT_S64:{
|
case BC_GT_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left > right;
|
S64 result = left > right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] > [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] > [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LT_S64:{
|
case BC_LT_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left < right;
|
S64 result = left < right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] < [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] < [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_OR_S64:{
|
case BC_OR_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left || right;
|
S64 result = left || right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] || [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] || [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GTE_S64:{
|
case BC_GTE_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left >= right;
|
S64 result = left >= right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] >= [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] >= [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LTE_S64:{
|
case BC_LTE_S64:{
|
||||||
S64 left = b->registers[instr->a].s64;
|
S64 left = b->registers[instr->index_a].s64;
|
||||||
S64 right = b->registers[instr->b].s64;
|
S64 right = b->registers[instr->index_b].s64;
|
||||||
S64 result = left <= right;
|
S64 result = left <= right;
|
||||||
b->registers[instr->dst].s64 = result;
|
b->registers[instr->index_c].s64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%lld] <= [%lld] = [%lld]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%lld] <= [%lld] = [%lld]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_ADD_U64:{
|
case BC_ADD_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left + right;
|
U64 result = left + right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] + [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] + [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SUB_U64:{
|
case BC_SUB_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left - right;
|
U64 result = left - right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] - [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] - [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_DIV_U64:{
|
case BC_DIV_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left / right;
|
U64 result = left / right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] / [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] / [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_MUL_U64:{
|
case BC_MUL_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left * right;
|
U64 result = left * right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] * [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] * [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_MOD_U64:{
|
case BC_MOD_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left % right;
|
U64 result = left % right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] % [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] % [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SHR_U64:{
|
case BC_SHR_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left >> right;
|
U64 result = left >> right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] >> [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] >> [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SHL_U64:{
|
case BC_SHL_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left << right;
|
U64 result = left << right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] << [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] << [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITAND_U64:{
|
case BC_BITAND_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left & right;
|
U64 result = left & right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] & [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] & [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITOR_U64:{
|
case BC_BITOR_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left | right;
|
U64 result = left | right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] | [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] | [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITXOR_U64:{
|
case BC_BITXOR_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left ^ right;
|
U64 result = left ^ right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] ^ [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] ^ [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_BITNOT_U64:{
|
case BC_BITNOT_U64:{
|
||||||
U64 left = (U64)b->registers[instr->a].u64;
|
U64 left = (U64)b->registers[instr->index_a].u64;
|
||||||
U64 result = ~left;
|
U64 result = ~left;
|
||||||
U64 *dst = b->registers[instr->dst].pointer_u64;
|
U64 *dst = b->registers[instr->index_c].pointer_u64;
|
||||||
*dst = result;
|
*dst = result;
|
||||||
bc_log("~ [%llu] = [%llu]", left, result);
|
bc_log("~ [%llu] = [%llu]", left, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_EQ_U64:{
|
case BC_EQ_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left == right;
|
U64 result = left == right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] == [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] == [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_NEQ_U64:{
|
case BC_NEQ_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left != right;
|
U64 result = left != right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] != [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] != [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GT_U64:{
|
case BC_GT_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left > right;
|
U64 result = left > right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] > [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] > [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LT_U64:{
|
case BC_LT_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left < right;
|
U64 result = left < right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] < [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] < [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_OR_U64:{
|
case BC_OR_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left || right;
|
U64 result = left || right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] || [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] || [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GTE_U64:{
|
case BC_GTE_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left >= right;
|
U64 result = left >= right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] >= [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] >= [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LTE_U64:{
|
case BC_LTE_U64:{
|
||||||
U64 left = b->registers[instr->a].u64;
|
U64 left = b->registers[instr->index_a].u64;
|
||||||
U64 right = b->registers[instr->b].u64;
|
U64 right = b->registers[instr->index_b].u64;
|
||||||
U64 result = left <= right;
|
U64 result = left <= right;
|
||||||
b->registers[instr->dst].u64 = result;
|
b->registers[instr->index_c].u64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%llu] <= [%llu] = [%llu]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%llu] <= [%llu] = [%llu]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_ADD_F64:{
|
case BC_ADD_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left + right;
|
F64 result = left + right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] + [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] + [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_SUB_F64:{
|
case BC_SUB_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left - right;
|
F64 result = left - right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] - [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] - [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_DIV_F64:{
|
case BC_DIV_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left / right;
|
F64 result = left / right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] / [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] / [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_MUL_F64:{
|
case BC_MUL_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left * right;
|
F64 result = left * right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] * [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] * [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_EQ_F64:{
|
case BC_EQ_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left == right;
|
F64 result = left == right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] == [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] == [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_NEQ_F64:{
|
case BC_NEQ_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left != right;
|
F64 result = left != right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] != [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] != [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GT_F64:{
|
case BC_GT_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left > right;
|
F64 result = left > right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] > [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] > [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LT_F64:{
|
case BC_LT_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left < right;
|
F64 result = left < right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] < [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] < [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_GTE_F64:{
|
case BC_GTE_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left >= right;
|
F64 result = left >= right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] >= [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] >= [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case BC_LTE_F64:{
|
case BC_LTE_F64:{
|
||||||
F64 left = b->registers[instr->a].f64;
|
F64 left = b->registers[instr->index_a].f64;
|
||||||
F64 right = b->registers[instr->b].f64;
|
F64 right = b->registers[instr->index_b].f64;
|
||||||
F64 result = left <= right;
|
F64 result = left <= right;
|
||||||
b->registers[instr->dst].f64 = result;
|
b->registers[instr->index_c].f64 = result;
|
||||||
bc_log("r%u + r%u = r%u => [%f] <= [%f] = [%f]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%u + r%u = r%u => [%f] <= [%f] = [%f]", instr->index_a, instr->index_b, instr->index_c, left, right, result);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ if True:
|
|||||||
{T} right = b->registers[instr->b].{t};
|
{T} right = b->registers[instr->b].{t};
|
||||||
{T} result = left {symbol} right;
|
{T} result = left {symbol} right;
|
||||||
b->registers[instr->dst].{t} = result;
|
b->registers[instr->dst].{t} = result;
|
||||||
bc_log("r%u + r%u = r%u => [{sign}] {symbol} [{sign}] = [{sign}]", instr->a, instr->b, instr->dst, left, right, result);
|
bc_log("r%s + r%s = r%s => [{sign}] {symbol} [{sign}] = [{sign}]", instr->a, instr->b, instr->dst, left, right, result);
|
||||||
}}break;
|
}}break;
|
||||||
"""
|
"""
|
||||||
################################
|
################################
|
||||||
|
|||||||
Reference in New Issue
Block a user