Search
lxdream.org :: lxdream/src/sh4/sh4x86.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4x86.c
changeset 395:c473acbde186
prev394:7eb172bfeefe
next397:640324505325
author nkeynes
date Wed Sep 19 10:04:16 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Add alignment checks to LDC.L/STC.L/LDS.L/STS.L
view annotate diff log raw
     1 /**
     2  * $Id: sh4x86.c,v 1.12 2007-09-19 10:04:16 nkeynes Exp $
     3  * 
     4  * SH4 => x86 translation. This version does no real optimization, it just
     5  * outputs straight-line x86 code - it mainly exists to provide a baseline
     6  * to test the optimizing versions against.
     7  *
     8  * Copyright (c) 2007 Nathan Keynes.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  */
    21 #include <assert.h>
    22 #include <math.h>
    24 #ifndef NDEBUG
    25 #define DEBUG_JUMPS 1
    26 #endif
    28 #include "sh4/sh4core.h"
    29 #include "sh4/sh4trans.h"
    30 #include "sh4/sh4mmio.h"
    31 #include "sh4/x86op.h"
    32 #include "clock.h"
    34 #define DEFAULT_BACKPATCH_SIZE 4096
    36 /** 
    37  * Struct to manage internal translation state. This state is not saved -
    38  * it is only valid between calls to sh4_translate_begin_block() and
    39  * sh4_translate_end_block()
    40  */
    41 struct sh4_x86_state {
    42     gboolean in_delay_slot;
    43     gboolean priv_checked; /* true if we've already checked the cpu mode. */
    44     gboolean fpuen_checked; /* true if we've already checked fpu enabled. */
    45     int exit_code;
    47     /* Allocated memory for the (block-wide) back-patch list */
    48     uint32_t **backpatch_list;
    49     uint32_t backpatch_posn;
    50     uint32_t backpatch_size;
    51 };
    53 #define EXIT_DATA_ADDR_READ 0
    54 #define EXIT_DATA_ADDR_WRITE 7
    55 #define EXIT_ILLEGAL 14
    56 #define EXIT_SLOT_ILLEGAL 21
    57 #define EXIT_FPU_DISABLED 28
    58 #define EXIT_SLOT_FPU_DISABLED 35
    60 static struct sh4_x86_state sh4_x86;
    62 static uint32_t max_int = 0x7FFFFFFF;
    63 static uint32_t min_int = 0x80000000;
    64 static uint32_t save_fcw; /* save value for fpu control word */
    65 static uint32_t trunc_fcw = 0x0F7F; /* fcw value for truncation mode */
    66 void signsat48( void )
    67 {
    68     if( ((int64_t)sh4r.mac) < (int64_t)0xFFFF800000000000LL )
    69 	sh4r.mac = 0xFFFF800000000000LL;
    70     else if( ((int64_t)sh4r.mac) > (int64_t)0x00007FFFFFFFFFFFLL )
    71 	sh4r.mac = 0x00007FFFFFFFFFFFLL;
    72 }
    74 void sh4_fsca( uint32_t anglei, float *fr )
    75 {
    76     float angle = (((float)(anglei&0xFFFF))/65536.0) * 2 * M_PI;
    77     *fr++ = cosf(angle);
    78     *fr = sinf(angle);
    79 }
    81 void sh4_sleep()
    82 {
    83     if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
    84 	sh4r.sh4_state = SH4_STATE_STANDBY;
    85     } else {
    86 	sh4r.sh4_state = SH4_STATE_SLEEP;
    87     }
    88 }
    90 /**
    91  * Compute the matrix tranform of fv given the matrix xf.
    92  * Both fv and xf are word-swapped as per the sh4r.fr banks
    93  */
    94 void sh4_ftrv( float *target, float *xf )
    95 {
    96     float fv[4] = { target[1], target[0], target[3], target[2] };
    97     target[1] = xf[1] * fv[0] + xf[5]*fv[1] +
    98 	xf[9]*fv[2] + xf[13]*fv[3];
    99     target[0] = xf[0] * fv[0] + xf[4]*fv[1] +
   100 	xf[8]*fv[2] + xf[12]*fv[3];
   101     target[3] = xf[3] * fv[0] + xf[7]*fv[1] +
   102 	xf[11]*fv[2] + xf[15]*fv[3];
   103     target[2] = xf[2] * fv[0] + xf[6]*fv[1] +
   104 	xf[10]*fv[2] + xf[14]*fv[3];
   105 }
   109 void sh4_x86_init()
   110 {
   111     sh4_x86.backpatch_list = malloc(DEFAULT_BACKPATCH_SIZE);
   112     sh4_x86.backpatch_size = DEFAULT_BACKPATCH_SIZE / sizeof(uint32_t *);
   113 }
   116 static void sh4_x86_add_backpatch( uint8_t *ptr )
   117 {
   118     if( sh4_x86.backpatch_posn == sh4_x86.backpatch_size ) {
   119 	sh4_x86.backpatch_size <<= 1;
   120 	sh4_x86.backpatch_list = realloc( sh4_x86.backpatch_list, sh4_x86.backpatch_size * sizeof(uint32_t *) );
   121 	assert( sh4_x86.backpatch_list != NULL );
   122     }
   123     sh4_x86.backpatch_list[sh4_x86.backpatch_posn++] = (uint32_t *)ptr;
   124 }
   126 static void sh4_x86_do_backpatch( uint8_t *reloc_base )
   127 {
   128     unsigned int i;
   129     for( i=0; i<sh4_x86.backpatch_posn; i++ ) {
   130 	*sh4_x86.backpatch_list[i] += (reloc_base - ((uint8_t *)sh4_x86.backpatch_list[i]) - 4);
   131     }
   132 }
   134 /**
   135  * Emit an instruction to load an SH4 reg into a real register
   136  */
   137 static inline void load_reg( int x86reg, int sh4reg ) 
   138 {
   139     /* mov [bp+n], reg */
   140     OP(0x8B);
   141     OP(0x45 + (x86reg<<3));
   142     OP(REG_OFFSET(r[sh4reg]));
   143 }
   145 static inline void load_reg16s( int x86reg, int sh4reg )
   146 {
   147     OP(0x0F);
   148     OP(0xBF);
   149     MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
   150 }
   152 static inline void load_reg16u( int x86reg, int sh4reg )
   153 {
   154     OP(0x0F);
   155     OP(0xB7);
   156     MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
   158 }
   160 #define load_spreg( x86reg, regoff ) MOV_sh4r_r32( regoff, x86reg )
   161 #define store_spreg( x86reg, regoff ) MOV_r32_sh4r( x86reg, regoff )
   162 /**
   163  * Emit an instruction to load an immediate value into a register
   164  */
   165 static inline void load_imm32( int x86reg, uint32_t value ) {
   166     /* mov #value, reg */
   167     OP(0xB8 + x86reg);
   168     OP32(value);
   169 }
   171 /**
   172  * Emit an instruction to store an SH4 reg (RN)
   173  */
   174 void static inline store_reg( int x86reg, int sh4reg ) {
   175     /* mov reg, [bp+n] */
   176     OP(0x89);
   177     OP(0x45 + (x86reg<<3));
   178     OP(REG_OFFSET(r[sh4reg]));
   179 }
   181 #define load_fr_bank(bankreg) load_spreg( bankreg, REG_OFFSET(fr_bank))
   183 /**
   184  * Load an FR register (single-precision floating point) into an integer x86
   185  * register (eg for register-to-register moves)
   186  */
   187 void static inline load_fr( int bankreg, int x86reg, int frm )
   188 {
   189     OP(0x8B); OP(0x40+bankreg+(x86reg<<3)); OP((frm^1)<<2);
   190 }
   192 /**
   193  * Store an FR register (single-precision floating point) into an integer x86
   194  * register (eg for register-to-register moves)
   195  */
   196 void static inline store_fr( int bankreg, int x86reg, int frn )
   197 {
   198     OP(0x89);  OP(0x40+bankreg+(x86reg<<3)); OP((frn^1)<<2);
   199 }
   202 /**
   203  * Load a pointer to the back fp back into the specified x86 register. The
   204  * bankreg must have been previously loaded with FPSCR.
   205  * NB: 12 bytes
   206  */
   207 static inline void load_xf_bank( int bankreg )
   208 {
   209     NOT_r32( bankreg );
   210     SHR_imm8_r32( (21 - 6), bankreg ); // Extract bit 21 then *64 for bank size
   211     AND_imm8s_r32( 0x40, bankreg );    // Complete extraction
   212     OP(0x8D); OP(0x44+(bankreg<<3)); OP(0x28+bankreg); OP(REG_OFFSET(fr)); // LEA [ebp+bankreg+disp], bankreg
   213 }
   215 /**
   216  * Update the fr_bank pointer based on the current fpscr value.
   217  */
   218 static inline void update_fr_bank( int fpscrreg )
   219 {
   220     SHR_imm8_r32( (21 - 6), fpscrreg ); // Extract bit 21 then *64 for bank size
   221     AND_imm8s_r32( 0x40, fpscrreg );    // Complete extraction
   222     OP(0x8D); OP(0x44+(fpscrreg<<3)); OP(0x28+fpscrreg); OP(REG_OFFSET(fr)); // LEA [ebp+fpscrreg+disp], fpscrreg
   223     store_spreg( fpscrreg, REG_OFFSET(fr_bank) );
   224 }
   225 /**
   226  * Push FPUL (as a 32-bit float) onto the FPU stack
   227  */
   228 static inline void push_fpul( )
   229 {
   230     OP(0xD9); OP(0x45); OP(R_FPUL);
   231 }
   233 /**
   234  * Pop FPUL (as a 32-bit float) from the FPU stack
   235  */
   236 static inline void pop_fpul( )
   237 {
   238     OP(0xD9); OP(0x5D); OP(R_FPUL);
   239 }
   241 /**
   242  * Push a 32-bit float onto the FPU stack, with bankreg previously loaded
   243  * with the location of the current fp bank.
   244  */
   245 static inline void push_fr( int bankreg, int frm ) 
   246 {
   247     OP(0xD9); OP(0x40 + bankreg); OP((frm^1)<<2);  // FLD.S [bankreg + frm^1*4]
   248 }
   250 /**
   251  * Pop a 32-bit float from the FPU stack and store it back into the fp bank, 
   252  * with bankreg previously loaded with the location of the current fp bank.
   253  */
   254 static inline void pop_fr( int bankreg, int frm )
   255 {
   256     OP(0xD9); OP(0x58 + bankreg); OP((frm^1)<<2); // FST.S [bankreg + frm^1*4]
   257 }
   259 /**
   260  * Push a 64-bit double onto the FPU stack, with bankreg previously loaded
   261  * with the location of the current fp bank.
   262  */
   263 static inline void push_dr( int bankreg, int frm )
   264 {
   265     OP(0xDD); OP(0x40 + bankreg); OP(frm<<2); // FLD.D [bankreg + frm*4]
   266 }
   268 static inline void pop_dr( int bankreg, int frm )
   269 {
   270     OP(0xDD); OP(0x58 + bankreg); OP(frm<<2); // FST.D [bankreg + frm*4]
   271 }
   273 /**
   274  * Note: clobbers EAX to make the indirect call - this isn't usually
   275  * a problem since the callee will usually clobber it anyway.
   276  */
   277 static inline void call_func0( void *ptr )
   278 {
   279     load_imm32(R_EAX, (uint32_t)ptr);
   280     CALL_r32(R_EAX);
   281 }
   283 static inline void call_func1( void *ptr, int arg1 )
   284 {
   285     PUSH_r32(arg1);
   286     call_func0(ptr);
   287     ADD_imm8s_r32( 4, R_ESP );
   288 }
   290 static inline void call_func2( void *ptr, int arg1, int arg2 )
   291 {
   292     PUSH_r32(arg2);
   293     PUSH_r32(arg1);
   294     call_func0(ptr);
   295     ADD_imm8s_r32( 8, R_ESP );
   296 }
   298 /**
   299  * Write a double (64-bit) value into memory, with the first word in arg2a, and
   300  * the second in arg2b
   301  * NB: 30 bytes
   302  */
   303 static inline void MEM_WRITE_DOUBLE( int addr, int arg2a, int arg2b )
   304 {
   305     ADD_imm8s_r32( 4, addr );
   306     PUSH_r32(arg2b);
   307     PUSH_r32(addr);
   308     ADD_imm8s_r32( -4, addr );
   309     PUSH_r32(arg2a);
   310     PUSH_r32(addr);
   311     call_func0(sh4_write_long);
   312     ADD_imm8s_r32( 8, R_ESP );
   313     call_func0(sh4_write_long);
   314     ADD_imm8s_r32( 8, R_ESP );
   315 }
   317 /**
   318  * Read a double (64-bit) value from memory, writing the first word into arg2a
   319  * and the second into arg2b. The addr must not be in EAX
   320  * NB: 27 bytes
   321  */
   322 static inline void MEM_READ_DOUBLE( int addr, int arg2a, int arg2b )
   323 {
   324     PUSH_r32(addr);
   325     call_func0(sh4_read_long);
   326     POP_r32(addr);
   327     PUSH_r32(R_EAX);
   328     ADD_imm8s_r32( 4, addr );
   329     PUSH_r32(addr);
   330     call_func0(sh4_read_long);
   331     ADD_imm8s_r32( 4, R_ESP );
   332     MOV_r32_r32( R_EAX, arg2b );
   333     POP_r32(arg2a);
   334 }
   336 /* Exception checks - Note that all exception checks will clobber EAX */
   337 static void check_priv( )
   338 {
   339     if( !sh4_x86.priv_checked ) {
   340 	sh4_x86.priv_checked = TRUE;
   341 	load_spreg( R_EAX, R_SR );
   342 	AND_imm32_r32( SR_MD, R_EAX );
   343 	if( sh4_x86.in_delay_slot ) {
   344 	    JE_exit( EXIT_SLOT_ILLEGAL );
   345 	} else {
   346 	    JE_exit( EXIT_ILLEGAL );
   347 	}
   348     }
   349 }
   351 static void check_fpuen( )
   352 {
   353     if( !sh4_x86.fpuen_checked ) {
   354 	sh4_x86.fpuen_checked = TRUE;
   355 	load_spreg( R_EAX, R_SR );
   356 	AND_imm32_r32( SR_FD, R_EAX );
   357 	if( sh4_x86.in_delay_slot ) {
   358 	    JNE_exit(EXIT_SLOT_FPU_DISABLED);
   359 	} else {
   360 	    JNE_exit(EXIT_FPU_DISABLED);
   361 	}
   362     }
   363 }
   365 static void check_ralign16( int x86reg )
   366 {
   367     TEST_imm32_r32( 0x00000001, x86reg );
   368     JNE_exit(EXIT_DATA_ADDR_READ);
   369 }
   371 static void check_walign16( int x86reg )
   372 {
   373     TEST_imm32_r32( 0x00000001, x86reg );
   374     JNE_exit(EXIT_DATA_ADDR_WRITE);
   375 }
   377 static void check_ralign32( int x86reg )
   378 {
   379     TEST_imm32_r32( 0x00000003, x86reg );
   380     JNE_exit(EXIT_DATA_ADDR_READ);
   381 }
   382 static void check_walign32( int x86reg )
   383 {
   384     TEST_imm32_r32( 0x00000003, x86reg );
   385     JNE_exit(EXIT_DATA_ADDR_WRITE);
   386 }
   388 #define UNDEF()
   389 #define MEM_RESULT(value_reg) if(value_reg != R_EAX) { MOV_r32_r32(R_EAX,value_reg); }
   390 #define MEM_READ_BYTE( addr_reg, value_reg ) call_func1(sh4_read_byte, addr_reg ); MEM_RESULT(value_reg)
   391 #define MEM_READ_WORD( addr_reg, value_reg ) call_func1(sh4_read_word, addr_reg ); MEM_RESULT(value_reg)
   392 #define MEM_READ_LONG( addr_reg, value_reg ) call_func1(sh4_read_long, addr_reg ); MEM_RESULT(value_reg)
   393 #define MEM_WRITE_BYTE( addr_reg, value_reg ) call_func2(sh4_write_byte, addr_reg, value_reg)
   394 #define MEM_WRITE_WORD( addr_reg, value_reg ) call_func2(sh4_write_word, addr_reg, value_reg)
   395 #define MEM_WRITE_LONG( addr_reg, value_reg ) call_func2(sh4_write_long, addr_reg, value_reg)
   397 #define SLOTILLEGAL() JMP_exit(EXIT_SLOT_ILLEGAL); sh4_x86.in_delay_slot = FALSE; return 1;
   401 /**
   402  * Emit the 'start of block' assembly. Sets up the stack frame and save
   403  * SI/DI as required
   404  */
   405 void sh4_translate_begin_block() 
   406 {
   407     PUSH_r32(R_EBP);
   408     /* mov &sh4r, ebp */
   409     load_imm32( R_EBP, (uint32_t)&sh4r );
   410     PUSH_r32(R_EDI);
   411     PUSH_r32(R_ESI);
   412     XOR_r32_r32(R_ESI, R_ESI);
   414     sh4_x86.in_delay_slot = FALSE;
   415     sh4_x86.priv_checked = FALSE;
   416     sh4_x86.fpuen_checked = FALSE;
   417     sh4_x86.backpatch_posn = 0;
   418     sh4_x86.exit_code = 1;
   419 }
   421 /**
   422  * Exit the block early (ie branch out), conditionally or otherwise
   423  */
   424 void exit_block( )
   425 {
   426     store_spreg( R_EDI, REG_OFFSET(pc) );
   427     MOV_moff32_EAX( (uint32_t)&sh4_cpu_period );
   428     load_spreg( R_ECX, REG_OFFSET(slice_cycle) );
   429     MUL_r32( R_ESI );
   430     ADD_r32_r32( R_EAX, R_ECX );
   431     store_spreg( R_ECX, REG_OFFSET(slice_cycle) );
   432     load_imm32( R_EAX, sh4_x86.exit_code );
   433     POP_r32(R_ESI);
   434     POP_r32(R_EDI);
   435     POP_r32(R_EBP);
   436     RET();
   437 }
   439 /**
   440  * Flush any open regs back to memory, restore SI/DI/, update PC, etc
   441  */
   442 void sh4_translate_end_block( sh4addr_t pc ) {
   443     assert( !sh4_x86.in_delay_slot ); // should never stop here
   444     // Normal termination - save PC, cycle count
   445     exit_block( );
   447     if( sh4_x86.backpatch_posn != 0 ) {
   448 	uint8_t *end_ptr = xlat_output;
   449 	// Exception termination. Jump block for various exception codes:
   450 	PUSH_imm32( EXC_DATA_ADDR_READ );
   451 	JMP_rel8( 33, target1 );
   452 	PUSH_imm32( EXC_DATA_ADDR_WRITE );
   453 	JMP_rel8( 26, target2 );
   454 	PUSH_imm32( EXC_ILLEGAL );
   455 	JMP_rel8( 19, target3 );
   456 	PUSH_imm32( EXC_SLOT_ILLEGAL ); 
   457 	JMP_rel8( 12, target4 );
   458 	PUSH_imm32( EXC_FPU_DISABLED ); 
   459 	JMP_rel8( 5, target5 );
   460 	PUSH_imm32( EXC_SLOT_FPU_DISABLED );
   461 	// target
   462 	JMP_TARGET(target1);
   463 	JMP_TARGET(target2);
   464 	JMP_TARGET(target3);
   465 	JMP_TARGET(target4);
   466 	JMP_TARGET(target5);
   467 	load_spreg( R_ECX, REG_OFFSET(pc) );
   468 	ADD_r32_r32( R_ESI, R_ECX );
   469 	ADD_r32_r32( R_ESI, R_ECX );
   470 	store_spreg( R_ECX, REG_OFFSET(pc) );
   471 	MOV_moff32_EAX( (uint32_t)&sh4_cpu_period );
   472 	load_spreg( R_ECX, REG_OFFSET(slice_cycle) );
   473 	MUL_r32( R_ESI );
   474 	ADD_r32_r32( R_EAX, R_ECX );
   475 	store_spreg( R_ECX, REG_OFFSET(slice_cycle) );
   477 	load_imm32( R_EAX, (uint32_t)sh4_raise_exception ); // 6
   478 	CALL_r32( R_EAX ); // 2
   479 	ADD_imm8s_r32( 4, R_ESP );
   480 	POP_r32(R_ESI);
   481 	POP_r32(R_EDI);
   482 	POP_r32(R_EBP);
   483 	RET();
   485 	sh4_x86_do_backpatch( end_ptr );
   486     }
   488 }
   491 extern uint16_t *sh4_icache;
   492 extern uint32_t sh4_icache_addr;
   494 /**
   495  * Translate a single instruction. Delayed branches are handled specially
   496  * by translating both branch and delayed instruction as a single unit (as
   497  * 
   498  *
   499  * @return true if the instruction marks the end of a basic block
   500  * (eg a branch or 
   501  */
   502 uint32_t sh4_x86_translate_instruction( uint32_t pc )
   503 {
   504     uint32_t ir;
   505     /* Read instruction */
   506     uint32_t pageaddr = pc >> 12;
   507     if( sh4_icache != NULL && pageaddr == sh4_icache_addr ) {
   508 	ir = sh4_icache[(pc&0xFFF)>>1];
   509     } else {
   510 	sh4_icache = (uint16_t *)mem_get_page(pc);
   511 	if( ((uint32_t)sh4_icache) < MAX_IO_REGIONS ) {
   512 	    /* If someone's actually been so daft as to try to execute out of an IO
   513 	     * region, fallback on the full-blown memory read
   514 	     */
   515 	    sh4_icache = NULL;
   516 	    ir = sh4_read_word(pc);
   517 	} else {
   518 	    sh4_icache_addr = pageaddr;
   519 	    ir = sh4_icache[(pc&0xFFF)>>1];
   520 	}
   521     }
   523         switch( (ir&0xF000) >> 12 ) {
   524             case 0x0:
   525                 switch( ir&0xF ) {
   526                     case 0x2:
   527                         switch( (ir&0x80) >> 7 ) {
   528                             case 0x0:
   529                                 switch( (ir&0x70) >> 4 ) {
   530                                     case 0x0:
   531                                         { /* STC SR, Rn */
   532                                         uint32_t Rn = ((ir>>8)&0xF); 
   533                                         check_priv();
   534                                         call_func0(sh4_read_sr);
   535                                         store_reg( R_EAX, Rn );
   536                                         }
   537                                         break;
   538                                     case 0x1:
   539                                         { /* STC GBR, Rn */
   540                                         uint32_t Rn = ((ir>>8)&0xF); 
   541                                         load_spreg( R_EAX, R_GBR );
   542                                         store_reg( R_EAX, Rn );
   543                                         }
   544                                         break;
   545                                     case 0x2:
   546                                         { /* STC VBR, Rn */
   547                                         uint32_t Rn = ((ir>>8)&0xF); 
   548                                         check_priv();
   549                                         load_spreg( R_EAX, R_VBR );
   550                                         store_reg( R_EAX, Rn );
   551                                         }
   552                                         break;
   553                                     case 0x3:
   554                                         { /* STC SSR, Rn */
   555                                         uint32_t Rn = ((ir>>8)&0xF); 
   556                                         check_priv();
   557                                         load_spreg( R_EAX, R_SSR );
   558                                         store_reg( R_EAX, Rn );
   559                                         }
   560                                         break;
   561                                     case 0x4:
   562                                         { /* STC SPC, Rn */
   563                                         uint32_t Rn = ((ir>>8)&0xF); 
   564                                         check_priv();
   565                                         load_spreg( R_EAX, R_SPC );
   566                                         store_reg( R_EAX, Rn );
   567                                         }
   568                                         break;
   569                                     default:
   570                                         UNDEF();
   571                                         break;
   572                                 }
   573                                 break;
   574                             case 0x1:
   575                                 { /* STC Rm_BANK, Rn */
   576                                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
   577                                 check_priv();
   578                                 load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
   579                                 store_reg( R_EAX, Rn );
   580                                 }
   581                                 break;
   582                         }
   583                         break;
   584                     case 0x3:
   585                         switch( (ir&0xF0) >> 4 ) {
   586                             case 0x0:
   587                                 { /* BSRF Rn */
   588                                 uint32_t Rn = ((ir>>8)&0xF); 
   589                                 if( sh4_x86.in_delay_slot ) {
   590                             	SLOTILLEGAL();
   591                                 } else {
   592                             	load_imm32( R_EAX, pc + 4 );
   593                             	store_spreg( R_EAX, R_PR );
   594                             	load_reg( R_EDI, Rn );
   595                             	ADD_r32_r32( R_EAX, R_EDI );
   596                             	sh4_x86.in_delay_slot = TRUE;
   597                             	return 0;
   598                                 }
   599                                 }
   600                                 break;
   601                             case 0x2:
   602                                 { /* BRAF Rn */
   603                                 uint32_t Rn = ((ir>>8)&0xF); 
   604                                 if( sh4_x86.in_delay_slot ) {
   605                             	SLOTILLEGAL();
   606                                 } else {
   607                             	load_reg( R_EDI, Rn );
   608                             	ADD_imm32_r32( pc + 4, R_EDI );
   609                             	sh4_x86.in_delay_slot = TRUE;
   610                             	return 0;
   611                                 }
   612                                 }
   613                                 break;
   614                             case 0x8:
   615                                 { /* PREF @Rn */
   616                                 uint32_t Rn = ((ir>>8)&0xF); 
   617                                 load_reg( R_EAX, Rn );
   618                                 PUSH_r32( R_EAX );
   619                                 AND_imm32_r32( 0xFC000000, R_EAX );
   620                                 CMP_imm32_r32( 0xE0000000, R_EAX );
   621                                 JNE_rel8(7, end);
   622                                 call_func0( sh4_flush_store_queue );
   623                                 JMP_TARGET(end);
   624                                 ADD_imm8s_r32( 4, R_ESP );
   625                                 }
   626                                 break;
   627                             case 0x9:
   628                                 { /* OCBI @Rn */
   629                                 uint32_t Rn = ((ir>>8)&0xF); 
   630                                 }
   631                                 break;
   632                             case 0xA:
   633                                 { /* OCBP @Rn */
   634                                 uint32_t Rn = ((ir>>8)&0xF); 
   635                                 }
   636                                 break;
   637                             case 0xB:
   638                                 { /* OCBWB @Rn */
   639                                 uint32_t Rn = ((ir>>8)&0xF); 
   640                                 }
   641                                 break;
   642                             case 0xC:
   643                                 { /* MOVCA.L R0, @Rn */
   644                                 uint32_t Rn = ((ir>>8)&0xF); 
   645                                 load_reg( R_EAX, 0 );
   646                                 load_reg( R_ECX, Rn );
   647                                 check_walign32( R_ECX );
   648                                 MEM_WRITE_LONG( R_ECX, R_EAX );
   649                                 }
   650                                 break;
   651                             default:
   652                                 UNDEF();
   653                                 break;
   654                         }
   655                         break;
   656                     case 0x4:
   657                         { /* MOV.B Rm, @(R0, Rn) */
   658                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   659                         load_reg( R_EAX, 0 );
   660                         load_reg( R_ECX, Rn );
   661                         ADD_r32_r32( R_EAX, R_ECX );
   662                         load_reg( R_EAX, Rm );
   663                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   664                         }
   665                         break;
   666                     case 0x5:
   667                         { /* MOV.W Rm, @(R0, Rn) */
   668                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   669                         load_reg( R_EAX, 0 );
   670                         load_reg( R_ECX, Rn );
   671                         ADD_r32_r32( R_EAX, R_ECX );
   672                         check_walign16( R_ECX );
   673                         load_reg( R_EAX, Rm );
   674                         MEM_WRITE_WORD( R_ECX, R_EAX );
   675                         }
   676                         break;
   677                     case 0x6:
   678                         { /* MOV.L Rm, @(R0, Rn) */
   679                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   680                         load_reg( R_EAX, 0 );
   681                         load_reg( R_ECX, Rn );
   682                         ADD_r32_r32( R_EAX, R_ECX );
   683                         check_walign32( R_ECX );
   684                         load_reg( R_EAX, Rm );
   685                         MEM_WRITE_LONG( R_ECX, R_EAX );
   686                         }
   687                         break;
   688                     case 0x7:
   689                         { /* MUL.L Rm, Rn */
   690                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   691                         load_reg( R_EAX, Rm );
   692                         load_reg( R_ECX, Rn );
   693                         MUL_r32( R_ECX );
   694                         store_spreg( R_EAX, R_MACL );
   695                         }
   696                         break;
   697                     case 0x8:
   698                         switch( (ir&0xFF0) >> 4 ) {
   699                             case 0x0:
   700                                 { /* CLRT */
   701                                 CLC();
   702                                 SETC_t();
   703                                 }
   704                                 break;
   705                             case 0x1:
   706                                 { /* SETT */
   707                                 STC();
   708                                 SETC_t();
   709                                 }
   710                                 break;
   711                             case 0x2:
   712                                 { /* CLRMAC */
   713                                 XOR_r32_r32(R_EAX, R_EAX);
   714                                 store_spreg( R_EAX, R_MACL );
   715                                 store_spreg( R_EAX, R_MACH );
   716                                 }
   717                                 break;
   718                             case 0x3:
   719                                 { /* LDTLB */
   720                                 }
   721                                 break;
   722                             case 0x4:
   723                                 { /* CLRS */
   724                                 CLC();
   725                                 SETC_sh4r(R_S);
   726                                 }
   727                                 break;
   728                             case 0x5:
   729                                 { /* SETS */
   730                                 STC();
   731                                 SETC_sh4r(R_S);
   732                                 }
   733                                 break;
   734                             default:
   735                                 UNDEF();
   736                                 break;
   737                         }
   738                         break;
   739                     case 0x9:
   740                         switch( (ir&0xF0) >> 4 ) {
   741                             case 0x0:
   742                                 { /* NOP */
   743                                 /* Do nothing. Well, we could emit an 0x90, but what would really be the point? */
   744                                 }
   745                                 break;
   746                             case 0x1:
   747                                 { /* DIV0U */
   748                                 XOR_r32_r32( R_EAX, R_EAX );
   749                                 store_spreg( R_EAX, R_Q );
   750                                 store_spreg( R_EAX, R_M );
   751                                 store_spreg( R_EAX, R_T );
   752                                 }
   753                                 break;
   754                             case 0x2:
   755                                 { /* MOVT Rn */
   756                                 uint32_t Rn = ((ir>>8)&0xF); 
   757                                 load_spreg( R_EAX, R_T );
   758                                 store_reg( R_EAX, Rn );
   759                                 }
   760                                 break;
   761                             default:
   762                                 UNDEF();
   763                                 break;
   764                         }
   765                         break;
   766                     case 0xA:
   767                         switch( (ir&0xF0) >> 4 ) {
   768                             case 0x0:
   769                                 { /* STS MACH, Rn */
   770                                 uint32_t Rn = ((ir>>8)&0xF); 
   771                                 load_spreg( R_EAX, R_MACH );
   772                                 store_reg( R_EAX, Rn );
   773                                 }
   774                                 break;
   775                             case 0x1:
   776                                 { /* STS MACL, Rn */
   777                                 uint32_t Rn = ((ir>>8)&0xF); 
   778                                 load_spreg( R_EAX, R_MACL );
   779                                 store_reg( R_EAX, Rn );
   780                                 }
   781                                 break;
   782                             case 0x2:
   783                                 { /* STS PR, Rn */
   784                                 uint32_t Rn = ((ir>>8)&0xF); 
   785                                 load_spreg( R_EAX, R_PR );
   786                                 store_reg( R_EAX, Rn );
   787                                 }
   788                                 break;
   789                             case 0x3:
   790                                 { /* STC SGR, Rn */
   791                                 uint32_t Rn = ((ir>>8)&0xF); 
   792                                 check_priv();
   793                                 load_spreg( R_EAX, R_SGR );
   794                                 store_reg( R_EAX, Rn );
   795                                 }
   796                                 break;
   797                             case 0x5:
   798                                 { /* STS FPUL, Rn */
   799                                 uint32_t Rn = ((ir>>8)&0xF); 
   800                                 load_spreg( R_EAX, R_FPUL );
   801                                 store_reg( R_EAX, Rn );
   802                                 }
   803                                 break;
   804                             case 0x6:
   805                                 { /* STS FPSCR, Rn */
   806                                 uint32_t Rn = ((ir>>8)&0xF); 
   807                                 load_spreg( R_EAX, R_FPSCR );
   808                                 store_reg( R_EAX, Rn );
   809                                 }
   810                                 break;
   811                             case 0xF:
   812                                 { /* STC DBR, Rn */
   813                                 uint32_t Rn = ((ir>>8)&0xF); 
   814                                 check_priv();
   815                                 load_spreg( R_EAX, R_DBR );
   816                                 store_reg( R_EAX, Rn );
   817                                 }
   818                                 break;
   819                             default:
   820                                 UNDEF();
   821                                 break;
   822                         }
   823                         break;
   824                     case 0xB:
   825                         switch( (ir&0xFF0) >> 4 ) {
   826                             case 0x0:
   827                                 { /* RTS */
   828                                 if( sh4_x86.in_delay_slot ) {
   829                             	SLOTILLEGAL();
   830                                 } else {
   831                             	load_spreg( R_EDI, R_PR );
   832                             	sh4_x86.in_delay_slot = TRUE;
   833                             	return 0;
   834                                 }
   835                                 }
   836                                 break;
   837                             case 0x1:
   838                                 { /* SLEEP */
   839                                 check_priv();
   840                                 call_func0( sh4_sleep );
   841                                 sh4_x86.exit_code = 0;
   842                                 sh4_x86.in_delay_slot = FALSE;
   843                                 INC_r32(R_ESI);
   844                                 return 1;
   845                                 }
   846                                 break;
   847                             case 0x2:
   848                                 { /* RTE */
   849                                 check_priv();
   850                                 if( sh4_x86.in_delay_slot ) {
   851                             	SLOTILLEGAL();
   852                                 } else {
   853                             	load_spreg( R_EDI, R_SPC );
   854                             	load_spreg( R_EAX, R_SSR );
   855                             	call_func1( sh4_write_sr, R_EAX );
   856                             	sh4_x86.in_delay_slot = TRUE;
   857                             	sh4_x86.priv_checked = FALSE;
   858                             	sh4_x86.fpuen_checked = FALSE;
   859                             	return 0;
   860                                 }
   861                                 }
   862                                 break;
   863                             default:
   864                                 UNDEF();
   865                                 break;
   866                         }
   867                         break;
   868                     case 0xC:
   869                         { /* MOV.B @(R0, Rm), Rn */
   870                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   871                         load_reg( R_EAX, 0 );
   872                         load_reg( R_ECX, Rm );
   873                         ADD_r32_r32( R_EAX, R_ECX );
   874                         MEM_READ_BYTE( R_ECX, R_EAX );
   875                         store_reg( R_EAX, Rn );
   876                         }
   877                         break;
   878                     case 0xD:
   879                         { /* MOV.W @(R0, Rm), Rn */
   880                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   881                         load_reg( R_EAX, 0 );
   882                         load_reg( R_ECX, Rm );
   883                         ADD_r32_r32( R_EAX, R_ECX );
   884                         check_ralign16( R_ECX );
   885                         MEM_READ_WORD( R_ECX, R_EAX );
   886                         store_reg( R_EAX, Rn );
   887                         }
   888                         break;
   889                     case 0xE:
   890                         { /* MOV.L @(R0, Rm), Rn */
   891                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   892                         load_reg( R_EAX, 0 );
   893                         load_reg( R_ECX, Rm );
   894                         ADD_r32_r32( R_EAX, R_ECX );
   895                         check_ralign32( R_ECX );
   896                         MEM_READ_LONG( R_ECX, R_EAX );
   897                         store_reg( R_EAX, Rn );
   898                         }
   899                         break;
   900                     case 0xF:
   901                         { /* MAC.L @Rm+, @Rn+ */
   902                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   903                         load_reg( R_ECX, Rm );
   904                         check_ralign32( R_ECX );
   905                         load_reg( R_ECX, Rn );
   906                         check_ralign32( R_ECX );
   907                         ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rn]) );
   908                         MEM_READ_LONG( R_ECX, R_EAX );
   909                         PUSH_r32( R_EAX );
   910                         load_reg( R_ECX, Rm );
   911                         ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rm]) );
   912                         MEM_READ_LONG( R_ECX, R_EAX );
   913                         POP_r32( R_ECX );
   914                         IMUL_r32( R_ECX );
   915                         ADD_r32_sh4r( R_EAX, R_MACL );
   916                         ADC_r32_sh4r( R_EDX, R_MACH );
   918                         load_spreg( R_ECX, R_S );
   919                         TEST_r32_r32(R_ECX, R_ECX);
   920                         JE_rel8( 7, nosat );
   921                         call_func0( signsat48 );
   922                         JMP_TARGET( nosat );
   923                         }
   924                         break;
   925                     default:
   926                         UNDEF();
   927                         break;
   928                 }
   929                 break;
   930             case 0x1:
   931                 { /* MOV.L Rm, @(disp, Rn) */
   932                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
   933                 load_reg( R_ECX, Rn );
   934                 load_reg( R_EAX, Rm );
   935                 ADD_imm32_r32( disp, R_ECX );
   936                 check_walign32( R_ECX );
   937                 MEM_WRITE_LONG( R_ECX, R_EAX );
   938                 }
   939                 break;
   940             case 0x2:
   941                 switch( ir&0xF ) {
   942                     case 0x0:
   943                         { /* MOV.B Rm, @Rn */
   944                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   945                         load_reg( R_EAX, Rm );
   946                         load_reg( R_ECX, Rn );
   947                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   948                         }
   949                         break;
   950                     case 0x1:
   951                         { /* MOV.W Rm, @Rn */
   952                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   953                         load_reg( R_ECX, Rn );
   954                         check_walign16( R_ECX );
   955                         load_reg( R_EAX, Rm );
   956                         MEM_WRITE_WORD( R_ECX, R_EAX );
   957                         }
   958                         break;
   959                     case 0x2:
   960                         { /* MOV.L Rm, @Rn */
   961                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   962                         load_reg( R_EAX, Rm );
   963                         load_reg( R_ECX, Rn );
   964                         check_walign32(R_ECX);
   965                         MEM_WRITE_LONG( R_ECX, R_EAX );
   966                         }
   967                         break;
   968                     case 0x4:
   969                         { /* MOV.B Rm, @-Rn */
   970                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   971                         load_reg( R_EAX, Rm );
   972                         load_reg( R_ECX, Rn );
   973                         ADD_imm8s_r32( -1, R_ECX );
   974                         store_reg( R_ECX, Rn );
   975                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   976                         }
   977                         break;
   978                     case 0x5:
   979                         { /* MOV.W Rm, @-Rn */
   980                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   981                         load_reg( R_ECX, Rn );
   982                         check_walign16( R_ECX );
   983                         load_reg( R_EAX, Rm );
   984                         ADD_imm8s_r32( -2, R_ECX );
   985                         store_reg( R_ECX, Rn );
   986                         MEM_WRITE_WORD( R_ECX, R_EAX );
   987                         }
   988                         break;
   989                     case 0x6:
   990                         { /* MOV.L Rm, @-Rn */
   991                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   992                         load_reg( R_EAX, Rm );
   993                         load_reg( R_ECX, Rn );
   994                         check_walign32( R_ECX );
   995                         ADD_imm8s_r32( -4, R_ECX );
   996                         store_reg( R_ECX, Rn );
   997                         MEM_WRITE_LONG( R_ECX, R_EAX );
   998                         }
   999                         break;
  1000                     case 0x7:
  1001                         { /* DIV0S Rm, Rn */
  1002                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1003                         load_reg( R_EAX, Rm );
  1004                         load_reg( R_ECX, Rn );
  1005                         SHR_imm8_r32( 31, R_EAX );
  1006                         SHR_imm8_r32( 31, R_ECX );
  1007                         store_spreg( R_EAX, R_M );
  1008                         store_spreg( R_ECX, R_Q );
  1009                         CMP_r32_r32( R_EAX, R_ECX );
  1010                         SETNE_t();
  1012                         break;
  1013                     case 0x8:
  1014                         { /* TST Rm, Rn */
  1015                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1016                         load_reg( R_EAX, Rm );
  1017                         load_reg( R_ECX, Rn );
  1018                         TEST_r32_r32( R_EAX, R_ECX );
  1019                         SETE_t();
  1021                         break;
  1022                     case 0x9:
  1023                         { /* AND Rm, Rn */
  1024                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1025                         load_reg( R_EAX, Rm );
  1026                         load_reg( R_ECX, Rn );
  1027                         AND_r32_r32( R_EAX, R_ECX );
  1028                         store_reg( R_ECX, Rn );
  1030                         break;
  1031                     case 0xA:
  1032                         { /* XOR Rm, Rn */
  1033                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1034                         load_reg( R_EAX, Rm );
  1035                         load_reg( R_ECX, Rn );
  1036                         XOR_r32_r32( R_EAX, R_ECX );
  1037                         store_reg( R_ECX, Rn );
  1039                         break;
  1040                     case 0xB:
  1041                         { /* OR Rm, Rn */
  1042                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1043                         load_reg( R_EAX, Rm );
  1044                         load_reg( R_ECX, Rn );
  1045                         OR_r32_r32( R_EAX, R_ECX );
  1046                         store_reg( R_ECX, Rn );
  1048                         break;
  1049                     case 0xC:
  1050                         { /* CMP/STR Rm, Rn */
  1051                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1052                         load_reg( R_EAX, Rm );
  1053                         load_reg( R_ECX, Rn );
  1054                         XOR_r32_r32( R_ECX, R_EAX );
  1055                         TEST_r8_r8( R_AL, R_AL );
  1056                         JE_rel8(13, target1);
  1057                         TEST_r8_r8( R_AH, R_AH ); // 2
  1058                         JE_rel8(9, target2);
  1059                         SHR_imm8_r32( 16, R_EAX ); // 3
  1060                         TEST_r8_r8( R_AL, R_AL ); // 2
  1061                         JE_rel8(2, target3);
  1062                         TEST_r8_r8( R_AH, R_AH ); // 2
  1063                         JMP_TARGET(target1);
  1064                         JMP_TARGET(target2);
  1065                         JMP_TARGET(target3);
  1066                         SETE_t();
  1068                         break;
  1069                     case 0xD:
  1070                         { /* XTRCT Rm, Rn */
  1071                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1072                         load_reg( R_EAX, Rm );
  1073                         load_reg( R_ECX, Rn );
  1074                         SHL_imm8_r32( 16, R_EAX );
  1075                         SHR_imm8_r32( 16, R_ECX );
  1076                         OR_r32_r32( R_EAX, R_ECX );
  1077                         store_reg( R_ECX, Rn );
  1079                         break;
  1080                     case 0xE:
  1081                         { /* MULU.W Rm, Rn */
  1082                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1083                         load_reg16u( R_EAX, Rm );
  1084                         load_reg16u( R_ECX, Rn );
  1085                         MUL_r32( R_ECX );
  1086                         store_spreg( R_EAX, R_MACL );
  1088                         break;
  1089                     case 0xF:
  1090                         { /* MULS.W Rm, Rn */
  1091                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1092                         load_reg16s( R_EAX, Rm );
  1093                         load_reg16s( R_ECX, Rn );
  1094                         MUL_r32( R_ECX );
  1095                         store_spreg( R_EAX, R_MACL );
  1097                         break;
  1098                     default:
  1099                         UNDEF();
  1100                         break;
  1102                 break;
  1103             case 0x3:
  1104                 switch( ir&0xF ) {
  1105                     case 0x0:
  1106                         { /* CMP/EQ Rm, Rn */
  1107                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1108                         load_reg( R_EAX, Rm );
  1109                         load_reg( R_ECX, Rn );
  1110                         CMP_r32_r32( R_EAX, R_ECX );
  1111                         SETE_t();
  1113                         break;
  1114                     case 0x2:
  1115                         { /* CMP/HS Rm, Rn */
  1116                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1117                         load_reg( R_EAX, Rm );
  1118                         load_reg( R_ECX, Rn );
  1119                         CMP_r32_r32( R_EAX, R_ECX );
  1120                         SETAE_t();
  1122                         break;
  1123                     case 0x3:
  1124                         { /* CMP/GE Rm, Rn */
  1125                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1126                         load_reg( R_EAX, Rm );
  1127                         load_reg( R_ECX, Rn );
  1128                         CMP_r32_r32( R_EAX, R_ECX );
  1129                         SETGE_t();
  1131                         break;
  1132                     case 0x4:
  1133                         { /* DIV1 Rm, Rn */
  1134                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1135                         load_spreg( R_ECX, R_M );
  1136                         load_reg( R_EAX, Rn );
  1137                         LDC_t();
  1138                         RCL1_r32( R_EAX );
  1139                         SETC_r8( R_DL ); // Q'
  1140                         CMP_sh4r_r32( R_Q, R_ECX );
  1141                         JE_rel8(5, mqequal);
  1142                         ADD_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
  1143                         JMP_rel8(3, end);
  1144                         JMP_TARGET(mqequal);
  1145                         SUB_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
  1146                         JMP_TARGET(end);
  1147                         store_reg( R_EAX, Rn ); // Done with Rn now
  1148                         SETC_r8(R_AL); // tmp1
  1149                         XOR_r8_r8( R_DL, R_AL ); // Q' = Q ^ tmp1
  1150                         XOR_r8_r8( R_AL, R_CL ); // Q'' = Q' ^ M
  1151                         store_spreg( R_ECX, R_Q );
  1152                         XOR_imm8s_r32( 1, R_AL );   // T = !Q'
  1153                         MOVZX_r8_r32( R_AL, R_EAX );
  1154                         store_spreg( R_EAX, R_T );
  1156                         break;
  1157                     case 0x5:
  1158                         { /* DMULU.L Rm, Rn */
  1159                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1160                         load_reg( R_EAX, Rm );
  1161                         load_reg( R_ECX, Rn );
  1162                         MUL_r32(R_ECX);
  1163                         store_spreg( R_EDX, R_MACH );
  1164                         store_spreg( R_EAX, R_MACL );
  1166                         break;
  1167                     case 0x6:
  1168                         { /* CMP/HI Rm, Rn */
  1169                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1170                         load_reg( R_EAX, Rm );
  1171                         load_reg( R_ECX, Rn );
  1172                         CMP_r32_r32( R_EAX, R_ECX );
  1173                         SETA_t();
  1175                         break;
  1176                     case 0x7:
  1177                         { /* CMP/GT Rm, Rn */
  1178                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1179                         load_reg( R_EAX, Rm );
  1180                         load_reg( R_ECX, Rn );
  1181                         CMP_r32_r32( R_EAX, R_ECX );
  1182                         SETG_t();
  1184                         break;
  1185                     case 0x8:
  1186                         { /* SUB Rm, Rn */
  1187                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1188                         load_reg( R_EAX, Rm );
  1189                         load_reg( R_ECX, Rn );
  1190                         SUB_r32_r32( R_EAX, R_ECX );
  1191                         store_reg( R_ECX, Rn );
  1193                         break;
  1194                     case 0xA:
  1195                         { /* SUBC Rm, Rn */
  1196                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1197                         load_reg( R_EAX, Rm );
  1198                         load_reg( R_ECX, Rn );
  1199                         LDC_t();
  1200                         SBB_r32_r32( R_EAX, R_ECX );
  1201                         store_reg( R_ECX, Rn );
  1202                         SETC_t();
  1204                         break;
  1205                     case 0xB:
  1206                         { /* SUBV Rm, Rn */
  1207                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1208                         load_reg( R_EAX, Rm );
  1209                         load_reg( R_ECX, Rn );
  1210                         SUB_r32_r32( R_EAX, R_ECX );
  1211                         store_reg( R_ECX, Rn );
  1212                         SETO_t();
  1214                         break;
  1215                     case 0xC:
  1216                         { /* ADD Rm, Rn */
  1217                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1218                         load_reg( R_EAX, Rm );
  1219                         load_reg( R_ECX, Rn );
  1220                         ADD_r32_r32( R_EAX, R_ECX );
  1221                         store_reg( R_ECX, Rn );
  1223                         break;
  1224                     case 0xD:
  1225                         { /* DMULS.L Rm, Rn */
  1226                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1227                         load_reg( R_EAX, Rm );
  1228                         load_reg( R_ECX, Rn );
  1229                         IMUL_r32(R_ECX);
  1230                         store_spreg( R_EDX, R_MACH );
  1231                         store_spreg( R_EAX, R_MACL );
  1233                         break;
  1234                     case 0xE:
  1235                         { /* ADDC Rm, Rn */
  1236                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1237                         load_reg( R_EAX, Rm );
  1238                         load_reg( R_ECX, Rn );
  1239                         LDC_t();
  1240                         ADC_r32_r32( R_EAX, R_ECX );
  1241                         store_reg( R_ECX, Rn );
  1242                         SETC_t();
  1244                         break;
  1245                     case 0xF:
  1246                         { /* ADDV Rm, Rn */
  1247                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1248                         load_reg( R_EAX, Rm );
  1249                         load_reg( R_ECX, Rn );
  1250                         ADD_r32_r32( R_EAX, R_ECX );
  1251                         store_reg( R_ECX, Rn );
  1252                         SETO_t();
  1254                         break;
  1255                     default:
  1256                         UNDEF();
  1257                         break;
  1259                 break;
  1260             case 0x4:
  1261                 switch( ir&0xF ) {
  1262                     case 0x0:
  1263                         switch( (ir&0xF0) >> 4 ) {
  1264                             case 0x0:
  1265                                 { /* SHLL Rn */
  1266                                 uint32_t Rn = ((ir>>8)&0xF); 
  1267                                 load_reg( R_EAX, Rn );
  1268                                 SHL1_r32( R_EAX );
  1269                                 store_reg( R_EAX, Rn );
  1271                                 break;
  1272                             case 0x1:
  1273                                 { /* DT Rn */
  1274                                 uint32_t Rn = ((ir>>8)&0xF); 
  1275                                 load_reg( R_EAX, Rn );
  1276                                 ADD_imm8s_r32( -1, R_EAX );
  1277                                 store_reg( R_EAX, Rn );
  1278                                 SETE_t();
  1280                                 break;
  1281                             case 0x2:
  1282                                 { /* SHAL Rn */
  1283                                 uint32_t Rn = ((ir>>8)&0xF); 
  1284                                 load_reg( R_EAX, Rn );
  1285                                 SHL1_r32( R_EAX );
  1286                                 store_reg( R_EAX, Rn );
  1288                                 break;
  1289                             default:
  1290                                 UNDEF();
  1291                                 break;
  1293                         break;
  1294                     case 0x1:
  1295                         switch( (ir&0xF0) >> 4 ) {
  1296                             case 0x0:
  1297                                 { /* SHLR Rn */
  1298                                 uint32_t Rn = ((ir>>8)&0xF); 
  1299                                 load_reg( R_EAX, Rn );
  1300                                 SHR1_r32( R_EAX );
  1301                                 store_reg( R_EAX, Rn );
  1303                                 break;
  1304                             case 0x1:
  1305                                 { /* CMP/PZ Rn */
  1306                                 uint32_t Rn = ((ir>>8)&0xF); 
  1307                                 load_reg( R_EAX, Rn );
  1308                                 CMP_imm8s_r32( 0, R_EAX );
  1309                                 SETGE_t();
  1311                                 break;
  1312                             case 0x2:
  1313                                 { /* SHAR Rn */
  1314                                 uint32_t Rn = ((ir>>8)&0xF); 
  1315                                 load_reg( R_EAX, Rn );
  1316                                 SAR1_r32( R_EAX );
  1317                                 store_reg( R_EAX, Rn );
  1319                                 break;
  1320                             default:
  1321                                 UNDEF();
  1322                                 break;
  1324                         break;
  1325                     case 0x2:
  1326                         switch( (ir&0xF0) >> 4 ) {
  1327                             case 0x0:
  1328                                 { /* STS.L MACH, @-Rn */
  1329                                 uint32_t Rn = ((ir>>8)&0xF); 
  1330                                 load_reg( R_ECX, Rn );
  1331                                 check_walign32( R_ECX );
  1332                                 ADD_imm8s_r32( -4, R_ECX );
  1333                                 store_reg( R_ECX, Rn );
  1334                                 load_spreg( R_EAX, R_MACH );
  1335                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1337                                 break;
  1338                             case 0x1:
  1339                                 { /* STS.L MACL, @-Rn */
  1340                                 uint32_t Rn = ((ir>>8)&0xF); 
  1341                                 load_reg( R_ECX, Rn );
  1342                                 check_walign32( R_ECX );
  1343                                 ADD_imm8s_r32( -4, R_ECX );
  1344                                 store_reg( R_ECX, Rn );
  1345                                 load_spreg( R_EAX, R_MACL );
  1346                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1348                                 break;
  1349                             case 0x2:
  1350                                 { /* STS.L PR, @-Rn */
  1351                                 uint32_t Rn = ((ir>>8)&0xF); 
  1352                                 load_reg( R_ECX, Rn );
  1353                                 check_walign32( R_ECX );
  1354                                 ADD_imm8s_r32( -4, R_ECX );
  1355                                 store_reg( R_ECX, Rn );
  1356                                 load_spreg( R_EAX, R_PR );
  1357                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1359                                 break;
  1360                             case 0x3:
  1361                                 { /* STC.L SGR, @-Rn */
  1362                                 uint32_t Rn = ((ir>>8)&0xF); 
  1363                                 check_priv();
  1364                                 load_reg( R_ECX, Rn );
  1365                                 check_walign32( R_ECX );
  1366                                 ADD_imm8s_r32( -4, R_ECX );
  1367                                 store_reg( R_ECX, Rn );
  1368                                 load_spreg( R_EAX, R_SGR );
  1369                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1371                                 break;
  1372                             case 0x5:
  1373                                 { /* STS.L FPUL, @-Rn */
  1374                                 uint32_t Rn = ((ir>>8)&0xF); 
  1375                                 load_reg( R_ECX, Rn );
  1376                                 check_walign32( R_ECX );
  1377                                 ADD_imm8s_r32( -4, R_ECX );
  1378                                 store_reg( R_ECX, Rn );
  1379                                 load_spreg( R_EAX, R_FPUL );
  1380                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1382                                 break;
  1383                             case 0x6:
  1384                                 { /* STS.L FPSCR, @-Rn */
  1385                                 uint32_t Rn = ((ir>>8)&0xF); 
  1386                                 load_reg( R_ECX, Rn );
  1387                                 check_walign32( R_ECX );
  1388                                 ADD_imm8s_r32( -4, R_ECX );
  1389                                 store_reg( R_ECX, Rn );
  1390                                 load_spreg( R_EAX, R_FPSCR );
  1391                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1393                                 break;
  1394                             case 0xF:
  1395                                 { /* STC.L DBR, @-Rn */
  1396                                 uint32_t Rn = ((ir>>8)&0xF); 
  1397                                 check_priv();
  1398                                 load_reg( R_ECX, Rn );
  1399                                 check_walign32( R_ECX );
  1400                                 ADD_imm8s_r32( -4, R_ECX );
  1401                                 store_reg( R_ECX, Rn );
  1402                                 load_spreg( R_EAX, R_DBR );
  1403                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1405                                 break;
  1406                             default:
  1407                                 UNDEF();
  1408                                 break;
  1410                         break;
  1411                     case 0x3:
  1412                         switch( (ir&0x80) >> 7 ) {
  1413                             case 0x0:
  1414                                 switch( (ir&0x70) >> 4 ) {
  1415                                     case 0x0:
  1416                                         { /* STC.L SR, @-Rn */
  1417                                         uint32_t Rn = ((ir>>8)&0xF); 
  1418                                         check_priv();
  1419                                         call_func0( sh4_read_sr );
  1420                                         load_reg( R_ECX, Rn );
  1421                                         check_walign32( R_ECX );
  1422                                         ADD_imm8s_r32( -4, R_ECX );
  1423                                         store_reg( R_ECX, Rn );
  1424                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1426                                         break;
  1427                                     case 0x1:
  1428                                         { /* STC.L GBR, @-Rn */
  1429                                         uint32_t Rn = ((ir>>8)&0xF); 
  1430                                         load_reg( R_ECX, Rn );
  1431                                         check_walign32( R_ECX );
  1432                                         ADD_imm8s_r32( -4, R_ECX );
  1433                                         store_reg( R_ECX, Rn );
  1434                                         load_spreg( R_EAX, R_GBR );
  1435                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1437                                         break;
  1438                                     case 0x2:
  1439                                         { /* STC.L VBR, @-Rn */
  1440                                         uint32_t Rn = ((ir>>8)&0xF); 
  1441                                         check_priv();
  1442                                         load_reg( R_ECX, Rn );
  1443                                         check_walign32( R_ECX );
  1444                                         ADD_imm8s_r32( -4, R_ECX );
  1445                                         store_reg( R_ECX, Rn );
  1446                                         load_spreg( R_EAX, R_VBR );
  1447                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1449                                         break;
  1450                                     case 0x3:
  1451                                         { /* STC.L SSR, @-Rn */
  1452                                         uint32_t Rn = ((ir>>8)&0xF); 
  1453                                         check_priv();
  1454                                         load_reg( R_ECX, Rn );
  1455                                         check_walign32( R_ECX );
  1456                                         ADD_imm8s_r32( -4, R_ECX );
  1457                                         store_reg( R_ECX, Rn );
  1458                                         load_spreg( R_EAX, R_SSR );
  1459                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1461                                         break;
  1462                                     case 0x4:
  1463                                         { /* STC.L SPC, @-Rn */
  1464                                         uint32_t Rn = ((ir>>8)&0xF); 
  1465                                         check_priv();
  1466                                         load_reg( R_ECX, Rn );
  1467                                         check_walign32( R_ECX );
  1468                                         ADD_imm8s_r32( -4, R_ECX );
  1469                                         store_reg( R_ECX, Rn );
  1470                                         load_spreg( R_EAX, R_SPC );
  1471                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1473                                         break;
  1474                                     default:
  1475                                         UNDEF();
  1476                                         break;
  1478                                 break;
  1479                             case 0x1:
  1480                                 { /* STC.L Rm_BANK, @-Rn */
  1481                                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
  1482                                 check_priv();
  1483                                 load_reg( R_ECX, Rn );
  1484                                 check_walign32( R_ECX );
  1485                                 ADD_imm8s_r32( -4, R_ECX );
  1486                                 store_reg( R_ECX, Rn );
  1487                                 load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
  1488                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1490                                 break;
  1492                         break;
  1493                     case 0x4:
  1494                         switch( (ir&0xF0) >> 4 ) {
  1495                             case 0x0:
  1496                                 { /* ROTL Rn */
  1497                                 uint32_t Rn = ((ir>>8)&0xF); 
  1498                                 load_reg( R_EAX, Rn );
  1499                                 ROL1_r32( R_EAX );
  1500                                 store_reg( R_EAX, Rn );
  1501                                 SETC_t();
  1503                                 break;
  1504                             case 0x2:
  1505                                 { /* ROTCL Rn */
  1506                                 uint32_t Rn = ((ir>>8)&0xF); 
  1507                                 load_reg( R_EAX, Rn );
  1508                                 LDC_t();
  1509                                 RCL1_r32( R_EAX );
  1510                                 store_reg( R_EAX, Rn );
  1511                                 SETC_t();
  1513                                 break;
  1514                             default:
  1515                                 UNDEF();
  1516                                 break;
  1518                         break;
  1519                     case 0x5:
  1520                         switch( (ir&0xF0) >> 4 ) {
  1521                             case 0x0:
  1522                                 { /* ROTR Rn */
  1523                                 uint32_t Rn = ((ir>>8)&0xF); 
  1524                                 load_reg( R_EAX, Rn );
  1525                                 ROR1_r32( R_EAX );
  1526                                 store_reg( R_EAX, Rn );
  1527                                 SETC_t();
  1529                                 break;
  1530                             case 0x1:
  1531                                 { /* CMP/PL Rn */
  1532                                 uint32_t Rn = ((ir>>8)&0xF); 
  1533                                 load_reg( R_EAX, Rn );
  1534                                 CMP_imm8s_r32( 0, R_EAX );
  1535                                 SETG_t();
  1537                                 break;
  1538                             case 0x2:
  1539                                 { /* ROTCR Rn */
  1540                                 uint32_t Rn = ((ir>>8)&0xF); 
  1541                                 load_reg( R_EAX, Rn );
  1542                                 LDC_t();
  1543                                 RCR1_r32( R_EAX );
  1544                                 store_reg( R_EAX, Rn );
  1545                                 SETC_t();
  1547                                 break;
  1548                             default:
  1549                                 UNDEF();
  1550                                 break;
  1552                         break;
  1553                     case 0x6:
  1554                         switch( (ir&0xF0) >> 4 ) {
  1555                             case 0x0:
  1556                                 { /* LDS.L @Rm+, MACH */
  1557                                 uint32_t Rm = ((ir>>8)&0xF); 
  1558                                 load_reg( R_EAX, Rm );
  1559                                 check_ralign32( R_EAX );
  1560                                 MOV_r32_r32( R_EAX, R_ECX );
  1561                                 ADD_imm8s_r32( 4, R_EAX );
  1562                                 store_reg( R_EAX, Rm );
  1563                                 MEM_READ_LONG( R_ECX, R_EAX );
  1564                                 store_spreg( R_EAX, R_MACH );
  1566                                 break;
  1567                             case 0x1:
  1568                                 { /* LDS.L @Rm+, MACL */
  1569                                 uint32_t Rm = ((ir>>8)&0xF); 
  1570                                 load_reg( R_EAX, Rm );
  1571                                 check_ralign32( R_EAX );
  1572                                 MOV_r32_r32( R_EAX, R_ECX );
  1573                                 ADD_imm8s_r32( 4, R_EAX );
  1574                                 store_reg( R_EAX, Rm );
  1575                                 MEM_READ_LONG( R_ECX, R_EAX );
  1576                                 store_spreg( R_EAX, R_MACL );
  1578                                 break;
  1579                             case 0x2:
  1580                                 { /* LDS.L @Rm+, PR */
  1581                                 uint32_t Rm = ((ir>>8)&0xF); 
  1582                                 load_reg( R_EAX, Rm );
  1583                                 check_ralign32( R_EAX );
  1584                                 MOV_r32_r32( R_EAX, R_ECX );
  1585                                 ADD_imm8s_r32( 4, R_EAX );
  1586                                 store_reg( R_EAX, Rm );
  1587                                 MEM_READ_LONG( R_ECX, R_EAX );
  1588                                 store_spreg( R_EAX, R_PR );
  1590                                 break;
  1591                             case 0x3:
  1592                                 { /* LDC.L @Rm+, SGR */
  1593                                 uint32_t Rm = ((ir>>8)&0xF); 
  1594                                 check_priv();
  1595                                 load_reg( R_EAX, Rm );
  1596                                 check_ralign32( R_EAX );
  1597                                 MOV_r32_r32( R_EAX, R_ECX );
  1598                                 ADD_imm8s_r32( 4, R_EAX );
  1599                                 store_reg( R_EAX, Rm );
  1600                                 MEM_READ_LONG( R_ECX, R_EAX );
  1601                                 store_spreg( R_EAX, R_SGR );
  1603                                 break;
  1604                             case 0x5:
  1605                                 { /* LDS.L @Rm+, FPUL */
  1606                                 uint32_t Rm = ((ir>>8)&0xF); 
  1607                                 load_reg( R_EAX, Rm );
  1608                                 check_ralign32( R_EAX );
  1609                                 MOV_r32_r32( R_EAX, R_ECX );
  1610                                 ADD_imm8s_r32( 4, R_EAX );
  1611                                 store_reg( R_EAX, Rm );
  1612                                 MEM_READ_LONG( R_ECX, R_EAX );
  1613                                 store_spreg( R_EAX, R_FPUL );
  1615                                 break;
  1616                             case 0x6:
  1617                                 { /* LDS.L @Rm+, FPSCR */
  1618                                 uint32_t Rm = ((ir>>8)&0xF); 
  1619                                 load_reg( R_EAX, Rm );
  1620                                 check_ralign32( R_EAX );
  1621                                 MOV_r32_r32( R_EAX, R_ECX );
  1622                                 ADD_imm8s_r32( 4, R_EAX );
  1623                                 store_reg( R_EAX, Rm );
  1624                                 MEM_READ_LONG( R_ECX, R_EAX );
  1625                                 store_spreg( R_EAX, R_FPSCR );
  1626                                 update_fr_bank( R_EAX );
  1628                                 break;
  1629                             case 0xF:
  1630                                 { /* LDC.L @Rm+, DBR */
  1631                                 uint32_t Rm = ((ir>>8)&0xF); 
  1632                                 check_priv();
  1633                                 load_reg( R_EAX, Rm );
  1634                                 check_ralign32( R_EAX );
  1635                                 MOV_r32_r32( R_EAX, R_ECX );
  1636                                 ADD_imm8s_r32( 4, R_EAX );
  1637                                 store_reg( R_EAX, Rm );
  1638                                 MEM_READ_LONG( R_ECX, R_EAX );
  1639                                 store_spreg( R_EAX, R_DBR );
  1641                                 break;
  1642                             default:
  1643                                 UNDEF();
  1644                                 break;
  1646                         break;
  1647                     case 0x7:
  1648                         switch( (ir&0x80) >> 7 ) {
  1649                             case 0x0:
  1650                                 switch( (ir&0x70) >> 4 ) {
  1651                                     case 0x0:
  1652                                         { /* LDC.L @Rm+, SR */
  1653                                         uint32_t Rm = ((ir>>8)&0xF); 
  1654                                         if( sh4_x86.in_delay_slot ) {
  1655                                     	SLOTILLEGAL();
  1656                                         } else {
  1657                                     	check_priv();
  1658                                     	load_reg( R_EAX, Rm );
  1659                                     	check_ralign32( R_EAX );
  1660                                     	MOV_r32_r32( R_EAX, R_ECX );
  1661                                     	ADD_imm8s_r32( 4, R_EAX );
  1662                                     	store_reg( R_EAX, Rm );
  1663                                     	MEM_READ_LONG( R_ECX, R_EAX );
  1664                                     	call_func1( sh4_write_sr, R_EAX );
  1665                                     	sh4_x86.priv_checked = FALSE;
  1666                                     	sh4_x86.fpuen_checked = FALSE;
  1669                                         break;
  1670                                     case 0x1:
  1671                                         { /* LDC.L @Rm+, GBR */
  1672                                         uint32_t Rm = ((ir>>8)&0xF); 
  1673                                         load_reg( R_EAX, Rm );
  1674                                         check_ralign32( R_EAX );
  1675                                         MOV_r32_r32( R_EAX, R_ECX );
  1676                                         ADD_imm8s_r32( 4, R_EAX );
  1677                                         store_reg( R_EAX, Rm );
  1678                                         MEM_READ_LONG( R_ECX, R_EAX );
  1679                                         store_spreg( R_EAX, R_GBR );
  1681                                         break;
  1682                                     case 0x2:
  1683                                         { /* LDC.L @Rm+, VBR */
  1684                                         uint32_t Rm = ((ir>>8)&0xF); 
  1685                                         check_priv();
  1686                                         load_reg( R_EAX, Rm );
  1687                                         check_ralign32( R_EAX );
  1688                                         MOV_r32_r32( R_EAX, R_ECX );
  1689                                         ADD_imm8s_r32( 4, R_EAX );
  1690                                         store_reg( R_EAX, Rm );
  1691                                         MEM_READ_LONG( R_ECX, R_EAX );
  1692                                         store_spreg( R_EAX, R_VBR );
  1694                                         break;
  1695                                     case 0x3:
  1696                                         { /* LDC.L @Rm+, SSR */
  1697                                         uint32_t Rm = ((ir>>8)&0xF); 
  1698                                         check_priv();
  1699                                         load_reg( R_EAX, Rm );
  1700                                         MOV_r32_r32( R_EAX, R_ECX );
  1701                                         ADD_imm8s_r32( 4, R_EAX );
  1702                                         store_reg( R_EAX, Rm );
  1703                                         MEM_READ_LONG( R_ECX, R_EAX );
  1704                                         store_spreg( R_EAX, R_SSR );
  1706                                         break;
  1707                                     case 0x4:
  1708                                         { /* LDC.L @Rm+, SPC */
  1709                                         uint32_t Rm = ((ir>>8)&0xF); 
  1710                                         check_priv();
  1711                                         load_reg( R_EAX, Rm );
  1712                                         check_ralign32( R_EAX );
  1713                                         MOV_r32_r32( R_EAX, R_ECX );
  1714                                         ADD_imm8s_r32( 4, R_EAX );
  1715                                         store_reg( R_EAX, Rm );
  1716                                         MEM_READ_LONG( R_ECX, R_EAX );
  1717                                         store_spreg( R_EAX, R_SPC );
  1719                                         break;
  1720                                     default:
  1721                                         UNDEF();
  1722                                         break;
  1724                                 break;
  1725                             case 0x1:
  1726                                 { /* LDC.L @Rm+, Rn_BANK */
  1727                                 uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
  1728                                 check_priv();
  1729                                 load_reg( R_EAX, Rm );
  1730                                 check_ralign32( R_EAX );
  1731                                 MOV_r32_r32( R_EAX, R_ECX );
  1732                                 ADD_imm8s_r32( 4, R_EAX );
  1733                                 store_reg( R_EAX, Rm );
  1734                                 MEM_READ_LONG( R_ECX, R_EAX );
  1735                                 store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
  1737                                 break;
  1739                         break;
  1740                     case 0x8:
  1741                         switch( (ir&0xF0) >> 4 ) {
  1742                             case 0x0:
  1743                                 { /* SHLL2 Rn */
  1744                                 uint32_t Rn = ((ir>>8)&0xF); 
  1745                                 load_reg( R_EAX, Rn );
  1746                                 SHL_imm8_r32( 2, R_EAX );
  1747                                 store_reg( R_EAX, Rn );
  1749                                 break;
  1750                             case 0x1:
  1751                                 { /* SHLL8 Rn */
  1752                                 uint32_t Rn = ((ir>>8)&0xF); 
  1753                                 load_reg( R_EAX, Rn );
  1754                                 SHL_imm8_r32( 8, R_EAX );
  1755                                 store_reg( R_EAX, Rn );
  1757                                 break;
  1758                             case 0x2:
  1759                                 { /* SHLL16 Rn */
  1760                                 uint32_t Rn = ((ir>>8)&0xF); 
  1761                                 load_reg( R_EAX, Rn );
  1762                                 SHL_imm8_r32( 16, R_EAX );
  1763                                 store_reg( R_EAX, Rn );
  1765                                 break;
  1766                             default:
  1767                                 UNDEF();
  1768                                 break;
  1770                         break;
  1771                     case 0x9:
  1772                         switch( (ir&0xF0) >> 4 ) {
  1773                             case 0x0:
  1774                                 { /* SHLR2 Rn */
  1775                                 uint32_t Rn = ((ir>>8)&0xF); 
  1776                                 load_reg( R_EAX, Rn );
  1777                                 SHR_imm8_r32( 2, R_EAX );
  1778                                 store_reg( R_EAX, Rn );
  1780                                 break;
  1781                             case 0x1:
  1782                                 { /* SHLR8 Rn */
  1783                                 uint32_t Rn = ((ir>>8)&0xF); 
  1784                                 load_reg( R_EAX, Rn );
  1785                                 SHR_imm8_r32( 8, R_EAX );
  1786                                 store_reg( R_EAX, Rn );
  1788                                 break;
  1789                             case 0x2:
  1790                                 { /* SHLR16 Rn */
  1791                                 uint32_t Rn = ((ir>>8)&0xF); 
  1792                                 load_reg( R_EAX, Rn );
  1793                                 SHR_imm8_r32( 16, R_EAX );
  1794                                 store_reg( R_EAX, Rn );
  1796                                 break;
  1797                             default:
  1798                                 UNDEF();
  1799                                 break;
  1801                         break;
  1802                     case 0xA:
  1803                         switch( (ir&0xF0) >> 4 ) {
  1804                             case 0x0:
  1805                                 { /* LDS Rm, MACH */
  1806                                 uint32_t Rm = ((ir>>8)&0xF); 
  1807                                 load_reg( R_EAX, Rm );
  1808                                 store_spreg( R_EAX, R_MACH );
  1810                                 break;
  1811                             case 0x1:
  1812                                 { /* LDS Rm, MACL */
  1813                                 uint32_t Rm = ((ir>>8)&0xF); 
  1814                                 load_reg( R_EAX, Rm );
  1815                                 store_spreg( R_EAX, R_MACL );
  1817                                 break;
  1818                             case 0x2:
  1819                                 { /* LDS Rm, PR */
  1820                                 uint32_t Rm = ((ir>>8)&0xF); 
  1821                                 load_reg( R_EAX, Rm );
  1822                                 store_spreg( R_EAX, R_PR );
  1824                                 break;
  1825                             case 0x3:
  1826                                 { /* LDC Rm, SGR */
  1827                                 uint32_t Rm = ((ir>>8)&0xF); 
  1828                                 check_priv();
  1829                                 load_reg( R_EAX, Rm );
  1830                                 store_spreg( R_EAX, R_SGR );
  1832                                 break;
  1833                             case 0x5:
  1834                                 { /* LDS Rm, FPUL */
  1835                                 uint32_t Rm = ((ir>>8)&0xF); 
  1836                                 load_reg( R_EAX, Rm );
  1837                                 store_spreg( R_EAX, R_FPUL );
  1839                                 break;
  1840                             case 0x6:
  1841                                 { /* LDS Rm, FPSCR */
  1842                                 uint32_t Rm = ((ir>>8)&0xF); 
  1843                                 load_reg( R_EAX, Rm );
  1844                                 store_spreg( R_EAX, R_FPSCR );
  1845                                 update_fr_bank( R_EAX );
  1847                                 break;
  1848                             case 0xF:
  1849                                 { /* LDC Rm, DBR */
  1850                                 uint32_t Rm = ((ir>>8)&0xF); 
  1851                                 check_priv();
  1852                                 load_reg( R_EAX, Rm );
  1853                                 store_spreg( R_EAX, R_DBR );
  1855                                 break;
  1856                             default:
  1857                                 UNDEF();
  1858                                 break;
  1860                         break;
  1861                     case 0xB:
  1862                         switch( (ir&0xF0) >> 4 ) {
  1863                             case 0x0:
  1864                                 { /* JSR @Rn */
  1865                                 uint32_t Rn = ((ir>>8)&0xF); 
  1866                                 if( sh4_x86.in_delay_slot ) {
  1867                             	SLOTILLEGAL();
  1868                                 } else {
  1869                             	load_imm32( R_EAX, pc + 4 );
  1870                             	store_spreg( R_EAX, R_PR );
  1871                             	load_reg( R_EDI, Rn );
  1872                             	sh4_x86.in_delay_slot = TRUE;
  1873                             	return 0;
  1876                                 break;
  1877                             case 0x1:
  1878                                 { /* TAS.B @Rn */
  1879                                 uint32_t Rn = ((ir>>8)&0xF); 
  1880                                 load_reg( R_ECX, Rn );
  1881                                 MEM_READ_BYTE( R_ECX, R_EAX );
  1882                                 TEST_r8_r8( R_AL, R_AL );
  1883                                 SETE_t();
  1884                                 OR_imm8_r8( 0x80, R_AL );
  1885                                 load_reg( R_ECX, Rn );
  1886                                 MEM_WRITE_BYTE( R_ECX, R_EAX );
  1888                                 break;
  1889                             case 0x2:
  1890                                 { /* JMP @Rn */
  1891                                 uint32_t Rn = ((ir>>8)&0xF); 
  1892                                 if( sh4_x86.in_delay_slot ) {
  1893                             	SLOTILLEGAL();
  1894                                 } else {
  1895                             	load_reg( R_EDI, Rn );
  1896                             	sh4_x86.in_delay_slot = TRUE;
  1897                             	return 0;
  1900                                 break;
  1901                             default:
  1902                                 UNDEF();
  1903                                 break;
  1905                         break;
  1906                     case 0xC:
  1907                         { /* SHAD Rm, Rn */
  1908                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1909                         /* Annoyingly enough, not directly convertible */
  1910                         load_reg( R_EAX, Rn );
  1911                         load_reg( R_ECX, Rm );
  1912                         CMP_imm32_r32( 0, R_ECX );
  1913                         JGE_rel8(16, doshl);
  1915                         NEG_r32( R_ECX );      // 2
  1916                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1917                         JE_rel8( 4, emptysar);     // 2
  1918                         SAR_r32_CL( R_EAX );       // 2
  1919                         JMP_rel8(10, end);          // 2
  1921                         JMP_TARGET(emptysar);
  1922                         SAR_imm8_r32(31, R_EAX );  // 3
  1923                         JMP_rel8(5, end2);
  1925                         JMP_TARGET(doshl);
  1926                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1927                         SHL_r32_CL( R_EAX );       // 2
  1928                         JMP_TARGET(end);
  1929                         JMP_TARGET(end2);
  1930                         store_reg( R_EAX, Rn );
  1932                         break;
  1933                     case 0xD:
  1934                         { /* SHLD Rm, Rn */
  1935                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1936                         load_reg( R_EAX, Rn );
  1937                         load_reg( R_ECX, Rm );
  1938                         CMP_imm32_r32( 0, R_ECX );
  1939                         JGE_rel8(15, doshl);
  1941                         NEG_r32( R_ECX );      // 2
  1942                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1943                         JE_rel8( 4, emptyshr );
  1944                         SHR_r32_CL( R_EAX );       // 2
  1945                         JMP_rel8(9, end);          // 2
  1947                         JMP_TARGET(emptyshr);
  1948                         XOR_r32_r32( R_EAX, R_EAX );
  1949                         JMP_rel8(5, end2);
  1951                         JMP_TARGET(doshl);
  1952                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1953                         SHL_r32_CL( R_EAX );       // 2
  1954                         JMP_TARGET(end);
  1955                         JMP_TARGET(end2);
  1956                         store_reg( R_EAX, Rn );
  1958                         break;
  1959                     case 0xE:
  1960                         switch( (ir&0x80) >> 7 ) {
  1961                             case 0x0:
  1962                                 switch( (ir&0x70) >> 4 ) {
  1963                                     case 0x0:
  1964                                         { /* LDC Rm, SR */
  1965                                         uint32_t Rm = ((ir>>8)&0xF); 
  1966                                         if( sh4_x86.in_delay_slot ) {
  1967                                     	SLOTILLEGAL();
  1968                                         } else {
  1969                                     	check_priv();
  1970                                     	load_reg( R_EAX, Rm );
  1971                                     	call_func1( sh4_write_sr, R_EAX );
  1972                                     	sh4_x86.priv_checked = FALSE;
  1973                                     	sh4_x86.fpuen_checked = FALSE;
  1976                                         break;
  1977                                     case 0x1:
  1978                                         { /* LDC Rm, GBR */
  1979                                         uint32_t Rm = ((ir>>8)&0xF); 
  1980                                         load_reg( R_EAX, Rm );
  1981                                         store_spreg( R_EAX, R_GBR );
  1983                                         break;
  1984                                     case 0x2:
  1985                                         { /* LDC Rm, VBR */
  1986                                         uint32_t Rm = ((ir>>8)&0xF); 
  1987                                         check_priv();
  1988                                         load_reg( R_EAX, Rm );
  1989                                         store_spreg( R_EAX, R_VBR );
  1991                                         break;
  1992                                     case 0x3:
  1993                                         { /* LDC Rm, SSR */
  1994                                         uint32_t Rm = ((ir>>8)&0xF); 
  1995                                         check_priv();
  1996                                         load_reg( R_EAX, Rm );
  1997                                         store_spreg( R_EAX, R_SSR );
  1999                                         break;
  2000                                     case 0x4:
  2001                                         { /* LDC Rm, SPC */
  2002                                         uint32_t Rm = ((ir>>8)&0xF); 
  2003                                         check_priv();
  2004                                         load_reg( R_EAX, Rm );
  2005                                         store_spreg( R_EAX, R_SPC );
  2007                                         break;
  2008                                     default:
  2009                                         UNDEF();
  2010                                         break;
  2012                                 break;
  2013                             case 0x1:
  2014                                 { /* LDC Rm, Rn_BANK */
  2015                                 uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
  2016                                 check_priv();
  2017                                 load_reg( R_EAX, Rm );
  2018                                 store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
  2020                                 break;
  2022                         break;
  2023                     case 0xF:
  2024                         { /* MAC.W @Rm+, @Rn+ */
  2025                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2026                         load_reg( R_ECX, Rm );
  2027                         check_ralign16( R_ECX );
  2028                         load_reg( R_ECX, Rn );
  2029                         check_ralign16( R_ECX );
  2030                         ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rn]) );
  2031                         MEM_READ_WORD( R_ECX, R_EAX );
  2032                         PUSH_r32( R_EAX );
  2033                         load_reg( R_ECX, Rm );
  2034                         ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rm]) );
  2035                         MEM_READ_WORD( R_ECX, R_EAX );
  2036                         POP_r32( R_ECX );
  2037                         IMUL_r32( R_ECX );
  2039                         load_spreg( R_ECX, R_S );
  2040                         TEST_r32_r32( R_ECX, R_ECX );
  2041                         JE_rel8( 47, nosat );
  2043                         ADD_r32_sh4r( R_EAX, R_MACL );  // 6
  2044                         JNO_rel8( 51, end );            // 2
  2045                         load_imm32( R_EDX, 1 );         // 5
  2046                         store_spreg( R_EDX, R_MACH );   // 6
  2047                         JS_rel8( 13, positive );        // 2
  2048                         load_imm32( R_EAX, 0x80000000 );// 5
  2049                         store_spreg( R_EAX, R_MACL );   // 6
  2050                         JMP_rel8( 25, end2 );           // 2
  2052                         JMP_TARGET(positive);
  2053                         load_imm32( R_EAX, 0x7FFFFFFF );// 5
  2054                         store_spreg( R_EAX, R_MACL );   // 6
  2055                         JMP_rel8( 12, end3);            // 2
  2057                         JMP_TARGET(nosat);
  2058                         ADD_r32_sh4r( R_EAX, R_MACL );  // 6
  2059                         ADC_r32_sh4r( R_EDX, R_MACH );  // 6
  2060                         JMP_TARGET(end);
  2061                         JMP_TARGET(end2);
  2062                         JMP_TARGET(end3);
  2064                         break;
  2066                 break;
  2067             case 0x5:
  2068                 { /* MOV.L @(disp, Rm), Rn */
  2069                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
  2070                 load_reg( R_ECX, Rm );
  2071                 ADD_imm8s_r32( disp, R_ECX );
  2072                 check_ralign32( R_ECX );
  2073                 MEM_READ_LONG( R_ECX, R_EAX );
  2074                 store_reg( R_EAX, Rn );
  2076                 break;
  2077             case 0x6:
  2078                 switch( ir&0xF ) {
  2079                     case 0x0:
  2080                         { /* MOV.B @Rm, Rn */
  2081                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2082                         load_reg( R_ECX, Rm );
  2083                         MEM_READ_BYTE( R_ECX, R_EAX );
  2084                         store_reg( R_EAX, Rn );
  2086                         break;
  2087                     case 0x1:
  2088                         { /* MOV.W @Rm, Rn */
  2089                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2090                         load_reg( R_ECX, Rm );
  2091                         check_ralign16( R_ECX );
  2092                         MEM_READ_WORD( R_ECX, R_EAX );
  2093                         store_reg( R_EAX, Rn );
  2095                         break;
  2096                     case 0x2:
  2097                         { /* MOV.L @Rm, Rn */
  2098                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2099                         load_reg( R_ECX, Rm );
  2100                         check_ralign32( R_ECX );
  2101                         MEM_READ_LONG( R_ECX, R_EAX );
  2102                         store_reg( R_EAX, Rn );
  2104                         break;
  2105                     case 0x3:
  2106                         { /* MOV Rm, Rn */
  2107                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2108                         load_reg( R_EAX, Rm );
  2109                         store_reg( R_EAX, Rn );
  2111                         break;
  2112                     case 0x4:
  2113                         { /* MOV.B @Rm+, Rn */
  2114                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2115                         load_reg( R_ECX, Rm );
  2116                         MOV_r32_r32( R_ECX, R_EAX );
  2117                         ADD_imm8s_r32( 1, R_EAX );
  2118                         store_reg( R_EAX, Rm );
  2119                         MEM_READ_BYTE( R_ECX, R_EAX );
  2120                         store_reg( R_EAX, Rn );
  2122                         break;
  2123                     case 0x5:
  2124                         { /* MOV.W @Rm+, Rn */
  2125                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2126                         load_reg( R_EAX, Rm );
  2127                         check_ralign16( R_EAX );
  2128                         MOV_r32_r32( R_EAX, R_ECX );
  2129                         ADD_imm8s_r32( 2, R_EAX );
  2130                         store_reg( R_EAX, Rm );
  2131                         MEM_READ_WORD( R_ECX, R_EAX );
  2132                         store_reg( R_EAX, Rn );
  2134                         break;
  2135                     case 0x6:
  2136                         { /* MOV.L @Rm+, Rn */
  2137                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2138                         load_reg( R_EAX, Rm );
  2139                         check_ralign32( R_EAX );
  2140                         MOV_r32_r32( R_EAX, R_ECX );
  2141                         ADD_imm8s_r32( 4, R_EAX );
  2142                         store_reg( R_EAX, Rm );
  2143                         MEM_READ_LONG( R_ECX, R_EAX );
  2144                         store_reg( R_EAX, Rn );
  2146                         break;
  2147                     case 0x7:
  2148                         { /* NOT Rm, Rn */
  2149                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2150                         load_reg( R_EAX, Rm );
  2151                         NOT_r32( R_EAX );
  2152                         store_reg( R_EAX, Rn );
  2154                         break;
  2155                     case 0x8:
  2156                         { /* SWAP.B Rm, Rn */
  2157                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2158                         load_reg( R_EAX, Rm );
  2159                         XCHG_r8_r8( R_AL, R_AH );
  2160                         store_reg( R_EAX, Rn );
  2162                         break;
  2163                     case 0x9:
  2164                         { /* SWAP.W Rm, Rn */
  2165                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2166                         load_reg( R_EAX, Rm );
  2167                         MOV_r32_r32( R_EAX, R_ECX );
  2168                         SHL_imm8_r32( 16, R_ECX );
  2169                         SHR_imm8_r32( 16, R_EAX );
  2170                         OR_r32_r32( R_EAX, R_ECX );
  2171                         store_reg( R_ECX, Rn );
  2173                         break;
  2174                     case 0xA:
  2175                         { /* NEGC Rm, Rn */
  2176                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2177                         load_reg( R_EAX, Rm );
  2178                         XOR_r32_r32( R_ECX, R_ECX );
  2179                         LDC_t();
  2180                         SBB_r32_r32( R_EAX, R_ECX );
  2181                         store_reg( R_ECX, Rn );
  2182                         SETC_t();
  2184                         break;
  2185                     case 0xB:
  2186                         { /* NEG Rm, Rn */
  2187                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2188                         load_reg( R_EAX, Rm );
  2189                         NEG_r32( R_EAX );
  2190                         store_reg( R_EAX, Rn );
  2192                         break;
  2193                     case 0xC:
  2194                         { /* EXTU.B Rm, Rn */
  2195                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2196                         load_reg( R_EAX, Rm );
  2197                         MOVZX_r8_r32( R_EAX, R_EAX );
  2198                         store_reg( R_EAX, Rn );
  2200                         break;
  2201                     case 0xD:
  2202                         { /* EXTU.W Rm, Rn */
  2203                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2204                         load_reg( R_EAX, Rm );
  2205                         MOVZX_r16_r32( R_EAX, R_EAX );
  2206                         store_reg( R_EAX, Rn );
  2208                         break;
  2209                     case 0xE:
  2210                         { /* EXTS.B Rm, Rn */
  2211                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2212                         load_reg( R_EAX, Rm );
  2213                         MOVSX_r8_r32( R_EAX, R_EAX );
  2214                         store_reg( R_EAX, Rn );
  2216                         break;
  2217                     case 0xF:
  2218                         { /* EXTS.W Rm, Rn */
  2219                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2220                         load_reg( R_EAX, Rm );
  2221                         MOVSX_r16_r32( R_EAX, R_EAX );
  2222                         store_reg( R_EAX, Rn );
  2224                         break;
  2226                 break;
  2227             case 0x7:
  2228                 { /* ADD #imm, Rn */
  2229                 uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
  2230                 load_reg( R_EAX, Rn );
  2231                 ADD_imm8s_r32( imm, R_EAX );
  2232                 store_reg( R_EAX, Rn );
  2234                 break;
  2235             case 0x8:
  2236                 switch( (ir&0xF00) >> 8 ) {
  2237                     case 0x0:
  2238                         { /* MOV.B R0, @(disp, Rn) */
  2239                         uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
  2240                         load_reg( R_EAX, 0 );
  2241                         load_reg( R_ECX, Rn );
  2242                         ADD_imm32_r32( disp, R_ECX );
  2243                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2245                         break;
  2246                     case 0x1:
  2247                         { /* MOV.W R0, @(disp, Rn) */
  2248                         uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
  2249                         load_reg( R_ECX, Rn );
  2250                         load_reg( R_EAX, 0 );
  2251                         ADD_imm32_r32( disp, R_ECX );
  2252                         check_walign16( R_ECX );
  2253                         MEM_WRITE_WORD( R_ECX, R_EAX );
  2255                         break;
  2256                     case 0x4:
  2257                         { /* MOV.B @(disp, Rm), R0 */
  2258                         uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
  2259                         load_reg( R_ECX, Rm );
  2260                         ADD_imm32_r32( disp, R_ECX );
  2261                         MEM_READ_BYTE( R_ECX, R_EAX );
  2262                         store_reg( R_EAX, 0 );
  2264                         break;
  2265                     case 0x5:
  2266                         { /* MOV.W @(disp, Rm), R0 */
  2267                         uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
  2268                         load_reg( R_ECX, Rm );
  2269                         ADD_imm32_r32( disp, R_ECX );
  2270                         check_ralign16( R_ECX );
  2271                         MEM_READ_WORD( R_ECX, R_EAX );
  2272                         store_reg( R_EAX, 0 );
  2274                         break;
  2275                     case 0x8:
  2276                         { /* CMP/EQ #imm, R0 */
  2277                         int32_t imm = SIGNEXT8(ir&0xFF); 
  2278                         load_reg( R_EAX, 0 );
  2279                         CMP_imm8s_r32(imm, R_EAX);
  2280                         SETE_t();
  2282                         break;
  2283                     case 0x9:
  2284                         { /* BT disp */
  2285                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2286                         if( sh4_x86.in_delay_slot ) {
  2287                     	SLOTILLEGAL();
  2288                         } else {
  2289                     	load_imm32( R_EDI, pc + 2 );
  2290                     	CMP_imm8s_sh4r( 0, R_T );
  2291                     	JE_rel8( 5, nottaken );
  2292                     	load_imm32( R_EDI, disp + pc + 4 );
  2293                     	JMP_TARGET(nottaken);
  2294                     	INC_r32(R_ESI);
  2295                     	return 1;
  2298                         break;
  2299                     case 0xB:
  2300                         { /* BF disp */
  2301                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2302                         if( sh4_x86.in_delay_slot ) {
  2303                     	SLOTILLEGAL();
  2304                         } else {
  2305                     	load_imm32( R_EDI, pc + 2 );
  2306                     	CMP_imm8s_sh4r( 0, R_T );
  2307                     	JNE_rel8( 5, nottaken );
  2308                     	load_imm32( R_EDI, disp + pc + 4 );
  2309                     	JMP_TARGET(nottaken);
  2310                     	INC_r32(R_ESI);
  2311                     	return 1;
  2314                         break;
  2315                     case 0xD:
  2316                         { /* BT/S disp */
  2317                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2318                         if( sh4_x86.in_delay_slot ) {
  2319                     	SLOTILLEGAL();
  2320                         } else {
  2321                     	load_imm32( R_EDI, pc + 4 );
  2322                     	CMP_imm8s_sh4r( 0, R_T );
  2323                     	JE_rel8( 5, nottaken );
  2324                     	load_imm32( R_EDI, disp + pc + 4 );
  2325                     	JMP_TARGET(nottaken);
  2326                     	sh4_x86.in_delay_slot = TRUE;
  2327                     	return 0;
  2330                         break;
  2331                     case 0xF:
  2332                         { /* BF/S disp */
  2333                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2334                         if( sh4_x86.in_delay_slot ) {
  2335                     	SLOTILLEGAL();
  2336                         } else {
  2337                     	load_imm32( R_EDI, pc + 4 );
  2338                     	CMP_imm8s_sh4r( 0, R_T );
  2339                     	JNE_rel8( 5, nottaken );
  2340                     	load_imm32( R_EDI, disp + pc + 4 );
  2341                     	JMP_TARGET(nottaken);
  2342                     	sh4_x86.in_delay_slot = TRUE;
  2343                     	return 0;
  2346                         break;
  2347                     default:
  2348                         UNDEF();
  2349                         break;
  2351                 break;
  2352             case 0x9:
  2353                 { /* MOV.W @(disp, PC), Rn */
  2354                 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<1; 
  2355                 if( sh4_x86.in_delay_slot ) {
  2356             	SLOTILLEGAL();
  2357                 } else {
  2358             	load_imm32( R_ECX, pc + disp + 4 );
  2359             	MEM_READ_WORD( R_ECX, R_EAX );
  2360             	store_reg( R_EAX, Rn );
  2363                 break;
  2364             case 0xA:
  2365                 { /* BRA disp */
  2366                 int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
  2367                 if( sh4_x86.in_delay_slot ) {
  2368             	SLOTILLEGAL();
  2369                 } else {
  2370             	load_imm32( R_EDI, disp + pc + 4 );
  2371             	sh4_x86.in_delay_slot = TRUE;
  2372             	return 0;
  2375                 break;
  2376             case 0xB:
  2377                 { /* BSR disp */
  2378                 int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
  2379                 if( sh4_x86.in_delay_slot ) {
  2380             	SLOTILLEGAL();
  2381                 } else {
  2382             	load_imm32( R_EAX, pc + 4 );
  2383             	store_spreg( R_EAX, R_PR );
  2384             	load_imm32( R_EDI, disp + pc + 4 );
  2385             	sh4_x86.in_delay_slot = TRUE;
  2386             	return 0;
  2389                 break;
  2390             case 0xC:
  2391                 switch( (ir&0xF00) >> 8 ) {
  2392                     case 0x0:
  2393                         { /* MOV.B R0, @(disp, GBR) */
  2394                         uint32_t disp = (ir&0xFF); 
  2395                         load_reg( R_EAX, 0 );
  2396                         load_spreg( R_ECX, R_GBR );
  2397                         ADD_imm32_r32( disp, R_ECX );
  2398                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2400                         break;
  2401                     case 0x1:
  2402                         { /* MOV.W R0, @(disp, GBR) */
  2403                         uint32_t disp = (ir&0xFF)<<1; 
  2404                         load_spreg( R_ECX, R_GBR );
  2405                         load_reg( R_EAX, 0 );
  2406                         ADD_imm32_r32( disp, R_ECX );
  2407                         check_walign16( R_ECX );
  2408                         MEM_WRITE_WORD( R_ECX, R_EAX );
  2410                         break;
  2411                     case 0x2:
  2412                         { /* MOV.L R0, @(disp, GBR) */
  2413                         uint32_t disp = (ir&0xFF)<<2; 
  2414                         load_spreg( R_ECX, R_GBR );
  2415                         load_reg( R_EAX, 0 );
  2416                         ADD_imm32_r32( disp, R_ECX );
  2417                         check_walign32( R_ECX );
  2418                         MEM_WRITE_LONG( R_ECX, R_EAX );
  2420                         break;
  2421                     case 0x3:
  2422                         { /* TRAPA #imm */
  2423                         uint32_t imm = (ir&0xFF); 
  2424                         if( sh4_x86.in_delay_slot ) {
  2425                     	SLOTILLEGAL();
  2426                         } else {
  2427                     	PUSH_imm32( imm );
  2428                     	call_func0( sh4_raise_trap );
  2429                     	ADD_imm8s_r32( 4, R_ESP );
  2432                         break;
  2433                     case 0x4:
  2434                         { /* MOV.B @(disp, GBR), R0 */
  2435                         uint32_t disp = (ir&0xFF); 
  2436                         load_spreg( R_ECX, R_GBR );
  2437                         ADD_imm32_r32( disp, R_ECX );
  2438                         MEM_READ_BYTE( R_ECX, R_EAX );
  2439                         store_reg( R_EAX, 0 );
  2441                         break;
  2442                     case 0x5:
  2443                         { /* MOV.W @(disp, GBR), R0 */
  2444                         uint32_t disp = (ir&0xFF)<<1; 
  2445                         load_spreg( R_ECX, R_GBR );
  2446                         ADD_imm32_r32( disp, R_ECX );
  2447                         check_ralign16( R_ECX );
  2448                         MEM_READ_WORD( R_ECX, R_EAX );
  2449                         store_reg( R_EAX, 0 );
  2451                         break;
  2452                     case 0x6:
  2453                         { /* MOV.L @(disp, GBR), R0 */
  2454                         uint32_t disp = (ir&0xFF)<<2; 
  2455                         load_spreg( R_ECX, R_GBR );
  2456                         ADD_imm32_r32( disp, R_ECX );
  2457                         check_ralign32( R_ECX );
  2458                         MEM_READ_LONG( R_ECX, R_EAX );
  2459                         store_reg( R_EAX, 0 );
  2461                         break;
  2462                     case 0x7:
  2463                         { /* MOVA @(disp, PC), R0 */
  2464                         uint32_t disp = (ir&0xFF)<<2; 
  2465                         if( sh4_x86.in_delay_slot ) {
  2466                     	SLOTILLEGAL();
  2467                         } else {
  2468                     	load_imm32( R_ECX, (pc & 0xFFFFFFFC) + disp + 4 );
  2469                     	store_reg( R_ECX, 0 );
  2472                         break;
  2473                     case 0x8:
  2474                         { /* TST #imm, R0 */
  2475                         uint32_t imm = (ir&0xFF); 
  2476                         load_reg( R_EAX, 0 );
  2477                         TEST_imm32_r32( imm, R_EAX );
  2478                         SETE_t();
  2480                         break;
  2481                     case 0x9:
  2482                         { /* AND #imm, R0 */
  2483                         uint32_t imm = (ir&0xFF); 
  2484                         load_reg( R_EAX, 0 );
  2485                         AND_imm32_r32(imm, R_EAX); 
  2486                         store_reg( R_EAX, 0 );
  2488                         break;
  2489                     case 0xA:
  2490                         { /* XOR #imm, R0 */
  2491                         uint32_t imm = (ir&0xFF); 
  2492                         load_reg( R_EAX, 0 );
  2493                         XOR_imm32_r32( imm, R_EAX );
  2494                         store_reg( R_EAX, 0 );
  2496                         break;
  2497                     case 0xB:
  2498                         { /* OR #imm, R0 */
  2499                         uint32_t imm = (ir&0xFF); 
  2500                         load_reg( R_EAX, 0 );
  2501                         OR_imm32_r32(imm, R_EAX);
  2502                         store_reg( R_EAX, 0 );
  2504                         break;
  2505                     case 0xC:
  2506                         { /* TST.B #imm, @(R0, GBR) */
  2507                         uint32_t imm = (ir&0xFF); 
  2508                         load_reg( R_EAX, 0);
  2509                         load_reg( R_ECX, R_GBR);
  2510                         ADD_r32_r32( R_EAX, R_ECX );
  2511                         MEM_READ_BYTE( R_ECX, R_EAX );
  2512                         TEST_imm8_r8( imm, R_AL );
  2513                         SETE_t();
  2515                         break;
  2516                     case 0xD:
  2517                         { /* AND.B #imm, @(R0, GBR) */
  2518                         uint32_t imm = (ir&0xFF); 
  2519                         load_reg( R_EAX, 0 );
  2520                         load_spreg( R_ECX, R_GBR );
  2521                         ADD_r32_r32( R_EAX, R_ECX );
  2522                         PUSH_r32(R_ECX);
  2523                         call_func0(sh4_read_byte);
  2524                         POP_r32(R_ECX);
  2525                         AND_imm32_r32(imm, R_EAX );
  2526                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2528                         break;
  2529                     case 0xE:
  2530                         { /* XOR.B #imm, @(R0, GBR) */
  2531                         uint32_t imm = (ir&0xFF); 
  2532                         load_reg( R_EAX, 0 );
  2533                         load_spreg( R_ECX, R_GBR );
  2534                         ADD_r32_r32( R_EAX, R_ECX );
  2535                         PUSH_r32(R_ECX);
  2536                         call_func0(sh4_read_byte);
  2537                         POP_r32(R_ECX);
  2538                         XOR_imm32_r32( imm, R_EAX );
  2539                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2541                         break;
  2542                     case 0xF:
  2543                         { /* OR.B #imm, @(R0, GBR) */
  2544                         uint32_t imm = (ir&0xFF); 
  2545                         load_reg( R_EAX, 0 );
  2546                         load_spreg( R_ECX, R_GBR );
  2547                         ADD_r32_r32( R_EAX, R_ECX );
  2548                         PUSH_r32(R_ECX);
  2549                         call_func0(sh4_read_byte);
  2550                         POP_r32(R_ECX);
  2551                         OR_imm32_r32(imm, R_EAX );
  2552                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2554                         break;
  2556                 break;
  2557             case 0xD:
  2558                 { /* MOV.L @(disp, PC), Rn */
  2559                 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<2; 
  2560                 if( sh4_x86.in_delay_slot ) {
  2561             	SLOTILLEGAL();
  2562                 } else {
  2563             	uint32_t target = (pc & 0xFFFFFFFC) + disp + 4;
  2564             	char *ptr = mem_get_region(target);
  2565             	if( ptr != NULL ) {
  2566             	    MOV_moff32_EAX( (uint32_t)ptr );
  2567             	} else {
  2568             	    load_imm32( R_ECX, target );
  2569             	    MEM_READ_LONG( R_ECX, R_EAX );
  2571             	store_reg( R_EAX, Rn );
  2574                 break;
  2575             case 0xE:
  2576                 { /* MOV #imm, Rn */
  2577                 uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
  2578                 load_imm32( R_EAX, imm );
  2579                 store_reg( R_EAX, Rn );
  2581                 break;
  2582             case 0xF:
  2583                 switch( ir&0xF ) {
  2584                     case 0x0:
  2585                         { /* FADD FRm, FRn */
  2586                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2587                         check_fpuen();
  2588                         load_spreg( R_ECX, R_FPSCR );
  2589                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2590                         load_fr_bank( R_EDX );
  2591                         JNE_rel8(13,doubleprec);
  2592                         push_fr(R_EDX, FRm);
  2593                         push_fr(R_EDX, FRn);
  2594                         FADDP_st(1);
  2595                         pop_fr(R_EDX, FRn);
  2596                         JMP_rel8(11,end);
  2597                         JMP_TARGET(doubleprec);
  2598                         push_dr(R_EDX, FRm);
  2599                         push_dr(R_EDX, FRn);
  2600                         FADDP_st(1);
  2601                         pop_dr(R_EDX, FRn);
  2602                         JMP_TARGET(end);
  2604                         break;
  2605                     case 0x1:
  2606                         { /* FSUB FRm, FRn */
  2607                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2608                         check_fpuen();
  2609                         load_spreg( R_ECX, R_FPSCR );
  2610                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2611                         load_fr_bank( R_EDX );
  2612                         JNE_rel8(13, doubleprec);
  2613                         push_fr(R_EDX, FRn);
  2614                         push_fr(R_EDX, FRm);
  2615                         FSUBP_st(1);
  2616                         pop_fr(R_EDX, FRn);
  2617                         JMP_rel8(11, end);
  2618                         JMP_TARGET(doubleprec);
  2619                         push_dr(R_EDX, FRn);
  2620                         push_dr(R_EDX, FRm);
  2621                         FSUBP_st(1);
  2622                         pop_dr(R_EDX, FRn);
  2623                         JMP_TARGET(end);
  2625                         break;
  2626                     case 0x2:
  2627                         { /* FMUL FRm, FRn */
  2628                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2629                         check_fpuen();
  2630                         load_spreg( R_ECX, R_FPSCR );
  2631                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2632                         load_fr_bank( R_EDX );
  2633                         JNE_rel8(13, doubleprec);
  2634                         push_fr(R_EDX, FRm);
  2635                         push_fr(R_EDX, FRn);
  2636                         FMULP_st(1);
  2637                         pop_fr(R_EDX, FRn);
  2638                         JMP_rel8(11, end);
  2639                         JMP_TARGET(doubleprec);
  2640                         push_dr(R_EDX, FRm);
  2641                         push_dr(R_EDX, FRn);
  2642                         FMULP_st(1);
  2643                         pop_dr(R_EDX, FRn);
  2644                         JMP_TARGET(end);
  2646                         break;
  2647                     case 0x3:
  2648                         { /* FDIV FRm, FRn */
  2649                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2650                         check_fpuen();
  2651                         load_spreg( R_ECX, R_FPSCR );
  2652                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2653                         load_fr_bank( R_EDX );
  2654                         JNE_rel8(13, doubleprec);
  2655                         push_fr(R_EDX, FRn);
  2656                         push_fr(R_EDX, FRm);
  2657                         FDIVP_st(1);
  2658                         pop_fr(R_EDX, FRn);
  2659                         JMP_rel8(11, end);
  2660                         JMP_TARGET(doubleprec);
  2661                         push_dr(R_EDX, FRn);
  2662                         push_dr(R_EDX, FRm);
  2663                         FDIVP_st(1);
  2664                         pop_dr(R_EDX, FRn);
  2665                         JMP_TARGET(end);
  2667                         break;
  2668                     case 0x4:
  2669                         { /* FCMP/EQ FRm, FRn */
  2670                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2671                         check_fpuen();
  2672                         load_spreg( R_ECX, R_FPSCR );
  2673                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2674                         load_fr_bank( R_EDX );
  2675                         JNE_rel8(8, doubleprec);
  2676                         push_fr(R_EDX, FRm);
  2677                         push_fr(R_EDX, FRn);
  2678                         JMP_rel8(6, end);
  2679                         JMP_TARGET(doubleprec);
  2680                         push_dr(R_EDX, FRm);
  2681                         push_dr(R_EDX, FRn);
  2682                         JMP_TARGET(end);
  2683                         FCOMIP_st(1);
  2684                         SETE_t();
  2685                         FPOP_st();
  2687                         break;
  2688                     case 0x5:
  2689                         { /* FCMP/GT FRm, FRn */
  2690                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2691                         check_fpuen();
  2692                         load_spreg( R_ECX, R_FPSCR );
  2693                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2694                         load_fr_bank( R_EDX );
  2695                         JNE_rel8(8, doubleprec);
  2696                         push_fr(R_EDX, FRm);
  2697                         push_fr(R_EDX, FRn);
  2698                         JMP_rel8(6, end);
  2699                         JMP_TARGET(doubleprec);
  2700                         push_dr(R_EDX, FRm);
  2701                         push_dr(R_EDX, FRn);
  2702                         JMP_TARGET(end);
  2703                         FCOMIP_st(1);
  2704                         SETA_t();
  2705                         FPOP_st();
  2707                         break;
  2708                     case 0x6:
  2709                         { /* FMOV @(R0, Rm), FRn */
  2710                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2711                         check_fpuen();
  2712                         load_reg( R_EDX, Rm );
  2713                         ADD_sh4r_r32( REG_OFFSET(r[0]), R_EDX );
  2714                         check_ralign32( R_EDX );
  2715                         load_spreg( R_ECX, R_FPSCR );
  2716                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2717                         JNE_rel8(19, doublesize);
  2718                         MEM_READ_LONG( R_EDX, R_EAX );
  2719                         load_fr_bank( R_ECX );
  2720                         store_fr( R_ECX, R_EAX, FRn );
  2721                         if( FRn&1 ) {
  2722                     	JMP_rel8(48, end);
  2723                     	JMP_TARGET(doublesize);
  2724                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2725                     	load_spreg( R_ECX, R_FPSCR ); // assume read_long clobbered it
  2726                     	load_xf_bank( R_ECX );
  2727                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2728                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2729                     	JMP_TARGET(end);
  2730                         } else {
  2731                     	JMP_rel8(36, end);
  2732                     	JMP_TARGET(doublesize);
  2733                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2734                     	load_fr_bank( R_ECX );
  2735                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2736                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2737                     	JMP_TARGET(end);
  2740                         break;
  2741                     case 0x7:
  2742                         { /* FMOV FRm, @(R0, Rn) */
  2743                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2744                         check_fpuen();
  2745                         load_reg( R_EDX, Rn );
  2746                         ADD_sh4r_r32( REG_OFFSET(r[0]), R_EDX );
  2747                         check_walign32( R_EDX );
  2748                         load_spreg( R_ECX, R_FPSCR );
  2749                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2750                         JNE_rel8(20, doublesize);
  2751                         load_fr_bank( R_ECX );
  2752                         load_fr( R_ECX, R_EAX, FRm );
  2753                         MEM_WRITE_LONG( R_EDX, R_EAX ); // 12
  2754                         if( FRm&1 ) {
  2755                     	JMP_rel8( 48, end );
  2756                     	JMP_TARGET(doublesize);
  2757                     	load_xf_bank( R_ECX );
  2758                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2759                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2760                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2761                     	JMP_TARGET(end);
  2762                         } else {
  2763                     	JMP_rel8( 39, end );
  2764                     	JMP_TARGET(doublesize);
  2765                     	load_fr_bank( R_ECX );
  2766                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2767                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2768                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2769                     	JMP_TARGET(end);
  2772                         break;
  2773                     case 0x8:
  2774                         { /* FMOV @Rm, FRn */
  2775                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2776                         check_fpuen();
  2777                         load_reg( R_EDX, Rm );
  2778                         check_ralign32( R_EDX );
  2779                         load_spreg( R_ECX, R_FPSCR );
  2780                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2781                         JNE_rel8(19, doublesize);
  2782                         MEM_READ_LONG( R_EDX, R_EAX );
  2783                         load_fr_bank( R_ECX );
  2784                         store_fr( R_ECX, R_EAX, FRn );
  2785                         if( FRn&1 ) {
  2786                     	JMP_rel8(48, end);
  2787                     	JMP_TARGET(doublesize);
  2788                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2789                     	load_spreg( R_ECX, R_FPSCR ); // assume read_long clobbered it
  2790                     	load_xf_bank( R_ECX );
  2791                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2792                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2793                     	JMP_TARGET(end);
  2794                         } else {
  2795                     	JMP_rel8(36, end);
  2796                     	JMP_TARGET(doublesize);
  2797                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2798                     	load_fr_bank( R_ECX );
  2799                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2800                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2801                     	JMP_TARGET(end);
  2804                         break;
  2805                     case 0x9:
  2806                         { /* FMOV @Rm+, FRn */
  2807                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2808                         check_fpuen();
  2809                         load_reg( R_EDX, Rm );
  2810                         check_ralign32( R_EDX );
  2811                         MOV_r32_r32( R_EDX, R_EAX );
  2812                         load_spreg( R_ECX, R_FPSCR );
  2813                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2814                         JNE_rel8(25, doublesize);
  2815                         ADD_imm8s_r32( 4, R_EAX );
  2816                         store_reg( R_EAX, Rm );
  2817                         MEM_READ_LONG( R_EDX, R_EAX );
  2818                         load_fr_bank( R_ECX );
  2819                         store_fr( R_ECX, R_EAX, FRn );
  2820                         if( FRn&1 ) {
  2821                     	JMP_rel8(54, end);
  2822                     	JMP_TARGET(doublesize);
  2823                     	ADD_imm8s_r32( 8, R_EAX );
  2824                     	store_reg(R_EAX, Rm);
  2825                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2826                     	load_spreg( R_ECX, R_FPSCR ); // assume read_long clobbered it
  2827                     	load_xf_bank( R_ECX );
  2828                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2829                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2830                     	JMP_TARGET(end);
  2831                         } else {
  2832                     	JMP_rel8(42, end);
  2833                     	ADD_imm8s_r32( 8, R_EAX );
  2834                     	store_reg(R_EAX, Rm);
  2835                     	MEM_READ_DOUBLE( R_EDX, R_EAX, R_EDX );
  2836                     	load_fr_bank( R_ECX );
  2837                     	store_fr( R_ECX, R_EAX, FRn&0x0E );
  2838                     	store_fr( R_ECX, R_EDX, FRn|0x01 );
  2839                     	JMP_TARGET(end);
  2842                         break;
  2843                     case 0xA:
  2844                         { /* FMOV FRm, @Rn */
  2845                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2846                         check_fpuen();
  2847                         load_reg( R_EDX, Rn );
  2848                         check_walign32( R_EDX );
  2849                         load_spreg( R_ECX, R_FPSCR );
  2850                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2851                         JNE_rel8(20, doublesize);
  2852                         load_fr_bank( R_ECX );
  2853                         load_fr( R_ECX, R_EAX, FRm );
  2854                         MEM_WRITE_LONG( R_EDX, R_EAX ); // 12
  2855                         if( FRm&1 ) {
  2856                     	JMP_rel8( 48, end );
  2857                     	JMP_TARGET(doublesize);
  2858                     	load_xf_bank( R_ECX );
  2859                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2860                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2861                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2862                     	JMP_TARGET(end);
  2863                         } else {
  2864                     	JMP_rel8( 39, end );
  2865                     	JMP_TARGET(doublesize);
  2866                     	load_fr_bank( R_ECX );
  2867                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2868                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2869                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2870                     	JMP_TARGET(end);
  2873                         break;
  2874                     case 0xB:
  2875                         { /* FMOV FRm, @-Rn */
  2876                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2877                         check_fpuen();
  2878                         load_reg( R_EDX, Rn );
  2879                         check_walign32( R_EDX );
  2880                         load_spreg( R_ECX, R_FPSCR );
  2881                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2882                         JNE_rel8(26, doublesize);
  2883                         load_fr_bank( R_ECX );
  2884                         load_fr( R_ECX, R_EAX, FRm );
  2885                         ADD_imm8s_r32(-4,R_EDX);
  2886                         store_reg( R_EDX, Rn );
  2887                         MEM_WRITE_LONG( R_EDX, R_EAX ); // 12
  2888                         if( FRm&1 ) {
  2889                     	JMP_rel8( 54, end );
  2890                     	JMP_TARGET(doublesize);
  2891                     	load_xf_bank( R_ECX );
  2892                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2893                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2894                     	ADD_imm8s_r32(-8,R_EDX);
  2895                     	store_reg( R_EDX, Rn );
  2896                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2897                     	JMP_TARGET(end);
  2898                         } else {
  2899                     	JMP_rel8( 45, end );
  2900                     	JMP_TARGET(doublesize);
  2901                     	load_fr_bank( R_ECX );
  2902                     	load_fr( R_ECX, R_EAX, FRm&0x0E );
  2903                     	load_fr( R_ECX, R_ECX, FRm|0x01 );
  2904                     	ADD_imm8s_r32(-8,R_EDX);
  2905                     	store_reg( R_EDX, Rn );
  2906                     	MEM_WRITE_DOUBLE( R_EDX, R_EAX, R_ECX );
  2907                     	JMP_TARGET(end);
  2910                         break;
  2911                     case 0xC:
  2912                         { /* FMOV FRm, FRn */
  2913                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2914                         /* As horrible as this looks, it's actually covering 5 separate cases:
  2915                          * 1. 32-bit fr-to-fr (PR=0)
  2916                          * 2. 64-bit dr-to-dr (PR=1, FRm&1 == 0, FRn&1 == 0 )
  2917                          * 3. 64-bit dr-to-xd (PR=1, FRm&1 == 0, FRn&1 == 1 )
  2918                          * 4. 64-bit xd-to-dr (PR=1, FRm&1 == 1, FRn&1 == 0 )
  2919                          * 5. 64-bit xd-to-xd (PR=1, FRm&1 == 1, FRn&1 == 1 )
  2920                          */
  2921                         check_fpuen();
  2922                         load_spreg( R_ECX, R_FPSCR );
  2923                         load_fr_bank( R_EDX );
  2924                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  2925                         JNE_rel8(8, doublesize);
  2926                         load_fr( R_EDX, R_EAX, FRm ); // PR=0 branch
  2927                         store_fr( R_EDX, R_EAX, FRn );
  2928                         if( FRm&1 ) {
  2929                     	JMP_rel8(24, end);
  2930                     	JMP_TARGET(doublesize);
  2931                     	load_xf_bank( R_ECX ); 
  2932                     	load_fr( R_ECX, R_EAX, FRm-1 );
  2933                     	if( FRn&1 ) {
  2934                     	    load_fr( R_ECX, R_EDX, FRm );
  2935                     	    store_fr( R_ECX, R_EAX, FRn-1 );
  2936                     	    store_fr( R_ECX, R_EDX, FRn );
  2937                     	} else /* FRn&1 == 0 */ {
  2938                     	    load_fr( R_ECX, R_ECX, FRm );
  2939                     	    store_fr( R_EDX, R_EAX, FRn );
  2940                     	    store_fr( R_EDX, R_ECX, FRn+1 );
  2942                     	JMP_TARGET(end);
  2943                         } else /* FRm&1 == 0 */ {
  2944                     	if( FRn&1 ) {
  2945                     	    JMP_rel8(24, end);
  2946                     	    load_xf_bank( R_ECX );
  2947                     	    load_fr( R_EDX, R_EAX, FRm );
  2948                     	    load_fr( R_EDX, R_EDX, FRm+1 );
  2949                     	    store_fr( R_ECX, R_EAX, FRn-1 );
  2950                     	    store_fr( R_ECX, R_EDX, FRn );
  2951                     	    JMP_TARGET(end);
  2952                     	} else /* FRn&1 == 0 */ {
  2953                     	    JMP_rel8(12, end);
  2954                     	    load_fr( R_EDX, R_EAX, FRm );
  2955                     	    load_fr( R_EDX, R_ECX, FRm+1 );
  2956                     	    store_fr( R_EDX, R_EAX, FRn );
  2957                     	    store_fr( R_EDX, R_ECX, FRn+1 );
  2958                     	    JMP_TARGET(end);
  2962                         break;
  2963                     case 0xD:
  2964                         switch( (ir&0xF0) >> 4 ) {
  2965                             case 0x0:
  2966                                 { /* FSTS FPUL, FRn */
  2967                                 uint32_t FRn = ((ir>>8)&0xF); 
  2968                                 check_fpuen();
  2969                                 load_fr_bank( R_ECX );
  2970                                 load_spreg( R_EAX, R_FPUL );
  2971                                 store_fr( R_ECX, R_EAX, FRn );
  2973                                 break;
  2974                             case 0x1:
  2975                                 { /* FLDS FRm, FPUL */
  2976                                 uint32_t FRm = ((ir>>8)&0xF); 
  2977                                 check_fpuen();
  2978                                 load_fr_bank( R_ECX );
  2979                                 load_fr( R_ECX, R_EAX, FRm );
  2980                                 store_spreg( R_EAX, R_FPUL );
  2982                                 break;
  2983                             case 0x2:
  2984                                 { /* FLOAT FPUL, FRn */
  2985                                 uint32_t FRn = ((ir>>8)&0xF); 
  2986                                 check_fpuen();
  2987                                 load_spreg( R_ECX, R_FPSCR );
  2988                                 load_spreg(R_EDX, REG_OFFSET(fr_bank));
  2989                                 FILD_sh4r(R_FPUL);
  2990                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  2991                                 JNE_rel8(5, doubleprec);
  2992                                 pop_fr( R_EDX, FRn );
  2993                                 JMP_rel8(3, end);
  2994                                 JMP_TARGET(doubleprec);
  2995                                 pop_dr( R_EDX, FRn );
  2996                                 JMP_TARGET(end);
  2998                                 break;
  2999                             case 0x3:
  3000                                 { /* FTRC FRm, FPUL */
  3001                                 uint32_t FRm = ((ir>>8)&0xF); 
  3002                                 check_fpuen();
  3003                                 load_spreg( R_ECX, R_FPSCR );
  3004                                 load_fr_bank( R_EDX );
  3005                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3006                                 JNE_rel8(5, doubleprec);
  3007                                 push_fr( R_EDX, FRm );
  3008                                 JMP_rel8(3, doop);
  3009                                 JMP_TARGET(doubleprec);
  3010                                 push_dr( R_EDX, FRm );
  3011                                 JMP_TARGET( doop );
  3012                                 load_imm32( R_ECX, (uint32_t)&max_int );
  3013                                 FILD_r32ind( R_ECX );
  3014                                 FCOMIP_st(1);
  3015                                 JNA_rel8( 32, sat );
  3016                                 load_imm32( R_ECX, (uint32_t)&min_int );  // 5
  3017                                 FILD_r32ind( R_ECX );           // 2
  3018                                 FCOMIP_st(1);                   // 2
  3019                                 JAE_rel8( 21, sat2 );            // 2
  3020                                 load_imm32( R_EAX, (uint32_t)&save_fcw );
  3021                                 FNSTCW_r32ind( R_EAX );
  3022                                 load_imm32( R_EDX, (uint32_t)&trunc_fcw );
  3023                                 FLDCW_r32ind( R_EDX );
  3024                                 FISTP_sh4r(R_FPUL);             // 3
  3025                                 FLDCW_r32ind( R_EAX );
  3026                                 JMP_rel8( 9, end );             // 2
  3028                                 JMP_TARGET(sat);
  3029                                 JMP_TARGET(sat2);
  3030                                 MOV_r32ind_r32( R_ECX, R_ECX ); // 2
  3031                                 store_spreg( R_ECX, R_FPUL );
  3032                                 FPOP_st();
  3033                                 JMP_TARGET(end);
  3035                                 break;
  3036                             case 0x4:
  3037                                 { /* FNEG FRn */
  3038                                 uint32_t FRn = ((ir>>8)&0xF); 
  3039                                 check_fpuen();
  3040                                 load_spreg( R_ECX, R_FPSCR );
  3041                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3042                                 load_fr_bank( R_EDX );
  3043                                 JNE_rel8(10, doubleprec);
  3044                                 push_fr(R_EDX, FRn);
  3045                                 FCHS_st0();
  3046                                 pop_fr(R_EDX, FRn);
  3047                                 JMP_rel8(8, end);
  3048                                 JMP_TARGET(doubleprec);
  3049                                 push_dr(R_EDX, FRn);
  3050                                 FCHS_st0();
  3051                                 pop_dr(R_EDX, FRn);
  3052                                 JMP_TARGET(end);
  3054                                 break;
  3055                             case 0x5:
  3056                                 { /* FABS FRn */
  3057                                 uint32_t FRn = ((ir>>8)&0xF); 
  3058                                 check_fpuen();
  3059                                 load_spreg( R_ECX, R_FPSCR );
  3060                                 load_fr_bank( R_EDX );
  3061                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3062                                 JNE_rel8(10, doubleprec);
  3063                                 push_fr(R_EDX, FRn); // 3
  3064                                 FABS_st0(); // 2
  3065                                 pop_fr( R_EDX, FRn); //3
  3066                                 JMP_rel8(8,end); // 2
  3067                                 JMP_TARGET(doubleprec);
  3068                                 push_dr(R_EDX, FRn);
  3069                                 FABS_st0();
  3070                                 pop_dr(R_EDX, FRn);
  3071                                 JMP_TARGET(end);
  3073                                 break;
  3074                             case 0x6:
  3075                                 { /* FSQRT FRn */
  3076                                 uint32_t FRn = ((ir>>8)&0xF); 
  3077                                 check_fpuen();
  3078                                 load_spreg( R_ECX, R_FPSCR );
  3079                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3080                                 load_fr_bank( R_EDX );
  3081                                 JNE_rel8(10, doubleprec);
  3082                                 push_fr(R_EDX, FRn);
  3083                                 FSQRT_st0();
  3084                                 pop_fr(R_EDX, FRn);
  3085                                 JMP_rel8(8, end);
  3086                                 JMP_TARGET(doubleprec);
  3087                                 push_dr(R_EDX, FRn);
  3088                                 FSQRT_st0();
  3089                                 pop_dr(R_EDX, FRn);
  3090                                 JMP_TARGET(end);
  3092                                 break;
  3093                             case 0x7:
  3094                                 { /* FSRRA FRn */
  3095                                 uint32_t FRn = ((ir>>8)&0xF); 
  3096                                 check_fpuen();
  3097                                 load_spreg( R_ECX, R_FPSCR );
  3098                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3099                                 load_fr_bank( R_EDX );
  3100                                 JNE_rel8(12, end); // PR=0 only
  3101                                 FLD1_st0();
  3102                                 push_fr(R_EDX, FRn);
  3103                                 FSQRT_st0();
  3104                                 FDIVP_st(1);
  3105                                 pop_fr(R_EDX, FRn);
  3106                                 JMP_TARGET(end);
  3108                                 break;
  3109                             case 0x8:
  3110                                 { /* FLDI0 FRn */
  3111                                 uint32_t FRn = ((ir>>8)&0xF); 
  3112                                 /* IFF PR=0 */
  3113                                   check_fpuen();
  3114                                   load_spreg( R_ECX, R_FPSCR );
  3115                                   TEST_imm32_r32( FPSCR_PR, R_ECX );
  3116                                   JNE_rel8(8, end);
  3117                                   XOR_r32_r32( R_EAX, R_EAX );
  3118                                   load_spreg( R_ECX, REG_OFFSET(fr_bank) );
  3119                                   store_fr( R_ECX, R_EAX, FRn );
  3120                                   JMP_TARGET(end);
  3122                                 break;
  3123                             case 0x9:
  3124                                 { /* FLDI1 FRn */
  3125                                 uint32_t FRn = ((ir>>8)&0xF); 
  3126                                 /* IFF PR=0 */
  3127                                   check_fpuen();
  3128                                   load_spreg( R_ECX, R_FPSCR );
  3129                                   TEST_imm32_r32( FPSCR_PR, R_ECX );
  3130                                   JNE_rel8(11, end);
  3131                                   load_imm32(R_EAX, 0x3F800000);
  3132                                   load_spreg( R_ECX, REG_OFFSET(fr_bank) );
  3133                                   store_fr( R_ECX, R_EAX, FRn );
  3134                                   JMP_TARGET(end);
  3136                                 break;
  3137                             case 0xA:
  3138                                 { /* FCNVSD FPUL, FRn */
  3139                                 uint32_t FRn = ((ir>>8)&0xF); 
  3140                                 check_fpuen();
  3141                                 load_spreg( R_ECX, R_FPSCR );
  3142                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3143                                 JE_rel8(9, end); // only when PR=1
  3144                                 load_fr_bank( R_ECX );
  3145                                 push_fpul();
  3146                                 pop_dr( R_ECX, FRn );
  3147                                 JMP_TARGET(end);
  3149                                 break;
  3150                             case 0xB:
  3151                                 { /* FCNVDS FRm, FPUL */
  3152                                 uint32_t FRm = ((ir>>8)&0xF); 
  3153                                 check_fpuen();
  3154                                 load_spreg( R_ECX, R_FPSCR );
  3155                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3156                                 JE_rel8(9, end); // only when PR=1
  3157                                 load_fr_bank( R_ECX );
  3158                                 push_dr( R_ECX, FRm );
  3159                                 pop_fpul();
  3160                                 JMP_TARGET(end);
  3162                                 break;
  3163                             case 0xE:
  3164                                 { /* FIPR FVm, FVn */
  3165                                 uint32_t FVn = ((ir>>10)&0x3); uint32_t FVm = ((ir>>8)&0x3); 
  3166                                 check_fpuen();
  3167                                 load_spreg( R_ECX, R_FPSCR );
  3168                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3169                                 JNE_rel8(44, doubleprec);
  3171                                 load_fr_bank( R_ECX );
  3172                                 push_fr( R_ECX, FVm<<2 );
  3173                                 push_fr( R_ECX, FVn<<2 );
  3174                                 FMULP_st(1);
  3175                                 push_fr( R_ECX, (FVm<<2)+1);
  3176                                 push_fr( R_ECX, (FVn<<2)+1);
  3177                                 FMULP_st(1);
  3178                                 FADDP_st(1);
  3179                                 push_fr( R_ECX, (FVm<<2)+2);
  3180                                 push_fr( R_ECX, (FVn<<2)+2);
  3181                                 FMULP_st(1);
  3182                                 FADDP_st(1);
  3183                                 push_fr( R_ECX, (FVm<<2)+3);
  3184                                 push_fr( R_ECX, (FVn<<2)+3);
  3185                                 FMULP_st(1);
  3186                                 FADDP_st(1);
  3187                                 pop_fr( R_ECX, (FVn<<2)+3);
  3188                                 JMP_TARGET(doubleprec);
  3190                                 break;
  3191                             case 0xF:
  3192                                 switch( (ir&0x100) >> 8 ) {
  3193                                     case 0x0:
  3194                                         { /* FSCA FPUL, FRn */
  3195                                         uint32_t FRn = ((ir>>9)&0x7)<<1; 
  3196                                         check_fpuen();
  3197                                         load_spreg( R_ECX, R_FPSCR );
  3198                                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  3199                                         JNE_rel8( 21, doubleprec );
  3200                                         load_fr_bank( R_ECX );
  3201                                         ADD_imm8s_r32( (FRn&0x0E)<<2, R_ECX );
  3202                                         load_spreg( R_EDX, R_FPUL );
  3203                                         call_func2( sh4_fsca, R_EDX, R_ECX );
  3204                                         JMP_TARGET(doubleprec);
  3206                                         break;
  3207                                     case 0x1:
  3208                                         switch( (ir&0x200) >> 9 ) {
  3209                                             case 0x0:
  3210                                                 { /* FTRV XMTRX, FVn */
  3211                                                 uint32_t FVn = ((ir>>10)&0x3); 
  3212                                                 check_fpuen();
  3213                                                 load_spreg( R_ECX, R_FPSCR );
  3214                                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3215                                                 JNE_rel8( 30, doubleprec );
  3216                                                 load_fr_bank( R_EDX );                 // 3
  3217                                                 ADD_imm8s_r32( FVn<<4, R_EDX );        // 3
  3218                                                 load_xf_bank( R_ECX );                 // 12
  3219                                                 call_func2( sh4_ftrv, R_EDX, R_ECX );  // 12
  3220                                                 JMP_TARGET(doubleprec);
  3222                                                 break;
  3223                                             case 0x1:
  3224                                                 switch( (ir&0xC00) >> 10 ) {
  3225                                                     case 0x0:
  3226                                                         { /* FSCHG */
  3227                                                         check_fpuen();
  3228                                                         load_spreg( R_ECX, R_FPSCR );
  3229                                                         XOR_imm32_r32( FPSCR_SZ, R_ECX );
  3230                                                         store_spreg( R_ECX, R_FPSCR );
  3232                                                         break;
  3233                                                     case 0x2:
  3234                                                         { /* FRCHG */
  3235                                                         check_fpuen();
  3236                                                         load_spreg( R_ECX, R_FPSCR );
  3237                                                         XOR_imm32_r32( FPSCR_FR, R_ECX );
  3238                                                         store_spreg( R_ECX, R_FPSCR );
  3239                                                         update_fr_bank( R_ECX );
  3241                                                         break;
  3242                                                     case 0x3:
  3243                                                         { /* UNDEF */
  3244                                                         if( sh4_x86.in_delay_slot ) {
  3245                                                     	SLOTILLEGAL();
  3246                                                         } else {
  3247                                                     	JMP_exit(EXIT_ILLEGAL);
  3248                                                     	return 1;
  3251                                                         break;
  3252                                                     default:
  3253                                                         UNDEF();
  3254                                                         break;
  3256                                                 break;
  3258                                         break;
  3260                                 break;
  3261                             default:
  3262                                 UNDEF();
  3263                                 break;
  3265                         break;
  3266                     case 0xE:
  3267                         { /* FMAC FR0, FRm, FRn */
  3268                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  3269                         check_fpuen();
  3270                         load_spreg( R_ECX, R_FPSCR );
  3271                         load_spreg( R_EDX, REG_OFFSET(fr_bank));
  3272                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  3273                         JNE_rel8(18, doubleprec);
  3274                         push_fr( R_EDX, 0 );
  3275                         push_fr( R_EDX, FRm );
  3276                         FMULP_st(1);
  3277                         push_fr( R_EDX, FRn );
  3278                         FADDP_st(1);
  3279                         pop_fr( R_EDX, FRn );
  3280                         JMP_rel8(16, end);
  3281                         JMP_TARGET(doubleprec);
  3282                         push_dr( R_EDX, 0 );
  3283                         push_dr( R_EDX, FRm );
  3284                         FMULP_st(1);
  3285                         push_dr( R_EDX, FRn );
  3286                         FADDP_st(1);
  3287                         pop_dr( R_EDX, FRn );
  3288                         JMP_TARGET(end);
  3290                         break;
  3291                     default:
  3292                         UNDEF();
  3293                         break;
  3295                 break;
  3298     if( sh4_x86.in_delay_slot ) {
  3299 	ADD_imm8s_r32(2,R_ESI);
  3300 	sh4_x86.in_delay_slot = FALSE;
  3301 	return 1;
  3302     } else {
  3303 	INC_r32(R_ESI);
  3305     return 0;
.