* Merged in twisti-branch.
[cacao.git] / src / vm / jit / sparc64 / codegen.c
1 /* src/vm/jit/sparc64/codegen.c - machine code generator for Sparc
2
3    Copyright (C) 1996-2005, 2006, 2007 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    $Id: codegen.c 4644 2006-03-16 18:44:46Z edwin $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <stdio.h>
34
35 #include "vm/types.h"
36
37 #include "md-abi.h"
38
39 /* #include "vm/jit/sparc64/arch.h" */
40 #include "vm/jit/sparc64/codegen.h"
41
42 #include "mm/memory.h"
43
44 #include "native/jni.h"
45 #include "native/native.h"
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/global.h"
49
50 #include "vm/jit/asmpart.h"
51 #include "vm/jit/codegen-common.h"
52 #include "vm/jit/dseg.h"
53 #include "vm/jit/emit-common.h"
54 #include "vm/jit/sparc64/emit.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/parse.h"
57 #include "vm/jit/patcher.h"
58 #include "vm/jit/reg.h"
59 #include "vm/jit/replace.h"
60 #include "vm/jit/stacktrace.h"
61 #include "vmcore/loader.h"
62 #include "vmcore/options.h"
63
64 /* XXX use something like this for window control ? 
65  * #define REG_PV (own_window?REG_PV_CALLEE:REG_PV_CALLER)
66  */
67 #define REG_PV REG_PV_CALLEE
68
69 bool fits_13(s4 disp)
70 {
71         /*
72         if ((disp < -4096) || (disp > 4095))
73                 printf("disp %d\n", disp);
74         */
75
76         return (disp >= -4096) && (disp <= 4095);
77 }
78
79 s4 get_lopart_disp(disp)
80 {
81         s4 lodisp;
82         
83         if (disp > 0)
84                 lodisp = setlo_part(disp);
85         else {
86                 if (setlo_part(disp) == 0)
87                         lodisp = 0;
88                 else
89                         lodisp = setlo_part(disp) | 0x1c00;
90         }
91                 
92         return lodisp;
93 }
94         
95
96 /* codegen_emit ****************************************************************
97
98    Generates machine code.
99
100 *******************************************************************************/
101
102 bool codegen_emit(jitdata *jd)
103 {
104         methodinfo         *m;
105         codeinfo           *code;
106         codegendata        *cd;
107         registerdata       *rd;
108         s4                  len, s1, s2, s3, d, disp;
109         varinfo            *var;
110         basicblock         *bptr;
111         instruction        *iptr;
112         exception_entry    *ex;
113         u2                  currentline;
114         constant_classref  *cr;
115         methodinfo         *lm;             /* local methodinfo for ICMD_INVOKE*  */
116         unresolved_method  *um;
117         builtintable_entry *bte;
118         methoddesc         *md;
119         fieldinfo          *fi;
120         unresolved_field   *uf;
121         s4                  fieldtype;
122         s4                  varindex;
123
124         /* get required compiler data */
125
126         m  = jd->m;
127         code = jd->code;
128         cd = jd->cd;
129         rd = jd->rd;
130         
131         /* prevent compiler warnings */
132
133         d = 0;
134         currentline = 0;
135         lm = NULL;
136         bte = NULL;
137
138         {
139         s4 i, p, t, l;
140         s4 savedregs_num, localbase;
141
142 #if 0 /* no leaf optimization yet */
143         savedregs_num = (jd->isleafmethod) ? 0 : 1;       /* space to save the RA */
144 #endif
145         savedregs_num = WINSAVE_CNT + ABIPARAMS_CNT; /* register-window save area */ 
146
147
148         /* space to save used callee saved registers */
149
150         savedregs_num += (INT_SAV_CNT - rd->savintreguse);
151         savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
152
153         cd->stackframesize = rd->memuse + savedregs_num;
154
155 #if defined(ENABLE_THREADS)        /* space to save argument of monitor_enter */
156         if (checksync && (m->flags & ACC_SYNCHRONIZED))
157                 cd->stackframesize++;
158 #endif
159
160         /* keep stack 16-byte aligned (ABI requirement) */
161
162         if (cd->stackframesize & 1)
163                 cd->stackframesize++;
164
165         /* create method header */
166
167         (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
168         (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
169
170 #if defined(ENABLE_THREADS)
171         /* IsSync contains the offset relative to the stack pointer for the
172            argument of monitor_exit used in the exception handler. Since the
173            offset could be zero and give a wrong meaning of the flag it is
174            offset by one.
175         */
176
177         if (checksync && (m->flags & ACC_SYNCHRONIZED))
178                 (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8); /* IsSync        */
179         else
180 #endif
181                 (void) dseg_add_unique_s4(cd, 0);                  /* IsSync          */
182                                                
183         (void) dseg_add_unique_s4(cd, jd->isleafmethod);       /* IsLeaf          */
184         (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
185         (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
186         dseg_addlinenumbertablesize(cd);
187         (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize   */
188
189         /* create exception table */
190
191         for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
192                 dseg_add_target(cd, ex->start);
193                 dseg_add_target(cd, ex->end);
194                 dseg_add_target(cd, ex->handler);
195                 (void) dseg_add_unique_address(cd, ex->catchtype.any);
196         }
197
198         /* save register window and create stack frame (if necessary) */
199
200         if (cd->stackframesize)
201                 M_SAVE(REG_SP, -cd->stackframesize * 8, REG_SP);
202
203
204         /* save callee saved float registers (none right now) */
205 #if 0
206         p = cd->stackframesize;
207         for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
208                 p--; M_DST(rd->savfltregs[i], REG_SP, USESTACK + (p * 8));
209         }
210 #endif
211
212 #if !defined(NDEBUG)
213         if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
214                 emit_verbosecall_enter(jd);
215 #endif
216         
217         
218         
219         /* take arguments out of register or stack frame */
220         
221         md = m->parseddesc;
222
223         /* when storing locals, use this as base */
224         localbase = JITSTACK;
225         
226         /* since the register allocator does not know about the shifting window
227          * arg regs need to be copied via the stack
228          */
229         if (md->argintreguse > 0) {
230                 /* allocate scratch space for copying in to save(i&l) regs */
231                 M_SUB_IMM(REG_SP, INT_ARG_CNT * 8, REG_SP);
232                 
233                 localbase += INT_ARG_CNT * 8;
234                 
235                 /* XXX could use the param slots on the stack for this! */
236                 for (p = 0; p < INT_ARG_CNT; p++)
237                         M_STX(REG_WINDOW_TRANSPOSE(rd->argintregs[p]), REG_SP, JITSTACK + (p * 8));
238         }
239         
240
241         for (p = 0, l = 0; p < md->paramcount; p++) {
242                 t = md->paramtypes[p].type;
243
244                 varindex = jd->local_map[l * 5 + t];
245
246                 l++;
247                 if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
248                         l++;
249
250                 if (varindex == UNUSED)
251                         continue;
252
253                 var = VAR(varindex);
254
255                 s1 = md->params[p].regoff;
256                 if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
257                         if (!md->params[p].inmemory) {           /* register arguments    */
258                                 /*s2 = rd->argintregs[s1];*/
259                                 /*s2 = REG_WINDOW_TRANSPOSE(s2);*/
260                                 if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
261                                         /*M_INTMOVE(s2, var->vv.regoff);*/
262                                         M_LDX(var->vv.regoff, REG_SP, JITSTACK + (s1 * 8));
263
264                                 } else {                             /* reg arg -> spilled    */
265                                         /*M_STX(s2, REG_SP, (WINSAVE_CNT + var->vv.regoff) * 8);*/
266                                         
267                                         M_LDX(REG_ITMP1, REG_SP, JITSTACK + (s1 * 8));
268                                         M_STX(REG_ITMP1, REG_SP, localbase + (var->vv.regoff * 8));
269                                 }
270
271                         } else {                                 /* stack arguments       */
272                                 if (!(var->flags & INMEMORY)) {      /* stack arg -> register */
273                                         M_LDX(var->vv.regoff, REG_FP, JITSTACK + (s1 * 8));
274
275                                 } else {                             /* stack arg -> spilled  */
276                                         /* add the callers window save registers */
277                                         var->vv.regoff = cd->stackframesize + s1;
278                                 }
279                         }
280                 
281                 } else {                                     /* floating args         */
282                         if (!md->params[p].inmemory) {           /* register arguments    */
283                                 s2 = rd->argfltregs[s1];
284                                 if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
285                                         M_FLTMOVE(s2, var->vv.regoff);
286
287                                 } else {                                         /* reg arg -> spilled    */
288                                         M_DST(s2, REG_SP, localbase + (var->vv.regoff) * 8);
289                                 }
290
291                         } else {                                 /* stack arguments       */
292                                 if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
293                                         M_DLD(var->vv.regoff, REG_FP, JITSTACK + (s1 * 8));
294
295                                 } else {                             /* stack-arg -> spilled  */
296                                         var->vv.regoff = cd->stackframesize + s1;
297                                 }
298                         }
299                 }
300         } /* end for */
301         
302         if (md->argintreguse > 0) {
303                 /* release scratch space */
304                 M_ADD_IMM(REG_SP, INT_ARG_CNT * 8, REG_SP);
305         }
306         
307         
308         /* XXX monitor enter */
309
310
311
312         
313         }
314         
315         /* end of header generation */ 
316         
317         /* create replacement points */
318
319         REPLACEMENT_POINTS_INIT(cd, jd);
320
321         /* walk through all basic blocks */
322
323         for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
324
325                 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
326
327                 if (bptr->flags >= BBREACHED) {
328
329                 /* branch resolving */
330
331                 codegen_resolve_branchrefs(cd, bptr);
332                 
333                 /* handle replacement points */
334
335 #if 0
336                 if (bptr->bitflags & BBFLAG_REPLACEMENT) {
337                         replacementpoint->pc = (u1*)(ptrint)bptr->mpc; /* will be resolved later */
338                         
339                         replacementpoint++;
340                 }
341 #endif
342
343                 /* copy interface registers to their destination */
344
345                 len = bptr->indepth;
346                 MCODECHECK(64+len);
347                 
348 #if defined(ENABLE_LSRA)
349 #error XXX LSRA not tested yet
350                 if (opt_lsra) {
351                 while (len) {
352                         len--;
353                         src = bptr->invars[len];
354                         if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
355                                         /*                              d = reg_of_var(m, src, REG_ITMP1); */
356                                         if (!(src->flags & INMEMORY))
357                                                 d = src->vv.regoff;
358                                         else
359                                                 d = REG_ITMP1;
360                                         M_INTMOVE(REG_ITMP1, d);
361                                         emit_store(jd, NULL, src, d);
362                                 }
363                         }
364                 } else {
365 #endif
366                 while (len) {
367                         len--;
368                         var = VAR(bptr->invars[len]);
369                         if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
370                                 d = codegen_reg_of_var(0, var, REG_ITMP1);
371                                 M_INTMOVE(REG_ITMP2_XPTR, d);
372                                 emit_store(jd, NULL, var, d);
373                         }
374                         else {
375                                 assert((var->flags & INOUT));
376                         }
377                 }
378 #if defined(ENABLE_LSRA)
379                 }
380 #endif
381                 /* walk through all instructions */
382                 
383                 len = bptr->icount;
384
385                 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
386                         if (iptr->line != currentline) {
387                                 dseg_addlinenumber(cd, iptr->line);
388                                 currentline = iptr->line;
389                         }
390
391                 MCODECHECK(64);       /* an instruction usually needs < 64 words      */
392
393                 switch (iptr->opc) {
394
395                 case ICMD_INLINE_START:
396                 case ICMD_INLINE_END:
397                         break;
398
399                 case ICMD_NOP:        /* ...  ==> ...                                 */
400                         break;
401
402                 case ICMD_CHECKNULL:  /* ..., objectref  ==> ..., objectref           */
403
404                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
405                         emit_nullpointer_check(cd, iptr, s1);
406                         break;
407         
408                 /* constant operations ************************************************/
409
410                 case ICMD_ICONST:     /* ...  ==> ..., constant                       */
411
412                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
413                         ICONST(d, iptr->sx.val.i);
414                         emit_store_dst(jd, iptr, d);
415                         break;
416
417                 case ICMD_LCONST:     /* ...  ==> ..., constant                       */
418
419                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
420                         LCONST(d, iptr->sx.val.l);
421                         emit_store_dst(jd, iptr, d);
422                         break;  
423
424                 case ICMD_FCONST:     /* ...  ==> ..., constant                       */
425
426                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
427                         disp = dseg_add_float(cd, iptr->sx.val.f);
428                         M_FLD(d, REG_PV, disp);
429                         emit_store_dst(jd, iptr, d);
430                         break;
431                         
432                 case ICMD_DCONST:     /* ...  ==> ..., constant                       */
433
434                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
435                         disp = dseg_add_double(cd, iptr->sx.val.d);
436                         M_DLD(d, REG_PV, disp);
437                         emit_store_dst(jd, iptr, d);
438                         break;
439
440                 case ICMD_ACONST:     /* ...  ==> ..., constant                       */
441
442                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
443
444                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
445                                 cr   = iptr->sx.val.c.ref;
446                                 disp = dseg_add_unique_address(cd, cr);
447
448                                 codegen_add_patch_ref(cd, PATCHER_aconst, cr, disp);
449
450                                 M_ALD(d, REG_PV, disp);
451
452                         } 
453                         else {
454                                 if (iptr->sx.val.anyptr == NULL) {
455                                         M_INTMOVE(REG_ZERO, d);
456                                 } 
457                                 else {
458                                         disp = dseg_add_address(cd, iptr->sx.val.anyptr);
459                                         M_ALD(d, REG_PV, disp);
460                                 }
461                         }
462                         emit_store_dst(jd, iptr, d);
463                         break;
464
465
466                 /* load/store/copy/move operations ************************************/
467
468                 case ICMD_ILOAD:      /* ...  ==> ..., content of local variable      */
469                 case ICMD_LLOAD:      /* ...  ==> ..., content of local variable      */
470                 case ICMD_ALOAD:      /* ...  ==> ..., content of local variable      */
471                 case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
472                 case ICMD_DLOAD:      /* ...  ==> ..., content of local variable      */
473                 case ICMD_ISTORE:     /* ..., value  ==> ...                          */
474                 case ICMD_LSTORE:     /* ..., value  ==> ...                          */
475                 case ICMD_FSTORE:     /* ..., value  ==> ...                          */
476                 case ICMD_DSTORE:     /* ..., value  ==> ...                          */
477                 case ICMD_COPY:
478                 case ICMD_MOVE:
479
480                         emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
481                         break;
482         
483                 case ICMD_ASTORE:
484                         if (!(iptr->flags.bits & INS_FLAG_RETADDR))
485                                 emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
486                         break;
487
488
489                 /* pop/dup/swap operations ********************************************/
490
491                 /* attention: double and longs are only one entry in CACAO ICMDs      */
492
493                 case ICMD_POP:        /* ..., value  ==> ...                          */
494                 case ICMD_POP2:       /* ..., value, value  ==> ...                   */
495                         break;
496
497
498                 /* integer operations *************************************************/
499
500                 case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
501                 case ICMD_LNEG:
502
503                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
504                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
505                         M_SUB(REG_ZERO, s1, d);
506                         emit_store_dst(jd, iptr, d);
507                         break;
508
509                 case ICMD_I2L:        /* ..., value  ==> ..., value                   */
510
511                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
512                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
513                         M_INTMOVE(s1, d);
514                         emit_store_dst(jd, iptr, d);
515                         break;
516
517                 case ICMD_L2I:        /* ..., value  ==> ..., value                   */
518
519                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
520                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
521                         M_SRA_IMM(s1, 0, d); /* sign extend upper 32 bits */
522                         emit_store_dst(jd, iptr, d);
523                         break;
524
525                 case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
526
527                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
528                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
529                         M_SLLX_IMM(s1, 56, d);
530                         M_SRAX_IMM( d, 56, d);
531                         emit_store_dst(jd, iptr, d);
532                         break;
533
534                 case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
535                 
536                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
537                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
538                         M_SLLX_IMM(s1, 48, d);
539                         M_SRLX_IMM( d, 48, d);
540                         emit_store_dst(jd, iptr, d);
541                         break;
542                         
543                 case ICMD_INT2SHORT:   /* ..., value  ==> ..., value                   */
544
545                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
546                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
547                         M_SLLX_IMM(s1, 48, d);
548                         M_SRAX_IMM( d, 48, d);
549                         emit_store_dst(jd, iptr, d);
550                         break;
551
552                 case ICMD_IADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
553                 case ICMD_LADD:
554
555                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
556                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
557                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
558                         M_ADD(s1, s2, d);
559                         emit_store_dst(jd, iptr, d);
560                         break;
561
562                 case ICMD_IINC:
563                 case ICMD_IADDCONST:  /* ..., value  ==> ..., value + constant        */
564                                       /* sx.val.i = constant                             */
565
566                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
567                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
568                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
569                                 M_ADD_IMM(s1, iptr->sx.val.i, d);
570                         } else {
571                                 ICONST(REG_ITMP2, iptr->sx.val.i);
572                                 M_ADD(s1, REG_ITMP2, d);
573                         }
574                         emit_store_dst(jd, iptr, d);
575                         break;
576
577                 case ICMD_LADDCONST:  /* ..., value  ==> ..., value + constant        */
578                                       /* sx.val.l = constant                             */
579
580                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
581                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
582                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
583                                 M_ADD_IMM(s1, iptr->sx.val.l, d);
584                         } else {
585                                 LCONST(REG_ITMP2, iptr->sx.val.l);
586                                 M_ADD(s1, REG_ITMP2, d);
587                         }
588                         emit_store_dst(jd, iptr, d);
589                         break;
590
591                 case ICMD_ISUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
592                 case ICMD_LSUB: 
593
594                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
595                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
596                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
597                         M_SUB(s1, s2, d);
598                         emit_store_dst(jd, iptr, d);
599                         break;
600
601                 case ICMD_ISUBCONST:  /* ..., value  ==> ..., value + constant        */
602                                       /* sx.val.i = constant                             */
603
604                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
605                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
606                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
607                                 M_SUB_IMM(s1, iptr->sx.val.i, d);
608                         } else {
609                                 ICONST(REG_ITMP2, iptr->sx.val.i);
610                                 M_SUB(s1, REG_ITMP2, d);
611                         }
612                         emit_store_dst(jd, iptr, d);
613                         break;
614
615                 case ICMD_LSUBCONST:  /* ..., value  ==> ..., value - constant        */
616                                       /* sx.val.l = constant                             */
617
618                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
619                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
620                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
621                                 M_SUB_IMM(s1, iptr->sx.val.l, d);
622                         } else {
623                                 LCONST(REG_ITMP2, iptr->sx.val.l);
624                                 M_SUB(s1, REG_ITMP2, d);
625                         }
626                         emit_store_dst(jd, iptr, d);
627                         break;
628
629                 case ICMD_IMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
630                 case ICMD_LMUL:
631
632                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
633                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
634                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
635                         M_MULX(s1, s2, d);
636                         emit_store_dst(jd, iptr, d);
637                         break;
638
639                 case ICMD_IMULCONST:  /* ..., value  ==> ..., value * constant        */
640                                       /* sx.val.i = constant                             */
641
642                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
643                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
644                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
645                                 M_MULX_IMM(s1, iptr->sx.val.i, d);
646                         } else {
647                                 ICONST(REG_ITMP2, iptr->sx.val.i);
648                                 M_MULX(s1, REG_ITMP2, d);
649                         }
650                         emit_store_dst(jd, iptr, d);
651                         break;
652
653                 case ICMD_LMULCONST:  /* ..., value  ==> ..., value * constant        */
654                                       /* sx.val.l = constant                             */
655
656                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
657                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
658                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
659                                 M_MULX_IMM(s1, iptr->sx.val.l, d);
660                         } else {
661                                 LCONST(REG_ITMP2, iptr->sx.val.l);
662                                 M_MULX(s1, REG_ITMP2, d);
663                         }
664                         emit_store_dst(jd, iptr, d);
665                         break;
666
667                 case ICMD_IDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
668 /* XXX could also clear Y and use 32bit div */
669                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
670                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
671                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
672                         emit_arithmetic_check(cd, iptr, s2);
673                         M_ISEXT(s1, s1);
674                         /* XXX trim s2 like s1 ? */
675                         M_DIVX(s1, s2, d);
676                         emit_store_dst(jd, iptr, d);
677                         break;
678
679                 case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
680
681                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
682                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
683                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
684                         emit_arithmetic_check(cd, iptr, s2);
685                         M_DIVX(s1, s2, d);
686                         emit_store_dst(jd, iptr, d);
687                         break;
688
689                 case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
690
691                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
692                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
693                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
694                         emit_arithmetic_check(cd, iptr, s2);
695                         M_ISEXT(s1, s1);
696                         /* XXX trim s2 like s1 ? */
697                         M_DIVX(s1, s2, REG_ITMP3);
698                         M_MULX(s2, REG_ITMP3, REG_ITMP3);
699                         M_SUB(s1, REG_ITMP3, d);
700                         emit_store_dst(jd, iptr, d);
701                         break;
702
703                 case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
704
705                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
706                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
707                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
708                         emit_arithmetic_check(cd, iptr, s2);
709                         M_DIVX(s1, s2, REG_ITMP3);
710                         M_MULX(s2, REG_ITMP3, REG_ITMP3);
711                         M_SUB(s1, REG_ITMP3, d);
712                         emit_store_dst(jd, iptr, d);
713                         break;
714
715                 case ICMD_IDIVPOW2:   /* ..., value  ==> ..., value << constant       */
716                 case ICMD_LDIVPOW2:   /* val.i = constant                             */
717                                       
718                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
719                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
720                         M_SRAX_IMM(s1, 63, REG_ITMP2);
721                         M_SRLX_IMM(REG_ITMP2, 64 - iptr->sx.val.i, REG_ITMP2);
722                         M_ADD(s1, REG_ITMP2, REG_ITMP2);
723                         M_SRAX_IMM(REG_ITMP2, iptr->sx.val.i, d);
724                         emit_store_dst(jd, iptr, d);
725                         break;
726
727                 case ICMD_ISHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
728
729                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
730                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
731                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
732                         M_SLL(s1, s2, d);
733                         emit_store_dst(jd, iptr, d);
734                         break;
735                         
736                 case ICMD_LSHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
737
738                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
739                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
740                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
741                         M_SLLX(s1, s2, d);
742                         emit_store_dst(jd, iptr, d);
743                         break;
744
745                 case ICMD_ISHLCONST:  /* ..., value  ==> ..., value << constant       */
746                                       /* val.i = constant                             */
747
748                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
749                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
750                         M_SLL_IMM(s1, iptr->sx.val.i, d);
751                         emit_store_dst(jd, iptr, d);
752                         break;
753                         
754                 case ICMD_LSHLCONST:  /* ..., value  ==> ..., value << constant       */
755                                       /* val.i = constant                             */
756
757                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
758                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
759                         M_SLLX_IMM(s1, iptr->sx.val.i, d);
760                         emit_store_dst(jd, iptr, d);
761                         break;
762
763                 case ICMD_ISHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
764
765                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
766                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
767                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
768                         M_SRA(s1, s2, d);
769                         emit_store_dst(jd, iptr, d);
770                         break;
771
772                 case ICMD_ISHRCONST:  /* ..., value  ==> ..., value >> constant       */
773                                       /* sx.val.i = constant                             */
774
775                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
776                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
777                         M_SRA_IMM(s1, iptr->sx.val.i, d);
778                         emit_store_dst(jd, iptr, d);
779                         break;
780
781                 case ICMD_IUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
782
783                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
784                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
785                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
786                         M_SRL(s1, s2, d);
787                         emit_store_dst(jd, iptr, d);
788                         break;
789
790                 case ICMD_IUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
791                                       /* sx.val.i = constant                             */
792
793                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
794                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
795                         M_SRL_IMM(s1, iptr->sx.val.i, d);
796                         emit_store_dst(jd, iptr, d);
797                         break;
798
799                 case ICMD_LSHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
800
801                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
802                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
803                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
804                         M_SRAX(s1, s2, d);
805                         emit_store_dst(jd, iptr, d);
806                         break;
807
808                 case ICMD_LSHRCONST:  /* ..., value  ==> ..., value >> constant       */
809                                       /* sx.val.i = constant                             */
810
811                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
812                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
813                         M_SRAX_IMM(s1, iptr->sx.val.i, d);
814                         emit_store_dst(jd, iptr, d);
815                         break;
816
817                 case ICMD_LUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
818
819                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
820                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
821                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
822                         M_SRLX(s1, s2, d);
823                         emit_store_dst(jd, iptr, d);
824                         break;
825
826                 case ICMD_LUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
827                                       /* sx.val.i = constant                             */
828
829                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
830                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
831                         M_SRLX_IMM(s1, iptr->sx.val.i, d);
832                         emit_store_dst(jd, iptr, d);
833                         break;
834
835                 case ICMD_IAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
836                 case ICMD_LAND:
837
838                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
839                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
840                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
841                         M_AND(s1, s2, d);
842                         emit_store_dst(jd, iptr, d);
843                         break;
844
845                 case ICMD_IANDCONST:  /* ..., value  ==> ..., value & constant        */
846                                       /* sx.val.i = constant                             */
847
848                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
849                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
850                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
851                                 M_AND_IMM(s1, iptr->sx.val.i, d);
852                         } else {
853                                 ICONST(REG_ITMP2, iptr->sx.val.i);
854                                 M_AND(s1, REG_ITMP2, d);
855                         }
856                         emit_store_dst(jd, iptr, d);
857                         break;
858
859                 case ICMD_IREMPOW2:   /* ..., value  ==> ..., value % constant        */
860                                       /* sx.val.i = constant                             */
861
862                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
863                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
864                         M_ISEXT(s1, s1); /* trim for 32-bit compare (BGEZ) */
865                         if (s1 == d) {
866                                 M_MOV(s1, REG_ITMP1);
867                                 s1 = REG_ITMP1;
868                         }
869                         if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
870                                 M_AND_IMM(s1, iptr->sx.val.i, d);
871                                 M_BGEZ(s1, 4);
872                                 M_NOP;
873                                 M_SUB(REG_ZERO, s1, d);
874                                 M_AND_IMM(d, iptr->sx.val.i, d);
875                         } else {
876                                 ICONST(REG_ITMP2, iptr->sx.val.i);
877                                 M_AND(s1, REG_ITMP2, d);
878                                 M_BGEZ(s1, 4);
879                                 M_NOP;
880                                 M_SUB(REG_ZERO, s1, d);
881                                 M_AND(d, REG_ITMP2, d);
882                         }
883                         M_SUB(REG_ZERO, d, d);
884                         emit_store_dst(jd, iptr, d);
885                         break;
886
887                 case ICMD_LANDCONST:  /* ..., value  ==> ..., value & constant        */
888                                       /* sx.val.l = constant                             */
889
890                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
891                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
892                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
893                                 M_AND_IMM(s1, iptr->sx.val.l, d);
894                         } else {
895                                 LCONST(REG_ITMP2, iptr->sx.val.l);
896                                 M_AND(s1, REG_ITMP2, d);
897                         }
898                         emit_store_dst(jd, iptr, d);
899                         break;
900
901                 case ICMD_LREMPOW2:   /* ..., value  ==> ..., value % constant        */
902                                       /* sx.val.l = constant                             */
903
904                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
905                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
906                         if (s1 == d) {
907                                 M_MOV(s1, REG_ITMP1);
908                                 s1 = REG_ITMP1;
909                         }
910                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
911                                 M_AND_IMM(s1, iptr->sx.val.l, d);
912                                 M_BGEZ(s1, 4);
913                                 M_NOP;
914                                 M_SUB(REG_ZERO, s1, d);
915                                 M_AND_IMM(d, iptr->sx.val.l, d);
916                         } else {
917                                 LCONST(REG_ITMP2, iptr->sx.val.l);
918                                 M_AND(s1, REG_ITMP2, d);
919                                 M_BGEZ(s1, 4);
920                                 M_NOP;
921                                 M_SUB(REG_ZERO, s1, d);
922                                 M_AND(d, REG_ITMP2, d);
923                         }
924                         M_SUB(REG_ZERO, d, d);
925                         emit_store_dst(jd, iptr, d);
926                         break;
927
928                 case ICMD_IOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
929                 case ICMD_LOR:
930
931                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
932                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
933                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
934                         M_OR(s1,s2, d);
935                         emit_store_dst(jd, iptr, d);
936                         break;
937
938                 case ICMD_IORCONST:   /* ..., value  ==> ..., value | constant        */
939                                       /* sx.val.i = constant                             */
940
941                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
942                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
943                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
944                                 M_OR_IMM(s1, iptr->sx.val.i, d);
945                         } else {
946                                 ICONST(REG_ITMP2, iptr->sx.val.i);
947                                 M_OR(s1, REG_ITMP2, d);
948                         }
949                         emit_store_dst(jd, iptr, d);
950                         break;
951
952                 case ICMD_LORCONST:   /* ..., value  ==> ..., value | constant        */
953                                       /* sx.val.l = constant                             */
954
955                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
956                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
957                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
958                                 M_OR_IMM(s1, iptr->sx.val.l, d);
959                         } else {
960                                 LCONST(REG_ITMP2, iptr->sx.val.l);
961                                 M_OR(s1, REG_ITMP2, d);
962                         }
963                         emit_store_dst(jd, iptr, d);
964                         break;
965
966                 case ICMD_IXOR:       /* ..., val1, val2  ==> ..., val1 ^ val2        */
967                 case ICMD_LXOR:
968
969                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
970                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
971                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
972                         M_XOR(s1, s2, d);
973                         emit_store_dst(jd, iptr, d);
974                         break;
975
976                 case ICMD_IXORCONST:  /* ..., value  ==> ..., value ^ constant        */
977                                       /* sx.val.i = constant                             */
978
979                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
980                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
981                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
982                                 M_XOR_IMM(s1, iptr->sx.val.i, d);
983                         } else {
984                                 ICONST(REG_ITMP2, iptr->sx.val.i);
985                                 M_XOR(s1, REG_ITMP2, d);
986                         }
987                         emit_store_dst(jd, iptr, d);
988                         break;
989
990                 case ICMD_LXORCONST:  /* ..., value  ==> ..., value ^ constant        */
991                                       /* sx.val.l = constant                             */
992
993                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
994                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
995                         if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
996                                 M_XOR_IMM(s1, iptr->sx.val.l, d);
997                         } else {
998                                 LCONST(REG_ITMP2, iptr->sx.val.l);
999                                 M_XOR(s1, REG_ITMP2, d);
1000                         }
1001                         emit_store_dst(jd, iptr, d);
1002                         break;
1003
1004
1005                 case ICMD_LCMP:       /* ..., val1, val2  ==> ..., val1 cmp val2      */
1006
1007                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1008                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1009                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1010                         M_CMP(s1, s2);
1011                         M_MOV(REG_ZERO, d);
1012                         M_XCMOVLT_IMM(-1, d);
1013                         M_XCMOVGT_IMM(1, d);
1014                         emit_store_dst(jd, iptr, d);
1015                         break;
1016
1017
1018                 /* floating operations ************************************************/
1019
1020                 case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
1021
1022                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1023                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1024                         M_FNEG(s1, d);
1025                         emit_store_dst(jd, iptr, d);
1026                         break;
1027
1028                 case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
1029
1030                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1031                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1032                         M_DNEG(s1, d);
1033                         emit_store_dst(jd, iptr, d);
1034                         break;
1035
1036                 case ICMD_FADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1037
1038                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1039                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1040                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1041                         M_FADD(s1, s2, d);
1042                         emit_store_dst(jd, iptr, d);
1043                         break;
1044
1045                 case ICMD_DADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1046
1047                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1048                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1049                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1050                         M_DADD(s1, s2, d);
1051                         emit_store_dst(jd, iptr, d);
1052                         break;
1053
1054                 case ICMD_FSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1055
1056                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1057                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1058                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1059                         M_FSUB(s1, s2, d);
1060                         emit_store_dst(jd, iptr, d);
1061                         break;
1062
1063                 case ICMD_DSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1064
1065                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1066                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1067                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1068                         M_DSUB(s1, s2, d);
1069                         emit_store_dst(jd, iptr, d);
1070                         break;
1071
1072                 case ICMD_FMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1073
1074                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1075                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1076                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1077                         M_FMUL(s1, s2, d);
1078                         emit_store_dst(jd, iptr, d);
1079                         break;
1080
1081                 case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2      */
1082
1083                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1084                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1085                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1086                         M_DMUL(s1, s2, d);
1087                         emit_store_dst(jd, iptr, d);
1088                         break;
1089
1090                 case ICMD_FDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1091
1092                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1093                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1094                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1095                         M_FDIV(s1, s2, d);
1096                         emit_store_dst(jd, iptr, d);
1097                         break;
1098
1099                 case ICMD_DDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1100
1101                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1102                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1103                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1104                         M_DDIV(s1, s2, d);
1105                         emit_store_dst(jd, iptr, d);
1106                         break;  
1107
1108                 case ICMD_I2F:
1109                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1110                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP3);
1111                         disp = dseg_add_float(cd, 0.0);
1112                         M_IST (s1, REG_PV_CALLEE, disp);
1113                         M_FLD (d, REG_PV_CALLEE, disp);
1114                         M_CVTIF (d, d); /* rd gets translated to double target register */
1115                         emit_store_dst(jd, iptr, d);
1116                         break;
1117                         
1118                 case ICMD_I2D:
1119                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1120                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP3);
1121                         disp = dseg_add_float(cd, 0.0);
1122                         M_IST (s1, REG_PV_CALLEE, disp);
1123                         M_FLD (REG_FTMP2, REG_PV_CALLEE, disp); /* REG_FTMP2 needs to be a double temp */
1124                         M_CVTID (REG_FTMP2, d); /* rd gets translated to double target register */
1125                         emit_store_dst(jd, iptr, d);
1126                         break;
1127
1128                 case ICMD_F2I:       /* ..., value  ==> ..., (int) value              */
1129                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1130                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1131                         disp = dseg_add_float(cd, 0.0);
1132                         M_CVTFI(s1, REG_FTMP2);
1133                         M_FST(REG_FTMP2, REG_PV_CALLEE, disp);
1134                         M_ILD(d, REG_PV, disp);
1135                         emit_store_dst(jd, iptr, d);
1136                         break;
1137                         
1138                                
1139                 case ICMD_D2I:       /* ..., value  ==> ..., (int) value             */
1140                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1141                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1142                         disp = dseg_add_float(cd, 0.0);
1143                         M_CVTDI(s1, REG_FTMP2);
1144                         M_FST(REG_FTMP2, REG_PV, disp);
1145                         M_ILD(d, REG_PV, disp);
1146                         emit_store_dst(jd, iptr, d);
1147                         break;
1148
1149                 case ICMD_F2L:       /* ..., value  ==> ..., (long) value             */
1150                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1151                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1152                         disp = dseg_add_double(cd, 0.0);
1153                         M_CVTFL(s1, REG_FTMP2); /* FTMP2 needs to be double reg */
1154                         M_DST(REG_FTMP2, REG_PV, disp);
1155                         M_LDX(d, REG_PV, disp);
1156                         emit_store_dst(jd, iptr, d);
1157                         break;
1158                         
1159                 case ICMD_D2L:       /* ..., value  ==> ..., (long) value             */
1160                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1161                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1162                         disp = dseg_add_double(cd, 0.0);
1163                         M_CVTDL(s1, REG_FTMP2); /* FTMP2 needs to be double reg */
1164                         M_DST(REG_FTMP2, REG_PV, disp);
1165                         M_LDX(d, REG_PV, disp);
1166                         emit_store_dst(jd, iptr, d);
1167                         break;
1168
1169                 case ICMD_F2D:       /* ..., value  ==> ..., (double) value           */
1170
1171                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1172                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP3);
1173                         M_CVTFD(s1, d);
1174                         emit_store_dst(jd, iptr, d);
1175                         break;
1176                                         
1177                 case ICMD_D2F:       /* ..., value  ==> ..., (float) value            */
1178
1179                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1180                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP3);
1181                         M_CVTDF(s1, d);
1182                         emit_store_dst(jd, iptr, d);
1183                         break;
1184         
1185         /* XXX merge F/D versions? only compare instr. is different */
1186                 case ICMD_FCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
1187
1188                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1189                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1190                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1191                         M_FCMP(s1,s2);
1192                         M_OR_IMM(REG_ZERO, -1, d); /* less by default (less or unordered) */
1193                         M_CMOVFEQ_IMM(0, d); /* 0 if equal */
1194                         M_CMOVFGT_IMM(1, d); /* 1 if greater */
1195                         emit_store_dst(jd, iptr, d);
1196                         break;
1197                         
1198                 case ICMD_DCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
1199
1200                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1201                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1202                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
1203                         M_DCMP(s1,s2);
1204                         M_OR_IMM(REG_ZERO, -1, d); /* less by default (less or unordered) */
1205                         M_CMOVFEQ_IMM(0, d); /* 0 if equal */
1206                         M_CMOVFGT_IMM(1, d); /* 1 if greater */
1207                         emit_store_dst(jd, iptr, d);
1208                         break;
1209                         
1210                 case ICMD_FCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
1211
1212                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1213                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1214                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);    
1215                         M_FCMP(s1,s2);
1216                         M_OR_IMM(REG_ZERO, 1, d); /* greater by default (greater or unordered) */
1217                         M_CMOVFEQ_IMM(0, d); /* 0 if equal */
1218                         M_CMOVFLT_IMM(-1, d); /* -1 if less */
1219                         emit_store_dst(jd, iptr, d);
1220                         break;
1221                         
1222                 case ICMD_DCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
1223
1224                         s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1225                         s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1226                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);    
1227                         M_DCMP(s1,s2);
1228                         M_OR_IMM(REG_ZERO, 1, d); /* greater by default (greater or unordered) */
1229                         M_CMOVFEQ_IMM(0, d); /* 0 if equal */
1230                         M_CMOVFLT_IMM(-1, d); /* -1 if less */
1231                         emit_store_dst(jd, iptr, d);
1232                         break;
1233                         
1234
1235                 /* memory operations **************************************************/
1236
1237                 case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
1238
1239                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1240                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1241                         emit_nullpointer_check(cd, iptr, s1);
1242                         M_ILD(d, s1, OFFSET(java_arrayheader, size));
1243                         emit_store_dst(jd, iptr, d);
1244                         break;
1245
1246                 case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
1247
1248                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1249                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1250                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1251                         /* implicit null-pointer check */
1252                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1253                         M_AADD(s2, s1, REG_ITMP3);
1254                         M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray, data[0]));
1255                         emit_store_dst(jd, iptr, d);
1256                         break;
1257
1258                 case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
1259
1260                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1261                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1262                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1263                         /* implicit null-pointer check */
1264                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1265                         M_AADD(s2, s1, REG_ITMP3);
1266                         M_AADD(s2, REG_ITMP3, REG_ITMP3);
1267                         M_SLDU(d, REG_ITMP3, OFFSET(java_chararray, data[0]));
1268                         emit_store_dst(jd, iptr, d);
1269                         break;                  
1270
1271                 case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
1272
1273                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1274                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1275                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1276                         /* implicit null-pointer check */
1277                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1278                         M_AADD(s2, s1, REG_ITMP3);
1279                         M_AADD(s2, REG_ITMP3, REG_ITMP3);
1280                         M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray, data[0]));
1281                         emit_store_dst(jd, iptr, d);
1282                         break;
1283
1284                 case ICMD_IALOAD:     /* ..., arrayref, index  ==> ..., value         */
1285
1286                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1287                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1288                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1289                         /* implicit null-pointer check */
1290                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1291                         M_ASLL_IMM(s2, 2, REG_ITMP3);
1292                         M_AADD(REG_ITMP3, s1, REG_ITMP3);
1293                         M_ILD(d, REG_ITMP3, OFFSET(java_intarray, data[0]));
1294                         emit_store_dst(jd, iptr, d);
1295                         break;
1296
1297                 case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
1298
1299                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1300                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1301                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1302                         /* implicit null-pointer check */
1303                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1304                         M_ASLL_IMM(s2, 3, REG_ITMP3);
1305                         M_AADD(REG_ITMP3, s1, REG_ITMP3);
1306                         M_LDX(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1307                         emit_store_dst(jd, iptr, d);
1308                         break;
1309
1310                 case ICMD_FALOAD:     /* ..., arrayref, index  ==> ..., value         */
1311
1312                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1313                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1314                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1315                         /* implicit null-pointer check */
1316                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1317                         M_ASLL_IMM(s2, 2, REG_ITMP3);
1318                         M_AADD(REG_ITMP3, s1, REG_ITMP3);
1319                         M_FLD(d, REG_ITMP3, OFFSET(java_floatarray, data[0]));
1320                         emit_store_dst(jd, iptr, d);
1321                         break;
1322
1323                 case ICMD_DALOAD:     /* ..., arrayref, index  ==> ..., value         */
1324
1325                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1326                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1327                         d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1328                         /* implicit null-pointer check */
1329                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1330                         M_ASLL_IMM(s2, 3, REG_ITMP3);
1331                         M_AADD(REG_ITMP3, s1, REG_ITMP3);
1332                         M_DLD(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1333                         emit_store_dst(jd, iptr, d);
1334                         break;
1335
1336                 case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
1337
1338                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1339                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1340                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1341                         /* implicit null-pointer check */
1342                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1343                         M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP3);
1344                         M_AADD(REG_ITMP3, s1, REG_ITMP3);
1345                         M_ALD(d, REG_ITMP3, OFFSET(java_objectarray, data[0]));
1346                         emit_store_dst(jd, iptr, d);
1347                         break;
1348
1349         
1350                 case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
1351
1352                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1353                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1354                         /* implicit null-pointer check */
1355                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1356                         M_AADD(s2, s1, REG_ITMP1);
1357                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1358                         M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1359                         break;
1360
1361                 case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
1362                 case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
1363
1364                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1365                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1366                         /* implicit null-pointer check */
1367                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1368                         M_AADD(s2, s1, REG_ITMP1);
1369                         M_AADD(s2, REG_ITMP1, REG_ITMP1);
1370                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1371                         M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1372                         break;
1373
1374                 case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
1375
1376                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1377                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1378                         /* implicit null-pointer check */
1379                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1380                         M_ASLL_IMM(s2, 2, REG_ITMP2);
1381                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1382                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1383                         M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1384                         break;
1385
1386                 case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
1387
1388                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1389                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1390                         /* implicit null-pointer check */
1391                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1392                         M_ASLL_IMM(s2, 3, REG_ITMP2);
1393                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1394                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1395                         M_STX_INTERN(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
1396                         break;
1397
1398                 case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
1399
1400                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1401                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1402                         /* implicit null-pointer check */
1403                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1404                         M_ASLL_IMM(s2, 2, REG_ITMP2);
1405                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1406                         s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1407                         M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1408                         break;
1409
1410                 case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
1411
1412                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1413                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1414                         /* implicit null-pointer check */
1415                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1416                         M_ASLL_IMM(s2, 3, REG_ITMP2);
1417                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1418                         s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1419                         M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1420                         break;
1421
1422
1423                 case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
1424
1425                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1426                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1427                         /* implicit null-pointer check */
1428                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1429                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1430
1431                         M_MOV(s1, rd->argintregs[0]);
1432                         M_MOV(s3, rd->argintregs[1]);
1433                         disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1434                         M_ALD(REG_ITMP3, REG_PV, disp);
1435                         M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
1436                         M_NOP;
1437                         emit_exception_check(cd, iptr);
1438
1439                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1440                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1441                         M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1442                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1443                         s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1444                         /* implicit null-pointer check */
1445                         M_AST_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1446                         break;
1447
1448
1449                 case ICMD_BASTORECONST:   /* ..., arrayref, index  ==> ...            */
1450
1451                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1452                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1453                         /* implicit null-pointer check */
1454                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1455                         M_AADD(s2, s1, REG_ITMP1);
1456                         M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1457                         break;
1458
1459                 case ICMD_CASTORECONST:   /* ..., arrayref, index  ==> ...            */
1460                 case ICMD_SASTORECONST:   /* ..., arrayref, index  ==> ...            */
1461
1462                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1463                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1464                         /* implicit null-pointer check */
1465                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1466                         M_AADD(s2, s1, REG_ITMP1);
1467                         M_AADD(s2, REG_ITMP1, REG_ITMP1);
1468                         M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0]));
1469                         break;
1470
1471                 case ICMD_IASTORECONST:   /* ..., arrayref, index  ==> ...            */
1472
1473                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1474                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1475                         /* implicit null-pointer check */
1476                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1477                         M_ASLL_IMM(s2, 2, REG_ITMP2);
1478                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1479                         M_IST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0]));
1480                         break;
1481
1482                 case ICMD_LASTORECONST:   /* ..., arrayref, index  ==> ...            */
1483
1484                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1485                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1486                         /* implicit null-pointer check */
1487                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1488                         M_ASLL_IMM(s2, 3, REG_ITMP2);
1489                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1490                         M_STX_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0]));
1491                         break;
1492
1493                 case ICMD_AASTORECONST:   /* ..., arrayref, index  ==> ...            */
1494
1495                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1496                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1497                         /* implicit null-pointer check */
1498                         emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1499                         M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1500                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1501                         M_AST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1502                         break;
1503                 
1504
1505                 case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
1506
1507                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1508                                 uf = iptr->sx.s23.s3.uf;
1509                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1510                                 disp      = dseg_add_unique_address(cd, uf);
1511
1512                                 codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
1513                         } 
1514                         else {
1515                                 fi = iptr->sx.s23.s3.fmiref->p.field;
1516                                 fieldtype = fi->type;
1517                                 disp = dseg_add_address(cd, &(fi->value));
1518
1519                                 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
1520                                         codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp);
1521                         }
1522
1523                         M_ALD(REG_ITMP1, REG_PV, disp);
1524
1525                         switch (fieldtype) {
1526                         case TYPE_INT:
1527                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1528                                 M_ILD_INTERN(d, REG_ITMP1, 0);
1529                                 break;
1530                         case TYPE_LNG:
1531                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1532                                 M_LDX_INTERN(d, REG_ITMP1, 0);
1533                                 break;
1534                         case TYPE_ADR:
1535                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1536                                 M_ALD_INTERN(d, REG_ITMP1, 0);
1537                                 break;
1538                         case TYPE_FLT:
1539                                 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1540                                 M_FLD_INTERN(d, REG_ITMP1, 0);
1541                                 break;
1542                         case TYPE_DBL:                          
1543                                 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1544                                 M_DLD_INTERN(d, REG_ITMP1, 0);
1545                                 break;
1546                         }
1547                         emit_store_dst(jd, iptr, d);
1548                         break;
1549
1550                 case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
1551
1552                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1553                                 uf = iptr->sx.s23.s3.uf;
1554                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1555                                 disp      = dseg_add_unique_address(cd, uf);
1556
1557                                 codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
1558                         } 
1559                         else {
1560                                 fi = iptr->sx.s23.s3.fmiref->p.field;
1561                                 fieldtype = fi->type;
1562                                 disp = dseg_add_address(cd, &(fi->value));
1563
1564                                 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
1565                                         codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp);
1566                         }
1567
1568                         M_ALD(REG_ITMP1, REG_PV, disp);
1569
1570                         switch (fieldtype) {
1571                         case TYPE_INT:
1572                                 s1 = emit_load_s1(jd, iptr, REG_ITMP2);
1573                                 M_IST_INTERN(s1, REG_ITMP1, 0);
1574                                 break;
1575                         case TYPE_LNG:
1576                                 s1 = emit_load_s1(jd, iptr, REG_ITMP2);
1577                                 M_STX_INTERN(s1, REG_ITMP1, 0);
1578                                 break;
1579                         case TYPE_ADR:
1580                                 s1 = emit_load_s1(jd, iptr, REG_ITMP2);
1581                                 M_AST_INTERN(s1, REG_ITMP1, 0);
1582                                 break;
1583                         case TYPE_FLT:
1584                                 s1 = emit_load_s1(jd, iptr, REG_FTMP2);
1585                                 M_FST_INTERN(s1, REG_ITMP1, 0);
1586                                 break;
1587                         case TYPE_DBL:
1588                                 s1 = emit_load_s1(jd, iptr, REG_FTMP2);
1589                                 M_DST_INTERN(s1, REG_ITMP1, 0);
1590                                 break;
1591                         }
1592                         break;
1593
1594                 case ICMD_PUTSTATICCONST: /* ...  ==> ...                             */
1595                                           /* val = value (in current instruction)     */
1596                                           /* following NOP)                           */
1597
1598                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1599                                 uf        = iptr->sx.s23.s3.uf;
1600                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1601                                 disp = dseg_add_unique_address(cd, uf);
1602
1603                                 codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
1604                         } 
1605                         else {
1606                                 fi        = iptr->sx.s23.s3.fmiref->p.field;
1607                                 fieldtype = fi->type;
1608                                 disp      = dseg_add_address(cd, &(fi->value));
1609
1610                                 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
1611                                         codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp);
1612                         }
1613
1614                         M_ALD(REG_ITMP1, REG_PV, disp);
1615
1616                         switch (fieldtype) {
1617                         case TYPE_INT:
1618                                 M_IST_INTERN(REG_ZERO, REG_ITMP1, 0);
1619                                 break;
1620                         case TYPE_LNG:
1621                                 M_STX_INTERN(REG_ZERO, REG_ITMP1, 0);
1622                                 break;
1623                         case TYPE_ADR:
1624                                 M_AST_INTERN(REG_ZERO, REG_ITMP1, 0);
1625                                 break;
1626                         case TYPE_FLT:
1627                                 M_FST_INTERN(REG_ZERO, REG_ITMP1, 0);
1628                                 break;
1629                         case TYPE_DBL:
1630                                 M_DST_INTERN(REG_ZERO, REG_ITMP1, 0);
1631                                 break;
1632                         }
1633                         break;
1634
1635
1636                 case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
1637
1638                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1639                         emit_nullpointer_check(cd, iptr, s1);
1640
1641                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1642                                 uf = iptr->sx.s23.s3.uf;
1643
1644                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1645                                 disp      = 0;
1646
1647                                 codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0);
1648                         } 
1649                         else {
1650                                 fi        = iptr->sx.s23.s3.fmiref->p.field;
1651                                 fieldtype = fi->type;
1652                                 disp      = fi->offset;
1653                         }
1654
1655                         switch (fieldtype) {
1656                         case TYPE_INT:
1657                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1658                                 M_ILD(d, s1, disp);
1659                                 break;
1660                         case TYPE_LNG:
1661                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1662                                 M_LDX(d, s1, disp);
1663                                 break;
1664                         case TYPE_ADR:
1665                                 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1666                                 M_ALD(d, s1, disp);
1667                                 break;
1668                         case TYPE_FLT:
1669                                 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1670                                 M_FLD(d, s1, disp);
1671                                 break;
1672                         case TYPE_DBL:                          
1673                                 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1674                                 M_DLD(d, s1, disp);
1675                                 break;
1676                         default:
1677                                 assert(0);
1678                                 break;
1679                         }
1680                         emit_store_dst(jd, iptr, d);
1681                         break;
1682
1683                 case ICMD_PUTFIELD:   /* ..., objectref, value  ==> ...               */
1684
1685                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1686                         emit_nullpointer_check(cd, iptr, s1);
1687
1688                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1689                                 uf = iptr->sx.s23.s3.uf;
1690                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1691                                 disp      = 0;
1692                         }
1693                         else {
1694                                 uf        = NULL;
1695                                 fi        = iptr->sx.s23.s3.fmiref->p.field;
1696                                 fieldtype = fi->type;
1697                                 disp      = fi->offset;
1698                                 }
1699
1700                         if (IS_INT_LNG_TYPE(fieldtype))
1701                                 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1702                         else
1703                                 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1704
1705                         if (INSTRUCTION_IS_UNRESOLVED(iptr))
1706                                 codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0);
1707
1708                         switch (fieldtype) {
1709                         case TYPE_INT:
1710                                 M_IST(s2, s1, disp);
1711                                 break;
1712                         case TYPE_LNG:
1713                                 M_STX(s2, s1, disp);
1714                                 break;
1715                         case TYPE_ADR:
1716                                 M_AST(s2, s1, disp);
1717                                 break;
1718                         case TYPE_FLT:
1719                                 M_FST(s2, s1, disp);
1720                                 break;
1721                         case TYPE_DBL:
1722                                 M_DST(s2, s1, disp);
1723                                 break;
1724                         default:
1725                                 assert(0);
1726                                 break;
1727                         }
1728                         break;
1729
1730                 case ICMD_PUTFIELDCONST:  /* ..., objectref  ==> ...                  */
1731                                           /* val = value (in current instruction)     */
1732                                           /* following NOP)                           */
1733
1734                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1735                         emit_nullpointer_check(cd, iptr, s1);
1736
1737                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1738                                 unresolved_field *uf = iptr->sx.s23.s3.uf;
1739
1740                                 fieldtype = uf->fieldref->parseddesc.fd->type;
1741
1742                                 codegen_addpatchref(cd, PATCHER_get_putfield,
1743                                                                         uf, 0);
1744
1745                                 if (opt_showdisassemble) {
1746                                         M_NOP; M_NOP;
1747                                 }
1748
1749                                 disp = 0;
1750
1751                         } else {
1752                         {
1753                                 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1754
1755                                 fieldtype = fi->type;
1756                                 disp = fi->offset;
1757                         }
1758
1759                         }
1760
1761                         switch (fieldtype) {
1762                         case TYPE_INT:
1763                                 M_IST(REG_ZERO, s1, disp);
1764                                 break;
1765                         case TYPE_LNG:
1766                                 M_STX(REG_ZERO, s1, disp);
1767                                 break;
1768                         case TYPE_ADR:
1769                                 M_AST(REG_ZERO, s1, disp);
1770                                 break;
1771                         case TYPE_FLT:
1772                                 M_FST(REG_ZERO, s1, disp);
1773                                 break;
1774                         case TYPE_DBL:
1775                                 M_DST(REG_ZERO, s1, disp);
1776                                 break;
1777                         }
1778                         break;
1779
1780
1781                 /* branch operations **************************************************/
1782
1783                 case ICMD_ATHROW:       /* ..., objectref ==> ... (, objectref)       */
1784
1785                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1786                         M_INTMOVE(s1, REG_ITMP2_XPTR);
1787
1788 #ifdef ENABLE_VERIFIER
1789                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1790                                 unresolved_class *uc = iptr->sx.s23.s2.uc;
1791
1792                                 codegen_add_patch_ref(cd, PATCHER_athrow_areturn, uc, 0);
1793                         }
1794 #endif /* ENABLE_VERIFIER */
1795
1796                         disp = dseg_add_functionptr(cd, asm_handle_exception);
1797                         M_ALD(REG_ITMP1, REG_PV, disp);
1798                         M_JMP(REG_ITMP3_XPC, REG_ITMP1, REG_ZERO);
1799                         M_NOP;
1800                         M_NOP;              /* nop ensures that XPC is less than the end */
1801                                             /* of basic block                            */
1802                         ALIGNCODENOP;
1803                         break;
1804
1805                 case ICMD_GOTO:         /* ... ==> ...                                */
1806                 case ICMD_RET:          /* ... ==> ...                                */
1807
1808                         emit_br(cd, iptr->dst.block);
1809                         ALIGNCODENOP;
1810                         break;
1811
1812                 case ICMD_JSR:          /* ... ==> ...                                */
1813
1814                         emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1815                         ALIGNCODENOP;
1816                         break;
1817
1818                 case ICMD_IFNULL:       /* ..., value ==> ...                         */
1819                 case ICMD_IFNONNULL:
1820
1821                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1822                         emit_bccz(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, s1, BRANCH_OPT_NONE);
1823                         break;
1824                         
1825                 /* Note: int compares must not branch on the register directly.       */
1826                 /* Reason is, that register content is not 32-bit clean.              */
1827
1828                 case ICMD_IFEQ:         /* ..., value ==> ...                         */
1829
1830                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1831                         
1832                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1833                                 M_CMP_IMM(s1, iptr->sx.val.i);
1834                         }
1835                         else {
1836                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1837                                 M_CMP(s1, REG_ITMP2);
1838                         }
1839                         emit_beq(cd, iptr->dst.block);
1840                         break;
1841
1842                 case ICMD_IFLT:         /* ..., value ==> ...                         */
1843
1844                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1845                         
1846                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1847                                 M_CMP_IMM(s1, iptr->sx.val.i);
1848                         } 
1849                         else {
1850                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1851                                 M_CMP(s1, REG_ITMP2);
1852                         }
1853                         emit_blt(cd, iptr->dst.block);
1854                         break;
1855
1856                 case ICMD_IFLE:         /* ..., value ==> ...                         */
1857
1858                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1859
1860                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1861                                 M_CMP_IMM(s1, iptr->sx.val.i);
1862                         }
1863                         else {
1864                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1865                                 M_CMP(s1, REG_ITMP2);
1866                         }
1867                         emit_ble(cd, iptr->dst.block);
1868                         break;
1869
1870                 case ICMD_IFNE:         /* ..., value ==> ...                         */
1871
1872                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1873                 
1874                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1875                                 M_CMP_IMM(s1, iptr->sx.val.i);
1876                         }
1877                         else {
1878                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1879                                 M_CMP(s1, REG_ITMP2);
1880                         }
1881                         emit_bne(cd, iptr->dst.block);
1882                         break;
1883                                                 
1884                 case ICMD_IFGT:         /* ..., value ==> ...                         */
1885
1886                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1887                 
1888                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1889                                 M_CMP_IMM(s1, iptr->sx.val.i);
1890                         } 
1891                         else {
1892                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1893                                 M_CMP(s1, REG_ITMP2);
1894                         }
1895                         emit_bgt(cd, iptr->dst.block);          
1896                         break;
1897
1898                 case ICMD_IFGE:         /* ..., value ==> ...                         */
1899
1900                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1901
1902                         if ((iptr->sx.val.i >= -4096) && (iptr->sx.val.i <= 4095)) {
1903                                 M_CMP_IMM(s1, iptr->sx.val.i);
1904                         }
1905                         else {
1906                                 ICONST(REG_ITMP2, iptr->sx.val.i);
1907                                 M_CMP(s1, REG_ITMP2);
1908                         }
1909                         emit_bge(cd, iptr->dst.block);
1910                         break;
1911                         
1912                 case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
1913
1914                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1915                         if (iptr->sx.val.l == 0)
1916                                 emit_beqz(cd, iptr->dst.block, s1);
1917                         else {
1918                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
1919                                         M_CMP_IMM(s1, iptr->sx.val.l);
1920                                 }
1921                                 else {
1922                                         LCONST(REG_ITMP2, iptr->sx.val.l);
1923                                         M_CMP(s1, REG_ITMP2);
1924                                 }
1925                                 emit_beq_xcc(cd, iptr->dst.block);
1926                         }
1927                         break;
1928                         
1929                 case ICMD_IF_LLT:       /* ..., value ==> ...                         */
1930
1931                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1932                         if (iptr->sx.val.l == 0)
1933                                 emit_bltz(cd, iptr->dst.block, s1);
1934                         else {
1935                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
1936                                         M_CMP_IMM(s1, iptr->sx.val.l);
1937                                 } 
1938                                 else {
1939                                         ICONST(REG_ITMP2, iptr->sx.val.l);
1940                                         M_CMP(s1, REG_ITMP2);
1941                                 }
1942                                 emit_blt_xcc(cd, iptr->dst.block);
1943                         }
1944                         break;
1945
1946                 case ICMD_IF_LLE:       /* ..., value ==> ...                         */
1947
1948                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1949                         if (iptr->sx.val.l == 0)
1950                                 emit_blez(cd, iptr->dst.block, s1);
1951                         else {
1952                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
1953                                         M_CMP_IMM(s1, iptr->sx.val.l);
1954                                 }
1955                                 else {
1956                                         ICONST(REG_ITMP2, iptr->sx.val.l);
1957                                         M_CMP(s1, REG_ITMP2);
1958                                 }
1959                                 emit_ble_xcc(cd, iptr->dst.block);
1960                         }
1961                         break;
1962                         
1963                 case ICMD_IF_LNE:       /* ..., value ==> ...                         */
1964
1965                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1966                         if (iptr->sx.val.l == 0)
1967                                 emit_bnez(cd, iptr->dst.block, s1);
1968                         else {
1969                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
1970                                         M_CMP_IMM(s1, iptr->sx.val.l);
1971                                 }
1972                                 else {
1973                                         ICONST(REG_ITMP2, iptr->sx.val.l);
1974                                         M_CMP(s1, REG_ITMP2);
1975                                 }
1976                                 emit_bne_xcc(cd, iptr->dst.block);
1977                         }
1978                         break;
1979                                                 
1980                 case ICMD_IF_LGT:       /* ..., value ==> ...                         */
1981
1982                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1983                         if (iptr->sx.val.l == 0)
1984                                 emit_bgtz(cd, iptr->dst.block, s1);
1985                         else {
1986                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
1987                                         M_CMP_IMM(s1, iptr->sx.val.l);
1988                                 } 
1989                                 else {
1990                                         ICONST(REG_ITMP2, iptr->sx.val.l);
1991                                         M_CMP(s1, REG_ITMP2);
1992                                 }
1993                                 emit_bgt_xcc(cd, iptr->dst.block);
1994                         }
1995                         break;
1996
1997                 case ICMD_IF_LGE:       /* ..., value ==> ...                         */
1998
1999                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2000                         if (iptr->sx.val.l == 0)
2001                                 emit_bgez(cd, iptr->dst.block, s1);
2002                         else {
2003                                 if ((iptr->sx.val.l >= -4096) && (iptr->sx.val.l <= 4095)) {
2004                                         M_CMP_IMM(s1, iptr->sx.val.l);
2005                                 }
2006                                 else {
2007                                         ICONST(REG_ITMP2, iptr->sx.val.l);
2008                                         M_CMP(s1, REG_ITMP2);
2009                                 }
2010                                 emit_bge_xcc(cd, iptr->dst.block);
2011                         }
2012                         break;                  
2013                         
2014
2015                 case ICMD_IF_ACMPEQ:    /* ..., value, value ==> ...                  */
2016                 case ICMD_IF_LCMPEQ:    /* op1 = target JavaVM pc                     */
2017
2018                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2019                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2020                         M_CMP(s1, s2);
2021                         emit_beq_xcc(cd, iptr->dst.block);
2022                         break;
2023
2024                 case ICMD_IF_ICMPEQ:    /* 32-bit compare                             */
2025
2026                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2027                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2028                         M_CMP(s1, s2);
2029                         emit_beq(cd, iptr->dst.block);
2030                         break;
2031
2032                 case ICMD_IF_ACMPNE:    /* ..., value, value ==> ...                  */
2033                 case ICMD_IF_LCMPNE:    /* op1 = target JavaVM pc                     */
2034
2035                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2036                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2037                         M_CMP(s1, s2);
2038                         emit_bne_xcc(cd, iptr->dst.block);
2039                         break;
2040                         
2041                 case ICMD_IF_ICMPNE:    /* 32-bit compare                             */
2042
2043                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2044                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2045                         M_CMP(s1, s2);
2046                         emit_bne(cd, iptr->dst.block);
2047                         break;
2048
2049                 case ICMD_IF_LCMPLT:    /* ..., value, value ==> ...                  */
2050
2051                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2052                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2053                         M_CMP(s1, s2);
2054                         emit_blt_xcc(cd, iptr->dst.block);
2055                         break;
2056                         
2057                 case ICMD_IF_ICMPLT:    /* 32-bit compare                             */
2058
2059                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2060                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2061                         M_CMP(s1, s2);
2062                         emit_blt(cd, iptr->dst.block);
2063                         break;
2064
2065                 case ICMD_IF_LCMPGT:    /* ..., value, value ==> ...                  */
2066
2067                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2068                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2069                         M_CMP(s1, s2);
2070                         emit_bgt_xcc(cd, iptr->dst.block);
2071                         break;
2072                         
2073                 case ICMD_IF_ICMPGT:    /* 32-bit compare                             */
2074
2075                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2076                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2077                         M_CMP(s1, s2);
2078                         emit_bgt(cd, iptr->dst.block);
2079                         break;
2080
2081                 case ICMD_IF_LCMPLE:    /* ..., value, value ==> ...                  */
2082
2083                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2084                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2085                         M_CMP(s1, s2);
2086                         emit_ble_xcc(cd, iptr->dst.block);
2087                         break;
2088                         
2089                 case ICMD_IF_ICMPLE:    /* 32-bit compare                             */
2090
2091                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2092                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2093                         M_CMP(s1, s2);
2094                         emit_ble(cd, iptr->dst.block);
2095                         break;                  
2096         
2097
2098                 case ICMD_IF_LCMPGE:    /* ..., value, value ==> ...                  */
2099
2100                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2101                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2102                         M_CMP(s1, s2);
2103                         emit_bge_xcc(cd, iptr->dst.block);
2104                         break;
2105                         
2106                 case ICMD_IF_ICMPGE:    /* 32-bit compare                             */
2107
2108                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2109                         s2 = emit_load_s2(jd, iptr, REG_ITMP2);
2110                         M_CMP(s1, s2);
2111                         emit_bge(cd, iptr->dst.block);
2112                         break;
2113
2114
2115                 case ICMD_IRETURN:      /* ..., retvalue ==> ...                      */
2116                 case ICMD_LRETURN:
2117
2118                         s1 = emit_load_s1(jd, iptr, REG_RESULT_CALLEE);
2119                         M_INTMOVE(s1, REG_RESULT_CALLEE);
2120                         goto nowperformreturn;
2121
2122                 case ICMD_ARETURN:      /* ..., retvalue ==> ...                      */
2123
2124                         s1 = emit_load_s1(jd, iptr, REG_RESULT_CALLEE);
2125                         M_INTMOVE(s1, REG_RESULT_CALLEE);
2126
2127 #ifdef ENABLE_VERIFIER
2128                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2129                                 unresolved_class *uc = iptr->sx.s23.s2.uc;
2130
2131                                 codegen_add_patch_ref(cd, PATCHER_athrow_areturn, uc, 0);
2132                         }
2133 #endif /* ENABLE_VERIFIER */
2134                         goto nowperformreturn;
2135
2136                 case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
2137                 case ICMD_DRETURN:
2138
2139                         s1 = emit_load_s1(jd, iptr, REG_FRESULT);
2140                         M_DBLMOVE(s1, REG_FRESULT);
2141                         goto nowperformreturn;
2142
2143                 case ICMD_RETURN:       /* ...  ==> ...                               */
2144
2145 nowperformreturn:
2146                         {
2147                         s4 i, p;
2148                         
2149                         p = cd->stackframesize;
2150
2151 #if !defined(NDEBUG)
2152                         if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2153                                 emit_verbosecall_exit(jd);
2154 #endif
2155
2156 #if defined(ENABLE_THREADS)
2157                         if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2158 /* XXX: REG_RESULT is save, but what about FRESULT? */
2159                                 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8); /* XXX: what for ? */
2160
2161                                 switch (iptr->opc) {
2162                                 case ICMD_FRETURN:
2163                                 case ICMD_DRETURN:
2164                                         M_DST(REG_FRESULT, REG_SP, rd->memuse * 8);
2165                                         break;
2166                                 }
2167
2168                                 disp = dseg_add_functionptr(cd, BUILTIN_monitorexit);
2169                                 M_ALD(REG_ITMP3, REG_PV, disp);
2170                                 M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO); /*REG_RA_CALLER */
2171
2172                                 switch (iptr->opc) {
2173                                 case ICMD_FRETURN:
2174                                 case ICMD_DRETURN:
2175                                         M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
2176                                         break;
2177                                 }
2178                         }
2179 #endif
2180
2181
2182
2183                         M_RETURN(REG_RA_CALLEE, 8); /* implicit window restore */
2184                         M_NOP;
2185                         ALIGNCODENOP;
2186                         }
2187                         break;
2188
2189                 case ICMD_TABLESWITCH:  /* ..., index ==> ...                         */
2190                         {
2191                         s4 i, l;
2192                         branch_target_t *table;
2193
2194                         table = iptr->dst.table;
2195
2196                         l = iptr->sx.s23.s2.tablelow;
2197                         i = iptr->sx.s23.s3.tablehigh;
2198                         
2199                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2200                         if (l == 0) {
2201                                 M_INTMOVE(s1, REG_ITMP1);
2202                         }
2203                         else if (l <= 4095) {
2204                                 M_ADD_IMM(s1, -l, REG_ITMP1);
2205                         }
2206                         else {
2207                                 ICONST(REG_ITMP2, l);
2208                                 /* XXX: do I need to truncate s1 to 32-bit ? */
2209                                 M_SUB(s1, REG_ITMP2, REG_ITMP1);
2210                         }
2211                         i = i - l + 1;
2212
2213
2214                         /* range check */
2215                                         
2216                         if (i <= 4095) {
2217                                 M_CMP_IMM(REG_ITMP1, i - 1);
2218                         }
2219                         else {
2220                                 ICONST(REG_ITMP2, i - 1);
2221                                 M_CMP(REG_ITMP1, REG_ITMP2);
2222                         }               
2223                         emit_bugt(cd, table[0].block); /* default target */
2224
2225                         /* build jump table top down and use address of lowest entry */
2226
2227                         table += i;
2228
2229                         while (--i >= 0) {
2230                                 dseg_add_target(cd, table->block); 
2231                                 --table;
2232                                 }
2233                         }
2234
2235                         /* length of dataseg after last dseg_addtarget is used by load */
2236
2237                         M_ASLL_IMM(REG_ITMP1, POINTERSHIFT, REG_ITMP1);
2238                         M_AADD(REG_ITMP1, REG_PV, REG_ITMP2);
2239                         M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
2240                         M_JMP(REG_ZERO, REG_ITMP2, REG_ZERO);
2241                         M_NOP;
2242                         ALIGNCODENOP;
2243                         break;
2244                         
2245                 case ICMD_LOOKUPSWITCH: /* ..., key ==> ...                           */
2246                         {
2247                         s4 i;
2248                         lookup_target_t *lookup;
2249
2250                         lookup = iptr->dst.lookup;
2251
2252                         i = iptr->sx.s23.s2.lookupcount;
2253                         
2254                         MCODECHECK((i<<2)+8);
2255                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2256
2257                         while (--i >= 0) {
2258                                 if ((lookup->value >= -4096) && (lookup->value <= 4095)) {
2259                                         M_CMP_IMM(s1, lookup->value);
2260                                 } else {                                        
2261                                         ICONST(REG_ITMP2, lookup->value);
2262                                         M_CMP(s1, REG_ITMP2);
2263                                 }
2264                                 emit_beq(cd, lookup->target.block);
2265                                 ++lookup;
2266                         }
2267
2268                         emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2269                         ALIGNCODENOP;
2270                         break;
2271                         }
2272
2273
2274                 case ICMD_BUILTIN:      /* ..., arg1, arg2, arg3 ==> ...              */
2275
2276                         bte = iptr->sx.s23.s3.bte;
2277                         md = bte->md;
2278                         
2279                         /* XXX: proper builtin calling and float args are so not implemented */
2280                         assert(md->paramcount <= 5 && md->argfltreguse < 1);
2281                         
2282                         goto gen_method;
2283
2284                 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...            */
2285
2286                 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2287                 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer    */
2288                 case ICMD_INVOKEINTERFACE:
2289
2290                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2291                                 lm = NULL;
2292                                 um = iptr->sx.s23.s3.um;
2293                                 md = um->methodref->parseddesc.md;
2294                         }
2295                         else {
2296                                 lm = iptr->sx.s23.s3.fmiref->p.method;
2297                                 um = NULL;
2298                                 md = lm->parseddesc;
2299                         }
2300
2301 gen_method:
2302                         s3 = md->paramcount;
2303
2304                         MCODECHECK((s3 << 1) + 64);
2305
2306                         /* copy arguments to registers or stack location                  */
2307
2308                         for (s3 = s3 - 1; s3 >= 0; s3--) {
2309                                 var = VAR(iptr->sx.s23.s2.args[s3]);
2310
2311                                 if (var->flags & PREALLOC)
2312                                         continue;
2313
2314                                 if (IS_INT_LNG_TYPE(var->type)) {
2315                                         if (!md->params[s3].inmemory) {
2316                                                 s1 = rd->argintregs[md->params[s3].regoff];
2317                                                 d = emit_load(jd, iptr, var, s1);
2318                                                 M_INTMOVE(d, s1);
2319                                         } 
2320                                         else {
2321                                                 d = emit_load(jd, iptr, var, REG_ITMP1);
2322                                                 M_STX(d, REG_SP, JITSTACK + md->params[s3].regoff * 8);
2323                                         }
2324                                 }
2325                                 else {
2326                                         if (!md->params[s3].inmemory) {
2327                                                 s1 = rd->argfltregs[md->params[s3].regoff];
2328                                                 d = emit_load(jd, iptr, var, s1);
2329                                                 if (IS_2_WORD_TYPE(var->type))
2330                                                         M_DMOV(d, s1);
2331                                                 else
2332                                                         M_FMOV(d, s1);
2333                                         }
2334                                         else {
2335                                                 d = emit_load(jd, iptr, var, REG_FTMP1);
2336                                                 if (IS_2_WORD_TYPE(var->type))
2337                                                         M_DST(d, REG_SP, JITSTACK + md->params[s3].regoff * 8);
2338                                                 else
2339                                                         M_FST(d, REG_SP, JITSTACK + md->params[s3].regoff * 8);
2340                                         }
2341                                 }
2342                         }
2343
2344                         switch (iptr->opc) {
2345                         case ICMD_BUILTIN:
2346                                 disp = dseg_add_functionptr(cd, bte->fp);
2347
2348                                 M_ALD(REG_PV_CALLER, REG_PV, disp);  /* built-in-function pointer */
2349
2350                                 /* XXX jit-c-call */
2351                                 /* generate the actual call */
2352     
2353                             M_JMP(REG_RA_CALLER, REG_PV_CALLER, REG_ZERO);
2354                             M_NOP;
2355                             disp = (s4) (cd->mcodeptr - cd->mcodebase);
2356                             /* REG_RA holds the value of the jmp instruction, therefore +8 */
2357                             M_LDA(REG_ZERO, REG_RA_CALLER, -disp + 8); 
2358
2359                                 emit_exception_check(cd, iptr);
2360                                 break;
2361
2362                         case ICMD_INVOKESPECIAL:
2363                                 emit_nullpointer_check(cd, iptr, REG_OUT0);
2364                                 /* fall-through */
2365
2366                         case ICMD_INVOKESTATIC:
2367                                 if (lm == NULL) {
2368                                         disp = dseg_add_unique_address(cd, NULL);
2369
2370                                         codegen_add_patch_ref(cd, PATCHER_invokestatic_special,
2371                                                                                 um, disp);
2372                                 }
2373                                 else
2374                                         disp = dseg_add_address(cd, lm->stubroutine);
2375
2376                                 M_ALD(REG_PV_CALLER, REG_PV, disp);          /* method pointer in pv */
2377                                 
2378                                 /* generate the actual call */
2379     
2380                             M_JMP(REG_RA_CALLER, REG_PV_CALLER, REG_ZERO);
2381                             M_NOP;
2382                             disp = (s4) (cd->mcodeptr - cd->mcodebase);
2383                             /* REG_RA holds the value of the jmp instruction, therefore +8 */
2384                             M_LDA(REG_ZERO, REG_RA_CALLER, -disp + 8); 
2385                                 break;
2386
2387                         case ICMD_INVOKEVIRTUAL:
2388                                 emit_nullpointer_check(cd, iptr, REG_OUT0);
2389
2390                                 if (lm == NULL) {
2391                                         codegen_add_patch_ref(cd, PATCHER_invokevirtual, um, 0);
2392
2393                                         s1 = 0;
2394                                 }
2395                                 else
2396                                         s1 = OFFSET(vftbl_t, table[0]) +
2397                                                 sizeof(methodptr) * lm->vftblindex;
2398
2399                                 /* implicit null-pointer check */
2400                                 M_ALD(REG_METHODPTR, REG_OUT0,OFFSET(java_objectheader, vftbl));
2401                                 M_ALD(REG_PV_CALLER, REG_METHODPTR, s1);
2402                                 
2403                                 /* generate the actual call */
2404     
2405                             M_JMP(REG_RA_CALLER, REG_PV_CALLER, REG_ZERO);
2406                             M_NOP;
2407                             disp = (s4) (cd->mcodeptr - cd->mcodebase);
2408                             /* REG_RA holds the value of the jmp instruction, therefore +8 */
2409                             M_LDA(REG_ZERO, REG_RA_CALLER, -disp + 8); 
2410                                 break;
2411
2412                         case ICMD_INVOKEINTERFACE:
2413                                 emit_nullpointer_check(cd, iptr, REG_OUT0);
2414
2415                                 if (lm == NULL) {
2416                                         codegen_add_patch_ref(cd, PATCHER_invokeinterface, um, 0);
2417
2418                                         s1 = 0;
2419                                         s2 = 0;
2420                                 } 
2421                                 else {
2422                                         s1 = OFFSET(vftbl_t, interfacetable[0]) -
2423                                                 sizeof(methodptr*) * lm->class->index;
2424
2425                                         s2 = sizeof(methodptr) * (lm - lm->class->methods);
2426                                 }
2427
2428                                 /* implicit null-pointer check */
2429                                 M_ALD(REG_METHODPTR, REG_OUT0, OFFSET(java_objectheader, vftbl));
2430                                 M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
2431                                 M_ALD(REG_PV_CALLER, REG_METHODPTR, s2);
2432
2433                             /* generate the actual call */
2434     
2435                             M_JMP(REG_RA_CALLER, REG_PV_CALLER, REG_ZERO);
2436                             M_NOP;
2437                             disp = (s4) (cd->mcodeptr - cd->mcodebase);
2438                             /* REG_RA holds the value of the jmp instruction, therefore +8 */
2439                             M_LDA(REG_ZERO, REG_RA_CALLER, -disp + 8);
2440                                 break;
2441                         }
2442
2443                         /* store return value */
2444
2445                         d = md->returntype.type;
2446
2447                         if (d != TYPE_VOID) {
2448                                 if (IS_INT_LNG_TYPE(d)) {
2449                                         s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_CALLER);
2450                                         M_INTMOVE(REG_RESULT_CALLER, s1);
2451                                 } 
2452                                 else {
2453                                         s1 = codegen_reg_of_dst(jd, iptr, REG_FRESULT);
2454                                         if (IS_2_WORD_TYPE(d)) {
2455                                                 M_DBLMOVE(REG_FRESULT, s1);
2456                                         } else {
2457                                                 M_FLTMOVE(REG_FRESULT, s1);
2458                                         }
2459                                 }
2460                                 emit_store_dst(jd, iptr, s1);
2461                         }
2462                         break;
2463
2464
2465                 case ICMD_CHECKCAST:  /* ..., objectref ==> ..., objectref            */
2466                                       /* val.a: (classinfo*) superclass               */
2467
2468                         /*  superclass is an interface:
2469                          *
2470                          *  OK if ((sub == NULL) ||
2471                          *         (sub->vftbl->interfacetablelength > super->index) &&
2472                          *         (sub->vftbl->interfacetable[-super->index] != NULL));
2473                          *
2474                          *  superclass is a class:
2475                          *
2476                          *  OK if ((sub == NULL) || (0
2477                          *         <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2478                          *         super->vftbl->diffvall));
2479                          */
2480
2481                         if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2482                                 classinfo *super;
2483                                 s4         superindex;
2484
2485                                 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2486                                         super      = NULL;
2487                                         superindex = 0;
2488                                 }
2489                                 else {
2490                                         super = iptr->sx.s23.s3.c.cls;
2491                                         superindex = super->index;
2492                                 }
2493
2494 #if defined(ENABLE_THREADS)
2495                                 codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2496 #endif
2497
2498                                 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2499
2500                                 /* if class is not resolved, check which code to call */
2501
2502                                 if (super == NULL) {
2503                                         emit_label_beqz(cd, BRANCH_LABEL_1, s1);
2504
2505                                         cr   = iptr->sx.s23.s3.c.ref;
2506                                         disp = dseg_add_unique_s4(cd, 0);         /* super->flags */
2507
2508                                         codegen_add_patch_ref(cd, PATCHER_checkcast_instanceof_flags,
2509                                                                                   cr, disp);
2510
2511                                         M_ILD(REG_ITMP2, REG_PV, disp);
2512                                         M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
2513                                         emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP2);
2514                                 }
2515
2516                                 /* interface checkcast code */
2517
2518                                 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2519                                         if (super == NULL) {
2520                                                 cr = iptr->sx.s23.s3.c.ref;
2521
2522                                                 codegen_add_patch_ref(cd, PATCHER_checkcast_interface,
2523                                                                                           cr, 0);
2524                                         }
2525                                         else {
2526                                                 emit_label_beqz(cd, BRANCH_LABEL_3, s1);
2527                                         }
2528
2529                                         M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2530                                         M_ILD(REG_ITMP3, REG_ITMP2,
2531                                                         OFFSET(vftbl_t, interfacetablelength));
2532                                         M_ADD_IMM(REG_ITMP3, -superindex, REG_ITMP3);
2533                                         emit_classcast_check(cd, iptr, ICMD_IFLE, REG_ITMP3, s1);
2534
2535                                         M_ALD(REG_ITMP3, REG_ITMP2,
2536                                                   OFFSET(vftbl_t, interfacetable[0]) -
2537                                                   superindex * sizeof(methodptr*));
2538                                         emit_classcast_check(cd, iptr, ICMD_IFEQ, REG_ITMP3, s1);
2539
2540                                         if (super == NULL)
2541                                                 emit_label_br(cd, BRANCH_LABEL_4);
2542                                         else
2543                                                 emit_label(cd, BRANCH_LABEL_3);
2544                                 }
2545
2546                                 /* class checkcast code */
2547
2548                                 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2549                                         if (super == NULL) {
2550                                                 emit_label(cd, BRANCH_LABEL_2);
2551
2552                                                 cr   = iptr->sx.s23.s3.c.ref;
2553                                                 disp = dseg_add_unique_address(cd, NULL);
2554
2555                                                 codegen_add_patch_ref(cd,
2556                                                                                         PATCHER_checkcast_instanceof_class,
2557                                                                                           cr, disp);
2558                                         }
2559                                         else {
2560                                                 disp = dseg_add_address(cd, super->vftbl);
2561
2562                                                 emit_label_beqz(cd, BRANCH_LABEL_5, s1);
2563                                         }
2564
2565                                         M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2566                                         M_ALD(REG_ITMP3, REG_PV, disp);
2567 #if defined(ENABLE_THREADS)
2568                                         codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
2569 #endif
2570                                         M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2571                                         M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2572                                         M_SUB(REG_ITMP2, REG_ITMP3, REG_ITMP2);
2573                                         M_ALD(REG_ITMP3, REG_PV, disp);
2574                                         M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2575 #if defined(ENABLE_THREADS)
2576                                         codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
2577 #endif
2578                                         /*                              } */
2579                                         M_CMP(REG_ITMP3, REG_ITMP2);
2580                                         emit_classcast_check(cd, iptr, BRANCH_ULT, REG_ITMP3, s1);
2581
2582                                         if (super != NULL)
2583                                                 emit_label(cd, BRANCH_LABEL_5);
2584                                 }
2585
2586                                 if (super == NULL) {
2587                                         emit_label(cd, BRANCH_LABEL_1);
2588                                         emit_label(cd, BRANCH_LABEL_4);
2589                                 }
2590
2591                                 d = codegen_reg_of_dst(jd, iptr, s1);
2592                         }
2593                         else {
2594                                 /* array type cast-check */
2595
2596                                 s1 = emit_load_s1(jd, iptr, rd->argintregs[0]);
2597                                 M_INTMOVE(s1, rd->argintregs[0]);
2598
2599                                 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2600
2601                                 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2602                                         cr   = iptr->sx.s23.s3.c.ref;
2603                                         disp = dseg_add_unique_address(cd, NULL);
2604
2605                                         codegen_add_patch_ref(cd, PATCHER_builtin_arraycheckcast,
2606                                                                                   cr, disp);
2607                                 }
2608                                 else
2609                                         disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2610
2611                                 M_ALD(rd->argintregs[1], REG_PV, disp);
2612                                 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2613                                 M_ALD(REG_ITMP3, REG_PV, disp);
2614                                 /* XXX jit-c-call */
2615                                 M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
2616                                 M_NOP;
2617
2618                                 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2619                                 emit_classcast_check(cd, iptr, ICMD_IFEQ, REG_RESULT_CALLER, s1);
2620
2621                                 d = codegen_reg_of_dst(jd, iptr, s1);
2622                         }
2623
2624                         M_INTMOVE(s1, d);
2625                         emit_store_dst(jd, iptr, d);
2626                         break;
2627
2628                 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
2629                                       /* val.a: (classinfo*) superclass               */
2630
2631                         /*  superclass is an interface:
2632                          *      
2633                          *  return (sub != NULL) &&
2634                          *         (sub->vftbl->interfacetablelength > super->index) &&
2635                          *         (sub->vftbl->interfacetable[-super->index] != NULL);
2636                          *      
2637                          *  superclass is a class:
2638                          *      
2639                          *  return ((sub != NULL) && (0
2640                          *          <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2641                          *          super->vftbl->diffvall));
2642                          */
2643
2644                         {
2645                         classinfo *super;
2646                         vftbl_t   *supervftbl;
2647                         s4         superindex;
2648
2649                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2650                                 super = NULL;
2651                                 superindex = 0;
2652                                 supervftbl = NULL;
2653
2654                         } else {
2655                                 super = iptr->sx.s23.s3.c.cls;
2656                                 superindex = super->index;
2657                                 supervftbl = super->vftbl;
2658                         }
2659
2660 #if defined(ENABLE_THREADS)
2661                         codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2662 #endif
2663                         s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2664                         d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2665                         if (s1 == d) {
2666                                 M_MOV(s1, REG_ITMP1);
2667                                 s1 = REG_ITMP1;
2668                         }
2669
2670                         M_CLR(d);
2671
2672                         /* if class is not resolved, check which code to call */
2673
2674                         if (super == NULL) {
2675                                 emit_label_beqz(cd, BRANCH_LABEL_1, s1);
2676
2677                                 cr   = iptr->sx.s23.s3.c.ref;
2678                                 disp = dseg_add_unique_s4(cd, 0);             /* super->flags */
2679
2680                                 codegen_add_patch_ref(cd, PATCHER_checkcast_instanceof_flags,
2681                                                                           cr, disp);
2682
2683                                 M_ILD(REG_ITMP3, REG_PV, disp);
2684                                 M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
2685                                 emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP3);
2686                         }
2687
2688                         /* interface instanceof code */
2689
2690                         if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2691                                 if (super == NULL) {
2692                                         cr = iptr->sx.s23.s3.c.ref;
2693
2694                                         codegen_add_patch_ref(cd, PATCHER_instanceof_interface,
2695                                                                                   cr, 0);
2696                                 }
2697                                 else {
2698                                         emit_label_beqz(cd, BRANCH_LABEL_3, s1);
2699                                 }
2700
2701                                 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2702                                 M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2703                                 M_CMP_IMM(REG_ITMP3, superindex);
2704                                 M_BLE(4);
2705                                 M_NOP;
2706                                 M_ALD(REG_ITMP1, REG_ITMP1,
2707                                           (s4) (OFFSET(vftbl_t, interfacetable[0]) -
2708                                                         superindex * sizeof(methodptr*)));
2709                                 M_CMOVRNE_IMM(REG_ITMP1, 1, d);      /* REG_ITMP1 != 0  */
2710
2711                                 if (super == NULL)
2712                                         emit_label_br(cd, BRANCH_LABEL_4);
2713                                 else
2714                                         emit_label(cd, BRANCH_LABEL_3);
2715                         }
2716
2717                         /* class instanceof code */
2718
2719                         if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2720                                 if (super == NULL) {
2721                                         emit_label(cd, BRANCH_LABEL_2);
2722
2723                                         cr   = iptr->sx.s23.s3.c.ref;
2724                                         disp = dseg_add_unique_address(cd, NULL);
2725
2726                                         codegen_add_patch_ref(cd, PATCHER_checkcast_instanceof_class,
2727                                                                                   cr, disp);
2728                                 }
2729                                 else {
2730                                         disp = dseg_add_address(cd, supervftbl);
2731
2732                                         emit_label_beqz(cd, BRANCH_LABEL_5, s1);
2733                                 }
2734
2735                                 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2736                                 M_ALD(REG_ITMP2, REG_PV, disp);
2737 #if defined(ENABLE_THREADS)
2738                                 codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
2739 #endif
2740                                 M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2741                                 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2742                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2743 #if defined(ENABLE_THREADS)
2744                                 codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
2745 #endif
2746                                 M_SUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
2747                                 M_CMP(REG_ITMP1, REG_ITMP2);
2748                                 M_XCMOVULE_IMM(1, d);
2749
2750                                 if (super != NULL)
2751                                         emit_label(cd, BRANCH_LABEL_5);
2752                         }
2753
2754                         if (super == NULL) {
2755                                 emit_label(cd, BRANCH_LABEL_1);
2756                                 emit_label(cd, BRANCH_LABEL_4);
2757                         }
2758
2759                         emit_store_dst(jd, iptr, d);
2760                         }
2761                         break;
2762
2763                 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
2764
2765                         /* check for negative sizes and copy sizes to stack if necessary  */
2766
2767                         MCODECHECK((iptr->s1.argcount << 1) + 64);
2768
2769                         for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2770
2771                                 var = VAR(iptr->sx.s23.s2.args[s1]);
2772         
2773                                 /* copy SAVEDVAR sizes to stack */
2774
2775                                 /* Already Preallocated? */
2776
2777                                 if (!(var->flags & PREALLOC)) {
2778                                         s2 = emit_load(jd, iptr, var, REG_ITMP1);
2779                                         M_STX(s2, REG_SP, CSTACK + (s1 * 8));
2780                                 }
2781                         }
2782
2783                         /* arg 0 = dimension count */
2784
2785                         ICONST(REG_OUT0, iptr->s1.argcount);
2786
2787                         /* is patcher function set? */
2788
2789                         if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2790                                 disp = dseg_add_unique_address(cd, 0);
2791
2792                                 codegen_add_patch_ref(cd, PATCHER_builtin_multianewarray,
2793                                                                           iptr->sx.s23.s3.c.ref,
2794                                                                           disp);
2795                         }
2796                         else
2797                                 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2798
2799                         /* arg 1 = arraydescriptor */
2800
2801                         M_ALD(REG_OUT1, REG_PV, disp);
2802
2803                         /* arg 2 = pointer to dimensions = stack pointer (absolute) */
2804
2805                         M_ADD_IMM(REG_SP, CSTACK, REG_OUT2);
2806
2807                         /* XXX c abi call */
2808                         disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2809                         M_ALD(REG_ITMP3, REG_PV, disp);
2810                         M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
2811                         M_NOP;
2812
2813                         /* check for exception before result assignment */
2814
2815                         emit_exception_check(cd, iptr);
2816
2817                         d = codegen_reg_of_dst(jd, iptr, REG_RESULT_CALLER);
2818                         M_INTMOVE(REG_RESULT_CALLER, d);
2819                         emit_store_dst(jd, iptr, d);
2820                         break;
2821
2822                 default:
2823                         exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2824                                                                                    iptr->opc);
2825                         return false;
2826                         
2827         } /* switch */
2828                 
2829         } /* for instruction */
2830         
2831
2832                 
2833         } /* if (bptr -> flags >= BBREACHED) */
2834         } /* for basic block */
2835         
2836         dseg_createlinenumbertable(cd);
2837
2838         /* generate stubs */
2839
2840         emit_patcher_stubs(jd);
2841         REPLACEMENT_EMIT_STUBS(jd);
2842         
2843         /* everything's ok */
2844
2845         return true;    
2846 }
2847
2848
2849 /* createcompilerstub **********************************************************
2850
2851    Creates a stub routine which calls the compiler.
2852         
2853 *******************************************************************************/
2854
2855 #define COMPILERSTUB_DATASIZE    3 * SIZEOF_VOID_P
2856 #define COMPILERSTUB_CODESIZE    4 * 4
2857
2858 #define COMPILERSTUB_SIZE        COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
2859
2860
2861 u1 *createcompilerstub(methodinfo *m)
2862 {
2863         u1     *s;                          /* memory to hold the stub            */
2864         ptrint      *d;
2865         codeinfo    *code;
2866         codegendata *cd;
2867         s4           dumpsize;
2868         
2869         s = CNEW(u1, COMPILERSTUB_SIZE);
2870
2871         /* set data pointer and code pointer */
2872
2873         d = (ptrint *) s;
2874         s = s + COMPILERSTUB_DATASIZE;
2875
2876         /* mark start of dump memory area */
2877
2878         dumpsize = dump_size();
2879
2880         cd = DNEW(codegendata);
2881         cd->mcodeptr = s;
2882         
2883         /* Store the codeinfo pointer in the same place as in the
2884            methodheader for compiled methods. */
2885
2886         code = code_codeinfo_new(m);
2887
2888         d[0] = (ptrint) asm_call_jit_compiler;
2889         d[1] = (ptrint) m;
2890         d[2] = (ptrint) code;
2891
2892         /* code for the stub */
2893         /* no window save yet, user caller's PV */
2894         M_ALD_INTERN(REG_ITMP1, REG_PV_CALLER, -2 * SIZEOF_VOID_P);  /* codeinfo pointer */
2895         M_ALD_INTERN(REG_PV_CALLER, REG_PV_CALLER, -3 * SIZEOF_VOID_P);  /* pointer to compiler */
2896         M_JMP(REG_ZERO, REG_PV_CALLER, REG_ZERO);  /* jump to the compiler, RA is wasted */
2897         M_NOP;
2898
2899 #if defined(ENABLE_STATISTICS)
2900         if (opt_stat)
2901                 count_cstub_len += COMPILERSTUB_SIZE;
2902 #endif
2903
2904         /* release dump area */
2905
2906         dump_release(dumpsize);
2907
2908         return s;
2909 }
2910
2911
2912
2913 /* createnativestub ************************************************************
2914
2915    Creates a stub routine which calls a native method.
2916
2917 *******************************************************************************/
2918
2919 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
2920 {
2921         methodinfo   *m;
2922         codeinfo     *code;
2923         codegendata  *cd;
2924         registerdata *rd;
2925         methoddesc   *md;
2926         s4            nativeparams;
2927         s4            i, j;                 /* count variables                    */
2928         s4            t;
2929         s4            s1, s2, disp;
2930         s4            funcdisp;             /* displacement of the function       */
2931
2932         /* get required compiler data */
2933
2934         m    = jd->m;
2935         code = jd->code;
2936         cd   = jd->cd;
2937         rd   = jd->rd;
2938
2939         /* initialize variables */
2940
2941         md = m->parseddesc;
2942         nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2943
2944         /* calculate stack frame size */
2945
2946         cd->stackframesize =
2947                 sizeof(stackframeinfo) / SIZEOF_VOID_P +
2948                 sizeof(localref_table) / SIZEOF_VOID_P +
2949                 md->paramcount +                /* for saving arguments over calls    */
2950                 nmd->memuse +  /* nmd knows about the native stackframe layout */
2951                 WINSAVE_CNT;
2952
2953         /* create method header */
2954
2955         (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
2956         (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
2957         (void) dseg_add_unique_s4(cd, 0);                      /* IsSync          */
2958         (void) dseg_add_unique_s4(cd, 0);                      /* IsLeaf          */
2959         (void) dseg_add_unique_s4(cd, 0);                      /* IntSave         */
2960         (void) dseg_add_unique_s4(cd, 0);                      /* FltSave         */
2961         (void) dseg_addlinenumbertablesize(cd);
2962         (void) dseg_add_unique_s4(cd, 0);                      /* ExTableSize     */
2963
2964         /* generate stub code */
2965
2966         M_SAVE(REG_SP, -cd->stackframesize * 8, REG_SP); /* build up stackframe    */
2967
2968 #if !defined(NDEBUG)
2969         if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2970                 emit_verbosecall_enter(jd);
2971 #endif
2972
2973         /* get function address (this must happen before the stackframeinfo) */
2974
2975         funcdisp = dseg_add_functionptr(cd, f);
2976
2977 #if !defined(WITH_STATIC_CLASSPATH)
2978         if (f == NULL) {
2979                 codegen_add_patch_ref(cd, PATCHER_resolve_native, m, funcdisp);
2980         }
2981 #endif
2982
2983         /* save float argument registers */
2984
2985         for (i = 0, j = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
2986                 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
2987                         M_DST(rd->argfltregs[i], REG_SP, CSTACK + (j * 8));
2988                         j++;
2989                 }
2990         }
2991
2992         /* prepare data structures for native function call */
2993
2994         M_ADD_IMM(REG_FP, BIAS, REG_OUT0); /* datasp == top of the stack frame (absolute == +BIAS) */
2995         M_MOV(REG_PV_CALLEE, REG_OUT1);
2996         M_MOV(REG_FP, REG_OUT2); /* java sp */
2997         M_MOV(REG_RA_CALLEE, REG_OUT3);
2998         disp = dseg_add_functionptr(cd, codegen_start_native_call);
2999         M_ALD(REG_ITMP3, REG_PV_CALLEE, disp);
3000         M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
3001         M_NOP; /* XXX fill me! */
3002
3003         /* restore float argument registers */
3004
3005         for (i = 0, j = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
3006                 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3007                         M_DLD(rd->argfltregs[i], REG_SP, CSTACK + (j * 8));
3008                         j++;
3009                 }
3010         }
3011
3012         /* copy or spill arguments to new locations */
3013         int num_fltregargs = 0;
3014         int fltregarg_inswap[16];
3015         for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3016                 t = md->paramtypes[i].type;
3017
3018                 if (IS_INT_LNG_TYPE(t)) {
3019                         if (!md->params[i].inmemory) {
3020                                 s1 = rd->argintregs[md->params[i].regoff];
3021                                 /* s1 refers to the old window, transpose */
3022                                 s1 = REG_WINDOW_TRANSPOSE(s1);
3023
3024                                 if (!nmd->params[j].inmemory) {
3025                                         s2 = nat_argintregs[nmd->params[j].regoff];
3026                                         M_INTMOVE(s1, s2);
3027                                 } else {
3028                                         s2 = nmd->params[j].regoff - 6;
3029                                         M_AST(s1, REG_SP, CSTACK + s2 * 8);
3030                                 }
3031
3032                         } else {
3033                                 s1 = md->params[i].regoff + cd->stackframesize;
3034                                 s2 = nmd->params[j].regoff - 6;
3035                                 M_ALD(REG_ITMP1, REG_SP, CSTACK + s1 * 8);
3036                                 M_AST(REG_ITMP1, REG_SP, CSTACK + s2 * 8);
3037                         }
3038
3039                 } else {
3040                         if (!md->params[i].inmemory) {
3041                                 s1 = rd->argfltregs[md->params[i].regoff];
3042
3043                                 if (!nmd->params[j].inmemory) {
3044                                         /* no mapping to regs needed, native flt args use regoff */
3045                                         s2 = nmd->params[j].regoff;
3046                                         
3047                                         /* we cannot move flt regs to their native arg locations directly */
3048                                         M_DMOV(s1, s2 + 16);
3049                                         fltregarg_inswap[num_fltregargs] = s2;
3050                                         num_fltregargs++;
3051                                         printf("flt arg swap to %d\n", s2 + 16);
3052
3053                                 } else {
3054                                         s2 = nmd->params[j].regoff;
3055                                         if (IS_2_WORD_TYPE(t))
3056                                                 M_DST(s1, REG_SP, CSTACK + (s2 * 8));
3057                                         else
3058                                                 M_FST(s1, REG_SP, CSTACK + (s2 * 8));
3059                                 }
3060
3061                         } else {
3062                                 s1 = md->params[i].regoff + cd->stackframesize;
3063                                 s2 = nmd->params[j].regoff - 6;
3064                                 if (IS_2_WORD_TYPE(t)) {
3065                                         M_DLD(REG_FTMP1, REG_SP, CSTACK + s1 * 8);
3066                                         M_DST(REG_FTMP1, REG_SP, CSTACK + s2 * 8);
3067                                 } else {
3068                                         M_FLD(REG_FTMP1, REG_SP, CSTACK + s1 * 8);
3069                                         M_FST(REG_FTMP1, REG_SP, CSTACK + s2 * 8);
3070                                 }
3071                         }
3072                 }
3073         }
3074         
3075         /* move swapped float args to target regs */
3076         for (i = 0; i < num_fltregargs; i++) {
3077                 s1 = fltregarg_inswap[i];
3078                 M_DMOV(s1 + 16, s1);
3079                 printf("float arg to target reg: %d ==> %d\n", s1+16, s1);
3080         }
3081
3082
3083         /* put class into second argument register */
3084
3085         if (m->flags & ACC_STATIC) {
3086                 disp = dseg_add_address(cd, m->class);
3087                 M_ALD(REG_OUT1, REG_PV_CALLEE, disp);
3088         }
3089
3090         /* put env into first argument register */
3091
3092         disp = dseg_add_address(cd, _Jv_env);
3093         M_ALD(REG_OUT0, REG_PV_CALLEE, disp);
3094
3095         /* do the native function call */
3096
3097         M_ALD(REG_ITMP3, REG_PV_CALLEE, funcdisp); /* load adress of native method       */
3098         M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO); /* call native method                 */
3099         M_NOP;                              /* delay slot                         */
3100
3101         /* save return value */
3102
3103         if (md->returntype.type != TYPE_VOID) {
3104                 if (IS_INT_LNG_TYPE(md->returntype.type))
3105                         M_MOV(REG_RESULT_CALLER, REG_RESULT_CALLEE);
3106                 else
3107                         M_DST(REG_FRESULT, REG_SP, CSTACK);
3108         }
3109         
3110         /* Note: native functions return float values in %f0 (see ABI) */
3111         /* we handle this by doing M_FLD below. (which will load the lower word into %f1) */
3112
3113 #if !defined(NDEBUG)
3114         /* But for the trace function we need to put a flt result into %f1 */
3115         if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
3116                 if (!IS_2_WORD_TYPE(md->returntype.type))
3117                         M_FLD(REG_FRESULT, REG_SP, CSTACK);
3118                 emit_verbosecall_exit(jd);
3119         }
3120 #endif
3121
3122         /* remove native stackframe info */
3123
3124         M_ADD_IMM(REG_FP, BIAS, REG_OUT0); /* datasp, like above */
3125         disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3126         M_ALD(REG_ITMP3, REG_PV_CALLEE, disp);
3127         M_JMP(REG_RA_CALLER, REG_ITMP3, REG_ZERO);
3128         M_NOP; /* XXX fill me! */
3129         M_MOV(REG_RESULT_CALLER, REG_ITMP2_XPTR);
3130
3131         /* restore float return value, int return value already in our return reg */
3132
3133         if (md->returntype.type != TYPE_VOID) {
3134                 if (IS_FLT_DBL_TYPE(md->returntype.type)) {
3135                         if (IS_2_WORD_TYPE(md->returntype.type))
3136                                 M_DLD(REG_FRESULT, REG_SP, CSTACK);
3137                         else
3138                                 M_FLD(REG_FRESULT, REG_SP, CSTACK);
3139                 }
3140         }
3141
3142         /* check for exception */
3143
3144         M_BNEZ(REG_ITMP2_XPTR, 4);          /* if no exception then return        */
3145         M_NOP;
3146
3147         M_RETURN(REG_RA_CALLEE, 8); /* implicit window restore */
3148         M_NOP;
3149 #if 0   
3150         M_RESTORE(REG_ZERO, 0, REG_ZERO);   /* restore callers window (DELAY)     */
3151
3152         M_RET(REG_RA_CALLER, 8);            /* return to caller                   */
3153         M_NOP;                              /* DELAY SLOT                         */
3154 #endif
3155
3156         /* handle exception */
3157         
3158         disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3159         M_ALD(REG_ITMP3, REG_PV, disp);     /* load asm exception handler address */
3160         M_JMP(REG_ZERO, REG_ITMP3, REG_ZERO);/* jump to asm exception handler     */
3161         M_MOV(REG_RA_CALLEE, REG_ITMP3_XPC); /* get exception address (DELAY)    */
3162
3163         /* generate patcher stubs */
3164
3165         emit_patcher_stubs(jd);
3166
3167         codegen_finish(jd);
3168
3169         return code->entrypoint;
3170 }
3171
3172 /*
3173  * These are local overrides for various environment variables in Emacs.
3174  * Please do not remove this and leave it at the end of the file, where
3175  * Emacs will automagically detect them.
3176  * ---------------------------------------------------------------------
3177  * Local variables:
3178  * mode: c
3179  * indent-tabs-mode: t
3180  * c-basic-offset: 4
3181  * tab-width: 4
3182  * End:
3183  * vim:noexpandtab:sw=4:ts=4:
3184  */