1 /* src/vm/jit/powerpc/emit.c - PowerPC 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
31 $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
44 #include "vm/jit/emit.h"
45 #include "vm/jit/jit.h"
46 #include "vm/jit/powerpc/codegen.h"
49 /* code generation functions **************************************************/
51 /* emit_load_s1 ****************************************************************
53 Emits a possible load of the first source operand.
55 *******************************************************************************/
57 s4 emit_load_s1(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
63 /* get required compiler data */
67 if (src->flags & INMEMORY) {
70 disp = src->regoff * 4;
72 if (IS_FLT_DBL_TYPE(src->type)) {
73 if (IS_2_WORD_TYPE(src->type))
74 M_DLD(tempreg, REG_SP, disp);
76 M_FLD(tempreg, REG_SP, disp);
79 if (IS_2_WORD_TYPE(src->type))
80 M_LLD(tempreg, REG_SP, disp);
82 M_ILD(tempreg, REG_SP, disp);
93 /* emit_load_s2 ****************************************************************
95 Emits a possible load of the second source operand.
97 *******************************************************************************/
99 s4 emit_load_s2(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
105 /* get required compiler data */
109 if (src->flags & INMEMORY) {
112 disp = src->regoff * 4;
114 if (IS_FLT_DBL_TYPE(src->type)) {
115 if (IS_2_WORD_TYPE(src->type))
116 M_DLD(tempreg, REG_SP, disp);
118 M_FLD(tempreg, REG_SP, disp);
121 if (IS_2_WORD_TYPE(src->type))
122 M_LLD(tempreg, REG_SP, disp);
124 M_ILD(tempreg, REG_SP, disp);
135 /* emit_load_s3 ****************************************************************
137 Emits a possible load of the third source operand.
139 *******************************************************************************/
141 s4 emit_load_s3(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
147 /* get required compiler data */
151 if (src->flags & INMEMORY) {
154 disp = src->regoff * 4;
156 if (IS_FLT_DBL_TYPE(src->type)) {
157 if (IS_2_WORD_TYPE(src->type))
158 M_DLD(tempreg, REG_SP, disp);
160 M_FLD(tempreg, REG_SP, disp);
163 if (IS_2_WORD_TYPE(src->type))
164 M_LLD(tempreg, REG_SP, disp);
166 M_ILD(tempreg, REG_SP, disp);
177 /* emit_load_s1_low ************************************************************
179 Emits a possible load of the low 32-bits of the first long source
182 *******************************************************************************/
184 s4 emit_load_s1_low(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
190 assert(src->type == TYPE_LNG);
192 /* get required compiler data */
196 if (src->flags & INMEMORY) {
199 disp = src->regoff * 4;
201 M_ILD(tempreg, REG_SP, disp + 4);
205 reg = GET_LOW_REG(src->regoff);
211 /* emit_load_s2_low ************************************************************
213 Emits a possible load of the low 32-bits of the second long source
216 *******************************************************************************/
218 s4 emit_load_s2_low(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
224 assert(src->type == TYPE_LNG);
226 /* get required compiler data */
230 if (src->flags & INMEMORY) {
233 disp = src->regoff * 4;
235 M_ILD(tempreg, REG_SP, disp + 4);
239 reg = GET_LOW_REG(src->regoff);
245 /* emit_load_s3_low ************************************************************
247 Emits a possible load of the low 32-bits of the third long source
250 *******************************************************************************/
252 s4 emit_load_s3_low(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
258 assert(src->type == TYPE_LNG);
260 /* get required compiler data */
264 if (src->flags & INMEMORY) {
267 disp = src->regoff * 4;
269 M_ILD(tempreg, REG_SP, disp + 4);
273 reg = GET_LOW_REG(src->regoff);
279 /* emit_load_s1_high ***********************************************************
281 Emits a possible load of the high 32-bits of the first long source
284 *******************************************************************************/
286 s4 emit_load_s1_high(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
292 assert(src->type == TYPE_LNG);
294 /* get required compiler data */
298 if (src->flags & INMEMORY) {
301 disp = src->regoff * 4;
303 M_ILD(tempreg, REG_SP, disp);
307 reg = GET_HIGH_REG(src->regoff);
313 /* emit_load_s2_high ***********************************************************
315 Emits a possible load of the high 32-bits of the second long source
318 *******************************************************************************/
320 s4 emit_load_s2_high(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
326 assert(src->type == TYPE_LNG);
328 /* get required compiler data */
332 if (src->flags & INMEMORY) {
335 disp = src->regoff * 4;
337 M_ILD(tempreg, REG_SP, disp);
341 reg = GET_HIGH_REG(src->regoff);
347 /* emit_load_s3_high ***********************************************************
349 Emits a possible load of the high 32-bits of the third long source
352 *******************************************************************************/
354 s4 emit_load_s3_high(jitdata *jd, instruction *iptr, stackptr src, s4 tempreg)
360 assert(src->type == TYPE_LNG);
362 /* get required compiler data */
366 if (src->flags & INMEMORY) {
369 disp = src->regoff * 4;
371 M_ILD(tempreg, REG_SP, disp);
375 reg = GET_HIGH_REG(src->regoff);
381 /* emit_store ******************************************************************
385 *******************************************************************************/
387 void emit_store(jitdata *jd, instruction *iptr, stackptr dst, s4 d)
391 /* get required compiler data */
395 if (dst->flags & INMEMORY) {
398 if (IS_FLT_DBL_TYPE(dst->type)) {
399 if (IS_2_WORD_TYPE(dst->type))
400 M_DST(d, REG_SP, dst->regoff * 4);
402 M_FST(d, REG_SP, dst->regoff * 4);
405 if (IS_2_WORD_TYPE(dst->type))
406 M_LST(d, REG_SP, dst->regoff * 4);
408 M_IST(d, REG_SP, dst->regoff * 4);
414 /* emit_copy *******************************************************************
418 *******************************************************************************/
420 void emit_copy(jitdata *jd, instruction *iptr, stackptr src, stackptr dst)
426 /* get required compiler data */
431 if (src->type == TYPE_LNG)
432 d = codegen_reg_of_var(rd, iptr->opc, dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
434 d = codegen_reg_of_var(rd, iptr->opc, dst, REG_IFTMP);
436 if ((src->regoff != dst->regoff) ||
437 ((src->flags ^ dst->flags) & INMEMORY)) {
438 s1 = emit_load_s1(jd, iptr, src, d);
441 if (IS_FLT_DBL_TYPE(src->type))
444 if (IS_2_WORD_TYPE(src->type)) {
445 M_MOV(GET_LOW_REG(s1), GET_LOW_REG(d));
446 M_MOV(GET_HIGH_REG(s1), GET_HIGH_REG(d));
452 emit_store(jd, iptr, dst, d);
457 /* emit_iconst *****************************************************************
461 *******************************************************************************/
463 void emit_iconst(codegendata *cd, s4 d, s4 value)
467 if ((value >= -32768) && (value <= 32767))
468 M_LDA_INTERN(d, REG_ZERO, value);
470 disp = dseg_adds4(cd, value);
471 M_ILD(d, REG_PV, disp);
477 * These are local overrides for various environment variables in Emacs.
478 * Please do not remove this and leave it at the end of the file, where
479 * Emacs will automagically detect them.
480 * ---------------------------------------------------------------------
483 * indent-tabs-mode: t
487 * vim:noexpandtab:sw=4:ts=4: