* Merged with 60f051a3c5ae.
[cacao.git] / src / vm / jit / alpha / codegen.h
index 3e81bff67fde688c43a4c69555da001f420626fd..c43ba7b6d56574ea5e20fd3e402a99be17f594a3 100644 (file)
@@ -1,6 +1,6 @@
-/* vm/jit/alpha/codegen.h - code generation macros and definitions for Alpha
+/* src/vm/jit/alpha/codegen.h - code generation macros and definitions for Alpha
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Andreas Krall
-            Reinhard Grafl
-
-   Changes: Christian Thalinger
-
-   $Id: codegen.h 4826 2006-04-24 16:06:16Z twisti $
-
 */
 
 
 
 /* additional functions and macros to generate code ***************************/
 
-/* gen_nullptr_check(objreg) */
-
-#define gen_nullptr_check(objreg) \
-    if (checknull) { \
-        M_BEQZ((objreg), 0); \
-        codegen_add_nullpointerexception_ref(cd); \
-    }
-
 #define gen_bound_check \
     if (checkbounds) { \
         M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
@@ -66,7 +49,7 @@
 
 #define MCODECHECK(icnt) \
     do { \
-        if ((cd->mcodeptr + (icnt)) > (u4 *) cd->mcodeend) \
+        if ((cd->mcodeptr + (icnt) * 4) > cd->mcodeend) \
             codegen_increase(cd); \
     } while (0)
 
     } while (0)
 
 
-#define M_COPY(s,d)                     emit_copy(jd, iptr, (s), (d))
-#define ICONST(d,c)                     emit_iconst(cd, (d), (c))
-#define LCONST(d,c)                     emit_lconst(cd, (d), (c))
+#define ICONST(d,c)        emit_iconst(cd, (d), (c))
+#define LCONST(d,c)        emit_lconst(cd, (d), (c))
+
+
+/* branch defines *************************************************************/
+
+#define BRANCH_NOPS \
+    do { \
+        M_NOP; \
+    } while (0)
+
+
+/* patcher defines ************************************************************/
+
+#define PATCHER_CALL_SIZE    1 * 4     /* an instruction is 4-bytes long      */
+
+#define PATCHER_NOPS \
+    do { \
+        M_NOP; \
+    } while (0)
+
+
+/* stub defines ***************************************************************/
+
+#define COMPILERSTUB_CODESIZE    1 * 4
 
 
 /* macros to create code ******************************************************/
 
+/* M_MEM - memory instruction format *******************************************
+
+    Opcode ........ opcode
+    Ra ............ source/target register for memory access
+    Rb ............ base register
+    Memory_disp ... memory displacement (16 bit signed) to be added to Rb
+
+*******************************************************************************/
+
+#define M_MEM(Opcode,Ra,Rb,Memory_disp) \
+    do { \
+        *((uint32_t *) cd->mcodeptr) = ((((Opcode)) << 26) | ((Ra) << 21) | ((Rb) << 16) | ((Memory_disp) & 0xffff)); \
+        cd->mcodeptr += 4; \
+    } while (0)
+
+#define M_MEM_GET_Opcode(x)             (          (((x) >> 26) & 0x3f  ))
+#define M_MEM_GET_Ra(x)                 (          (((x) >> 21) & 0x1f  ))
+#define M_MEM_GET_Rb(x)                 (          (((x) >> 16) & 0x1f  ))
+#define M_MEM_GET_Memory_disp(x)        ((int16_t) ( (x)        & 0xffff))
+
+
+/* M_BRA - branch instruction format *******************************************
+
+    Opcode ........ opcode
+    Ra ............ register to be tested
+    Branch_disp ... relative address to be jumped to (divided by 4)
+
+*******************************************************************************/
+
+#define M_BRA(Opcode,Ra,Branch_disp) \
+    do { \
+        *((uint32_t *) cd->mcodeptr) = ((((Opcode)) << 26) | ((Ra) << 21) | ((Branch_disp) & 0x1fffff)); \
+        cd->mcodeptr += 4; \
+    } while (0)
+
+
 #define REG   0
 #define CONST 1
 
 */      
 
 #define M_OP3(op,fu,a,b,c,const) \
