summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2017-12-12 18:58:59 +0000
committerotto <otto@openbsd.org>2017-12-12 18:58:59 +0000
commite9875b0cb666879b339f3b0f9c8973cda1d9f1fa (patch)
treea897dc1ac7cdcb9f27c399bce5caf1e66d94331a
parentConsistently use .Va for "errno"; (diff)
downloadwireguard-openbsd-e9875b0cb666879b339f3b0f9c8973cda1d9f1fa.tar.xz
wireguard-openbsd-e9875b0cb666879b339f3b0f9c8973cda1d9f1fa.zip
optimize add, sub and mul; from kshe; ok tom@
-rw-r--r--usr.bin/dc/bcode.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index 07e3fa68168..7dea121c9ed 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcode.c,v 1.59 2017/12/05 14:05:22 otto Exp $ */
+/* $OpenBSD: bcode.c,v 1.60 2017/12/12 18:58:59 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -978,7 +978,6 @@ static void
badd(void)
{
struct number *a, *b;
- struct number *r;
a = pop_number();
if (a == NULL)
@@ -989,23 +988,19 @@ badd(void)
return;
}
- r = new_number();
- r->scale = max(a->scale, b->scale);
- if (r->scale > a->scale)
- normalize(a, r->scale);
- else if (r->scale > b->scale)
- normalize(b, r->scale);
- bn_check(BN_add(r->number, a->number, b->number));
- push_number(r);
+ if (b->scale > a->scale)
+ normalize(a, b->scale);
+ else if (a->scale > b->scale)
+ normalize(b, a->scale);
+ bn_check(BN_add(b->number, a->number, b->number));
free_number(a);
- free_number(b);
+ push_number(b);
}
static void
bsub(void)
{
struct number *a, *b;
- struct number *r;
a = pop_number();
if (a == NULL)
@@ -1016,17 +1011,13 @@ bsub(void)
return;
}
- r = new_number();
-
- r->scale = max(a->scale, b->scale);
- if (r->scale > a->scale)
- normalize(a, r->scale);
- else if (r->scale > b->scale)
- normalize(b, r->scale);
- bn_check(BN_sub(r->number, b->number, a->number));
- push_number(r);
+ if (b->scale > a->scale)
+ normalize(a, b->scale);
+ else if (a->scale > b->scale)
+ normalize(b, a->scale);
+ bn_check(BN_sub(b->number, b->number, a->number));
free_number(a);
- free_number(b);
+ push_number(b);
}
void
@@ -1048,7 +1039,6 @@ static void
bmul(void)
{
struct number *a, *b;
- struct number *r;
a = pop_number();
if (a == NULL)
@@ -1059,12 +1049,9 @@ bmul(void)
return;
}
- r = new_number();
- bmul_number(r, a, b, bmachine.scale);
-
- push_number(r);
+ bmul_number(b, a, b, bmachine.scale);
free_number(a);
- free_number(b);
+ push_number(b);
}
static void