Merged revisions 7797-7917 via svnmerge from
[cacao.git] / src / vm / jit / m68k / emit.c
1 /* src/vm/jit/m68k/emit.c
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: arch.h 5330 2006-09-05 18:43:12Z edwin $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33
34 #include "emit.h"
35 #include "vm/jit/emit-common.h"
36 #include "vm/exceptions.h"
37 #include "vm/jit/asmpart.h"
38 #include "vm/builtin.h"
39
40 #include "mm/memory.h"
41
42 #include "threads/lock-common.h"
43
44 #include "codegen.h"
45 #include "md-os.h"
46
47 /* emit_mov_imm_reg **************************************************************************
48  *
49  *      Loads an immededat operand into an integer data register
50  *
51  ********************************************************************************************/
52 void emit_mov_imm_reg (codegendata *cd, s4 imm, s4 dreg)
53 {
54         /* FIXME: -1 can be used as byte form 0xff, but this ifs cascade is plain wrong it seems */
55
56         if ( (imm & 0x0000007F) == imm) {
57                 /* use byte form */
58                 *((s2*)cd->mcodeptr) = 0x7000 | (dreg << 9) | imm;      /* MOVEQ.L */
59                 cd->mcodeptr += 2;
60         } else if ((imm  & 0x00007FFF) == imm)  {
61                 /* use word form */
62                 OPWORD( ((7<<6) | (dreg << 3) | 5), 7, 4);                      /* MVS.W */
63                 *((s2*)cd->mcodeptr) = (s2)imm;
64                 cd->mcodeptr += 2;
65         } else {
66                 /* use long form */
67                 OPWORD( ((2<<6) | (dreg << 3) | 0), 7, 4);
68                 *((s4*)cd->mcodeptr) = (s4)imm;
69                 cd->mcodeptr += 4;
70
71         }
72 }
73
74 /* emit_copy *******************************************************************
75
76    Generates a register/memory to register/memory copy.
77
78 *******************************************************************************/
79
80 void emit_copy(jitdata *jd, instruction *iptr)
81 {
82         codegendata *cd;
83         varinfo     *src;
84         varinfo     *dst;
85         s4           s1, d;
86
87         /* get required compiler data */
88
89         cd = jd->cd;
90
91         /* get source and destination variables */
92
93         src = VAROP(iptr->s1);
94         dst = VAROP(iptr->dst);
95
96         if ((src->vv.regoff != dst->vv.regoff) ||
97                 (IS_INMEMORY(src->flags ^ dst->flags))) {
98
99                 if ((src->type == TYPE_RET) || (dst->type == TYPE_RET)) {
100                         /* emit nothing, as the value won't be used anyway */
101                         return;
102                 }
103
104                 /* If one of the variables resides in memory, we can eliminate
105                    the register move from/to the temporary register with the
106                    order of getting the destination register and the load. */
107
108                 if (IS_INMEMORY(src->flags)) {
109                         if (IS_LNG_TYPE(src->type))
110                                 d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP12_PACKED);
111                         else
112                                 d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
113
114                         s1 = emit_load(jd, iptr, src, d);
115                 }
116                 else {
117                         if (IS_LNG_TYPE(src->type))
118                                 s1 = emit_load(jd, iptr, src, REG_ITMP12_PACKED);
119                         else
120                                 s1 = emit_load(jd, iptr, src, REG_IFTMP);
121
122                         d = codegen_reg_of_var(iptr->opc, dst, s1);
123                 }
124
125                 if (s1 != d) {
126                         switch(src->type)       {
127                         case TYPE_INT: M_INTMOVE(s1, d); break;
128                         case TYPE_ADR: M_ADRMOVE(s1, d); break;
129                         case TYPE_LNG: M_LNGMOVE(s1, d); break;
130 #if !defined(ENABLE_SOFTFLOAT)
131                         case TYPE_FLT: M_FLTMOVE(s1, d); break;
132                         case TYPE_DBL: M_DBLMOVE(s1, d); break;
133 #else
134                         case TYPE_FLT: M_INTMOVE(s1, d); break;
135                         case TYPE_DBL: M_LNGMOVE(s1, d); break;
136 #endif
137                         default:
138                                 vm_abort("emit_copy: unknown type %d", src->type);
139                         }
140                 }
141
142                 emit_store(jd, iptr, dst, d);
143         }
144 }
145
146
147 /* emit_store ******************************************************************
148
149    Emits a possible store of the destination operand.
150
151 *******************************************************************************/
152
153 inline void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
154 {
155         codegendata  *cd;
156
157         /* get required compiler data */
158
159         cd = jd->cd;
160
161         if (IS_INMEMORY(dst->flags)) {
162                 COUNT_SPILLS;
163         
164                 switch(dst->type)       {
165 #if defined(ENABLE_SOFTFLOAT)
166                         case TYPE_DBL:
167 #endif
168                         case TYPE_LNG:
169                                 M_LST(d, REG_SP, dst->vv.regoff * 4);
170                                 break;
171 #if defined(ENABLE_SOFTFLOAT)
172                         case TYPE_FLT:
173 #endif
174                         case TYPE_INT:
175                                 M_IST(d, REG_SP, dst->vv.regoff * 4);
176                                 break;
177                         case TYPE_ADR:
178                                 M_AST(d, REG_SP, dst->vv.regoff * 4);
179                                 break;
180 #if !defined(ENABLE_SOFTFLOAT)
181                         case TYPE_DBL:
182                                 M_DST(d, REG_SP, dst->vv.regoff * 4);
183                                 break;
184                         case TYPE_FLT:
185                                 M_FST(d, REG_SP, dst->vv.regoff * 4);
186                                 break;
187 #endif
188                         default:
189                                 vm_abort("emit_store: unknown type %d", dst->type);
190                 }
191         }
192 }
193
194
195 /* emit_load *******************************************************************
196
197    Emits a possible load of an operand.
198
199 *******************************************************************************/
200
201 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
202 {
203         codegendata *cd;
204         s4           disp;
205         s4           reg;
206
207         /* get required compiler data */
208
209         cd = jd->cd;
210
211         if (IS_INMEMORY(src->flags)) {
212                 COUNT_SPILLS;
213
214                 disp = src->vv.regoff * 4;
215         
216                 switch (src->type)      {
217 #if defined(ENABLE_SOFTFLOAT)
218                         case TYPE_FLT:
219 #endif
220                         case TYPE_INT: 
221                                 M_ILD(tempreg, REG_SP, disp);
222                                 break;
223 #if defined(ENABLE_SOFTFLOAT)
224                         case TYPE_DBL:
225 #endif
226                         case TYPE_LNG:
227                                 M_LLD(tempreg, REG_SP, disp);
228                                 break;
229                         case TYPE_ADR:
230                                 M_ALD(tempreg, REG_SP, disp);
231                                 break;
232 #if !defined(ENABLE_SOFTFLOAT)
233                         case TYPE_FLT:
234                                 M_FLD(tempreg, REG_SP, disp);
235                                 break;
236                         case TYPE_DBL:
237                                 M_DLD(tempreg, REG_SP, disp);
238                                 break;
239 #endif
240                         default:
241                                 vm_abort("emit_load: unknown type %d", src->type);
242                 }
243                 #if 0
244                 if (IS_FLT_DBL_TYPE(src->type)) {
245                         if (IS_2_WORD_TYPE(src->type)) {
246                                 M_DLD(tempreg, REG_SP, disp);
247                          } else {
248                                 M_FLD(tempreg, REG_SP, disp);
249                         }
250                 } else {
251                         if (IS_2_WORD_TYPE(src->type)) {
252                                 M_LLD(tempreg, REG_SP, disp);
253                         } else {
254                                 M_ILD(tempreg, REG_SP, disp);
255                         }
256                 }
257                 #endif
258
259                 reg = tempreg;
260         }
261         else
262                 reg = src->vv.regoff;
263
264         return reg;
265 }
266
267
268 /* emit_patcher_stubs **********************************************************
269
270    Generates the code for the patcher stubs.
271
272 *******************************************************************************/
273 void emit_patcher_stubs(jitdata *jd)
274 {
275         codegendata *cd;
276         patchref    *pref;
277         u8           mcode;
278         u1          *savedmcodeptr;
279         u1          *tmpmcodeptr;
280         s4           targetdisp;
281         s4           disp;
282
283         /* get required compiler data */
284
285         cd = jd->cd;
286
287         /* generate code patching stub call code */
288
289         targetdisp = 0;
290
291         for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
292                 /* check code segment size */
293
294                 MCODECHECK(512);
295
296                 /* Get machine code which is patched back in later. A
297                    `bsr.l' is 6 bytes long. */
298
299                 savedmcodeptr = cd->mcodebase + pref->branchpos;
300                 mcode = *((u8 *) savedmcodeptr);
301
302                 /* patch in `bsr.l' to call the following code */
303
304                 tmpmcodeptr  = cd->mcodeptr;    /* save current mcodeptr              */
305                 cd->mcodeptr = savedmcodeptr;   /* set mcodeptr to patch position     */
306
307                 M_BSR_IMM(tmpmcodeptr - (savedmcodeptr + PATCHER_CALL_SIZE) + 4);
308
309                 cd->mcodeptr = tmpmcodeptr;     /* restore the current mcodeptr       */
310
311                 /* save REG_ITMP3, restored in asm_patcher_wrapper  */
312                 M_IPUSH(REG_ITMP3);             
313
314                 /* move pointer to java_objectheader onto stack */
315
316 #if defined(ENABLE_THREADS)
317                 (void) dseg_add_unique_address(cd, NULL);                  /* flcword */
318                 (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
319                 disp = dseg_add_unique_address(cd, NULL);                  /* vftbl   */
320
321                 M_IMOV_IMM32(0, REG_ITMP3);
322                 dseg_adddata(cd);
323                 M_IADD_IMM(disp, REG_ITMP3);
324                 M_IPUSH(REG_ITMP3);
325 #else
326                 M_IPUSH_IMM(0);
327 #endif
328
329                 /* push move machine code bytes and classinfo pointer */
330
331                 M_IPUSH_IMM(mcode >> 32);
332                 M_IPUSH_IMM(mcode);
333                 M_IPUSH_IMM(pref->ref);
334                 M_IPUSH_IMM(pref->patcher);
335
336                 M_JMP_IMM(asm_patcher_wrapper);
337         }
338 }
339 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg) 
340 {
341         codegendata  *cd;
342         s4            disp;
343         s4            reg;
344
345 #if !defined(ENABLE_SOFTFLOAT)
346         assert(src->type == TYPE_LNG);
347 #else
348         assert(src->type == TYPE_LNG || src->type == TYPE_DBL);
349 #endif
350
351         /* get required compiler data */
352         cd = jd->cd;
353
354         if (IS_INMEMORY(src->flags)) {
355                 COUNT_SPILLS;
356
357                 disp = src->vv.regoff * 4;
358                 M_ILD(tempreg, REG_SP, disp + 4);
359                 reg = tempreg;
360         } else {
361                 reg = GET_LOW_REG(src->vv.regoff);
362         }
363         return reg;
364 }
365 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
366 {
367         codegendata  *cd;
368         s4            disp;
369         s4            reg;
370
371 #if !defined(ENABLE_SOFTFLOAT)
372         assert(src->type == TYPE_LNG);
373 #else
374         assert(src->type == TYPE_LNG || src->type == TYPE_DBL);
375 #endif
376         /* get required compiler data */
377         cd = jd->cd;
378
379         if (IS_INMEMORY(src->flags)) {
380                 COUNT_SPILLS;
381                 disp = src->vv.regoff * 4;
382                 M_ILD(tempreg, REG_SP, disp);
383                 reg = tempreg;
384         } else {
385                 reg = GET_HIGH_REG(src->vv.regoff);
386         }
387         return reg;
388 }
389 /* emit_branch *****************************************************************
390
391    Emits the code for conditional and unconditional branchs.
392
393 *******************************************************************************/
394 void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt) 
395
396         /* calculate the different displacements */
397         /* PC is a at branch instruction + 2 */
398         /* coditional and uncondition branching work the same way */
399         /* short branches have signed 16 bit offset */
400         /* long branches are signed 32 bit */
401         /* the 8 bit offset branching instructions are not used */
402
403         disp  =  disp - 2;
404
405         /* check displacement for overflow */
406         if ((disp & 0x0000FFFF) != disp)        {
407                 if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
408                         cd->flags |= (CODEGENDATA_FLAG_ERROR | CODEGENDATA_FLAG_LONGBRANCHES);
409                 }
410         }
411
412         /* check which branch to generate */
413
414         if (condition == BRANCH_UNCONDITIONAL) {
415                 if (CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd))      {
416                         M_BR_32(disp);
417                 } else  {
418                         M_BR_16(disp);
419                 }
420         } else {
421                 if (CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
422                         switch (condition) {
423                         case BRANCH_EQ:
424                                 M_BEQ_32(disp);
425                                 break;
426                         case BRANCH_NE:
427                                 M_BNE_32(disp);
428                                 break;
429                         case BRANCH_LT:
430                                 M_BLT_32(disp);
431                                 break;
432                         case BRANCH_GE:
433                                 M_BGE_32(disp);
434                                 break;
435                         case BRANCH_GT:
436                                 M_BGT_32(disp);
437                                 break;
438                         case BRANCH_LE:
439                                 M_BLE_32(disp);
440                                 break;
441                         case BRANCH_NAN:
442                                 M_BNAN_32(disp);
443                                 break;
444                         case BRANCH_UGT:
445                                 M_BHI_32(disp);
446                                 break;
447
448                         default:
449                                 vm_abort("emit_branch: unknown condition %d", condition);
450                         }
451                 } else {
452                         switch (condition) {
453                         case BRANCH_EQ:
454                                 M_BEQ_16(disp);
455                                 break;
456                         case BRANCH_NE:
457                                 M_BNE_16(disp);
458                                 break;
459                         case BRANCH_LT:
460                                 M_BLT_16(disp);
461                                 break;
462                         case BRANCH_GE:
463                                 M_BGE_16(disp);
464                                 break;
465                         case BRANCH_GT:
466                                 M_BGT_16(disp);
467                                 break;
468                         case BRANCH_LE:
469                                 M_BLE_16(disp);
470                                 break;
471                         case BRANCH_NAN:
472                                 M_BNAN_16(disp);
473                                 break;
474                         case BRANCH_UGT:
475                                 M_BHI_16(disp);
476                                 break;
477                         default:
478                                 vm_abort("emit_branch: unknown condition %d", condition);
479                         }
480                 }
481         }
482 }
483
484
485 #if !defined(NDEBUG)
486 /*
487  *      Trace functions. Implement -verbose:call flag
488  *      code marked by real NOP, but performance is no matter when using -verbose:call :)
489  */
490 void emit_verbosecall_enter(jitdata* jd) 
491
492         methodinfo   *m;
493         codegendata  *cd;
494         registerdata *rd;
495         methoddesc   *md;
496         s4      disp,i,t;
497
498
499         if (!JITDATA_HAS_FLAG_VERBOSECALL(jd))
500                 return;
501         
502         /* get required compiler data */
503         m  = jd->m;
504         cd = jd->cd;
505         rd = jd->rd;
506         md = m->parseddesc;
507
508         /* mark trace code */
509         M_NOP;
510
511         M_IPUSH(REG_D0);
512         M_IPUSH(REG_D1);
513         M_APUSH(REG_A0);
514         M_APUSH(REG_A1);
515
516 #if !defined(ENABLE_SOFTFLOAT)
517         M_AADD_IMM(-8*2, REG_SP);
518         M_FSTORE(REG_F0, REG_SP, 8);
519         M_FSTORE(REG_F1, REG_SP, 0);
520
521         disp = 4*4 + 8*2 + 4;   /* points to old argument stack initially */
522 #else
523         disp = 4*4 + 4;
524 #endif
525         /* builtin_verbosecall_enter takes all args as s8 type */
526         /* TRACE_ARGS_NUM is the number of args the builtin_verbosecall_enter expects */
527         M_IPUSH_IMM(m);
528         
529
530         /* travel up stack to the first argument of the function which needs to be copied */
531         for (i=0; (i < md->paramcount) && (i < TRACE_ARGS_NUM); i++)    {
532                 disp += 4;
533                 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {   
534                         disp += 4;
535                 }
536         }
537
538         /* disp now points to the first arg which gets copied to the trace stack, relative to REG_SP! */
539         for (i=TRACE_ARGS_NUM-1; i>=0; --i) {
540                 if (i < md->paramcount) {
541                         /* traced function has such an argument */
542                         t = md->paramtypes[i].type;
543                         
544                         if (IS_2_WORD_TYPE(t))  {
545                                 /* copy from original argument stack */
546                                 M_ILD(REG_ITMP1, REG_SP, disp);
547                                 M_IPUSH(REG_ITMP1);
548                                 M_ILD(REG_ITMP1, REG_SP, disp);
549                                 M_IPUSH(REG_ITMP1);
550                         } else  {
551                                 /* displacment is increased as 4 byte on original stack but 8 byte on trace stack */
552                                 M_ILD(REG_ITMP1, REG_SP, disp);
553                                 M_IPUSH(REG_ITMP1);
554                                 M_IPUSH_IMM(0);
555                                 disp += 4;
556                         }
557                 } else  {
558                         /* function has no arg here, push nothing and adapt displacement */
559                         M_IPUSH_IMM(0);
560                         M_IPUSH_IMM(0);
561                         disp += 8;
562                 }
563         }
564         M_JSR_IMM(builtin_verbosecall_enter);
565         /* pop arguments off stack */
566         M_AADD_IMM(TRACE_ARGS_NUM*8+4, REG_SP);
567
568 #if !defined(ENABLE_SOFTFLOAT)
569         M_FSTORE(REG_F1, REG_SP, 0);
570         M_FSTORE(REG_F0, REG_SP, 8);
571         M_AADD_IMM(8*2, REG_SP);
572 #endif
573
574         M_APOP(REG_A1);
575         M_APOP(REG_A0);
576         M_IPOP(REG_D1);
577         M_IPOP(REG_D0);
578
579         M_NOP;
580 }
581 void emit_verbosecall_exit(jitdata* jd) 
582
583         methodinfo   *m;
584         codegendata  *cd;
585         registerdata *rd;
586         methoddesc   *md;
587
588         if (!JITDATA_HAS_FLAG_VERBOSECALL(jd))
589                 return;
590
591         /* get required compiler data */
592         m  = jd->m;
593         cd = jd->cd;
594         rd = jd->rd;
595         md = m->parseddesc;
596
597         /* void builtin_verbosecall_exit(s8 l, double d, float f, methodinfo *m); */
598
599
600         /* mark trace code */
601         M_NOP;
602
603 #if !defined(ENABLE_SOFTFLOAT)
604         M_AADD_IMM(-8, REG_SP);
605         M_FSTORE(REG_F1, REG_SP, 0);
606 #endif
607
608         M_IPUSH_IMM(m);                                 /* push methodinfo */
609
610 #if !defined(ENABLE_SOFTFLOAT)
611         M_AADD_IMM(-3*4, REG_SP);
612         M_FST(REG_D0, REG_SP, 8);
613         M_DST(REG_D0, REG_SP, 0);
614 #else
615         M_IPUSH_IMM(0);
616
617         M_IPUSH_IMM(0);
618         M_IPUSH_IMM(0);
619 #endif
620
621         M_IPUSH(GET_HIGH_REG(REG_RESULT_PACKED))
622         M_IPUSH(GET_LOW_REG(REG_RESULT_PACKED))         /* push long result */
623
624         M_JSR_IMM(builtin_verbosecall_exit);
625
626         /* poping result registers from stack */
627         M_IPOP(GET_LOW_REG(REG_RESULT_PACKED))
628         M_IPOP(GET_HIGH_REG(REG_RESULT_PACKED))
629
630 #if !defined(ENABLE_SOFTFLOAT)
631         M_DLD(REG_D0, REG_SP, 0)
632         M_FLD(REG_D0, REG_SP, 8)
633 #endif
634         M_AADD_IMM(3*4 + 4, REG_SP);
635
636 #if !defined(ENABLE_SOFTFLOAT)
637         M_FLOAD(REG_F1, REG_SP, 0)
638         M_AADD_IMM(8, REG_SP);
639 #endif
640
641         M_NOP;
642 }
643 #endif
644
645 /* emit_classcast_check ********************************************************
646
647    Emit a ClassCastException check.
648
649 *******************************************************************************/
650
651 void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 reg, s4 s1)
652 {
653         if (INSTRUCTION_MUST_CHECK(iptr)) {
654                 switch (condition) {
655                 case BRANCH_LE:
656                         M_BGT(4);
657                         break;
658                 case BRANCH_EQ:
659                         M_BNE(4);
660                         break;
661                 case BRANCH_GT:
662                         M_BLE(4);
663                         break;
664                 case BRANCH_UGT:
665                         M_BLS(4);
666                         break;
667                 default:
668                         vm_abort("emit_classcast_check: unknown condition %d", condition);
669                 }
670                 M_TRAP_SETREGISTER(s1);
671                 M_TRAP(EXCEPTION_HARDWARE_CLASSCAST);
672         }
673 }
674
675 /* emit_arrayindexoutofbounds_check ********************************************
676
677    Emit a ArrayIndexOutOfBoundsException check.
678
679 *******************************************************************************/
680 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
681 {
682         if (INSTRUCTION_MUST_CHECK(iptr)) {
683                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
684                 M_ICMP(s2, REG_ITMP3);
685                 M_BHI(4);
686                 M_TRAP_SETREGISTER(s2);
687                 M_TRAP(EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
688         }
689 }
690
691 /* emit_nullpointer_check ******************************************************
692
693    Emit a NullPointerException check.
694
695 *******************************************************************************/
696 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
697 {
698         if (INSTRUCTION_MUST_CHECK(iptr)) {
699                 /* XXX: this check is copied to call monitor_enter 
700                  * invocation at the beginning of codegen.c */
701                 M_ATST(reg);
702                 M_BNE(2);
703                 M_TRAP(M68K_EXCEPTION_HARDWARE_NULLPOINTER);
704         }
705 }
706
707 /* emit_arithmetic_check *******************************************************
708
709    Emit an ArithmeticException check.
710
711 *******************************************************************************/
712
713 void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
714 {
715         if (INSTRUCTION_MUST_CHECK(iptr)) {
716                 M_ITST(reg);
717                 M_BNE(2);
718                 M_TRAP(EXCEPTION_HARDWARE_ARITHMETIC);
719         }
720 }
721
722 /* emit_exception_check_ireg **************************************************
723
724    Emit an Exception check. Teste register is integer REG_RESULT
725
726 *******************************************************************************/
727 void emit_exception_check(codegendata *cd, instruction *iptr)
728 {
729         if (INSTRUCTION_MUST_CHECK(iptr)) {
730                 M_ITST(REG_RESULT);
731                 M_BNE(2);
732                 /*M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);*/
733                 M_TRAP(EXCEPTION_HARDWARE_EXCEPTION);
734         }
735 }
736
737
738 /*
739  * These are local overrides for various environment variables in Emacs.
740  * Please do not remove this and leave it at the end of the file, where
741  * Emacs will automagically detect them.
742  * ---------------------------------------------------------------------
743  * Local variables:
744  * mode: c
745  * indent-tabs-mode: t
746  * c-basic-offset: 4
747  * tab-width: 4
748  * End:
749  * vim:noexpandtab:sw=4:ts=4:
750  */