Made loging thread-safe
[cacao.git] / src / vm / jit / alpha / codegen.c
1 /* jit/alpha/codegen.c - machine code generator for alpha
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authors: Andreas Krall
29             Reinhard Grafl
30
31    $Id: codegen.c 691 2003-12-05 18:17:22Z stefan $
32
33 */
34
35
36 #include <stdio.h>
37 #include <signal.h>
38 #include "types.h"
39 #include "codegen.h"
40 #include "jit.h"
41 #include "reg.h"
42 #include "builtin.h"
43 #include "asmpart.h"
44 #include "jni.h"
45 #include "loader.h"
46 #include "tables.h"
47 #include "native.h"
48
49 /* include independent code generation stuff */
50 #include "codegen.inc"
51 #include "reg.inc"
52
53
54 /* *****************************************************************************
55
56 Datatypes and Register Allocations:
57 ----------------------------------- 
58
59 On 64-bit-machines (like the Alpha) all operands are stored in the
60 registers in a 64-bit form, even when the correspondig JavaVM  operands
61 only need 32 bits. This is done by a canonical representation:
62
63 32-bit integers are allways stored as sign-extended 64-bit values (this
64 approach is directly supported by the Alpha architecture and is very easy
65 to implement).
66
67 32-bit-floats are stored in a 64-bit doubleprecision register by simply
68 expanding the exponent and mantissa with zeroes. (also supported by the
69 architecture)
70
71
72 Stackframes:
73
74 The calling conventions and the layout of the stack is  explained in detail
75 in the documention file: calling.doc
76
77 *******************************************************************************/
78
79
80 /* register descripton - array ************************************************/
81
82 /* #define REG_RES   0         reserved register for OS or code generator     */
83 /* #define REG_RET   1         return value register                          */
84 /* #define REG_EXC   2         exception value register (only old jit)        */
85 /* #define REG_SAV   3         (callee) saved register                        */
86 /* #define REG_TMP   4         scratch temporary register (caller saved)      */
87 /* #define REG_ARG   5         argument register (caller saved)               */
88
89 /* #define REG_END   -1        last entry in tables */
90  
91 int nregdescint[] = {
92         REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
93         REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
94         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
95         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
96         REG_END };
97
98 /* for use of reserved registers, see comment above */
99         
100 int nregdescfloat[] = {
101         REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
102         REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
103         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
104         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
105         REG_END };
106
107 /* for use of reserved registers, see comment above */
108
109
110 /* parameter allocation mode */
111
112 int nreg_parammode = PARAMMODE_NUMBERED;  
113
114    /* parameter-registers will be allocated by assigning the
115       1. parameter:   int/float-reg 16
116       2. parameter:   int/float-reg 17  
117       3. parameter:   int/float-reg 18 ....
118    */
119
120
121 /* stackframe-infos ***********************************************************/
122
123 int parentargs_base; /* offset in stackframe for the parameter from the caller*/
124
125 /* -> see file 'calling.doc' */
126
127
128 /* additional functions and macros to generate code ***************************/
129
130 /* #define BlockPtrOfPC(pc)        block+block_index[pc] */
131 #define BlockPtrOfPC(pc)  ((basicblock *) iptr->target)
132
133
134 #ifdef STATISTICS
135 #define COUNT_SPILLS count_spills++
136 #else
137 #define COUNT_SPILLS
138 #endif
139
140
141 /* gen_nullptr_check(objreg) */
142
143 #ifdef SOFTNULLPTRCHECK
144 #define gen_nullptr_check(objreg) \
145         if (checknull) {\
146             M_BEQZ((objreg), 0);\
147             codegen_addxnullrefs(mcodeptr);\
148         }
149 #else
150 #define gen_nullptr_check(objreg)
151 #endif
152
153
154 /* MCODECHECK(icnt) */
155
156 #define MCODECHECK(icnt) \
157         if((mcodeptr + (icnt)) > mcodeend) mcodeptr = codegen_increase((u1*) mcodeptr)
158
159 /* M_INTMOVE:
160      generates an integer-move from register a to b.
161      if a and b are the same int-register, no code will be generated.
162 */ 
163
164 #define M_INTMOVE(a,b) if(a!=b){M_MOV(a,b);}
165
166
167 /* M_FLTMOVE:
168     generates a floating-point-move from register a to b.
169     if a and b are the same float-register, no code will be generated
170 */ 
171
172 #define M_FLTMOVE(a,b) if(a!=b){M_FMOV(a,b);}
173
174
175 /* var_to_reg_xxx:
176     this function generates code to fetch data from a pseudo-register
177     into a real register. 
178     If the pseudo-register has actually been assigned to a real 
179     register, no code will be emitted, since following operations
180     can use this register directly.
181     
182     v: pseudoregister to be fetched from
183     tempregnum: temporary register to be used if v is actually spilled to ram
184
185     return: the register number, where the operand can be found after 
186             fetching (this wil be either tempregnum or the register
187             number allready given to v)
188 */
189
190 #define var_to_reg_int(regnr,v,tempnr) { \
191         if ((v)->flags & INMEMORY) \
192                 {COUNT_SPILLS;M_LLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
193         else regnr=(v)->regoff; \
194 }
195
196
197 #define var_to_reg_flt(regnr,v,tempnr) { \
198         if ((v)->flags & INMEMORY) \
199                 {COUNT_SPILLS;M_DLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
200         else regnr=(v)->regoff; \
201 }
202
203
204 /* reg_of_var:
205     This function determines a register, to which the result of an operation
206     should go, when it is ultimatively intended to store the result in
207     pseudoregister v.
208     If v is assigned to an actual register, this register will be returned.
209     Otherwise (when v is spilled) this function returns tempregnum.
210     If not already done, regoff and flags are set in the stack location.
211 */        
212
213 static int reg_of_var(stackptr v, int tempregnum)
214 {
215         varinfo      *var;
216
217         switch (v->varkind) {
218                 case TEMPVAR:
219                         if (!(v->flags & INMEMORY))
220                                 return(v->regoff);
221                         break;
222                 case STACKVAR:
223                         var = &(interfaces[v->varnum][v->type]);
224                         v->regoff = var->regoff;
225                         if (!(var->flags & INMEMORY))
226                                 return(var->regoff);
227                         break;
228                 case LOCALVAR:
229                         var = &(locals[v->varnum][v->type]);
230                         v->regoff = var->regoff;
231                         if (!(var->flags & INMEMORY))
232                                 return(var->regoff);
233                         break;
234                 case ARGVAR:
235                         v->regoff = v->varnum;
236                         if (IS_FLT_DBL_TYPE(v->type)) {
237                                 if (v->varnum < fltreg_argnum) {
238                                         v->regoff = argfltregs[v->varnum];
239                                         return(argfltregs[v->varnum]);
240                                         }
241                                 }
242                         else
243                                 if (v->varnum < intreg_argnum) {
244                                         v->regoff = argintregs[v->varnum];
245                                         return(argintregs[v->varnum]);
246                                         }
247                         v->regoff -= intreg_argnum;
248                         break;
249                 }
250         v->flags |= INMEMORY;
251         return tempregnum;
252 }
253
254
255 /* store_reg_to_var_xxx:
256     This function generates the code to store the result of an operation
257     back into a spilled pseudo-variable.
258     If the pseudo-variable has not been spilled in the first place, this 
259     function will generate nothing.
260     
261     v ............ Pseudovariable
262     tempregnum ... Number of the temporary registers as returned by
263                    reg_of_var.
264 */      
265
266 #define store_reg_to_var_int(sptr, tempregnum) {       \
267         if ((sptr)->flags & INMEMORY) {                    \
268                 COUNT_SPILLS;                                  \
269                 M_LST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
270                 }                                              \
271         }
272
273 #define store_reg_to_var_flt(sptr, tempregnum) {       \
274         if ((sptr)->flags & INMEMORY) {                    \
275                 COUNT_SPILLS;                                  \
276                 M_DST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
277                 }                                              \
278         }
279
280
281 /* NullPointerException handlers and exception handling initialisation        */
282
283 typedef struct sigctx_struct {
284
285         long          sc_onstack;           /* sigstack state to restore          */
286         long          sc_mask;              /* signal mask to restore             */
287         long          sc_pc;                /* pc at time of signal               */
288         long          sc_ps;                /* psl to retore                      */
289         long          sc_regs[32];          /* processor regs 0 to 31             */
290         long          sc_ownedfp;           /* fp has been used                   */
291         long          sc_fpregs[32];        /* fp regs 0 to 31                    */
292         unsigned long sc_fpcr;              /* floating point control register    */
293         unsigned long sc_fp_control;        /* software fpcr                      */
294                                             /* rest is unused                     */
295         unsigned long sc_reserved1, sc_reserved2;
296         unsigned long sc_ssize;
297         char          *sc_sbase;
298         unsigned long sc_traparg_a0;
299         unsigned long sc_traparg_a1;
300         unsigned long sc_traparg_a2;
301         unsigned long sc_fp_trap_pc;
302         unsigned long sc_fp_trigger_sum;
303         unsigned long sc_fp_trigger_inst;
304         unsigned long sc_retcode[2];
305 } sigctx_struct;
306
307
308 /* NullPointerException signal handler for hardware null pointer check */
309
310 void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx)
311 {
312         sigset_t nsig;
313         int      instr;
314         long     faultaddr;
315
316         /* Reset signal handler - necessary for SysV, does no harm for BSD */
317
318         instr = *((int*)(sigctx->sc_pc));
319         faultaddr = sigctx->sc_regs[(instr >> 16) & 0x1f];
320
321         if (faultaddr == 0) {
322                 signal(sig, (void*) catch_NullPointerException); /* reinstall handler */
323                 sigemptyset(&nsig);
324                 sigaddset(&nsig, sig);
325                 sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
326                 sigctx->sc_regs[REG_ITMP1_XPTR] =
327                                             (long) proto_java_lang_NullPointerException;
328                 sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
329                 sigctx->sc_pc = (long) asm_handle_exception;
330                 return;
331                 }
332         else {
333                 faultaddr += (long) ((instr << 16) >> 16);
334                 fprintf(stderr, "faulting address: 0x%16lx\n", faultaddr);
335                 panic("Stack overflow");
336                 }
337 }
338
339
340 #ifdef __osf__
341
342 void init_exceptions(void)
343 {
344
345 #else /* Linux */
346
347 /* Linux on Digital Alpha needs an initialisation of the ieee floating point
348         control for IEEE compliant arithmetic (option -mieee of GCC). Under
349         Digital Unix this is done automatically.
350 */
351
352 #include <asm/fpu.h>
353
354 extern unsigned long ieee_get_fp_control();
355 extern void ieee_set_fp_control(unsigned long fp_control);
356
357 void init_exceptions(void)
358 {
359 /* initialize floating point control */
360
361 ieee_set_fp_control(ieee_get_fp_control()
362                     & ~IEEE_TRAP_ENABLE_INV
363                     & ~IEEE_TRAP_ENABLE_DZE
364 /*                  & ~IEEE_TRAP_ENABLE_UNF   we dont want underflow */
365                     & ~IEEE_TRAP_ENABLE_OVF);
366 #endif
367
368         /* install signal handlers we need to convert to exceptions */
369
370         if (!checknull) {
371
372 #if defined(SIGSEGV)
373                 signal(SIGSEGV, (void*) catch_NullPointerException);
374 #endif
375
376 #if defined(SIGBUS)
377                 signal(SIGBUS, (void*) catch_NullPointerException);
378 #endif
379                 }
380 }
381
382
383 /* function gen_mcode **********************************************************
384
385         generates machine code
386
387 *******************************************************************************/
388
389 #define         MethodPointer   -8
390 #define         FrameSize       -12
391 #define     IsSync          -16
392 #define     IsLeaf          -20
393 #define     IntSave         -24
394 #define     FltSave         -28
395 #define     ExTableSize     -32
396 #define     ExTableStart    -32
397
398 #define     ExEntrySize     -32
399 #define     ExStartPC       -8
400 #define     ExEndPC         -16
401 #define     ExHandlerPC     -24
402 #define     ExCatchType     -32
403
404 void codegen()
405 {
406         int  len, s1, s2, s3, d, bbs;
407         s4   a;
408         s4          *mcodeptr;
409         stackptr    src;
410         varinfo     *var;
411         basicblock  *bptr;
412         instruction *iptr;
413         xtable *ex;
414
415         {
416         int p, pa, t, l, r;
417
418         savedregs_num = (isleafmethod) ? 0 : 1;           /* space to save the RA */
419
420         /* space to save used callee saved registers */
421
422         savedregs_num += (savintregcnt - maxsavintreguse);
423         savedregs_num += (savfltregcnt - maxsavfltreguse);
424
425         parentargs_base = maxmemuse + savedregs_num;
426
427 #ifdef USE_THREADS                 /* space to save argument of monitor_enter */
428
429         if (checksync && (method->flags & ACC_SYNCHRONIZED))
430                 parentargs_base++;
431
432 #endif
433
434         /* create method header */
435
436         (void) dseg_addaddress(method);                         /* MethodPointer  */
437         (void) dseg_adds4(parentargs_base * 8);                 /* FrameSize      */
438
439 #ifdef USE_THREADS
440
441         /* IsSync contains the offset relative to the stack pointer for the
442            argument of monitor_exit used in the exception handler. Since the
443            offset could be zero and give a wrong meaning of the flag it is
444            offset by one.
445         */
446
447         if (checksync && (method->flags & ACC_SYNCHRONIZED))
448                 (void) dseg_adds4((maxmemuse + 1) * 8);             /* IsSync         */
449         else
450
451 #endif
452
453         (void) dseg_adds4(0);                                   /* IsSync         */
454                                                
455         (void) dseg_adds4(isleafmethod);                        /* IsLeaf         */
456         (void) dseg_adds4(savintregcnt - maxsavintreguse);      /* IntSave        */
457         (void) dseg_adds4(savfltregcnt - maxsavfltreguse);      /* FltSave        */
458         (void) dseg_adds4(exceptiontablelength);                /* ExTableSize    */
459
460         /* create exception table */
461
462         for (ex = extable; ex != NULL; ex = ex->down) {
463
464 #ifdef LOOP_DEBUG       
465                 if (ex->start != NULL)
466                         printf("adding start - %d - ", ex->start->debug_nr);
467                 else {
468                         printf("PANIC - start is NULL");
469                         exit(-1);
470                 }
471 #endif
472
473                 dseg_addtarget(ex->start);
474
475 #ifdef LOOP_DEBUG                       
476                 if (ex->end != NULL)
477                         printf("adding end - %d - ", ex->end->debug_nr);
478                 else {
479                         printf("PANIC - end is NULL");
480                         exit(-1);
481                 }
482 #endif
483
484                 dseg_addtarget(ex->end);
485
486 #ifdef LOOP_DEBUG               
487                 if (ex->handler != NULL)
488                         printf("adding handler - %d\n", ex->handler->debug_nr);
489                 else {
490                         printf("PANIC - handler is NULL");
491                         exit(-1);
492                 }
493 #endif
494
495                 dseg_addtarget(ex->handler);
496            
497                 (void) dseg_addaddress(ex->catchtype);
498                 }
499         
500         /* initialize mcode variables */
501         
502         mcodeptr = (s4*) mcodebase;
503         mcodeend = (s4*) (mcodebase + mcodesize);
504         MCODECHECK(128 + mparamcount);
505
506         /* create stack frame (if necessary) */
507
508         if (parentargs_base)
509                 {M_LDA (REG_SP, REG_SP, -parentargs_base * 8);}
510
511         /* save return address and used callee saved registers */
512
513         p = parentargs_base;
514         if (!isleafmethod)
515                 {p--;  M_AST (REG_RA, REG_SP, 8*p);}
516         for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
517                 {p--; M_LST (savintregs[r], REG_SP, 8 * p);}
518         for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
519                 {p--; M_DST (savfltregs[r], REG_SP, 8 * p);}
520
521         /* save monitorenter argument */
522
523 #ifdef USE_THREADS
524         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
525                 if (method->flags & ACC_STATIC) {
526                         p = dseg_addaddress (class);
527                         M_ALD(REG_ITMP1, REG_PV, p);
528                         M_AST(REG_ITMP1, REG_SP, 8 * maxmemuse);
529                         } 
530                 else {
531                         M_AST (argintregs[0], REG_SP, 8 * maxmemuse);
532                         }
533                 }                       
534 #endif
535
536         /* copy argument registers to stack and call trace function with pointer
537            to arguments on stack. ToDo: save floating point registers !!!!!!!!!
538         */
539
540         if (runverbose) {
541                 int disp;
542                 M_LDA (REG_SP, REG_SP, -(14*8));
543                 M_AST(REG_RA, REG_SP, 1*8);
544
545                 M_LST(argintregs[0], REG_SP,  2*8);
546                 M_LST(argintregs[1], REG_SP,  3*8);
547                 M_LST(argintregs[2], REG_SP,  4*8);
548                 M_LST(argintregs[3], REG_SP,  5*8);
549                 M_LST(argintregs[4], REG_SP,  6*8);
550                 M_LST(argintregs[5], REG_SP,  7*8);
551
552                 M_DST(argfltregs[0], REG_SP,  8*8);
553                 M_DST(argfltregs[1], REG_SP,  9*8);
554                 M_DST(argfltregs[2], REG_SP, 10*8);
555                 M_DST(argfltregs[3], REG_SP, 11*8);
556                 M_DST(argfltregs[4], REG_SP, 12*8);
557                 M_DST(argfltregs[5], REG_SP, 13*8);
558
559                 p = dseg_addaddress (method);
560                 M_ALD(REG_ITMP1, REG_PV, p);
561                 M_AST(REG_ITMP1, REG_SP, 0);
562                 p = dseg_addaddress ((void*) (builtin_trace_args));
563                 M_ALD(REG_PV, REG_PV, p);
564                 M_JSR(REG_RA, REG_PV);
565                 disp = -(int)((u1*) mcodeptr - mcodebase);
566                 M_LDA(REG_PV, REG_RA, disp);
567                 M_ALD(REG_RA, REG_SP, 1*8);
568
569                 M_LLD(argintregs[0], REG_SP,  2*8);
570                 M_LLD(argintregs[1], REG_SP,  3*8);
571                 M_LLD(argintregs[2], REG_SP,  4*8);
572                 M_LLD(argintregs[3], REG_SP,  5*8);
573                 M_LLD(argintregs[4], REG_SP,  6*8);
574                 M_LLD(argintregs[5], REG_SP,  7*8);
575
576                 M_DLD(argfltregs[0], REG_SP,  8*8);
577                 M_DLD(argfltregs[1], REG_SP,  9*8);
578                 M_DLD(argfltregs[2], REG_SP, 10*8);
579                 M_DLD(argfltregs[3], REG_SP, 11*8);
580                 M_DLD(argfltregs[4], REG_SP, 12*8);
581                 M_DLD(argfltregs[5], REG_SP, 13*8);
582
583                 M_LDA (REG_SP, REG_SP, 14*8);
584                 }
585
586         /* take arguments out of register or stack frame */
587
588         for (p = 0, l = 0; p < mparamcount; p++) {
589                 t = mparamtypes[p];
590                 var = &(locals[l][t]);
591                 l++;
592                 if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
593                         l++;
594                 if (var->type < 0)
595                         continue;
596                 r = var->regoff; 
597                 if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
598                         if (p < INT_ARG_CNT) {                   /* register arguments    */
599                                 if (!(var->flags & INMEMORY))        /* reg arg -> register   */
600                                         {M_INTMOVE (argintregs[p], r);}
601                                 else                                 /* reg arg -> spilled    */
602                                         M_LST (argintregs[p], REG_SP, 8 * r);
603                                 }
604                         else {                                   /* stack arguments       */
605                                 pa = p - INT_ARG_CNT;
606                                 if (!(var->flags & INMEMORY))        /* stack arg -> register */ 
607                                         M_LLD (r, REG_SP, 8 * (parentargs_base + pa));
608                                 else {                               /* stack arg -> spilled  */
609                                         M_LLD (REG_ITMP1, REG_SP, 8 * (parentargs_base + pa));
610                                         M_LST (REG_ITMP1, REG_SP, 8 * r);
611                                         }
612                                 }
613                         }
614                 else {                                       /* floating args         */   
615                         if (p < FLT_ARG_CNT) {                   /* register arguments    */
616                                 if (!(var->flags & INMEMORY))        /* reg arg -> register   */
617                                         {M_FLTMOVE (argfltregs[p], r);}
618                                 else                                             /* reg arg -> spilled    */
619                                         M_DST (argfltregs[p], REG_SP, 8 * r);
620                                 }
621                         else {                                   /* stack arguments       */
622                                 pa = p - FLT_ARG_CNT;
623                                 if (!(var->flags & INMEMORY))        /* stack-arg -> register */
624                                         M_DLD (r, REG_SP, 8 * (parentargs_base + pa) );
625                                 else {                               /* stack-arg -> spilled  */
626                                         M_DLD (REG_FTMP1, REG_SP, 8 * (parentargs_base + pa));
627                                         M_DST (REG_FTMP1, REG_SP, 8 * r);
628                                         }
629                                 }
630                         }
631                 }  /* end for */
632
633         /* call trace function */
634
635 #if 0
636         if (runverbose && !isleafmethod) {
637                 M_LDA (REG_SP, REG_SP, -8);
638                 p = dseg_addaddress (method);
639                 M_ALD(REG_ITMP1, REG_PV, p);
640                 M_AST(REG_ITMP1, REG_SP, 0);
641                 p = dseg_addaddress ((void*) (builtin_trace_args));
642                 M_ALD(REG_PV, REG_PV, p);
643                 M_JSR(REG_RA, REG_PV);
644                 M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
645                 M_LDA(REG_SP, REG_SP, 8);
646                 }
647 #endif
648
649         /* call monitorenter function */
650
651 #ifdef USE_THREADS
652         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
653                 int disp;
654                 p = dseg_addaddress ((void*) (builtin_monitorenter));
655                 M_ALD(REG_PV, REG_PV, p);
656                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
657                 M_JSR(REG_RA, REG_PV);
658                 disp = -(int)((u1*) mcodeptr - mcodebase);
659                 M_LDA(REG_PV, REG_RA, disp);
660                 }                       
661 #endif
662         }
663
664         /* end of header generation */
665
666         /* walk through all basic blocks */
667         for (/* bbs = block_count, */ bptr = block; /* --bbs >= 0 */ bptr != NULL; bptr = bptr->next) {
668
669                 bptr -> mpc = (int)((u1*) mcodeptr - mcodebase);
670
671                 if (bptr->flags >= BBREACHED) {
672
673                 /* branch resolving */
674
675                 {
676                 branchref *brefs;
677                 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
678                         gen_resolvebranch((u1*) mcodebase + brefs->branchpos, 
679                                           brefs->branchpos, bptr->mpc);
680                         }
681                 }
682
683                 /* copy interface registers to their destination */
684
685                 src = bptr->instack;
686                 len = bptr->indepth;
687                 MCODECHECK(64+len);
688                 while (src != NULL) {
689                         len--;
690                         if ((len == 0) && (bptr->type != BBTYPE_STD)) {
691                                 d = reg_of_var(src, REG_ITMP1);
692                                 M_INTMOVE(REG_ITMP1, d);
693                                 store_reg_to_var_int(src, d);
694                                 }
695                         else {
696                                 d = reg_of_var(src, REG_IFTMP);
697                                 if ((src->varkind != STACKVAR)) {
698                                         s2 = src->type;
699                                         if (IS_FLT_DBL_TYPE(s2)) {
700                                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
701                                                         s1 = interfaces[len][s2].regoff;
702                                                         M_FLTMOVE(s1,d);
703                                                         }
704                                                 else {
705                                                         M_DLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
706                                                         }
707                                                 store_reg_to_var_flt(src, d);
708                                                 }
709                                         else {
710                                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
711                                                         s1 = interfaces[len][s2].regoff;
712                                                         M_INTMOVE(s1,d);
713                                                         }
714                                                 else {
715                                                         M_LLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
716                                                         }
717                                                 store_reg_to_var_int(src, d);
718                                                 }
719                                         }
720                                 }
721                         src = src->prev;
722                         }
723
724                 /* walk through all instructions */
725                 
726                 src = bptr->instack;
727                 len = bptr->icount;
728                 for (iptr = bptr->iinstr;
729                     len > 0;
730                     src = iptr->dst, len--, iptr++) {
731
732         MCODECHECK(64);           /* an instruction usually needs < 64 words      */
733         switch (iptr->opc) {
734
735                 case ICMD_NOP:        /* ...  ==> ...                                 */
736                         break;
737
738                 case ICMD_NULLCHECKPOP: /* ..., objectref  ==> ...                    */
739
740                         var_to_reg_int(s1, src, REG_ITMP1);
741                         M_BEQZ(s1, 0);
742                         codegen_addxnullrefs(mcodeptr);
743                         break;
744
745                 /* constant operations ************************************************/
746
747 #define ICONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
748                     else{a=dseg_adds4(c);M_ILD(r,REG_PV,a);}
749
750 #define LCONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
751                     else{a=dseg_adds8(c);M_LLD(r,REG_PV,a);}
752
753                 case ICMD_ICONST:     /* ...  ==> ..., constant                       */
754                                       /* op1 = 0, val.i = constant                    */
755
756                         d = reg_of_var(iptr->dst, REG_ITMP1);
757                         ICONST(d, iptr->val.i);
758                         store_reg_to_var_int(iptr->dst, d);
759                         break;
760
761                 case ICMD_LCONST:     /* ...  ==> ..., constant                       */
762                                       /* op1 = 0, val.l = constant                    */
763
764                         d = reg_of_var(iptr->dst, REG_ITMP1);
765                         LCONST(d, iptr->val.l);
766                         store_reg_to_var_int(iptr->dst, d);
767                         break;
768
769                 case ICMD_FCONST:     /* ...  ==> ..., constant                       */
770                                       /* op1 = 0, val.f = constant                    */
771
772                         d = reg_of_var (iptr->dst, REG_FTMP1);
773                         a = dseg_addfloat (iptr->val.f);
774                         M_FLD(d, REG_PV, a);
775                         store_reg_to_var_flt (iptr->dst, d);
776                         break;
777                         
778                 case ICMD_DCONST:     /* ...  ==> ..., constant                       */
779                                       /* op1 = 0, val.d = constant                    */
780
781                         d = reg_of_var (iptr->dst, REG_FTMP1);
782                         a = dseg_adddouble (iptr->val.d);
783                         M_DLD(d, REG_PV, a);
784                         store_reg_to_var_flt (iptr->dst, d);
785                         break;
786
787                 case ICMD_ACONST:     /* ...  ==> ..., constant                       */
788                                       /* op1 = 0, val.a = constant                    */
789
790                         d = reg_of_var(iptr->dst, REG_ITMP1);
791                         if (iptr->val.a) {
792                                 a = dseg_addaddress (iptr->val.a);
793                                 M_ALD(d, REG_PV, a);
794                                 }
795                         else {
796                                 M_INTMOVE(REG_ZERO, d);
797                                 }
798                         store_reg_to_var_int(iptr->dst, d);
799                         break;
800
801
802                 /* load/store operations **********************************************/
803
804                 case ICMD_ILOAD:      /* ...  ==> ..., content of local variable      */
805                 case ICMD_LLOAD:      /* op1 = local variable                         */
806                 case ICMD_ALOAD:
807
808                         d = reg_of_var(iptr->dst, REG_ITMP1);
809                         if ((iptr->dst->varkind == LOCALVAR) &&
810                             (iptr->dst->varnum == iptr->op1))
811                                 break;
812                         var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
813                         if (var->flags & INMEMORY)
814                                 M_LLD(d, REG_SP, 8 * var->regoff);
815                         else
816                                 {M_INTMOVE(var->regoff,d);}
817                         store_reg_to_var_int(iptr->dst, d);
818                         break;
819
820                 case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
821                 case ICMD_DLOAD:      /* op1 = local variable                         */
822
823                         d = reg_of_var(iptr->dst, REG_FTMP1);
824                         if ((iptr->dst->varkind == LOCALVAR) &&
825                             (iptr->dst->varnum == iptr->op1))
826                                 break;
827                         var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
828                         if (var->flags & INMEMORY)
829                                 M_DLD(d, REG_SP, 8 * var->regoff);
830                         else
831                                 {M_FLTMOVE(var->regoff,d);}
832                         store_reg_to_var_flt(iptr->dst, d);
833                         break;
834
835
836                 case ICMD_ISTORE:     /* ..., value  ==> ...                          */
837                 case ICMD_LSTORE:     /* op1 = local variable                         */
838                 case ICMD_ASTORE:
839
840                         if ((src->varkind == LOCALVAR) &&
841                             (src->varnum == iptr->op1))
842                                 break;
843                         var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
844                         if (var->flags & INMEMORY) {
845                                 var_to_reg_int(s1, src, REG_ITMP1);
846                                 M_LST(s1, REG_SP, 8 * var->regoff);
847                                 }
848                         else {
849                                 var_to_reg_int(s1, src, var->regoff);
850                                 M_INTMOVE(s1, var->regoff);
851                                 }
852                         break;
853
854                 case ICMD_FSTORE:     /* ..., value  ==> ...                          */
855                 case ICMD_DSTORE:     /* op1 = local variable                         */
856
857                         if ((src->varkind == LOCALVAR) &&
858                             (src->varnum == iptr->op1))
859                                 break;
860                         var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
861                         if (var->flags & INMEMORY) {
862                                 var_to_reg_flt(s1, src, REG_FTMP1);
863                                 M_DST(s1, REG_SP, 8 * var->regoff);
864                                 }
865                         else {
866                                 var_to_reg_flt(s1, src, var->regoff);
867                                 M_FLTMOVE(s1, var->regoff);
868                                 }
869                         break;
870
871
872                 /* pop/dup/swap operations ********************************************/
873
874                 /* attention: double and longs are only one entry in CACAO ICMDs      */
875
876                 case ICMD_POP:        /* ..., value  ==> ...                          */
877                 case ICMD_POP2:       /* ..., value, value  ==> ...                   */
878                         break;
879
880 #define M_COPY(from,to) \
881                         d = reg_of_var(to, REG_IFTMP); \
882                         if ((from->regoff != to->regoff) || \
883                             ((from->flags ^ to->flags) & INMEMORY)) { \
884                                 if (IS_FLT_DBL_TYPE(from->type)) { \
885                                         var_to_reg_flt(s1, from, d); \
886                                         M_FLTMOVE(s1,d); \
887                                         store_reg_to_var_flt(to, d); \
888                                         }\
889                                 else { \
890                                         var_to_reg_int(s1, from, d); \
891                                         M_INTMOVE(s1,d); \
892                                         store_reg_to_var_int(to, d); \
893                                         }\
894                                 }
895
896                 case ICMD_DUP:        /* ..., a ==> ..., a, a                         */
897                         M_COPY(src, iptr->dst);
898                         break;
899
900                 case ICMD_DUP_X1:     /* ..., a, b ==> ..., b, a, b                   */
901
902                         M_COPY(src,       iptr->dst->prev->prev);
903
904                 case ICMD_DUP2:       /* ..., a, b ==> ..., a, b, a, b                */
905
906                         M_COPY(src,       iptr->dst);
907                         M_COPY(src->prev, iptr->dst->prev);
908                         break;
909
910                 case ICMD_DUP2_X1:    /* ..., a, b, c ==> ..., b, c, a, b, c          */
911
912                         M_COPY(src->prev,       iptr->dst->prev->prev->prev);
913
914                 case ICMD_DUP_X2:     /* ..., a, b, c ==> ..., c, a, b, c             */
915
916                         M_COPY(src,             iptr->dst);
917                         M_COPY(src->prev,       iptr->dst->prev);
918                         M_COPY(src->prev->prev, iptr->dst->prev->prev);
919                         M_COPY(src, iptr->dst->prev->prev->prev);
920                         break;
921
922                 case ICMD_DUP2_X2:    /* ..., a, b, c, d ==> ..., c, d, a, b, c, d    */
923
924                         M_COPY(src,                   iptr->dst);
925                         M_COPY(src->prev,             iptr->dst->prev);
926                         M_COPY(src->prev->prev,       iptr->dst->prev->prev);
927                         M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
928                         M_COPY(src,       iptr->dst->prev->prev->prev->prev);
929                         M_COPY(src->prev, iptr->dst->prev->prev->prev->prev->prev);
930                         break;
931
932                 case ICMD_SWAP:       /* ..., a, b ==> ..., b, a                      */
933
934                         M_COPY(src, iptr->dst->prev);
935                         M_COPY(src->prev, iptr->dst);
936                         break;
937
938
939                 /* integer operations *************************************************/
940
941                 case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
942
943                         var_to_reg_int(s1, src, REG_ITMP1); 
944                         d = reg_of_var(iptr->dst, REG_ITMP3);
945                         M_ISUB(REG_ZERO, s1, d);
946                         store_reg_to_var_int(iptr->dst, d);
947                         break;
948
949                 case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
950
951                         var_to_reg_int(s1, src, REG_ITMP1);
952                         d = reg_of_var(iptr->dst, REG_ITMP3);
953                         M_LSUB(REG_ZERO, s1, d);
954                         store_reg_to_var_int(iptr->dst, d);
955                         break;
956
957                 case ICMD_I2L:        /* ..., value  ==> ..., value                   */
958
959                         var_to_reg_int(s1, src, REG_ITMP1);
960                         d = reg_of_var(iptr->dst, REG_ITMP3);
961                         M_INTMOVE(s1, d);
962                         store_reg_to_var_int(iptr->dst, d);
963                         break;
964
965                 case ICMD_L2I:        /* ..., value  ==> ..., value                   */
966
967                         var_to_reg_int(s1, src, REG_ITMP1);
968                         d = reg_of_var(iptr->dst, REG_ITMP3);
969                         M_IADD(s1, REG_ZERO, d );
970                         store_reg_to_var_int(iptr->dst, d);
971                         break;
972
973                 case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
974
975                         var_to_reg_int(s1, src, REG_ITMP1);
976                         d = reg_of_var(iptr->dst, REG_ITMP3);
977                         if (has_ext_instr_set) {
978                                 M_BSEXT(s1, d);
979                                 }
980                         else {
981                                 M_SLL_IMM(s1, 56, d);
982                                 M_SRA_IMM( d, 56, d);
983                                 }
984                         store_reg_to_var_int(iptr->dst, d);
985                         break;
986
987                 case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
988
989                         var_to_reg_int(s1, src, REG_ITMP1);
990                         d = reg_of_var(iptr->dst, REG_ITMP3);
991             M_CZEXT(s1, d);
992                         store_reg_to_var_int(iptr->dst, d);
993                         break;
994
995                 case ICMD_INT2SHORT:  /* ..., value  ==> ..., value                   */
996
997                         var_to_reg_int(s1, src, REG_ITMP1);
998                         d = reg_of_var(iptr->dst, REG_ITMP3);
999                         if (has_ext_instr_set) {
1000                                 M_SSEXT(s1, d);
1001                                 }
1002                         else {
1003                                 M_SLL_IMM(s1, 48, d);
1004                                 M_SRA_IMM( d, 48, d);
1005                                 }
1006                         store_reg_to_var_int(iptr->dst, d);
1007                         break;
1008
1009
1010                 case ICMD_IADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1011
1012                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1013                         var_to_reg_int(s2, src, REG_ITMP2);
1014                         d = reg_of_var(iptr->dst, REG_ITMP3);
1015                         M_IADD(s1, s2, d);
1016                         store_reg_to_var_int(iptr->dst, d);
1017                         break;
1018
1019                 case ICMD_IADDCONST:  /* ..., value  ==> ..., value + constant        */
1020                                       /* val.i = constant                             */
1021
1022                         var_to_reg_int(s1, src, REG_ITMP1);
1023                         d = reg_of_var(iptr->dst, REG_ITMP3);
1024                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1025                                 M_IADD_IMM(s1, iptr->val.i, d);
1026                                 }
1027                         else {
1028                                 ICONST(REG_ITMP2, iptr->val.i);
1029                                 M_IADD(s1, REG_ITMP2, d);
1030                                 }
1031                         store_reg_to_var_int(iptr->dst, d);
1032                         break;
1033
1034                 case ICMD_LADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1035
1036                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1037                         var_to_reg_int(s2, src, REG_ITMP2);
1038                         d = reg_of_var(iptr->dst, REG_ITMP3);
1039                         M_LADD(s1, s2, d);
1040                         store_reg_to_var_int(iptr->dst, d);
1041                         break;
1042
1043                 case ICMD_LADDCONST:  /* ..., value  ==> ..., value + constant        */
1044                                       /* val.l = constant                             */
1045
1046                         var_to_reg_int(s1, src, REG_ITMP1);
1047                         d = reg_of_var(iptr->dst, REG_ITMP3);
1048                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1049                                 M_LADD_IMM(s1, iptr->val.l, d);
1050                                 }
1051                         else {
1052                                 LCONST(REG_ITMP2, iptr->val.l);
1053                                 M_LADD(s1, REG_ITMP2, d);
1054                                 }
1055                         store_reg_to_var_int(iptr->dst, d);
1056                         break;
1057
1058                 case ICMD_ISUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1059
1060                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1061                         var_to_reg_int(s2, src, REG_ITMP2);
1062                         d = reg_of_var(iptr->dst, REG_ITMP3);
1063                         M_ISUB(s1, s2, d);
1064                         store_reg_to_var_int(iptr->dst, d);
1065                         break;
1066
1067                 case ICMD_ISUBCONST:  /* ..., value  ==> ..., value + constant        */
1068                                       /* val.i = constant                             */
1069
1070                         var_to_reg_int(s1, src, REG_ITMP1);
1071                         d = reg_of_var(iptr->dst, REG_ITMP3);
1072                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1073                                 M_ISUB_IMM(s1, iptr->val.i, d);
1074                                 }
1075                         else {
1076                                 ICONST(REG_ITMP2, iptr->val.i);
1077                                 M_ISUB(s1, REG_ITMP2, d);
1078                                 }
1079                         store_reg_to_var_int(iptr->dst, d);
1080                         break;
1081
1082                 case ICMD_LSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1083
1084                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1085                         var_to_reg_int(s2, src, REG_ITMP2);
1086                         d = reg_of_var(iptr->dst, REG_ITMP3);
1087                         M_LSUB(s1, s2, d);
1088                         store_reg_to_var_int(iptr->dst, d);
1089                         break;
1090
1091                 case ICMD_LSUBCONST:  /* ..., value  ==> ..., value - constant        */
1092                                       /* val.l = constant                             */
1093
1094                         var_to_reg_int(s1, src, REG_ITMP1);
1095                         d = reg_of_var(iptr->dst, REG_ITMP3);
1096                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1097                                 M_LSUB_IMM(s1, iptr->val.l, d);
1098                                 }
1099                         else {
1100                                 LCONST(REG_ITMP2, iptr->val.l);
1101                                 M_LSUB(s1, REG_ITMP2, d);
1102                                 }
1103                         store_reg_to_var_int(iptr->dst, d);
1104                         break;
1105
1106                 case ICMD_IMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1107
1108                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1109                         var_to_reg_int(s2, src, REG_ITMP2);
1110                         d = reg_of_var(iptr->dst, REG_ITMP3);
1111                         M_IMUL(s1, s2, d);
1112                         store_reg_to_var_int(iptr->dst, d);
1113                         break;
1114
1115                 case ICMD_IMULCONST:  /* ..., value  ==> ..., value * constant        */
1116                                       /* val.i = constant                             */
1117
1118                         var_to_reg_int(s1, src, REG_ITMP1);
1119                         d = reg_of_var(iptr->dst, REG_ITMP3);
1120                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1121                                 M_IMUL_IMM(s1, iptr->val.i, d);
1122                                 }
1123                         else {
1124                                 ICONST(REG_ITMP2, iptr->val.i);
1125                                 M_IMUL(s1, REG_ITMP2, d);
1126                                 }
1127                         store_reg_to_var_int(iptr->dst, d);
1128                         break;
1129
1130                 case ICMD_LMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1131
1132                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1133                         var_to_reg_int(s2, src, REG_ITMP2);
1134                         d = reg_of_var(iptr->dst, REG_ITMP3);
1135                         M_LMUL (s1, s2, d);
1136                         store_reg_to_var_int(iptr->dst, d);
1137                         break;
1138
1139                 case ICMD_LMULCONST:  /* ..., value  ==> ..., value * constant        */
1140                                       /* val.l = constant                             */
1141
1142                         var_to_reg_int(s1, src, REG_ITMP1);
1143                         d = reg_of_var(iptr->dst, REG_ITMP3);
1144                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1145                                 M_LMUL_IMM(s1, iptr->val.l, d);
1146                                 }
1147                         else {
1148                                 LCONST(REG_ITMP2, iptr->val.l);
1149                                 M_LMUL(s1, REG_ITMP2, d);
1150                                 }
1151                         store_reg_to_var_int(iptr->dst, d);
1152                         break;
1153
1154                 case ICMD_IDIVPOW2:   /* ..., value  ==> ..., value << constant       */
1155                 case ICMD_LDIVPOW2:   /* val.i = constant                             */
1156                                       
1157                         var_to_reg_int(s1, src, REG_ITMP1);
1158                         d = reg_of_var(iptr->dst, REG_ITMP3);
1159                         if (iptr->val.i <= 15) {
1160                                 M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1);
1161                                 M_CMOVGE(s1, s1, REG_ITMP2);
1162                                 }
1163                         else {
1164                                 M_SRA_IMM(s1, 63, REG_ITMP2);
1165                                 M_SRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
1166                                 M_LADD(s1, REG_ITMP2, REG_ITMP2);
1167                                 }
1168                         M_SRA_IMM(REG_ITMP2, iptr->val.i, d);
1169                         store_reg_to_var_int(iptr->dst, d);
1170                         break;
1171
1172                 case ICMD_ISHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
1173
1174                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1175                         var_to_reg_int(s2, src, REG_ITMP2);
1176                         d = reg_of_var(iptr->dst, REG_ITMP3);
1177                         M_AND_IMM(s2, 0x1f, REG_ITMP3);
1178                         M_SLL(s1, REG_ITMP3, d);
1179                         M_IADD(d, REG_ZERO, d);
1180                         store_reg_to_var_int(iptr->dst, d);
1181                         break;
1182
1183                 case ICMD_ISHLCONST:  /* ..., value  ==> ..., value << constant       */
1184                                       /* val.i = constant                             */
1185
1186                         var_to_reg_int(s1, src, REG_ITMP1);
1187                         d = reg_of_var(iptr->dst, REG_ITMP3);
1188                         M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
1189                         M_IADD(d, REG_ZERO, d);
1190                         store_reg_to_var_int(iptr->dst, d);
1191                         break;
1192
1193                 case ICMD_ISHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
1194
1195                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1196                         var_to_reg_int(s2, src, REG_ITMP2);
1197                         d = reg_of_var(iptr->dst, REG_ITMP3);
1198                         M_AND_IMM(s2, 0x1f, REG_ITMP3);
1199                         M_SRA(s1, REG_ITMP3, d);
1200                         store_reg_to_var_int(iptr->dst, d);
1201                         break;
1202
1203                 case ICMD_ISHRCONST:  /* ..., value  ==> ..., value >> constant       */
1204                                       /* val.i = constant                             */
1205
1206                         var_to_reg_int(s1, src, REG_ITMP1);
1207                         d = reg_of_var(iptr->dst, REG_ITMP3);
1208                         M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
1209                         store_reg_to_var_int(iptr->dst, d);
1210                         break;
1211
1212                 case ICMD_IUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
1213
1214                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1215                         var_to_reg_int(s2, src, REG_ITMP2);
1216                         d = reg_of_var(iptr->dst, REG_ITMP3);
1217                         M_AND_IMM(s2, 0x1f, REG_ITMP2);
1218             M_IZEXT(s1, d);
1219                         M_SRL(d, REG_ITMP2, d);
1220                         M_IADD(d, REG_ZERO, d);
1221                         store_reg_to_var_int(iptr->dst, d);
1222                         break;
1223
1224                 case ICMD_IUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
1225                                       /* val.i = constant                             */
1226
1227                         var_to_reg_int(s1, src, REG_ITMP1);
1228                         d = reg_of_var(iptr->dst, REG_ITMP3);
1229             M_IZEXT(s1, d);
1230                         M_SRL_IMM(d, iptr->val.i & 0x1f, d);
1231                         M_IADD(d, REG_ZERO, d);
1232                         store_reg_to_var_int(iptr->dst, d);
1233                         break;
1234
1235                 case ICMD_LSHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
1236
1237                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1238                         var_to_reg_int(s2, src, REG_ITMP2);
1239                         d = reg_of_var(iptr->dst, REG_ITMP3);
1240                         M_SLL(s1, s2, d);
1241                         store_reg_to_var_int(iptr->dst, d);
1242                         break;
1243
1244                 case ICMD_LSHLCONST:  /* ..., value  ==> ..., value << constant       */
1245                                       /* val.i = constant                             */
1246
1247                         var_to_reg_int(s1, src, REG_ITMP1);
1248                         d = reg_of_var(iptr->dst, REG_ITMP3);
1249                         M_SLL_IMM(s1, iptr->val.i & 0x3f, d);
1250                         store_reg_to_var_int(iptr->dst, d);
1251                         break;
1252
1253                 case ICMD_LSHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
1254
1255                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1256                         var_to_reg_int(s2, src, REG_ITMP2);
1257                         d = reg_of_var(iptr->dst, REG_ITMP3);
1258                         M_SRA(s1, s2, d);
1259                         store_reg_to_var_int(iptr->dst, d);
1260                         break;
1261
1262                 case ICMD_LSHRCONST:  /* ..., value  ==> ..., value >> constant       */
1263                                       /* val.i = constant                             */
1264
1265                         var_to_reg_int(s1, src, REG_ITMP1);
1266                         d = reg_of_var(iptr->dst, REG_ITMP3);
1267                         M_SRA_IMM(s1, iptr->val.i & 0x3f, d);
1268                         store_reg_to_var_int(iptr->dst, d);
1269                         break;
1270
1271                 case ICMD_LUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
1272
1273                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1274                         var_to_reg_int(s2, src, REG_ITMP2);
1275                         d = reg_of_var(iptr->dst, REG_ITMP3);
1276                         M_SRL(s1, s2, d);
1277                         store_reg_to_var_int(iptr->dst, d);
1278                         break;
1279
1280                 case ICMD_LUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
1281                                       /* val.i = constant                             */
1282
1283                         var_to_reg_int(s1, src, REG_ITMP1);
1284                         d = reg_of_var(iptr->dst, REG_ITMP3);
1285                         M_SRL_IMM(s1, iptr->val.i & 0x3f, d);
1286                         store_reg_to_var_int(iptr->dst, d);
1287                         break;
1288
1289                 case ICMD_IAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
1290                 case ICMD_LAND:
1291
1292                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1293                         var_to_reg_int(s2, src, REG_ITMP2);
1294                         d = reg_of_var(iptr->dst, REG_ITMP3);
1295                         M_AND(s1, s2, d);
1296                         store_reg_to_var_int(iptr->dst, d);
1297                         break;
1298
1299                 case ICMD_IANDCONST:  /* ..., value  ==> ..., value & constant        */
1300                                       /* val.i = constant                             */
1301
1302                         var_to_reg_int(s1, src, REG_ITMP1);
1303                         d = reg_of_var(iptr->dst, REG_ITMP3);
1304                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1305                                 M_AND_IMM(s1, iptr->val.i, d);
1306                                 }
1307                         else if (iptr->val.i == 0xffff) {
1308                                 M_CZEXT(s1, d);
1309                                 }
1310                         else if (iptr->val.i == 0xffffff) {
1311                                 M_ZAPNOT_IMM(s1, 0x07, d);
1312                                 }
1313                         else {
1314                                 ICONST(REG_ITMP2, iptr->val.i);
1315                                 M_AND(s1, REG_ITMP2, d);
1316                                 }
1317                         store_reg_to_var_int(iptr->dst, d);
1318                         break;
1319
1320                 case ICMD_IREMPOW2:   /* ..., value  ==> ..., value % constant        */
1321                                       /* val.i = constant                             */
1322
1323                         var_to_reg_int(s1, src, REG_ITMP1);
1324                         d = reg_of_var(iptr->dst, REG_ITMP3);
1325                         if (s1 == d) {
1326                                 M_MOV(s1, REG_ITMP1);
1327                                 s1 = REG_ITMP1;
1328                                 }
1329                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1330                                 M_AND_IMM(s1, iptr->val.i, d);
1331                                 M_BGEZ(s1, 3);
1332                                 M_ISUB(REG_ZERO, s1, d);
1333                                 M_AND_IMM(d, iptr->val.i, d);
1334                                 }
1335                         else if (iptr->val.i == 0xffff) {
1336                                 M_CZEXT(s1, d);
1337                                 M_BGEZ(s1, 3);
1338                                 M_ISUB(REG_ZERO, s1, d);
1339                                 M_CZEXT(d, d);
1340                                 }
1341                         else if (iptr->val.i == 0xffffff) {
1342                                 M_ZAPNOT_IMM(s1, 0x07, d);
1343                                 M_BGEZ(s1, 3);
1344                                 M_ISUB(REG_ZERO, s1, d);
1345                                 M_ZAPNOT_IMM(d, 0x07, d);
1346                                 }
1347                         else {
1348                                 ICONST(REG_ITMP2, iptr->val.i);
1349                                 M_AND(s1, REG_ITMP2, d);
1350                                 M_BGEZ(s1, 3);
1351                                 M_ISUB(REG_ZERO, s1, d);
1352                                 M_AND(d, REG_ITMP2, d);
1353                                 }
1354                         M_ISUB(REG_ZERO, d, d);
1355                         store_reg_to_var_int(iptr->dst, d);
1356                         break;
1357
1358                 case ICMD_IREM0X10001:  /* ..., value  ==> ..., value % 0x100001      */
1359                 
1360 /*          b = value & 0xffff;
1361                         a = value >> 16;
1362                         a = ((b - a) & 0xffff) + (b < a);
1363 */
1364                         var_to_reg_int(s1, src, REG_ITMP1);
1365                         d = reg_of_var(iptr->dst, REG_ITMP3);
1366                         if (s1 == d) {
1367                                 M_MOV(s1, REG_ITMP3);
1368                                 s1 = REG_ITMP3;
1369                                 }
1370                         M_BLTZ(s1, 7);
1371             M_CZEXT(s1, REG_ITMP2);
1372                         M_SRA_IMM(s1, 16, d);
1373                         M_CMPLT(REG_ITMP2, d, REG_ITMP1);
1374                         M_ISUB(REG_ITMP2, d, d);
1375             M_CZEXT(d, d);
1376                         M_IADD(d, REG_ITMP1, d);
1377                         M_BR(11 + (s1 == REG_ITMP1));
1378                         M_ISUB(REG_ZERO, s1, REG_ITMP1);
1379             M_CZEXT(REG_ITMP1, REG_ITMP2);
1380                         M_SRA_IMM(REG_ITMP1, 16, d);
1381                         M_CMPLT(REG_ITMP2, d, REG_ITMP1);
1382                         M_ISUB(REG_ITMP2, d, d);
1383             M_CZEXT(d, d);
1384                         M_IADD(d, REG_ITMP1, d);
1385                         M_ISUB(REG_ZERO, d, d);
1386                         if (s1 == REG_ITMP1) {
1387                                 var_to_reg_int(s1, src, REG_ITMP1);
1388                                 }
1389                         M_SLL_IMM(s1, 33, REG_ITMP2);
1390                         M_CMPEQ(REG_ITMP2, REG_ZERO, REG_ITMP2);
1391                         M_ISUB(d, REG_ITMP2, d);
1392                         store_reg_to_var_int(iptr->dst, d);
1393                         break;
1394
1395                 case ICMD_LANDCONST:  /* ..., value  ==> ..., value & constant        */
1396                                       /* val.l = constant                             */
1397
1398                         var_to_reg_int(s1, src, REG_ITMP1);
1399                         d = reg_of_var(iptr->dst, REG_ITMP3);
1400                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1401                                 M_AND_IMM(s1, iptr->val.l, d);
1402                                 }
1403                         else if (iptr->val.l == 0xffffL) {
1404                                 M_CZEXT(s1, d);
1405                                 }
1406                         else if (iptr->val.l == 0xffffffL) {
1407                                 M_ZAPNOT_IMM(s1, 0x07, d);
1408                                 }
1409                         else if (iptr->val.l == 0xffffffffL) {
1410                                 M_IZEXT(s1, d);
1411                                 }
1412                         else if (iptr->val.l == 0xffffffffffL) {
1413                                 M_ZAPNOT_IMM(s1, 0x1f, d);
1414                                 }
1415                         else if (iptr->val.l == 0xffffffffffffL) {
1416                                 M_ZAPNOT_IMM(s1, 0x3f, d);
1417                                 }
1418                         else if (iptr->val.l == 0xffffffffffffffL) {
1419                                 M_ZAPNOT_IMM(s1, 0x7f, d);
1420                                 }
1421                         else {
1422                                 LCONST(REG_ITMP2, iptr->val.l);
1423                                 M_AND(s1, REG_ITMP2, d);
1424                                 }
1425                         store_reg_to_var_int(iptr->dst, d);
1426                         break;
1427
1428                 case ICMD_LREMPOW2:   /* ..., value  ==> ..., value % constant        */
1429                                       /* val.l = constant                             */
1430
1431                         var_to_reg_int(s1, src, REG_ITMP1);
1432                         d = reg_of_var(iptr->dst, REG_ITMP3);
1433                         if (s1 == d) {
1434                                 M_MOV(s1, REG_ITMP1);
1435                                 s1 = REG_ITMP1;
1436                                 }
1437                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1438                                 M_AND_IMM(s1, iptr->val.l, d);
1439                                 M_BGEZ(s1, 3);
1440                                 M_LSUB(REG_ZERO, s1, d);
1441                                 M_AND_IMM(d, iptr->val.l, d);
1442                                 }
1443                         else if (iptr->val.l == 0xffffL) {
1444                                 M_CZEXT(s1, d);
1445                                 M_BGEZ(s1, 3);
1446                                 M_LSUB(REG_ZERO, s1, d);
1447                                 M_CZEXT(d, d);
1448                                 }
1449                         else if (iptr->val.l == 0xffffffL) {
1450                                 M_ZAPNOT_IMM(s1, 0x07, d);
1451                                 M_BGEZ(s1, 3);
1452                                 M_LSUB(REG_ZERO, s1, d);
1453                                 M_ZAPNOT_IMM(d, 0x07, d);
1454                                 }
1455                         else if (iptr->val.l == 0xffffffffL) {
1456                                 M_IZEXT(s1, d);
1457                                 M_BGEZ(s1, 3);
1458                                 M_LSUB(REG_ZERO, s1, d);
1459                                 M_IZEXT(d, d);
1460                                 }
1461                         else if (iptr->val.l == 0xffffffffffL) {
1462                                 M_ZAPNOT_IMM(s1, 0x1f, d);
1463                                 M_BGEZ(s1, 3);
1464                                 M_LSUB(REG_ZERO, s1, d);
1465                                 M_ZAPNOT_IMM(d, 0x1f, d);
1466                                 }
1467                         else if (iptr->val.l == 0xffffffffffffL) {
1468                                 M_ZAPNOT_IMM(s1, 0x3f, d);
1469                                 M_BGEZ(s1, 3);
1470                                 M_LSUB(REG_ZERO, s1, d);
1471                                 M_ZAPNOT_IMM(d, 0x3f, d);
1472                                 }
1473                         else if (iptr->val.l == 0xffffffffffffffL) {
1474                                 M_ZAPNOT_IMM(s1, 0x7f, d);
1475                                 M_BGEZ(s1, 3);
1476                                 M_LSUB(REG_ZERO, s1, d);
1477                                 M_ZAPNOT_IMM(d, 0x7f, d);
1478                                 }
1479                         else {
1480                                 LCONST(REG_ITMP2, iptr->val.l);
1481                                 M_AND(s1, REG_ITMP2, d);
1482                                 M_BGEZ(s1, 3);
1483                                 M_LSUB(REG_ZERO, s1, d);
1484                                 M_AND(d, REG_ITMP2, d);
1485                                 }
1486                         M_LSUB(REG_ZERO, d, d);
1487                         store_reg_to_var_int(iptr->dst, d);
1488                         break;
1489
1490                 case ICMD_LREM0X10001:/* ..., value  ==> ..., value % 0x10001         */
1491
1492                         var_to_reg_int(s1, src, REG_ITMP1);
1493                         d = reg_of_var(iptr->dst, REG_ITMP3);
1494                         if (s1 == d) {
1495                                 M_MOV(s1, REG_ITMP3);
1496                                 s1 = REG_ITMP3;
1497                                 }
1498                         M_CZEXT(s1, REG_ITMP2);
1499                         M_SRA_IMM(s1, 16, d);
1500                         M_CMPLT(REG_ITMP2, d, REG_ITMP1);
1501                         M_LSUB(REG_ITMP2, d, d);
1502             M_CZEXT(d, d);
1503                         M_LADD(d, REG_ITMP1, d);
1504                         M_LDA(REG_ITMP2, REG_ZERO, -1);
1505                         M_SRL_IMM(REG_ITMP2, 33, REG_ITMP2);
1506                         if (s1 == REG_ITMP1) {
1507                                 var_to_reg_int(s1, src, REG_ITMP1);
1508                                 }
1509                         M_CMPULT(s1, REG_ITMP2, REG_ITMP2);
1510                         M_BNEZ(REG_ITMP2, 11);
1511                         M_LDA(d, REG_ZERO, -257);
1512                         M_ZAPNOT_IMM(d, 0xcd, d);
1513                         M_LSUB(REG_ZERO, s1, REG_ITMP2);
1514                         M_CMOVGE(s1, s1, REG_ITMP2);
1515                         M_UMULH(REG_ITMP2, d, REG_ITMP2);
1516                         M_SRL_IMM(REG_ITMP2, 16, REG_ITMP2);
1517                         M_LSUB(REG_ZERO, REG_ITMP2, d);
1518                         M_CMOVGE(s1, REG_ITMP2, d);
1519                         M_SLL_IMM(d, 16, REG_ITMP2);
1520                         M_LADD(d, REG_ITMP2, d);
1521                         M_LSUB(s1, d, d);
1522                         store_reg_to_var_int(iptr->dst, d);
1523                         break;
1524
1525                 case ICMD_IOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
1526                 case ICMD_LOR:
1527
1528                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1529                         var_to_reg_int(s2, src, REG_ITMP2);
1530                         d = reg_of_var(iptr->dst, REG_ITMP3);
1531                         M_OR( s1,s2, d);
1532                         store_reg_to_var_int(iptr->dst, d);
1533                         break;
1534
1535                 case ICMD_IORCONST:   /* ..., value  ==> ..., value | constant        */
1536                                       /* val.i = constant                             */
1537
1538                         var_to_reg_int(s1, src, REG_ITMP1);
1539                         d = reg_of_var(iptr->dst, REG_ITMP3);
1540                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1541                                 M_OR_IMM(s1, iptr->val.i, d);
1542                                 }
1543                         else {
1544                                 ICONST(REG_ITMP2, iptr->val.i);
1545                                 M_OR(s1, REG_ITMP2, d);
1546                                 }
1547                         store_reg_to_var_int(iptr->dst, d);
1548                         break;
1549
1550                 case ICMD_LORCONST:   /* ..., value  ==> ..., value | constant        */
1551                                       /* val.l = constant                             */
1552
1553                         var_to_reg_int(s1, src, REG_ITMP1);
1554                         d = reg_of_var(iptr->dst, REG_ITMP3);
1555                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1556                                 M_OR_IMM(s1, iptr->val.l, d);
1557                                 }
1558                         else {
1559                                 LCONST(REG_ITMP2, iptr->val.l);
1560                                 M_OR(s1, REG_ITMP2, d);
1561                                 }
1562                         store_reg_to_var_int(iptr->dst, d);
1563                         break;
1564
1565                 case ICMD_IXOR:       /* ..., val1, val2  ==> ..., val1 ^ val2        */
1566                 case ICMD_LXOR:
1567
1568                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1569                         var_to_reg_int(s2, src, REG_ITMP2);
1570                         d = reg_of_var(iptr->dst, REG_ITMP3);
1571                         M_XOR(s1, s2, d);
1572                         store_reg_to_var_int(iptr->dst, d);
1573                         break;
1574
1575                 case ICMD_IXORCONST:  /* ..., value  ==> ..., value ^ constant        */
1576                                       /* val.i = constant                             */
1577
1578                         var_to_reg_int(s1, src, REG_ITMP1);
1579                         d = reg_of_var(iptr->dst, REG_ITMP3);
1580                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1581                                 M_XOR_IMM(s1, iptr->val.i, d);
1582                                 }
1583                         else {
1584                                 ICONST(REG_ITMP2, iptr->val.i);
1585                                 M_XOR(s1, REG_ITMP2, d);
1586                                 }
1587                         store_reg_to_var_int(iptr->dst, d);
1588                         break;
1589
1590                 case ICMD_LXORCONST:  /* ..., value  ==> ..., value ^ constant        */
1591                                       /* val.l = constant                             */
1592
1593                         var_to_reg_int(s1, src, REG_ITMP1);
1594                         d = reg_of_var(iptr->dst, REG_ITMP3);
1595                         if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
1596                                 M_XOR_IMM(s1, iptr->val.l, d);
1597                                 }
1598                         else {
1599                                 LCONST(REG_ITMP2, iptr->val.l);
1600                                 M_XOR(s1, REG_ITMP2, d);
1601                                 }
1602                         store_reg_to_var_int(iptr->dst, d);
1603                         break;
1604
1605
1606                 case ICMD_LCMP:       /* ..., val1, val2  ==> ..., val1 cmp val2      */
1607
1608                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1609                         var_to_reg_int(s2, src, REG_ITMP2);
1610                         d = reg_of_var(iptr->dst, REG_ITMP3);
1611                         M_CMPLT(s1, s2, REG_ITMP3);
1612                         M_CMPLT(s2, s1, REG_ITMP1);
1613                         M_LSUB (REG_ITMP1, REG_ITMP3, d);
1614                         store_reg_to_var_int(iptr->dst, d);
1615                         break;
1616
1617
1618                 case ICMD_IINC:       /* ..., value  ==> ..., value + constant        */
1619                                       /* op1 = variable, val.i = constant             */
1620
1621                         var = &(locals[iptr->op1][TYPE_INT]);
1622                         if (var->flags & INMEMORY) {
1623                                 s1 = REG_ITMP1;
1624                                 M_LLD(s1, REG_SP, 8 * var->regoff);
1625                                 }
1626                         else
1627                                 s1 = var->regoff;
1628                         if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
1629                                 M_IADD_IMM(s1, iptr->val.i, s1);
1630                                 }
1631                         else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
1632                                 M_ISUB_IMM(s1, (-iptr->val.i), s1);
1633                                 }
1634                         else {
1635                                 M_LDA (s1, s1, iptr->val.i);
1636                                 M_IADD(s1, REG_ZERO, s1);
1637                                 }
1638                         if (var->flags & INMEMORY)
1639                                 M_LST(s1, REG_SP, 8 * var->regoff);
1640                         break;
1641
1642
1643                 /* floating operations ************************************************/
1644
1645                 case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
1646
1647                         var_to_reg_flt(s1, src, REG_FTMP1);
1648                         d = reg_of_var(iptr->dst, REG_FTMP3);
1649                         M_FMOVN(s1, d);
1650                         store_reg_to_var_flt(iptr->dst, d);
1651                         break;
1652
1653                 case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
1654
1655                         var_to_reg_flt(s1, src, REG_FTMP1);
1656                         d = reg_of_var(iptr->dst, REG_FTMP3);
1657                         M_FMOVN(s1, d);
1658                         store_reg_to_var_flt(iptr->dst, d);
1659                         break;
1660
1661                 case ICMD_FADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1662
1663                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1664                         var_to_reg_flt(s2, src, REG_FTMP2);
1665                         d = reg_of_var(iptr->dst, REG_FTMP3);
1666                         if (opt_noieee) {
1667                                 M_FADD(s1, s2, d);
1668                                 }
1669                         else {
1670                                 if (d == s1 || d == s2) {
1671                                         M_FADDS(s1, s2, REG_FTMP3);
1672                                         M_TRAPB;
1673                                         M_FMOV(REG_FTMP3, d);
1674                                         }
1675                                 else {
1676                                         M_FADDS(s1, s2, d);
1677                                         M_TRAPB;
1678                                         }
1679                                 }
1680                         store_reg_to_var_flt(iptr->dst, d);
1681                         break;
1682
1683                 case ICMD_DADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1684
1685                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1686                         var_to_reg_flt(s2, src, REG_FTMP2);
1687                         d = reg_of_var(iptr->dst, REG_FTMP3);
1688                         if (opt_noieee) {
1689                                 M_DADD(s1, s2, d);
1690                                 }
1691                         else {
1692                                 if (d == s1 || d == s2) {
1693                                         M_DADDS(s1, s2, REG_FTMP3);
1694                                         M_TRAPB;
1695                                         M_FMOV(REG_FTMP3, d);
1696                                         }
1697                                 else {
1698                                         M_DADDS(s1, s2, d);
1699                                         M_TRAPB;
1700                                         }
1701                                 }
1702                         store_reg_to_var_flt(iptr->dst, d);
1703                         break;
1704
1705                 case ICMD_FSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1706
1707                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1708                         var_to_reg_flt(s2, src, REG_FTMP2);
1709                         d = reg_of_var(iptr->dst, REG_FTMP3);
1710                         if (opt_noieee) {
1711                                 M_FSUB(s1, s2, d);
1712                                 }
1713                         else {
1714                                 if (d == s1 || d == s2) {
1715                                         M_FSUBS(s1, s2, REG_FTMP3);
1716                                         M_TRAPB;
1717                                         M_FMOV(REG_FTMP3, d);
1718                                         }
1719                                 else {
1720                                         M_FSUBS(s1, s2, d);
1721                                         M_TRAPB;
1722                                         }
1723                                 }
1724                         store_reg_to_var_flt(iptr->dst, d);
1725                         break;
1726
1727                 case ICMD_DSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1728
1729                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1730                         var_to_reg_flt(s2, src, REG_FTMP2);
1731                         d = reg_of_var(iptr->dst, REG_FTMP3);
1732                         if (opt_noieee) {
1733                                 M_DSUB(s1, s2, d);
1734                                 }
1735                         else {
1736                                 if (d == s1 || d == s2) {
1737                                         M_DSUBS(s1, s2, REG_FTMP3);
1738                                         M_TRAPB;
1739                                         M_FMOV(REG_FTMP3, d);
1740                                         }
1741                                 else {
1742                                         M_DSUBS(s1, s2, d);
1743                                         M_TRAPB;
1744                                         }
1745                                 }
1746                         store_reg_to_var_flt(iptr->dst, d);
1747                         break;
1748
1749                 case ICMD_FMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1750
1751                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1752                         var_to_reg_flt(s2, src, REG_FTMP2);
1753                         d = reg_of_var(iptr->dst, REG_FTMP3);
1754                         if (opt_noieee) {
1755                                 M_FMUL(s1, s2, d);
1756                                 }
1757                         else {
1758                                 if (d == s1 || d == s2) {
1759                                         M_FMULS(s1, s2, REG_FTMP3);
1760                                         M_TRAPB;
1761                                         M_FMOV(REG_FTMP3, d);
1762                                         }
1763                                 else {
1764                                         M_FMULS(s1, s2, d);
1765                                         M_TRAPB;
1766                                         }
1767                                 }
1768                         store_reg_to_var_flt(iptr->dst, d);
1769                         break;
1770
1771                 case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2        */
1772
1773                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1774                         var_to_reg_flt(s2, src, REG_FTMP2);
1775                         d = reg_of_var(iptr->dst, REG_FTMP3);
1776                         if (opt_noieee) {
1777                                 M_DMUL(s1, s2, d);
1778                                 }
1779                         else {
1780                                 if (d == s1 || d == s2) {
1781                                         M_DMULS(s1, s2, REG_FTMP3);
1782                                         M_TRAPB;
1783                                         M_FMOV(REG_FTMP3, d);
1784                                         }
1785                                 else {
1786                                         M_DMULS(s1, s2, d);
1787                                         M_TRAPB;
1788                                         }
1789                                 }
1790                         store_reg_to_var_flt(iptr->dst, d);
1791                         break;
1792
1793                 case ICMD_FDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1794
1795                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1796                         var_to_reg_flt(s2, src, REG_FTMP2);
1797                         d = reg_of_var(iptr->dst, REG_FTMP3);
1798                         if (opt_noieee) {
1799                                 M_FDIV(s1, s2, d);
1800                                 }
1801                         else {
1802                                 if (d == s1 || d == s2) {
1803                                         M_FDIVS(s1, s2, REG_FTMP3);
1804                                         M_TRAPB;
1805                                         M_FMOV(REG_FTMP3, d);
1806                                         }
1807                                 else {
1808                                         M_FDIVS(s1, s2, d);
1809                                         M_TRAPB;
1810                                         }
1811                                 }
1812                         store_reg_to_var_flt(iptr->dst, d);
1813                         break;
1814
1815                 case ICMD_DDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1816
1817                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1818                         var_to_reg_flt(s2, src, REG_FTMP2);
1819                         d = reg_of_var(iptr->dst, REG_FTMP3);
1820                         if (opt_noieee) {
1821                                 M_DDIV(s1, s2, d);
1822                                 }
1823                         else {
1824                                 if (d == s1 || d == s2) {
1825                                         M_DDIVS(s1, s2, REG_FTMP3);
1826                                         M_TRAPB;
1827                                         M_FMOV(REG_FTMP3, d);
1828                                         }
1829                                 else {
1830                                         M_DDIVS(s1, s2, d);
1831                                         M_TRAPB;
1832                                         }
1833                                 }
1834                         store_reg_to_var_flt(iptr->dst, d);
1835                         break;
1836                 
1837                 case ICMD_I2F:       /* ..., value  ==> ..., (float) value            */
1838                 case ICMD_L2F:
1839                         var_to_reg_int(s1, src, REG_ITMP1);
1840                         d = reg_of_var(iptr->dst, REG_FTMP3);
1841                         a = dseg_adddouble(0.0);
1842                         M_LST (s1, REG_PV, a);
1843                         M_DLD (d, REG_PV, a);
1844                         M_CVTLF(d, d);
1845                         store_reg_to_var_flt(iptr->dst, d);
1846                         break;
1847
1848                 case ICMD_I2D:       /* ..., value  ==> ..., (double) value           */
1849                 case ICMD_L2D:
1850                         var_to_reg_int(s1, src, REG_ITMP1);
1851                         d = reg_of_var(iptr->dst, REG_FTMP3);
1852                         a = dseg_adddouble(0.0);
1853                         M_LST (s1, REG_PV, a);
1854                         M_DLD (d, REG_PV, a);
1855                         M_CVTLD(d, d);
1856                         store_reg_to_var_flt(iptr->dst, d);
1857                         break;
1858                         
1859                 case ICMD_F2I:       /* ..., value  ==> ..., (int) value              */
1860                 case ICMD_D2I:
1861                         var_to_reg_flt(s1, src, REG_FTMP1);
1862                         d = reg_of_var(iptr->dst, REG_ITMP3);
1863                         a = dseg_adddouble(0.0);
1864                         M_CVTDL_C(s1, REG_FTMP2);
1865                         M_CVTLI(REG_FTMP2, REG_FTMP3);
1866                         M_DST (REG_FTMP3, REG_PV, a);
1867                         M_ILD (d, REG_PV, a);
1868                         store_reg_to_var_int(iptr->dst, d);
1869                         break;
1870                 
1871                 case ICMD_F2L:       /* ..., value  ==> ..., (long) value             */
1872                 case ICMD_D2L:
1873                         var_to_reg_flt(s1, src, REG_FTMP1);
1874                         d = reg_of_var(iptr->dst, REG_ITMP3);
1875                         a = dseg_adddouble(0.0);
1876                         M_CVTDL_C(s1, REG_FTMP2);
1877                         M_DST (REG_FTMP2, REG_PV, a);
1878                         M_LLD (d, REG_PV, a);
1879                         store_reg_to_var_int(iptr->dst, d);
1880                         break;
1881
1882                 case ICMD_F2D:       /* ..., value  ==> ..., (double) value           */
1883
1884                         var_to_reg_flt(s1, src, REG_FTMP1);
1885                         d = reg_of_var(iptr->dst, REG_FTMP3);
1886                         M_FLTMOVE(s1, d);
1887                         store_reg_to_var_flt(iptr->dst, d);
1888                         break;
1889                                         
1890                 case ICMD_D2F:       /* ..., value  ==> ..., (double) value           */
1891
1892                         var_to_reg_flt(s1, src, REG_FTMP1);
1893                         d = reg_of_var(iptr->dst, REG_FTMP3);
1894                         if (opt_noieee) {
1895                                 M_CVTDF(s1, d);
1896                                 }
1897                         else {
1898                                 M_CVTDFS(s1, d);
1899                                 M_TRAPB;
1900                                 }
1901                         store_reg_to_var_flt(iptr->dst, d);
1902                         break;
1903                 
1904                 case ICMD_FCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
1905                 case ICMD_DCMPL:
1906                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1907                         var_to_reg_flt(s2, src, REG_FTMP2);
1908                         d = reg_of_var(iptr->dst, REG_ITMP3);
1909                         if (opt_noieee) {
1910                                 M_LSUB_IMM(REG_ZERO, 1, d);
1911                                 M_FCMPEQ(s1, s2, REG_FTMP3);
1912                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instructions */
1913                                 M_CLR   (d);
1914                                 M_FCMPLT(s2, s1, REG_FTMP3);
1915                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1916                                 M_LADD_IMM(REG_ZERO, 1, d);
1917                                 }
1918                         else {
1919                                 M_LSUB_IMM(REG_ZERO, 1, d);
1920                                 M_FCMPEQS(s1, s2, REG_FTMP3);
1921                                 M_TRAPB;
1922                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instructions */
1923                                 M_CLR   (d);
1924                                 M_FCMPLTS(s2, s1, REG_FTMP3);
1925                                 M_TRAPB;
1926                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1927                                 M_LADD_IMM(REG_ZERO, 1, d);
1928                                 }
1929                         store_reg_to_var_int(iptr->dst, d);
1930                         break;
1931                         
1932                 case ICMD_FCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
1933                 case ICMD_DCMPG:
1934                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1935                         var_to_reg_flt(s2, src, REG_FTMP2);
1936                         d = reg_of_var(iptr->dst, REG_ITMP3);
1937                         if (opt_noieee) {
1938                                 M_LADD_IMM(REG_ZERO, 1, d);
1939                                 M_FCMPEQ(s1, s2, REG_FTMP3);
1940                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1941                                 M_CLR   (d);
1942                                 M_FCMPLT(s1, s2, REG_FTMP3);
1943                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1944                                 M_LSUB_IMM(REG_ZERO, 1, d);
1945                                 }
1946                         else {
1947                                 M_LADD_IMM(REG_ZERO, 1, d);
1948                                 M_FCMPEQS(s1, s2, REG_FTMP3);
1949                                 M_TRAPB;
1950                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1951                                 M_CLR   (d);
1952                                 M_FCMPLTS(s1, s2, REG_FTMP3);
1953                                 M_TRAPB;
1954                                 M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
1955                                 M_LSUB_IMM(REG_ZERO, 1, d);
1956                                 }
1957                         store_reg_to_var_int(iptr->dst, d);
1958                         break;
1959
1960
1961                 /* memory operations **************************************************/
1962
1963                         /* #define gen_bound_check \
1964                         if (checkbounds) {\
1965                                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
1966                                 M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
1967                                 M_BEQZ(REG_ITMP3, 0);\
1968                                 codegen_addxboundrefs(mcodeptr);\
1969                                 }
1970                         */
1971
1972 #define gen_bound_check \
1973             if (checkbounds) { \
1974                                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
1975                                 M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
1976                                 M_BEQZ(REG_ITMP3, 0);\
1977                                 codegen_addxboundrefs(mcodeptr); \
1978                 }
1979
1980                 case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
1981
1982                         var_to_reg_int(s1, src, REG_ITMP1);
1983                         d = reg_of_var(iptr->dst, REG_ITMP3);
1984                         gen_nullptr_check(s1);
1985                         M_ILD(d, s1, OFFSET(java_arrayheader, size));
1986                         store_reg_to_var_int(iptr->dst, d);
1987                         break;
1988
1989                 case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
1990
1991                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1992                         var_to_reg_int(s2, src, REG_ITMP2);
1993                         d = reg_of_var(iptr->dst, REG_ITMP3);
1994                         if (iptr->op1 == 0) {
1995                                 gen_nullptr_check(s1);
1996                                 gen_bound_check;
1997                                 }
1998                         M_SAADDQ(s2, s1, REG_ITMP1);
1999                         M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
2000                         store_reg_to_var_int(iptr->dst, d);
2001                         break;
2002
2003                 case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
2004
2005                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2006                         var_to_reg_int(s2, src, REG_ITMP2);
2007                         d = reg_of_var(iptr->dst, REG_ITMP3);
2008                         if (iptr->op1 == 0) {
2009                                 gen_nullptr_check(s1);
2010                                 gen_bound_check;
2011                                 }
2012                         M_S8ADDQ(s2, s1, REG_ITMP1);
2013                         M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
2014                         store_reg_to_var_int(iptr->dst, d);
2015                         break;
2016
2017                 case ICMD_IALOAD:     /* ..., arrayref, index  ==> ..., value         */
2018
2019                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2020                         var_to_reg_int(s2, src, REG_ITMP2);
2021                         d = reg_of_var(iptr->dst, REG_ITMP3);
2022                         if (iptr->op1 == 0) {
2023                                 gen_nullptr_check(s1);
2024                                 gen_bound_check;
2025                                 }
2026                   
2027                         M_S4ADDQ(s2, s1, REG_ITMP1);
2028                         M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
2029                         store_reg_to_var_int(iptr->dst, d);
2030                         break;
2031
2032                 case ICMD_FALOAD:     /* ..., arrayref, index  ==> ..., value         */
2033
2034                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2035                         var_to_reg_int(s2, src, REG_ITMP2);
2036                         d = reg_of_var(iptr->dst, REG_FTMP3);
2037                         if (iptr->op1 == 0) {
2038                                 gen_nullptr_check(s1);
2039                                 gen_bound_check;
2040                                 }
2041                         M_S4ADDQ(s2, s1, REG_ITMP1);
2042                         M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
2043                         store_reg_to_var_flt(iptr->dst, d);
2044                         break;
2045
2046                 case ICMD_DALOAD:     /* ..., arrayref, index  ==> ..., value         */
2047
2048                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2049                         var_to_reg_int(s2, src, REG_ITMP2);
2050                         d = reg_of_var(iptr->dst, REG_FTMP3);
2051                         if (iptr->op1 == 0) {
2052                                 gen_nullptr_check(s1);
2053                                 gen_bound_check;
2054                                 }
2055                         M_S8ADDQ(s2, s1, REG_ITMP1);
2056                         M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
2057                         store_reg_to_var_flt(iptr->dst, d);
2058                         break;
2059
2060                 case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
2061
2062                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2063                         var_to_reg_int(s2, src, REG_ITMP2);
2064                         d = reg_of_var(iptr->dst, REG_ITMP3);
2065                         if (iptr->op1 == 0) {
2066                                 gen_nullptr_check(s1);
2067                                 gen_bound_check;
2068                                 }
2069                         if (has_ext_instr_set) {
2070                                 M_LADD(s2, s1, REG_ITMP1);
2071                                 M_LADD(s2, REG_ITMP1, REG_ITMP1);
2072                                 M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
2073                                 }
2074                         else {
2075                                 M_LADD (s2, s1, REG_ITMP1);
2076                                 M_LADD (s2, REG_ITMP1, REG_ITMP1);
2077                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
2078                                 M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
2079                                 M_EXTWL(REG_ITMP2, REG_ITMP1, d);
2080                                 }
2081                         store_reg_to_var_int(iptr->dst, d);
2082                         break;                  
2083
2084                 case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
2085
2086                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2087                         var_to_reg_int(s2, src, REG_ITMP2);
2088                         d = reg_of_var(iptr->dst, REG_ITMP3);
2089                         if (iptr->op1 == 0) {
2090                                 gen_nullptr_check(s1);
2091                                 gen_bound_check;
2092                                 }
2093                         if (has_ext_instr_set) {
2094                                 M_LADD(s2, s1, REG_ITMP1);
2095                                 M_LADD(s2, REG_ITMP1, REG_ITMP1);
2096                                 M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
2097                                 M_SSEXT(d, d);
2098                                 }
2099                         else {
2100                                 M_LADD(s2, s1, REG_ITMP1);
2101                                 M_LADD(s2, REG_ITMP1, REG_ITMP1);
2102                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
2103                                 M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
2104                                 M_EXTQH(REG_ITMP2, REG_ITMP1, d);
2105                                 M_SRA_IMM(d, 48, d);
2106                                 }
2107                         store_reg_to_var_int(iptr->dst, d);
2108                         break;
2109
2110                 case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
2111
2112                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2113                         var_to_reg_int(s2, src, REG_ITMP2);
2114                         d = reg_of_var(iptr->dst, REG_ITMP3);
2115                         if (iptr->op1 == 0) {
2116                                 gen_nullptr_check(s1);
2117                                 gen_bound_check;
2118                                 }
2119                         if (has_ext_instr_set) {
2120                                 M_LADD   (s2, s1, REG_ITMP1);
2121                                 M_BLDU   (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
2122                                 M_BSEXT  (d, d);
2123                                 }
2124                         else {
2125                                 M_LADD(s2, s1, REG_ITMP1);
2126                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
2127                                 M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
2128                                 M_EXTQH(REG_ITMP2, REG_ITMP1, d);
2129                                 M_SRA_IMM(d, 56, d);
2130                                 }
2131                         store_reg_to_var_int(iptr->dst, d);
2132                         break;
2133
2134
2135                 case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
2136
2137                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2138                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2139                         if (iptr->op1 == 0) {
2140                                 gen_nullptr_check(s1);
2141                                 gen_bound_check;
2142                                 }
2143                         var_to_reg_int(s3, src, REG_ITMP3);
2144                         M_SAADDQ(s2, s1, REG_ITMP1);
2145                         M_AST   (s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
2146                         break;
2147
2148                 case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
2149
2150                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2151                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2152                         if (iptr->op1 == 0) {
2153                                 gen_nullptr_check(s1);
2154                                 gen_bound_check;
2155                                 }
2156                         var_to_reg_int(s3, src, REG_ITMP3);
2157                         M_S8ADDQ(s2, s1, REG_ITMP1);
2158                         M_LST   (s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
2159                         break;
2160
2161                 case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
2162
2163                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2164                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2165                         if (iptr->op1 == 0) {
2166                                 gen_nullptr_check(s1);
2167                                 gen_bound_check;
2168                                 }
2169
2170                         var_to_reg_int(s3, src, REG_ITMP3);
2171                         M_S4ADDQ(s2, s1, REG_ITMP1);
2172                         M_IST   (s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
2173                         break;
2174
2175                 case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
2176
2177                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2178                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2179                         if (iptr->op1 == 0) {
2180                                 gen_nullptr_check(s1);
2181                                 gen_bound_check;
2182                                 }
2183                         var_to_reg_flt(s3, src, REG_FTMP3);
2184                         M_S4ADDQ(s2, s1, REG_ITMP1);
2185                         M_FST   (s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
2186                         break;
2187
2188                 case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
2189
2190                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2191                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2192                         if (iptr->op1 == 0) {
2193                                 gen_nullptr_check(s1);
2194                                 gen_bound_check;
2195                                 }
2196                         var_to_reg_flt(s3, src, REG_FTMP3);
2197                         M_S8ADDQ(s2, s1, REG_ITMP1);
2198                         M_DST   (s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
2199                         break;
2200
2201                 case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
2202
2203                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2204                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2205                         if (iptr->op1 == 0) {
2206                                 gen_nullptr_check(s1);
2207                                 gen_bound_check;
2208                                 }
2209                         var_to_reg_int(s3, src, REG_ITMP3);
2210                         if (has_ext_instr_set) {
2211                                 M_LADD(s2, s1, REG_ITMP1);
2212                                 M_LADD(s2, REG_ITMP1, REG_ITMP1);
2213                                 M_SST (s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
2214                                 }
2215                         else {
2216                                 M_LADD (s2, s1, REG_ITMP1);
2217                                 M_LADD (s2, REG_ITMP1, REG_ITMP1);
2218                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
2219                                 M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
2220                                 M_INSWL(s3, REG_ITMP1, REG_ITMP3);
2221                                 M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
2222                                 M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
2223                                 M_LST_U(REG_ITMP2, REG_ITMP1, 0);
2224                                 }
2225                         break;
2226
2227                 case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
2228
2229                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2230                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2231                         if (iptr->op1 == 0) {
2232                                 gen_nullptr_check(s1);
2233                                 gen_bound_check;
2234                                 }
2235                         var_to_reg_int(s3, src, REG_ITMP3);
2236                         if (has_ext_instr_set) {
2237                                 M_LADD(s2, s1, REG_ITMP1);
2238                                 M_LADD(s2, REG_ITMP1, REG_ITMP1);
2239                                 M_SST (s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
2240                                 }
2241                         else {
2242                                 M_LADD (s2, s1, REG_ITMP1);
2243                                 M_LADD (s2, REG_ITMP1, REG_ITMP1);
2244                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
2245                                 M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
2246                                 M_INSWL(s3, REG_ITMP1, REG_ITMP3);
2247                                 M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
2248                                 M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
2249                                 M_LST_U(REG_ITMP2, REG_ITMP1, 0);
2250                                 }
2251                         break;
2252
2253                 case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
2254
2255                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2256                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2257                         if (iptr->op1 == 0) {
2258                                 gen_nullptr_check(s1);
2259                                 gen_bound_check;
2260                                 }
2261                         var_to_reg_int(s3, src, REG_ITMP3);
2262                         if (has_ext_instr_set) {
2263                                 M_LADD(s2, s1, REG_ITMP1);
2264                                 M_BST (s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
2265                                 }
2266                         else {
2267                                 M_LADD (s2, s1, REG_ITMP1);
2268                                 M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
2269                                 M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
2270                                 M_INSBL(s3, REG_ITMP1, REG_ITMP3);
2271                                 M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
2272                                 M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
2273                                 M_LST_U(REG_ITMP2, REG_ITMP1, 0);
2274                                 }
2275                         break;
2276
2277
2278                 case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
2279                                       /* op1 = type, val.a = field address            */
2280
2281                         a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
2282                         M_ALD(REG_ITMP1, REG_PV, a);
2283                         switch (iptr->op1) {
2284                                 case TYPE_INT:
2285                                         var_to_reg_int(s2, src, REG_ITMP2);
2286                                         M_IST(s2, REG_ITMP1, 0);
2287                                         break;
2288                                 case TYPE_LNG:
2289                                         var_to_reg_int(s2, src, REG_ITMP2);
2290                                         M_LST(s2, REG_ITMP1, 0);
2291                                         break;
2292                                 case TYPE_ADR:
2293                                         var_to_reg_int(s2, src, REG_ITMP2);
2294                                         M_AST(s2, REG_ITMP1, 0);
2295                                         break;
2296                                 case TYPE_FLT:
2297                                         var_to_reg_flt(s2, src, REG_FTMP2);
2298                                         M_FST(s2, REG_ITMP1, 0);
2299                                         break;
2300                                 case TYPE_DBL:
2301                                         var_to_reg_flt(s2, src, REG_FTMP2);
2302                                         M_DST(s2, REG_ITMP1, 0);
2303                                         break;
2304                                 default: panic ("internal error");
2305                                 }
2306                         break;
2307
2308                 case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
2309                                       /* op1 = type, val.a = field address            */
2310
2311                         a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
2312                         M_ALD(REG_ITMP1, REG_PV, a);
2313                         switch (iptr->op1) {
2314                                 case TYPE_INT:
2315                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2316                                         M_ILD(d, REG_ITMP1, 0);
2317                                         store_reg_to_var_int(iptr->dst, d);
2318                                         break;
2319                                 case TYPE_LNG:
2320                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2321                                         M_LLD(d, REG_ITMP1, 0);
2322                                         store_reg_to_var_int(iptr->dst, d);
2323                                         break;
2324                                 case TYPE_ADR:
2325                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2326                                         M_ALD(d, REG_ITMP1, 0);
2327                                         store_reg_to_var_int(iptr->dst, d);
2328                                         break;
2329                                 case TYPE_FLT:
2330                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2331                                         M_FLD(d, REG_ITMP1, 0);
2332                                         store_reg_to_var_flt(iptr->dst, d);
2333                                         break;
2334                                 case TYPE_DBL:                          
2335                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2336                                         M_DLD(d, REG_ITMP1, 0);
2337                                         store_reg_to_var_flt(iptr->dst, d);
2338                                         break;
2339                                 default: panic ("internal error");
2340                                 }
2341                         break;
2342
2343
2344                 case ICMD_PUTFIELD:   /* ..., value  ==> ...                          */
2345                                       /* op1 = type, val.i = field offset             */
2346
2347                         a = ((fieldinfo *)(iptr->val.a))->offset;
2348                         switch (iptr->op1) {
2349                                 case TYPE_INT:
2350                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2351                                         var_to_reg_int(s2, src, REG_ITMP2);
2352                                         gen_nullptr_check(s1);
2353                                         M_IST(s2, s1, a);
2354                                         break;
2355                                 case TYPE_LNG:
2356                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2357                                         var_to_reg_int(s2, src, REG_ITMP2);
2358                                         gen_nullptr_check(s1);
2359                                         M_LST(s2, s1, a);
2360                                         break;
2361                                 case TYPE_ADR:
2362                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2363                                         var_to_reg_int(s2, src, REG_ITMP2);
2364                                         gen_nullptr_check(s1);
2365                                         M_AST(s2, s1, a);
2366                                         break;
2367                                 case TYPE_FLT:
2368                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2369                                         var_to_reg_flt(s2, src, REG_FTMP2);
2370                                         gen_nullptr_check(s1);
2371                                         M_FST(s2, s1, a);
2372                                         break;
2373                                 case TYPE_DBL:
2374                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2375                                         var_to_reg_flt(s2, src, REG_FTMP2);
2376                                         gen_nullptr_check(s1);
2377                                         M_DST(s2, s1, a);
2378                                         break;
2379                                 default: panic ("internal error");
2380                                 }
2381                         break;
2382
2383                 case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
2384                                       /* op1 = type, val.i = field offset             */
2385
2386                         a = ((fieldinfo *)(iptr->val.a))->offset;
2387                         switch (iptr->op1) {
2388                                 case TYPE_INT:
2389                                         var_to_reg_int(s1, src, REG_ITMP1);
2390                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2391                                         gen_nullptr_check(s1);
2392                                         M_ILD(d, s1, a);
2393                                         store_reg_to_var_int(iptr->dst, d);
2394                                         break;
2395                                 case TYPE_LNG:
2396                                         var_to_reg_int(s1, src, REG_ITMP1);
2397                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2398                                         gen_nullptr_check(s1);
2399                                         M_LLD(d, s1, a);
2400                                         store_reg_to_var_int(iptr->dst, d);
2401                                         break;
2402                                 case TYPE_ADR:
2403                                         var_to_reg_int(s1, src, REG_ITMP1);
2404                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2405                                         gen_nullptr_check(s1);
2406                                         M_ALD(d, s1, a);
2407                                         store_reg_to_var_int(iptr->dst, d);
2408                                         break;
2409                                 case TYPE_FLT:
2410                                         var_to_reg_int(s1, src, REG_ITMP1);
2411                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2412                                         gen_nullptr_check(s1);
2413                                         M_FLD(d, s1, a);
2414                                         store_reg_to_var_flt(iptr->dst, d);
2415                                         break;
2416                                 case TYPE_DBL:                          
2417                                         var_to_reg_int(s1, src, REG_ITMP1);
2418                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2419                                         gen_nullptr_check(s1);
2420                                         M_DLD(d, s1, a);
2421                                         store_reg_to_var_flt(iptr->dst, d);
2422                                         break;
2423                                 default: panic ("internal error");
2424                                 }
2425                         break;
2426
2427
2428                 /* branch operations **************************************************/
2429
2430 #define ALIGNCODENOP {if((int)((long)mcodeptr&7)){M_NOP;}}
2431
2432                 case ICMD_ATHROW:       /* ..., objectref ==> ... (, objectref)       */
2433
2434                         var_to_reg_int(s1, src, REG_ITMP1);
2435                         M_INTMOVE(s1, REG_ITMP1_XPTR);
2436                         a = dseg_addaddress(asm_handle_exception);
2437                         M_ALD(REG_ITMP2, REG_PV, a);
2438                         M_JMP(REG_ITMP2_XPC, REG_ITMP2);
2439                         M_NOP;              /* nop ensures that XPC is less than the end */
2440                                             /* of basic block                            */
2441                         ALIGNCODENOP;
2442                         break;
2443
2444                 case ICMD_GOTO:         /* ... ==> ...                                */
2445                                         /* op1 = target JavaVM pc                     */
2446                         M_BR(0);
2447                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2448                         ALIGNCODENOP;
2449                         break;
2450
2451                 case ICMD_JSR:          /* ... ==> ...                                */
2452                                         /* op1 = target JavaVM pc                     */
2453
2454                         M_BSR(REG_ITMP1, 0);
2455                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2456                         break;
2457                         
2458                 case ICMD_RET:          /* ... ==> ...                                */
2459                                         /* op1 = local variable                       */
2460
2461                         var = &(locals[iptr->op1][TYPE_ADR]);
2462                         if (var->flags & INMEMORY) {
2463                                 M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff);
2464                                 M_RET(REG_ZERO, REG_ITMP1);
2465                                 }
2466                         else
2467                                 M_RET(REG_ZERO, var->regoff);
2468                         ALIGNCODENOP;
2469                         break;
2470
2471                 case ICMD_IFNULL:       /* ..., value ==> ...                         */
2472                                         /* op1 = target JavaVM pc                     */
2473
2474                         var_to_reg_int(s1, src, REG_ITMP1);
2475                         M_BEQZ(s1, 0);
2476                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2477                         break;
2478
2479                 case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
2480                                         /* op1 = target JavaVM pc                     */
2481
2482                         var_to_reg_int(s1, src, REG_ITMP1);
2483                         M_BNEZ(s1, 0);
2484                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2485                         break;
2486
2487                 case ICMD_IFEQ:         /* ..., value ==> ...                         */
2488                                         /* op1 = target JavaVM pc, val.i = constant   */
2489
2490                         var_to_reg_int(s1, src, REG_ITMP1);
2491                         if (iptr->val.i == 0) {
2492                                 M_BEQZ(s1, 0);
2493                                 }
2494                         else {
2495                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2496                                         M_CMPEQ_IMM(s1, iptr->val.i, REG_ITMP1);
2497                                         }
2498                                 else {
2499                                         ICONST(REG_ITMP2, iptr->val.i);
2500                                         M_CMPEQ(s1, REG_ITMP2, REG_ITMP1);
2501                                         }
2502                                 M_BNEZ(REG_ITMP1, 0);
2503                                 }
2504                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2505                         break;
2506
2507                 case ICMD_IFLT:         /* ..., value ==> ...                         */
2508                                         /* op1 = target JavaVM pc, val.i = constant   */
2509
2510                         var_to_reg_int(s1, src, REG_ITMP1);
2511                         if (iptr->val.i == 0) {
2512                                 M_BLTZ(s1, 0);
2513                                 }
2514                         else {
2515                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2516                                         M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2517                                         }
2518                                 else {
2519                                         ICONST(REG_ITMP2, iptr->val.i);
2520                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2521                                         }
2522                                 M_BNEZ(REG_ITMP1, 0);
2523                                 }
2524                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2525                         break;
2526
2527                 case ICMD_IFLE:         /* ..., value ==> ...                         */
2528                                         /* op1 = target JavaVM pc, val.i = constant   */
2529
2530                         var_to_reg_int(s1, src, REG_ITMP1);
2531                         if (iptr->val.i == 0) {
2532                                 M_BLEZ(s1, 0);
2533                                 }
2534                         else {
2535                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2536                                         M_CMPLE_IMM(s1, iptr->val.i, REG_ITMP1);
2537                                         }
2538                                 else {
2539                                         ICONST(REG_ITMP2, iptr->val.i);
2540                                         M_CMPLE(s1, REG_ITMP2, REG_ITMP1);
2541                                         }
2542                                 M_BNEZ(REG_ITMP1, 0);
2543                                 }
2544                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2545                         break;
2546
2547                 case ICMD_IFNE:         /* ..., value ==> ...                         */
2548                                         /* op1 = target JavaVM pc, val.i = constant   */
2549
2550                         var_to_reg_int(s1, src, REG_ITMP1);
2551                         if (iptr->val.i == 0) {
2552                                 M_BNEZ(s1, 0);
2553                                 }
2554                         else {
2555                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2556                                         M_CMPEQ_IMM(s1, iptr->val.i, REG_ITMP1);
2557                                         }
2558                                 else {
2559                                         ICONST(REG_ITMP2, iptr->val.i);
2560                                         M_CMPEQ(s1, REG_ITMP2, REG_ITMP1);
2561                                         }
2562                                 M_BEQZ(REG_ITMP1, 0);
2563                                 }
2564                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2565                         break;
2566
2567                 case ICMD_IFGT:         /* ..., value ==> ...                         */
2568                                         /* op1 = target JavaVM pc, val.i = constant   */
2569
2570                         var_to_reg_int(s1, src, REG_ITMP1);
2571                         if (iptr->val.i == 0) {
2572                                 M_BGTZ(s1, 0);
2573                                 }
2574                         else {
2575                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2576                                         M_CMPLE_IMM(s1, iptr->val.i, REG_ITMP1);
2577                                         }
2578                                 else {
2579                                         ICONST(REG_ITMP2, iptr->val.i);
2580                                         M_CMPLE(s1, REG_ITMP2, REG_ITMP1);
2581                                         }
2582                                 M_BEQZ(REG_ITMP1, 0);
2583                                 }
2584                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2585                         break;
2586
2587                 case ICMD_IFGE:         /* ..., value ==> ...                         */
2588                                         /* op1 = target JavaVM pc, val.i = constant   */
2589
2590                         var_to_reg_int(s1, src, REG_ITMP1);
2591                         if (iptr->val.i == 0) {
2592                                 M_BGEZ(s1, 0);
2593                                 }
2594                         else {
2595                                 if ((iptr->val.i > 0) && (iptr->val.i <= 255)) {
2596                                         M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2597                                         }
2598                                 else {
2599                                         ICONST(REG_ITMP2, iptr->val.i);
2600                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2601                                         }
2602                                 M_BEQZ(REG_ITMP1, 0);
2603                                 }
2604                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2605                         break;
2606
2607                 case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
2608                                         /* op1 = target JavaVM pc, val.l = constant   */
2609
2610                         var_to_reg_int(s1, src, REG_ITMP1);
2611                         if (iptr->val.l == 0) {
2612                                 M_BEQZ(s1, 0);
2613                                 }
2614                         else {
2615                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2616                                         M_CMPEQ_IMM(s1, iptr->val.l, REG_ITMP1);
2617                                         }
2618                                 else {
2619                                         LCONST(REG_ITMP2, iptr->val.l);
2620                                         M_CMPEQ(s1, REG_ITMP2, REG_ITMP1);
2621                                         }
2622                                 M_BNEZ(REG_ITMP1, 0);
2623                                 }
2624                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2625                         break;
2626
2627                 case ICMD_IF_LLT:       /* ..., value ==> ...                         */
2628                                         /* op1 = target JavaVM pc, val.l = constant   */
2629
2630                         var_to_reg_int(s1, src, REG_ITMP1);
2631                         if (iptr->val.l == 0) {
2632                                 M_BLTZ(s1, 0);
2633                                 }
2634                         else {
2635                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2636                                         M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2637                                         }
2638                                 else {
2639                                         LCONST(REG_ITMP2, iptr->val.l);
2640                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2641                                         }
2642                                 M_BNEZ(REG_ITMP1, 0);
2643                                 }
2644                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2645                         break;
2646
2647                 case ICMD_IF_LLE:       /* ..., value ==> ...                         */
2648                                         /* op1 = target JavaVM pc, val.l = constant   */
2649
2650                         var_to_reg_int(s1, src, REG_ITMP1);
2651                         if (iptr->val.l == 0) {
2652                                 M_BLEZ(s1, 0);
2653                                 }
2654                         else {
2655                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2656                                         M_CMPLE_IMM(s1, iptr->val.l, REG_ITMP1);
2657                                         }
2658                                 else {
2659                                         LCONST(REG_ITMP2, iptr->val.l);
2660                                         M_CMPLE(s1, REG_ITMP2, REG_ITMP1);
2661                                         }
2662                                 M_BNEZ(REG_ITMP1, 0);
2663                                 }
2664                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2665                         break;
2666
2667                 case ICMD_IF_LNE:       /* ..., value ==> ...                         */
2668                                         /* op1 = target JavaVM pc, val.l = constant   */
2669
2670                         var_to_reg_int(s1, src, REG_ITMP1);
2671                         if (iptr->val.l == 0) {
2672                                 M_BNEZ(s1, 0);
2673                                 }
2674                         else {
2675                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2676                                         M_CMPEQ_IMM(s1, iptr->val.l, REG_ITMP1);
2677                                         }
2678                                 else {
2679                                         LCONST(REG_ITMP2, iptr->val.l);
2680                                         M_CMPEQ(s1, REG_ITMP2, REG_ITMP1);
2681                                         }
2682                                 M_BEQZ(REG_ITMP1, 0);
2683                                 }
2684                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2685                         break;
2686
2687                 case ICMD_IF_LGT:       /* ..., value ==> ...                         */
2688                                         /* op1 = target JavaVM pc, val.l = constant   */
2689
2690                         var_to_reg_int(s1, src, REG_ITMP1);
2691                         if (iptr->val.l == 0) {
2692                                 M_BGTZ(s1, 0);
2693                                 }
2694                         else {
2695                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2696                                         M_CMPLE_IMM(s1, iptr->val.l, REG_ITMP1);
2697                                         }
2698                                 else {
2699                                         LCONST(REG_ITMP2, iptr->val.l);
2700                                         M_CMPLE(s1, REG_ITMP2, REG_ITMP1);
2701                                         }
2702                                 M_BEQZ(REG_ITMP1, 0);
2703                                 }
2704                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2705                         break;
2706
2707                 case ICMD_IF_LGE:       /* ..., value ==> ...                         */
2708                                         /* op1 = target JavaVM pc, val.l = constant   */
2709
2710                         var_to_reg_int(s1, src, REG_ITMP1);
2711                         if (iptr->val.l == 0) {
2712                                 M_BGEZ(s1, 0);
2713                                 }
2714                         else {
2715                                 if ((iptr->val.l > 0) && (iptr->val.l <= 255)) {
2716                                         M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2717                                         }
2718                                 else {
2719                                         LCONST(REG_ITMP2, iptr->val.l);
2720                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2721                                         }
2722                                 M_BEQZ(REG_ITMP1, 0);
2723                                 }
2724                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2725                         break;
2726
2727                 case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
2728                 case ICMD_IF_LCMPEQ:    /* op1 = target JavaVM pc                     */
2729                 case ICMD_IF_ACMPEQ:
2730
2731                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2732                         var_to_reg_int(s2, src, REG_ITMP2);
2733                         M_CMPEQ(s1, s2, REG_ITMP1);
2734                         M_BNEZ(REG_ITMP1, 0);
2735                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2736                         break;
2737
2738                 case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
2739                 case ICMD_IF_LCMPNE:    /* op1 = target JavaVM pc                     */
2740                 case ICMD_IF_ACMPNE:
2741
2742                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2743                         var_to_reg_int(s2, src, REG_ITMP2);
2744                         M_CMPEQ(s1, s2, REG_ITMP1);
2745                         M_BEQZ(REG_ITMP1, 0);
2746                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2747                         break;
2748
2749                 case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
2750                 case ICMD_IF_LCMPLT:    /* op1 = target JavaVM pc                     */
2751
2752                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2753                         var_to_reg_int(s2, src, REG_ITMP2);
2754                         M_CMPLT(s1, s2, REG_ITMP1);
2755                         M_BNEZ(REG_ITMP1, 0);
2756                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2757                         break;
2758
2759                 case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
2760                 case ICMD_IF_LCMPGT:    /* op1 = target JavaVM pc                     */
2761
2762                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2763                         var_to_reg_int(s2, src, REG_ITMP2);
2764                         M_CMPLE(s1, s2, REG_ITMP1);
2765                         M_BEQZ(REG_ITMP1, 0);
2766                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2767                         break;
2768
2769                 case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
2770                 case ICMD_IF_LCMPLE:    /* op1 = target JavaVM pc                     */
2771
2772                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2773                         var_to_reg_int(s2, src, REG_ITMP2);
2774                         M_CMPLE(s1, s2, REG_ITMP1);
2775                         M_BNEZ(REG_ITMP1, 0);
2776                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2777                         break;
2778
2779                 case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
2780                 case ICMD_IF_LCMPGE:    /* op1 = target JavaVM pc                     */
2781
2782                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2783                         var_to_reg_int(s2, src, REG_ITMP2);
2784                         M_CMPLT(s1, s2, REG_ITMP1);
2785                         M_BEQZ(REG_ITMP1, 0);
2786                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2787                         break;
2788
2789                 /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST                           */
2790
2791                 case ICMD_ELSE_ICONST:  /* handled by IFxx_ICONST                     */
2792                         break;
2793
2794                 case ICMD_IFEQ_ICONST:  /* ..., value ==> ..., constant               */
2795                                         /* val.i = constant                           */
2796
2797                         var_to_reg_int(s1, src, REG_ITMP1);
2798                         d = reg_of_var(iptr->dst, REG_ITMP3);
2799                         s3 = iptr->val.i;
2800                         if (iptr[1].opc == ICMD_ELSE_ICONST) {
2801                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2802                                         M_CMPEQ(s1, REG_ZERO, d);
2803                                         store_reg_to_var_int(iptr->dst, d);
2804                                         break;
2805                                         }
2806                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2807                                         M_CMPEQ(s1, REG_ZERO, d);
2808                                         M_XOR_IMM(d, 1, d);
2809                                         store_reg_to_var_int(iptr->dst, d);
2810                                         break;
2811                                         }
2812                                 if (s1 == d) {
2813                                         M_MOV(s1, REG_ITMP1);
2814                                         s1 = REG_ITMP1;
2815                                         }
2816                                 ICONST(d, iptr[1].val.i);
2817                                 }
2818                         if ((s3 >= 0) && (s3 <= 255)) {
2819                                 M_CMOVEQ_IMM(s1, s3, d);
2820                                 }
2821                         else {
2822                                 ICONST(REG_ITMP2, s3);
2823                                 M_CMOVEQ(s1, REG_ITMP2, d);
2824                                 }
2825                         store_reg_to_var_int(iptr->dst, d);
2826                         break;
2827
2828                 case ICMD_IFNE_ICONST:  /* ..., value ==> ..., constant               */
2829                                         /* val.i = constant                           */
2830
2831                         var_to_reg_int(s1, src, REG_ITMP1);
2832                         d = reg_of_var(iptr->dst, REG_ITMP3);
2833                         s3 = iptr->val.i;
2834                         if (iptr[1].opc == ICMD_ELSE_ICONST) {
2835                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2836                                         M_CMPEQ(s1, REG_ZERO, d);
2837                                         store_reg_to_var_int(iptr->dst, d);
2838                                         break;
2839                                         }
2840                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2841                                         M_CMPEQ(s1, REG_ZERO, d);
2842                                         M_XOR_IMM(d, 1, d);
2843                                         store_reg_to_var_int(iptr->dst, d);
2844                                         break;
2845                                         }
2846                                 if (s1 == d) {
2847                                         M_MOV(s1, REG_ITMP1);
2848                                         s1 = REG_ITMP1;
2849                                         }
2850                                 ICONST(d, iptr[1].val.i);
2851                                 }
2852                         if ((s3 >= 0) && (s3 <= 255)) {
2853                                 M_CMOVNE_IMM(s1, s3, d);
2854                                 }
2855                         else {
2856                                 ICONST(REG_ITMP2, s3);
2857                                 M_CMOVNE(s1, REG_ITMP2, d);
2858                                 }
2859                         store_reg_to_var_int(iptr->dst, d);
2860                         break;
2861
2862                 case ICMD_IFLT_ICONST:  /* ..., value ==> ..., constant               */
2863                                         /* val.i = constant                           */
2864
2865                         var_to_reg_int(s1, src, REG_ITMP1);
2866                         d = reg_of_var(iptr->dst, REG_ITMP3);
2867                         s3 = iptr->val.i;
2868                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2869                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2870                                         M_CMPLT(s1, REG_ZERO, d);
2871                                         store_reg_to_var_int(iptr->dst, d);
2872                                         break;
2873                                         }
2874                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2875                                         M_CMPLE(REG_ZERO, s1, d);
2876                                         store_reg_to_var_int(iptr->dst, d);
2877                                         break;
2878                                         }
2879                                 if (s1 == d) {
2880                                         M_MOV(s1, REG_ITMP1);
2881                                         s1 = REG_ITMP1;
2882                                         }
2883                                 ICONST(d, iptr[1].val.i);
2884                                 }
2885                         if ((s3 >= 0) && (s3 <= 255)) {
2886                                 M_CMOVLT_IMM(s1, s3, d);
2887                                 }
2888                         else {
2889                                 ICONST(REG_ITMP2, s3);
2890                                 M_CMOVLT(s1, REG_ITMP2, d);
2891                                 }
2892                         store_reg_to_var_int(iptr->dst, d);
2893                         break;
2894
2895                 case ICMD_IFGE_ICONST:  /* ..., value ==> ..., constant               */
2896                                         /* val.i = constant                           */
2897
2898                         var_to_reg_int(s1, src, REG_ITMP1);
2899                         d = reg_of_var(iptr->dst, REG_ITMP3);
2900                         s3 = iptr->val.i;
2901                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2902                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2903                                         M_CMPLE(REG_ZERO, s1, d);
2904                                         store_reg_to_var_int(iptr->dst, d);
2905                                         break;
2906                                         }
2907                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2908                                         M_CMPLT(s1, REG_ZERO, d);
2909                                         store_reg_to_var_int(iptr->dst, d);
2910                                         break;
2911                                         }
2912                                 if (s1 == d) {
2913                                         M_MOV(s1, REG_ITMP1);
2914                                         s1 = REG_ITMP1;
2915                                         }
2916                                 ICONST(d, iptr[1].val.i);
2917                                 }
2918                         if ((s3 >= 0) && (s3 <= 255)) {
2919                                 M_CMOVGE_IMM(s1, s3, d);
2920                                 }
2921                         else {
2922                                 ICONST(REG_ITMP2, s3);
2923                                 M_CMOVGE(s1, REG_ITMP2, d);
2924                                 }
2925                         store_reg_to_var_int(iptr->dst, d);
2926                         break;
2927
2928                 case ICMD_IFGT_ICONST:  /* ..., value ==> ..., constant               */
2929                                         /* val.i = constant                           */
2930
2931                         var_to_reg_int(s1, src, REG_ITMP1);
2932                         d = reg_of_var(iptr->dst, REG_ITMP3);
2933                         s3 = iptr->val.i;
2934                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2935                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2936                                         M_CMPLT(REG_ZERO, s1, d);
2937                                         store_reg_to_var_int(iptr->dst, d);
2938                                         break;
2939                                         }
2940                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2941                                         M_CMPLE(s1, REG_ZERO, d);
2942                                         store_reg_to_var_int(iptr->dst, d);
2943                                         break;
2944                                         }
2945                                 if (s1 == d) {
2946                                         M_MOV(s1, REG_ITMP1);
2947                                         s1 = REG_ITMP1;
2948                                         }
2949                                 ICONST(d, iptr[1].val.i);
2950                                 }
2951                         if ((s3 >= 0) && (s3 <= 255)) {
2952                                 M_CMOVGT_IMM(s1, s3, d);
2953                                 }
2954                         else {
2955                                 ICONST(REG_ITMP2, s3);
2956                                 M_CMOVGT(s1, REG_ITMP2, d);
2957                                 }
2958                         store_reg_to_var_int(iptr->dst, d);
2959                         break;
2960
2961                 case ICMD_IFLE_ICONST:  /* ..., value ==> ..., constant               */
2962                                         /* val.i = constant                           */
2963
2964                         var_to_reg_int(s1, src, REG_ITMP1);
2965                         d = reg_of_var(iptr->dst, REG_ITMP3);
2966                         s3 = iptr->val.i;
2967                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2968                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2969                                         M_CMPLE(s1, REG_ZERO, d);
2970                                         store_reg_to_var_int(iptr->dst, d);
2971                                         break;
2972                                         }
2973                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2974                                         M_CMPLT(REG_ZERO, s1, d);
2975                                         store_reg_to_var_int(iptr->dst, d);
2976                                         break;
2977                                         }
2978                                 if (s1 == d) {
2979                                         M_MOV(s1, REG_ITMP1);
2980                                         s1 = REG_ITMP1;
2981                                         }
2982                                 ICONST(d, iptr[1].val.i);
2983                                 }
2984                         if ((s3 >= 0) && (s3 <= 255)) {
2985                                 M_CMOVLE_IMM(s1, s3, d);
2986                                 }
2987                         else {
2988                                 ICONST(REG_ITMP2, s3);
2989                                 M_CMOVLE(s1, REG_ITMP2, d);
2990                                 }
2991                         store_reg_to_var_int(iptr->dst, d);
2992                         break;
2993
2994
2995                 case ICMD_IRETURN:      /* ..., retvalue ==> ...                      */
2996                 case ICMD_LRETURN:
2997                 case ICMD_ARETURN:
2998
2999 #ifdef USE_THREADS
3000                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
3001                                 int disp;
3002                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
3003                                 M_ALD(REG_PV, REG_PV, a);
3004                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
3005                                 M_JSR(REG_RA, REG_PV);
3006                                 disp = -(int)((u1*) mcodeptr - mcodebase);
3007                                 M_LDA(REG_PV, REG_RA, disp);
3008                                 }                       
3009 #endif
3010                         var_to_reg_int(s1, src, REG_RESULT);
3011                         M_INTMOVE(s1, REG_RESULT);
3012                         goto nowperformreturn;
3013
3014                 case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
3015                 case ICMD_DRETURN:
3016
3017 #ifdef USE_THREADS
3018                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
3019                                 int disp;
3020                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
3021                                 M_ALD(REG_PV, REG_PV, a);
3022                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
3023                                 M_JSR(REG_RA, REG_PV);
3024                                 disp = -(int)((u1*) mcodeptr - mcodebase);
3025                                 M_LDA(REG_PV, REG_RA, disp);
3026                                 }                       
3027 #endif
3028                         var_to_reg_flt(s1, src, REG_FRESULT);
3029                         M_FLTMOVE(s1, REG_FRESULT);
3030                         goto nowperformreturn;
3031
3032                 case ICMD_RETURN:      /* ...  ==> ...                                */
3033
3034 #ifdef USE_THREADS
3035                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
3036                                 int disp;
3037                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
3038                                 M_ALD(REG_PV, REG_PV, a);
3039                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
3040                                 M_JSR(REG_RA, REG_PV);
3041                                 disp = -(int)((u1*) mcodeptr - mcodebase);
3042                                 M_LDA(REG_PV, REG_RA, disp);
3043                                 }                       
3044 #endif
3045
3046 nowperformreturn:
3047                         {
3048                         int r, p;
3049                         
3050                         p = parentargs_base;
3051                         
3052                         /* restore return address                                         */
3053
3054                         if (!isleafmethod)
3055                                 {p--;  M_LLD (REG_RA, REG_SP, 8 * p);}
3056
3057                         /* restore saved registers                                        */
3058
3059                         for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
3060                                         {p--; M_LLD(savintregs[r], REG_SP, 8 * p);}
3061                         for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
3062                                         {p--; M_DLD(savfltregs[r], REG_SP, 8 * p);}
3063
3064                         /* deallocate stack                                               */
3065
3066                         if (parentargs_base)
3067                                 {M_LDA(REG_SP, REG_SP, parentargs_base*8);}
3068
3069                         /* call trace function */
3070
3071                         if (runverbose) {
3072                                 M_LDA (REG_SP, REG_SP, -24);
3073                                 M_AST(REG_RA, REG_SP, 0);
3074                                 M_LST(REG_RESULT, REG_SP, 8);
3075                                 M_DST(REG_FRESULT, REG_SP,16);
3076                                 a = dseg_addaddress (method);
3077                                 M_ALD(argintregs[0], REG_PV, a);
3078                                 M_MOV(REG_RESULT, argintregs[1]);
3079                                 M_FLTMOVE(REG_FRESULT, argfltregs[2]);
3080                                 M_FLTMOVE(REG_FRESULT, argfltregs[3]);
3081                                 a = dseg_addaddress ((void*) (builtin_displaymethodstop));
3082                                 M_ALD(REG_PV, REG_PV, a);
3083                                 M_JSR (REG_RA, REG_PV);
3084                                 s1 = (int)((u1*) mcodeptr - mcodebase);
3085                                 if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1);
3086                                 else {
3087                                         s4 ml=-s1, mh=0;
3088                                         while (ml<-32768) { ml+=65536; mh--; }
3089                                         M_LDA (REG_PV, REG_RA, ml );
3090                                         M_LDAH (REG_PV, REG_PV, mh );
3091                                         }
3092                                 M_DLD(REG_FRESULT, REG_SP,16);
3093                                 M_LLD(REG_RESULT, REG_SP, 8);
3094                                 M_ALD(REG_RA, REG_SP, 0);
3095                                 M_LDA (REG_SP, REG_SP, 24);
3096                                 }
3097
3098                         M_RET(REG_ZERO, REG_RA);
3099                         ALIGNCODENOP;
3100                         }
3101                         break;
3102
3103
3104                 case ICMD_TABLESWITCH:  /* ..., index ==> ...                         */
3105                         {
3106                         s4 i, l, *s4ptr;
3107                         void **tptr;
3108
3109                         tptr = (void **) iptr->target;
3110
3111                         s4ptr = iptr->val.a;
3112                         l = s4ptr[1];                          /* low     */
3113                         i = s4ptr[2];                          /* high    */
3114                         
3115                         var_to_reg_int(s1, src, REG_ITMP1);
3116                         if (l == 0)
3117                                 {M_INTMOVE(s1, REG_ITMP1);}
3118                         else if (l <= 32768) {
3119                                 M_LDA(REG_ITMP1, s1, -l);
3120                                 }
3121                         else {
3122                                 ICONST(REG_ITMP2, l);
3123                                 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
3124                                 }
3125                         i = i - l + 1;
3126
3127                         /* range check */
3128
3129                         if (i <= 256)
3130                                 M_CMPULE_IMM(REG_ITMP1, i - 1, REG_ITMP2);
3131                         else {
3132                                 M_LDA(REG_ITMP2, REG_ZERO, i - 1);
3133                                 M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
3134                                 }
3135                         M_BEQZ(REG_ITMP2, 0);
3136
3137
3138                         /* codegen_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr); */
3139                         codegen_addreference((basicblock *) tptr[0], mcodeptr);
3140
3141                         /* build jump table top down and use address of lowest entry */
3142
3143                         /* s4ptr += 3 + i; */
3144                         tptr += i;
3145
3146                         while (--i >= 0) {
3147                                 /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */
3148                                 dseg_addtarget((basicblock *) tptr[0]); 
3149                                 --tptr;
3150                                 }
3151                         }
3152
3153                         /* length of dataseg after last dseg_addtarget is used by load */
3154
3155                         M_SAADDQ(REG_ITMP1, REG_PV, REG_ITMP2);
3156                         M_ALD(REG_ITMP2, REG_ITMP2, -dseglen);
3157                         M_JMP(REG_ZERO, REG_ITMP2);
3158                         ALIGNCODENOP;
3159                         break;
3160
3161
3162                 case ICMD_LOOKUPSWITCH: /* ..., key ==> ...                           */
3163                         {
3164                         s4 i, l, val, *s4ptr;
3165                         void **tptr;
3166
3167                         tptr = (void **) iptr->target;
3168
3169                         s4ptr = iptr->val.a;
3170                         l = s4ptr[0];                          /* default  */
3171                         i = s4ptr[1];                          /* count    */
3172                         
3173                         MCODECHECK((i<<2)+8);
3174                         var_to_reg_int(s1, src, REG_ITMP1);
3175                         while (--i >= 0) {
3176                                 s4ptr += 2;
3177                                 ++tptr;
3178
3179                                 val = s4ptr[0];
3180                                 if ((val >= 0) && (val <= 255)) {
3181                                         M_CMPEQ_IMM(s1, val, REG_ITMP2);
3182                                         }
3183                                 else {
3184                                         if ((val >= -32768) && (val <= 32767)) {
3185                                                 M_LDA(REG_ITMP2, REG_ZERO, val);
3186                                                 } 
3187                                         else {
3188                                                 a = dseg_adds4 (val);
3189                                                 M_ILD(REG_ITMP2, REG_PV, a);
3190                                                 }
3191                                         M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
3192                                         }
3193                                 M_BNEZ(REG_ITMP2, 0);
3194                                 /* codegen_addreference(BlockPtrOfPC(s4ptr[1]), mcodeptr); */
3195                                 codegen_addreference((basicblock *) tptr[0], mcodeptr); 
3196                                 }
3197
3198                         M_BR(0);
3199                         /* codegen_addreference(BlockPtrOfPC(l), mcodeptr); */
3200                         
3201                         tptr = (void **) iptr->target;
3202                         codegen_addreference((basicblock *) tptr[0], mcodeptr);
3203
3204                         ALIGNCODENOP;
3205                         break;
3206                         }
3207
3208
3209                 case ICMD_BUILTIN3:     /* ..., arg1, arg2, arg3 ==> ...              */
3210                                         /* op1 = return type, val.a = function pointer*/
3211                         s3 = 3;
3212                         goto gen_method;
3213
3214                 case ICMD_BUILTIN2:     /* ..., arg1, arg2 ==> ...                    */
3215                                         /* op1 = return type, val.a = function pointer*/
3216                         s3 = 2;
3217                         goto gen_method;
3218
3219                 case ICMD_BUILTIN1:     /* ..., arg1 ==> ...                          */
3220                                         /* op1 = return type, val.a = function pointer*/
3221                         s3 = 1;
3222                         goto gen_method;
3223
3224                 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...            */
3225                                         /* op1 = arg count, val.a = method pointer    */
3226
3227                 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
3228                                         /* op1 = arg count, val.a = method pointer    */
3229
3230                 case ICMD_INVOKEVIRTUAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
3231                                         /* op1 = arg count, val.a = method pointer    */
3232
3233                 case ICMD_INVOKEINTERFACE:/*.., objectref, [arg1, [arg2 ...]] ==> ... */
3234                                         /* op1 = arg count, val.a = method pointer    */
3235
3236                         s3 = iptr->op1;
3237
3238 gen_method: {
3239                         methodinfo   *m;
3240                         classinfo    *ci;
3241
3242                         MCODECHECK((s3 << 1) + 64);
3243
3244                         /* copy arguments to registers or stack location                  */
3245
3246                         for (; --s3 >= 0; src = src->prev) {
3247                                 if (src->varkind == ARGVAR)
3248                                         continue;
3249                                 if (IS_INT_LNG_TYPE(src->type)) {
3250                                         if (s3 < INT_ARG_CNT) {
3251                                                 s1 = argintregs[s3];
3252                                                 var_to_reg_int(d, src, s1);
3253                                                 M_INTMOVE(d, s1);
3254                                                 }
3255                                         else  {
3256                                                 var_to_reg_int(d, src, REG_ITMP1);
3257                                                 M_LST(d, REG_SP, 8 * (s3 - INT_ARG_CNT));
3258                                                 }
3259                                         }
3260                                 else
3261                                         if (s3 < FLT_ARG_CNT) {
3262                                                 s1 = argfltregs[s3];
3263                                                 var_to_reg_flt(d, src, s1);
3264                                                 M_FLTMOVE(d, s1);
3265                                                 }
3266                                         else {
3267                                                 var_to_reg_flt(d, src, REG_FTMP1);
3268                                                 M_DST(d, REG_SP, 8 * (s3 - FLT_ARG_CNT));
3269                                                 }
3270                                 } /* end of for */
3271
3272                         m = iptr->val.a;
3273                         switch (iptr->opc) {
3274                                 case ICMD_BUILTIN3:
3275                                 case ICMD_BUILTIN2:
3276                                 case ICMD_BUILTIN1:
3277                                         a = dseg_addaddress ((void*) (m));
3278
3279                                         M_ALD(REG_PV, REG_PV, a); /* Pointer to built-in-function */
3280                                         d = iptr->op1;
3281                                         goto makeactualcall;
3282
3283                                 case ICMD_INVOKESTATIC:
3284                                 case ICMD_INVOKESPECIAL:
3285                                         a = dseg_addaddress (m->stubroutine);
3286
3287                                         M_ALD(REG_PV, REG_PV, a );       /* method pointer in r27 */
3288
3289                                         d = m->returntype;
3290                                         goto makeactualcall;
3291
3292                                 case ICMD_INVOKEVIRTUAL:
3293
3294                                         gen_nullptr_check(argintregs[0]);
3295                                         M_ALD(REG_METHODPTR, argintregs[0],
3296                                                                  OFFSET(java_objectheader, vftbl));
3297                                         M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl, table[0]) +
3298                                                                 sizeof(methodptr) * m->vftblindex);
3299
3300                                         d = m->returntype;
3301                                         goto makeactualcall;
3302
3303                                 case ICMD_INVOKEINTERFACE:
3304                                         ci = m->class;
3305                                         
3306                                         gen_nullptr_check(argintregs[0]);
3307                                         M_ALD(REG_METHODPTR, argintregs[0],
3308                                                                  OFFSET(java_objectheader, vftbl));    
3309                                         M_ALD(REG_METHODPTR, REG_METHODPTR,
3310                                               OFFSET(vftbl, interfacetable[0]) -
3311                                               sizeof(methodptr*) * ci->index);
3312                                         M_ALD(REG_PV, REG_METHODPTR,
3313                                                             sizeof(methodptr) * (m - ci->methods));
3314
3315                                         d = m->returntype;
3316                                         goto makeactualcall;
3317
3318                                 default:
3319                                         d = 0;
3320                                         error ("Unkown ICMD-Command: %d", iptr->opc);
3321                                 }
3322
3323 makeactualcall:
3324
3325                         M_JSR (REG_RA, REG_PV);
3326
3327                         /* recompute pv */
3328
3329                         s1 = (int)((u1*) mcodeptr - mcodebase);
3330                         if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1);
3331                         else {
3332                                 s4 ml=-s1, mh=0;
3333                                 while (ml<-32768) { ml+=65536; mh--; }
3334                                 M_LDA (REG_PV, REG_RA, ml );
3335                                 M_LDAH (REG_PV, REG_PV, mh );
3336                                 }
3337
3338                         /* d contains return type */
3339
3340                         if (d != TYPE_VOID) {
3341                                 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
3342                                         s1 = reg_of_var(iptr->dst, REG_RESULT);
3343                                         M_INTMOVE(REG_RESULT, s1);
3344                                         store_reg_to_var_int(iptr->dst, s1);
3345                                         }
3346                                 else {
3347                                         s1 = reg_of_var(iptr->dst, REG_FRESULT);
3348                                         M_FLTMOVE(REG_FRESULT, s1);
3349                                         store_reg_to_var_flt(iptr->dst, s1);
3350                                         }
3351                                 }
3352                         }
3353                         break;
3354
3355
3356                 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
3357
3358                                       /* op1:   0 == array, 1 == class                */
3359                                       /* val.a: (classinfo*) superclass               */
3360
3361 /*          superclass is an interface:
3362  *
3363  *          return (sub != NULL) &&
3364  *                 (sub->vftbl->interfacetablelength > super->index) &&
3365  *                 (sub->vftbl->interfacetable[-super->index] != NULL);
3366  *
3367  *          superclass is a class:
3368  *
3369  *          return ((sub != NULL) && (0
3370  *                  <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3371  *                  super->vftbl->diffvall));
3372  */
3373
3374                         {
3375                         classinfo *super = (classinfo*) iptr->val.a;
3376                         
3377                         var_to_reg_int(s1, src, REG_ITMP1);
3378                         d = reg_of_var(iptr->dst, REG_ITMP3);
3379                         if (s1 == d) {
3380                                 M_MOV(s1, REG_ITMP1);
3381                                 s1 = REG_ITMP1;
3382                                 }
3383                         M_CLR(d);
3384                         if (iptr->op1) {                               /* class/interface */
3385                                 if (super->flags & ACC_INTERFACE) {        /* interface       */
3386                                         M_BEQZ(s1, 6);
3387                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3388                                         M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
3389                                         M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
3390                                         M_BLEZ(REG_ITMP2, 2);
3391                                         M_ALD(REG_ITMP1, REG_ITMP1,
3392                                               OFFSET(vftbl, interfacetable[0]) -
3393                                               super->index * sizeof(methodptr*));
3394                                         M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
3395                                         }
3396                                 else {                                     /* class           */
3397 /*
3398                                         s2 = super->vftbl->diffval;
3399                                         M_BEQZ(s1, 4 + (s2 > 255));
3400                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3401                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3402                                         M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
3403                                         if (s2 <= 255)
3404                                                 M_CMPULE_IMM(REG_ITMP1, s2, d);
3405                                         else {
3406                                                 M_LDA(REG_ITMP2, REG_ZERO, s2);
3407                                                 M_CMPULE(REG_ITMP1, REG_ITMP2, d);
3408                                                 }
3409 */
3410                                         M_BEQZ(s1, 7);
3411                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3412                                         a = dseg_addaddress ((void*) super->vftbl);
3413                                         M_ALD(REG_ITMP2, REG_PV, a);
3414                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3415                                         M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
3416                                         M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3417                                         M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3418                                         M_CMPULE(REG_ITMP1, REG_ITMP2, d);
3419                                         }
3420                                 }
3421                         else
3422                                 panic ("internal error: no inlined array instanceof");
3423                         }
3424                         store_reg_to_var_int(iptr->dst, d);
3425                         break;
3426
3427                 case ICMD_CHECKCAST:  /* ..., objectref ==> ..., objectref            */
3428
3429                                       /* op1:   0 == array, 1 == class                */
3430                                       /* val.a: (classinfo*) superclass               */
3431
3432 /*          superclass is an interface:
3433  *
3434  *          OK if ((sub == NULL) ||
3435  *                 (sub->vftbl->interfacetablelength > super->index) &&
3436  *                 (sub->vftbl->interfacetable[-super->index] != NULL));
3437  *
3438  *          superclass is a class:
3439  *
3440  *          OK if ((sub == NULL) || (0
3441  *                 <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3442  *                 super->vftbl->diffvall));
3443  */
3444
3445                         {
3446                         classinfo *super = (classinfo*) iptr->val.a;
3447                         
3448                         d = reg_of_var(iptr->dst, REG_ITMP3);
3449                         var_to_reg_int(s1, src, d);
3450                         if (iptr->op1) {                               /* class/interface */
3451                                 if (super->flags & ACC_INTERFACE) {        /* interface       */
3452                                         M_BEQZ(s1, 6);
3453                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3454                                         M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
3455                                         M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
3456                                         M_BLEZ(REG_ITMP2, 0);
3457                                         codegen_addxcastrefs(mcodeptr);
3458                                         M_ALD(REG_ITMP2, REG_ITMP1,
3459                                               OFFSET(vftbl, interfacetable[0]) -
3460                                               super->index * sizeof(methodptr*));
3461                                         M_BEQZ(REG_ITMP2, 0);
3462                                         codegen_addxcastrefs(mcodeptr);
3463                                         }
3464                                 else {                                     /* class           */
3465 /*
3466                                         s2 = super->vftbl->diffval;
3467                                         M_BEQZ(s1, 4 + (s2 != 0) + (s2 > 255));
3468                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3469                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3470                                         M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
3471                                         if (s2 == 0) {
3472                                                 M_BNEZ(REG_ITMP1, 0);
3473                                                 }
3474                                         else if (s2 <= 255) {
3475                                                 M_CMPULE_IMM(REG_ITMP1, s2, REG_ITMP2);
3476                                                 M_BEQZ(REG_ITMP2, 0);
3477                                                 }
3478                                         else {
3479                                                 M_LDA(REG_ITMP2, REG_ZERO, s2);
3480                                                 M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
3481                                                 M_BEQZ(REG_ITMP2, 0);
3482                                                 }
3483 */
3484                                         M_BEQZ(s1, 8 + (d == REG_ITMP3));
3485                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3486                                         a = dseg_addaddress ((void*) super->vftbl);
3487                                         M_ALD(REG_ITMP2, REG_PV, a);
3488                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3489                                         if (d != REG_ITMP3) {
3490                                                 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
3491                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3492                                                 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3493                                                 }
3494                                         else {
3495                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, baseval));
3496                                                 M_ISUB(REG_ITMP1, REG_ITMP2, REG_ITMP1);
3497                                                 M_ALD(REG_ITMP2, REG_PV, a);
3498                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3499                                                 }
3500                                         M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
3501                                         M_BEQZ(REG_ITMP2, 0);
3502                                         codegen_addxcastrefs(mcodeptr);
3503                                         }
3504                                 }
3505                         else
3506                                 panic ("internal error: no inlined array checkcast");
3507                         }
3508                         M_INTMOVE(s1, d);
3509                         store_reg_to_var_int(iptr->dst, d);
3510                         break;
3511
3512                 case ICMD_CHECKASIZE:  /* ..., size ==> ..., size                     */
3513
3514                         var_to_reg_int(s1, src, REG_ITMP1);
3515                         M_BLTZ(s1, 0);
3516                         codegen_addxcheckarefs(mcodeptr);
3517                         break;
3518
3519                 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
3520                                       /* op1 = dimension, val.a = array descriptor    */
3521
3522                         /* check for negative sizes and copy sizes to stack if necessary  */
3523
3524                         MCODECHECK((iptr->op1 << 1) + 64);
3525
3526                         for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3527                                 var_to_reg_int(s2, src, REG_ITMP1);
3528                                 M_BLTZ(s2, 0);
3529                                 codegen_addxcheckarefs(mcodeptr);
3530
3531                                 /* copy sizes to stack (argument numbers >= INT_ARG_CNT)      */
3532
3533                                 if (src->varkind != ARGVAR) {
3534                                         M_LST(s2, REG_SP, 8 * (s1 + INT_ARG_CNT));
3535                                         }
3536                                 }
3537
3538                         /* a0 = dimension count */
3539
3540                         ICONST(argintregs[0], iptr->op1);
3541
3542                         /* a1 = arraydescriptor */
3543
3544                         a = dseg_addaddress(iptr->val.a);
3545                         M_ALD(argintregs[1], REG_PV, a);
3546
3547                         /* a2 = pointer to dimensions = stack pointer */
3548
3549                         M_INTMOVE(REG_SP, argintregs[2]);
3550
3551                         a = dseg_addaddress((void*) (builtin_nmultianewarray));
3552                         M_ALD(REG_PV, REG_PV, a);
3553                         M_JSR(REG_RA, REG_PV);
3554                         s1 = (int)((u1*) mcodeptr - mcodebase);
3555                         if (s1 <= 32768)
3556                                 M_LDA (REG_PV, REG_RA, -s1);
3557                         else {
3558                                 s4 ml = -s1, mh = 0;
3559                                 while (ml < -32768) {ml += 65536; mh--;}
3560                                 M_LDA(REG_PV, REG_RA, ml);
3561                                 M_LDAH(REG_PV, REG_PV, mh);
3562                             }
3563                         s1 = reg_of_var(iptr->dst, REG_RESULT);
3564                         M_INTMOVE(REG_RESULT, s1);
3565                         store_reg_to_var_int(iptr->dst, s1);
3566                         break;
3567
3568
3569                 default: error ("Unknown pseudo command: %d", iptr->opc);
3570         
3571    
3572
3573         } /* switch */
3574                 
3575         } /* for instruction */
3576                 
3577         /* copy values to interface registers */
3578
3579         src = bptr->outstack;
3580         len = bptr->outdepth;
3581         MCODECHECK(64+len);
3582         while (src) {
3583                 len--;
3584                 if ((src->varkind != STACKVAR)) {
3585                         s2 = src->type;
3586                         if (IS_FLT_DBL_TYPE(s2)) {
3587                                 var_to_reg_flt(s1, src, REG_FTMP1);
3588                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
3589                                         M_FLTMOVE(s1,interfaces[len][s2].regoff);
3590                                         }
3591                                 else {
3592                                         M_DST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
3593                                         }
3594                                 }
3595                         else {
3596                                 var_to_reg_int(s1, src, REG_ITMP1);
3597                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
3598                                         M_INTMOVE(s1,interfaces[len][s2].regoff);
3599                                         }
3600                                 else {
3601                                         M_LST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
3602                                         }
3603                                 }
3604                         }
3605                 src = src->prev;
3606                 }
3607         } /* if (bptr -> flags >= BBREACHED) */
3608         } /* for basic block */
3609
3610         /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */
3611
3612         {
3613         /* generate bound check stubs */
3614
3615         s4 *xcodeptr = NULL;
3616         
3617         for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
3618                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3619                         gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
3620                                 xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3621                         continue;
3622                         }
3623
3624
3625                 gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
3626                                   xboundrefs->branchpos, (u1*) mcodeptr - mcodebase);
3627
3628                 MCODECHECK(8);
3629
3630                 M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
3631
3632                 if (xcodeptr != NULL) {
3633                         int disp = (xcodeptr-mcodeptr)-1;
3634                         M_BR(disp);
3635                         }
3636                 else {
3637                         xcodeptr = mcodeptr;
3638
3639                         a = dseg_addaddress(proto_java_lang_ArrayIndexOutOfBoundsException);
3640                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3641
3642                         a = dseg_addaddress(asm_handle_exception);
3643                         M_ALD(REG_ITMP3, REG_PV, a);
3644
3645                         M_JMP(REG_ZERO, REG_ITMP3);
3646                         }
3647                 }
3648
3649         /* generate negative array size check stubs */
3650
3651         xcodeptr = NULL;
3652         
3653         for (; xcheckarefs != NULL; xcheckarefs = xcheckarefs->next) {
3654                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3655                         gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
3656                                 xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3657                         continue;
3658                         }
3659
3660                 gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
3661                                   xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase);
3662
3663                 MCODECHECK(8);
3664
3665                 M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
3666
3667                 if (xcodeptr != NULL) {
3668                         int disp = (xcodeptr-mcodeptr)-1;
3669                         M_BR(disp);
3670                         }
3671                 else {
3672                         xcodeptr = mcodeptr;
3673
3674                         a = dseg_addaddress(proto_java_lang_NegativeArraySizeException);
3675                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3676
3677                         a = dseg_addaddress(asm_handle_exception);
3678                         M_ALD(REG_ITMP3, REG_PV, a);
3679
3680                         M_JMP(REG_ZERO, REG_ITMP3);
3681                         }
3682                 }
3683
3684         /* generate cast check stubs */
3685
3686         xcodeptr = NULL;
3687         
3688         for (; xcastrefs != NULL; xcastrefs = xcastrefs->next) {
3689                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3690                         gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
3691                                 xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3692                         continue;
3693                         }
3694
3695                 gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
3696                                   xcastrefs->branchpos, (u1*) mcodeptr - mcodebase);
3697
3698                 MCODECHECK(8);
3699
3700                 M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
3701
3702                 if (xcodeptr != NULL) {
3703                         int disp = (xcodeptr-mcodeptr)-1;
3704                         M_BR(disp);
3705                         }
3706                 else {
3707                         xcodeptr = mcodeptr;
3708
3709                         a = dseg_addaddress(proto_java_lang_ClassCastException);
3710                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3711
3712                         a = dseg_addaddress(asm_handle_exception);
3713                         M_ALD(REG_ITMP3, REG_PV, a);
3714
3715                         M_JMP(REG_ZERO, REG_ITMP3);
3716                         }
3717                 }
3718
3719
3720 #ifdef SOFTNULLPTRCHECK
3721
3722         /* generate null pointer check stubs */
3723
3724         xcodeptr = NULL;
3725
3726         for (; xnullrefs != NULL; xnullrefs = xnullrefs->next) {
3727                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3728                         gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
3729                                 xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3730                         continue;
3731                         }
3732
3733                 gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
3734                                   xnullrefs->branchpos, (u1*) mcodeptr - mcodebase);
3735
3736                 MCODECHECK(8);
3737
3738                 M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
3739
3740                 if (xcodeptr != NULL) {
3741                         int disp = (xcodeptr-mcodeptr)-1;
3742                         M_BR(disp);
3743                         }
3744                 else {
3745                         xcodeptr = mcodeptr;
3746
3747                         a = dseg_addaddress(proto_java_lang_NullPointerException);
3748                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3749
3750                         a = dseg_addaddress(asm_handle_exception);
3751                         M_ALD(REG_ITMP3, REG_PV, a);
3752
3753                         M_JMP(REG_ZERO, REG_ITMP3);
3754                         }
3755                 }
3756
3757 #endif
3758         }
3759
3760         codegen_finish((int)((u1*) mcodeptr - mcodebase));
3761 }
3762
3763
3764 /* redefinition of code generation macros (compiling into array) **************/
3765
3766 /* 
3767 These macros are newly defined to allow code generation into an array.
3768 This is necessary, because the original M_.. macros generate code by
3769 calling 'codegen_adds4' that uses an additional data structure to
3770 receive the code.
3771
3772 For a faster (but less flexible) version to generate code, these
3773 macros directly use the (s4* p) - pointer to put the code directly
3774 in a locally defined array.
3775 This makes sense only for the stub-generation-routines below.
3776 */
3777
3778 #undef M_OP3
3779 #define M_OP3(op,fu,a,b,c,const) \
3780         *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<(16-3*(const)))| \
3781         ((const)<<12)|((fu)<<5)|((c)) )
3782 #undef M_FOP3
3783 #define M_FOP3(op,fu,a,b,c) \
3784         *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<16)|((fu)<<5)|(c) )
3785 #undef M_BRA
3786 #define M_BRA(op,a,disp) \
3787         *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((disp)&0x1fffff) )
3788 #undef M_MEM
3789 #define M_MEM(op,a,b,disp) \
3790         *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<16)|((disp)&0xffff) )
3791
3792
3793 /* function createcompilerstub *************************************************
3794
3795         creates a stub routine which calls the compiler
3796         
3797 *******************************************************************************/
3798
3799 #define COMPSTUBSIZE 3
3800
3801 u1 *createcompilerstub (methodinfo *m)
3802 {
3803         u8 *s = CNEW (u8, COMPSTUBSIZE);    /* memory to hold the stub            */
3804         s4 *p = (s4*) s;                    /* code generation pointer            */
3805         
3806                                             /* code for the stub                  */
3807         M_ALD (REG_PV, REG_PV, 16);         /* load pointer to the compiler       */
3808         M_JMP (0, REG_PV);                  /* jump to the compiler, return address
3809                                                in reg 0 is used as method pointer */
3810         s[1] = (u8) m;                      /* literals to be adressed            */  
3811         s[2] = (u8) asm_call_jit_compiler;  /* jump directly via PV from above    */
3812
3813 #ifdef STATISTICS
3814         count_cstub_len += COMPSTUBSIZE * 8;
3815 #endif
3816
3817         return (u1*) s;
3818 }
3819
3820
3821 /* function removecompilerstub *************************************************
3822
3823      deletes a compilerstub from memory  (simply by freeing it)
3824
3825 *******************************************************************************/
3826
3827 void removecompilerstub (u1 *stub) 
3828 {
3829         CFREE (stub, COMPSTUBSIZE * 8);
3830 }
3831
3832
3833 bool isFloat(char **utf_ptr,char *desc_end)
3834 {
3835     char c;
3836
3837     if (*utf_ptr>=desc_end)
3838         panic("illegal methoddescriptor (isFloat)");
3839     switch (c=utf_nextu2(utf_ptr)) {
3840       case 'L' : {
3841                     while (utf_nextu2(utf_ptr)!=';');
3842                  }
3843       case 'I' :
3844       case 'J' :
3845       case 'B' :
3846       case 'C' :
3847       case 'S' :
3848       case 'Z' :
3849       case 'V' :
3850                 return 0;
3851
3852       case 'F' : 
3853       case 'D' : 
3854                 return 1;
3855
3856       case '[' : {
3857                     /* arrayclass */
3858                     char ch;
3859
3860                     while ((ch = utf_nextu2(utf_ptr))=='[')
3861                         /* skip */ ;
3862
3863                     if (ch == 'L') {
3864                         while (utf_nextu2(utf_ptr)!=';')
3865                             /* skip */ ;
3866                     }
3867
3868                         return 0;
3869                 }
3870      default:
3871                 printf("CHAR: %c\n",c);
3872                 panic ("illegal methoddescriptor(isFloat)");
3873         }
3874
3875     return 0;
3876 }
3877
3878
3879 u4 ngen_get_parametercount(methodinfo *m)
3880 {
3881     utf  *descr    =  m->descriptor;    /* method-descriptor */
3882     char *utf_ptr  =  descr->text;      /* current position in utf-text */
3883     char *desc_end =  utf_end(descr);   /* points behind utf string     */
3884     java_objectarray* result;
3885     int parametercount = 0;
3886    int i;
3887
3888     /* skip '(' */
3889     utf_nextu2(&utf_ptr);
3890
3891     /* determine number of parameters */
3892     while ( *utf_ptr != ')' ) {
3893         isFloat(&utf_ptr,desc_end);
3894         parametercount++;
3895     }
3896
3897     return parametercount;
3898 }
3899
3900
3901 /* function: createnativestub **************************************************
3902
3903         creates a stub routine which calls a native method
3904
3905 *******************************************************************************/
3906
3907 #define NATIVESTUBSIZE 35
3908 #define NATIVESTUBOFFSET 9
3909
3910 int runverbosenat = 1;
3911
3912 u1 *createnativestub (functionptr f, methodinfo *m)
3913 {
3914         int disp;
3915         int regoffset=0;
3916         int paramsOnStack=0;
3917         int paramCount=0;
3918         int paramsStillToMove=0;
3919         int paramTargetOffset=0;
3920         int paramSourceOffset=0;
3921         int i;
3922         u8 *s = CNEW (u8, (NATIVESTUBSIZE));  /* memory to hold the stub            */
3923         u8 *cs = s + NATIVESTUBOFFSET;
3924         s4 *p = (s4*) (cs);                 /* code generation pointer            */
3925
3926     utf  *descr    =  m->descriptor;    /* method-descriptor */
3927     char *utf_ptr  =  descr->text;      /* current position in utf-text */
3928     char *desc_end =  utf_end(descr);   /* points behind utf string     */
3929
3930
3931
3932         *(cs-1) = (u8) f;                   /* address of native method           */
3933         *(cs-2) = (u8) (&exceptionptr);     /* address of exceptionptr            */
3934         *(cs-3) = (u8) asm_handle_nat_exception; /* addr of asm exception handler */
3935         *(cs-4) = (u8) (&env);              /* addr of jni_environement           */
3936         *(cs-5) = (u8) asm_builtin_trace;
3937         *(cs-6) = (u8) m;
3938         *(cs-7) = (u8) asm_builtin_exittrace;
3939         *(cs-8) = (u8) builtin_trace_exception;
3940         *(cs-9) = (u8) m->class;
3941
3942
3943
3944
3945
3946 #if 1
3947         printf("stub: ");
3948         utf_display(m->class->name);
3949         printf(".");
3950         utf_display(m->name);
3951         printf(" 0x%p\n", cs);
3952 #endif
3953
3954         M_LDA  (REG_SP, REG_SP, -8);        /* build up stackframe                */
3955         M_AST  (REG_RA, REG_SP, 0);         /* store return address               */
3956
3957 #if 1
3958         if (runverbosenat) {
3959                 M_ALD(REG_ITMP1, REG_PV, -6*8);
3960                 M_ALD(REG_PV, REG_PV, -5*8);
3961
3962                 M_JSR(REG_RA, REG_PV);
3963                 disp = -(int) (p - (s4*) cs)*4;
3964                 M_LDA(REG_PV, REG_RA, disp);
3965         }
3966 #endif
3967
3968         reg_init(m);
3969
3970         utf_display(m->descriptor);
3971
3972         paramCount=ngen_get_parametercount(m);
3973
3974
3975         paramsOnStack=paramCount-(6/*paramregs*/ -1/*env*/ - ((m->flags & ACC_STATIC)?1:0));
3976         paramsStillToMove=paramsOnStack;
3977         if (paramsOnStack>0)
3978                 M_LDA(REG_SP,REG_SP,-8*paramsOnStack);
3979
3980         if (m->flags & ACC_STATIC) {
3981                 regoffset=1;
3982                         if (paramsOnStack>0) {
3983                                 utf_nextu2(&utf_ptr);
3984                                 for (i=0;i<4;i++)
3985                                         isFloat(&utf_ptr,desc_end);
3986
3987                                 if (isFloat(&utf_ptr,desc_end))
3988                                         M_DST  (argfltregs[4], REG_SP, 0);
3989                                 else
3990                                         M_LST  (argintregs[4], REG_SP, 0);
3991
3992                         if (paramsOnStack>1)
3993                                 if (isFloat(&utf_ptr,desc_end))
3994                                         M_DST  (argfltregs[5], REG_SP, 8);
3995                                 else
3996                                         M_LST  (argintregs[5], REG_SP, 8);
3997                         }
3998                         paramsStillToMove -=2;
3999                         paramTargetOffset=16;
4000
4001
4002         }
4003         else {
4004                 if (paramsOnStack>0) {
4005                         utf_nextu2(&utf_ptr);
4006                         for (i=0;i<5;i++)
4007                                 isFloat(&utf_ptr,desc_end);
4008
4009                         if (isFloat(&utf_ptr,desc_end))
4010                                 M_DST  (argfltregs[5], REG_SP, 0);
4011                         else
4012                                 M_LST  (argintregs[5], REG_SP, 0);
4013                         paramsStillToMove -=1;
4014                         paramTargetOffset = 8;
4015                 }
4016                 M_MOV  (argintregs[4],argintregs[5]); 
4017                 M_FMOV (argfltregs[4],argfltregs[5]);
4018         }
4019         M_MOV  (argintregs[3],argintregs[4+regoffset]);
4020         M_FMOV (argfltregs[3],argfltregs[4+regoffset]);
4021
4022         M_MOV  (argintregs[2],argintregs[3+regoffset]);
4023         M_FMOV (argfltregs[2],argfltregs[3+regoffset]);
4024
4025         M_MOV  (argintregs[1],argintregs[2+regoffset]);
4026         M_FMOV (argfltregs[1],argfltregs[2+regoffset]);
4027
4028         M_MOV  (argintregs[0],argintregs[1+regoffset]);
4029         M_FMOV (argfltregs[0],argfltregs[1+regoffset]);
4030
4031         if (m->flags & ACC_STATIC) {
4032                 M_ALD  (argintregs[1],REG_PV,  -9*8);/* class adress */
4033         }
4034
4035         paramSourceOffset=8*paramsOnStack+9;
4036         for (i=0;i<paramsStillToMove;i++) {
4037                 if (isFloat(&utf_ptr,desc_end)) {
4038                         M_DLD(REG_ITMP1,REG_SP,paramSourceOffset);
4039                         M_DST  (REG_ITMP1, REG_SP, paramTargetOffset);
4040                 } else {
4041                         M_ALD(REG_ITMP1,REG_SP,paramSourceOffset);
4042                         M_LST  (REG_ITMP1, REG_SP, paramTargetOffset);
4043                 }
4044                 paramSourceOffset+=8;
4045                 paramTargetOffset+=8;
4046         }
4047
4048         M_ALD  (argintregs[0], REG_PV, -4*8);/* load adress of jni_environement   */
4049
4050         M_ALD  (REG_PV, REG_PV, -1*8);      /* load adress of native method       */
4051
4052
4053         M_JSR  (REG_RA, REG_PV);            /* call native method                 */
4054
4055         disp = -(int) (p - (s4*) cs)*4;
4056         M_LDA  (REG_PV, REG_RA, disp);      /* recompute pv from ra               */
4057         M_ALD  (REG_ITMP3, REG_PV, -2*8);   /* get address of exceptionptr        */
4058
4059         M_ALD  (REG_ITMP1, REG_ITMP3, 0);   /* load exception into reg. itmp1     */
4060
4061         if (paramsOnStack>0)
4062                 M_LDA(REG_SP,REG_SP,8*paramsOnStack);
4063
4064
4065         M_BNEZ (REG_ITMP1,
4066                         3 + (runverbosenat ? 6 : 0));  /* if no exception then return        */
4067
4068 #if 1
4069         if (runverbosenat) {
4070                 M_ALD(argintregs[0], REG_PV, -6*8);
4071                 M_MOV(REG_RESULT, argintregs[1]);
4072                 M_FMOV(REG_FRESULT, argfltregs[2]);
4073                 M_FMOV(REG_FRESULT, argfltregs[3]);
4074                 M_ALD(REG_PV, REG_PV, -7*8);
4075                 M_JSR(REG_RA, REG_PV);
4076         }
4077 #endif
4078
4079         M_ALD  (REG_RA, REG_SP, 0);         /* load return address                */
4080         M_LDA  (REG_SP, REG_SP, 8);         /* remove stackframe                  */
4081
4082         M_RET  (REG_ZERO, REG_RA);          /* return to caller                   */
4083         
4084         M_AST  (REG_ZERO, REG_ITMP3, 0);    /* store NULL into exceptionptr       */
4085
4086 #if 1
4087         if (runverbosenat) {
4088                 M_LDA(REG_SP, REG_SP, -9);
4089                 M_AST(REG_ITMP1, REG_SP, 0);
4090                 M_MOV(REG_ITMP1, argintregs[0]);
4091                 M_ALD(argintregs[1], REG_PV, -6*8);
4092                 M_ALD(argintregs[2], REG_SP, 0);
4093                 M_CLR(argintregs[3]);
4094                 M_ALD(REG_PV, REG_PV, -8*8);
4095                 M_JSR(REG_RA, REG_PV);
4096                 disp = -(int) (p - (s4*) cs)*4;
4097                 M_LDA  (REG_PV, REG_RA, disp);
4098                 M_ALD(REG_ITMP1, REG_SP, 0);
4099                 M_LDA(REG_SP, REG_SP, 9);
4100         }
4101 #endif
4102
4103         M_ALD  (REG_RA, REG_SP, 0);         /* load return address                */
4104         M_LDA  (REG_SP, REG_SP, 8);         /* remove stackframe                  */
4105
4106         M_LDA  (REG_ITMP2, REG_RA, -4);     /* move fault address into reg. itmp2 */
4107
4108         M_ALD  (REG_ITMP3, REG_PV, -3*8);   /* load asm exception handler address */
4109         M_JMP  (REG_ZERO, REG_ITMP3);       /* jump to asm exception handler      */
4110         
4111 #if 1
4112         {
4113                 static int stubprinted;
4114                 if (!stubprinted)
4115                         printf("stubsize: %d/2\n", (int) (p - (s4*) s));
4116                 stubprinted = 1;
4117         }
4118 #endif
4119
4120 #ifdef STATISTICS
4121         count_nstub_len += NATIVESTUBSIZE * 8;
4122 #endif
4123
4124         return (u1*) (s + NATIVESTUBOFFSET);
4125 }
4126
4127 /* function: removenativestub **************************************************
4128
4129     removes a previously created native-stub from memory
4130     
4131 *******************************************************************************/
4132
4133 void removenativestub (u1 *stub)
4134 {
4135         CFREE ((u8*) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8);
4136 }
4137
4138
4139 /*
4140  * These are local overrides for various environment variables in Emacs.
4141  * Please do not remove this and leave it at the end of the file, where
4142  * Emacs will automagically detect them.
4143  * ---------------------------------------------------------------------
4144  * Local variables:
4145  * mode: c
4146  * indent-tabs-mode: t
4147  * c-basic-offset: 4
4148  * tab-width: 4
4149  * End:
4150  */