fix set-space ir extension instruction; expand ctrlbits to u16, so that it can encode modern register sized decodes

This commit is contained in:
Ryan Fleury
2024-09-16 11:59:06 -07:00
parent c00fede4f1
commit 84f685803d
7 changed files with 19 additions and 19 deletions
+2 -2
View File
@@ -67,14 +67,14 @@ e_interpret(String8 bytecode)
{
// rjf: consume next opcode
RDI_EvalOp op = (RDI_EvalOp)*ptr;
U8 ctrlbits = 0;
U16 ctrlbits = 0;
if(op < RDI_EvalOp_COUNT)
{
ctrlbits = rdi_eval_op_ctrlbits_table[op];
}
else switch(op)
{
case E_IRExtKind_SetSpace:{ctrlbits = RDI_EVAL_CTRLBITS(16, 0, 0);}break;
case E_IRExtKind_SetSpace:{ctrlbits = RDI_EVAL_CTRLBITS(32, 0, 0);}break;
default:
{
result.code = E_InterpretationCode_BadOp;
+4 -4
View File
@@ -78,7 +78,7 @@ e_select_ir_ctx(E_IRCtx *ctx)
internal void
e_oplist_push_op(Arena *arena, E_OpList *list, RDI_EvalOp opcode, E_Value value)
{
U8 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U16 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
E_Op *node = push_array_no_zero(arena, E_Op, 1);
node->opcode = opcode;
@@ -149,7 +149,7 @@ internal void
e_oplist_push_string_literal(Arena *arena, E_OpList *list, String8 string)
{
RDI_EvalOp opcode = RDI_EvalOp_ConstString;
U8 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U16 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
E_Op *node = push_array_no_zero(arena, E_Op, 1);
node->opcode = opcode;
@@ -1383,7 +1383,7 @@ e_append_oplist_from_irtree(Arena *arena, E_IRNode *root, E_OpList *out)
else
{
// rjf: append ops for all children
U8 ctrlbits = rdi_eval_op_ctrlbits_table[op];
U16 ctrlbits = rdi_eval_op_ctrlbits_table[op];
U64 child_count = RDI_POPN_FROM_CTRLBITS(ctrlbits);
U64 idx = 0;
for(E_IRNode *child = root->first;
@@ -1428,7 +1428,7 @@ e_bytecode_from_oplist(Arena *arena, E_OpList *oplist)
default:
{
// rjf: compute bytecode advance
U8 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U16 ctrlbits = rdi_eval_op_ctrlbits_table[opcode];
U64 extra_byte_count = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
U8 *next_ptr = ptr + 1 + extra_byte_count;
Assert(next_ptr <= opl);
+1 -1
View File
@@ -1385,7 +1385,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
{
break;
}
U8 ctrlbits = rdi_eval_op_ctrlbits_table[op];
U16 ctrlbits = rdi_eval_op_ctrlbits_table[op];
U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
bytecode_size += 1+p_size;
}
+1 -1
View File
@@ -92,7 +92,7 @@ RDI_U8 rdi_section_is_required_table[37] =
0,
};
RDI_U8 rdi_eval_op_ctrlbits_table[49] =
RDI_U16 rdi_eval_op_ctrlbits_table[49] =
{
RDI_EVAL_CTRLBITS(0, 0, 0),
RDI_EVAL_CTRLBITS(0, 0, 0),
+5 -5
View File
@@ -997,10 +997,10 @@ typedef RDI_U32_Table RDI_U32_NameMapBuckets;
typedef RDI_U32_Table RDI_U32_NameMapNodes;
#endif
#define RDI_EVAL_CTRLBITS(decodeN,popN,pushN) ((decodeN) | ((popN) << 5) | ((pushN) << 7))
#define RDI_DECODEN_FROM_CTRLBITS(ctrlbits) ((ctrlbits) & 0x1f)
#define RDI_POPN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 5) & 0x3)
#define RDI_PUSHN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 7) & 0x1)
#define RDI_EVAL_CTRLBITS(decodeN,popN,pushN) (((decodeN) << 8) | ((popN) << 4) | ((pushN) << 0))
#define RDI_DECODEN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 8) & 0xff)
#define RDI_POPN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 4) & 0xf)
#define RDI_PUSHN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 0) & 0xf)
#define RDI_EncodeRegReadParam(reg,bytesize,bytepos) ((reg)|((bytesize)<<8)|((bytepos)<<16))
typedef struct RDI_Header RDI_Header;
@@ -1361,6 +1361,6 @@ RDI_PROC RDI_U8 *rdi_explanation_string_from_eval_conversion_kind(RDI_EvalConver
extern RDI_U16 rdi_section_element_size_table[37];
extern RDI_U8 rdi_section_is_required_table[37];
extern RDI_U8 rdi_eval_op_ctrlbits_table[49];
extern RDI_U16 rdi_eval_op_ctrlbits_table[49];
#endif // RDI_FORMAT_H
+1 -1
View File
@@ -970,7 +970,7 @@ rdim_scope_push_local(RDIM_Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope
RDI_PROC void
rdim_bytecode_push_op(RDIM_Arena *arena, RDIM_EvalBytecode *bytecode, RDI_EvalOp op, RDI_U64 p)
{
RDI_U8 ctrlbits = rdi_eval_op_ctrlbits_table[op];
RDI_U16 ctrlbits = rdi_eval_op_ctrlbits_table[op];
RDI_U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
RDIM_EvalBytecodeOp *node = rdim_push_array(arena, RDIM_EvalBytecodeOp, 1);
+5 -5
View File
@@ -1337,14 +1337,14 @@ RDI_EvalConversionKindTable:
@gen(enums)
```
#define RDI_EVAL_CTRLBITS(decodeN,popN,pushN) ((decodeN) | ((popN) << 5) | ((pushN) << 7))
#define RDI_DECODEN_FROM_CTRLBITS(ctrlbits) ((ctrlbits) & 0x1f)
#define RDI_POPN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 5) & 0x3)
#define RDI_PUSHN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 7) & 0x1)
#define RDI_EVAL_CTRLBITS(decodeN,popN,pushN) (((decodeN) << 8) | ((popN) << 4) | ((pushN) << 0))
#define RDI_DECODEN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 8) & 0xff)
#define RDI_POPN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 4) & 0xf)
#define RDI_PUSHN_FROM_CTRLBITS(ctrlbits) (((ctrlbits) >> 0) & 0xf)
#define RDI_EncodeRegReadParam(reg,bytesize,bytepos) ((reg)|((bytesize)<<8)|((bytepos)<<16))
```
@data(RDI_U8) rdi_eval_op_ctrlbits_table:
@data(RDI_U16) rdi_eval_op_ctrlbits_table:
{
@expand(RDI_EvalOpTable a) `RDI_EVAL_CTRLBITS($(a.num_decodes), $(a.num_pops), $(a.num_pushes))`;
}