Skip to content

Commit

Permalink
Support endian switching in writeu?int
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Dec 10, 2018
1 parent 652b2f4 commit 73b079c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
18 changes: 16 additions & 2 deletions src/core/interp.c
Expand Up @@ -5405,8 +5405,22 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
MVMuint64 const off = (MVMuint64)GET_REG(cur_op, 2).i64;
MVMuint64 const value = (MVMuint64)GET_REG(cur_op, 4).i64;
MVMuint64 const flags = (MVMuint64)GET_REG(cur_op, 6).i64;
unsigned char const size = 1 << (flags >> ((flags & 1) ? 2 : 1));
REPR(buf)->pos_funcs.write_buf(tc, STABLE(buf), buf, OBJECT_BODY(buf), (char*)&value, off, size);
unsigned char const size = 1 << (flags >> 2);
if ((flags & 3) == 3 || size > 8) {
MVM_exception_throw_adhoc(tc, "Invalid flags value for writeint");
}
if ((flags & 3) == MVM_SWITCHENDIAN) {
MVMRegister byte;
char i;
for(i = 0; i < size; i++) {
byte.i64 = (unsigned char)((value & (0xFFull << (i * 8))) >> (i * 8));
REPR(buf)->pos_funcs.bind_pos(tc, STABLE(buf), buf,
OBJECT_BODY(buf), off + size - 1 - i, byte, MVM_reg_int64);
}
}
else {
REPR(buf)->pos_funcs.write_buf(tc, STABLE(buf), buf, OBJECT_BODY(buf), (char*)&value, off, size);
}
MVM_SC_WB_OBJ(tc, buf);
cur_op += 8;
goto NEXT;
Expand Down
6 changes: 6 additions & 0 deletions src/core/interp.h
Expand Up @@ -95,6 +95,12 @@ struct MVMOpInfo {
#define MVM_operand_uint64 (MVM_reg_uint64 << 3)
#define MVM_operand_type_mask (31 << 3)

#ifdef MVM_BIGENDIAN
#define MVM_SWITCHENDIAN 1
#else
#define MVM_SWITCHENDIAN 2
#endif

/* Functions. */
void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContext *, void *), void *invoke_data);
MVM_PUBLIC void MVM_interp_enable_tracing();
Expand Down
46 changes: 27 additions & 19 deletions src/jit/graph.c
Expand Up @@ -2322,29 +2322,37 @@ static MVMint32 consume_ins(MVMThreadContext *tc, MVMJitGraph *jg,
MVMint16 flags = ins->operands[3].reg.orig;
MVMSpeshFacts *facts = MVM_spesh_get_facts(tc, jg->sg, ins->operands[3]);
if (facts->flags & MVM_SPESH_FACT_KNOWN_VALUE) {
unsigned char const size = 1 << (facts->value.i >> ((facts->value.i & 1) ? 2 : 1));
if ((facts->value.i & 3) != MVM_SWITCHENDIAN) {
unsigned char const size = 1 << (facts->value.i >> 2);

MVMSpeshFacts *type_facts = MVM_spesh_get_facts(tc, jg->sg, ins->operands[0]);
if (type_facts && type_facts->flags & MVM_SPESH_FACT_KNOWN_TYPE && type_facts->type &&
type_facts->flags & MVM_SPESH_FACT_CONCRETE) {
void *function = (void *)((MVMObject*)type_facts->type)->st->REPR->pos_funcs.write_buf;
MVMSpeshFacts *type_facts = MVM_spesh_get_facts(tc, jg->sg, ins->operands[0]);
if (type_facts && type_facts->flags & MVM_SPESH_FACT_KNOWN_TYPE && type_facts->type &&
type_facts->flags & MVM_SPESH_FACT_CONCRETE) {
void *function = (void *)((MVMObject*)type_facts->type)->st->REPR->pos_funcs.write_buf;

MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_STABLE, buf },
{ MVM_JIT_REG_VAL, buf },
{ MVM_JIT_REG_OBJBODY, buf },
{ MVM_JIT_REG_ADDR, value },
{ MVM_JIT_REG_VAL, off },
{ MVM_JIT_LITERAL, size } };
jg_append_call_c(tc, jg, function, 7, args, MVM_JIT_RV_VOID, -1);
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_STABLE, buf },
{ MVM_JIT_REG_VAL, buf },
{ MVM_JIT_REG_OBJBODY, buf },
{ MVM_JIT_REG_ADDR, value },
{ MVM_JIT_REG_VAL, off },
{ MVM_JIT_LITERAL, size } };
jg_append_call_c(tc, jg, function, 7, args, MVM_JIT_RV_VOID, -1);
}
else {
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, buf },
{ MVM_JIT_REG_ADDR, value },
{ MVM_JIT_REG_VAL, off },
{ MVM_JIT_LITERAL, size } };
jg_append_call_c(tc, jg, op_to_func(tc, op), 5, args, MVM_JIT_RV_VOID, -1);
}
}
else {
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, buf },
{ MVM_JIT_REG_ADDR, value },
{ MVM_JIT_REG_VAL, off },
{ MVM_JIT_LITERAL, size } };
jg_append_call_c(tc, jg, op_to_func(tc, op), 5, args, MVM_JIT_RV_VOID, -1);
MVM_spesh_graph_add_comment(tc, iter->graph, iter->ins,
"BAIL: op <%s>, - endian switching not yet supported by JIT",
ins->info->name);
return 0;
}
}
else {
Expand Down

0 comments on commit 73b079c

Please sign in to comment.