Diff for /gforth/vmgen-ex2/engine.c between versions 1.1 and 1.7

version 1.1, 2002/06/02 15:46:17 version 1.7, 2003/08/25 08:02:59
Line 1 Line 1
 /* vm interpreter wrapper  /* vm interpreter wrapper
   
   Copyright (C) 2001 Free Software Foundation, Inc.    Copyright (C) 2001,2002 Free Software Foundation, Inc.
   
   This file is part of Gforth.    This file is part of Gforth.
   
Line 21 Line 21
   
 #include "mini.h"  #include "mini.h"
   
 #define vm_Cell2Cell(_x,_y) ((_y)=(_x))  
   
 #define USE_spTOS 1  #define USE_spTOS 1
   
 #ifdef USE_spTOS  #ifdef USE_spTOS
Line 42 Line 40
   
 /* here you select the threading scheme; I have only set this up for  /* here you select the threading scheme; I have only set this up for
    386 and generic, because I don't know what preprocessor macros to     386 and generic, because I don't know what preprocessor macros to
    test for (Gforth uses config.guess instead).     test for (Gforth uses config.guess instead).  Anyway, it's probably
    Anyway, it's probably best to build them all and select the fastest     best to build them all and select the fastest instead of hardwiring
    instead of hardwiring a specific scheme for an architecture. */     a specific scheme for an architecture.  E.g., scheme 8 is fastest
      for Gforth "make bench" on a 486, whereas scheme 5 is fastest for
      "mini fib.mini" on an Athlon */
 #ifndef THREADING_SCHEME  #ifndef THREADING_SCHEME
 #ifdef i386  
 #define THREADING_SCHEME 8  
 #else  
 #define THREADING_SCHEME 5  #define THREADING_SCHEME 5
 #endif  
 #endif /* defined(THREADING_SCHEME) */  #endif /* defined(THREADING_SCHEME) */
   
   #ifdef __GNUC__
 #if THREADING_SCHEME==1  #if THREADING_SCHEME==1
 /* direct threading scheme 1: autoinc, long latency (HPPA, Sharc) */  /* direct threading scheme 1: autoinc, long latency (HPPA, Sharc) */
 #  define NEXT_P0       ({cfa=*ip++;})  #  define NEXT_P0       ({cfa=*ip++;})
Line 62 Line 59
 #  define INC_IP(const_inc)     ({cfa=IP[const_inc]; ip+=(const_inc);})  #  define INC_IP(const_inc)     ({cfa=IP[const_inc]; ip+=(const_inc);})
 #  define DEF_CA  #  define DEF_CA
 #  define NEXT_P1  #  define NEXT_P1
 #  define NEXT_P2       ({goto *cfa;})  #  define NEXT_P2       ({goto *(cfa.inst);})
 #endif  #endif
   
 #if THREADING_SCHEME==3  #if THREADING_SCHEME==3
Line 74 Line 71
 #  define INC_IP(const_inc)     ({ip+=(const_inc);})  #  define INC_IP(const_inc)     ({ip+=(const_inc);})
 #  define DEF_CA  #  define DEF_CA
 #  define NEXT_P1       ({cfa=*ip++;})  #  define NEXT_P1       ({cfa=*ip++;})
 #  define NEXT_P2       ({goto *cfa;})  #  define NEXT_P2       ({goto *(cfa.inst);})
 #endif  #endif
   
 #if THREADING_SCHEME==5  #if THREADING_SCHEME==5
 /* direct threading scheme 5: early fetching (Alpha, MIPS) */  /* direct threading scheme 5: early fetching (Alpha, MIPS) */
 #  define CFA_NEXT  #  define CFA_NEXT
 #  define NEXT_P0       ({cfa=*ip;})  #  define NEXT_P0       ({cfa=*ip;})
 #  define IP            ((Cell *)ip)  #  define IP            (ip)
 #  define SET_IP(p)     ({ip=(Inst *)(p); NEXT_P0;})  #  define SET_IP(p)     ({ip=(Inst *)(p); NEXT_P0;})
 #  define NEXT_INST     ((Cell)cfa)  #  define NEXT_INST     (cfa)
 #  define INC_IP(const_inc)     ({cfa=ip[const_inc]; ip+=(const_inc);})  #  define INC_IP(const_inc)     ({cfa=ip[const_inc]; ip+=(const_inc);})
 #  define DEF_CA  #  define DEF_CA
 #  define NEXT_P1       (ip++)  #  define NEXT_P1       (ip++)
 #  define NEXT_P2       ({goto *cfa;})  #  define NEXT_P2       ({goto *(cfa.inst);})
 #endif  #endif
   
 #if THREADING_SCHEME==8  #if THREADING_SCHEME==8
