cvsuser     03/02/17 07:10:57

  Modified:    languages/imcc optimizer.c symreg.c
               languages/imcc/t/imcpasm opt1.t
  Log:
  imcc-opt #2: fixed big constant floats optimization
  
  Revision  Changes    Path
  1.16      +20 -11    parrot/languages/imcc/optimizer.c
  
  Index: optimizer.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -r1.15 -r1.16
  --- optimizer.c       17 Feb 2003 13:56:36 -0000      1.15
  +++ optimizer.c       17 Feb 2003 15:10:52 -0000      1.16
  @@ -283,9 +283,7 @@
                        atof(ins->r[2]->name) == 0.0)) &&
                   !strcmp(ins->op, "mul")) {
               debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
  -            r = mk_const(ins->r[0]->set == 'I' ? str_dup("0") :
  -                    str_dup("0.000000"),
  -                    ins->r[0]->set);
  +            r = mk_const(str_dup("0"), ins->r[0]->set);
               --ins->r[1]->use_count;
               if (ins->opsize == 4)
                   --ins->r[2]->use_count;
  @@ -368,8 +366,7 @@
                       ins->r[2]->type == VTCONST &&
                       ins->r[2]->set == 'I') {
                   debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
  -                sprintf(b, FLOATVAL_FMT,
  -                        (FLOATVAL)atof(ins->r[2]->name));
  +                strcpy(b, ins->r[2]->name);
                   r = mk_const(str_dup(b), 'N');
                   --ins->r[2]->use_count;
                   ins->r[2] = r;
  @@ -406,8 +403,7 @@
                       ins->r[1]->set == 'I' &&
                       !strcmp(ins->op, ops[i])) {
                   debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
  -                sprintf(b, FLOATVAL_FMT,
  -                        (FLOATVAL)atof(ins->r[1]->name));
  +                strcpy(b, ins->r[1]->name);
                   r = mk_const(str_dup(b), 'N');
                   --ins->r[1]->use_count;
                   ins->r[1] = r;
  @@ -491,7 +487,7 @@
           "sech", "sin", "sinh", "tan", "tanh", "fact"
       };
       size_t i;
  -    char b[128];
  +    char b[128], fmt[64];
       SymReg *r;
       struct Parrot_Context *ctx;
       int found;
  @@ -499,6 +495,19 @@
       /* save interpreter ctx */
       ctx = mem_sys_allocate(sizeof(struct Parrot_Context));
       mem_sys_memcopy(ctx, &interp->ctx, sizeof(struct Parrot_Context));
  +    /* construct a FLOATVAL_FMT with needed precision */
  +    switch (NUMVAL_SIZE) {
  +        case 8:
  +            strcpy(fmt, "%0.16g");
  +            break;
  +        case 12:
  +            strcpy(fmt, "%0.18Lg");
  +            break;
  +        default:
  +            warning("subs_constants", "used default FLOATVAL_FMT\n");
  +            strcpy(fmt, FLOATVAL_FMT);
  +            break;
  +    }
   
       for (ins = instructions; ins; ins = ins->next) {
           found = 0;
  @@ -523,7 +532,7 @@
               }
           }
           if (!found)
  -            break;
  +            continue;
           debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
           /* we construct a parrot instruction
            * here and let parrot do the calculation in a
  @@ -536,8 +545,8 @@
               case 'I':
                   sprintf(b, INTVAL_FMT, interp->ctx.int_reg.registers[0]);
                   break;
  -            case 'N':   /* FIXME precision/exponent */
  -                sprintf(b, FLOATVAL_FMT, interp->ctx.num_reg.registers[0]);
  +            case 'N':
  +                sprintf(b, fmt, interp->ctx.num_reg.registers[0]);
                   break;
           }
           r = mk_const(str_dup(b), ins->r[0]->set);
  
  
  
  1.16      +1 -1      parrot/languages/imcc/symreg.c
  
  Index: symreg.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/symreg.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -r1.15 -r1.16
  --- symreg.c  17 Feb 2003 13:56:36 -0000      1.15
  +++ symreg.c  17 Feb 2003 15:10:52 -0000      1.16
  @@ -46,7 +46,7 @@
   /* Makes a new SymReg from its varname and type */
   SymReg * _mk_symreg(SymReg* hsh[],char * name, char t) {
       SymReg * r;
  -    if((r = _get_sym(hsh, name))) {
  +    if((r = _get_sym(hsh, name)) && r->set == t) {
        free(name);
           return r;
       }
  
  
  
  1.5       +38 -10    parrot/languages/imcc/t/imcpasm/opt1.t
  
  Index: opt1.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/opt1.t,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- opt1.t    17 Feb 2003 13:56:38 -0000      1.4
  +++ opt1.t    17 Feb 2003 15:10:57 -0000      1.5
  @@ -1,6 +1,6 @@
   #!perl
   use strict;
  -use TestCompiler tests => 47;
  +use TestCompiler tests => 49;
   use Test::More qw(skip);
   
   # these tests are run with -O1 by TestCompiler and show
  @@ -105,7 +105,7 @@
      end
   CODE
      set I0, 25
  -   set N0, 25.000000
  +   set N0, 25
      end
   OUT
   
  @@ -116,7 +116,7 @@
      end
   CODE
      set I0, -5
  -   set N0, -5.000000
  +   set N0, -5
      end
   OUT
   
  @@ -127,7 +127,7 @@
      end
   CODE
      set I0, 150
  -   set N0, 150.000000
  +   set N0, 150
      end
   OUT
   
  @@ -138,7 +138,7 @@
      end
   CODE
      set I0, 2
  -   set N0, 2.000000
  +   set N0, 2
      end
   OUT
   
  @@ -149,7 +149,7 @@
      end
   CODE
      set I0, 3
  -   set N0, 3.000000
  +   set N0, 3
      end
   OUT
   
  @@ -160,7 +160,7 @@
      end
   CODE
      set I0, 3
  -   set N0, 3.000000
  +   set N0, 3
      end
   OUT
   
  @@ -381,7 +381,7 @@
      add N0, 10.0, 15
      end
   CODE
  -   set N0, 25.000000
  +   set N0, 25
      end
   OUT
   
  @@ -399,7 +399,7 @@
      set N0, 5
      end
   CODE
  -   set N0, 5.000000
  +   set N0, 5
      end
   OUT
   
  @@ -435,7 +435,7 @@
      mul N0, 0.0, N1
      end
   CODE
  -   set N0, 0.000000
  +   set N0, 0
      end
   OUT
   
  @@ -499,3 +499,31 @@
      set N0, N1
      end
   OUT
  +
  +##############################
  +output_is(<<'CODE', <<'OUT', "multiple const syms");
  +   set I0, 0
  +   set I1, 1
  +   add N0, -1.0, 2
  +   add N0, -1.0, 1
  +   add N0, 1.0, 0
  +   end
  +CODE
  +   set I0, 0
  +   set I1, 1
  +   set N0, 1
  +   set N0, 0
  +   set N0, 1
  +   end
  +OUT
  +
  +##############################
  +output_is(<<'CODE', <<'OUT', "constant add big nums");
  +   add N0, 10.0e20, 15.0e21
  +   end
  +CODE
  +   set N0, 1.6e+22
  +   end
  +OUT
  +
  +
  
  
  


Reply via email to