1 /* src/vm/jit/emit-common.c - common code emitter functions
3 Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
30 $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
43 #include "vm/options.h"
45 #if defined(ENABLE_STATISTICS)
46 # include "vm/statistics.h"
49 #include "vm/jit/emit-common.h"
50 #include "vm/jit/jit.h"
53 /* emit_load_s1 ****************************************************************
55 Emits a possible load of the first source operand.
57 *******************************************************************************/
59 s4 emit_load_s1(jitdata *jd, instruction *iptr, s4 tempreg)
64 src = VAROP(iptr->s1);
66 reg = emit_load(jd, iptr, src, tempreg);
72 /* emit_load_s2 ****************************************************************
74 Emits a possible load of the second source operand.
76 *******************************************************************************/
78 s4 emit_load_s2(jitdata *jd, instruction *iptr, s4 tempreg)
83 src = VAROP(iptr->sx.s23.s2);
85 reg = emit_load(jd, iptr, src, tempreg);
91 /* emit_load_s3 ****************************************************************
93 Emits a possible load of the third source operand.
95 *******************************************************************************/
97 s4 emit_load_s3(jitdata *jd, instruction *iptr, s4 tempreg)
102 src = VAROP(iptr->sx.s23.s3);
104 reg = emit_load(jd, iptr, src, tempreg);
110 /* emit_load_s1_low ************************************************************
112 Emits a possible load of the low 32-bits of the first long source
115 *******************************************************************************/
117 #if SIZEOF_VOID_P == 4
118 s4 emit_load_s1_low(jitdata *jd, instruction *iptr, s4 tempreg)
123 src = VAROP(iptr->s1);
125 reg = emit_load_low(jd, iptr, src, tempreg);
132 /* emit_load_s2_low ************************************************************
134 Emits a possible load of the low 32-bits of the second long source
137 *******************************************************************************/
139 #if SIZEOF_VOID_P == 4
140 s4 emit_load_s2_low(jitdata *jd, instruction *iptr, s4 tempreg)
145 src = VAROP(iptr->sx.s23.s2);
147 reg = emit_load_low(jd, iptr, src, tempreg);
154 /* emit_load_s3_low ************************************************************
156 Emits a possible load of the low 32-bits of the third long source
159 *******************************************************************************/
161 #if SIZEOF_VOID_P == 4
162 s4 emit_load_s3_low(jitdata *jd, instruction *iptr, s4 tempreg)
167 src = VAROP(iptr->sx.s23.s3);
169 reg = emit_load_low(jd, iptr, src, tempreg);
176 /* emit_load_s1_high ***********************************************************
178 Emits a possible load of the high 32-bits of the first long source
181 *******************************************************************************/
183 #if SIZEOF_VOID_P == 4
184 s4 emit_load_s1_high(jitdata *jd, instruction *iptr, s4 tempreg)
189 src = VAROP(iptr->s1);
191 reg = emit_load_high(jd, iptr, src, tempreg);
198 /* emit_load_s2_high ***********************************************************
200 Emits a possible load of the high 32-bits of the second long source
203 *******************************************************************************/
205 #if SIZEOF_VOID_P == 4
206 s4 emit_load_s2_high(jitdata *jd, instruction *iptr, s4 tempreg)
211 src = VAROP(iptr->sx.s23.s2);
213 reg = emit_load_high(jd, iptr, src, tempreg);
220 /* emit_load_s3_high ***********************************************************
222 Emits a possible load of the high 32-bits of the third long source
225 *******************************************************************************/
227 #if SIZEOF_VOID_P == 4
228 s4 emit_load_s3_high(jitdata *jd, instruction *iptr, s4 tempreg)
233 src = VAROP(iptr->sx.s23.s3);
235 reg = emit_load_high(jd, iptr, src, tempreg);
242 /* emit_store_dst **************************************************************
244 This function generates the code to store the result of an
245 operation back into a spilled pseudo-variable. If the
246 pseudo-variable has not been spilled in the first place, this
247 function will generate nothing.
249 *******************************************************************************/
251 void emit_store_dst(jitdata *jd, instruction *iptr, s4 d)
253 emit_store(jd, iptr, VAROP(iptr->dst), d);
257 /* emit_bxx ********************************************************************
259 Wrappers for conditional branch instructions.
261 *******************************************************************************/
263 void emit_bc(codegendata *cd, basicblock *target, s4 condition)
268 /* Target basic block already has an PC, so we can generate the
269 branch immediately. */
271 if ((target->mpc >= 0)) {
272 STATISTICS(count_branches_resolved++);
274 /* calculate the mpc of the branch instruction */
276 branchmpc = cd->mcodeptr - cd->mcodebase;
277 disp = target->mpc - branchmpc;
280 emit_branch(cd, disp, condition);
284 /* current mcodeptr is the correct position,
285 afterwards emit the NOPs */
288 codegen_add_branch_ref(cd, target, condition);
291 /* generate NOPs as placeholder for branch code */
292 /* XXX if recompile-with-long-branches */
299 void emit_br(codegendata *cd, basicblock *target)
301 emit_bc(cd, target, BRANCH_UNCONDITIONAL);
305 void emit_beq(codegendata *cd, basicblock *target)
307 emit_bc(cd, target, BRANCH_EQ);
311 void emit_bne(codegendata *cd, basicblock *target)
313 emit_bc(cd, target, BRANCH_NE);
317 void emit_blt(codegendata *cd, basicblock *target)
319 emit_bc(cd, target, BRANCH_LT);
323 void emit_bge(codegendata *cd, basicblock *target)
325 emit_bc(cd, target, BRANCH_GE);
329 void emit_bgt(codegendata *cd, basicblock *target)
331 emit_bc(cd, target, BRANCH_GT);
335 void emit_ble(codegendata *cd, basicblock *target)
337 emit_bc(cd, target, BRANCH_LE);
341 void emit_bnan(codegendata *cd, basicblock *target)
343 emit_bc(cd, target, BRANCH_NAN);
347 /* emit_array_checks ***********************************************************
349 Emit exception checks for array accesses, if they need to be
352 *******************************************************************************/
354 #if defined(__ALPHA__) || defined(__POWERPC__)
355 void emit_array_checks(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
357 if (INSTRUCTION_MUST_CHECK(iptr)) {
358 emit_nullpointer_check(cd, s1);
359 emit_arrayindexoutofbounds_check(cd, s1, s2);
366 * These are local overrides for various environment variables in Emacs.
367 * Please do not remove this and leave it at the end of the file, where
368 * Emacs will automagically detect them.
369 * ---------------------------------------------------------------------
372 * indent-tabs-mode: t
376 * vim:noexpandtab:sw=4:ts=4: