Diff for /gforth/engine/peephole.c between versions 1.2 and 1.3

version 1.2, 2001/02/27 21:17:11 version 1.3, 2001/03/28 16:18:51
Line 34  Combination peephole_table[] = { Line 34  Combination peephole_table[] = {
 #include "peephole.i"  #include "peephole.i"
 };  };
   
 Xt *primtable(Label symbols[], Cell size)  int use_super = 1;
 {  
 #ifdef DIRECT_THREADED  
   return symbols;  
 #else /* !defined(DIRECT_THREADED) */  
   Xt *xts = (Xt *)malloc(size*sizeof(Xt));  
   Cell i;  
   
   for (i=0; i<size; i++)  typedef Xt Inst;
     xts[i] = &symbols[i];  
   return xts;  
 #endif /* !defined(DIRECT_THREADED) */  
 }  
   
 /* we are currently using a simple linear search; we can refine this  typedef struct Peeptable_entry {
    once the interface has settled and this works */    struct Peeptable_entry *next;
     Inst prefix;
     Inst lastprim;
     Inst combination_prim;
   } Peeptable_entry;
   
 Cell prepare_peephole_table(Xt xts[])  #define HASH_SIZE 1024
 {  #define hash(_i1,_i2) (((((Cell)(_i1))^((Cell)(_i2)))>>4)&(HASH_SIZE-1))
   return (Cell)xts;  
 }  
   
 Xt peephole_opt(Xt xt1, Xt xt2, Cell peeptable)  Cell peeptable;
   
   Cell prepare_peephole_table(Inst insts[])
 {  {
   Xt *xts = (Xt *)peeptable;  
   Cell i;    Cell i;
     Peeptable_entry **pt = (Peeptable_entry **)calloc(HASH_SIZE,sizeof(Peeptable_entry *));
   
   for (i=0; i<(sizeof(peephole_table)/sizeof(Combination)); i++) {    for (i=0; i<sizeof(peephole_table)/sizeof(peephole_table[0]); i++) {
     Combination *c = &peephole_table[i];      Combination *c = &peephole_table[i];
     if (xt1 == xts[c->prefix] && xt2 == xts[c->lastprim])      Peeptable_entry *p = (Peeptable_entry *)malloc(sizeof(Peeptable_entry));
       return xts[c->combination_prim];      Cell h;
       p->prefix =           insts[c->prefix];
       p->lastprim =         insts[c->lastprim];
       p->combination_prim = insts[c->combination_prim];
       h = hash(p->prefix,p->lastprim);
       p->next = pt[h];
       pt[h] = p;
   }    }
   return 0;    return (Cell)pt;
   }
   
   Inst peephole_opt(Inst inst1, Inst inst2, Cell peeptable)
   {
     Peeptable_entry **pt = (Peeptable_entry **)peeptable;
     Peeptable_entry *p;
   
     if (use_super == 0)
         return 0;
     for (p = pt[hash(inst1,inst2)]; p != NULL; p = p->next)
       if (inst1 == p->prefix && inst2 == p->lastprim)
         return p->combination_prim;
     return NULL;
 }  }

Removed from v.1.2  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>