File:  [gforth] / gforth / arch / alpha / machine.h
Revision 1.5: download - view: text, annotated - select for diffs
Sat Feb 6 22:28:22 1999 UTC (23 years, 5 months ago) by anton
Branches: MAIN
CVS tags: HEAD
cleaned up threading stuff:
  now the schemes are selected with -DTHREADED_SCHEME=n
  there is now a macro SET_IP for setting ip.
New threading schemes: for Power (20% speedup on 604e) and a plain scheme

    1: /* DEC Alpha
    2: 
    3:   Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
    4: 
    5:   This file is part of Gforth.
    6: 
    7:   Gforth is free software; you can redistribute it and/or
    8:   modify it under the terms of the GNU General Public License
    9:   as published by the Free Software Foundation; either version 2
   10:   of the License, or (at your option) any later version.
   11: 
   12:   This program is distributed in the hope that it will be useful,
   13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15:   GNU General Public License for more details.
   16: 
   17:   You should have received a copy of the GNU General Public License
   18:   along with this program; if not, write to the Free Software
   19:   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20: */
   21: 
   22: /* Be careful: long long on Alpha are 64 bit :-(( */
   23: 
   24: #ifndef THREADING_SCHEME
   25: #define THREADING_SCHEME 5
   26: #endif
   27: 
   28: #if !defined(USE_TOS) && !defined(USE_NO_TOS)
   29: #define USE_TOS
   30: #endif
   31: 
   32: #ifndef INDIRECT_THREADED
   33: #ifndef DIRECT_THREADED
   34: #define DIRECT_THREADED
   35: #endif
   36: #endif
   37: 
   38: #define FLUSH_ICACHE(addr,size)		asm("call_pal 0x86") /* imb (instruction-memory barrier) */
   39: 
   40: #include "../generic/machine.h"
   41: 
   42: #ifdef DIRECT_THREADED
   43: #ifdef WORDS_BIGENDIAN
   44: #error Direct threading only supported for little-endian Alphas.
   45: /* big-endian Alphas still store instructions in little-endian format,
   46:    so you would have to reverse the instruction accesses in the following
   47: */
   48: #endif
   49: #if SIZEOF_CHAR_P != 8
   50: #error Direct threading only supported for Alphas with 64-bit Cells.
   51: /* some of the stuff below assumes that the first cell in a code field
   52:    can contain 2 instructions
   53: 
   54:    A simple way around this problem would be to have _alpha_docol
   55:    contain &&dodoes. This would slow down colon defs, however.
   56: 
   57:    Another way is to use a special DOES_HANDLER, like most other CPUs */
   58: #endif
   59: 
   60: #warning Direct threading for Alpha may not work with all gcc versions
   61: #warning ;CODE does not work on the Alpha with direct threading
   62: /* ;CODE puts a jump to the code after ;CODE into the defined
   63:    word. The code generated for the jump can only jump to targets near
   64:    docol (near means: within 32KB). Because the code is far from
   65:    docol, this does not work.
   66: 
   67:    Solution: let the code be: x=cfa[1]; goto *x;
   68:    */
   69: 
   70: typedef int Int32;
   71: typedef short Int16;
   72: 
   73: /* PFA gives the parameter field address corresponding to a cfa */
   74: #define PFA(cfa)	(((Cell *)cfa)+2)
   75: /* PFA1 is a special version for use just after a NEXT1 */
   76: /* the improvement here is that we may destroy cfa before using PFA1 */
   77: #define PFA1(cfa)       PFA(cfa)
   78: 
   79: /*
   80:    On the Alpha, code (in the text segment) typically cannot be
   81:    reached from the dictionary (in the data segment) with a normal
   82:    branch. It also usually takes too long (and too much space on
   83:    32-bit systems) to load the address as literal and jump indirectly.
   84:    
   85:    So, what we do is this: a pointer into our code (at docol, to be
   86:    exact) is kept in a register: _alpha_docol. When the inner
   87:    interpreter jumps to the word address of a variable etc., the
   88:    destination address is computed from that with a lda instruction
   89:    and stored in another register: _alpha_ca. Then an indirect jump
   90:    through _alpha_ca is performed. For docol, we need not compute
   91:    _alpha_ca first.
   92: 
   93:    How do we tell gcc all this? We declare the registers as variables:
   94:    _alpha_docol as explicit variable, to avoid spilling; _alpha_ca is
   95:    so short-lived, so it hopefully won't be spilled. A
   96:    pseudo-primitive cpu_dep is created with code that lets gcc's data
   97:    flow analysis know that _alpha_docol is used and that _alpha_ca may
   98:    be defined and used after any NEXT and before any primitive.  We
   99:    let gcc choose the register for _alpha_ca and simply change the
  100:    code gcc produces for the cpu_dep routine.
  101: */
  102: 
  103: #define CPU_DEP2	register Label _alpha_docol asm("$9")=&&docol; \
  104: 			register Label _alpha_ca;
  105: 
  106: #define CPU_DEP3	cpu_dep: asm("lda %0, 500(%1)":"=r"(_alpha_ca):"r"(_alpha_docol)); goto *_alpha_ca;
  107: 
  108: #define CPU_DEP1	(&&cpu_dep)
  109: 
  110: 
  111: /* CODE_ADDRESS is the address of the code jumped to through the code field */
  112: #define CODE_ADDRESS(wa)	({Int32 *_wa=(Int32 *)(wa); \
  113: 				    (_wa[0]&0xfc000000)==0x68000000 ? /*JMP?*/\
  114: 				    &&docol : \
  115: 				    &&docol+((Int16 *)_wa)[0]; })
  116: 
  117: #define _CPU_DEP_LABEL	(symbols[DOESJUMP])
  118: #define _DOCOL_LABEL	(symbols[DOCOL])
  119: 
  120: /* MAKE_CF creates an appropriate code field at the wa; ca is the code
  121:    address. For the Alpha, this is a lda followed by a jmp (or just a
  122:    jmp, if ca==&&docol).  We patch the jmp with a good hint (on the
  123:    21064A this saves 5 cycles!) */
  124: #define MAKE_CF(wa,ca)	({ \
  125: 			     Int32 *_wa=(Int32 *)(wa); \
  126: 			     Label _ca=(Label)(ca); \
  127: 			     if (_ca==_DOCOL_LABEL)  \
  128: 			       _wa[0]=(((0x1a<<26)|(31<<21)|(9<<16))| \
  129: 				       (((((Cell)_ca)-((Cell)_wa)-4) & 0xffff)>>2)); \
  130: 			     else { \
  131: 			       _wa[0]=((((Int32 *)_CPU_DEP_LABEL)[0] & 0xffff0000)| \
  132: 				       ((((Cell)_ca)-((Cell)_DOCOL_LABEL)) & 0xffff)); \
  133: 			       _wa[1]=((((Int32 *)_CPU_DEP_LABEL)[1] & 0xffffc000)| \
  134: 				       (((((Cell)_ca)-((Cell)_wa)-8) & 0xffff)>>2));  \
  135: 			     } \
  136: 			})
  137: 
  138: /* this is the point where the does code for the word with the xt cfa
  139:    starts. Because the jump to the code field takes only one cell on
  140:    64-bit systems we can use the second cell of the cfa for storing
  141:    the does address */
  142: #define DOES_CODE(cfa) \
  143:      ({ Int32 *_wa=(cfa); \
  144: 	(_wa[0] == ((((Int32 *)_CPU_DEP_LABEL)[0] & 0xffff0000)| \
  145: 		    ((((Cell)&&dodoes)-((Cell)&&docol)) & 0xffff)) && \
  146: 	 (_wa[1]&0xffffc000) == (((Int32 *)_CPU_DEP_LABEL)[1] & 0xffffc000)) \
  147: 	? DOES_CODE1(_wa) : 0; })
  148: 
  149: /* this is a special version of DOES_CODE for use in dodoes */
  150: #define DOES_CODE1(cfa)	((Xt *)(((Cell *)(cfa))[1]))
  151: 
  152: /* the does handler resides between DOES> and the following Forth
  153:    code. Since the code-field jumps directly to dodoes, the
  154:    does-handler is not needed for the Alpha architecture */
  155: #define MAKE_DOES_HANDLER(addr)   0
  156: 
  157: /* This makes a code field for a does-defined word. doesp is the
  158:    address of the does-code. On the Alpha, the code field consists of
  159:    a jump to dodoes and the address of the does code */
  160: #define MAKE_DOES_CF(cfa,doesp) ({Xt *_cfa = (Xt *)(cfa); \
  161: 				    MAKE_CF(_cfa, symbols[DODOES]); \
  162: 				    _cfa[1] = (doesp); })
  163: #endif
  164: 
  165: #ifdef FORCE_REG
  166: /* $9-$14 are callee-saved, $1-$8 and $22-$25 are caller-saved */
  167: #define IPREG asm("$10")
  168: #define SPREG asm("$11")
  169: #define RPREG asm("$12")
  170: #define LPREG asm("$13")
  171: #define TOSREG asm("$14")
  172: /* #define CFAREG asm("$22") egcs-1.0.3 crashes with any caller-saved
  173:    register decl */
  174: #endif /* FORCE_REG */

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