-       *(cd->mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << (16 - 3 * (const))) | ((const) << 12) | ((fu) << 5) | ((c)))
+    do { \
+        *((u4 *) cd->mcodeptr) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << (16 - 3 * (const))) | ((const) << 12) | ((fu) << 5) | ((c))); \
+        cd->mcodeptr += 4; \
+    } while (0)
 
 
 /* 3-address-floating-point-operation: M_FOP3 
 */ 
 
 #define M_FOP3(op,fu,a,b,c) \
-       *(cd->mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << 16) | ((fu) << 5) | (c))
-
-
-/* branch instructions: M_BRA 
-      op ..... opcode
-      a ...... register to be tested
-      disp ... relative address to be jumped to (divided by 4)
-*/
-
-#define M_BRA(op,a,disp) \
-       *(cd->mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((disp) & 0x1fffff))
-
-
-/* memory operations: M_MEM
-      op ..... opcode
-      a ...... source/target register for memory access
-      b ...... base register
-      disp ... displacement (16 bit signed) to be added to b
-*/ 
-
-#define M_MEM(op,a,b,disp) \
-       *(cd->mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << 16) | ((disp) & 0xffff))
+    do { \
+        *((u4 *) cd->mcodeptr) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << 16) | ((fu) << 5) | (c)); \
+        cd->mcodeptr += 4; \
+    } while (0)
 
 
 /* macros for all used commands (see an Alpha-manual for description) *********/
         } \
     } while (0)
 
+#define M_ALD_INTERN(a,b,disp)  M_LLD_INTERN(a,b,disp)
 #define M_ALD(a,b,disp)         M_LLD(a,b,disp)                 /* addr load  */
 
 #define M_BST(a,b,disp)         M_MEM(0x0e,a,b,disp)            /*  8 store   */
 #define M_LMUL_IMM(a,b,c)       M_OP3 (0x13,0x20, a,b,c,1)      /* 64 mul     */
 
 #define M_AADD_IMM(a,b,c)       M_LADD_IMM(a,b,c)
+#define M_ASUB_IMM(a,b,c)       M_LSUB_IMM(a,b,c)
 
 #define M_CMPEQ(a,b,c)          M_OP3 (0x10,0x2d, a,b,c,0)      /* c = a == b */
 #define M_CMPLT(a,b,c)          M_OP3 (0x10,0x4d, a,b,c,0)      /* c = a <  b */
 #define M_CMOVLE_IMM(a,b,c)     M_OP3 (0x11,0x64, a,b,c,1)     /* a<=0 ? c=b  */
 #define M_CMOVGT_IMM(a,b,c)     M_OP3 (0x11,0x66, a,b,c,1)     /* a> 0 ? c=b  */
 
-/* macros for unused commands (see an Alpha-manual for description) ***********/ 
+/* macros for unused commands (see an Alpha-manual for description) ***********/
 
 #define M_ANDNOT(a,b,c,const)   M_OP3 (0x11,0x08, a,b,c,const) /* c = a &~ b  */
 #define M_ORNOT(a,b,c,const)    M_OP3 (0x11,0x28, a,b,c,const) /* c = a |~ b  */
 
 #define M_JMP_CO(a,b)           M_MEM (0x1a,a,b,0xc000)        /* call cosub  */
 
-
-/* gen_resolvebranch ***********************************************************
-
-   backpatches a branch instruction; Alpha branch instructions are very
-   regular, so it is only necessary to overwrite some fixed bits in the
-   instruction.
-
-   parameters: ip ... pointer to instruction after branch (void*)
-               so ... offset of instruction after branch  (s4)
-               to ... offset of branch target             (s4)
-
-*******************************************************************************/
-
-#define gen_resolvebranch(ip,so,to) \
-    ((s4 *) (ip))[-1] |= ((s4) (to) - (so)) >> 2 & 0x1fffff
-
 #endif /* _CODEGEN_H */