Search
lxdream.org :: lxdream/src/sh4/sh4x86.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4x86.c
changeset 547:d6e00ffc4adc
prev539:75f3e594d4a7
next550:a27e31340147
author nkeynes
date Thu Dec 06 10:37:55 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Fix stack alignment on x86-64
view annotate diff log raw
     1 /**
     2  * $Id: sh4x86.in,v 1.20 2007-11-08 11:54: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/xltcache.h"
    29 #include "sh4/sh4core.h"
    30 #include "sh4/sh4trans.h"
    31 #include "sh4/sh4mmio.h"
    32 #include "sh4/x86op.h"
    33 #include "clock.h"
    35 #define DEFAULT_BACKPATCH_SIZE 4096
    37 /** 
    38  * Struct to manage internal translation state. This state is not saved -
    39  * it is only valid between calls to sh4_translate_begin_block() and
    40  * sh4_translate_end_block()
    41  */
    42 struct sh4_x86_state {
    43     gboolean in_delay_slot;
    44     gboolean priv_checked; /* true if we've already checked the cpu mode. */
    45     gboolean fpuen_checked; /* true if we've already checked fpu enabled. */
    46     gboolean branch_taken; /* true if we branched unconditionally */
    47     uint32_t block_start_pc;
    48     uint32_t stack_posn;   /* Trace stack height for alignment purposes */
    49     int tstate;
    51     /* Allocated memory for the (block-wide) back-patch list */
    52     uint32_t **backpatch_list;
    53     uint32_t backpatch_posn;
    54     uint32_t backpatch_size;
    55 };
    57 #define TSTATE_NONE -1
    58 #define TSTATE_O    0
    59 #define TSTATE_C    2
    60 #define TSTATE_E    4
    61 #define TSTATE_NE   5
    62 #define TSTATE_G    0xF
    63 #define TSTATE_GE   0xD
    64 #define TSTATE_A    7
    65 #define TSTATE_AE   3
    67 /** Branch if T is set (either in the current cflags, or in sh4r.t) */
    68 #define JT_rel8(rel8,label) if( sh4_x86.tstate == TSTATE_NONE ) { \
    69 	CMP_imm8s_sh4r( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
    70     OP(0x70+sh4_x86.tstate); OP(rel8); \
    71     MARK_JMP(rel8,label)
    72 /** Branch if T is clear (either in the current cflags or in sh4r.t) */
    73 #define JF_rel8(rel8,label) if( sh4_x86.tstate == TSTATE_NONE ) { \
    74 	CMP_imm8s_sh4r( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
    75     OP(0x70+ (sh4_x86.tstate^1)); OP(rel8); \
    76     MARK_JMP(rel8, label)
    79 #define EXIT_DATA_ADDR_READ 0
    80 #define EXIT_DATA_ADDR_WRITE 7
    81 #define EXIT_ILLEGAL 14
    82 #define EXIT_SLOT_ILLEGAL 21
    83 #define EXIT_FPU_DISABLED 28
    84 #define EXIT_SLOT_FPU_DISABLED 35
    86 static struct sh4_x86_state sh4_x86;
    88 static uint32_t max_int = 0x7FFFFFFF;
    89 static uint32_t min_int = 0x80000000;
    90 static uint32_t save_fcw; /* save value for fpu control word */
    91 static uint32_t trunc_fcw = 0x0F7F; /* fcw value for truncation mode */
    93 void sh4_x86_init()
    94 {
    95     sh4_x86.backpatch_list = malloc(DEFAULT_BACKPATCH_SIZE);
    96     sh4_x86.backpatch_size = DEFAULT_BACKPATCH_SIZE / sizeof(uint32_t *);
    97 }
   100 static void sh4_x86_add_backpatch( uint8_t *ptr )
   101 {
   102     if( sh4_x86.backpatch_posn == sh4_x86.backpatch_size ) {
   103 	sh4_x86.backpatch_size <<= 1;
   104 	sh4_x86.backpatch_list = realloc( sh4_x86.backpatch_list, sh4_x86.backpatch_size * sizeof(uint32_t *) );
   105 	assert( sh4_x86.backpatch_list != NULL );
   106     }
   107     sh4_x86.backpatch_list[sh4_x86.backpatch_posn++] = (uint32_t *)ptr;
   108 }
   110 static void sh4_x86_do_backpatch( uint8_t *reloc_base )
   111 {
   112     unsigned int i;
   113     for( i=0; i<sh4_x86.backpatch_posn; i++ ) {
   114 	*sh4_x86.backpatch_list[i] += (reloc_base - ((uint8_t *)sh4_x86.backpatch_list[i]) - 4);
   115     }
   116 }
   118 /**
   119  * Emit an instruction to load an SH4 reg into a real register
   120  */
   121 static inline void load_reg( int x86reg, int sh4reg ) 
   122 {
   123     /* mov [bp+n], reg */
   124     OP(0x8B);
   125     OP(0x45 + (x86reg<<3));
   126     OP(REG_OFFSET(r[sh4reg]));
   127 }
   129 static inline void load_reg16s( int x86reg, int sh4reg )
   130 {
   131     OP(0x0F);
   132     OP(0xBF);
   133     MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
   134 }
   136 static inline void load_reg16u( int x86reg, int sh4reg )
   137 {
   138     OP(0x0F);
   139     OP(0xB7);
   140     MODRM_r32_sh4r(x86reg, REG_OFFSET(r[sh4reg]));
   142 }
   144 #define load_spreg( x86reg, regoff ) MOV_sh4r_r32( regoff, x86reg )
   145 #define store_spreg( x86reg, regoff ) MOV_r32_sh4r( x86reg, regoff )
   146 /**
   147  * Emit an instruction to load an immediate value into a register
   148  */
   149 static inline void load_imm32( int x86reg, uint32_t value ) {
   150     /* mov #value, reg */
   151     OP(0xB8 + x86reg);
   152     OP32(value);
   153 }
   155 /**
   156  * Load an immediate 64-bit quantity (note: x86-64 only)
   157  */
   158 static inline void load_imm64( int x86reg, uint32_t value ) {
   159     /* mov #value, reg */
   160     REXW();
   161     OP(0xB8 + x86reg);
   162     OP64(value);
   163 }
   166 /**
   167  * Emit an instruction to store an SH4 reg (RN)
   168  */
   169 void static inline store_reg( int x86reg, int sh4reg ) {
   170     /* mov reg, [bp+n] */
   171     OP(0x89);
   172     OP(0x45 + (x86reg<<3));
   173     OP(REG_OFFSET(r[sh4reg]));
   174 }
   176 #define load_fr_bank(bankreg) load_spreg( bankreg, REG_OFFSET(fr_bank))
   178 /**
   179  * Load an FR register (single-precision floating point) into an integer x86
   180  * register (eg for register-to-register moves)
   181  */
   182 void static inline load_fr( int bankreg, int x86reg, int frm )
   183 {
   184     OP(0x8B); OP(0x40+bankreg+(x86reg<<3)); OP((frm^1)<<2);
   185 }
   187 /**
   188  * Store an FR register (single-precision floating point) into an integer x86
   189  * register (eg for register-to-register moves)
   190  */
   191 void static inline store_fr( int bankreg, int x86reg, int frn )
   192 {
   193     OP(0x89);  OP(0x40+bankreg+(x86reg<<3)); OP((frn^1)<<2);
   194 }
   197 /**
   198  * Load a pointer to the back fp back into the specified x86 register. The
   199  * bankreg must have been previously loaded with FPSCR.
   200  * NB: 12 bytes
   201  */
   202 static inline void load_xf_bank( int bankreg )
   203 {
   204     NOT_r32( bankreg );
   205     SHR_imm8_r32( (21 - 6), bankreg ); // Extract bit 21 then *64 for bank size
   206     AND_imm8s_r32( 0x40, bankreg );    // Complete extraction
   207     OP(0x8D); OP(0x44+(bankreg<<3)); OP(0x28+bankreg); OP(REG_OFFSET(fr)); // LEA [ebp+bankreg+disp], bankreg
   208 }
   210 /**
   211  * Update the fr_bank pointer based on the current fpscr value.
   212  */
   213 static inline void update_fr_bank( int fpscrreg )
   214 {
   215     SHR_imm8_r32( (21 - 6), fpscrreg ); // Extract bit 21 then *64 for bank size
   216     AND_imm8s_r32( 0x40, fpscrreg );    // Complete extraction
   217     OP(0x8D); OP(0x44+(fpscrreg<<3)); OP(0x28+fpscrreg); OP(REG_OFFSET(fr)); // LEA [ebp+fpscrreg+disp], fpscrreg
   218     store_spreg( fpscrreg, REG_OFFSET(fr_bank) );
   219 }
   220 /**
   221  * Push FPUL (as a 32-bit float) onto the FPU stack
   222  */
   223 static inline void push_fpul( )
   224 {
   225     OP(0xD9); OP(0x45); OP(R_FPUL);
   226 }
   228 /**
   229  * Pop FPUL (as a 32-bit float) from the FPU stack
   230  */
   231 static inline void pop_fpul( )
   232 {
   233     OP(0xD9); OP(0x5D); OP(R_FPUL);
   234 }
   236 /**
   237  * Push a 32-bit float onto the FPU stack, with bankreg previously loaded
   238  * with the location of the current fp bank.
   239  */
   240 static inline void push_fr( int bankreg, int frm ) 
   241 {
   242     OP(0xD9); OP(0x40 + bankreg); OP((frm^1)<<2);  // FLD.S [bankreg + frm^1*4]
   243 }
   245 /**
   246  * Pop a 32-bit float from the FPU stack and store it back into the fp bank, 
   247  * with bankreg previously loaded with the location of the current fp bank.
   248  */
   249 static inline void pop_fr( int bankreg, int frm )
   250 {
   251     OP(0xD9); OP(0x58 + bankreg); OP((frm^1)<<2); // FST.S [bankreg + frm^1*4]
   252 }
   254 /**
   255  * Push a 64-bit double onto the FPU stack, with bankreg previously loaded
   256  * with the location of the current fp bank.
   257  */
   258 static inline void push_dr( int bankreg, int frm )
   259 {
   260     OP(0xDD); OP(0x40 + bankreg); OP(frm<<2); // FLD.D [bankreg + frm*4]
   261 }
   263 static inline void pop_dr( int bankreg, int frm )
   264 {
   265     OP(0xDD); OP(0x58 + bankreg); OP(frm<<2); // FST.D [bankreg + frm*4]
   266 }
   268 /* Exception checks - Note that all exception checks will clobber EAX */
   269 #define precheck() load_imm32(R_EDX, (pc-sh4_x86.block_start_pc-(sh4_x86.in_delay_slot?2:0))>>1)
   271 #define check_priv( ) \
   272     if( !sh4_x86.priv_checked ) { \
   273 	sh4_x86.priv_checked = TRUE;\
   274 	precheck();\
   275 	load_spreg( R_EAX, R_SR );\
   276 	AND_imm32_r32( SR_MD, R_EAX );\
   277 	if( sh4_x86.in_delay_slot ) {\
   278 	    JE_exit( EXIT_SLOT_ILLEGAL );\
   279 	} else {\
   280 	    JE_exit( EXIT_ILLEGAL );\
   281 	}\
   282     }\
   285 static void check_priv_no_precheck()
   286 {
   287     if( !sh4_x86.priv_checked ) {
   288 	sh4_x86.priv_checked = TRUE;
   289 	load_spreg( R_EAX, R_SR );
   290 	AND_imm32_r32( SR_MD, R_EAX );
   291 	if( sh4_x86.in_delay_slot ) {
   292 	    JE_exit( EXIT_SLOT_ILLEGAL );
   293 	} else {
   294 	    JE_exit( EXIT_ILLEGAL );
   295 	}
   296     }
   297 }
   299 #define check_fpuen( ) \
   300     if( !sh4_x86.fpuen_checked ) {\
   301 	sh4_x86.fpuen_checked = TRUE;\
   302 	precheck();\
   303 	load_spreg( R_EAX, R_SR );\
   304 	AND_imm32_r32( SR_FD, R_EAX );\
   305 	if( sh4_x86.in_delay_slot ) {\
   306 	    JNE_exit(EXIT_SLOT_FPU_DISABLED);\
   307 	} else {\
   308 	    JNE_exit(EXIT_FPU_DISABLED);\
   309 	}\
   310     }
   312 static void check_fpuen_no_precheck()
   313 {
   314     if( !sh4_x86.fpuen_checked ) {
   315 	sh4_x86.fpuen_checked = TRUE;
   316 	load_spreg( R_EAX, R_SR );
   317 	AND_imm32_r32( SR_FD, R_EAX );
   318 	if( sh4_x86.in_delay_slot ) {
   319 	    JNE_exit(EXIT_SLOT_FPU_DISABLED);
   320 	} else {
   321 	    JNE_exit(EXIT_FPU_DISABLED);
   322 	}
   323     }
   325 }
   327 static void check_ralign16( int x86reg )
   328 {
   329     TEST_imm32_r32( 0x00000001, x86reg );
   330     JNE_exit(EXIT_DATA_ADDR_READ);
   331 }
   333 static void check_walign16( int x86reg )
   334 {
   335     TEST_imm32_r32( 0x00000001, x86reg );
   336     JNE_exit(EXIT_DATA_ADDR_WRITE);
   337 }
   339 static void check_ralign32( int x86reg )
   340 {
   341     TEST_imm32_r32( 0x00000003, x86reg );
   342     JNE_exit(EXIT_DATA_ADDR_READ);
   343 }
   344 static void check_walign32( int x86reg )
   345 {
   346     TEST_imm32_r32( 0x00000003, x86reg );
   347     JNE_exit(EXIT_DATA_ADDR_WRITE);
   348 }
   350 #define UNDEF()
   351 #define MEM_RESULT(value_reg) if(value_reg != R_EAX) { MOV_r32_r32(R_EAX,value_reg); }
   352 #define MEM_READ_BYTE( addr_reg, value_reg ) call_func1(sh4_read_byte, addr_reg ); MEM_RESULT(value_reg)
   353 #define MEM_READ_WORD( addr_reg, value_reg ) call_func1(sh4_read_word, addr_reg ); MEM_RESULT(value_reg)
   354 #define MEM_READ_LONG( addr_reg, value_reg ) call_func1(sh4_read_long, addr_reg ); MEM_RESULT(value_reg)
   355 #define MEM_WRITE_BYTE( addr_reg, value_reg ) call_func2(sh4_write_byte, addr_reg, value_reg)
   356 #define MEM_WRITE_WORD( addr_reg, value_reg ) call_func2(sh4_write_word, addr_reg, value_reg)
   357 #define MEM_WRITE_LONG( addr_reg, value_reg ) call_func2(sh4_write_long, addr_reg, value_reg)
   359 #define SLOTILLEGAL() precheck(); JMP_exit(EXIT_SLOT_ILLEGAL); sh4_x86.in_delay_slot = FALSE; return 1;
   361 extern uint16_t *sh4_icache;
   362 extern uint32_t sh4_icache_addr;
   364 /****** Import appropriate calling conventions ******/
   365 #if SH4_TRANSLATOR == TARGET_X86_64
   366 #include "sh4/ia64abi.h"
   367 #else /* SH4_TRANSLATOR == TARGET_X86 */
   368 #ifdef APPLE_BUILD
   369 #include "sh4/ia32mac.h"
   370 #else
   371 #include "sh4/ia32abi.h"
   372 #endif
   373 #endif
   376 /**
   377  * Translate a single instruction. Delayed branches are handled specially
   378  * by translating both branch and delayed instruction as a single unit (as
   379  * 
   380  *
   381  * @return true if the instruction marks the end of a basic block
   382  * (eg a branch or 
   383  */
   384 uint32_t sh4_translate_instruction( sh4addr_t pc )
   385 {
   386     uint32_t ir;
   387     /* Read instruction */
   388     uint32_t pageaddr = pc >> 12;
   389     if( sh4_icache != NULL && pageaddr == sh4_icache_addr ) {
   390 	ir = sh4_icache[(pc&0xFFF)>>1];
   391     } else {
   392 	sh4_icache = (uint16_t *)mem_get_page(pc);
   393 	if( ((uintptr_t)sh4_icache) < MAX_IO_REGIONS ) {
   394 	    /* If someone's actually been so daft as to try to execute out of an IO
   395 	     * region, fallback on the full-blown memory read
   396 	     */
   397 	    sh4_icache = NULL;
   398 	    ir = sh4_read_word(pc);
   399 	} else {
   400 	    sh4_icache_addr = pageaddr;
   401 	    ir = sh4_icache[(pc&0xFFF)>>1];
   402 	}
   403     }
   405         switch( (ir&0xF000) >> 12 ) {
   406             case 0x0:
   407                 switch( ir&0xF ) {
   408                     case 0x2:
   409                         switch( (ir&0x80) >> 7 ) {
   410                             case 0x0:
   411                                 switch( (ir&0x70) >> 4 ) {
   412                                     case 0x0:
   413                                         { /* STC SR, Rn */
   414                                         uint32_t Rn = ((ir>>8)&0xF); 
   415                                         check_priv();
   416                                         call_func0(sh4_read_sr);
   417                                         store_reg( R_EAX, Rn );
   418                                         sh4_x86.tstate = TSTATE_NONE;
   419                                         }
   420                                         break;
   421                                     case 0x1:
   422                                         { /* STC GBR, Rn */
   423                                         uint32_t Rn = ((ir>>8)&0xF); 
   424                                         load_spreg( R_EAX, R_GBR );
   425                                         store_reg( R_EAX, Rn );
   426                                         }
   427                                         break;
   428                                     case 0x2:
   429                                         { /* STC VBR, Rn */
   430                                         uint32_t Rn = ((ir>>8)&0xF); 
   431                                         check_priv();
   432                                         load_spreg( R_EAX, R_VBR );
   433                                         store_reg( R_EAX, Rn );
   434                                         sh4_x86.tstate = TSTATE_NONE;
   435                                         }
   436                                         break;
   437                                     case 0x3:
   438                                         { /* STC SSR, Rn */
   439                                         uint32_t Rn = ((ir>>8)&0xF); 
   440                                         check_priv();
   441                                         load_spreg( R_EAX, R_SSR );
   442                                         store_reg( R_EAX, Rn );
   443                                         sh4_x86.tstate = TSTATE_NONE;
   444                                         }
   445                                         break;
   446                                     case 0x4:
   447                                         { /* STC SPC, Rn */
   448                                         uint32_t Rn = ((ir>>8)&0xF); 
   449                                         check_priv();
   450                                         load_spreg( R_EAX, R_SPC );
   451                                         store_reg( R_EAX, Rn );
   452                                         sh4_x86.tstate = TSTATE_NONE;
   453                                         }
   454                                         break;
   455                                     default:
   456                                         UNDEF();
   457                                         break;
   458                                 }
   459                                 break;
   460                             case 0x1:
   461                                 { /* STC Rm_BANK, Rn */
   462                                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
   463                                 check_priv();
   464                                 load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
   465                                 store_reg( R_EAX, Rn );
   466                                 sh4_x86.tstate = TSTATE_NONE;
   467                                 }
   468                                 break;
   469                         }
   470                         break;
   471                     case 0x3:
   472                         switch( (ir&0xF0) >> 4 ) {
   473                             case 0x0:
   474                                 { /* BSRF Rn */
   475                                 uint32_t Rn = ((ir>>8)&0xF); 
   476                                 if( sh4_x86.in_delay_slot ) {
   477                             	SLOTILLEGAL();
   478                                 } else {
   479                             	load_imm32( R_ECX, pc + 4 );
   480                             	store_spreg( R_ECX, R_PR );
   481                             	ADD_sh4r_r32( REG_OFFSET(r[Rn]), R_ECX );
   482                             	store_spreg( R_ECX, REG_OFFSET(pc) );
   483                             	sh4_x86.in_delay_slot = TRUE;
   484                             	sh4_x86.tstate = TSTATE_NONE;
   485                             	sh4_translate_instruction( pc + 2 );
   486                             	exit_block_pcset(pc+2);
   487                             	sh4_x86.branch_taken = TRUE;
   488                             	return 4;
   489                                 }
   490                                 }
   491                                 break;
   492                             case 0x2:
   493                                 { /* BRAF Rn */
   494                                 uint32_t Rn = ((ir>>8)&0xF); 
   495                                 if( sh4_x86.in_delay_slot ) {
   496                             	SLOTILLEGAL();
   497                                 } else {
   498                             	load_reg( R_EAX, Rn );
   499                             	ADD_imm32_r32( pc + 4, R_EAX );
   500                             	store_spreg( R_EAX, REG_OFFSET(pc) );
   501                             	sh4_x86.in_delay_slot = TRUE;
   502                             	sh4_x86.tstate = TSTATE_NONE;
   503                             	sh4_translate_instruction( pc + 2 );
   504                             	exit_block_pcset(pc+2);
   505                             	sh4_x86.branch_taken = TRUE;
   506                             	return 4;
   507                                 }
   508                                 }
   509                                 break;
   510                             case 0x8:
   511                                 { /* PREF @Rn */
   512                                 uint32_t Rn = ((ir>>8)&0xF); 
   513                                 load_reg( R_EAX, Rn );
   514                                 MOV_r32_r32( R_EAX, R_ECX );
   515                                 AND_imm32_r32( 0xFC000000, R_EAX );
   516                                 CMP_imm32_r32( 0xE0000000, R_EAX );
   517                                 JNE_rel8(CALL_FUNC1_SIZE, end);
   518                                 call_func1( sh4_flush_store_queue, R_ECX );
   519                                 JMP_TARGET(end);
   520                                 sh4_x86.tstate = TSTATE_NONE;
   521                                 }
   522                                 break;
   523                             case 0x9:
   524                                 { /* OCBI @Rn */
   525                                 uint32_t Rn = ((ir>>8)&0xF); 
   526                                 }
   527                                 break;
   528                             case 0xA:
   529                                 { /* OCBP @Rn */
   530                                 uint32_t Rn = ((ir>>8)&0xF); 
   531                                 }
   532                                 break;
   533                             case 0xB:
   534                                 { /* OCBWB @Rn */
   535                                 uint32_t Rn = ((ir>>8)&0xF); 
   536                                 }
   537                                 break;
   538                             case 0xC:
   539                                 { /* MOVCA.L R0, @Rn */
   540                                 uint32_t Rn = ((ir>>8)&0xF); 
   541                                 load_reg( R_EAX, 0 );
   542                                 load_reg( R_ECX, Rn );
   543                                 precheck();
   544                                 check_walign32( R_ECX );
   545                                 MEM_WRITE_LONG( R_ECX, R_EAX );
   546                                 sh4_x86.tstate = TSTATE_NONE;
   547                                 }
   548                                 break;
   549                             default:
   550                                 UNDEF();
   551                                 break;
   552                         }
   553                         break;
   554                     case 0x4:
   555                         { /* MOV.B Rm, @(R0, Rn) */
   556                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   557                         load_reg( R_EAX, 0 );
   558                         load_reg( R_ECX, Rn );
   559                         ADD_r32_r32( R_EAX, R_ECX );
   560                         load_reg( R_EAX, Rm );
   561                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   562                         sh4_x86.tstate = TSTATE_NONE;
   563                         }
   564                         break;
   565                     case 0x5:
   566                         { /* MOV.W Rm, @(R0, Rn) */
   567                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   568                         load_reg( R_EAX, 0 );
   569                         load_reg( R_ECX, Rn );
   570                         ADD_r32_r32( R_EAX, R_ECX );
   571                         precheck();
   572                         check_walign16( R_ECX );
   573                         load_reg( R_EAX, Rm );
   574                         MEM_WRITE_WORD( R_ECX, R_EAX );
   575                         sh4_x86.tstate = TSTATE_NONE;
   576                         }
   577                         break;
   578                     case 0x6:
   579                         { /* MOV.L Rm, @(R0, Rn) */
   580                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   581                         load_reg( R_EAX, 0 );
   582                         load_reg( R_ECX, Rn );
   583                         ADD_r32_r32( R_EAX, R_ECX );
   584                         precheck();
   585                         check_walign32( R_ECX );
   586                         load_reg( R_EAX, Rm );
   587                         MEM_WRITE_LONG( R_ECX, R_EAX );
   588                         sh4_x86.tstate = TSTATE_NONE;
   589                         }
   590                         break;
   591                     case 0x7:
   592                         { /* MUL.L Rm, Rn */
   593                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   594                         load_reg( R_EAX, Rm );
   595                         load_reg( R_ECX, Rn );
   596                         MUL_r32( R_ECX );
   597                         store_spreg( R_EAX, R_MACL );
   598                         sh4_x86.tstate = TSTATE_NONE;
   599                         }
   600                         break;
   601                     case 0x8:
   602                         switch( (ir&0xFF0) >> 4 ) {
   603                             case 0x0:
   604                                 { /* CLRT */
   605                                 CLC();
   606                                 SETC_t();
   607                                 sh4_x86.tstate = TSTATE_C;
   608                                 }
   609                                 break;
   610                             case 0x1:
   611                                 { /* SETT */
   612                                 STC();
   613                                 SETC_t();
   614                                 sh4_x86.tstate = TSTATE_C;
   615                                 }
   616                                 break;
   617                             case 0x2:
   618                                 { /* CLRMAC */
   619                                 XOR_r32_r32(R_EAX, R_EAX);
   620                                 store_spreg( R_EAX, R_MACL );
   621                                 store_spreg( R_EAX, R_MACH );
   622                                 sh4_x86.tstate = TSTATE_NONE;
   623                                 }
   624                                 break;
   625                             case 0x3:
   626                                 { /* LDTLB */
   627                                 }
   628                                 break;
   629                             case 0x4:
   630                                 { /* CLRS */
   631                                 CLC();
   632                                 SETC_sh4r(R_S);
   633                                 sh4_x86.tstate = TSTATE_C;
   634                                 }
   635                                 break;
   636                             case 0x5:
   637                                 { /* SETS */
   638                                 STC();
   639                                 SETC_sh4r(R_S);
   640                                 sh4_x86.tstate = TSTATE_C;
   641                                 }
   642                                 break;
   643                             default:
   644                                 UNDEF();
   645                                 break;
   646                         }
   647                         break;
   648                     case 0x9:
   649                         switch( (ir&0xF0) >> 4 ) {
   650                             case 0x0:
   651                                 { /* NOP */
   652                                 /* Do nothing. Well, we could emit an 0x90, but what would really be the point? */
   653                                 }
   654                                 break;
   655                             case 0x1:
   656                                 { /* DIV0U */
   657                                 XOR_r32_r32( R_EAX, R_EAX );
   658                                 store_spreg( R_EAX, R_Q );
   659                                 store_spreg( R_EAX, R_M );
   660                                 store_spreg( R_EAX, R_T );
   661                                 sh4_x86.tstate = TSTATE_C; // works for DIV1
   662                                 }
   663                                 break;
   664                             case 0x2:
   665                                 { /* MOVT Rn */
   666                                 uint32_t Rn = ((ir>>8)&0xF); 
   667                                 load_spreg( R_EAX, R_T );
   668                                 store_reg( R_EAX, Rn );
   669                                 }
   670                                 break;
   671                             default:
   672                                 UNDEF();
   673                                 break;
   674                         }
   675                         break;
   676                     case 0xA:
   677                         switch( (ir&0xF0) >> 4 ) {
   678                             case 0x0:
   679                                 { /* STS MACH, Rn */
   680                                 uint32_t Rn = ((ir>>8)&0xF); 
   681                                 load_spreg( R_EAX, R_MACH );
   682                                 store_reg( R_EAX, Rn );
   683                                 }
   684                                 break;
   685                             case 0x1:
   686                                 { /* STS MACL, Rn */
   687                                 uint32_t Rn = ((ir>>8)&0xF); 
   688                                 load_spreg( R_EAX, R_MACL );
   689                                 store_reg( R_EAX, Rn );
   690                                 }
   691                                 break;
   692                             case 0x2:
   693                                 { /* STS PR, Rn */
   694                                 uint32_t Rn = ((ir>>8)&0xF); 
   695                                 load_spreg( R_EAX, R_PR );
   696                                 store_reg( R_EAX, Rn );
   697                                 }
   698                                 break;
   699                             case 0x3:
   700                                 { /* STC SGR, Rn */
   701                                 uint32_t Rn = ((ir>>8)&0xF); 
   702                                 check_priv();
   703                                 load_spreg( R_EAX, R_SGR );
   704                                 store_reg( R_EAX, Rn );
   705                                 sh4_x86.tstate = TSTATE_NONE;
   706                                 }
   707                                 break;
   708                             case 0x5:
   709                                 { /* STS FPUL, Rn */
   710                                 uint32_t Rn = ((ir>>8)&0xF); 
   711                                 load_spreg( R_EAX, R_FPUL );
   712                                 store_reg( R_EAX, Rn );
   713                                 }
   714                                 break;
   715                             case 0x6:
   716                                 { /* STS FPSCR, Rn */
   717                                 uint32_t Rn = ((ir>>8)&0xF); 
   718                                 load_spreg( R_EAX, R_FPSCR );
   719                                 store_reg( R_EAX, Rn );
   720                                 }
   721                                 break;
   722                             case 0xF:
   723                                 { /* STC DBR, Rn */
   724                                 uint32_t Rn = ((ir>>8)&0xF); 
   725                                 check_priv();
   726                                 load_spreg( R_EAX, R_DBR );
   727                                 store_reg( R_EAX, Rn );
   728                                 sh4_x86.tstate = TSTATE_NONE;
   729                                 }
   730                                 break;
   731                             default:
   732                                 UNDEF();
   733                                 break;
   734                         }
   735                         break;
   736                     case 0xB:
   737                         switch( (ir&0xFF0) >> 4 ) {
   738                             case 0x0:
   739                                 { /* RTS */
   740                                 if( sh4_x86.in_delay_slot ) {
   741                             	SLOTILLEGAL();
   742                                 } else {
   743                             	load_spreg( R_ECX, R_PR );
   744                             	store_spreg( R_ECX, REG_OFFSET(pc) );
   745                             	sh4_x86.in_delay_slot = TRUE;
   746                             	sh4_translate_instruction(pc+2);
   747                             	exit_block_pcset(pc+2);
   748                             	sh4_x86.branch_taken = TRUE;
   749                             	return 4;
   750                                 }
   751                                 }
   752                                 break;
   753                             case 0x1:
   754                                 { /* SLEEP */
   755                                 check_priv();
   756                                 call_func0( sh4_sleep );
   757                                 sh4_x86.tstate = TSTATE_NONE;
   758                                 sh4_x86.in_delay_slot = FALSE;
   759                                 return 2;
   760                                 }
   761                                 break;
   762                             case 0x2:
   763                                 { /* RTE */
   764                                 if( sh4_x86.in_delay_slot ) {
   765                             	SLOTILLEGAL();
   766                                 } else {
   767                             	check_priv();
   768                             	load_spreg( R_ECX, R_SPC );
   769                             	store_spreg( R_ECX, REG_OFFSET(pc) );
   770                             	load_spreg( R_EAX, R_SSR );
   771                             	call_func1( sh4_write_sr, R_EAX );
   772                             	sh4_x86.in_delay_slot = TRUE;
   773                             	sh4_x86.priv_checked = FALSE;
   774                             	sh4_x86.fpuen_checked = FALSE;
   775                             	sh4_x86.tstate = TSTATE_NONE;
   776                             	sh4_translate_instruction(pc+2);
   777                             	exit_block_pcset(pc+2);
   778                             	sh4_x86.branch_taken = TRUE;
   779                             	return 4;
   780                                 }
   781                                 }
   782                                 break;
   783                             default:
   784                                 UNDEF();
   785                                 break;
   786                         }
   787                         break;
   788                     case 0xC:
   789                         { /* MOV.B @(R0, Rm), Rn */
   790                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   791                         load_reg( R_EAX, 0 );
   792                         load_reg( R_ECX, Rm );
   793                         ADD_r32_r32( R_EAX, R_ECX );
   794                         MEM_READ_BYTE( R_ECX, R_EAX );
   795                         store_reg( R_EAX, Rn );
   796                         sh4_x86.tstate = TSTATE_NONE;
   797                         }
   798                         break;
   799                     case 0xD:
   800                         { /* MOV.W @(R0, Rm), Rn */
   801                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   802                         load_reg( R_EAX, 0 );
   803                         load_reg( R_ECX, Rm );
   804                         ADD_r32_r32( R_EAX, R_ECX );
   805                         precheck();
   806                         check_ralign16( R_ECX );
   807                         MEM_READ_WORD( R_ECX, R_EAX );
   808                         store_reg( R_EAX, Rn );
   809                         sh4_x86.tstate = TSTATE_NONE;
   810                         }
   811                         break;
   812                     case 0xE:
   813                         { /* MOV.L @(R0, Rm), Rn */
   814                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   815                         load_reg( R_EAX, 0 );
   816                         load_reg( R_ECX, Rm );
   817                         ADD_r32_r32( R_EAX, R_ECX );
   818                         precheck();
   819                         check_ralign32( R_ECX );
   820                         MEM_READ_LONG( R_ECX, R_EAX );
   821                         store_reg( R_EAX, Rn );
   822                         sh4_x86.tstate = TSTATE_NONE;
   823                         }
   824                         break;
   825                     case 0xF:
   826                         { /* MAC.L @Rm+, @Rn+ */
   827                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   828                         load_reg( R_ECX, Rm );
   829                         precheck();
   830                         check_ralign32( R_ECX );
   831                         load_reg( R_ECX, Rn );
   832                         check_ralign32( R_ECX );
   833                         ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rn]) );
   834                         MEM_READ_LONG( R_ECX, R_EAX );
   835                         PUSH_realigned_r32( R_EAX );
   836                         load_reg( R_ECX, Rm );
   837                         ADD_imm8s_sh4r( 4, REG_OFFSET(r[Rm]) );
   838                         MEM_READ_LONG( R_ECX, R_EAX );
   839                         POP_realigned_r32( R_ECX );
   840                         IMUL_r32( R_ECX );
   841                         ADD_r32_sh4r( R_EAX, R_MACL );
   842                         ADC_r32_sh4r( R_EDX, R_MACH );
   844                         load_spreg( R_ECX, R_S );
   845                         TEST_r32_r32(R_ECX, R_ECX);
   846                         JE_rel8( CALL_FUNC0_SIZE, nosat );
   847                         call_func0( signsat48 );
   848                         JMP_TARGET( nosat );
   849                         sh4_x86.tstate = TSTATE_NONE;
   850                         }
   851                         break;
   852                     default:
   853                         UNDEF();
   854                         break;
   855                 }
   856                 break;
   857             case 0x1:
   858                 { /* MOV.L Rm, @(disp, Rn) */
   859                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
   860                 load_reg( R_ECX, Rn );
   861                 load_reg( R_EAX, Rm );
   862                 ADD_imm32_r32( disp, R_ECX );
   863                 precheck();
   864                 check_walign32( R_ECX );
   865                 MEM_WRITE_LONG( R_ECX, R_EAX );
   866                 sh4_x86.tstate = TSTATE_NONE;
   867                 }
   868                 break;
   869             case 0x2:
   870                 switch( ir&0xF ) {
   871                     case 0x0:
   872                         { /* MOV.B Rm, @Rn */
   873                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   874                         load_reg( R_EAX, Rm );
   875                         load_reg( R_ECX, Rn );
   876                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   877                         sh4_x86.tstate = TSTATE_NONE;
   878                         }
   879                         break;
   880                     case 0x1:
   881                         { /* MOV.W Rm, @Rn */
   882                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   883                         load_reg( R_ECX, Rn );
   884                         precheck();
   885                         check_walign16( R_ECX );
   886                         load_reg( R_EAX, Rm );
   887                         MEM_WRITE_WORD( R_ECX, R_EAX );
   888                         sh4_x86.tstate = TSTATE_NONE;
   889                         }
   890                         break;
   891                     case 0x2:
   892                         { /* MOV.L Rm, @Rn */
   893                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   894                         load_reg( R_EAX, Rm );
   895                         load_reg( R_ECX, Rn );
   896                         precheck();
   897                         check_walign32(R_ECX);
   898                         MEM_WRITE_LONG( R_ECX, R_EAX );
   899                         sh4_x86.tstate = TSTATE_NONE;
   900                         }
   901                         break;
   902                     case 0x4:
   903                         { /* MOV.B Rm, @-Rn */
   904                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   905                         load_reg( R_EAX, Rm );
   906                         load_reg( R_ECX, Rn );
   907                         ADD_imm8s_r32( -1, R_ECX );
   908                         store_reg( R_ECX, Rn );
   909                         MEM_WRITE_BYTE( R_ECX, R_EAX );
   910                         sh4_x86.tstate = TSTATE_NONE;
   911                         }
   912                         break;
   913                     case 0x5:
   914                         { /* MOV.W Rm, @-Rn */
   915                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   916                         load_reg( R_ECX, Rn );
   917                         precheck();
   918                         check_walign16( R_ECX );
   919                         load_reg( R_EAX, Rm );
   920                         ADD_imm8s_r32( -2, R_ECX );
   921                         store_reg( R_ECX, Rn );
   922                         MEM_WRITE_WORD( R_ECX, R_EAX );
   923                         sh4_x86.tstate = TSTATE_NONE;
   924                         }
   925                         break;
   926                     case 0x6:
   927                         { /* MOV.L Rm, @-Rn */
   928                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   929                         load_reg( R_EAX, Rm );
   930                         load_reg( R_ECX, Rn );
   931                         precheck();
   932                         check_walign32( R_ECX );
   933                         ADD_imm8s_r32( -4, R_ECX );
   934                         store_reg( R_ECX, Rn );
   935                         MEM_WRITE_LONG( R_ECX, R_EAX );
   936                         sh4_x86.tstate = TSTATE_NONE;
   937                         }
   938                         break;
   939                     case 0x7:
   940                         { /* DIV0S Rm, Rn */
   941                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   942                         load_reg( R_EAX, Rm );
   943                         load_reg( R_ECX, Rn );
   944                         SHR_imm8_r32( 31, R_EAX );
   945                         SHR_imm8_r32( 31, R_ECX );
   946                         store_spreg( R_EAX, R_M );
   947                         store_spreg( R_ECX, R_Q );
   948                         CMP_r32_r32( R_EAX, R_ECX );
   949                         SETNE_t();
   950                         sh4_x86.tstate = TSTATE_NE;
   951                         }
   952                         break;
   953                     case 0x8:
   954                         { /* TST Rm, Rn */
   955                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   956                         load_reg( R_EAX, Rm );
   957                         load_reg( R_ECX, Rn );
   958                         TEST_r32_r32( R_EAX, R_ECX );
   959                         SETE_t();
   960                         sh4_x86.tstate = TSTATE_E;
   961                         }
   962                         break;
   963                     case 0x9:
   964                         { /* AND Rm, Rn */
   965                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   966                         load_reg( R_EAX, Rm );
   967                         load_reg( R_ECX, Rn );
   968                         AND_r32_r32( R_EAX, R_ECX );
   969                         store_reg( R_ECX, Rn );
   970                         sh4_x86.tstate = TSTATE_NONE;
   971                         }
   972                         break;
   973                     case 0xA:
   974                         { /* XOR Rm, Rn */
   975                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   976                         load_reg( R_EAX, Rm );
   977                         load_reg( R_ECX, Rn );
   978                         XOR_r32_r32( R_EAX, R_ECX );
   979                         store_reg( R_ECX, Rn );
   980                         sh4_x86.tstate = TSTATE_NONE;
   981                         }
   982                         break;
   983                     case 0xB:
   984                         { /* OR Rm, Rn */
   985                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   986                         load_reg( R_EAX, Rm );
   987                         load_reg( R_ECX, Rn );
   988                         OR_r32_r32( R_EAX, R_ECX );
   989                         store_reg( R_ECX, Rn );
   990                         sh4_x86.tstate = TSTATE_NONE;
   991                         }
   992                         break;
   993                     case 0xC:
   994                         { /* CMP/STR Rm, Rn */
   995                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
   996                         load_reg( R_EAX, Rm );
   997                         load_reg( R_ECX, Rn );
   998                         XOR_r32_r32( R_ECX, R_EAX );
   999                         TEST_r8_r8( R_AL, R_AL );
  1000                         JE_rel8(13, target1);
  1001                         TEST_r8_r8( R_AH, R_AH ); // 2
  1002                         JE_rel8(9, target2);
  1003                         SHR_imm8_r32( 16, R_EAX ); // 3
  1004                         TEST_r8_r8( R_AL, R_AL ); // 2
  1005                         JE_rel8(2, target3);
  1006                         TEST_r8_r8( R_AH, R_AH ); // 2
  1007                         JMP_TARGET(target1);
  1008                         JMP_TARGET(target2);
  1009                         JMP_TARGET(target3);
  1010                         SETE_t();
  1011                         sh4_x86.tstate = TSTATE_E;
  1013                         break;
  1014                     case 0xD:
  1015                         { /* XTRCT Rm, Rn */
  1016                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1017                         load_reg( R_EAX, Rm );
  1018                         load_reg( R_ECX, Rn );
  1019                         SHL_imm8_r32( 16, R_EAX );
  1020                         SHR_imm8_r32( 16, R_ECX );
  1021                         OR_r32_r32( R_EAX, R_ECX );
  1022                         store_reg( R_ECX, Rn );
  1023                         sh4_x86.tstate = TSTATE_NONE;
  1025                         break;
  1026                     case 0xE:
  1027                         { /* MULU.W Rm, Rn */
  1028                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1029                         load_reg16u( R_EAX, Rm );
  1030                         load_reg16u( R_ECX, Rn );
  1031                         MUL_r32( R_ECX );
  1032                         store_spreg( R_EAX, R_MACL );
  1033                         sh4_x86.tstate = TSTATE_NONE;
  1035                         break;
  1036                     case 0xF:
  1037                         { /* MULS.W Rm, Rn */
  1038                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1039                         load_reg16s( R_EAX, Rm );
  1040                         load_reg16s( R_ECX, Rn );
  1041                         MUL_r32( R_ECX );
  1042                         store_spreg( R_EAX, R_MACL );
  1043                         sh4_x86.tstate = TSTATE_NONE;
  1045                         break;
  1046                     default:
  1047                         UNDEF();
  1048                         break;
  1050                 break;
  1051             case 0x3:
  1052                 switch( ir&0xF ) {
  1053                     case 0x0:
  1054                         { /* CMP/EQ Rm, Rn */
  1055                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1056                         load_reg( R_EAX, Rm );
  1057                         load_reg( R_ECX, Rn );
  1058                         CMP_r32_r32( R_EAX, R_ECX );
  1059                         SETE_t();
  1060                         sh4_x86.tstate = TSTATE_E;
  1062                         break;
  1063                     case 0x2:
  1064                         { /* CMP/HS Rm, Rn */
  1065                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1066                         load_reg( R_EAX, Rm );
  1067                         load_reg( R_ECX, Rn );
  1068                         CMP_r32_r32( R_EAX, R_ECX );
  1069                         SETAE_t();
  1070                         sh4_x86.tstate = TSTATE_AE;
  1072                         break;
  1073                     case 0x3:
  1074                         { /* CMP/GE Rm, Rn */
  1075                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1076                         load_reg( R_EAX, Rm );
  1077                         load_reg( R_ECX, Rn );
  1078                         CMP_r32_r32( R_EAX, R_ECX );
  1079                         SETGE_t();
  1080                         sh4_x86.tstate = TSTATE_GE;
  1082                         break;
  1083                     case 0x4:
  1084                         { /* DIV1 Rm, Rn */
  1085                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1086                         load_spreg( R_ECX, R_M );
  1087                         load_reg( R_EAX, Rn );
  1088                         if( sh4_x86.tstate != TSTATE_C ) {
  1089                     	LDC_t();
  1091                         RCL1_r32( R_EAX );
  1092                         SETC_r8( R_DL ); // Q'
  1093                         CMP_sh4r_r32( R_Q, R_ECX );
  1094                         JE_rel8(5, mqequal);
  1095                         ADD_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
  1096                         JMP_rel8(3, end);
  1097                         JMP_TARGET(mqequal);
  1098                         SUB_sh4r_r32( REG_OFFSET(r[Rm]), R_EAX );
  1099                         JMP_TARGET(end);
  1100                         store_reg( R_EAX, Rn ); // Done with Rn now
  1101                         SETC_r8(R_AL); // tmp1
  1102                         XOR_r8_r8( R_DL, R_AL ); // Q' = Q ^ tmp1
  1103                         XOR_r8_r8( R_AL, R_CL ); // Q'' = Q' ^ M
  1104                         store_spreg( R_ECX, R_Q );
  1105                         XOR_imm8s_r32( 1, R_AL );   // T = !Q'
  1106                         MOVZX_r8_r32( R_AL, R_EAX );
  1107                         store_spreg( R_EAX, R_T );
  1108                         sh4_x86.tstate = TSTATE_NONE;
  1110                         break;
  1111                     case 0x5:
  1112                         { /* DMULU.L Rm, Rn */
  1113                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1114                         load_reg( R_EAX, Rm );
  1115                         load_reg( R_ECX, Rn );
  1116                         MUL_r32(R_ECX);
  1117                         store_spreg( R_EDX, R_MACH );
  1118                         store_spreg( R_EAX, R_MACL );    
  1119                         sh4_x86.tstate = TSTATE_NONE;
  1121                         break;
  1122                     case 0x6:
  1123                         { /* CMP/HI Rm, Rn */
  1124                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1125                         load_reg( R_EAX, Rm );
  1126                         load_reg( R_ECX, Rn );
  1127                         CMP_r32_r32( R_EAX, R_ECX );
  1128                         SETA_t();
  1129                         sh4_x86.tstate = TSTATE_A;
  1131                         break;
  1132                     case 0x7:
  1133                         { /* CMP/GT Rm, Rn */
  1134                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1135                         load_reg( R_EAX, Rm );
  1136                         load_reg( R_ECX, Rn );
  1137                         CMP_r32_r32( R_EAX, R_ECX );
  1138                         SETG_t();
  1139                         sh4_x86.tstate = TSTATE_G;
  1141                         break;
  1142                     case 0x8:
  1143                         { /* SUB Rm, Rn */
  1144                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1145                         load_reg( R_EAX, Rm );
  1146                         load_reg( R_ECX, Rn );
  1147                         SUB_r32_r32( R_EAX, R_ECX );
  1148                         store_reg( R_ECX, Rn );
  1149                         sh4_x86.tstate = TSTATE_NONE;
  1151                         break;
  1152                     case 0xA:
  1153                         { /* SUBC Rm, Rn */
  1154                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1155                         load_reg( R_EAX, Rm );
  1156                         load_reg( R_ECX, Rn );
  1157                         if( sh4_x86.tstate != TSTATE_C ) {
  1158                     	LDC_t();
  1160                         SBB_r32_r32( R_EAX, R_ECX );
  1161                         store_reg( R_ECX, Rn );
  1162                         SETC_t();
  1163                         sh4_x86.tstate = TSTATE_C;
  1165                         break;
  1166                     case 0xB:
  1167                         { /* SUBV Rm, Rn */
  1168                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1169                         load_reg( R_EAX, Rm );
  1170                         load_reg( R_ECX, Rn );
  1171                         SUB_r32_r32( R_EAX, R_ECX );
  1172                         store_reg( R_ECX, Rn );
  1173                         SETO_t();
  1174                         sh4_x86.tstate = TSTATE_O;
  1176                         break;
  1177                     case 0xC:
  1178                         { /* ADD Rm, Rn */
  1179                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1180                         load_reg( R_EAX, Rm );
  1181                         load_reg( R_ECX, Rn );
  1182                         ADD_r32_r32( R_EAX, R_ECX );
  1183                         store_reg( R_ECX, Rn );
  1184                         sh4_x86.tstate = TSTATE_NONE;
  1186                         break;
  1187                     case 0xD:
  1188                         { /* DMULS.L Rm, Rn */
  1189                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1190                         load_reg( R_EAX, Rm );
  1191                         load_reg( R_ECX, Rn );
  1192                         IMUL_r32(R_ECX);
  1193                         store_spreg( R_EDX, R_MACH );
  1194                         store_spreg( R_EAX, R_MACL );
  1195                         sh4_x86.tstate = TSTATE_NONE;
  1197                         break;
  1198                     case 0xE:
  1199                         { /* ADDC Rm, Rn */
  1200                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1201                         if( sh4_x86.tstate != TSTATE_C ) {
  1202                     	LDC_t();
  1204                         load_reg( R_EAX, Rm );
  1205                         load_reg( R_ECX, Rn );
  1206                         ADC_r32_r32( R_EAX, R_ECX );
  1207                         store_reg( R_ECX, Rn );
  1208                         SETC_t();
  1209                         sh4_x86.tstate = TSTATE_C;
  1211                         break;
  1212                     case 0xF:
  1213                         { /* ADDV Rm, Rn */
  1214                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1215                         load_reg( R_EAX, Rm );
  1216                         load_reg( R_ECX, Rn );
  1217                         ADD_r32_r32( R_EAX, R_ECX );
  1218                         store_reg( R_ECX, Rn );
  1219                         SETO_t();
  1220                         sh4_x86.tstate = TSTATE_O;
  1222                         break;
  1223                     default:
  1224                         UNDEF();
  1225                         break;
  1227                 break;
  1228             case 0x4:
  1229                 switch( ir&0xF ) {
  1230                     case 0x0:
  1231                         switch( (ir&0xF0) >> 4 ) {
  1232                             case 0x0:
  1233                                 { /* SHLL Rn */
  1234                                 uint32_t Rn = ((ir>>8)&0xF); 
  1235                                 load_reg( R_EAX, Rn );
  1236                                 SHL1_r32( R_EAX );
  1237                                 SETC_t();
  1238                                 store_reg( R_EAX, Rn );
  1239                                 sh4_x86.tstate = TSTATE_C;
  1241                                 break;
  1242                             case 0x1:
  1243                                 { /* DT Rn */
  1244                                 uint32_t Rn = ((ir>>8)&0xF); 
  1245                                 load_reg( R_EAX, Rn );
  1246                                 ADD_imm8s_r32( -1, R_EAX );
  1247                                 store_reg( R_EAX, Rn );
  1248                                 SETE_t();
  1249                                 sh4_x86.tstate = TSTATE_E;
  1251                                 break;
  1252                             case 0x2:
  1253                                 { /* SHAL Rn */
  1254                                 uint32_t Rn = ((ir>>8)&0xF); 
  1255                                 load_reg( R_EAX, Rn );
  1256                                 SHL1_r32( R_EAX );
  1257                                 SETC_t();
  1258                                 store_reg( R_EAX, Rn );
  1259                                 sh4_x86.tstate = TSTATE_C;
  1261                                 break;
  1262                             default:
  1263                                 UNDEF();
  1264                                 break;
  1266                         break;
  1267                     case 0x1:
  1268                         switch( (ir&0xF0) >> 4 ) {
  1269                             case 0x0:
  1270                                 { /* SHLR Rn */
  1271                                 uint32_t Rn = ((ir>>8)&0xF); 
  1272                                 load_reg( R_EAX, Rn );
  1273                                 SHR1_r32( R_EAX );
  1274                                 SETC_t();
  1275                                 store_reg( R_EAX, Rn );
  1276                                 sh4_x86.tstate = TSTATE_C;
  1278                                 break;
  1279                             case 0x1:
  1280                                 { /* CMP/PZ Rn */
  1281                                 uint32_t Rn = ((ir>>8)&0xF); 
  1282                                 load_reg( R_EAX, Rn );
  1283                                 CMP_imm8s_r32( 0, R_EAX );
  1284                                 SETGE_t();
  1285                                 sh4_x86.tstate = TSTATE_GE;
  1287                                 break;
  1288                             case 0x2:
  1289                                 { /* SHAR Rn */
  1290                                 uint32_t Rn = ((ir>>8)&0xF); 
  1291                                 load_reg( R_EAX, Rn );
  1292                                 SAR1_r32( R_EAX );
  1293                                 SETC_t();
  1294                                 store_reg( R_EAX, Rn );
  1295                                 sh4_x86.tstate = TSTATE_C;
  1297                                 break;
  1298                             default:
  1299                                 UNDEF();
  1300                                 break;
  1302                         break;
  1303                     case 0x2:
  1304                         switch( (ir&0xF0) >> 4 ) {
  1305                             case 0x0:
  1306                                 { /* STS.L MACH, @-Rn */
  1307                                 uint32_t Rn = ((ir>>8)&0xF); 
  1308                                 load_reg( R_ECX, Rn );
  1309                                 precheck();
  1310                                 check_walign32( R_ECX );
  1311                                 ADD_imm8s_r32( -4, R_ECX );
  1312                                 store_reg( R_ECX, Rn );
  1313                                 load_spreg( R_EAX, R_MACH );
  1314                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1315                                 sh4_x86.tstate = TSTATE_NONE;
  1317                                 break;
  1318                             case 0x1:
  1319                                 { /* STS.L MACL, @-Rn */
  1320                                 uint32_t Rn = ((ir>>8)&0xF); 
  1321                                 load_reg( R_ECX, Rn );
  1322                                 precheck();
  1323                                 check_walign32( R_ECX );
  1324                                 ADD_imm8s_r32( -4, R_ECX );
  1325                                 store_reg( R_ECX, Rn );
  1326                                 load_spreg( R_EAX, R_MACL );
  1327                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1328                                 sh4_x86.tstate = TSTATE_NONE;
  1330                                 break;
  1331                             case 0x2:
  1332                                 { /* STS.L PR, @-Rn */
  1333                                 uint32_t Rn = ((ir>>8)&0xF); 
  1334                                 load_reg( R_ECX, Rn );
  1335                                 precheck();
  1336                                 check_walign32( R_ECX );
  1337                                 ADD_imm8s_r32( -4, R_ECX );
  1338                                 store_reg( R_ECX, Rn );
  1339                                 load_spreg( R_EAX, R_PR );
  1340                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1341                                 sh4_x86.tstate = TSTATE_NONE;
  1343                                 break;
  1344                             case 0x3:
  1345                                 { /* STC.L SGR, @-Rn */
  1346                                 uint32_t Rn = ((ir>>8)&0xF); 
  1347                                 precheck();
  1348                                 check_priv_no_precheck();
  1349                                 load_reg( R_ECX, Rn );
  1350                                 check_walign32( R_ECX );
  1351                                 ADD_imm8s_r32( -4, R_ECX );
  1352                                 store_reg( R_ECX, Rn );
  1353                                 load_spreg( R_EAX, R_SGR );
  1354                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1355                                 sh4_x86.tstate = TSTATE_NONE;
  1357                                 break;
  1358                             case 0x5:
  1359                                 { /* STS.L FPUL, @-Rn */
  1360                                 uint32_t Rn = ((ir>>8)&0xF); 
  1361                                 load_reg( R_ECX, Rn );
  1362                                 precheck();
  1363                                 check_walign32( R_ECX );
  1364                                 ADD_imm8s_r32( -4, R_ECX );
  1365                                 store_reg( R_ECX, Rn );
  1366                                 load_spreg( R_EAX, R_FPUL );
  1367                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1368                                 sh4_x86.tstate = TSTATE_NONE;
  1370                                 break;
  1371                             case 0x6:
  1372                                 { /* STS.L FPSCR, @-Rn */
  1373                                 uint32_t Rn = ((ir>>8)&0xF); 
  1374                                 load_reg( R_ECX, Rn );
  1375                                 precheck();
  1376                                 check_walign32( R_ECX );
  1377                                 ADD_imm8s_r32( -4, R_ECX );
  1378                                 store_reg( R_ECX, Rn );
  1379                                 load_spreg( R_EAX, R_FPSCR );
  1380                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1381                                 sh4_x86.tstate = TSTATE_NONE;
  1383                                 break;
  1384                             case 0xF:
  1385                                 { /* STC.L DBR, @-Rn */
  1386                                 uint32_t Rn = ((ir>>8)&0xF); 
  1387                                 precheck();
  1388                                 check_priv_no_precheck();
  1389                                 load_reg( R_ECX, Rn );
  1390                                 check_walign32( R_ECX );
  1391                                 ADD_imm8s_r32( -4, R_ECX );
  1392                                 store_reg( R_ECX, Rn );
  1393                                 load_spreg( R_EAX, R_DBR );
  1394                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1395                                 sh4_x86.tstate = TSTATE_NONE;
  1397                                 break;
  1398                             default:
  1399                                 UNDEF();
  1400                                 break;
  1402                         break;
  1403                     case 0x3:
  1404                         switch( (ir&0x80) >> 7 ) {
  1405                             case 0x0:
  1406                                 switch( (ir&0x70) >> 4 ) {
  1407                                     case 0x0:
  1408                                         { /* STC.L SR, @-Rn */
  1409                                         uint32_t Rn = ((ir>>8)&0xF); 
  1410                                         precheck();
  1411                                         check_priv_no_precheck();
  1412                                         call_func0( sh4_read_sr );
  1413                                         load_reg( R_ECX, Rn );
  1414                                         check_walign32( R_ECX );
  1415                                         ADD_imm8s_r32( -4, R_ECX );
  1416                                         store_reg( R_ECX, Rn );
  1417                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1418                                         sh4_x86.tstate = TSTATE_NONE;
  1420                                         break;
  1421                                     case 0x1:
  1422                                         { /* STC.L GBR, @-Rn */
  1423                                         uint32_t Rn = ((ir>>8)&0xF); 
  1424                                         load_reg( R_ECX, Rn );
  1425                                         precheck();
  1426                                         check_walign32( R_ECX );
  1427                                         ADD_imm8s_r32( -4, R_ECX );
  1428                                         store_reg( R_ECX, Rn );
  1429                                         load_spreg( R_EAX, R_GBR );
  1430                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1431                                         sh4_x86.tstate = TSTATE_NONE;
  1433                                         break;
  1434                                     case 0x2:
  1435                                         { /* STC.L VBR, @-Rn */
  1436                                         uint32_t Rn = ((ir>>8)&0xF); 
  1437                                         precheck();
  1438                                         check_priv_no_precheck();
  1439                                         load_reg( R_ECX, Rn );
  1440                                         check_walign32( R_ECX );
  1441                                         ADD_imm8s_r32( -4, R_ECX );
  1442                                         store_reg( R_ECX, Rn );
  1443                                         load_spreg( R_EAX, R_VBR );
  1444                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1445                                         sh4_x86.tstate = TSTATE_NONE;
  1447                                         break;
  1448                                     case 0x3:
  1449                                         { /* STC.L SSR, @-Rn */
  1450                                         uint32_t Rn = ((ir>>8)&0xF); 
  1451                                         precheck();
  1452                                         check_priv_no_precheck();
  1453                                         load_reg( R_ECX, Rn );
  1454                                         check_walign32( R_ECX );
  1455                                         ADD_imm8s_r32( -4, R_ECX );
  1456                                         store_reg( R_ECX, Rn );
  1457                                         load_spreg( R_EAX, R_SSR );
  1458                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1459                                         sh4_x86.tstate = TSTATE_NONE;
  1461                                         break;
  1462                                     case 0x4:
  1463                                         { /* STC.L SPC, @-Rn */
  1464                                         uint32_t Rn = ((ir>>8)&0xF); 
  1465                                         precheck();
  1466                                         check_priv_no_precheck();
  1467                                         load_reg( R_ECX, Rn );
  1468                                         check_walign32( R_ECX );
  1469                                         ADD_imm8s_r32( -4, R_ECX );
  1470                                         store_reg( R_ECX, Rn );
  1471                                         load_spreg( R_EAX, R_SPC );
  1472                                         MEM_WRITE_LONG( R_ECX, R_EAX );
  1473                                         sh4_x86.tstate = TSTATE_NONE;
  1475                                         break;
  1476                                     default:
  1477                                         UNDEF();
  1478                                         break;
  1480                                 break;
  1481                             case 0x1:
  1482                                 { /* STC.L Rm_BANK, @-Rn */
  1483                                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
  1484                                 precheck();
  1485                                 check_priv_no_precheck();
  1486                                 load_reg( R_ECX, Rn );
  1487                                 check_walign32( R_ECX );
  1488                                 ADD_imm8s_r32( -4, R_ECX );
  1489                                 store_reg( R_ECX, Rn );
  1490                                 load_spreg( R_EAX, REG_OFFSET(r_bank[Rm_BANK]) );
  1491                                 MEM_WRITE_LONG( R_ECX, R_EAX );
  1492                                 sh4_x86.tstate = TSTATE_NONE;
  1494                                 break;
  1496                         break;
  1497                     case 0x4:
  1498                         switch( (ir&0xF0) >> 4 ) {
  1499                             case 0x0:
  1500                                 { /* ROTL Rn */
  1501                                 uint32_t Rn = ((ir>>8)&0xF); 
  1502                                 load_reg( R_EAX, Rn );
  1503                                 ROL1_r32( R_EAX );
  1504                                 store_reg( R_EAX, Rn );
  1505                                 SETC_t();
  1506                                 sh4_x86.tstate = TSTATE_C;
  1508                                 break;
  1509                             case 0x2:
  1510                                 { /* ROTCL Rn */
  1511                                 uint32_t Rn = ((ir>>8)&0xF); 
  1512                                 load_reg( R_EAX, Rn );
  1513                                 if( sh4_x86.tstate != TSTATE_C ) {
  1514                             	LDC_t();
  1516                                 RCL1_r32( R_EAX );
  1517                                 store_reg( R_EAX, Rn );
  1518                                 SETC_t();
  1519                                 sh4_x86.tstate = TSTATE_C;
  1521                                 break;
  1522                             default:
  1523                                 UNDEF();
  1524                                 break;
  1526                         break;
  1527                     case 0x5:
  1528                         switch( (ir&0xF0) >> 4 ) {
  1529                             case 0x0:
  1530                                 { /* ROTR Rn */
  1531                                 uint32_t Rn = ((ir>>8)&0xF); 
  1532                                 load_reg( R_EAX, Rn );
  1533                                 ROR1_r32( R_EAX );
  1534                                 store_reg( R_EAX, Rn );
  1535                                 SETC_t();
  1536                                 sh4_x86.tstate = TSTATE_C;
  1538                                 break;
  1539                             case 0x1:
  1540                                 { /* CMP/PL Rn */
  1541                                 uint32_t Rn = ((ir>>8)&0xF); 
  1542                                 load_reg( R_EAX, Rn );
  1543                                 CMP_imm8s_r32( 0, R_EAX );
  1544                                 SETG_t();
  1545                                 sh4_x86.tstate = TSTATE_G;
  1547                                 break;
  1548                             case 0x2:
  1549                                 { /* ROTCR Rn */
  1550                                 uint32_t Rn = ((ir>>8)&0xF); 
  1551                                 load_reg( R_EAX, Rn );
  1552                                 if( sh4_x86.tstate != TSTATE_C ) {
  1553                             	LDC_t();
  1555                                 RCR1_r32( R_EAX );
  1556                                 store_reg( R_EAX, Rn );
  1557                                 SETC_t();
  1558                                 sh4_x86.tstate = TSTATE_C;
  1560                                 break;
  1561                             default:
  1562                                 UNDEF();
  1563                                 break;
  1565                         break;
  1566                     case 0x6:
  1567                         switch( (ir&0xF0) >> 4 ) {
  1568                             case 0x0:
  1569                                 { /* LDS.L @Rm+, MACH */
  1570                                 uint32_t Rm = ((ir>>8)&0xF); 
  1571                                 load_reg( R_EAX, Rm );
  1572                                 precheck();
  1573                                 check_ralign32( R_EAX );
  1574                                 MOV_r32_r32( R_EAX, R_ECX );
  1575                                 ADD_imm8s_r32( 4, R_EAX );
  1576                                 store_reg( R_EAX, Rm );
  1577                                 MEM_READ_LONG( R_ECX, R_EAX );
  1578                                 store_spreg( R_EAX, R_MACH );
  1579                                 sh4_x86.tstate = TSTATE_NONE;
  1581                                 break;
  1582                             case 0x1:
  1583                                 { /* LDS.L @Rm+, MACL */
  1584                                 uint32_t Rm = ((ir>>8)&0xF); 
  1585                                 load_reg( R_EAX, Rm );
  1586                                 precheck();
  1587                                 check_ralign32( R_EAX );
  1588                                 MOV_r32_r32( R_EAX, R_ECX );
  1589                                 ADD_imm8s_r32( 4, R_EAX );
  1590                                 store_reg( R_EAX, Rm );
  1591                                 MEM_READ_LONG( R_ECX, R_EAX );
  1592                                 store_spreg( R_EAX, R_MACL );
  1593                                 sh4_x86.tstate = TSTATE_NONE;
  1595                                 break;
  1596                             case 0x2:
  1597                                 { /* LDS.L @Rm+, PR */
  1598                                 uint32_t Rm = ((ir>>8)&0xF); 
  1599                                 load_reg( R_EAX, Rm );
  1600                                 precheck();
  1601                                 check_ralign32( R_EAX );
  1602                                 MOV_r32_r32( R_EAX, R_ECX );
  1603                                 ADD_imm8s_r32( 4, R_EAX );
  1604                                 store_reg( R_EAX, Rm );
  1605                                 MEM_READ_LONG( R_ECX, R_EAX );
  1606                                 store_spreg( R_EAX, R_PR );
  1607                                 sh4_x86.tstate = TSTATE_NONE;
  1609                                 break;
  1610                             case 0x3:
  1611                                 { /* LDC.L @Rm+, SGR */
  1612                                 uint32_t Rm = ((ir>>8)&0xF); 
  1613                                 precheck();
  1614                                 check_priv_no_precheck();
  1615                                 load_reg( R_EAX, Rm );
  1616                                 check_ralign32( R_EAX );
  1617                                 MOV_r32_r32( R_EAX, R_ECX );
  1618                                 ADD_imm8s_r32( 4, R_EAX );
  1619                                 store_reg( R_EAX, Rm );
  1620                                 MEM_READ_LONG( R_ECX, R_EAX );
  1621                                 store_spreg( R_EAX, R_SGR );
  1622                                 sh4_x86.tstate = TSTATE_NONE;
  1624                                 break;
  1625                             case 0x5:
  1626                                 { /* LDS.L @Rm+, FPUL */
  1627                                 uint32_t Rm = ((ir>>8)&0xF); 
  1628                                 load_reg( R_EAX, Rm );
  1629                                 precheck();
  1630                                 check_ralign32( R_EAX );
  1631                                 MOV_r32_r32( R_EAX, R_ECX );
  1632                                 ADD_imm8s_r32( 4, R_EAX );
  1633                                 store_reg( R_EAX, Rm );
  1634                                 MEM_READ_LONG( R_ECX, R_EAX );
  1635                                 store_spreg( R_EAX, R_FPUL );
  1636                                 sh4_x86.tstate = TSTATE_NONE;
  1638                                 break;
  1639                             case 0x6:
  1640                                 { /* LDS.L @Rm+, FPSCR */
  1641                                 uint32_t Rm = ((ir>>8)&0xF); 
  1642                                 load_reg( R_EAX, Rm );
  1643                                 precheck();
  1644                                 check_ralign32( R_EAX );
  1645                                 MOV_r32_r32( R_EAX, R_ECX );
  1646                                 ADD_imm8s_r32( 4, R_EAX );
  1647                                 store_reg( R_EAX, Rm );
  1648                                 MEM_READ_LONG( R_ECX, R_EAX );
  1649                                 store_spreg( R_EAX, R_FPSCR );
  1650                                 update_fr_bank( R_EAX );
  1651                                 sh4_x86.tstate = TSTATE_NONE;
  1653                                 break;
  1654                             case 0xF:
  1655                                 { /* LDC.L @Rm+, DBR */
  1656                                 uint32_t Rm = ((ir>>8)&0xF); 
  1657                                 precheck();
  1658                                 check_priv_no_precheck();
  1659                                 load_reg( R_EAX, Rm );
  1660                                 check_ralign32( R_EAX );
  1661                                 MOV_r32_r32( R_EAX, R_ECX );
  1662                                 ADD_imm8s_r32( 4, R_EAX );
  1663                                 store_reg( R_EAX, Rm );
  1664                                 MEM_READ_LONG( R_ECX, R_EAX );
  1665                                 store_spreg( R_EAX, R_DBR );
  1666                                 sh4_x86.tstate = TSTATE_NONE;
  1668                                 break;
  1669                             default:
  1670                                 UNDEF();
  1671                                 break;
  1673                         break;
  1674                     case 0x7:
  1675                         switch( (ir&0x80) >> 7 ) {
  1676                             case 0x0:
  1677                                 switch( (ir&0x70) >> 4 ) {
  1678                                     case 0x0:
  1679                                         { /* LDC.L @Rm+, SR */
  1680                                         uint32_t Rm = ((ir>>8)&0xF); 
  1681                                         if( sh4_x86.in_delay_slot ) {
  1682                                     	SLOTILLEGAL();
  1683                                         } else {
  1684                                     	precheck();
  1685                                     	check_priv_no_precheck();
  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                                     	call_func1( sh4_write_sr, R_EAX );
  1693                                     	sh4_x86.priv_checked = FALSE;
  1694                                     	sh4_x86.fpuen_checked = FALSE;
  1695                                     	sh4_x86.tstate = TSTATE_NONE;
  1698                                         break;
  1699                                     case 0x1:
  1700                                         { /* LDC.L @Rm+, GBR */
  1701                                         uint32_t Rm = ((ir>>8)&0xF); 
  1702                                         load_reg( R_EAX, Rm );
  1703                                         precheck();
  1704                                         check_ralign32( R_EAX );
  1705                                         MOV_r32_r32( R_EAX, R_ECX );
  1706                                         ADD_imm8s_r32( 4, R_EAX );
  1707                                         store_reg( R_EAX, Rm );
  1708                                         MEM_READ_LONG( R_ECX, R_EAX );
  1709                                         store_spreg( R_EAX, R_GBR );
  1710                                         sh4_x86.tstate = TSTATE_NONE;
  1712                                         break;
  1713                                     case 0x2:
  1714                                         { /* LDC.L @Rm+, VBR */
  1715                                         uint32_t Rm = ((ir>>8)&0xF); 
  1716                                         precheck();
  1717                                         check_priv_no_precheck();
  1718                                         load_reg( R_EAX, Rm );
  1719                                         check_ralign32( R_EAX );
  1720                                         MOV_r32_r32( R_EAX, R_ECX );
  1721                                         ADD_imm8s_r32( 4, R_EAX );
  1722                                         store_reg( R_EAX, Rm );
  1723                                         MEM_READ_LONG( R_ECX, R_EAX );
  1724                                         store_spreg( R_EAX, R_VBR );
  1725                                         sh4_x86.tstate = TSTATE_NONE;
  1727                                         break;
  1728                                     case 0x3:
  1729                                         { /* LDC.L @Rm+, SSR */
  1730                                         uint32_t Rm = ((ir>>8)&0xF); 
  1731                                         precheck();
  1732                                         check_priv_no_precheck();
  1733                                         load_reg( R_EAX, Rm );
  1734                                         check_ralign32( R_EAX );
  1735                                         MOV_r32_r32( R_EAX, R_ECX );
  1736                                         ADD_imm8s_r32( 4, R_EAX );
  1737                                         store_reg( R_EAX, Rm );
  1738                                         MEM_READ_LONG( R_ECX, R_EAX );
  1739                                         store_spreg( R_EAX, R_SSR );
  1740                                         sh4_x86.tstate = TSTATE_NONE;
  1742                                         break;
  1743                                     case 0x4:
  1744                                         { /* LDC.L @Rm+, SPC */
  1745                                         uint32_t Rm = ((ir>>8)&0xF); 
  1746                                         precheck();
  1747                                         check_priv_no_precheck();
  1748                                         load_reg( R_EAX, Rm );
  1749                                         check_ralign32( R_EAX );
  1750                                         MOV_r32_r32( R_EAX, R_ECX );
  1751                                         ADD_imm8s_r32( 4, R_EAX );
  1752                                         store_reg( R_EAX, Rm );
  1753                                         MEM_READ_LONG( R_ECX, R_EAX );
  1754                                         store_spreg( R_EAX, R_SPC );
  1755                                         sh4_x86.tstate = TSTATE_NONE;
  1757                                         break;
  1758                                     default:
  1759                                         UNDEF();
  1760                                         break;
  1762                                 break;
  1763                             case 0x1:
  1764                                 { /* LDC.L @Rm+, Rn_BANK */
  1765                                 uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
  1766                                 precheck();
  1767                                 check_priv_no_precheck();
  1768                                 load_reg( R_EAX, Rm );
  1769                                 check_ralign32( R_EAX );
  1770                                 MOV_r32_r32( R_EAX, R_ECX );
  1771                                 ADD_imm8s_r32( 4, R_EAX );
  1772                                 store_reg( R_EAX, Rm );
  1773                                 MEM_READ_LONG( R_ECX, R_EAX );
  1774                                 store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
  1775                                 sh4_x86.tstate = TSTATE_NONE;
  1777                                 break;
  1779                         break;
  1780                     case 0x8:
  1781                         switch( (ir&0xF0) >> 4 ) {
  1782                             case 0x0:
  1783                                 { /* SHLL2 Rn */
  1784                                 uint32_t Rn = ((ir>>8)&0xF); 
  1785                                 load_reg( R_EAX, Rn );
  1786                                 SHL_imm8_r32( 2, R_EAX );
  1787                                 store_reg( R_EAX, Rn );
  1788                                 sh4_x86.tstate = TSTATE_NONE;
  1790                                 break;
  1791                             case 0x1:
  1792                                 { /* SHLL8 Rn */
  1793                                 uint32_t Rn = ((ir>>8)&0xF); 
  1794                                 load_reg( R_EAX, Rn );
  1795                                 SHL_imm8_r32( 8, R_EAX );
  1796                                 store_reg( R_EAX, Rn );
  1797                                 sh4_x86.tstate = TSTATE_NONE;
  1799                                 break;
  1800                             case 0x2:
  1801                                 { /* SHLL16 Rn */
  1802                                 uint32_t Rn = ((ir>>8)&0xF); 
  1803                                 load_reg( R_EAX, Rn );
  1804                                 SHL_imm8_r32( 16, R_EAX );
  1805                                 store_reg( R_EAX, Rn );
  1806                                 sh4_x86.tstate = TSTATE_NONE;
  1808                                 break;
  1809                             default:
  1810                                 UNDEF();
  1811                                 break;
  1813                         break;
  1814                     case 0x9:
  1815                         switch( (ir&0xF0) >> 4 ) {
  1816                             case 0x0:
  1817                                 { /* SHLR2 Rn */
  1818                                 uint32_t Rn = ((ir>>8)&0xF); 
  1819                                 load_reg( R_EAX, Rn );
  1820                                 SHR_imm8_r32( 2, R_EAX );
  1821                                 store_reg( R_EAX, Rn );
  1822                                 sh4_x86.tstate = TSTATE_NONE;
  1824                                 break;
  1825                             case 0x1:
  1826                                 { /* SHLR8 Rn */
  1827                                 uint32_t Rn = ((ir>>8)&0xF); 
  1828                                 load_reg( R_EAX, Rn );
  1829                                 SHR_imm8_r32( 8, R_EAX );
  1830                                 store_reg( R_EAX, Rn );
  1831                                 sh4_x86.tstate = TSTATE_NONE;
  1833                                 break;
  1834                             case 0x2:
  1835                                 { /* SHLR16 Rn */
  1836                                 uint32_t Rn = ((ir>>8)&0xF); 
  1837                                 load_reg( R_EAX, Rn );
  1838                                 SHR_imm8_r32( 16, R_EAX );
  1839                                 store_reg( R_EAX, Rn );
  1840                                 sh4_x86.tstate = TSTATE_NONE;
  1842                                 break;
  1843                             default:
  1844                                 UNDEF();
  1845                                 break;
  1847                         break;
  1848                     case 0xA:
  1849                         switch( (ir&0xF0) >> 4 ) {
  1850                             case 0x0:
  1851                                 { /* LDS Rm, MACH */
  1852                                 uint32_t Rm = ((ir>>8)&0xF); 
  1853                                 load_reg( R_EAX, Rm );
  1854                                 store_spreg( R_EAX, R_MACH );
  1856                                 break;
  1857                             case 0x1:
  1858                                 { /* LDS Rm, MACL */
  1859                                 uint32_t Rm = ((ir>>8)&0xF); 
  1860                                 load_reg( R_EAX, Rm );
  1861                                 store_spreg( R_EAX, R_MACL );
  1863                                 break;
  1864                             case 0x2:
  1865                                 { /* LDS Rm, PR */
  1866                                 uint32_t Rm = ((ir>>8)&0xF); 
  1867                                 load_reg( R_EAX, Rm );
  1868                                 store_spreg( R_EAX, R_PR );
  1870                                 break;
  1871                             case 0x3:
  1872                                 { /* LDC Rm, SGR */
  1873                                 uint32_t Rm = ((ir>>8)&0xF); 
  1874                                 check_priv();
  1875                                 load_reg( R_EAX, Rm );
  1876                                 store_spreg( R_EAX, R_SGR );
  1877                                 sh4_x86.tstate = TSTATE_NONE;
  1879                                 break;
  1880                             case 0x5:
  1881                                 { /* LDS Rm, FPUL */
  1882                                 uint32_t Rm = ((ir>>8)&0xF); 
  1883                                 load_reg( R_EAX, Rm );
  1884                                 store_spreg( R_EAX, R_FPUL );
  1886                                 break;
  1887                             case 0x6:
  1888                                 { /* LDS Rm, FPSCR */
  1889                                 uint32_t Rm = ((ir>>8)&0xF); 
  1890                                 load_reg( R_EAX, Rm );
  1891                                 store_spreg( R_EAX, R_FPSCR );
  1892                                 update_fr_bank( R_EAX );
  1893                                 sh4_x86.tstate = TSTATE_NONE;
  1895                                 break;
  1896                             case 0xF:
  1897                                 { /* LDC Rm, DBR */
  1898                                 uint32_t Rm = ((ir>>8)&0xF); 
  1899                                 check_priv();
  1900                                 load_reg( R_EAX, Rm );
  1901                                 store_spreg( R_EAX, R_DBR );
  1902                                 sh4_x86.tstate = TSTATE_NONE;
  1904                                 break;
  1905                             default:
  1906                                 UNDEF();
  1907                                 break;
  1909                         break;
  1910                     case 0xB:
  1911                         switch( (ir&0xF0) >> 4 ) {
  1912                             case 0x0:
  1913                                 { /* JSR @Rn */
  1914                                 uint32_t Rn = ((ir>>8)&0xF); 
  1915                                 if( sh4_x86.in_delay_slot ) {
  1916                             	SLOTILLEGAL();
  1917                                 } else {
  1918                             	load_imm32( R_EAX, pc + 4 );
  1919                             	store_spreg( R_EAX, R_PR );
  1920                             	load_reg( R_ECX, Rn );
  1921                             	store_spreg( R_ECX, REG_OFFSET(pc) );
  1922                             	sh4_x86.in_delay_slot = TRUE;
  1923                             	sh4_translate_instruction(pc+2);
  1924                             	exit_block_pcset(pc+2);
  1925                             	sh4_x86.branch_taken = TRUE;
  1926                             	return 4;
  1929                                 break;
  1930                             case 0x1:
  1931                                 { /* TAS.B @Rn */
  1932                                 uint32_t Rn = ((ir>>8)&0xF); 
  1933                                 load_reg( R_ECX, Rn );
  1934                                 MEM_READ_BYTE( R_ECX, R_EAX );
  1935                                 TEST_r8_r8( R_AL, R_AL );
  1936                                 SETE_t();
  1937                                 OR_imm8_r8( 0x80, R_AL );
  1938                                 load_reg( R_ECX, Rn );
  1939                                 MEM_WRITE_BYTE( R_ECX, R_EAX );
  1940                                 sh4_x86.tstate = TSTATE_NONE;
  1942                                 break;
  1943                             case 0x2:
  1944                                 { /* JMP @Rn */
  1945                                 uint32_t Rn = ((ir>>8)&0xF); 
  1946                                 if( sh4_x86.in_delay_slot ) {
  1947                             	SLOTILLEGAL();
  1948                                 } else {
  1949                             	load_reg( R_ECX, Rn );
  1950                             	store_spreg( R_ECX, REG_OFFSET(pc) );
  1951                             	sh4_x86.in_delay_slot = TRUE;
  1952                             	sh4_translate_instruction(pc+2);
  1953                             	exit_block_pcset(pc+2);
  1954                             	sh4_x86.branch_taken = TRUE;
  1955                             	return 4;
  1958                                 break;
  1959                             default:
  1960                                 UNDEF();
  1961                                 break;
  1963                         break;
  1964                     case 0xC:
  1965                         { /* SHAD Rm, Rn */
  1966                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1967                         /* Annoyingly enough, not directly convertible */
  1968                         load_reg( R_EAX, Rn );
  1969                         load_reg( R_ECX, Rm );
  1970                         CMP_imm32_r32( 0, R_ECX );
  1971                         JGE_rel8(16, doshl);
  1973                         NEG_r32( R_ECX );      // 2
  1974                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1975                         JE_rel8( 4, emptysar);     // 2
  1976                         SAR_r32_CL( R_EAX );       // 2
  1977                         JMP_rel8(10, end);          // 2
  1979                         JMP_TARGET(emptysar);
  1980                         SAR_imm8_r32(31, R_EAX );  // 3
  1981                         JMP_rel8(5, end2);
  1983                         JMP_TARGET(doshl);
  1984                         AND_imm8_r8( 0x1F, R_CL ); // 3
  1985                         SHL_r32_CL( R_EAX );       // 2
  1986                         JMP_TARGET(end);
  1987                         JMP_TARGET(end2);
  1988                         store_reg( R_EAX, Rn );
  1989                         sh4_x86.tstate = TSTATE_NONE;
  1991                         break;
  1992                     case 0xD:
  1993                         { /* SHLD Rm, Rn */
  1994                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  1995                         load_reg( R_EAX, Rn );
  1996                         load_reg( R_ECX, Rm );
  1997                         CMP_imm32_r32( 0, R_ECX );
  1998                         JGE_rel8(15, doshl);
  2000                         NEG_r32( R_ECX );      // 2
  2001                         AND_imm8_r8( 0x1F, R_CL ); // 3
  2002                         JE_rel8( 4, emptyshr );
  2003                         SHR_r32_CL( R_EAX );       // 2
  2004                         JMP_rel8(9, end);          // 2
  2006                         JMP_TARGET(emptyshr);
  2007                         XOR_r32_r32( R_EAX, R_EAX );
  2008                         JMP_rel8(5, end2);
  2010                         JMP_TARGET(doshl);
  2011                         AND_imm8_r8( 0x1F, R_CL ); // 3
  2012                         SHL_r32_CL( R_EAX );       // 2
  2013                         JMP_TARGET(end);
  2014                         JMP_TARGET(end2);
  2015                         store_reg( R_EAX, Rn );
  2016                         sh4_x86.tstate = TSTATE_NONE;
  2018                         break;
  2019                     case 0xE:
  2020                         switch( (ir&0x80) >> 7 ) {
  2021                             case 0x0:
  2022                                 switch( (ir&0x70) >> 4 ) {
  2023                                     case 0x0:
  2024                                         { /* LDC Rm, SR */
  2025                                         uint32_t Rm = ((ir>>8)&0xF); 
  2026                                         if( sh4_x86.in_delay_slot ) {
  2027                                     	SLOTILLEGAL();
  2028                                         } else {
  2029                                     	check_priv();
  2030                                     	load_reg( R_EAX, Rm );
  2031                                     	call_func1( sh4_write_sr, R_EAX );
  2032                                     	sh4_x86.priv_checked = FALSE;
  2033                                     	sh4_x86.fpuen_checked = FALSE;
  2034                                     	sh4_x86.tstate = TSTATE_NONE;
  2037                                         break;
  2038                                     case 0x1:
  2039                                         { /* LDC Rm, GBR */
  2040                                         uint32_t Rm = ((ir>>8)&0xF); 
  2041                                         load_reg( R_EAX, Rm );
  2042                                         store_spreg( R_EAX, R_GBR );
  2044                                         break;
  2045                                     case 0x2:
  2046                                         { /* LDC Rm, VBR */
  2047                                         uint32_t Rm = ((ir>>8)&0xF); 
  2048                                         check_priv();
  2049                                         load_reg( R_EAX, Rm );
  2050                                         store_spreg( R_EAX, R_VBR );
  2051                                         sh4_x86.tstate = TSTATE_NONE;
  2053                                         break;
  2054                                     case 0x3:
  2055                                         { /* LDC Rm, SSR */
  2056                                         uint32_t Rm = ((ir>>8)&0xF); 
  2057                                         check_priv();
  2058                                         load_reg( R_EAX, Rm );
  2059                                         store_spreg( R_EAX, R_SSR );
  2060                                         sh4_x86.tstate = TSTATE_NONE;
  2062                                         break;
  2063                                     case 0x4:
  2064                                         { /* LDC Rm, SPC */
  2065                                         uint32_t Rm = ((ir>>8)&0xF); 
  2066                                         check_priv();
  2067                                         load_reg( R_EAX, Rm );
  2068                                         store_spreg( R_EAX, R_SPC );
  2069                                         sh4_x86.tstate = TSTATE_NONE;
  2071                                         break;
  2072                                     default:
  2073                                         UNDEF();
  2074                                         break;
  2076                                 break;
  2077                             case 0x1:
  2078                                 { /* LDC Rm, Rn_BANK */
  2079                                 uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
  2080                                 check_priv();
  2081                                 load_reg( R_EAX, Rm );
  2082                                 store_spreg( R_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
  2083                                 sh4_x86.tstate = TSTATE_NONE;
  2085                                 break;
  2087                         break;
  2088                     case 0xF:
  2089                         { /* MAC.W @Rm+, @Rn+ */
  2090                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2091                         load_reg( R_ECX, Rm );
  2092                         precheck();
  2093                         check_ralign16( R_ECX );
  2094                         load_reg( R_ECX, Rn );
  2095                         check_ralign16( R_ECX );
  2096                         ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rn]) );
  2097                         MEM_READ_WORD( R_ECX, R_EAX );
  2098                         PUSH_realigned_r32( R_EAX );
  2099                         load_reg( R_ECX, Rm );
  2100                         ADD_imm8s_sh4r( 2, REG_OFFSET(r[Rm]) );
  2101                         MEM_READ_WORD( R_ECX, R_EAX );
  2102                         POP_realigned_r32( R_ECX );
  2103                         IMUL_r32( R_ECX );
  2105                         load_spreg( R_ECX, R_S );
  2106                         TEST_r32_r32( R_ECX, R_ECX );
  2107                         JE_rel8( 47, nosat );
  2109                         ADD_r32_sh4r( R_EAX, R_MACL );  // 6
  2110                         JNO_rel8( 51, end );            // 2
  2111                         load_imm32( R_EDX, 1 );         // 5
  2112                         store_spreg( R_EDX, R_MACH );   // 6
  2113                         JS_rel8( 13, positive );        // 2
  2114                         load_imm32( R_EAX, 0x80000000 );// 5
  2115                         store_spreg( R_EAX, R_MACL );   // 6
  2116                         JMP_rel8( 25, end2 );           // 2
  2118                         JMP_TARGET(positive);
  2119                         load_imm32( R_EAX, 0x7FFFFFFF );// 5
  2120                         store_spreg( R_EAX, R_MACL );   // 6
  2121                         JMP_rel8( 12, end3);            // 2
  2123                         JMP_TARGET(nosat);
  2124                         ADD_r32_sh4r( R_EAX, R_MACL );  // 6
  2125                         ADC_r32_sh4r( R_EDX, R_MACH );  // 6
  2126                         JMP_TARGET(end);
  2127                         JMP_TARGET(end2);
  2128                         JMP_TARGET(end3);
  2129                         sh4_x86.tstate = TSTATE_NONE;
  2131                         break;
  2133                 break;
  2134             case 0x5:
  2135                 { /* MOV.L @(disp, Rm), Rn */
  2136                 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
  2137                 load_reg( R_ECX, Rm );
  2138                 ADD_imm8s_r32( disp, R_ECX );
  2139                 precheck();
  2140                 check_ralign32( R_ECX );
  2141                 MEM_READ_LONG( R_ECX, R_EAX );
  2142                 store_reg( R_EAX, Rn );
  2143                 sh4_x86.tstate = TSTATE_NONE;
  2145                 break;
  2146             case 0x6:
  2147                 switch( ir&0xF ) {
  2148                     case 0x0:
  2149                         { /* MOV.B @Rm, Rn */
  2150                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2151                         load_reg( R_ECX, Rm );
  2152                         MEM_READ_BYTE( R_ECX, R_EAX );
  2153                         store_reg( R_EAX, Rn );
  2154                         sh4_x86.tstate = TSTATE_NONE;
  2156                         break;
  2157                     case 0x1:
  2158                         { /* MOV.W @Rm, Rn */
  2159                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2160                         load_reg( R_ECX, Rm );
  2161                         precheck();
  2162                         check_ralign16( R_ECX );
  2163                         MEM_READ_WORD( R_ECX, R_EAX );
  2164                         store_reg( R_EAX, Rn );
  2165                         sh4_x86.tstate = TSTATE_NONE;
  2167                         break;
  2168                     case 0x2:
  2169                         { /* MOV.L @Rm, Rn */
  2170                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2171                         load_reg( R_ECX, Rm );
  2172                         precheck();
  2173                         check_ralign32( R_ECX );
  2174                         MEM_READ_LONG( R_ECX, R_EAX );
  2175                         store_reg( R_EAX, Rn );
  2176                         sh4_x86.tstate = TSTATE_NONE;
  2178                         break;
  2179                     case 0x3:
  2180                         { /* MOV Rm, Rn */
  2181                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2182                         load_reg( R_EAX, Rm );
  2183                         store_reg( R_EAX, Rn );
  2185                         break;
  2186                     case 0x4:
  2187                         { /* MOV.B @Rm+, Rn */
  2188                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2189                         load_reg( R_ECX, Rm );
  2190                         MOV_r32_r32( R_ECX, R_EAX );
  2191                         ADD_imm8s_r32( 1, R_EAX );
  2192                         store_reg( R_EAX, Rm );
  2193                         MEM_READ_BYTE( R_ECX, R_EAX );
  2194                         store_reg( R_EAX, Rn );
  2195                         sh4_x86.tstate = TSTATE_NONE;
  2197                         break;
  2198                     case 0x5:
  2199                         { /* MOV.W @Rm+, Rn */
  2200                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2201                         load_reg( R_EAX, Rm );
  2202                         precheck();
  2203                         check_ralign16( R_EAX );
  2204                         MOV_r32_r32( R_EAX, R_ECX );
  2205                         ADD_imm8s_r32( 2, R_EAX );
  2206                         store_reg( R_EAX, Rm );
  2207                         MEM_READ_WORD( R_ECX, R_EAX );
  2208                         store_reg( R_EAX, Rn );
  2209                         sh4_x86.tstate = TSTATE_NONE;
  2211                         break;
  2212                     case 0x6:
  2213                         { /* MOV.L @Rm+, Rn */
  2214                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2215                         load_reg( R_EAX, Rm );
  2216                         precheck();
  2217                         check_ralign32( R_EAX );
  2218                         MOV_r32_r32( R_EAX, R_ECX );
  2219                         ADD_imm8s_r32( 4, R_EAX );
  2220                         store_reg( R_EAX, Rm );
  2221                         MEM_READ_LONG( R_ECX, R_EAX );
  2222                         store_reg( R_EAX, Rn );
  2223                         sh4_x86.tstate = TSTATE_NONE;
  2225                         break;
  2226                     case 0x7:
  2227                         { /* NOT Rm, Rn */
  2228                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2229                         load_reg( R_EAX, Rm );
  2230                         NOT_r32( R_EAX );
  2231                         store_reg( R_EAX, Rn );
  2232                         sh4_x86.tstate = TSTATE_NONE;
  2234                         break;
  2235                     case 0x8:
  2236                         { /* SWAP.B Rm, Rn */
  2237                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2238                         load_reg( R_EAX, Rm );
  2239                         XCHG_r8_r8( R_AL, R_AH );
  2240                         store_reg( R_EAX, Rn );
  2242                         break;
  2243                     case 0x9:
  2244                         { /* SWAP.W Rm, Rn */
  2245                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2246                         load_reg( R_EAX, Rm );
  2247                         MOV_r32_r32( R_EAX, R_ECX );
  2248                         SHL_imm8_r32( 16, R_ECX );
  2249                         SHR_imm8_r32( 16, R_EAX );
  2250                         OR_r32_r32( R_EAX, R_ECX );
  2251                         store_reg( R_ECX, Rn );
  2252                         sh4_x86.tstate = TSTATE_NONE;
  2254                         break;
  2255                     case 0xA:
  2256                         { /* NEGC Rm, Rn */
  2257                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2258                         load_reg( R_EAX, Rm );
  2259                         XOR_r32_r32( R_ECX, R_ECX );
  2260                         LDC_t();
  2261                         SBB_r32_r32( R_EAX, R_ECX );
  2262                         store_reg( R_ECX, Rn );
  2263                         SETC_t();
  2264                         sh4_x86.tstate = TSTATE_C;
  2266                         break;
  2267                     case 0xB:
  2268                         { /* NEG Rm, Rn */
  2269                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2270                         load_reg( R_EAX, Rm );
  2271                         NEG_r32( R_EAX );
  2272                         store_reg( R_EAX, Rn );
  2273                         sh4_x86.tstate = TSTATE_NONE;
  2275                         break;
  2276                     case 0xC:
  2277                         { /* EXTU.B Rm, Rn */
  2278                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2279                         load_reg( R_EAX, Rm );
  2280                         MOVZX_r8_r32( R_EAX, R_EAX );
  2281                         store_reg( R_EAX, Rn );
  2283                         break;
  2284                     case 0xD:
  2285                         { /* EXTU.W Rm, Rn */
  2286                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2287                         load_reg( R_EAX, Rm );
  2288                         MOVZX_r16_r32( R_EAX, R_EAX );
  2289                         store_reg( R_EAX, Rn );
  2291                         break;
  2292                     case 0xE:
  2293                         { /* EXTS.B Rm, Rn */
  2294                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2295                         load_reg( R_EAX, Rm );
  2296                         MOVSX_r8_r32( R_EAX, R_EAX );
  2297                         store_reg( R_EAX, Rn );
  2299                         break;
  2300                     case 0xF:
  2301                         { /* EXTS.W Rm, Rn */
  2302                         uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2303                         load_reg( R_EAX, Rm );
  2304                         MOVSX_r16_r32( R_EAX, R_EAX );
  2305                         store_reg( R_EAX, Rn );
  2307                         break;
  2309                 break;
  2310             case 0x7:
  2311                 { /* ADD #imm, Rn */
  2312                 uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
  2313                 load_reg( R_EAX, Rn );
  2314                 ADD_imm8s_r32( imm, R_EAX );
  2315                 store_reg( R_EAX, Rn );
  2316                 sh4_x86.tstate = TSTATE_NONE;
  2318                 break;
  2319             case 0x8:
  2320                 switch( (ir&0xF00) >> 8 ) {
  2321                     case 0x0:
  2322                         { /* MOV.B R0, @(disp, Rn) */
  2323                         uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
  2324                         load_reg( R_EAX, 0 );
  2325                         load_reg( R_ECX, Rn );
  2326                         ADD_imm32_r32( disp, R_ECX );
  2327                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2328                         sh4_x86.tstate = TSTATE_NONE;
  2330                         break;
  2331                     case 0x1:
  2332                         { /* MOV.W R0, @(disp, Rn) */
  2333                         uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
  2334                         load_reg( R_ECX, Rn );
  2335                         load_reg( R_EAX, 0 );
  2336                         ADD_imm32_r32( disp, R_ECX );
  2337                         precheck();
  2338                         check_walign16( R_ECX );
  2339                         MEM_WRITE_WORD( R_ECX, R_EAX );
  2340                         sh4_x86.tstate = TSTATE_NONE;
  2342                         break;
  2343                     case 0x4:
  2344                         { /* MOV.B @(disp, Rm), R0 */
  2345                         uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
  2346                         load_reg( R_ECX, Rm );
  2347                         ADD_imm32_r32( disp, R_ECX );
  2348                         MEM_READ_BYTE( R_ECX, R_EAX );
  2349                         store_reg( R_EAX, 0 );
  2350                         sh4_x86.tstate = TSTATE_NONE;
  2352                         break;
  2353                     case 0x5:
  2354                         { /* MOV.W @(disp, Rm), R0 */
  2355                         uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
  2356                         load_reg( R_ECX, Rm );
  2357                         ADD_imm32_r32( disp, R_ECX );
  2358                         precheck();
  2359                         check_ralign16( R_ECX );
  2360                         MEM_READ_WORD( R_ECX, R_EAX );
  2361                         store_reg( R_EAX, 0 );
  2362                         sh4_x86.tstate = TSTATE_NONE;
  2364                         break;
  2365                     case 0x8:
  2366                         { /* CMP/EQ #imm, R0 */
  2367                         int32_t imm = SIGNEXT8(ir&0xFF); 
  2368                         load_reg( R_EAX, 0 );
  2369                         CMP_imm8s_r32(imm, R_EAX);
  2370                         SETE_t();
  2371                         sh4_x86.tstate = TSTATE_E;
  2373                         break;
  2374                     case 0x9:
  2375                         { /* BT disp */
  2376                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2377                         if( sh4_x86.in_delay_slot ) {
  2378                     	SLOTILLEGAL();
  2379                         } else {
  2380                     	JF_rel8( EXIT_BLOCK_SIZE, nottaken );
  2381                     	exit_block( disp + pc + 4, pc+2 );
  2382                     	JMP_TARGET(nottaken);
  2383                     	return 2;
  2386                         break;
  2387                     case 0xB:
  2388                         { /* BF disp */
  2389                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2390                         if( sh4_x86.in_delay_slot ) {
  2391                     	SLOTILLEGAL();
  2392                         } else {
  2393                     	JT_rel8( EXIT_BLOCK_SIZE, nottaken );
  2394                     	exit_block( disp + pc + 4, pc+2 );
  2395                     	JMP_TARGET(nottaken);
  2396                     	return 2;
  2399                         break;
  2400                     case 0xD:
  2401                         { /* BT/S disp */
  2402                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2403                         if( sh4_x86.in_delay_slot ) {
  2404                     	SLOTILLEGAL();
  2405                         } else {
  2406                     	sh4_x86.in_delay_slot = TRUE;
  2407                     	if( sh4_x86.tstate == TSTATE_NONE ) {
  2408                     	    CMP_imm8s_sh4r( 1, R_T );
  2409                     	    sh4_x86.tstate = TSTATE_E;
  2411                     	OP(0x0F); OP(0x80+(sh4_x86.tstate^1)); uint32_t *patch = (uint32_t *)xlat_output; OP32(0); // JE rel32
  2412                     	sh4_translate_instruction(pc+2);
  2413                     	exit_block( disp + pc + 4, pc+4 );
  2414                     	// not taken
  2415                     	*patch = (xlat_output - ((uint8_t *)patch)) - 4;
  2416                     	sh4_translate_instruction(pc+2);
  2417                     	return 4;
  2420                         break;
  2421                     case 0xF:
  2422                         { /* BF/S disp */
  2423                         int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
  2424                         if( sh4_x86.in_delay_slot ) {
  2425                     	SLOTILLEGAL();
  2426                         } else {
  2427                     	sh4_x86.in_delay_slot = TRUE;
  2428                     	if( sh4_x86.tstate == TSTATE_NONE ) {
  2429                     	    CMP_imm8s_sh4r( 1, R_T );
  2430                     	    sh4_x86.tstate = TSTATE_E;
  2432                     	OP(0x0F); OP(0x80+sh4_x86.tstate); uint32_t *patch = (uint32_t *)xlat_output; OP32(0); // JNE rel32
  2433                     	sh4_translate_instruction(pc+2);
  2434                     	exit_block( disp + pc + 4, pc+4 );
  2435                     	// not taken
  2436                     	*patch = (xlat_output - ((uint8_t *)patch)) - 4;
  2437                     	sh4_translate_instruction(pc+2);
  2438                     	return 4;
  2441                         break;
  2442                     default:
  2443                         UNDEF();
  2444                         break;
  2446                 break;
  2447             case 0x9:
  2448                 { /* MOV.W @(disp, PC), Rn */
  2449                 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<1; 
  2450                 if( sh4_x86.in_delay_slot ) {
  2451             	SLOTILLEGAL();
  2452                 } else {
  2453             	load_imm32( R_ECX, pc + disp + 4 );
  2454             	MEM_READ_WORD( R_ECX, R_EAX );
  2455             	store_reg( R_EAX, Rn );
  2456             	sh4_x86.tstate = TSTATE_NONE;
  2459                 break;
  2460             case 0xA:
  2461                 { /* BRA disp */
  2462                 int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
  2463                 if( sh4_x86.in_delay_slot ) {
  2464             	SLOTILLEGAL();
  2465                 } else {
  2466             	sh4_x86.in_delay_slot = TRUE;
  2467             	sh4_translate_instruction( pc + 2 );
  2468             	exit_block( disp + pc + 4, pc+4 );
  2469             	sh4_x86.branch_taken = TRUE;
  2470             	return 4;
  2473                 break;
  2474             case 0xB:
  2475                 { /* BSR disp */
  2476                 int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
  2477                 if( sh4_x86.in_delay_slot ) {
  2478             	SLOTILLEGAL();
  2479                 } else {
  2480             	load_imm32( R_EAX, pc + 4 );
  2481             	store_spreg( R_EAX, R_PR );
  2482             	sh4_x86.in_delay_slot = TRUE;
  2483             	sh4_translate_instruction( pc + 2 );
  2484             	exit_block( disp + pc + 4, pc+4 );
  2485             	sh4_x86.branch_taken = TRUE;
  2486             	return 4;
  2489                 break;
  2490             case 0xC:
  2491                 switch( (ir&0xF00) >> 8 ) {
  2492                     case 0x0:
  2493                         { /* MOV.B R0, @(disp, GBR) */
  2494                         uint32_t disp = (ir&0xFF); 
  2495                         load_reg( R_EAX, 0 );
  2496                         load_spreg( R_ECX, R_GBR );
  2497                         ADD_imm32_r32( disp, R_ECX );
  2498                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2499                         sh4_x86.tstate = TSTATE_NONE;
  2501                         break;
  2502                     case 0x1:
  2503                         { /* MOV.W R0, @(disp, GBR) */
  2504                         uint32_t disp = (ir&0xFF)<<1; 
  2505                         load_spreg( R_ECX, R_GBR );
  2506                         load_reg( R_EAX, 0 );
  2507                         ADD_imm32_r32( disp, R_ECX );
  2508                         precheck();
  2509                         check_walign16( R_ECX );
  2510                         MEM_WRITE_WORD( R_ECX, R_EAX );
  2511                         sh4_x86.tstate = TSTATE_NONE;
  2513                         break;
  2514                     case 0x2:
  2515                         { /* MOV.L R0, @(disp, GBR) */
  2516                         uint32_t disp = (ir&0xFF)<<2; 
  2517                         load_spreg( R_ECX, R_GBR );
  2518                         load_reg( R_EAX, 0 );
  2519                         ADD_imm32_r32( disp, R_ECX );
  2520                         precheck();
  2521                         check_walign32( R_ECX );
  2522                         MEM_WRITE_LONG( R_ECX, R_EAX );
  2523                         sh4_x86.tstate = TSTATE_NONE;
  2525                         break;
  2526                     case 0x3:
  2527                         { /* TRAPA #imm */
  2528                         uint32_t imm = (ir&0xFF); 
  2529                         if( sh4_x86.in_delay_slot ) {
  2530                     	SLOTILLEGAL();
  2531                         } else {
  2532                     	load_imm32( R_ECX, pc+2 );
  2533                     	store_spreg( R_ECX, REG_OFFSET(pc) );
  2534                     	load_imm32( R_EAX, imm );
  2535                     	call_func1( sh4_raise_trap, R_EAX );
  2536                     	sh4_x86.tstate = TSTATE_NONE;
  2537                     	exit_block_pcset(pc);
  2538                     	sh4_x86.branch_taken = TRUE;
  2539                     	return 2;
  2542                         break;
  2543                     case 0x4:
  2544                         { /* MOV.B @(disp, GBR), R0 */
  2545                         uint32_t disp = (ir&0xFF); 
  2546                         load_spreg( R_ECX, R_GBR );
  2547                         ADD_imm32_r32( disp, R_ECX );
  2548                         MEM_READ_BYTE( R_ECX, R_EAX );
  2549                         store_reg( R_EAX, 0 );
  2550                         sh4_x86.tstate = TSTATE_NONE;
  2552                         break;
  2553                     case 0x5:
  2554                         { /* MOV.W @(disp, GBR), R0 */
  2555                         uint32_t disp = (ir&0xFF)<<1; 
  2556                         load_spreg( R_ECX, R_GBR );
  2557                         ADD_imm32_r32( disp, R_ECX );
  2558                         precheck();
  2559                         check_ralign16( R_ECX );
  2560                         MEM_READ_WORD( R_ECX, R_EAX );
  2561                         store_reg( R_EAX, 0 );
  2562                         sh4_x86.tstate = TSTATE_NONE;
  2564                         break;
  2565                     case 0x6:
  2566                         { /* MOV.L @(disp, GBR), R0 */
  2567                         uint32_t disp = (ir&0xFF)<<2; 
  2568                         load_spreg( R_ECX, R_GBR );
  2569                         ADD_imm32_r32( disp, R_ECX );
  2570                         precheck();
  2571                         check_ralign32( R_ECX );
  2572                         MEM_READ_LONG( R_ECX, R_EAX );
  2573                         store_reg( R_EAX, 0 );
  2574                         sh4_x86.tstate = TSTATE_NONE;
  2576                         break;
  2577                     case 0x7:
  2578                         { /* MOVA @(disp, PC), R0 */
  2579                         uint32_t disp = (ir&0xFF)<<2; 
  2580                         if( sh4_x86.in_delay_slot ) {
  2581                     	SLOTILLEGAL();
  2582                         } else {
  2583                     	load_imm32( R_ECX, (pc & 0xFFFFFFFC) + disp + 4 );
  2584                     	store_reg( R_ECX, 0 );
  2587                         break;
  2588                     case 0x8:
  2589                         { /* TST #imm, R0 */
  2590                         uint32_t imm = (ir&0xFF); 
  2591                         load_reg( R_EAX, 0 );
  2592                         TEST_imm32_r32( imm, R_EAX );
  2593                         SETE_t();
  2594                         sh4_x86.tstate = TSTATE_E;
  2596                         break;
  2597                     case 0x9:
  2598                         { /* AND #imm, R0 */
  2599                         uint32_t imm = (ir&0xFF); 
  2600                         load_reg( R_EAX, 0 );
  2601                         AND_imm32_r32(imm, R_EAX); 
  2602                         store_reg( R_EAX, 0 );
  2603                         sh4_x86.tstate = TSTATE_NONE;
  2605                         break;
  2606                     case 0xA:
  2607                         { /* XOR #imm, R0 */
  2608                         uint32_t imm = (ir&0xFF); 
  2609                         load_reg( R_EAX, 0 );
  2610                         XOR_imm32_r32( imm, R_EAX );
  2611                         store_reg( R_EAX, 0 );
  2612                         sh4_x86.tstate = TSTATE_NONE;
  2614                         break;
  2615                     case 0xB:
  2616                         { /* OR #imm, R0 */
  2617                         uint32_t imm = (ir&0xFF); 
  2618                         load_reg( R_EAX, 0 );
  2619                         OR_imm32_r32(imm, R_EAX);
  2620                         store_reg( R_EAX, 0 );
  2621                         sh4_x86.tstate = TSTATE_NONE;
  2623                         break;
  2624                     case 0xC:
  2625                         { /* TST.B #imm, @(R0, GBR) */
  2626                         uint32_t imm = (ir&0xFF); 
  2627                         load_reg( R_EAX, 0);
  2628                         load_reg( R_ECX, R_GBR);
  2629                         ADD_r32_r32( R_EAX, R_ECX );
  2630                         MEM_READ_BYTE( R_ECX, R_EAX );
  2631                         TEST_imm8_r8( imm, R_AL );
  2632                         SETE_t();
  2633                         sh4_x86.tstate = TSTATE_E;
  2635                         break;
  2636                     case 0xD:
  2637                         { /* AND.B #imm, @(R0, GBR) */
  2638                         uint32_t imm = (ir&0xFF); 
  2639                         load_reg( R_EAX, 0 );
  2640                         load_spreg( R_ECX, R_GBR );
  2641                         ADD_r32_r32( R_EAX, R_ECX );
  2642                         PUSH_realigned_r32(R_ECX);
  2643                         MEM_READ_BYTE( R_ECX, R_EAX );
  2644                         POP_realigned_r32(R_ECX);
  2645                         AND_imm32_r32(imm, R_EAX );
  2646                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2647                         sh4_x86.tstate = TSTATE_NONE;
  2649                         break;
  2650                     case 0xE:
  2651                         { /* XOR.B #imm, @(R0, GBR) */
  2652                         uint32_t imm = (ir&0xFF); 
  2653                         load_reg( R_EAX, 0 );
  2654                         load_spreg( R_ECX, R_GBR );
  2655                         ADD_r32_r32( R_EAX, R_ECX );
  2656                         PUSH_realigned_r32(R_ECX);
  2657                         MEM_READ_BYTE(R_ECX, R_EAX);
  2658                         POP_realigned_r32(R_ECX);
  2659                         XOR_imm32_r32( imm, R_EAX );
  2660                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2661                         sh4_x86.tstate = TSTATE_NONE;
  2663                         break;
  2664                     case 0xF:
  2665                         { /* OR.B #imm, @(R0, GBR) */
  2666                         uint32_t imm = (ir&0xFF); 
  2667                         load_reg( R_EAX, 0 );
  2668                         load_spreg( R_ECX, R_GBR );
  2669                         ADD_r32_r32( R_EAX, R_ECX );
  2670                         PUSH_realigned_r32(R_ECX);
  2671                         MEM_READ_BYTE( R_ECX, R_EAX );
  2672                         POP_realigned_r32(R_ECX);
  2673                         OR_imm32_r32(imm, R_EAX );
  2674                         MEM_WRITE_BYTE( R_ECX, R_EAX );
  2675                         sh4_x86.tstate = TSTATE_NONE;
  2677                         break;
  2679                 break;
  2680             case 0xD:
  2681                 { /* MOV.L @(disp, PC), Rn */
  2682                 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<2; 
  2683                 if( sh4_x86.in_delay_slot ) {
  2684             	SLOTILLEGAL();
  2685                 } else {
  2686             	uint32_t target = (pc & 0xFFFFFFFC) + disp + 4;
  2687             	sh4ptr_t ptr = mem_get_region(target);
  2688             	if( ptr != NULL ) {
  2689             	    MOV_moff32_EAX( ptr );
  2690             	} else {
  2691             	    load_imm32( R_ECX, target );
  2692             	    MEM_READ_LONG( R_ECX, R_EAX );
  2694             	store_reg( R_EAX, Rn );
  2695             	sh4_x86.tstate = TSTATE_NONE;
  2698                 break;
  2699             case 0xE:
  2700                 { /* MOV #imm, Rn */
  2701                 uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
  2702                 load_imm32( R_EAX, imm );
  2703                 store_reg( R_EAX, Rn );
  2705                 break;
  2706             case 0xF:
  2707                 switch( ir&0xF ) {
  2708                     case 0x0:
  2709                         { /* FADD FRm, FRn */
  2710                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2711                         check_fpuen();
  2712                         load_spreg( R_ECX, R_FPSCR );
  2713                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2714                         load_fr_bank( R_EDX );
  2715                         JNE_rel8(13,doubleprec);
  2716                         push_fr(R_EDX, FRm);
  2717                         push_fr(R_EDX, FRn);
  2718                         FADDP_st(1);
  2719                         pop_fr(R_EDX, FRn);
  2720                         JMP_rel8(11,end);
  2721                         JMP_TARGET(doubleprec);
  2722                         push_dr(R_EDX, FRm);
  2723                         push_dr(R_EDX, FRn);
  2724                         FADDP_st(1);
  2725                         pop_dr(R_EDX, FRn);
  2726                         JMP_TARGET(end);
  2727                         sh4_x86.tstate = TSTATE_NONE;
  2729                         break;
  2730                     case 0x1:
  2731                         { /* FSUB FRm, FRn */
  2732                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2733                         check_fpuen();
  2734                         load_spreg( R_ECX, R_FPSCR );
  2735                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2736                         load_fr_bank( R_EDX );
  2737                         JNE_rel8(13, doubleprec);
  2738                         push_fr(R_EDX, FRn);
  2739                         push_fr(R_EDX, FRm);
  2740                         FSUBP_st(1);
  2741                         pop_fr(R_EDX, FRn);
  2742                         JMP_rel8(11, end);
  2743                         JMP_TARGET(doubleprec);
  2744                         push_dr(R_EDX, FRn);
  2745                         push_dr(R_EDX, FRm);
  2746                         FSUBP_st(1);
  2747                         pop_dr(R_EDX, FRn);
  2748                         JMP_TARGET(end);
  2749                         sh4_x86.tstate = TSTATE_NONE;
  2751                         break;
  2752                     case 0x2:
  2753                         { /* FMUL FRm, FRn */
  2754                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2755                         check_fpuen();
  2756                         load_spreg( R_ECX, R_FPSCR );
  2757                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2758                         load_fr_bank( R_EDX );
  2759                         JNE_rel8(13, doubleprec);
  2760                         push_fr(R_EDX, FRm);
  2761                         push_fr(R_EDX, FRn);
  2762                         FMULP_st(1);
  2763                         pop_fr(R_EDX, FRn);
  2764                         JMP_rel8(11, end);
  2765                         JMP_TARGET(doubleprec);
  2766                         push_dr(R_EDX, FRm);
  2767                         push_dr(R_EDX, FRn);
  2768                         FMULP_st(1);
  2769                         pop_dr(R_EDX, FRn);
  2770                         JMP_TARGET(end);
  2771                         sh4_x86.tstate = TSTATE_NONE;
  2773                         break;
  2774                     case 0x3:
  2775                         { /* FDIV FRm, FRn */
  2776                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2777                         check_fpuen();
  2778                         load_spreg( R_ECX, R_FPSCR );
  2779                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2780                         load_fr_bank( R_EDX );
  2781                         JNE_rel8(13, doubleprec);
  2782                         push_fr(R_EDX, FRn);
  2783                         push_fr(R_EDX, FRm);
  2784                         FDIVP_st(1);
  2785                         pop_fr(R_EDX, FRn);
  2786                         JMP_rel8(11, end);
  2787                         JMP_TARGET(doubleprec);
  2788                         push_dr(R_EDX, FRn);
  2789                         push_dr(R_EDX, FRm);
  2790                         FDIVP_st(1);
  2791                         pop_dr(R_EDX, FRn);
  2792                         JMP_TARGET(end);
  2793                         sh4_x86.tstate = TSTATE_NONE;
  2795                         break;
  2796                     case 0x4:
  2797                         { /* FCMP/EQ FRm, FRn */
  2798                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2799                         check_fpuen();
  2800                         load_spreg( R_ECX, R_FPSCR );
  2801                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2802                         load_fr_bank( R_EDX );
  2803                         JNE_rel8(8, doubleprec);
  2804                         push_fr(R_EDX, FRm);
  2805                         push_fr(R_EDX, FRn);
  2806                         JMP_rel8(6, end);
  2807                         JMP_TARGET(doubleprec);
  2808                         push_dr(R_EDX, FRm);
  2809                         push_dr(R_EDX, FRn);
  2810                         JMP_TARGET(end);
  2811                         FCOMIP_st(1);
  2812                         SETE_t();
  2813                         FPOP_st();
  2814                         sh4_x86.tstate = TSTATE_NONE;
  2816                         break;
  2817                     case 0x5:
  2818                         { /* FCMP/GT FRm, FRn */
  2819                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2820                         check_fpuen();
  2821                         load_spreg( R_ECX, R_FPSCR );
  2822                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  2823                         load_fr_bank( R_EDX );
  2824                         JNE_rel8(8, doubleprec);
  2825                         push_fr(R_EDX, FRm);
  2826                         push_fr(R_EDX, FRn);
  2827                         JMP_rel8(6, end);
  2828                         JMP_TARGET(doubleprec);
  2829                         push_dr(R_EDX, FRm);
  2830                         push_dr(R_EDX, FRn);
  2831                         JMP_TARGET(end);
  2832                         FCOMIP_st(1);
  2833                         SETA_t();
  2834                         FPOP_st();
  2835                         sh4_x86.tstate = TSTATE_NONE;
  2837                         break;
  2838                     case 0x6:
  2839                         { /* FMOV @(R0, Rm), FRn */
  2840                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2841                         precheck();
  2842                         check_fpuen_no_precheck();
  2843                         load_reg( R_ECX, Rm );
  2844                         ADD_sh4r_r32( REG_OFFSET(r[0]), R_ECX );
  2845                         check_ralign32( R_ECX );
  2846                         load_spreg( R_EDX, R_FPSCR );
  2847                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  2848                         JNE_rel8(8 + CALL_FUNC1_SIZE, doublesize);
  2849                         MEM_READ_LONG( R_ECX, R_EAX );
  2850                         load_fr_bank( R_EDX );
  2851                         store_fr( R_EDX, R_EAX, FRn );
  2852                         if( FRn&1 ) {
  2853                     	JMP_rel8(21 + MEM_READ_DOUBLE_SIZE, end);
  2854                     	JMP_TARGET(doublesize);
  2855                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2856                     	load_spreg( R_EDX, R_FPSCR ); // assume read_long clobbered it
  2857                     	load_xf_bank( R_EDX );
  2858                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2859                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2860                     	JMP_TARGET(end);
  2861                         } else {
  2862                     	JMP_rel8(9 + MEM_READ_DOUBLE_SIZE, end);
  2863                     	JMP_TARGET(doublesize);
  2864                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2865                     	load_fr_bank( R_EDX );
  2866                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2867                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2868                     	JMP_TARGET(end);
  2870                         sh4_x86.tstate = TSTATE_NONE;
  2872                         break;
  2873                     case 0x7:
  2874                         { /* FMOV FRm, @(R0, Rn) */
  2875                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2876                         precheck();
  2877                         check_fpuen_no_precheck();
  2878                         load_reg( R_ECX, Rn );
  2879                         ADD_sh4r_r32( REG_OFFSET(r[0]), R_ECX );
  2880                         check_walign32( R_ECX );
  2881                         load_spreg( R_EDX, R_FPSCR );
  2882                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  2883                         JNE_rel8(8 + CALL_FUNC2_SIZE, doublesize);
  2884                         load_fr_bank( R_EDX );
  2885                         load_fr( R_EDX, R_EAX, FRm );
  2886                         MEM_WRITE_LONG( R_ECX, R_EAX ); // 12
  2887                         if( FRm&1 ) {
  2888                     	JMP_rel8( 18 + MEM_WRITE_DOUBLE_SIZE, end );
  2889                     	JMP_TARGET(doublesize);
  2890                     	load_xf_bank( R_EDX );
  2891                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  2892                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  2893                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  2894                     	JMP_TARGET(end);
  2895                         } else {
  2896                     	JMP_rel8( 9 + MEM_WRITE_DOUBLE_SIZE, end );
  2897                     	JMP_TARGET(doublesize);
  2898                     	load_fr_bank( R_EDX );
  2899                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  2900                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  2901                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  2902                     	JMP_TARGET(end);
  2904                         sh4_x86.tstate = TSTATE_NONE;
  2906                         break;
  2907                     case 0x8:
  2908                         { /* FMOV @Rm, FRn */
  2909                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2910                         precheck();
  2911                         check_fpuen_no_precheck();
  2912                         load_reg( R_ECX, Rm );
  2913                         check_ralign32( R_ECX );
  2914                         load_spreg( R_EDX, R_FPSCR );
  2915                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  2916                         JNE_rel8(8 + CALL_FUNC1_SIZE, doublesize);
  2917                         MEM_READ_LONG( R_ECX, R_EAX );
  2918                         load_fr_bank( R_EDX );
  2919                         store_fr( R_EDX, R_EAX, FRn );
  2920                         if( FRn&1 ) {
  2921                     	JMP_rel8(21 + MEM_READ_DOUBLE_SIZE, end);
  2922                     	JMP_TARGET(doublesize);
  2923                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2924                     	load_spreg( R_EDX, R_FPSCR ); // assume read_long clobbered it
  2925                     	load_xf_bank( R_EDX );
  2926                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2927                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2928                     	JMP_TARGET(end);
  2929                         } else {
  2930                     	JMP_rel8(9 + MEM_READ_DOUBLE_SIZE, end);
  2931                     	JMP_TARGET(doublesize);
  2932                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2933                     	load_fr_bank( R_EDX );
  2934                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2935                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2936                     	JMP_TARGET(end);
  2938                         sh4_x86.tstate = TSTATE_NONE;
  2940                         break;
  2941                     case 0x9:
  2942                         { /* FMOV @Rm+, FRn */
  2943                         uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
  2944                         precheck();
  2945                         check_fpuen_no_precheck();
  2946                         load_reg( R_ECX, Rm );
  2947                         check_ralign32( R_ECX );
  2948                         MOV_r32_r32( R_ECX, R_EAX );
  2949                         load_spreg( R_EDX, R_FPSCR );
  2950                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  2951                         JNE_rel8(14 + CALL_FUNC1_SIZE, doublesize);
  2952                         ADD_imm8s_r32( 4, R_EAX );
  2953                         store_reg( R_EAX, Rm );
  2954                         MEM_READ_LONG( R_ECX, R_EAX );
  2955                         load_fr_bank( R_EDX );
  2956                         store_fr( R_EDX, R_EAX, FRn );
  2957                         if( FRn&1 ) {
  2958                     	JMP_rel8(27 + MEM_READ_DOUBLE_SIZE, end);
  2959                     	JMP_TARGET(doublesize);
  2960                     	ADD_imm8s_r32( 8, R_EAX );
  2961                     	store_reg(R_EAX, Rm);
  2962                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2963                     	load_spreg( R_EDX, R_FPSCR ); // assume read_long clobbered it
  2964                     	load_xf_bank( R_EDX );
  2965                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2966                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2967                     	JMP_TARGET(end);
  2968                         } else {
  2969                     	JMP_rel8(15 + MEM_READ_DOUBLE_SIZE, end);
  2970                     	ADD_imm8s_r32( 8, R_EAX );
  2971                     	store_reg(R_EAX, Rm);
  2972                     	MEM_READ_DOUBLE( R_ECX, R_EAX, R_ECX );
  2973                     	load_fr_bank( R_EDX );
  2974                     	store_fr( R_EDX, R_EAX, FRn&0x0E );
  2975                     	store_fr( R_EDX, R_ECX, FRn|0x01 );
  2976                     	JMP_TARGET(end);
  2978                         sh4_x86.tstate = TSTATE_NONE;
  2980                         break;
  2981                     case 0xA:
  2982                         { /* FMOV FRm, @Rn */
  2983                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  2984                         precheck();
  2985                         check_fpuen_no_precheck();
  2986                         load_reg( R_ECX, Rn );
  2987                         check_walign32( R_ECX );
  2988                         load_spreg( R_EDX, R_FPSCR );
  2989                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  2990                         JNE_rel8(8 + CALL_FUNC2_SIZE, doublesize);
  2991                         load_fr_bank( R_EDX );
  2992                         load_fr( R_EDX, R_EAX, FRm );
  2993                         MEM_WRITE_LONG( R_ECX, R_EAX ); // 12
  2994                         if( FRm&1 ) {
  2995                     	JMP_rel8( 18 + MEM_WRITE_DOUBLE_SIZE, end );
  2996                     	JMP_TARGET(doublesize);
  2997                     	load_xf_bank( R_EDX );
  2998                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  2999                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  3000                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  3001                     	JMP_TARGET(end);
  3002                         } else {
  3003                     	JMP_rel8( 9 + MEM_WRITE_DOUBLE_SIZE, end );
  3004                     	JMP_TARGET(doublesize);
  3005                     	load_fr_bank( R_EDX );
  3006                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  3007                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  3008                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  3009                     	JMP_TARGET(end);
  3011                         sh4_x86.tstate = TSTATE_NONE;
  3013                         break;
  3014                     case 0xB:
  3015                         { /* FMOV FRm, @-Rn */
  3016                         uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  3017                         precheck();
  3018                         check_fpuen_no_precheck();
  3019                         load_reg( R_ECX, Rn );
  3020                         check_walign32( R_ECX );
  3021                         load_spreg( R_EDX, R_FPSCR );
  3022                         TEST_imm32_r32( FPSCR_SZ, R_EDX );
  3023                         JNE_rel8(14 + CALL_FUNC2_SIZE, doublesize);
  3024                         load_fr_bank( R_EDX );
  3025                         load_fr( R_EDX, R_EAX, FRm );
  3026                         ADD_imm8s_r32(-4,R_ECX);
  3027                         store_reg( R_ECX, Rn );
  3028                         MEM_WRITE_LONG( R_ECX, R_EAX ); // 12
  3029                         if( FRm&1 ) {
  3030                     	JMP_rel8( 24 + MEM_WRITE_DOUBLE_SIZE, end );
  3031                     	JMP_TARGET(doublesize);
  3032                     	load_xf_bank( R_EDX );
  3033                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  3034                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  3035                     	ADD_imm8s_r32(-8,R_ECX);
  3036                     	store_reg( R_ECX, Rn );
  3037                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  3038                     	JMP_TARGET(end);
  3039                         } else {
  3040                     	JMP_rel8( 15 + MEM_WRITE_DOUBLE_SIZE, end );
  3041                     	JMP_TARGET(doublesize);
  3042                     	load_fr_bank( R_EDX );
  3043                     	load_fr( R_EDX, R_EAX, FRm&0x0E );
  3044                     	load_fr( R_EDX, R_EDX, FRm|0x01 );
  3045                     	ADD_imm8s_r32(-8,R_ECX);
  3046                     	store_reg( R_ECX, Rn );
  3047                     	MEM_WRITE_DOUBLE( R_ECX, R_EAX, R_EDX );
  3048                     	JMP_TARGET(end);
  3050                         sh4_x86.tstate = TSTATE_NONE;
  3052                         break;
  3053                     case 0xC:
  3054                         { /* FMOV FRm, FRn */
  3055                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  3056                         /* As horrible as this looks, it's actually covering 5 separate cases:
  3057                          * 1. 32-bit fr-to-fr (PR=0)
  3058                          * 2. 64-bit dr-to-dr (PR=1, FRm&1 == 0, FRn&1 == 0 )
  3059                          * 3. 64-bit dr-to-xd (PR=1, FRm&1 == 0, FRn&1 == 1 )
  3060                          * 4. 64-bit xd-to-dr (PR=1, FRm&1 == 1, FRn&1 == 0 )
  3061                          * 5. 64-bit xd-to-xd (PR=1, FRm&1 == 1, FRn&1 == 1 )
  3062                          */
  3063                         check_fpuen();
  3064                         load_spreg( R_ECX, R_FPSCR );
  3065                         load_fr_bank( R_EDX );
  3066                         TEST_imm32_r32( FPSCR_SZ, R_ECX );
  3067                         JNE_rel8(8, doublesize);
  3068                         load_fr( R_EDX, R_EAX, FRm ); // PR=0 branch
  3069                         store_fr( R_EDX, R_EAX, FRn );
  3070                         if( FRm&1 ) {
  3071                     	JMP_rel8(24, end);
  3072                     	JMP_TARGET(doublesize);
  3073                     	load_xf_bank( R_ECX ); 
  3074                     	load_fr( R_ECX, R_EAX, FRm-1 );
  3075                     	if( FRn&1 ) {
  3076                     	    load_fr( R_ECX, R_EDX, FRm );
  3077                     	    store_fr( R_ECX, R_EAX, FRn-1 );
  3078                     	    store_fr( R_ECX, R_EDX, FRn );
  3079                     	} else /* FRn&1 == 0 */ {
  3080                     	    load_fr( R_ECX, R_ECX, FRm );
  3081                     	    store_fr( R_EDX, R_EAX, FRn );
  3082                     	    store_fr( R_EDX, R_ECX, FRn+1 );
  3084                     	JMP_TARGET(end);
  3085                         } else /* FRm&1 == 0 */ {
  3086                     	if( FRn&1 ) {
  3087                     	    JMP_rel8(24, end);
  3088                     	    load_xf_bank( R_ECX );
  3089                     	    load_fr( R_EDX, R_EAX, FRm );
  3090                     	    load_fr( R_EDX, R_EDX, FRm+1 );
  3091                     	    store_fr( R_ECX, R_EAX, FRn-1 );
  3092                     	    store_fr( R_ECX, R_EDX, FRn );
  3093                     	    JMP_TARGET(end);
  3094                     	} else /* FRn&1 == 0 */ {
  3095                     	    JMP_rel8(12, end);
  3096                     	    load_fr( R_EDX, R_EAX, FRm );
  3097                     	    load_fr( R_EDX, R_ECX, FRm+1 );
  3098                     	    store_fr( R_EDX, R_EAX, FRn );
  3099                     	    store_fr( R_EDX, R_ECX, FRn+1 );
  3100                     	    JMP_TARGET(end);
  3103                         sh4_x86.tstate = TSTATE_NONE;
  3105                         break;
  3106                     case 0xD:
  3107                         switch( (ir&0xF0) >> 4 ) {
  3108                             case 0x0:
  3109                                 { /* FSTS FPUL, FRn */
  3110                                 uint32_t FRn = ((ir>>8)&0xF); 
  3111                                 check_fpuen();
  3112                                 load_fr_bank( R_ECX );
  3113                                 load_spreg( R_EAX, R_FPUL );
  3114                                 store_fr( R_ECX, R_EAX, FRn );
  3115                                 sh4_x86.tstate = TSTATE_NONE;
  3117                                 break;
  3118                             case 0x1:
  3119                                 { /* FLDS FRm, FPUL */
  3120                                 uint32_t FRm = ((ir>>8)&0xF); 
  3121                                 check_fpuen();
  3122                                 load_fr_bank( R_ECX );
  3123                                 load_fr( R_ECX, R_EAX, FRm );
  3124                                 store_spreg( R_EAX, R_FPUL );
  3125                                 sh4_x86.tstate = TSTATE_NONE;
  3127                                 break;
  3128                             case 0x2:
  3129                                 { /* FLOAT FPUL, FRn */
  3130                                 uint32_t FRn = ((ir>>8)&0xF); 
  3131                                 check_fpuen();
  3132                                 load_spreg( R_ECX, R_FPSCR );
  3133                                 load_spreg(R_EDX, REG_OFFSET(fr_bank));
  3134                                 FILD_sh4r(R_FPUL);
  3135                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3136                                 JNE_rel8(5, doubleprec);
  3137                                 pop_fr( R_EDX, FRn );
  3138                                 JMP_rel8(3, end);
  3139                                 JMP_TARGET(doubleprec);
  3140                                 pop_dr( R_EDX, FRn );
  3141                                 JMP_TARGET(end);
  3142                                 sh4_x86.tstate = TSTATE_NONE;
  3144                                 break;
  3145                             case 0x3:
  3146                                 { /* FTRC FRm, FPUL */
  3147                                 uint32_t FRm = ((ir>>8)&0xF); 
  3148                                 check_fpuen();
  3149                                 load_spreg( R_ECX, R_FPSCR );
  3150                                 load_fr_bank( R_EDX );
  3151                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3152                                 JNE_rel8(5, doubleprec);
  3153                                 push_fr( R_EDX, FRm );
  3154                                 JMP_rel8(3, doop);
  3155                                 JMP_TARGET(doubleprec);
  3156                                 push_dr( R_EDX, FRm );
  3157                                 JMP_TARGET( doop );
  3158                                 load_imm32( R_ECX, (uint32_t)&max_int );
  3159                                 FILD_r32ind( R_ECX );
  3160                                 FCOMIP_st(1);
  3161                                 JNA_rel8( 32, sat );
  3162                                 load_imm32( R_ECX, (uint32_t)&min_int );  // 5
  3163                                 FILD_r32ind( R_ECX );           // 2
  3164                                 FCOMIP_st(1);                   // 2
  3165                                 JAE_rel8( 21, sat2 );            // 2
  3166                                 load_imm32( R_EAX, (uint32_t)&save_fcw );
  3167                                 FNSTCW_r32ind( R_EAX );
  3168                                 load_imm32( R_EDX, (uint32_t)&trunc_fcw );
  3169                                 FLDCW_r32ind( R_EDX );
  3170                                 FISTP_sh4r(R_FPUL);             // 3
  3171                                 FLDCW_r32ind( R_EAX );
  3172                                 JMP_rel8( 9, end );             // 2
  3174                                 JMP_TARGET(sat);
  3175                                 JMP_TARGET(sat2);
  3176                                 MOV_r32ind_r32( R_ECX, R_ECX ); // 2
  3177                                 store_spreg( R_ECX, R_FPUL );
  3178                                 FPOP_st();
  3179                                 JMP_TARGET(end);
  3180                                 sh4_x86.tstate = TSTATE_NONE;
  3182                                 break;
  3183                             case 0x4:
  3184                                 { /* FNEG FRn */
  3185                                 uint32_t FRn = ((ir>>8)&0xF); 
  3186                                 check_fpuen();
  3187                                 load_spreg( R_ECX, R_FPSCR );
  3188                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3189                                 load_fr_bank( R_EDX );
  3190                                 JNE_rel8(10, doubleprec);
  3191                                 push_fr(R_EDX, FRn);
  3192                                 FCHS_st0();
  3193                                 pop_fr(R_EDX, FRn);
  3194                                 JMP_rel8(8, end);
  3195                                 JMP_TARGET(doubleprec);
  3196                                 push_dr(R_EDX, FRn);
  3197                                 FCHS_st0();
  3198                                 pop_dr(R_EDX, FRn);
  3199                                 JMP_TARGET(end);
  3200                                 sh4_x86.tstate = TSTATE_NONE;
  3202                                 break;
  3203                             case 0x5:
  3204                                 { /* FABS FRn */
  3205                                 uint32_t FRn = ((ir>>8)&0xF); 
  3206                                 check_fpuen();
  3207                                 load_spreg( R_ECX, R_FPSCR );
  3208                                 load_fr_bank( R_EDX );
  3209                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3210                                 JNE_rel8(10, doubleprec);
  3211                                 push_fr(R_EDX, FRn); // 3
  3212                                 FABS_st0(); // 2
  3213                                 pop_fr( R_EDX, FRn); //3
  3214                                 JMP_rel8(8,end); // 2
  3215                                 JMP_TARGET(doubleprec);
  3216                                 push_dr(R_EDX, FRn);
  3217                                 FABS_st0();
  3218                                 pop_dr(R_EDX, FRn);
  3219                                 JMP_TARGET(end);
  3220                                 sh4_x86.tstate = TSTATE_NONE;
  3222                                 break;
  3223                             case 0x6:
  3224                                 { /* FSQRT FRn */
  3225                                 uint32_t FRn = ((ir>>8)&0xF); 
  3226                                 check_fpuen();
  3227                                 load_spreg( R_ECX, R_FPSCR );
  3228                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3229                                 load_fr_bank( R_EDX );
  3230                                 JNE_rel8(10, doubleprec);
  3231                                 push_fr(R_EDX, FRn);
  3232                                 FSQRT_st0();
  3233                                 pop_fr(R_EDX, FRn);
  3234                                 JMP_rel8(8, end);
  3235                                 JMP_TARGET(doubleprec);
  3236                                 push_dr(R_EDX, FRn);
  3237                                 FSQRT_st0();
  3238                                 pop_dr(R_EDX, FRn);
  3239                                 JMP_TARGET(end);
  3240                                 sh4_x86.tstate = TSTATE_NONE;
  3242                                 break;
  3243                             case 0x7:
  3244                                 { /* FSRRA FRn */
  3245                                 uint32_t FRn = ((ir>>8)&0xF); 
  3246                                 check_fpuen();
  3247                                 load_spreg( R_ECX, R_FPSCR );
  3248                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3249                                 load_fr_bank( R_EDX );
  3250                                 JNE_rel8(12, end); // PR=0 only
  3251                                 FLD1_st0();
  3252                                 push_fr(R_EDX, FRn);
  3253                                 FSQRT_st0();
  3254                                 FDIVP_st(1);
  3255                                 pop_fr(R_EDX, FRn);
  3256                                 JMP_TARGET(end);
  3257                                 sh4_x86.tstate = TSTATE_NONE;
  3259                                 break;
  3260                             case 0x8:
  3261                                 { /* FLDI0 FRn */
  3262                                 uint32_t FRn = ((ir>>8)&0xF); 
  3263                                 /* IFF PR=0 */
  3264                                   check_fpuen();
  3265                                   load_spreg( R_ECX, R_FPSCR );
  3266                                   TEST_imm32_r32( FPSCR_PR, R_ECX );
  3267                                   JNE_rel8(8, end);
  3268                                   XOR_r32_r32( R_EAX, R_EAX );
  3269                                   load_spreg( R_ECX, REG_OFFSET(fr_bank) );
  3270                                   store_fr( R_ECX, R_EAX, FRn );
  3271                                   JMP_TARGET(end);
  3272                                   sh4_x86.tstate = TSTATE_NONE;
  3274                                 break;
  3275                             case 0x9:
  3276                                 { /* FLDI1 FRn */
  3277                                 uint32_t FRn = ((ir>>8)&0xF); 
  3278                                 /* IFF PR=0 */
  3279                                   check_fpuen();
  3280                                   load_spreg( R_ECX, R_FPSCR );
  3281                                   TEST_imm32_r32( FPSCR_PR, R_ECX );
  3282                                   JNE_rel8(11, end);
  3283                                   load_imm32(R_EAX, 0x3F800000);
  3284                                   load_spreg( R_ECX, REG_OFFSET(fr_bank) );
  3285                                   store_fr( R_ECX, R_EAX, FRn );
  3286                                   JMP_TARGET(end);
  3287                                   sh4_x86.tstate = TSTATE_NONE;
  3289                                 break;
  3290                             case 0xA:
  3291                                 { /* FCNVSD FPUL, FRn */
  3292                                 uint32_t FRn = ((ir>>8)&0xF); 
  3293                                 check_fpuen();
  3294                                 load_spreg( R_ECX, R_FPSCR );
  3295                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3296                                 JE_rel8(9, end); // only when PR=1
  3297                                 load_fr_bank( R_ECX );
  3298                                 push_fpul();
  3299                                 pop_dr( R_ECX, FRn );
  3300                                 JMP_TARGET(end);
  3301                                 sh4_x86.tstate = TSTATE_NONE;
  3303                                 break;
  3304                             case 0xB:
  3305                                 { /* FCNVDS FRm, FPUL */
  3306                                 uint32_t FRm = ((ir>>8)&0xF); 
  3307                                 check_fpuen();
  3308                                 load_spreg( R_ECX, R_FPSCR );
  3309                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3310                                 JE_rel8(9, end); // only when PR=1
  3311                                 load_fr_bank( R_ECX );
  3312                                 push_dr( R_ECX, FRm );
  3313                                 pop_fpul();
  3314                                 JMP_TARGET(end);
  3315                                 sh4_x86.tstate = TSTATE_NONE;
  3317                                 break;
  3318                             case 0xE:
  3319                                 { /* FIPR FVm, FVn */
  3320                                 uint32_t FVn = ((ir>>10)&0x3); uint32_t FVm = ((ir>>8)&0x3); 
  3321                                 check_fpuen();
  3322                                 load_spreg( R_ECX, R_FPSCR );
  3323                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3324                                 JNE_rel8(44, doubleprec);
  3326                                 load_fr_bank( R_ECX );
  3327                                 push_fr( R_ECX, FVm<<2 );
  3328                                 push_fr( R_ECX, FVn<<2 );
  3329                                 FMULP_st(1);
  3330                                 push_fr( R_ECX, (FVm<<2)+1);
  3331                                 push_fr( R_ECX, (FVn<<2)+1);
  3332                                 FMULP_st(1);
  3333                                 FADDP_st(1);
  3334                                 push_fr( R_ECX, (FVm<<2)+2);
  3335                                 push_fr( R_ECX, (FVn<<2)+2);
  3336                                 FMULP_st(1);
  3337                                 FADDP_st(1);
  3338                                 push_fr( R_ECX, (FVm<<2)+3);
  3339                                 push_fr( R_ECX, (FVn<<2)+3);
  3340                                 FMULP_st(1);
  3341                                 FADDP_st(1);
  3342                                 pop_fr( R_ECX, (FVn<<2)+3);
  3343                                 JMP_TARGET(doubleprec);
  3344                                 sh4_x86.tstate = TSTATE_NONE;
  3346                                 break;
  3347                             case 0xF:
  3348                                 switch( (ir&0x100) >> 8 ) {
  3349                                     case 0x0:
  3350                                         { /* FSCA FPUL, FRn */
  3351                                         uint32_t FRn = ((ir>>9)&0x7)<<1; 
  3352                                         check_fpuen();
  3353                                         load_spreg( R_ECX, R_FPSCR );
  3354                                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  3355                                         JNE_rel8( CALL_FUNC2_SIZE + 9, doubleprec );
  3356                                         load_fr_bank( R_ECX );
  3357                                         ADD_imm8s_r32( (FRn&0x0E)<<2, R_ECX );
  3358                                         load_spreg( R_EDX, R_FPUL );
  3359                                         call_func2( sh4_fsca, R_EDX, R_ECX );
  3360                                         JMP_TARGET(doubleprec);
  3361                                         sh4_x86.tstate = TSTATE_NONE;
  3363                                         break;
  3364                                     case 0x1:
  3365                                         switch( (ir&0x200) >> 9 ) {
  3366                                             case 0x0:
  3367                                                 { /* FTRV XMTRX, FVn */
  3368                                                 uint32_t FVn = ((ir>>10)&0x3); 
  3369                                                 check_fpuen();
  3370                                                 load_spreg( R_ECX, R_FPSCR );
  3371                                                 TEST_imm32_r32( FPSCR_PR, R_ECX );
  3372                                                 JNE_rel8( 18 + CALL_FUNC2_SIZE, doubleprec );
  3373                                                 load_fr_bank( R_EDX );                 // 3
  3374                                                 ADD_imm8s_r32( FVn<<4, R_EDX );        // 3
  3375                                                 load_xf_bank( R_ECX );                 // 12
  3376                                                 call_func2( sh4_ftrv, R_EDX, R_ECX );  // 12
  3377                                                 JMP_TARGET(doubleprec);
  3378                                                 sh4_x86.tstate = TSTATE_NONE;
  3380                                                 break;
  3381                                             case 0x1:
  3382                                                 switch( (ir&0xC00) >> 10 ) {
  3383                                                     case 0x0:
  3384                                                         { /* FSCHG */
  3385                                                         check_fpuen();
  3386                                                         load_spreg( R_ECX, R_FPSCR );
  3387                                                         XOR_imm32_r32( FPSCR_SZ, R_ECX );
  3388                                                         store_spreg( R_ECX, R_FPSCR );
  3389                                                         sh4_x86.tstate = TSTATE_NONE;
  3391                                                         break;
  3392                                                     case 0x2:
  3393                                                         { /* FRCHG */
  3394                                                         check_fpuen();
  3395                                                         load_spreg( R_ECX, R_FPSCR );
  3396                                                         XOR_imm32_r32( FPSCR_FR, R_ECX );
  3397                                                         store_spreg( R_ECX, R_FPSCR );
  3398                                                         update_fr_bank( R_ECX );
  3399                                                         sh4_x86.tstate = TSTATE_NONE;
  3401                                                         break;
  3402                                                     case 0x3:
  3403                                                         { /* UNDEF */
  3404                                                         if( sh4_x86.in_delay_slot ) {
  3405                                                     	SLOTILLEGAL();
  3406                                                         } else {
  3407                                                     	precheck();
  3408                                                     	JMP_exit(EXIT_ILLEGAL);
  3409                                                     	return 2;
  3412                                                         break;
  3413                                                     default:
  3414                                                         UNDEF();
  3415                                                         break;
  3417                                                 break;
  3419                                         break;
  3421                                 break;
  3422                             default:
  3423                                 UNDEF();
  3424                                 break;
  3426                         break;
  3427                     case 0xE:
  3428                         { /* FMAC FR0, FRm, FRn */
  3429                         uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
  3430                         check_fpuen();
  3431                         load_spreg( R_ECX, R_FPSCR );
  3432                         load_spreg( R_EDX, REG_OFFSET(fr_bank));
  3433                         TEST_imm32_r32( FPSCR_PR, R_ECX );
  3434                         JNE_rel8(18, doubleprec);
  3435                         push_fr( R_EDX, 0 );
  3436                         push_fr( R_EDX, FRm );
  3437                         FMULP_st(1);
  3438                         push_fr( R_EDX, FRn );
  3439                         FADDP_st(1);
  3440                         pop_fr( R_EDX, FRn );
  3441                         JMP_rel8(16, end);
  3442                         JMP_TARGET(doubleprec);
  3443                         push_dr( R_EDX, 0 );
  3444                         push_dr( R_EDX, FRm );
  3445                         FMULP_st(1);
  3446                         push_dr( R_EDX, FRn );
  3447                         FADDP_st(1);
  3448                         pop_dr( R_EDX, FRn );
  3449                         JMP_TARGET(end);
  3450                         sh4_x86.tstate = TSTATE_NONE;
  3452                         break;
  3453                     default:
  3454                         UNDEF();
  3455                         break;
  3457                 break;
  3460     sh4_x86.in_delay_slot = FALSE;
  3461     return 0;
.