Skip to content

Commit

Permalink
Merge pull request #1346 from MoarVM/optimize-boxed-float-boolification
Browse files Browse the repository at this point in the history
Better specialize boolification of boxed Num
  • Loading branch information
jnthn committed Sep 21, 2020
2 parents 1fdfdf5 + 50d3311 commit 21992e6
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 28 deletions.
4 changes: 4 additions & 0 deletions src/core/interp.c
Expand Up @@ -6423,6 +6423,10 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
}
goto NEXT;
}
OP(sp_istrue_n):
GET_REG(cur_op, 0).i64 = GET_REG(cur_op, 2).n64 ? 1 : 0;
cur_op += 4;
goto NEXT;
OP(sp_boolify_iter): {
GET_REG(cur_op, 0).i64 = MVM_iter_istrue(tc, (MVMIter*)GET_REG(cur_op, 2).o);
cur_op += 4;
Expand Down
2 changes: 1 addition & 1 deletion src/core/oplabels.h
Expand Up @@ -902,6 +902,7 @@ static const void * const LABELS[] = {
&&OP_sp_getstringfrom,
&&OP_sp_getwvalfrom,
&&OP_sp_jit_enter,
&&OP_sp_istrue_n,
&&OP_sp_boolify_iter,
&&OP_sp_boolify_iter_arr,
&&OP_sp_boolify_iter_hash,
Expand Down Expand Up @@ -1024,7 +1025,6 @@ static const void * const LABELS[] = {
NULL,
NULL,
NULL,
NULL,
&&OP_CALL_EXTOP,
&&OP_CALL_EXTOP,
&&OP_CALL_EXTOP,
Expand Down
3 changes: 3 additions & 0 deletions src/core/oplist
Expand Up @@ -1040,6 +1040,9 @@ sp_getwvalfrom .s w(obj) sslot int64 :pure
# Enter the JIT
sp_jit_enter .s w(obj)

# boolification of numeric values
sp_istrue_n .s w(int64) r(num64) :pure

# we boolify iter objects all the time, but we have no op for it. until now!
sp_boolify_iter .s w(int64) r(obj) :pure
sp_boolify_iter_arr .s w(int64) r(obj) :pure
Expand Down
16 changes: 15 additions & 1 deletion src/core/ops.c
Expand Up @@ -12615,6 +12615,20 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
MVM_OP_sp_istrue_n,
"sp_istrue_n",
2,
1,
0,
0,
0,
0,
0,
0,
0,
{ MVM_operand_write_reg | MVM_operand_int64, MVM_operand_read_reg | MVM_operand_num64 }
},
{
MVM_OP_sp_boolify_iter,
"sp_boolify_iter",
Expand Down Expand Up @@ -12897,7 +12911,7 @@ static const MVMOpInfo MVM_op_infos[] = {
},
};

static const unsigned short MVM_op_counts = 921;
static const unsigned short MVM_op_counts = 922;

static const MVMuint16 last_op_allowed = 824;

Expand Down
41 changes: 21 additions & 20 deletions src/core/ops.h
Expand Up @@ -902,26 +902,27 @@
#define MVM_OP_sp_getstringfrom 898
#define MVM_OP_sp_getwvalfrom 899
#define MVM_OP_sp_jit_enter 900
#define MVM_OP_sp_boolify_iter 901
#define MVM_OP_sp_boolify_iter_arr 902
#define MVM_OP_sp_boolify_iter_hash 903
#define MVM_OP_sp_cas_o 904
#define MVM_OP_sp_atomicload_o 905
#define MVM_OP_sp_atomicstore_o 906
#define MVM_OP_sp_add_I 907
#define MVM_OP_sp_sub_I 908
#define MVM_OP_sp_mul_I 909
#define MVM_OP_sp_bool_I 910
#define MVM_OP_prof_enter 911
#define MVM_OP_prof_enterspesh 912
#define MVM_OP_prof_enterinline 913
#define MVM_OP_prof_enternative 914
#define MVM_OP_prof_exit 915
#define MVM_OP_prof_allocated 916
#define MVM_OP_prof_replaced 917
#define MVM_OP_ctw_check 918
#define MVM_OP_coverage_log 919
#define MVM_OP_breakpoint 920
#define MVM_OP_sp_istrue_n 901
#define MVM_OP_sp_boolify_iter 902
#define MVM_OP_sp_boolify_iter_arr 903
#define MVM_OP_sp_boolify_iter_hash 904
#define MVM_OP_sp_cas_o 905
#define MVM_OP_sp_atomicload_o 906
#define MVM_OP_sp_atomicstore_o 907
#define MVM_OP_sp_add_I 908
#define MVM_OP_sp_sub_I 909
#define MVM_OP_sp_mul_I 910
#define MVM_OP_sp_bool_I 911
#define MVM_OP_prof_enter 912
#define MVM_OP_prof_enterspesh 913
#define MVM_OP_prof_enterinline 914
#define MVM_OP_prof_enternative 915
#define MVM_OP_prof_exit 916
#define MVM_OP_prof_allocated 917
#define MVM_OP_prof_replaced 918
#define MVM_OP_ctw_check 919
#define MVM_OP_coverage_log 920
#define MVM_OP_breakpoint 921

#define MVM_OP_EXT_BASE 1024
#define MVM_OP_EXT_CU_LIMIT 1024
Expand Down
1 change: 1 addition & 0 deletions src/jit/graph.c
Expand Up @@ -1763,6 +1763,7 @@ static MVMint32 consume_ins(MVMThreadContext *tc, MVMJitGraph *jg,
case MVM_OP_trunc_u16:
case MVM_OP_trunc_i32:
case MVM_OP_trunc_u32:
case MVM_OP_sp_istrue_n:
/* comparison (integer) */
case MVM_OP_eq_i:
case MVM_OP_ne_i:
Expand Down
11 changes: 11 additions & 0 deletions src/jit/x64/emit.dasc
Expand Up @@ -1470,6 +1470,17 @@ void MVM_jit_emit_primitive(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJ
| mov WORK[dst], TMP2;
break;
}
case MVM_OP_sp_istrue_n: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 src = ins->operands[1].reg.orig;
| movsd xmm0, qword WORK[src];
| xorps xmm1, xmm1;
| cmpsd xmm0, xmm1, 4;
| movd TMP1, xmm0;
| and TMP1, 1;
| mov WORK[dst], TMP1;
break;
}
case MVM_OP_add_n:
case MVM_OP_sub_n:
case MVM_OP_mul_n:
Expand Down
25 changes: 19 additions & 6 deletions src/spesh/optimize.c
Expand Up @@ -1279,12 +1279,25 @@ static void optimize_istrue_isfalse(MVMThreadContext *tc, MVMSpeshGraph *g, MVMS
/* And now defer another bit of optimization */
optimize_isconcrete(tc, g, ins);
break;
/* We need to change the register type for our result for this,
* means we need to insert a temporarary and a coerce:
case MVM_BOOL_MODE_UNBOX_NUM:
op_info = MVM_op_get_op(MVM_OP_unbox_i);
break;
*/
case MVM_BOOL_MODE_UNBOX_NUM: {
/* Unbox it into a temporary number register. */
MVMSpeshOperand temp = MVM_spesh_manipulate_get_temp_reg(tc, g, MVM_reg_num64);
MVMSpeshIns *unbox_ins = MVM_spesh_alloc(tc, g, sizeof(MVMSpeshIns));
unbox_ins->info = MVM_op_get_op(MVM_OP_unbox_n);
unbox_ins->operands = MVM_spesh_alloc(tc, g, 2 * sizeof(MVMSpeshOperand));
unbox_ins->operands[0] = temp;
unbox_ins->operands[1] = ins->operands[1];
MVM_spesh_get_facts(tc, g, unbox_ins->operands[0])->writer = unbox_ins;
MVM_spesh_usages_add_by_reg(tc, g, unbox_ins->operands[1], unbox_ins);
MVM_spesh_usages_delete_by_reg(tc, g, ins->operands[1], ins);
MVM_spesh_manipulate_insert_ins(tc, bb, ins->prev, unbox_ins);

/* Tweak the original instruction to test this. */
ins->info = MVM_op_get_op(MVM_OP_sp_istrue_n);
ins->operands[1] = temp;
MVM_spesh_usages_add_by_reg(tc, g, ins->operands[1], ins);
break;
}
default:
return;
}
Expand Down

0 comments on commit 21992e6

Please sign in to comment.