Skip to content

Commit

Permalink
JIT neg_I and abs_I
Browse files Browse the repository at this point in the history
Rewrite the MVM_BIGINT_UNARY_OP macro the same way as was done for the
MVM_BIGINT_BINARY_OP macro so it can be JITted.
  • Loading branch information
MasterDuke17 committed Jul 21, 2018
1 parent 403460e commit 1ab3b18
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/core/interp.c
Expand Up @@ -3301,17 +3301,13 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
}
OP(neg_I): {
MVMObject * const type = GET_REG(cur_op, 4).o;
MVMObject * const result = MVM_repr_alloc_init(tc, type);
MVM_bigint_neg(tc, result, GET_REG(cur_op, 2).o);
GET_REG(cur_op, 0).o = result;
GET_REG(cur_op, 0).o = MVM_bigint_neg(tc, type, GET_REG(cur_op, 2).o);
cur_op += 6;
goto NEXT;
}
OP(abs_I): {
MVMObject * const type = GET_REG(cur_op, 4).o;
MVMObject * const result = MVM_repr_alloc_init(tc, type);
MVM_bigint_abs(tc, result, GET_REG(cur_op, 2).o);
GET_REG(cur_op, 0).o = result;
GET_REG(cur_op, 0).o = MVM_bigint_abs(tc, type, GET_REG(cur_op, 2).o);
cur_op += 6;
goto NEXT;
}
Expand Down
14 changes: 14 additions & 0 deletions src/jit/core_templates.expr
Expand Up @@ -1436,6 +1436,20 @@
(carg $1 ptr)
(carg $2 ptr)) ptr_sz))

(template: neg_I
(call (^func &MVM_bigint_neg)
(arglist
(carg (tc) ptr)
(carg $2 ptr)
(carg $1 ptr)) int_sz))

(template: abs_I
(call (^func &MVM_bigint_abs)
(arglist
(carg (tc) ptr)
(carg $2 ptr)
(carg $1 ptr)) int_sz))

(template: cmp_I
(call (^func &MVM_bigint_cmp)
(arglist
Expand Down
14 changes: 14 additions & 0 deletions src/jit/graph.c
Expand Up @@ -276,6 +276,8 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
case MVM_OP_sub_I: return MVM_bigint_sub;
case MVM_OP_mul_I: return MVM_bigint_mul;
case MVM_OP_div_I: return MVM_bigint_div;
case MVM_OP_neg_I: return MVM_bigint_neg;
case MVM_OP_abs_I: return MVM_bigint_abs;
case MVM_OP_bor_I: return MVM_bigint_or;
case MVM_OP_band_I: return MVM_bigint_and;
case MVM_OP_bxor_I: return MVM_bigint_xor;
Expand Down Expand Up @@ -2829,6 +2831,18 @@ static MVMint32 consume_ins(MVMThreadContext *tc, MVMJitGraph *jg,
MVM_JIT_RV_PTR, dst);
break;
}
case MVM_OP_neg_I:
case MVM_OP_abs_I: {
MVMint16 src = ins->operands[1].reg.orig;
MVMint16 type = ins->operands[2].reg.orig;
MVMint16 dst = ins->operands[0].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, { MVM_JIT_INTERP_TC } },
{ MVM_JIT_REG_VAL, { type } },
{ MVM_JIT_REG_VAL, { src } } };
jg_append_call_c(tc, jg, op_to_func(tc, op), 3, args,
MVM_JIT_RV_PTR, dst);
break;
}
case MVM_OP_pow_I: {
MVMint16 src_a = ins->operands[1].reg.orig;
MVMint16 src_b = ins->operands[2].reg.orig;
Expand Down
10 changes: 8 additions & 2 deletions src/math/bigintops.c
Expand Up @@ -323,8 +323,13 @@ static void two_complement_shl(mp_int *result, mp_int *value, MVMint64 count) {
}

#define MVM_BIGINT_UNARY_OP(opname, SMALLINT_OP) \
void MVM_bigint_##opname(MVMThreadContext *tc, MVMObject *result, MVMObject *source) { \
MVMP6bigintBody *bb = get_bigint_body(tc, result); \
MVMObject * MVM_bigint_##opname(MVMThreadContext *tc, MVMObject *result_type, MVMObject *source) { \
MVMP6bigintBody *bb; \
MVMObject *result; \
MVMROOT(tc, source, { \
result = MVM_repr_alloc_init(tc, result_type);\
}); \
bb = get_bigint_body(tc, result); \
if (!IS_CONCRETE(source)) { \
store_int64_result(bb, 0); \
} \
Expand All @@ -345,6 +350,7 @@ void MVM_bigint_##opname(MVMThreadContext *tc, MVMObject *result, MVMObject *sou
store_int64_result(bb, sb); \
} \
} \
return result; \
}

#define MVM_BIGINT_BINARY_OP(opname) \
Expand Down
4 changes: 2 additions & 2 deletions src/math/bigintops.h
@@ -1,7 +1,7 @@
int MVM_bigint_mp_set_uint64(mp_int * a, MVMuint64 b);

void MVM_bigint_abs(MVMThreadContext *tc, MVMObject *result, MVMObject *a);
void MVM_bigint_neg(MVMThreadContext *tc, MVMObject *result, MVMObject *a);
MVMObject * MVM_bigint_abs(MVMThreadContext *tc, MVMObject *result, MVMObject *a);
MVMObject * MVM_bigint_neg(MVMThreadContext *tc, MVMObject *result, MVMObject *a);
MVMObject * MVM_bigint_not(MVMThreadContext *tc, MVMObject *result, MVMObject *a);
/* unused */
/* void MVM_bigint_sqrt(MVMObject *b, MVMObject *a); */
Expand Down

0 comments on commit 1ab3b18

Please sign in to comment.