From: otto Date: Tue, 12 Dec 2017 18:58:59 +0000 (+0000) Subject: optimize add, sub and mul; from kshe; ok tom@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e9875b0cb666879b339f3b0f9c8973cda1d9f1fa;p=openbsd optimize add, sub and mul; from kshe; ok tom@ --- 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 @@ -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