gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, gawk_performance, updated. 83861dd7beef2


From: John Haque
Subject: [gawk-diffs] [SCM] gawk branch, gawk_performance, updated. 83861dd7beef2bd73e86f17cb196e5131bff5a69
Date: Thu, 08 Sep 2011 10:36:02 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, gawk_performance has been updated
       via  83861dd7beef2bd73e86f17cb196e5131bff5a69 (commit)
      from  0b11e4c50a7f583300ec92fca2d6c4f54df5d30b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=83861dd7beef2bd73e86f17cb196e5131bff5a69

commit 83861dd7beef2bd73e86f17cb196e5131bff5a69
Author: john haque <address@hidden>
Date:   Thu Sep 8 04:53:35 2011 -0500

    Optimization for compound assignment, increment and decrement operators.

diff --git a/eval.c b/eval.c
index 3077a40..f3d2c26 100644
--- a/eval.c
+++ b/eval.c
@@ -1255,7 +1255,7 @@ setup_frame(INSTRUCTION *pc)
        NODE *r = NULL;
        NODE *m, *f, *fp;
        NODE **sp = NULL;
-       int pcount, arg_count, i;
+       int pcount, arg_count, i, j;
 
        f = pc->func_body;
        pcount = f->param_cnt;
@@ -1279,7 +1279,7 @@ setup_frame(INSTRUCTION *pc)
                memset(sp, 0, pcount * sizeof(NODE *));
        }
 
-       for (i = 0; i < pcount; i++) {
+       for (i = 0, j = arg_count - 1; i < pcount; i++, j--) {
                getnode(r);
                memset(r, 0, sizeof(NODE));
                sp[i] = r;
@@ -1290,7 +1290,7 @@ setup_frame(INSTRUCTION *pc)
                        continue;
                }
 
-               m = PEEK(arg_count - i - 1); /* arguments in reverse order on 
runtime stack */
+               m = PEEK(j); /* arguments in reverse order on runtime stack */
 
                if (m->type == Node_param_list)
                        m = GET_PARAM(m->param_cnt);
@@ -1485,38 +1485,37 @@ cmp_scalar()
        return di;
 }
 
+
 /* op_assign --- assignment operators excluding = */
  
 static void
 op_assign(OPCODE op)
 {
        NODE **lhs;
-       NODE *r = NULL;
-       AWKNUM x1, x2;
-#ifndef HAVE_FMOD
-       AWKNUM x;
-#endif
+       NODE *t1;
+       AWKNUM x = 0.0, x1, x2;
 
        lhs = POP_ADDRESS();
-       x1 = force_number(*lhs);
+       t1 = *lhs;
+       x1 = force_number(t1);
        TOP_NUMBER(x2);
-       unref(*lhs);
+
        switch (op) {
        case Op_assign_plus:
-               r = *lhs = make_number(x1 + x2);
+               x = x1 + x2;
                break;
        case Op_assign_minus:
-               r = *lhs = make_number(x1 - x2);
+               x = x1 - x2;
                break;
        case Op_assign_times:
-               r = *lhs = make_number(x1 * x2);
+               x = x1 * x2;
                break;
        case Op_assign_quotient:
                if (x2 == (AWKNUM) 0) {
                        decr_sp();
                        fatal(_("division by zero attempted in `/='"));
                }
-               r = *lhs = make_number(x1 / x2);
+               x = x1 / x2;
                break;
        case Op_assign_mod:
                if (x2 == (AWKNUM) 0) {
@@ -1524,22 +1523,29 @@ op_assign(OPCODE op)
                        fatal(_("division by zero attempted in `%%='"));
                }
 #ifdef HAVE_FMOD
-               r = *lhs = make_number(fmod(x1, x2));
+               x = fmod(x1, x2);
 #else   /* ! HAVE_FMOD */
                (void) modf(x1 / x2, &x);
                x = x1 - x2 * x;
-               r = *lhs = make_number(x);
 #endif  /* ! HAVE_FMOD */
                break;
        case Op_assign_exp:
-               r = *lhs = make_number((AWKNUM) calc_exp((double) x1, (double) 
x2));
+               x = calc_exp((double) x1, (double) x2);
                break;
        default:
                break;
        }
 
-       UPREF(r);
-       REPLACE(r);
+       if (t1->valref == 1 && t1->flags == (MALLOC|NUMCUR|NUMBER)) {
+               /* optimization */
+               t1->numbr = x;
+       } else {
+               unref(t1);
+               t1 = *lhs = make_number(x);
+       }
+
+       UPREF(t1);
+       REPLACE(t1);
 }
 
 
@@ -2023,25 +2029,33 @@ mod:
                case Op_predecrement:
                        x2 = pc->opcode == Op_preincrement ? 1.0 : -1.0;
                        lhs = TOP_ADDRESS();
-                       x1 = force_number(*lhs);
-                       x = x1 + x2;
-                       r = make_number(x);
-                       unref(*lhs);
-                       *lhs = r;
-                       UPREF(r);
-                       REPLACE(r);
+                       t1 = *lhs;
+                       x1 = force_number(t1);
+                       if (t1->valref == 1 && t1->flags == 
(MALLOC|NUMCUR|NUMBER)) {
+                               /* optimization */
+                               t1->numbr = x1 + x2;
+                       } else {
+                               unref(t1);
+                               t1 = *lhs = make_number(x1 + x2);
+                       }
+                       UPREF(t1);
+                       REPLACE(t1);
                        break;
 
                case Op_postincrement:
                case Op_postdecrement:
                        x2 = pc->opcode == Op_postincrement ? 1.0 : -1.0;
                        lhs = TOP_ADDRESS();
-                       x1 = force_number(*lhs);
-                       x = x1 + x2;
-                       t1 = make_number(x);
+                       t1 = *lhs;
+                       x1 = force_number(t1);
+                       if (t1->valref == 1 && t1->flags == 
(MALLOC|NUMCUR|NUMBER)) {
+                               /* optimization */
+                               t1->numbr = x1 + x2;
+                       } else {
+                               unref(t1);
+                               *lhs = make_number(x1 + x2);
+                       }
                        r = make_number(x1);
-                       unref(*lhs);
-                       *lhs = t1;
                        REPLACE(r);
                        break;
 
@@ -2075,7 +2089,7 @@ mod:
        
                        lhs = get_lhs(pc->memory, FALSE);
                        unref(*lhs);
-                       r = pc->initval;
+                       r = pc->initval;        /* constant initializer */
                        if (r == NULL)
                                *lhs = POP_SCALAR();
                        else {

-----------------------------------------------------------------------

Summary of changes:
 eval.c |   78 +++++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 46 insertions(+), 32 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]