Line 114 Line 111
 #  define INC_IP(const_inc)     ({next_cfa=IP[const_inc]; ip+=(const_inc);})  #  define INC_IP(const_inc)     ({next_cfa=IP[const_inc]; ip+=(const_inc);})
 #  define DEF_CA          #  define DEF_CA        
 #  define NEXT_P1       ({cfa=next_cfa; ip++; next_cfa=*ip;})  #  define NEXT_P1       ({cfa=next_cfa; ip++; next_cfa=*ip;})
 #  define NEXT_P2       ({goto *cfa;})  #  define NEXT_P2       ({goto *(cfa.inst);})
 #  define MORE_VARS     Inst next_cfa;  #  define MORE_VARS     Cell next_cfa;
 #endif  #endif
   
 #if THREADING_SCHEME==10  #if THREADING_SCHEME==10
Line 127 Line 124
 #  define INC_IP(const_inc)     ({ip+=(const_inc);})  #  define INC_IP(const_inc)     ({ip+=(const_inc);})
 #  define DEF_CA  #  define DEF_CA
 #  define NEXT_P1  #  define NEXT_P1
 #  define NEXT_P2       ({cfa=*ip++; goto *cfa;})  #  define NEXT_P2       ({cfa=*ip++; goto *(cfa.inst);})
 #endif  #endif
   
   
 #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})  #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})
 #define IPTOS ((Cell)(NEXT_INST))  #define IPTOS ((NEXT_INST))
 #define CASE  
   #define INST_ADDR(name) (Label)&&I_##name
   #define LABEL(name) I_##name:
   #else /* !defined(__GNUC__) */
   /* use switch dispatch */
   #define DEF_CA
   #define NEXT_P0
   #define NEXT_P1
   #define NEXT_P2 goto next_inst;
   #define SET_IP(p)       (ip=(p))
   #define IP              ip
   #define NEXT_INST       (*ip)
   #define INC_IP(const_inc)       (ip+=(const_inc))
   #define IPTOS NEXT_INST
   #define INST_ADDR(name) I_##name
   #define LABEL(name) case I_##name:
   
   #endif /* !defined(__GNUC__) */
   
   #define LABEL2(x)
   
 #ifdef VM_PROFILING  #ifdef VM_PROFILING
 #define SUPER_END  vm_count_block(IP)  #define SUPER_END  vm_count_block(IP)
Line 141 Line 157
 #define SUPER_END  #define SUPER_END
 #endif  #endif
   
 #define INST_ADDR(name) (Label)&&I_##name  #ifndef __GNUC__
 #define LABEL(name) I_##name  enum {
   #include "mini-labels.i"
   };
   #endif
   
   #if defined(__GNUC__) && ((__GNUC__==2 && defined(__GNUC_MINOR__) && __GNUC_MINOR__>=7)||(__GNUC__>2))
   #define MAYBE_UNUSED __attribute__((unused))
   #else
   #define MAYBE_UNUSED
   #endif
   
 /* the return type can be anything you want it to */  /* the return type can be anything you want it to */
 long engine(Cell *ip0, Cell *sp, char *fp)  long engine(Cell *ip0, Cell *sp, char *fp)
 {  {
   /* VM registers (you may want to use gcc's "Explicit Reg Vars" here) */    /* VM registers (you may want to use gcc's "Explicit Reg Vars" here) */
   Cell * ip;    Cell * ip;
   Cell * cfa;    Cell cfa;
 #ifdef USE_spTOS  #ifdef USE_spTOS
   Cell   spTOS;    Cell   spTOS;
 #else  #else
Line 175  long engine(Cell *ip0, Cell *sp, char *f Line 200  long engine(Cell *ip0, Cell *sp, char *f
   
   SET_IP(ip0);    SET_IP(ip0);
   SUPER_END;  /* count the BB starting at ip0 */    SUPER_END;  /* count the BB starting at ip0 */
   NEXT;  
   
   #ifdef __GNUC__
     NEXT;
   #include "mini-vm.i"
   #else  
    next_inst:
     switch((*ip++).inst) {
 #include "mini-vm.i"  #include "mini-vm.i"
     default:
       fprintf(stderr,"unknown instruction %d at %p\n", ip[-1], ip-1);
       exit(1);
     }
   #endif
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.7


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