563a4d4c9b6565a92bb8c4b1ed714b5abfee7ae0
[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/sparc64/codegen.h"
42 #include "vm/jit/sparc64/emit.h"
43
44
45 /* code generation functions **************************************************/
46
47 /* emit_load_s1 ****************************************************************
48
49    Emits a possible load of the first source operand.
50
51 *******************************************************************************/
52
53 s4 emit_load_s1(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
54 {
55         codegendata  *cd;
56         s4            reg;
57
58         /* get required compiler data */
59
60         cd = jd->cd;
61
62         if (src->flags & INMEMORY) {
63                 COUNT_SPILLS;
64
65                 if (IS_FLT_DBL_TYPE(src->type))
66                         M_LDDF(REG_SP, src->regoff * 8, tempreg);
67                 else
68                         M_LDX(REG_SP, src->regoff * 8, tempreg);
69
70                 reg = tempreg;
71         } else
72                 reg = src->regoff;
73
74         return reg;
75 }
76
77
78 /* emit_load_s2 ****************************************************************
79
80    Emits a possible load of the second source operand.
81
82 *******************************************************************************/
83
84 s4 emit_load_s2(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
85 {
86         codegendata  *cd;
87         s4            reg;
88
89         /* get required compiler data */
90
91         cd = jd->cd;
92
93         if (src->flags & INMEMORY) {
94                 COUNT_SPILLS;
95
96                 if (IS_FLT_DBL_TYPE(src->type))
97                         M_LDDF(REG_SP, src->regoff * 8, tempreg);
98                 else
99                         M_LDX(REG_SP, src->regoff * 8, tempreg);
100
101                 reg = tempreg;
102         } else
103                 reg = src->regoff;
104
105         return reg;
106 }
107
108
109 /* emit_load_s3 ****************************************************************
110
111    Emits a possible load of the third source operand.
112
113 *******************************************************************************/
114
115 s4 emit_load_s3(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
116 {
117         codegendata  *cd;
118         s4            reg;
119
120         /* get required compiler data */
121
122         cd = jd->cd;
123
124         if (src->flags & INMEMORY) {
125                 COUNT_SPILLS;
126
127                 if (IS_FLT_DBL_TYPE(src->type))
128                         M_LDDF(REG_SP, src->regoff * 8, tempreg);
129                 else
130                         M_LDX(REG_SP, src->regoff * 8, tempreg);
131
132                 reg = tempreg;
133         } else
134                 reg = src->regoff;
135
136         return reg;
137 }
138
139
140 /* emit_store ******************************************************************
141
142    XXX
143
144 *******************************************************************************/
145
146 void emit_store(jitdata *jd, instruction *iptr, stackptr dst, s4 d)
147 {
148         codegendata  *cd;
149
150         /* get required compiler data */
151
152         cd = jd->cd;
153
154         if (dst->flags & INMEMORY) {
155                 COUNT_SPILLS;
156
157                 if (IS_FLT_DBL_TYPE(dst->type))
158                         M_STDF(d, REG_SP, dst->regoff * 8);
159                 else
160                         M_STX(d, REG_SP, dst->regoff * 8);
161         }
162 }
163
164
165 void emit_copy(jitdata *jd, instruction *iptr, stackptr src, stackptr dst)
166 {
167         codegendata  *cd;
168         registerdata *rd;
169         s4            s1, d;
170
171         /* get required compiler data */
172
173         cd = jd->cd;
174         rd = jd->rd;
175
176         d = codegen_reg_of_var(rd, iptr->opc, dst, REG_IFTMP);
177
178         if ((src->regoff != dst->regoff) ||
179                 ((src->flags ^ dst->flags) & INMEMORY)) {
180                 s1 = emit_load_s1(jd, iptr, src, d);
181
182                 if (IS_FLT_DBL_TYPE(src->type)) {
183                         /* always move doubles for now */
184                         M_DBLMOVE(s1, d);
185                 }
186                 else
187                         M_INTMOVE(s1, d);
188
189                 emit_store(jd, iptr, dst, d);
190         }
191 }
192
193
194 void emit_iconst(codegendata *cd, s4 d, s4 value)
195 {
196         s4 disp;
197
198         if ((value >= -4096) && (value <= 4095)) {
199                 M_IOR(REG_ZERO, value, d, IMM);
200         } else {
201                 disp = dseg_adds4(cd, value);
202                 M_ILD(d, REG_PV, disp);
203         }
204 }
205
206
207 /*
208  * These are local overrides for various environment variables in Emacs.
209  * Please do not remove this and leave it at the end of the file, where
210  * Emacs will automagically detect them.
211  * ---------------------------------------------------------------------
212  * Local variables:
213  * mode: c
214  * indent-tabs-mode: t
215  * c-basic-offset: 4
216  * tab-width: 4
217  * End:
218  * vim:noexpandtab:sw=4:ts=4:
219  */