Skip to content

Commit

Permalink
Use a cheaper way to force_bigint
Browse files Browse the repository at this point in the history
This does rely on mp_digit being at least 32-bit, but we rely on that
elsewhere in multiple other places already. Gives ~15% off a Rat
addition benchmark.
  • Loading branch information
jnthn committed May 17, 2019
1 parent aad6fdc commit 2fe2f58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/math/bigintops.c
Expand Up @@ -166,13 +166,15 @@ static mp_int * force_bigint(MVMThreadContext *tc, const MVMP6bigintBody *body,
return body->u.bigint;
}
else {
MVMint32 value = body->u.smallint.value;
MVMint64 value = body->u.smallint.value;
mp_int *i = tc->temp_bigints[idx];
if (value >= 0) {
mp_set_int(i, value);
mp_digit d = value;
mp_set(i, d);
}
else {
mp_set_int(i, -value);
mp_digit d = -value;
mp_set(i, d);
mp_neg(i, i);
}
return i;
Expand Down

1 comment on commit 2fe2f58

@minad
Copy link

@minad minad commented on 2fe2f58 Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnthn Note that we recently added mp_set_i32 and related functions to tommath master. There are more changes which might be useful for you (bitwise operations, double get/set, ...).

Please sign in to comment.