* src/vm/jit/sparc64/codegen.c: Ported to unified variables.
[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
47 /* emit_load *******************************************************************
48
49    Emits a possible load of an operand.
50
51 *******************************************************************************/
52
53 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
54 {
55         codegendata  *cd;
56         s4            disp;
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                 disp = src->vv.regoff * 8;
67
68                 if (IS_FLT_DBL_TYPE(src->type))
69                         M_DLD(tempreg, REG_SP, disp);
70                 else
71                         M_LDX(tempreg, REG_SP, disp);
72
73                 reg = tempreg;
74         }
75         else
76                 reg = src->vv.regoff;
77
78         return reg;
79 }
80
81
82 /* emit_store ******************************************************************
83
84    Emits a possible store to variable.
85
86 *******************************************************************************/
87
88 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
89 {
90         codegendata  *cd;
91         s4            disp;
92
93         /* get required compiler data */
94
95         cd = jd->cd;
96
97         if (dst->flags & INMEMORY) {
98                 COUNT_SPILLS;
99
100                 disp = dst->vv.regoff * 8;
101
102                 if (IS_FLT_DBL_TYPE(dst->type))
103                         M_DST(d, REG_SP, disp);
104                 else
105                         M_STX(d, REG_SP, disp);
106         }
107 }
108
109
110 /* emit_copy *******************************************************************
111
112    Generates a register/memory to register/memory copy.
113
114 *******************************************************************************/
115
116 void emit_copy(jitdata *jd, instruction *iptr, varinfo *src, varinfo *dst)
117 {
118         codegendata  *cd;
119         registerdata *rd;
120         s4            s1, d;
121
122         /* get required compiler data */
123
124         cd = jd->cd;
125         rd = jd->rd;
126
127         if ((src->vv.regoff != dst->vv.regoff) ||
128                 ((src->flags ^ dst->flags) & INMEMORY)) {
129
130                 /* If one of the variables resides in memory, we can eliminate
131                    the register move from/to the temporary register with the
132                    order of getting the destination register and the load. */
133
134                 if (IS_INMEMORY(src->flags)) {
135                         d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
136                         s1 = emit_load(jd, iptr, src, d);
137                 }
138                 else {
139                         s1 = emit_load(jd, iptr, src, REG_IFTMP);
140                         d = codegen_reg_of_var(iptr->opc, dst, s1);
141                 }
142
143                 if (s1 != d) {
144                         if (IS_FLT_DBL_TYPE(src->type))
145                                 M_FMOV(s1, d);
146                 else
147                                 M_MOV(s1, d);
148                 }
149
150                 emit_store(jd, iptr, dst, d);
151         }
152 }
153
154
155 /* emit_iconst *****************************************************************
156
157    XXX
158
159 *******************************************************************************/
160
161 void emit_iconst(codegendata *cd, s4 d, s4 value)
162 {
163         s4 disp;
164
165         if ((value >= -4096) && (value <= 4095)) {
166                 M_XOR(REG_ZERO, value, d);
167         } else {
168                 disp = dseg_adds4(cd, value);
169                 M_ILD(d, REG_PV_CALLEE, disp);
170         }
171 }
172
173
174 /* emit_lconst *****************************************************************
175
176    XXX
177
178 *******************************************************************************/
179
180 void emit_lconst(codegendata *cd, s4 d, s8 value)
181 {
182         s4 disp;
183
184         if ((value >= -4096) && (value <= 4095)) {
185                 M_XOR(REG_ZERO, value, d);      
186         } else {
187                 disp = dseg_adds8(cd, value);
188                 M_LDX(d, REG_PV_CALLEE, disp);
189         }
190 }
191
192
193 /* emit_exception_stubs ********************************************************
194
195    Generates the code for the exception stubs.
196
197 *******************************************************************************/
198
199 void emit_exception_stubs(jitdata *jd)
200 {
201 }
202
203 /* emit_patcher_stubs **********************************************************
204
205    Generates the code for the patcher stubs.
206
207 *******************************************************************************/
208
209 void emit_patcher_stubs(jitdata *jd)
210 {
211 }
212
213 /* emit_replacement_stubs ******************************************************
214
215    Generates the code for the replacement stubs.
216
217 *******************************************************************************/
218
219 void emit_replacement_stubs(jitdata *jd)
220 {
221 }
222
223
224 /*
225  * These are local overrides for various environment variables in Emacs.
226  * Please do not remove this and leave it at the end of the file, where
227  * Emacs will automagically detect them.
228  * ---------------------------------------------------------------------
229  * Local variables:
230  * mode: c
231  * indent-tabs-mode: t
232  * c-basic-offset: 4
233  * tab-width: 4
234  * End:
235  * vim:noexpandtab:sw=4:ts=4:
236  */