d65aee7bda9f41d08f4ff35bad0b24f5b21940b6
[cacao.git] / src / vm / jit / sparc64 / emit.c
1 /* src/vm/jit/sparc64/emit.c - Sparc code emitter functions
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28             Alexander Jordan
29
30    Changes: 
31
32    $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
33
34 */
35
36 #include "vm/types.h"
37
38 #include "md-abi.h"
39
40 #include "vm/jit/jit.h"
41 #include "vm/jit/dseg.h"
42 #include "vm/jit/emit-common.h"
43 #include "vm/jit/sparc64/codegen.h"
44
45
46 /* code generation functions **************************************************/
47
48 /* emit_load *******************************************************************
49
50    Emits a possible load of an operand.
51
52 *******************************************************************************/
53
54 s4 emit_load(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
55 {
56         codegendata  *cd;
57         s4            reg;
58
59         /* get required compiler data */
60
61         cd = jd->cd;
62
63         if (src->flags & INMEMORY) {
64                 COUNT_SPILLS;
65
66                 if (IS_FLT_DBL_TYPE(src->type))
67                         M_DLD(tempreg, REG_SP, src->regoff * 8);
68                 else
69                         M_LDX(tempreg, REG_SP, src->regoff * 8);
70
71                 reg = tempreg;
72         }
73         else
74                 reg = src->regoff;
75
76         return reg;
77 }
78
79
80 /* emit_store ******************************************************************
81
82    Emit a possible store for the given variable.
83
84 *******************************************************************************/
85
86 void emit_store(jitdata *jd, instruction *iptr, stackptr dst, s4 d)
87 {
88         codegendata  *cd;
89
90         /* get required compiler data */
91
92         cd = jd->cd;
93
94         if (dst->flags & INMEMORY) {
95                 COUNT_SPILLS;
96
97                 if (IS_FLT_DBL_TYPE(dst->type))
98                         M_DST(d, REG_SP, dst->regoff * 8);
99                 else
100                         M_STX(d, REG_SP, dst->regoff * 8);
101         }
102 }
103
104
105 /* emit_copy *******************************************************************
106
107    Generates a register/memory to register/memory copy.
108
109 *******************************************************************************/
110
111 void emit_copy(jitdata *jd, instruction *iptr, stackptr src, stackptr dst)
112 {
113         codegendata  *cd;
114         registerdata *rd;
115         s4            s1, d;
116
117         /* get required compiler data */
118
119         cd = jd->cd;
120         rd = jd->rd;
121
122         if ((src->regoff != dst->regoff) ||
123                 ((src->flags ^ dst->flags) & INMEMORY)) {
124
125                 /* If one of the variables resides in memory, we can eliminate
126                    the register move from/to the temporary register with the
127                    order of getting the destination register and the load. */
128
129                 if (IS_INMEMORY(src->flags)) {
130                         d = codegen_reg_of_var(rd, iptr->opc, dst, REG_IFTMP);
131                         s1 = emit_load(jd, iptr, src, d);
132                 }
133                 else {
134                         s1 = emit_load(jd, iptr, src, REG_IFTMP);
135                         d = codegen_reg_of_var(rd, iptr->opc, dst, s1);
136                 }
137
138                 if (s1 != d) {
139                         if (IS_FLT_DBL_TYPE(src->type))
140                                 M_FMOV(s1, d);
141                 else
142                                 M_MOV(s1, d);
143                 }
144
145                 emit_store(jd, iptr, dst, d);
146         }
147 }
148
149
150 /* emit_iconst *****************************************************************
151
152    XXX
153
154 *******************************************************************************/
155
156 void emit_iconst(codegendata *cd, s4 d, s4 value)
157 {
158         s4 disp;
159
160         if ((value >= -4096) && (value <= 4095)) {
161                 M_XOR(REG_ZERO, value, d);
162         } else {
163                 disp = dseg_adds4(cd, value);
164                 M_ILD(d, REG_PV_CALLEE, disp);
165         }
166 }
167
168
169 /* emit_lconst *****************************************************************
170
171    XXX
172
173 *******************************************************************************/
174
175 void emit_lconst(codegendata *cd, s4 d, s8 value)
176 {
177         s4 disp;
178
179         if ((value >= -4096) && (value <= 4095)) {
180                 M_XOR(REG_ZERO, value, d);      
181         } else {
182                 disp = dseg_adds8(cd, value);
183                 M_LDX(d, REG_PV_CALLEE, disp);
184         }
185 }
186
187
188 /* emit_exception_stubs ********************************************************
189
190    Generates the code for the exception stubs.
191
192 *******************************************************************************/
193
194 void emit_exception_stubs(jitdata *jd)
195 {
196 }
197
198 /* emit_patcher_stubs **********************************************************
199
200    Generates the code for the patcher stubs.
201
202 *******************************************************************************/
203
204 void emit_patcher_stubs(jitdata *jd)
205 {
206 }
207
208 /* emit_replacement_stubs ******************************************************
209
210    Generates the code for the replacement stubs.
211
212 *******************************************************************************/
213
214 void emit_replacement_stubs(jitdata *jd)
215 {
216 }
217
218
219 /*
220  * These are local overrides for various environment variables in Emacs.
221  * Please do not remove this and leave it at the end of the file, where
222  * Emacs will automagically detect them.
223  * ---------------------------------------------------------------------
224  * Local variables:
225  * mode: c
226  * indent-tabs-mode: t
227  * c-basic-offset: 4
228  * tab-width: 4
229  * End:
230  * vim:noexpandtab:sw=4:ts=4:
231  */