emit.h 2.94 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */



#ifndef EMIT_H
#define EMIT_H

/*
 * this contains the emission macros, but not the 
 * generic EMIT_INST, which must be defined elsewhere
 */

#define  EMIT_FAST

#ifdef EMIT_FAST


#define EMIT_M(_opcode,_ra,_rb,_off) \
           EMIT_U(_opcode<<26|(_ra)<<21|(_rb)<<16|((_off)&0xffff))

#define EMIT_OPI(_opcode,_func,_ra,_lit,_rc) \
        EMIT_U(_opcode<<26|(_ra)<<21|((_lit)&0xff)<<13|(1<<12)|(_func)<<5|(_rc))

#define EMIT_OP(_opcode,_func,_ra,_rb,_rc) \
      EMIT_U(_opcode<<26|(_ra)<<21|(_rb)<<16|(_func)<<5|(_rc))



#else /* EMIT_FAST */
j
#define EMIT_M(_opcode,_ra,_rb,_off) { register union alpha_instruction t; \
          ASSERT(_ra<32 && _rb<32 && ((int64)(_off)) >=-32768 && ((int64)(_off)) <32768); \
          t.common.opcode = _opcode; \
          t.m_format.ra = _ra;  \
          t.m_format.rb = _rb;  \
          t.m_format.memory_displacement = (_off);  \
          EMIT_INSTR(t); } 

#define EMIT_OPI(_opcode,_func,_ra,_lit,_rc) { register union alpha_instruction t; \
          ASSERT( _lit > -127 && _lit < 128 && _ra<32&&_rc<32); \
          t.common.opcode = _opcode; \
          t.l_format.function = _func; \
          t.l_format.form = 1; \
          t.l_format.literal = _lit; \
          t.l_format.ra = _ra;  \
          t.l_format.rc = _rc;  \
          EMIT_INSTR(t); }

#define EMIT_OP(_opcode,_func,_ra,_rb,_rc) { register union alpha_instruction t; \
          t.common.opcode = _opcode; \
          t.o_format.function = _func; \
          t.o_format.form = 0; \
          t.o_format.ra = _ra;  \
          t.o_format.rb = _rb;  \
          t.o_format.rc = _rc;  \
          EMIT_INSTR(t); }

#endif /* EMIT_FAST */


#define EMIT_LDA(_ra,_rb,_off)   EMIT_M(op_lda,_ra,_rb,_off)
#define EMIT_STORE(_ra,_rb,_off) EMIT_M(op_stq,_ra,_rb,_off)
#define EMIT_LOAD(_ra,_rb,_off)  EMIT_M(op_ldq,_ra,_rb,_off)


#define EMIT_JMP(_ra,_rb,_func,_hint) {  register union alpha_instruction t; \
          t.common.opcode = op_jsr; \
          t.j_format.ra = _ra; \
          t.j_format.rb = _rb; \
          t.j_format.function = _func; \
          t.j_format.hint = _hint; \
          EMIT_INSTR(t); }


#define EMIT_ADDI(_ra,_lit,_rc) EMIT_OPI(op_inta,inta_addq,_ra,_lit,_rc)
#define EMIT_MOVE(_src,_dst) EMIT_OP(op_intl,intl_bis,_src,_src,_dst)
#define EMIT_NOP() EMIT_OP(op_intl,intl_bis,REG_ZERO,REG_ZERO,REG_ZERO)

/*
 * reload all caller-saved registers after callout
 */
#define EMIT_RELOAD() { \
     EMIT_LOAD(DELTAREG_CONSTANTS,DELTAREG_BASE,CONSTANTS_OFF); \
     EMIT_LOAD(DELTAREG_CURIQC,DELTAREG_BASE,CURIQC_OFF); \
     EMIT_LOAD(DELTAREG_CURDQC,DELTAREG_BASE,CURDQC_OFF); \
}

#define LENGTH_EMIT_RELOAD 3


extern void  EmitFunctions(int cache);
extern void *GetEmitFunction(int cache, int callout);

#endif