summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-12 18:15:57 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-12 18:15:57 -0800
commit3b60aa9463bc649ae8982173e0630d864d254806 (patch)
tree26842a7d035a4fa0438066f8fcf2b320a47d3fdb /arith.c
parentfc14a0592d94b1dbb502afe298a67b9b544559af (diff)
downloadtxr-3b60aa9463bc649ae8982173e0630d864d254806.tar.gz
txr-3b60aa9463bc649ae8982173e0630d864d254806.tar.bz2
txr-3b60aa9463bc649ae8982173e0630d864d254806.zip
Some bignum-related optimizations
* arith.c (plus, minus, mul, trunc): Optimize cases where bignum is opposite 1 or 0.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/arith.c b/arith.c
index 18a5fc37..e4972209 100644
--- a/arith.c
+++ b/arith.c
@@ -304,6 +304,8 @@ tail:
case BGNUM:
{
val n;
+ if (anum == zero)
+ return bnum;
n = make_bignum();
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum a = c_num(anum);
@@ -333,6 +335,8 @@ tail:
{
val n;
n = make_bignum();
+ if (bnum == zero)
+ return anum;
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum b = c_num(bnum);
cnum bp = ABS(b);
@@ -426,6 +430,10 @@ tail:
{
val n;
n = make_bignum();
+ if (anum == zero) {
+ mp_neg(mp(bnum), mp(n));
+ return n;
+ }
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum a = c_num(anum);
cnum ap = ABS(a);
@@ -453,6 +461,8 @@ tail:
case BGNUM:
{
val n;
+ if (bnum == zero)
+ return anum;
n = make_bignum();
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum b = c_num(bnum);
@@ -588,6 +598,8 @@ tail:
case BGNUM:
{
val n;
+ if (anum == one)
+ return bnum;
n = make_bignum();
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum a = c_num(anum);
@@ -614,6 +626,8 @@ tail:
case BGNUM:
{
val n;
+ if (bnum == one)
+ return anum;
n = make_bignum();
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum b = c_num(bnum);
@@ -700,6 +714,8 @@ tail:
case BGNUM:
{
val n;
+ if (bnum == one)
+ return anum;
n = make_bignum();
if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
cnum b = c_num(bnum);