Merged new changes from default (manually: src/vm/jit/emit-common.cpp, src/vm/ji
[cacao.git] / src / vm / jit / emit-common.hpp
1 /* src/vm/jit/emit-common.hpp - common code emitter functions
2
3    Copyright (C) 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _EMIT_COMMON_H
27 #define _EMIT_COMMON_H
28
29 #include "config.h"
30 #include "vm/types.h"
31
32 #include "arch.h"
33
34 #include "vm/jit/codegen-common.hpp"
35 #include "vm/jit/jit.hpp"
36
37
38 /* branch labels **************************************************************/
39
40 #define BRANCH_LABEL_1    1
41 #define BRANCH_LABEL_2    2
42 #define BRANCH_LABEL_3    3
43 #define BRANCH_LABEL_4    4
44 #define BRANCH_LABEL_5    5
45 #define BRANCH_LABEL_6    6
46 #define BRANCH_LABEL_7    7
47 #define BRANCH_LABEL_8    8
48 #define BRANCH_LABEL_9    9
49 #define BRANCH_LABEL_10  10
50
51
52 /* constant range macros ******************************************************/
53
54 #if SIZEOF_VOID_P == 8
55
56 # define IS_IMM8(c) \
57     (((s8) (c) >= -128) && ((s8) (c) <= 127))
58
59 # define IS_IMM32(c) \
60     (((s8) (c) >= (-2147483647-1)) && ((s8) (c) <= 2147483647))
61
62 #else
63
64 # define IS_IMM8(c) \
65     (((s4) (c) >= -128) && ((s4) (c) <= 127))
66
67 # define IS_IMM16(c) \
68     (((s4) (c) >= -32768) && ((s4) (c) <= 32767))
69
70 #endif
71
72
73 /* code generation functions **************************************************/
74
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78
79 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
80 s4 emit_load_s1(jitdata *jd, instruction *iptr, s4 tempreg);
81 s4 emit_load_s2(jitdata *jd, instruction *iptr, s4 tempreg);
82 s4 emit_load_s3(jitdata *jd, instruction *iptr, s4 tempreg);
83
84 #if SIZEOF_VOID_P == 4
85 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
86 s4 emit_load_s1_low(jitdata *jd, instruction *iptr, s4 tempreg);
87 s4 emit_load_s2_low(jitdata *jd, instruction *iptr, s4 tempreg);
88 s4 emit_load_s3_low(jitdata *jd, instruction *iptr, s4 tempreg);
89
90 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
91 s4 emit_load_s1_high(jitdata *jd, instruction *iptr, s4 tempreg);
92 s4 emit_load_s2_high(jitdata *jd, instruction *iptr, s4 tempreg);
93 s4 emit_load_s3_high(jitdata *jd, instruction *iptr, s4 tempreg);
94 #endif
95
96 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
97 void emit_store_dst(jitdata *jd, instruction *iptr, s4 d);
98
99 #if SIZEOF_VOID_P == 4
100 void emit_store_low(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
101 void emit_store_high(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
102 #endif
103
104 void emit_copy(jitdata *jd, instruction *iptr);
105
106 void emit_iconst(codegendata *cd, s4 d, s4 value);
107 void emit_lconst(codegendata *cd, s4 d, s8 value);
108
109 /* branch-emitting functions */
110 void emit_bccz(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
111 void emit_bcc(codegendata *cd, basicblock *target, s4 condition, u4 options);
112
113 /* wrapper for unconditional branches */
114 void emit_br(codegendata *cd, basicblock *target);
115
116 /* wrappers for branches on one integer register */
117
118 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
119 void emit_beqz(codegendata *cd, basicblock *target, s4 reg);
120 void emit_bnez(codegendata *cd, basicblock *target, s4 reg);
121 void emit_bltz(codegendata *cd, basicblock *target, s4 reg);
122 void emit_bgez(codegendata *cd, basicblock *target, s4 reg);
123 void emit_bgtz(codegendata *cd, basicblock *target, s4 reg);
124 void emit_blez(codegendata *cd, basicblock *target, s4 reg);
125 #endif
126
127 /* wrappers for branches on two integer registers */
128
129 #if SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
130 void emit_beq(codegendata *cd, basicblock *target, s4 s1, s4 s2);
131 void emit_bne(codegendata *cd, basicblock *target, s4 s1, s4 s2);
132 #endif
133
134 /* wrappers for branches on condition codes */
135
136 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
137 void emit_beq(codegendata *cd, basicblock *target);
138 void emit_bne(codegendata *cd, basicblock *target);
139 void emit_blt(codegendata *cd, basicblock *target);
140 void emit_bge(codegendata *cd, basicblock *target);
141 void emit_bgt(codegendata *cd, basicblock *target);
142 void emit_ble(codegendata *cd, basicblock *target);
143 #endif
144
145 #if SUPPORT_BRANCH_CONDITIONAL_UNSIGNED_CONDITIONS
146 void emit_bult(codegendata *cd, basicblock *target);
147 void emit_bule(codegendata *cd, basicblock *target);
148 void emit_buge(codegendata *cd, basicblock *target);
149 void emit_bugt(codegendata *cd, basicblock *target);
150 #endif
151
152 #if defined(__POWERPC__) || defined(__POWERPC64__)
153 void emit_bnan(codegendata *cd, basicblock *target);
154 #endif
155
156 /* label-branches */
157 void emit_label_bccz(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
158 void emit_label(codegendata *cd, s4 label);
159 void emit_label_bcc(codegendata *cd, s4 label, s4 condition, u4 options);
160
161 void emit_label_br(codegendata *cd, s4 label);
162
163 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
164 void emit_label_beqz(codegendata* cd, int label, int reg);
165 void emit_label_bnez(codegendata* cd, int label, int reg);
166 void emit_label_bltz(codegendata* cd, int label, int reg);
167 void emit_label_bgtz(codegendata* cd, int label, int reg);
168 #endif
169
170 #if SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
171 void emit_label_bne(codegendata* cd, int label, int s1, int s2);
172 #endif
173
174 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
175 void emit_label_beq(codegendata *cd, s4 label);
176 void emit_label_bne(codegendata *cd, s4 label);
177 void emit_label_blt(codegendata *cd, s4 label);
178 void emit_label_bge(codegendata *cd, s4 label);
179 void emit_label_bgt(codegendata *cd, s4 label);
180 void emit_label_ble(codegendata *cd, s4 label);
181 #endif
182
183 /* machine dependent branch-emitting function */
184 void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 options);
185
186 void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg);
187 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2);
188 void emit_arraystore_check(codegendata *cd, instruction *iptr);
189 void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 reg, s4 s1);
190 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg);
191 void emit_exception_check(codegendata *cd, instruction *iptr);
192
193 void emit_trap_compiler(codegendata *cd);
194 void emit_trap_countdown(codegendata *cd, s4 *counter);
195 uint32_t emit_trap(codegendata *cd);
196
197 void emit_patcher_traps(jitdata *jd);
198
199 void emit_verbosecall_enter(jitdata *jd);
200 void emit_verbosecall_exit(jitdata *jd);
201
202 #ifdef __cplusplus
203 }
204 #endif
205
206 #endif /* _EMIT_COMMON_H */
207
208
209 /*
210  * These are local overrides for various environment variables in Emacs.
211  * Please do not remove this and leave it at the end of the file, where
212  * Emacs will automagically detect them.
213  * ---------------------------------------------------------------------
214  * Local variables:
215  * mode: c
216  * indent-tabs-mode: t
217  * c-basic-offset: 4
218  * tab-width: 4
219  * End:
220  * vim:noexpandtab:sw=4:ts=4:
221  */