1 /* src/vm/jit/sparc64/emit.c - Sparc code emitter functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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
32 $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
40 #include "vm/jit/sparc64/codegen.h"
42 #include "vm/exceptions.h"
43 #include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
44 #include "vm/jit/abi-asm.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/dseg.h"
47 #include "vm/jit/emit-common.h"
48 #include "vm/jit/jit.h"
49 #include "vm/jit/replace.h"
52 /* emit_load *******************************************************************
54 Emits a possible load of an operand.
56 *******************************************************************************/
58 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
64 /* get required compiler data */
68 if (src->flags & INMEMORY) {
71 disp = src->vv.regoff * 8;
73 if (IS_FLT_DBL_TYPE(src->type))
74 M_DLD(tempreg, REG_SP, disp);
76 M_LDX(tempreg, REG_SP, disp);
87 /* emit_store ******************************************************************
89 Emits a possible store to variable.
91 *******************************************************************************/
93 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
98 /* get required compiler data */
102 if (dst->flags & INMEMORY) {
105 disp = dst->vv.regoff * 8;
107 if (IS_FLT_DBL_TYPE(dst->type))
108 M_DST(d, REG_SP, disp);
110 M_STX(d, REG_SP, disp);
115 /* emit_copy *******************************************************************
117 Generates a register/memory to register/memory copy.
119 *******************************************************************************/
121 void emit_copy(jitdata *jd, instruction *iptr, varinfo *src, varinfo *dst)
127 /* get required compiler data */
132 if ((src->vv.regoff != dst->vv.regoff) ||
133 ((src->flags ^ dst->flags) & INMEMORY)) {
135 /* If one of the variables resides in memory, we can eliminate
136 the register move from/to the temporary register with the
137 order of getting the destination register and the load. */
139 if (IS_INMEMORY(src->flags)) {
140 d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
141 s1 = emit_load(jd, iptr, src, d);
144 s1 = emit_load(jd, iptr, src, REG_IFTMP);
145 d = codegen_reg_of_var(iptr->opc, dst, s1);
149 if (IS_FLT_DBL_TYPE(src->type))
155 emit_store(jd, iptr, dst, d);
160 /* emit_iconst *****************************************************************
164 *******************************************************************************/
166 void emit_iconst(codegendata *cd, s4 d, s4 value)
170 if ((value >= -4096) && (value <= 4095)) {
171 M_XOR(REG_ZERO, value, d);
173 disp = dseg_adds4(cd, value);
174 M_ILD(d, REG_PV_CALLEE, disp);
179 /* emit_lconst *****************************************************************
183 *******************************************************************************/
185 void emit_lconst(codegendata *cd, s4 d, s8 value)
189 if ((value >= -4096) && (value <= 4095)) {
190 M_XOR(REG_ZERO, value, d);
192 disp = dseg_adds8(cd, value);
193 M_LDX(d, REG_PV_CALLEE, disp);
198 /* emit_exception_stubs ********************************************************
200 Generates the code for the exception stubs.
202 *******************************************************************************/
204 void emit_exception_stubs(jitdata *jd)
208 /* emit_patcher_stubs **********************************************************
210 Generates the code for the patcher stubs.
212 *******************************************************************************/
214 void emit_patcher_stubs(jitdata *jd)
218 /* emit_replacement_stubs ******************************************************
220 Generates the code for the replacement stubs.
222 *******************************************************************************/
224 void emit_replacement_stubs(jitdata *jd)
228 /* emit_verbosecall_enter ******************************************************
230 Generates the code for the call trace.
232 *******************************************************************************/
235 void emit_verbosecall_enter(jitdata *jd)
244 /* get required compiler data */
252 /* mark trace code */
256 M_LDA(REG_SP, REG_SP, -(1 + WINSAVE_CNT + FLT_ARG_CNT) * 8);
258 /* save float argument registers */
260 for (i = 0; i < FLT_ARG_CNT; i++)
261 M_DST(rd->argfltregs[i], REG_SP, BIAS + (WINSAVE_CNT + 1 + i) * 8);
263 /* save temporary registers for leaf methods */
264 /* XXX no leaf optimization yet
265 if (jd->isleafmethod) {
266 for (i = 0; i < INT_TMP_CNT; i++)
267 M_LST(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
269 for (i = 0; i < FLT_TMP_CNT; i++)
270 M_DST(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
273 /* load float arguments into integer registers */
275 for (i = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
276 t = md->paramtypes[i].type;
278 if (IS_FLT_DBL_TYPE(t)) {
279 if (IS_2_WORD_TYPE(t)) {
280 M_DST(rd->argfltregs[i], REG_SP, USESTACK);
281 M_LDX(rd->argintregs[i], REG_SP, USESTACK);
284 M_DST(rd->argfltregs[i], REG_SP, USESTACK);
285 M_LDX(rd->argintregs[i], REG_SP, USESTACK);
290 disp = dseg_add_address(cd, m);
291 M_ALD(REG_ITMP1, REG_PV_CALLEE, disp);
292 M_AST(REG_ITMP1, REG_SP, USESTACK);
293 disp = dseg_add_functionptr(cd, builtin_trace_args);
294 M_ALD(REG_PV_CALLER, REG_PV_CALLEE, disp);
295 M_JMP(REG_RA_CALLER, REG_PV_CALLER, REG_ZERO);
298 /* restore float argument registers */
300 for (i = 0; i < FLT_ARG_CNT; i++)
301 M_DLD(rd->argfltregs[i], REG_SP, BIAS + (WINSAVE_CNT + 1 + i) * 8);
303 /* restore temporary registers for leaf methods */
304 /* XXX no leaf optimization yet
305 if (jd->isleafmethod) {
306 for (i = 0; i < INT_TMP_CNT; i++)
307 M_LLD(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
309 for (i = 0; i < FLT_TMP_CNT; i++)
310 M_DLD(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
313 M_LDA(REG_SP, REG_SP, (1 + WINSAVE_CNT + FLT_ARG_CNT) * 8);
315 /* mark trace code */
319 #endif /* !defined(NDEBUG) */
322 /* emit_verbosecall_exit *******************************************************
324 Generates the code for the call trace.
326 *******************************************************************************/
329 void emit_verbosecall_exit(jitdata *jd)
336 /* get required compiler data */
342 /* mark trace code */
346 M_LDA(REG_SP, REG_SP, -2 * 8); /* keep stack 16-byte aligned ???*/
348 M_DST(REG_FRESULT, REG_SP, USESTACK + (1 * 8));
350 disp = dseg_add_address(cd, m);
351 M_ALD(rd->argintregs[0], REG_PV_CALLEE, disp);
353 M_MOV(REG_RESULT_CALLEE, rd->argintregs[1]);
354 M_DMOV(REG_FRESULT, rd->argfltregs[2]);
355 M_FMOV(REG_FRESULT, rd->argfltregs[3]);
357 disp = dseg_add_functionptr(cd, builtin_displaymethodstop);
358 M_ALD(REG_ITMP3, REG_PV_CALLEE, disp);
359 M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
362 M_DLD(REG_FRESULT, REG_SP, USESTACK + (1 * 8));
364 M_LDA(REG_SP, REG_SP, 2 * 8);
366 /* mark trace code */
370 #endif /* !defined(NDEBUG) */
374 * These are local overrides for various environment variables in Emacs.
375 * Please do not remove this and leave it at the end of the file, where
376 * Emacs will automagically detect them.
377 * ---------------------------------------------------------------------
380 * indent-tabs-mode: t
384 * vim:noexpandtab:sw=4:ts=4: