Search
lxdream.org :: lxdream/src/sh4/sh4x86.in
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4x86.in
changeset 1003:7b2688cbbca3
prev996:2e8cf0a87243
next1004:eae001858134
author nkeynes
date Fri Mar 27 06:13:34 2009 +0000 (11 years ago)
permissions -rw-r--r--
last change Revert change to xltcache and fix breakpoint precision correctly
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4 => x86 translation. This version does no real optimization, it just
nkeynes@359
     5
 * outputs straight-line x86 code - it mainly exists to provide a baseline
nkeynes@359
     6
 * to test the optimizing versions against.
nkeynes@359
     7
 *
nkeynes@359
     8
 * Copyright (c) 2007 Nathan Keynes.
nkeynes@359
     9
 *
nkeynes@359
    10
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
    11
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    12
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    13
 * (at your option) any later version.
nkeynes@359
    14
 *
nkeynes@359
    15
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    18
 * GNU General Public License for more details.
nkeynes@359
    19
 */
nkeynes@359
    20
nkeynes@368
    21
#include <assert.h>
nkeynes@388
    22
#include <math.h>
nkeynes@368
    23
nkeynes@380
    24
#ifndef NDEBUG
nkeynes@380
    25
#define DEBUG_JUMPS 1
nkeynes@380
    26
#endif
nkeynes@380
    27
nkeynes@905
    28
#include "lxdream.h"
nkeynes@368
    29
#include "sh4/sh4core.h"
nkeynes@368
    30
#include "sh4/sh4trans.h"
nkeynes@671
    31
#include "sh4/sh4stat.h"
nkeynes@388
    32
#include "sh4/sh4mmio.h"
nkeynes@953
    33
#include "sh4/mmu.h"
nkeynes@991
    34
#include "xlat/xltcache.h"
nkeynes@991
    35
#include "xlat/x86/x86op.h"
nkeynes@368
    36
#include "clock.h"
nkeynes@368
    37
nkeynes@368
    38
#define DEFAULT_BACKPATCH_SIZE 4096
nkeynes@368
    39
nkeynes@991
    40
/* Offset of a reg relative to the sh4r structure */
nkeynes@991
    41
#define REG_OFFSET(reg)  (((char *)&sh4r.reg) - ((char *)&sh4r) - 128)
nkeynes@991
    42
nkeynes@995
    43
#define R_T      REG_OFFSET(t)
nkeynes@995
    44
#define R_Q      REG_OFFSET(q)
nkeynes@995
    45
#define R_S      REG_OFFSET(s)
nkeynes@995
    46
#define R_M      REG_OFFSET(m)
nkeynes@995
    47
#define R_SR     REG_OFFSET(sr)
nkeynes@995
    48
#define R_GBR    REG_OFFSET(gbr)
nkeynes@995
    49
#define R_SSR    REG_OFFSET(ssr)
nkeynes@995
    50
#define R_SPC    REG_OFFSET(spc)
nkeynes@995
    51
#define R_VBR    REG_OFFSET(vbr)
nkeynes@995
    52
#define R_MACH   REG_OFFSET(mac)+4
nkeynes@995
    53
#define R_MACL   REG_OFFSET(mac)
nkeynes@995
    54
#define R_PC     REG_OFFSET(pc)
nkeynes@991
    55
#define R_NEW_PC REG_OFFSET(new_pc)
nkeynes@995
    56
#define R_PR     REG_OFFSET(pr)
nkeynes@995
    57
#define R_SGR    REG_OFFSET(sgr)
nkeynes@995
    58
#define R_FPUL   REG_OFFSET(fpul)
nkeynes@995
    59
#define R_FPSCR  REG_OFFSET(fpscr)
nkeynes@995
    60
#define R_DBR    REG_OFFSET(dbr)
nkeynes@995
    61
#define R_R(rn)  REG_OFFSET(r[rn])
nkeynes@995
    62
#define R_FR(f)  REG_OFFSET(fr[0][(f)^1])
nkeynes@995
    63
#define R_XF(f)  REG_OFFSET(fr[1][(f)^1])
nkeynes@995
    64
#define R_DR(f)  REG_OFFSET(fr[(f)&1][(f)&0x0E])
nkeynes@995
    65
#define R_DRL(f) REG_OFFSET(fr[(f)&1][(f)|0x01])
nkeynes@995
    66
#define R_DRH(f) REG_OFFSET(fr[(f)&1][(f)&0x0E])
nkeynes@995
    67
nkeynes@995
    68
#define DELAY_NONE 0
nkeynes@995
    69
#define DELAY_PC 1
nkeynes@995
    70
#define DELAY_PC_PR 2
nkeynes@991
    71
nkeynes@586
    72
struct backpatch_record {
nkeynes@604
    73
    uint32_t fixup_offset;
nkeynes@586
    74
    uint32_t fixup_icount;
nkeynes@596
    75
    int32_t exc_code;
nkeynes@586
    76
};
nkeynes@586
    77
nkeynes@368
    78
/** 
nkeynes@368
    79
 * Struct to manage internal translation state. This state is not saved -
nkeynes@368
    80
 * it is only valid between calls to sh4_translate_begin_block() and
nkeynes@368
    81
 * sh4_translate_end_block()
nkeynes@368
    82
 */
nkeynes@368
    83
struct sh4_x86_state {
nkeynes@590
    84
    int in_delay_slot;
nkeynes@368
    85
    gboolean fpuen_checked; /* true if we've already checked fpu enabled. */
nkeynes@409
    86
    gboolean branch_taken; /* true if we branched unconditionally */
nkeynes@901
    87
    gboolean double_prec; /* true if FPU is in double-precision mode */
nkeynes@903
    88
    gboolean double_size; /* true if FPU is in double-size mode */
nkeynes@903
    89
    gboolean sse3_enabled; /* true if host supports SSE3 instructions */
nkeynes@408
    90
    uint32_t block_start_pc;
nkeynes@547
    91
    uint32_t stack_posn;   /* Trace stack height for alignment purposes */
nkeynes@417
    92
    int tstate;
nkeynes@368
    93
nkeynes@586
    94
    /* mode flags */
nkeynes@586
    95
    gboolean tlb_on; /* True if tlb translation is active */
nkeynes@586
    96
nkeynes@368
    97
    /* Allocated memory for the (block-wide) back-patch list */
nkeynes@586
    98
    struct backpatch_record *backpatch_list;
nkeynes@368
    99
    uint32_t backpatch_posn;
nkeynes@368
   100
    uint32_t backpatch_size;
nkeynes@368
   101
};
nkeynes@368
   102
nkeynes@368
   103
static struct sh4_x86_state sh4_x86;
nkeynes@368
   104
nkeynes@388
   105
static uint32_t max_int = 0x7FFFFFFF;
nkeynes@388
   106
static uint32_t min_int = 0x80000000;
nkeynes@394
   107
static uint32_t save_fcw; /* save value for fpu control word */
nkeynes@394
   108
static uint32_t trunc_fcw = 0x0F7F; /* fcw value for truncation mode */
nkeynes@386
   109
nkeynes@903
   110
gboolean is_sse3_supported()
nkeynes@903
   111
{
nkeynes@903
   112
    uint32_t features;
nkeynes@903
   113
    
nkeynes@903
   114
    __asm__ __volatile__(
nkeynes@903
   115
        "mov $0x01, %%eax\n\t"
nkeynes@908
   116
        "cpuid\n\t" : "=c" (features) : : "eax", "edx", "ebx");
nkeynes@903
   117
    return (features & 1) ? TRUE : FALSE;
nkeynes@903
   118
}
nkeynes@903
   119
nkeynes@669
   120
void sh4_translate_init(void)
nkeynes@368
   121
{
nkeynes@368
   122
    sh4_x86.backpatch_list = malloc(DEFAULT_BACKPATCH_SIZE);
nkeynes@586
   123
    sh4_x86.backpatch_size = DEFAULT_BACKPATCH_SIZE / sizeof(struct backpatch_record);
nkeynes@903
   124
    sh4_x86.sse3_enabled = is_sse3_supported();
nkeynes@368
   125
}
nkeynes@368
   126
nkeynes@368
   127
nkeynes@586
   128
static void sh4_x86_add_backpatch( uint8_t *fixup_addr, uint32_t fixup_pc, uint32_t exc_code )
nkeynes@368
   129
{
nkeynes@991
   130
    int reloc_size = 4;
nkeynes@991
   131
    
nkeynes@991
   132
    if( exc_code == -2 ) {
nkeynes@991
   133
        reloc_size = sizeof(void *);
nkeynes@991
   134
    }
nkeynes@991
   135
    
nkeynes@368
   136
    if( sh4_x86.backpatch_posn == sh4_x86.backpatch_size ) {
nkeynes@368
   137
	sh4_x86.backpatch_size <<= 1;
nkeynes@586
   138
	sh4_x86.backpatch_list = realloc( sh4_x86.backpatch_list, 
nkeynes@586
   139
					  sh4_x86.backpatch_size * sizeof(struct backpatch_record));
nkeynes@368
   140
	assert( sh4_x86.backpatch_list != NULL );
nkeynes@368
   141
    }
nkeynes@586
   142
    if( sh4_x86.in_delay_slot ) {
nkeynes@586
   143
	fixup_pc -= 2;
nkeynes@586
   144
    }
nkeynes@991
   145
nkeynes@604
   146
    sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_offset = 
nkeynes@991
   147
	(((uint8_t *)fixup_addr) - ((uint8_t *)xlat_current_block->code)) - reloc_size;
nkeynes@586
   148
    sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_icount = (fixup_pc - sh4_x86.block_start_pc)>>1;
nkeynes@586
   149
    sh4_x86.backpatch_list[sh4_x86.backpatch_posn].exc_code = exc_code;
nkeynes@586
   150
    sh4_x86.backpatch_posn++;
nkeynes@368
   151
}
nkeynes@368
   152
nkeynes@991
   153
#define TSTATE_NONE -1
nkeynes@995
   154
#define TSTATE_O    X86_COND_O
nkeynes@995
   155
#define TSTATE_C    X86_COND_C
nkeynes@995
   156
#define TSTATE_E    X86_COND_E
nkeynes@995
   157
#define TSTATE_NE   X86_COND_NE
nkeynes@995
   158
#define TSTATE_G    X86_COND_G
nkeynes@995
   159
#define TSTATE_GE   X86_COND_GE
nkeynes@995
   160
#define TSTATE_A    X86_COND_A
nkeynes@995
   161
#define TSTATE_AE   X86_COND_AE
nkeynes@359
   162
nkeynes@991
   163
#define MARK_JMP8(x) uint8_t *_mark_jmp_##x = (xlat_output-1)
nkeynes@991
   164
#define JMP_TARGET(x) *_mark_jmp_##x += (xlat_output - _mark_jmp_##x)
nkeynes@368
   165
nkeynes@991
   166
/* Convenience instructions */
nkeynes@991
   167
#define LDC_t()          CMPB_imms_rbpdisp(1,R_T); CMC()
nkeynes@991
   168
#define SETE_t()         SETCCB_cc_rbpdisp(X86_COND_E,R_T)
nkeynes@991
   169
#define SETA_t()         SETCCB_cc_rbpdisp(X86_COND_A,R_T)
nkeynes@991
   170
#define SETAE_t()        SETCCB_cc_rbpdisp(X86_COND_AE,R_T)
nkeynes@991
   171
#define SETG_t()         SETCCB_cc_rbpdisp(X86_COND_G,R_T)
nkeynes@991
   172
#define SETGE_t()        SETCCB_cc_rbpdisp(X86_COND_GE,R_T)
nkeynes@991
   173
#define SETC_t()         SETCCB_cc_rbpdisp(X86_COND_C,R_T)
nkeynes@991
   174
#define SETO_t()         SETCCB_cc_rbpdisp(X86_COND_O,R_T)
nkeynes@991
   175
#define SETNE_t()        SETCCB_cc_rbpdisp(X86_COND_NE,R_T)
nkeynes@991
   176
#define SETC_r8(r1)      SETCCB_cc_r8(X86_COND_C, r1)
nkeynes@991
   177
#define JAE_label(label) JCC_cc_rel8(X86_COND_AE,-1); MARK_JMP8(label)
nkeynes@991
   178
#define JE_label(label)  JCC_cc_rel8(X86_COND_E,-1); MARK_JMP8(label)
nkeynes@991
   179
#define JGE_label(label) JCC_cc_rel8(X86_COND_GE,-1); MARK_JMP8(label)
nkeynes@991
   180
#define JNA_label(label) JCC_cc_rel8(X86_COND_NA,-1); MARK_JMP8(label)
nkeynes@991
   181
#define JNE_label(label) JCC_cc_rel8(X86_COND_NE,-1); MARK_JMP8(label)
nkeynes@991
   182
#define JNO_label(label) JCC_cc_rel8(X86_COND_NO,-1); MARK_JMP8(label)
nkeynes@991
   183
#define JS_label(label)  JCC_cc_rel8(X86_COND_S,-1); MARK_JMP8(label)
nkeynes@991
   184
#define JMP_label(label) JMP_rel8(-1); MARK_JMP8(label)
nkeynes@991
   185
#define JNE_exc(exc)     JCC_cc_rel32(X86_COND_NE,0); sh4_x86_add_backpatch(xlat_output, pc, exc)
nkeynes@374
   186
nkeynes@991
   187
/** Branch if T is set (either in the current cflags, or in sh4r.t) */
nkeynes@991
   188
#define JT_label(label) if( sh4_x86.tstate == TSTATE_NONE ) { \
nkeynes@991
   189
	CMPL_imms_rbpdisp( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
nkeynes@991
   190
    JCC_cc_rel8(sh4_x86.tstate,-1); MARK_JMP8(label)
nkeynes@368
   191
nkeynes@991
   192
/** Branch if T is clear (either in the current cflags or in sh4r.t) */
nkeynes@991
   193
#define JF_label(label) if( sh4_x86.tstate == TSTATE_NONE ) { \
nkeynes@991
   194
	CMPL_imms_rbpdisp( 1, R_T ); sh4_x86.tstate = TSTATE_E; } \
nkeynes@991
   195
    JCC_cc_rel8(sh4_x86.tstate^1, -1); MARK_JMP8(label)
nkeynes@359
   196
nkeynes@995
   197
nkeynes@991
   198
#define load_reg(x86reg,sh4reg)     MOVL_rbpdisp_r32( REG_OFFSET(r[sh4reg]), x86reg )
nkeynes@991
   199
#define store_reg(x86reg,sh4reg)    MOVL_r32_rbpdisp( x86reg, REG_OFFSET(r[sh4reg]) )
nkeynes@374
   200
nkeynes@375
   201
/**
nkeynes@375
   202
 * Load an FR register (single-precision floating point) into an integer x86
nkeynes@375
   203
 * register (eg for register-to-register moves)
nkeynes@375
   204
 */
nkeynes@991
   205
#define load_fr(reg,frm)  MOVL_rbpdisp_r32( REG_OFFSET(fr[0][(frm)^1]), reg )
nkeynes@991
   206
#define load_xf(reg,frm)  MOVL_rbpdisp_r32( REG_OFFSET(fr[1][(frm)^1]), reg )
nkeynes@375
   207
nkeynes@375
   208
/**
nkeynes@669
   209
 * Load the low half of a DR register (DR or XD) into an integer x86 register 
nkeynes@669
   210
 */
nkeynes@991
   211
#define load_dr0(reg,frm) MOVL_rbpdisp_r32( REG_OFFSET(fr[frm&1][frm|0x01]), reg )
nkeynes@991
   212
#define load_dr1(reg,frm) MOVL_rbpdisp_r32( REG_OFFSET(fr[frm&1][frm&0x0E]), reg )
nkeynes@669
   213
nkeynes@669
   214
/**
nkeynes@669
   215
 * Store an FR register (single-precision floating point) from an integer x86+
nkeynes@375
   216
 * register (eg for register-to-register moves)
nkeynes@375
   217
 */
nkeynes@991
   218
#define store_fr(reg,frm) MOVL_r32_rbpdisp( reg, REG_OFFSET(fr[0][(frm)^1]) )
nkeynes@991
   219
#define store_xf(reg,frm) MOVL_r32_rbpdisp( reg, REG_OFFSET(fr[1][(frm)^1]) )
nkeynes@375
   220
nkeynes@991
   221
#define store_dr0(reg,frm) MOVL_r32_rbpdisp( reg, REG_OFFSET(fr[frm&1][frm|0x01]) )
nkeynes@991
   222
#define store_dr1(reg,frm) MOVL_r32_rbpdisp( reg, REG_OFFSET(fr[frm&1][frm&0x0E]) )
nkeynes@375
   223
nkeynes@374
   224
nkeynes@991
   225
#define push_fpul()  FLDF_rbpdisp(R_FPUL)
nkeynes@991
   226
#define pop_fpul()   FSTPF_rbpdisp(R_FPUL)
nkeynes@991
   227
#define push_fr(frm) FLDF_rbpdisp( REG_OFFSET(fr[0][(frm)^1]) )
nkeynes@991
   228
#define pop_fr(frm)  FSTPF_rbpdisp( REG_OFFSET(fr[0][(frm)^1]) )
nkeynes@991
   229
#define push_xf(frm) FLDF_rbpdisp( REG_OFFSET(fr[1][(frm)^1]) )
nkeynes@991
   230
#define pop_xf(frm)  FSTPF_rbpdisp( REG_OFFSET(fr[1][(frm)^1]) )
nkeynes@991
   231
#define push_dr(frm) FLDD_rbpdisp( REG_OFFSET(fr[0][(frm)&0x0E]) )
nkeynes@991
   232
#define pop_dr(frm)  FSTPD_rbpdisp( REG_OFFSET(fr[0][(frm)&0x0E]) )
nkeynes@991
   233
#define push_xdr(frm) FLDD_rbpdisp( REG_OFFSET(fr[1][(frm)&0x0E]) )
nkeynes@991
   234
#define pop_xdr(frm)  FSTPD_rbpdisp( REG_OFFSET(fr[1][(frm)&0x0E]) )
nkeynes@377
   235
nkeynes@991
   236
#ifdef ENABLE_SH4STATS
nkeynes@995
   237
#define COUNT_INST(id) MOVL_imm32_r32( id, REG_EAX ); CALL1_ptr_r32(sh4_stats_add, REG_EAX); sh4_x86.tstate = TSTATE_NONE
nkeynes@991
   238
#else
nkeynes@991
   239
#define COUNT_INST(id)
nkeynes@991
   240
#endif
nkeynes@377
   241
nkeynes@374
   242
nkeynes@368
   243
/* Exception checks - Note that all exception checks will clobber EAX */
nkeynes@416
   244
nkeynes@416
   245
#define check_priv( ) \
nkeynes@953
   246
    if( (sh4r.xlat_sh4_mode & SR_MD) == 0 ) { \
nkeynes@953
   247
        if( sh4_x86.in_delay_slot ) { \
nkeynes@956
   248
            exit_block_exc(EXC_SLOT_ILLEGAL, (pc-2) ); \
nkeynes@953
   249
        } else { \
nkeynes@956
   250
            exit_block_exc(EXC_ILLEGAL, pc); \
nkeynes@953
   251
        } \
nkeynes@956
   252
        sh4_x86.branch_taken = TRUE; \
nkeynes@953
   253
        sh4_x86.in_delay_slot = DELAY_NONE; \
nkeynes@953
   254
        return 2; \
nkeynes@953
   255
    }
nkeynes@416
   256
nkeynes@416
   257
#define check_fpuen( ) \
nkeynes@416
   258
    if( !sh4_x86.fpuen_checked ) {\
nkeynes@416
   259
	sh4_x86.fpuen_checked = TRUE;\
nkeynes@995
   260
	MOVL_rbpdisp_r32( R_SR, REG_EAX );\
nkeynes@991
   261
	ANDL_imms_r32( SR_FD, REG_EAX );\
nkeynes@416
   262
	if( sh4_x86.in_delay_slot ) {\
nkeynes@586
   263
	    JNE_exc(EXC_SLOT_FPU_DISABLED);\
nkeynes@416
   264
	} else {\
nkeynes@586
   265
	    JNE_exc(EXC_FPU_DISABLED);\
nkeynes@416
   266
	}\
nkeynes@875
   267
	sh4_x86.tstate = TSTATE_NONE; \
nkeynes@416
   268
    }
nkeynes@416
   269
nkeynes@586
   270
#define check_ralign16( x86reg ) \
nkeynes@991
   271
    TESTL_imms_r32( 0x00000001, x86reg ); \
nkeynes@586
   272
    JNE_exc(EXC_DATA_ADDR_READ)
nkeynes@416
   273
nkeynes@586
   274
#define check_walign16( x86reg ) \
nkeynes@991
   275
    TESTL_imms_r32( 0x00000001, x86reg ); \
nkeynes@586
   276
    JNE_exc(EXC_DATA_ADDR_WRITE);
nkeynes@368
   277
nkeynes@586
   278
#define check_ralign32( x86reg ) \
nkeynes@991
   279
    TESTL_imms_r32( 0x00000003, x86reg ); \
nkeynes@586
   280
    JNE_exc(EXC_DATA_ADDR_READ)
nkeynes@368
   281
nkeynes@586
   282
#define check_walign32( x86reg ) \
nkeynes@991
   283
    TESTL_imms_r32( 0x00000003, x86reg ); \
nkeynes@586
   284
    JNE_exc(EXC_DATA_ADDR_WRITE);
nkeynes@368
   285
nkeynes@732
   286
#define check_ralign64( x86reg ) \
nkeynes@991
   287
    TESTL_imms_r32( 0x00000007, x86reg ); \
nkeynes@732
   288
    JNE_exc(EXC_DATA_ADDR_READ)
nkeynes@732
   289
nkeynes@732
   290
#define check_walign64( x86reg ) \
nkeynes@991
   291
    TESTL_imms_r32( 0x00000007, x86reg ); \
nkeynes@732
   292
    JNE_exc(EXC_DATA_ADDR_WRITE);
nkeynes@732
   293
nkeynes@824
   294
#define UNDEF(ir)
nkeynes@953
   295
/* Note: For SR.MD == 1 && MMUCR.AT == 0, there are no memory exceptions, so 
nkeynes@953
   296
 * don't waste the cycles expecting them. Otherwise we need to save the exception pointer.
nkeynes@953
   297
 */
nkeynes@953
   298
#ifdef HAVE_FRAME_ADDRESS
nkeynes@995
   299
static void call_read_func(int addr_reg, int value_reg, int offset, int pc)
nkeynes@995
   300
{
nkeynes@995
   301
    decode_address(addr_reg);
nkeynes@995
   302
    if( !sh4_x86.tlb_on && (sh4r.xlat_sh4_mode & SR_MD) ) { 
nkeynes@995
   303
        CALL1_r32disp_r32(REG_ECX, offset, addr_reg);
nkeynes@995
   304
    } else {
nkeynes@995
   305
        if( addr_reg != REG_ARG1 ) {
nkeynes@995
   306
            MOVL_r32_r32( addr_reg, REG_ARG1 );
nkeynes@995
   307
        }
nkeynes@995
   308
        MOVP_immptr_rptr( 0, REG_ARG2 );
nkeynes@995
   309
        sh4_x86_add_backpatch( xlat_output, pc, -2 );
nkeynes@995
   310
        CALL2_r32disp_r32_r32(REG_ECX, offset, REG_ARG1, REG_ARG2);
nkeynes@995
   311
    }
nkeynes@995
   312
    if( value_reg != REG_RESULT1 ) { 
nkeynes@995
   313
        MOVL_r32_r32( REG_RESULT1, value_reg );
nkeynes@995
   314
    }
nkeynes@995
   315
}
nkeynes@995
   316
nkeynes@995
   317
static void call_write_func(int addr_reg, int value_reg, int offset, int pc)
nkeynes@995
   318
{
nkeynes@995
   319
    decode_address(addr_reg);
nkeynes@995
   320
    if( !sh4_x86.tlb_on && (sh4r.xlat_sh4_mode & SR_MD) ) { 
nkeynes@995
   321
        CALL2_r32disp_r32_r32(REG_ECX, offset, addr_reg, value_reg);
nkeynes@995
   322
    } else {
nkeynes@995
   323
        if( value_reg != REG_ARG2 ) {
nkeynes@995
   324
            MOVL_r32_r32( value_reg, REG_ARG2 );
nkeynes@995
   325
	}        
nkeynes@995
   326
        if( addr_reg != REG_ARG1 ) {
nkeynes@995
   327
            MOVL_r32_r32( addr_reg, REG_ARG1 );
nkeynes@995
   328
        }
nkeynes@995
   329
#if MAX_REG_ARG > 2        
nkeynes@995
   330
        MOVP_immptr_rptr( 0, REG_ARG3 );
nkeynes@995
   331
        sh4_x86_add_backpatch( xlat_output, pc, -2 );
nkeynes@995
   332
        CALL3_r32disp_r32_r32_r32(REG_ECX, offset, REG_ARG1, REG_ARG2, REG_ARG3);
nkeynes@995
   333
#else
nkeynes@995
   334
        MOVL_imm32_rspdisp( 0, 0 );
nkeynes@995
   335
        sh4_x86_add_backpatch( xlat_output, pc, -2 );
nkeynes@995
   336
        CALL3_r32disp_r32_r32_r32(REG_ECX, offset, REG_ARG1, REG_ARG2, 0);
nkeynes@995
   337
#endif
nkeynes@995
   338
    }
nkeynes@995
   339
}
nkeynes@995
   340
#else
nkeynes@995
   341
static void call_read_func(int addr_reg, int value_reg, int offset, int pc)
nkeynes@995
   342
{
nkeynes@995
   343
    decode_address(addr_reg);
nkeynes@995
   344
    CALL1_r32disp_r32(REG_ECX, offset, addr_reg);
nkeynes@995
   345
    if( value_reg != REG_RESULT1 ) {
nkeynes@995
   346
        MOVL_r32_r32( REG_RESULT1, value_reg );
nkeynes@995
   347
    }
nkeynes@995
   348
}     
nkeynes@995
   349
nkeynes@996
   350
static void call_write_func(int addr_reg, int value_reg, int offset, int pc)
nkeynes@995
   351
{
nkeynes@995
   352
    decode_address(addr_reg);
nkeynes@995
   353
    CALL2_r32disp_r32_r32(REG_ECX, offset, addr_reg, value_reg);
nkeynes@995
   354
}
nkeynes@953
   355
#endif
nkeynes@953
   356
                
nkeynes@995
   357
#define MEM_REGION_PTR(name) offsetof( struct mem_region_fn, name )
nkeynes@995
   358
#define MEM_READ_BYTE( addr_reg, value_reg ) call_read_func(addr_reg, value_reg, MEM_REGION_PTR(read_byte), pc)
nkeynes@995
   359
#define MEM_READ_BYTE_FOR_WRITE( addr_reg, value_reg ) call_read_func( addr_reg, value_reg, MEM_REGION_PTR(read_byte_for_write), pc) 
nkeynes@995
   360
#define MEM_READ_WORD( addr_reg, value_reg ) call_read_func(addr_reg, value_reg, MEM_REGION_PTR(read_word), pc)
nkeynes@995
   361
#define MEM_READ_LONG( addr_reg, value_reg ) call_read_func(addr_reg, value_reg, MEM_REGION_PTR(read_long), pc)
nkeynes@995
   362
#define MEM_WRITE_BYTE( addr_reg, value_reg ) call_write_func(addr_reg, value_reg, MEM_REGION_PTR(write_byte), pc)
nkeynes@995
   363
#define MEM_WRITE_WORD( addr_reg, value_reg ) call_write_func(addr_reg, value_reg, MEM_REGION_PTR(write_word), pc)
nkeynes@995
   364
#define MEM_WRITE_LONG( addr_reg, value_reg ) call_write_func(addr_reg, value_reg, MEM_REGION_PTR(write_long), pc)
nkeynes@995
   365
#define MEM_PREFETCH( addr_reg ) call_read_func(addr_reg, REG_RESULT1, MEM_REGION_PTR(prefetch), pc)
nkeynes@361
   366
nkeynes@956
   367
#define SLOTILLEGAL() exit_block_exc(EXC_SLOT_ILLEGAL, pc-2); sh4_x86.in_delay_slot = DELAY_NONE; return 2;
nkeynes@388
   368
nkeynes@901
   369
void sh4_translate_begin_block( sh4addr_t pc ) 
nkeynes@901
   370
{
nkeynes@927
   371
    enter_block();
nkeynes@901
   372
    sh4_x86.in_delay_slot = FALSE;
nkeynes@901
   373
    sh4_x86.fpuen_checked = FALSE;
nkeynes@901
   374
    sh4_x86.branch_taken = FALSE;
nkeynes@901
   375
    sh4_x86.backpatch_posn = 0;
nkeynes@901
   376
    sh4_x86.block_start_pc = pc;
nkeynes@953
   377
    sh4_x86.tlb_on = IS_TLB_ENABLED();
nkeynes@901
   378
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@901
   379
    sh4_x86.double_prec = sh4r.fpscr & FPSCR_PR;
nkeynes@903
   380
    sh4_x86.double_size = sh4r.fpscr & FPSCR_SZ;
nkeynes@901
   381
}
nkeynes@901
   382
nkeynes@901
   383
nkeynes@593
   384
uint32_t sh4_translate_end_block_size()
nkeynes@593
   385
{
nkeynes@596
   386
    if( sh4_x86.backpatch_posn <= 3 ) {
nkeynes@901
   387
        return EPILOGUE_SIZE + (sh4_x86.backpatch_posn*12);
nkeynes@596
   388
    } else {
nkeynes@901
   389
        return EPILOGUE_SIZE + 48 + (sh4_x86.backpatch_posn-3)*15;
nkeynes@596
   390
    }
nkeynes@593
   391
}
nkeynes@593
   392
nkeynes@593
   393
nkeynes@590
   394
/**
nkeynes@590
   395
 * Embed a breakpoint into the generated code
nkeynes@590
   396
 */
nkeynes@586
   397
void sh4_translate_emit_breakpoint( sh4vma_t pc )
nkeynes@586
   398
{
nkeynes@995
   399
    MOVL_imm32_r32( pc, REG_EAX );
nkeynes@995
   400
    CALL1_ptr_r32( sh4_translate_breakpoint_hit, REG_EAX );
nkeynes@875
   401
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@586
   402
}
nkeynes@590
   403
nkeynes@601
   404
nkeynes@601
   405
#define UNTRANSLATABLE(pc) !IS_IN_ICACHE(pc)
nkeynes@601
   406
nkeynes@590
   407
/**
nkeynes@995
   408
 * Exit the block with sh4r.pc already written
nkeynes@995
   409
 */
nkeynes@995
   410
void exit_block_pcset( sh4addr_t pc )
nkeynes@995
   411
{
nkeynes@995
   412
    MOVL_imm32_r32( ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period, REG_ECX );
nkeynes@995
   413
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );
nkeynes@995
   414
    MOVL_rbpdisp_r32( R_PC, REG_ARG1 );
nkeynes@995
   415
    if( sh4_x86.tlb_on ) {
nkeynes@995
   416
        CALL1_ptr_r32(xlat_get_code_by_vma,REG_ARG1);
nkeynes@995
   417
    } else {
nkeynes@995
   418
        CALL1_ptr_r32(xlat_get_code,REG_ARG1);
nkeynes@995
   419
    }
nkeynes@995
   420
    exit_block();
nkeynes@995
   421
}
nkeynes@995
   422
nkeynes@995
   423
/**
nkeynes@995
   424
 * Exit the block with sh4r.new_pc written with the target pc
nkeynes@995
   425
 */
nkeynes@995
   426
void exit_block_newpcset( sh4addr_t pc )
nkeynes@995
   427
{
nkeynes@995
   428
    MOVL_imm32_r32( ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period, REG_ECX );
nkeynes@995
   429
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );
nkeynes@995
   430
    MOVL_rbpdisp_r32( R_NEW_PC, REG_ARG1 );
nkeynes@995
   431
    MOVL_r32_rbpdisp( REG_ARG1, R_PC );
nkeynes@995
   432
    if( sh4_x86.tlb_on ) {
nkeynes@995
   433
        CALL1_ptr_r32(xlat_get_code_by_vma,REG_ARG1);
nkeynes@995
   434
    } else {
nkeynes@995
   435
        CALL1_ptr_r32(xlat_get_code,REG_ARG1);
nkeynes@995
   436
    }
nkeynes@995
   437
    exit_block();
nkeynes@995
   438
}
nkeynes@995
   439
nkeynes@995
   440
nkeynes@995
   441
/**
nkeynes@995
   442
 * Exit the block to an absolute PC
nkeynes@995
   443
 */
nkeynes@995
   444
void exit_block_abs( sh4addr_t pc, sh4addr_t endpc )
nkeynes@995
   445
{
nkeynes@995
   446
    MOVL_imm32_r32( pc, REG_ECX );
nkeynes@995
   447
    MOVL_r32_rbpdisp( REG_ECX, R_PC );
nkeynes@995
   448
    if( IS_IN_ICACHE(pc) ) {
nkeynes@995
   449
        MOVP_moffptr_rax( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) );
nkeynes@995
   450
        ANDP_imms_rptr( -4, REG_EAX );
nkeynes@995
   451
    } else if( sh4_x86.tlb_on ) {
nkeynes@995
   452
        CALL1_ptr_r32(xlat_get_code_by_vma, REG_ECX);
nkeynes@995
   453
    } else {
nkeynes@995
   454
        CALL1_ptr_r32(xlat_get_code, REG_ECX);
nkeynes@995
   455
    }
nkeynes@995
   456
    MOVL_imm32_r32( ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period, REG_ECX );
nkeynes@995
   457
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );
nkeynes@995
   458
    exit_block();
nkeynes@995
   459
}
nkeynes@995
   460
nkeynes@995
   461
/**
nkeynes@995
   462
 * Exit the block to a relative PC
nkeynes@995
   463
 */
nkeynes@995
   464
void exit_block_rel( sh4addr_t pc, sh4addr_t endpc )
nkeynes@995
   465
{
nkeynes@995
   466
    MOVL_imm32_r32( pc - sh4_x86.block_start_pc, REG_ECX );
nkeynes@995
   467
    ADDL_rbpdisp_r32( R_PC, REG_ECX );
nkeynes@995
   468
    MOVL_r32_rbpdisp( REG_ECX, R_PC );
nkeynes@995
   469
    if( IS_IN_ICACHE(pc) ) {
nkeynes@995
   470
        MOVP_moffptr_rax( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) );
nkeynes@995
   471
        ANDP_imms_rptr( -4, REG_EAX );
nkeynes@995
   472
    } else if( sh4_x86.tlb_on ) {
nkeynes@995
   473
        CALL1_ptr_r32(xlat_get_code_by_vma, REG_ECX);
nkeynes@995
   474
    } else {
nkeynes@995
   475
        CALL1_ptr_r32(xlat_get_code, REG_ECX);
nkeynes@995
   476
    }
nkeynes@995
   477
    MOVL_imm32_r32( ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period, REG_ECX );
nkeynes@995
   478
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );
nkeynes@995
   479
    exit_block();
nkeynes@995
   480
}
nkeynes@995
   481
nkeynes@995
   482
/**
nkeynes@995
   483
 * Exit unconditionally with a general exception
nkeynes@995
   484
 */
nkeynes@995
   485
void exit_block_exc( int code, sh4addr_t pc )
nkeynes@995
   486
{
nkeynes@995
   487
    MOVL_imm32_r32( pc - sh4_x86.block_start_pc, REG_ECX );
nkeynes@995
   488
    ADDL_r32_rbpdisp( REG_ECX, R_PC );
nkeynes@995
   489
    MOVL_imm32_r32( ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period, REG_ECX );
nkeynes@995
   490
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );
nkeynes@995
   491
    MOVL_imm32_r32( code, REG_ARG1 );
nkeynes@995
   492
    CALL1_ptr_r32( sh4_raise_exception, REG_ARG1 );
nkeynes@995
   493
    MOVL_rbpdisp_r32( R_PC, REG_ARG1 );
nkeynes@995
   494
    if( sh4_x86.tlb_on ) {
nkeynes@995
   495
        CALL1_ptr_r32(xlat_get_code_by_vma,REG_ARG1);
nkeynes@995
   496
    } else {
nkeynes@995
   497
        CALL1_ptr_r32(xlat_get_code,REG_ARG1);
nkeynes@995
   498
    }
nkeynes@995
   499
nkeynes@995
   500
    exit_block();
nkeynes@995
   501
}    
nkeynes@995
   502
nkeynes@995
   503
/**
nkeynes@590
   504
 * Embed a call to sh4_execute_instruction for situations that we
nkeynes@601
   505
 * can't translate (just page-crossing delay slots at the moment).
nkeynes@601
   506
 * Caller is responsible for setting new_pc before calling this function.
nkeynes@601
   507
 *
nkeynes@601
   508
 * Performs:
nkeynes@601
   509
 *   Set PC = endpc
nkeynes@601
   510
 *   Set sh4r.in_delay_slot = sh4_x86.in_delay_slot
nkeynes@601
   511
 *   Update slice_cycle for endpc+2 (single step doesn't update slice_cycle)
nkeynes@601
   512
 *   Call sh4_execute_instruction
nkeynes@601
   513
 *   Call xlat_get_code_by_vma / xlat_get_code as for normal exit
nkeynes@590
   514
 */
nkeynes@601
   515
void exit_block_emu( sh4vma_t endpc )
nkeynes@590
   516
{
nkeynes@995
   517
    MOVL_imm32_r32( endpc - sh4_x86.block_start_pc, REG_ECX );   // 5
nkeynes@991
   518
    ADDL_r32_rbpdisp( REG_ECX, R_PC );
nkeynes@586
   519
    
nkeynes@995
   520
    MOVL_imm32_r32( (((endpc - sh4_x86.block_start_pc)>>1)+1)*sh4_cpu_period, REG_ECX ); // 5
nkeynes@991
   521
    ADDL_r32_rbpdisp( REG_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@995
   522
    MOVL_imm32_r32( sh4_x86.in_delay_slot ? 1 : 0, REG_ECX );
nkeynes@995
   523
    MOVL_r32_rbpdisp( REG_ECX, REG_OFFSET(in_delay_slot) );
nkeynes@590
   524
nkeynes@995
   525
    CALL_ptr( sh4_execute_instruction );    
nkeynes@995
   526
    MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@590
   527
    if( sh4_x86.tlb_on ) {
nkeynes@995
   528
	CALL1_ptr_r32(xlat_get_code_by_vma,REG_EAX);
nkeynes@590
   529
    } else {
nkeynes@995
   530
	CALL1_ptr_r32(xlat_get_code,REG_EAX);
nkeynes@590
   531
    }
nkeynes@926
   532
    exit_block();
nkeynes@590
   533
} 
nkeynes@539
   534
nkeynes@359
   535
/**
nkeynes@995
   536
 * Write the block trailer (exception handling block)
nkeynes@995
   537
 */
nkeynes@995
   538
void sh4_translate_end_block( sh4addr_t pc ) {
nkeynes@995
   539
    if( sh4_x86.branch_taken == FALSE ) {
nkeynes@995
   540
        // Didn't exit unconditionally already, so write the termination here
nkeynes@995
   541
        exit_block_rel( pc, pc );
nkeynes@995
   542
    }
nkeynes@995
   543
    if( sh4_x86.backpatch_posn != 0 ) {
nkeynes@995
   544
        unsigned int i;
nkeynes@995
   545
        // Exception raised - cleanup and exit
nkeynes@995
   546
        uint8_t *end_ptr = xlat_output;
nkeynes@995
   547
        MOVL_r32_r32( REG_EDX, REG_ECX );
nkeynes@995
   548
        ADDL_r32_r32( REG_EDX, REG_ECX );
nkeynes@995
   549
        ADDL_r32_rbpdisp( REG_ECX, R_SPC );
nkeynes@995
   550
        MOVL_moffptr_eax( &sh4_cpu_period );
nkeynes@995
   551
        MULL_r32( REG_EDX );
nkeynes@995
   552
        ADDL_r32_rbpdisp( REG_EAX, REG_OFFSET(slice_cycle) );
nkeynes@995
   553
        MOVL_rbpdisp_r32( R_PC, REG_ARG1 );
nkeynes@995
   554
        if( sh4_x86.tlb_on ) {
nkeynes@995
   555
            CALL1_ptr_r32(xlat_get_code_by_vma, REG_ARG1);
nkeynes@995
   556
        } else {
nkeynes@995
   557
            CALL1_ptr_r32(xlat_get_code, REG_ARG1);
nkeynes@995
   558
        }
nkeynes@995
   559
        exit_block();
nkeynes@995
   560
nkeynes@995
   561
        for( i=0; i< sh4_x86.backpatch_posn; i++ ) {
nkeynes@995
   562
            uint32_t *fixup_addr = (uint32_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset];
nkeynes@995
   563
            if( sh4_x86.backpatch_list[i].exc_code < 0 ) {
nkeynes@995
   564
                if( sh4_x86.backpatch_list[i].exc_code == -2 ) {
nkeynes@995
   565
                    *((uintptr_t *)fixup_addr) = (uintptr_t)xlat_output; 
nkeynes@995
   566
                } else {
nkeynes@995
   567
                    *fixup_addr += xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4;
nkeynes@995
   568
                }
nkeynes@995
   569
                MOVL_imm32_r32( sh4_x86.backpatch_list[i].fixup_icount, REG_EDX );
nkeynes@995
   570
                int rel = end_ptr - xlat_output;
nkeynes@995
   571
                JMP_prerel(rel);
nkeynes@995
   572
            } else {
nkeynes@995
   573
                *fixup_addr += xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4;
nkeynes@995
   574
                MOVL_imm32_r32( sh4_x86.backpatch_list[i].exc_code, REG_ARG1 );
nkeynes@995
   575
                CALL1_ptr_r32( sh4_raise_exception, REG_ARG1 );
nkeynes@995
   576
                MOVL_imm32_r32( sh4_x86.backpatch_list[i].fixup_icount, REG_EDX );
nkeynes@995
   577
                int rel = end_ptr - xlat_output;
nkeynes@995
   578
                JMP_prerel(rel);
nkeynes@995
   579
            }
nkeynes@995
   580
        }
nkeynes@995
   581
    }
nkeynes@995
   582
}
nkeynes@995
   583
nkeynes@995
   584
/**
nkeynes@359
   585
 * Translate a single instruction. Delayed branches are handled specially
nkeynes@359
   586
 * by translating both branch and delayed instruction as a single unit (as
nkeynes@359
   587
 * 
nkeynes@586
   588
 * The instruction MUST be in the icache (assert check)
nkeynes@359
   589
 *
nkeynes@359
   590
 * @return true if the instruction marks the end of a basic block
nkeynes@359
   591
 * (eg a branch or 
nkeynes@359
   592
 */
nkeynes@590
   593
uint32_t sh4_translate_instruction( sh4vma_t pc )
nkeynes@359
   594
{
nkeynes@388
   595
    uint32_t ir;
nkeynes@586
   596
    /* Read instruction from icache */
nkeynes@586
   597
    assert( IS_IN_ICACHE(pc) );
nkeynes@586
   598
    ir = *(uint16_t *)GET_ICACHE_PTR(pc);
nkeynes@586
   599
    
nkeynes@586
   600
    if( !sh4_x86.in_delay_slot ) {
nkeynes@596
   601
	sh4_translate_add_recovery( (pc - sh4_x86.block_start_pc)>>1 );
nkeynes@388
   602
    }
nkeynes@1003
   603
    
nkeynes@1003
   604
    /* check for breakpoints at this pc */
nkeynes@1003
   605
    for( int i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@1003
   606
        if( sh4_breakpoints[i].address == pc ) {
nkeynes@1003
   607
            sh4_translate_emit_breakpoint(pc);
nkeynes@1003
   608
            break;
nkeynes@1003
   609
        }
nkeynes@1003
   610
    }
nkeynes@359
   611
%%
nkeynes@359
   612
/* ALU operations */
nkeynes@359
   613
ADD Rm, Rn {:
nkeynes@671
   614
    COUNT_INST(I_ADD);
nkeynes@991
   615
    load_reg( REG_EAX, Rm );
nkeynes@991
   616
    load_reg( REG_ECX, Rn );
nkeynes@991
   617
    ADDL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   618
    store_reg( REG_ECX, Rn );
nkeynes@417
   619
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   620
:}
nkeynes@359
   621
ADD #imm, Rn {:  
nkeynes@671
   622
    COUNT_INST(I_ADDI);
nkeynes@991
   623
    ADDL_imms_rbpdisp( imm, REG_OFFSET(r[Rn]) );
nkeynes@417
   624
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   625
:}
nkeynes@359
   626
ADDC Rm, Rn {:
nkeynes@671
   627
    COUNT_INST(I_ADDC);
nkeynes@417
   628
    if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@911
   629
        LDC_t();
nkeynes@417
   630
    }
nkeynes@991
   631
    load_reg( REG_EAX, Rm );
nkeynes@991
   632
    load_reg( REG_ECX, Rn );
nkeynes@991
   633
    ADCL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   634
    store_reg( REG_ECX, Rn );
nkeynes@359
   635
    SETC_t();
nkeynes@417
   636
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
   637
:}
nkeynes@359
   638
ADDV Rm, Rn {:
nkeynes@671
   639
    COUNT_INST(I_ADDV);
nkeynes@991
   640
    load_reg( REG_EAX, Rm );
nkeynes@991
   641
    load_reg( REG_ECX, Rn );
nkeynes@991
   642
    ADDL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   643
    store_reg( REG_ECX, Rn );
nkeynes@359
   644
    SETO_t();
nkeynes@417
   645
    sh4_x86.tstate = TSTATE_O;
nkeynes@359
   646
:}
nkeynes@359
   647
AND Rm, Rn {:
nkeynes@671
   648
    COUNT_INST(I_AND);
nkeynes@991
   649
    load_reg( REG_EAX, Rm );
nkeynes@991
   650
    load_reg( REG_ECX, Rn );
nkeynes@991
   651
    ANDL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   652
    store_reg( REG_ECX, Rn );
nkeynes@417
   653
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   654
:}
nkeynes@359
   655
AND #imm, R0 {:  
nkeynes@671
   656
    COUNT_INST(I_ANDI);
nkeynes@991
   657
    load_reg( REG_EAX, 0 );
nkeynes@991
   658
    ANDL_imms_r32(imm, REG_EAX); 
nkeynes@991
   659
    store_reg( REG_EAX, 0 );
nkeynes@417
   660
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   661
:}
nkeynes@359
   662
AND.B #imm, @(R0, GBR) {: 
nkeynes@671
   663
    COUNT_INST(I_ANDB);
nkeynes@991
   664
    load_reg( REG_EAX, 0 );
nkeynes@991
   665
    ADDL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
   666
    MOVL_r32_rspdisp(REG_EAX, 0);
nkeynes@991
   667
    MEM_READ_BYTE_FOR_WRITE( REG_EAX, REG_EDX );
nkeynes@991
   668
    MOVL_rspdisp_r32(0, REG_EAX);
nkeynes@991
   669
    ANDL_imms_r32(imm, REG_EDX );
nkeynes@991
   670
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
   671
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   672
:}
nkeynes@359
   673
CMP/EQ Rm, Rn {:  
nkeynes@671
   674
    COUNT_INST(I_CMPEQ);
nkeynes@991
   675
    load_reg( REG_EAX, Rm );
nkeynes@991
   676
    load_reg( REG_ECX, Rn );
nkeynes@991
   677
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@359
   678
    SETE_t();
nkeynes@417
   679
    sh4_x86.tstate = TSTATE_E;
nkeynes@359
   680
:}
nkeynes@359
   681
CMP/EQ #imm, R0 {:  
nkeynes@671
   682
    COUNT_INST(I_CMPEQI);
nkeynes@991
   683
    load_reg( REG_EAX, 0 );
nkeynes@991
   684
    CMPL_imms_r32(imm, REG_EAX);
nkeynes@359
   685
    SETE_t();
nkeynes@417
   686
    sh4_x86.tstate = TSTATE_E;
nkeynes@359
   687
:}
nkeynes@359
   688
CMP/GE Rm, Rn {:  
nkeynes@671
   689
    COUNT_INST(I_CMPGE);
nkeynes@991
   690
    load_reg( REG_EAX, Rm );
nkeynes@991
   691
    load_reg( REG_ECX, Rn );
nkeynes@991
   692
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@359
   693
    SETGE_t();
nkeynes@417
   694
    sh4_x86.tstate = TSTATE_GE;
nkeynes@359
   695
:}
nkeynes@359
   696
CMP/GT Rm, Rn {: 
nkeynes@671
   697
    COUNT_INST(I_CMPGT);
nkeynes@991
   698
    load_reg( REG_EAX, Rm );
nkeynes@991
   699
    load_reg( REG_ECX, Rn );
nkeynes@991
   700
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@359
   701
    SETG_t();
nkeynes@417
   702
    sh4_x86.tstate = TSTATE_G;
nkeynes@359
   703
:}
nkeynes@359
   704
CMP/HI Rm, Rn {:  
nkeynes@671
   705
    COUNT_INST(I_CMPHI);
nkeynes@991
   706
    load_reg( REG_EAX, Rm );
nkeynes@991
   707
    load_reg( REG_ECX, Rn );
nkeynes@991
   708
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@359
   709
    SETA_t();
nkeynes@417
   710
    sh4_x86.tstate = TSTATE_A;
nkeynes@359
   711
:}
nkeynes@359
   712
CMP/HS Rm, Rn {: 
nkeynes@671
   713
    COUNT_INST(I_CMPHS);
nkeynes@991
   714
    load_reg( REG_EAX, Rm );
nkeynes@991
   715
    load_reg( REG_ECX, Rn );
nkeynes@991
   716
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@359
   717
    SETAE_t();
nkeynes@417
   718
    sh4_x86.tstate = TSTATE_AE;
nkeynes@359
   719
 :}
nkeynes@359
   720
CMP/PL Rn {: 
nkeynes@671
   721
    COUNT_INST(I_CMPPL);
nkeynes@991
   722
    load_reg( REG_EAX, Rn );
nkeynes@991
   723
    CMPL_imms_r32( 0, REG_EAX );
nkeynes@359
   724
    SETG_t();
nkeynes@417
   725
    sh4_x86.tstate = TSTATE_G;
nkeynes@359
   726
:}
nkeynes@359
   727
CMP/PZ Rn {:  
nkeynes@671
   728
    COUNT_INST(I_CMPPZ);
nkeynes@991
   729
    load_reg( REG_EAX, Rn );
nkeynes@991
   730
    CMPL_imms_r32( 0, REG_EAX );
nkeynes@359
   731
    SETGE_t();
nkeynes@417
   732
    sh4_x86.tstate = TSTATE_GE;
nkeynes@359
   733
:}
nkeynes@361
   734
CMP/STR Rm, Rn {:  
nkeynes@671
   735
    COUNT_INST(I_CMPSTR);
nkeynes@991
   736
    load_reg( REG_EAX, Rm );
nkeynes@991
   737
    load_reg( REG_ECX, Rn );
nkeynes@991
   738
    XORL_r32_r32( REG_ECX, REG_EAX );
nkeynes@991
   739
    TESTB_r8_r8( REG_AL, REG_AL );
nkeynes@991
   740
    JE_label(target1);
nkeynes@991
   741
    TESTB_r8_r8( REG_AH, REG_AH );
nkeynes@991
   742
    JE_label(target2);
nkeynes@991
   743
    SHRL_imm_r32( 16, REG_EAX );
nkeynes@991
   744
    TESTB_r8_r8( REG_AL, REG_AL );
nkeynes@991
   745
    JE_label(target3);
nkeynes@991
   746
    TESTB_r8_r8( REG_AH, REG_AH );
nkeynes@380
   747
    JMP_TARGET(target1);
nkeynes@380
   748
    JMP_TARGET(target2);
nkeynes@380
   749
    JMP_TARGET(target3);
nkeynes@368
   750
    SETE_t();
nkeynes@417
   751
    sh4_x86.tstate = TSTATE_E;
nkeynes@361
   752
:}
nkeynes@361
   753
DIV0S Rm, Rn {:
nkeynes@671
   754
    COUNT_INST(I_DIV0S);
nkeynes@991
   755
    load_reg( REG_EAX, Rm );
nkeynes@991
   756
    load_reg( REG_ECX, Rn );
nkeynes@991
   757
    SHRL_imm_r32( 31, REG_EAX );
nkeynes@991
   758
    SHRL_imm_r32( 31, REG_ECX );
nkeynes@995
   759
    MOVL_r32_rbpdisp( REG_EAX, R_M );
nkeynes@995
   760
    MOVL_r32_rbpdisp( REG_ECX, R_Q );
nkeynes@991
   761
    CMPL_r32_r32( REG_EAX, REG_ECX );
nkeynes@386
   762
    SETNE_t();
nkeynes@417
   763
    sh4_x86.tstate = TSTATE_NE;
nkeynes@361
   764
:}
nkeynes@361
   765
DIV0U {:  
nkeynes@671
   766
    COUNT_INST(I_DIV0U);
nkeynes@991
   767
    XORL_r32_r32( REG_EAX, REG_EAX );
nkeynes@995
   768
    MOVL_r32_rbpdisp( REG_EAX, R_Q );
nkeynes@995
   769
    MOVL_r32_rbpdisp( REG_EAX, R_M );
nkeynes@995
   770
    MOVL_r32_rbpdisp( REG_EAX, R_T );
nkeynes@417
   771
    sh4_x86.tstate = TSTATE_C; // works for DIV1
nkeynes@361
   772
:}
nkeynes@386
   773
DIV1 Rm, Rn {:
nkeynes@671
   774
    COUNT_INST(I_DIV1);
nkeynes@995
   775
    MOVL_rbpdisp_r32( R_M, REG_ECX );
nkeynes@991
   776
    load_reg( REG_EAX, Rn );
nkeynes@417
   777
    if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
   778
	LDC_t();
nkeynes@417
   779
    }
nkeynes@991
   780
    RCLL_imm_r32( 1, REG_EAX );
nkeynes@991
   781
    SETC_r8( REG_DL ); // Q'
nkeynes@991
   782
    CMPL_rbpdisp_r32( R_Q, REG_ECX );
nkeynes@991
   783
    JE_label(mqequal);
nkeynes@991
   784
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rm]), REG_EAX );
nkeynes@991
   785
    JMP_label(end);
nkeynes@380
   786
    JMP_TARGET(mqequal);
nkeynes@991
   787
    SUBL_rbpdisp_r32( REG_OFFSET(r[Rm]), REG_EAX );
nkeynes@386
   788
    JMP_TARGET(end);
nkeynes@991
   789
    store_reg( REG_EAX, Rn ); // Done with Rn now
nkeynes@991
   790
    SETC_r8(REG_AL); // tmp1
nkeynes@991
   791
    XORB_r8_r8( REG_DL, REG_AL ); // Q' = Q ^ tmp1
nkeynes@991
   792
    XORB_r8_r8( REG_AL, REG_CL ); // Q'' = Q' ^ M
nkeynes@995
   793
    MOVL_r32_rbpdisp( REG_ECX, R_Q );
nkeynes@991
   794
    XORL_imms_r32( 1, REG_AL );   // T = !Q'
nkeynes@991
   795
    MOVZXL_r8_r32( REG_AL, REG_EAX );
nkeynes@995
   796
    MOVL_r32_rbpdisp( REG_EAX, R_T );
nkeynes@417
   797
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@374
   798
:}
nkeynes@361
   799
DMULS.L Rm, Rn {:  
nkeynes@671
   800
    COUNT_INST(I_DMULS);
nkeynes@991
   801
    load_reg( REG_EAX, Rm );
nkeynes@991
   802
    load_reg( REG_ECX, Rn );
nkeynes@991
   803
    IMULL_r32(REG_ECX);
nkeynes@995
   804
    MOVL_r32_rbpdisp( REG_EDX, R_MACH );
nkeynes@995
   805
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@417
   806
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
   807
:}
nkeynes@361
   808
DMULU.L Rm, Rn {:  
nkeynes@671
   809
    COUNT_INST(I_DMULU);
nkeynes@991
   810
    load_reg( REG_EAX, Rm );
nkeynes@991
   811
    load_reg( REG_ECX, Rn );
nkeynes@991
   812
    MULL_r32(REG_ECX);
nkeynes@995
   813
    MOVL_r32_rbpdisp( REG_EDX, R_MACH );
nkeynes@995
   814
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );    
nkeynes@417
   815
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
   816
:}
nkeynes@359
   817
DT Rn {:  
nkeynes@671
   818
    COUNT_INST(I_DT);
nkeynes@991
   819
    load_reg( REG_EAX, Rn );
nkeynes@991
   820
    ADDL_imms_r32( -1, REG_EAX );
nkeynes@991
   821
    store_reg( REG_EAX, Rn );
nkeynes@359
   822
    SETE_t();
nkeynes@417
   823
    sh4_x86.tstate = TSTATE_E;
nkeynes@359
   824
:}
nkeynes@359
   825
EXTS.B Rm, Rn {:  
nkeynes@671
   826
    COUNT_INST(I_EXTSB);
nkeynes@991
   827
    load_reg( REG_EAX, Rm );
nkeynes@991
   828
    MOVSXL_r8_r32( REG_EAX, REG_EAX );
nkeynes@991
   829
    store_reg( REG_EAX, Rn );
nkeynes@359
   830
:}
nkeynes@361
   831
EXTS.W Rm, Rn {:  
nkeynes@671
   832
    COUNT_INST(I_EXTSW);
nkeynes@991
   833
    load_reg( REG_EAX, Rm );
nkeynes@991
   834
    MOVSXL_r16_r32( REG_EAX, REG_EAX );
nkeynes@991
   835
    store_reg( REG_EAX, Rn );
nkeynes@361
   836
:}
nkeynes@361
   837
EXTU.B Rm, Rn {:  
nkeynes@671
   838
    COUNT_INST(I_EXTUB);
nkeynes@991
   839
    load_reg( REG_EAX, Rm );
nkeynes@991
   840
    MOVZXL_r8_r32( REG_EAX, REG_EAX );
nkeynes@991
   841
    store_reg( REG_EAX, Rn );
nkeynes@361
   842
:}
nkeynes@361
   843
EXTU.W Rm, Rn {:  
nkeynes@671
   844
    COUNT_INST(I_EXTUW);
nkeynes@991
   845
    load_reg( REG_EAX, Rm );
nkeynes@991
   846
    MOVZXL_r16_r32( REG_EAX, REG_EAX );
nkeynes@991
   847
    store_reg( REG_EAX, Rn );
nkeynes@361
   848
:}
nkeynes@586
   849
MAC.L @Rm+, @Rn+ {:
nkeynes@671
   850
    COUNT_INST(I_MACL);
nkeynes@586
   851
    if( Rm == Rn ) {
nkeynes@991
   852
	load_reg( REG_EAX, Rm );
nkeynes@991
   853
	check_ralign32( REG_EAX );
nkeynes@991
   854
	MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
   855
	MOVL_r32_rspdisp(REG_EAX, 0);
nkeynes@991
   856
	load_reg( REG_EAX, Rm );
nkeynes@991
   857
	LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
   858
	MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
   859
        ADDL_imms_rbpdisp( 8, REG_OFFSET(r[Rn]) );
nkeynes@586
   860
    } else {
nkeynes@991
   861
	load_reg( REG_EAX, Rm );
nkeynes@991
   862
	check_ralign32( REG_EAX );
nkeynes@991
   863
	MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
   864
	MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
   865
	load_reg( REG_EAX, Rn );
nkeynes@991
   866
	check_ralign32( REG_EAX );
nkeynes@991
   867
	MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
   868
	ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rn]) );
nkeynes@991
   869
	ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@586
   870
    }
nkeynes@953
   871
    
nkeynes@991
   872
    IMULL_rspdisp( 0 );
nkeynes@991
   873
    ADDL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@991
   874
    ADCL_r32_rbpdisp( REG_EDX, R_MACH );
nkeynes@386
   875
nkeynes@995
   876
    MOVL_rbpdisp_r32( R_S, REG_ECX );
nkeynes@991
   877
    TESTL_r32_r32(REG_ECX, REG_ECX);
nkeynes@991
   878
    JE_label( nosat );
nkeynes@995
   879
    CALL_ptr( signsat48 );
nkeynes@386
   880
    JMP_TARGET( nosat );
nkeynes@417
   881
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@386
   882
:}
nkeynes@386
   883
MAC.W @Rm+, @Rn+ {:  
nkeynes@671
   884
    COUNT_INST(I_MACW);
nkeynes@586
   885
    if( Rm == Rn ) {
nkeynes@991
   886
	load_reg( REG_EAX, Rm );
nkeynes@991
   887
	check_ralign16( REG_EAX );
nkeynes@991
   888
	MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
   889
        MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
   890
	load_reg( REG_EAX, Rm );
nkeynes@991
   891
	LEAL_r32disp_r32( REG_EAX, 2, REG_EAX );
nkeynes@991
   892
	MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
   893
	ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rn]) );
nkeynes@586
   894
	// Note translate twice in case of page boundaries. Maybe worth
nkeynes@586
   895
	// adding a page-boundary check to skip the second translation
nkeynes@586
   896
    } else {
nkeynes@991
   897
	load_reg( REG_EAX, Rm );
nkeynes@991
   898
	check_ralign16( REG_EAX );
nkeynes@991
   899
	MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
   900
        MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
   901
	load_reg( REG_EAX, Rn );
nkeynes@991
   902
	check_ralign16( REG_EAX );
nkeynes@991
   903
	MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
   904
	ADDL_imms_rbpdisp( 2, REG_OFFSET(r[Rn]) );
nkeynes@991
   905
	ADDL_imms_rbpdisp( 2, REG_OFFSET(r[Rm]) );
nkeynes@586
   906
    }
nkeynes@991
   907
    IMULL_rspdisp( 0 );
nkeynes@995
   908
    MOVL_rbpdisp_r32( R_S, REG_ECX );
nkeynes@991
   909
    TESTL_r32_r32( REG_ECX, REG_ECX );
nkeynes@991
   910
    JE_label( nosat );
nkeynes@386
   911
nkeynes@991
   912
    ADDL_r32_rbpdisp( REG_EAX, R_MACL );  // 6
nkeynes@991
   913
    JNO_label( end );            // 2
nkeynes@995
   914
    MOVL_imm32_r32( 1, REG_EDX );         // 5
nkeynes@995
   915
    MOVL_r32_rbpdisp( REG_EDX, R_MACH );   // 6
nkeynes@991
   916
    JS_label( positive );        // 2
nkeynes@995
   917
    MOVL_imm32_r32( 0x80000000, REG_EAX );// 5
nkeynes@995
   918
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );   // 6
nkeynes@991
   919
    JMP_label(end2);           // 2
nkeynes@386
   920
nkeynes@386
   921
    JMP_TARGET(positive);
nkeynes@995
   922
    MOVL_imm32_r32( 0x7FFFFFFF, REG_EAX );// 5
nkeynes@995
   923
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );   // 6
nkeynes@991
   924
    JMP_label(end3);            // 2
nkeynes@386
   925
nkeynes@386
   926
    JMP_TARGET(nosat);
nkeynes@991
   927
    ADDL_r32_rbpdisp( REG_EAX, R_MACL );  // 6
nkeynes@991
   928
    ADCL_r32_rbpdisp( REG_EDX, R_MACH );  // 6
nkeynes@386
   929
    JMP_TARGET(end);
nkeynes@386
   930
    JMP_TARGET(end2);
nkeynes@386
   931
    JMP_TARGET(end3);
nkeynes@417
   932
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@386
   933
:}
nkeynes@359
   934
MOVT Rn {:  
nkeynes@671
   935
    COUNT_INST(I_MOVT);
nkeynes@995
   936
    MOVL_rbpdisp_r32( R_T, REG_EAX );
nkeynes@991
   937
    store_reg( REG_EAX, Rn );
nkeynes@359
   938
:}
nkeynes@361
   939
MUL.L Rm, Rn {:  
nkeynes@671
   940
    COUNT_INST(I_MULL);
nkeynes@991
   941
    load_reg( REG_EAX, Rm );
nkeynes@991
   942
    load_reg( REG_ECX, Rn );
nkeynes@991
   943
    MULL_r32( REG_ECX );
nkeynes@995
   944
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@417
   945
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
   946
:}
nkeynes@374
   947
MULS.W Rm, Rn {:
nkeynes@671
   948
    COUNT_INST(I_MULSW);
nkeynes@995
   949
    MOVSXL_rbpdisp16_r32( R_R(Rm), REG_EAX );
nkeynes@995
   950
    MOVSXL_rbpdisp16_r32( R_R(Rn), REG_ECX );
nkeynes@991
   951
    MULL_r32( REG_ECX );
nkeynes@995
   952
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@417
   953
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
   954
:}
nkeynes@374
   955
MULU.W Rm, Rn {:  
nkeynes@671
   956
    COUNT_INST(I_MULUW);
nkeynes@995
   957
    MOVZXL_rbpdisp16_r32( R_R(Rm), REG_EAX );
nkeynes@995
   958
    MOVZXL_rbpdisp16_r32( R_R(Rn), REG_ECX );
nkeynes@991
   959
    MULL_r32( REG_ECX );
nkeynes@995
   960
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@417
   961
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@374
   962
:}
nkeynes@359
   963
NEG Rm, Rn {:
nkeynes@671
   964
    COUNT_INST(I_NEG);
nkeynes@991
   965
    load_reg( REG_EAX, Rm );
nkeynes@991
   966
    NEGL_r32( REG_EAX );
nkeynes@991
   967
    store_reg( REG_EAX, Rn );
nkeynes@417
   968
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   969
:}
nkeynes@359
   970
NEGC Rm, Rn {:  
nkeynes@671
   971
    COUNT_INST(I_NEGC);
nkeynes@991
   972
    load_reg( REG_EAX, Rm );
nkeynes@991
   973
    XORL_r32_r32( REG_ECX, REG_ECX );
nkeynes@359
   974
    LDC_t();
nkeynes@991
   975
    SBBL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   976
    store_reg( REG_ECX, Rn );
nkeynes@359
   977
    SETC_t();
nkeynes@417
   978
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
   979
:}
nkeynes@359
   980
NOT Rm, Rn {:  
nkeynes@671
   981
    COUNT_INST(I_NOT);
nkeynes@991
   982
    load_reg( REG_EAX, Rm );
nkeynes@991
   983
    NOTL_r32( REG_EAX );
nkeynes@991
   984
    store_reg( REG_EAX, Rn );
nkeynes@417
   985
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   986
:}
nkeynes@359
   987
OR Rm, Rn {:  
nkeynes@671
   988
    COUNT_INST(I_OR);
nkeynes@991
   989
    load_reg( REG_EAX, Rm );
nkeynes@991
   990
    load_reg( REG_ECX, Rn );
nkeynes@991
   991
    ORL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
   992
    store_reg( REG_ECX, Rn );
nkeynes@417
   993
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
   994
:}
nkeynes@359
   995
OR #imm, R0 {:
nkeynes@671
   996
    COUNT_INST(I_ORI);
nkeynes@991
   997
    load_reg( REG_EAX, 0 );
nkeynes@991
   998
    ORL_imms_r32(imm, REG_EAX);
nkeynes@991
   999
    store_reg( REG_EAX, 0 );
nkeynes@417
  1000
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1001
:}
nkeynes@374
  1002
OR.B #imm, @(R0, GBR) {:  
nkeynes@671
  1003
    COUNT_INST(I_ORB);
nkeynes@991
  1004
    load_reg( REG_EAX, 0 );
nkeynes@991
  1005
    ADDL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1006
    MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
  1007
    MEM_READ_BYTE_FOR_WRITE( REG_EAX, REG_EDX );
nkeynes@991
  1008
    MOVL_rspdisp_r32( 0, REG_EAX );
nkeynes@991
  1009
    ORL_imms_r32(imm, REG_EDX );
nkeynes@991
  1010
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1011
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@374
  1012
:}
nkeynes@359
  1013
ROTCL Rn {:
nkeynes@671
  1014
    COUNT_INST(I_ROTCL);
nkeynes@991
  1015
    load_reg( REG_EAX, Rn );
nkeynes@417
  1016
    if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1017
	LDC_t();
nkeynes@417
  1018
    }
nkeynes@991
  1019
    RCLL_imm_r32( 1, REG_EAX );
nkeynes@991
  1020
    store_reg( REG_EAX, Rn );
nkeynes@359
  1021
    SETC_t();
nkeynes@417
  1022
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1023
:}
nkeynes@359
  1024
ROTCR Rn {:  
nkeynes@671
  1025
    COUNT_INST(I_ROTCR);
nkeynes@991
  1026
    load_reg( REG_EAX, Rn );
nkeynes@417
  1027
    if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1028
	LDC_t();
nkeynes@417
  1029
    }
nkeynes@991
  1030
    RCRL_imm_r32( 1, REG_EAX );
nkeynes@991
  1031
    store_reg( REG_EAX, Rn );
nkeynes@359
  1032
    SETC_t();
nkeynes@417
  1033
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1034
:}
nkeynes@359
  1035
ROTL Rn {:  
nkeynes@671
  1036
    COUNT_INST(I_ROTL);
nkeynes@991
  1037
    load_reg( REG_EAX, Rn );
nkeynes@991
  1038
    ROLL_imm_r32( 1, REG_EAX );
nkeynes@991
  1039
    store_reg( REG_EAX, Rn );
nkeynes@359
  1040
    SETC_t();
nkeynes@417
  1041
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1042
:}
nkeynes@359
  1043
ROTR Rn {:  
nkeynes@671
  1044
    COUNT_INST(I_ROTR);
nkeynes@991
  1045
    load_reg( REG_EAX, Rn );
nkeynes@991
  1046
    RORL_imm_r32( 1, REG_EAX );
nkeynes@991
  1047
    store_reg( REG_EAX, Rn );
nkeynes@359
  1048
    SETC_t();
nkeynes@417
  1049
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1050
:}
nkeynes@359
  1051
SHAD Rm, Rn {:
nkeynes@671
  1052
    COUNT_INST(I_SHAD);
nkeynes@359
  1053
    /* Annoyingly enough, not directly convertible */
nkeynes@991
  1054
    load_reg( REG_EAX, Rn );
nkeynes@991
  1055
    load_reg( REG_ECX, Rm );
nkeynes@991
  1056
    CMPL_imms_r32( 0, REG_ECX );
nkeynes@991
  1057
    JGE_label(doshl);
nkeynes@361
  1058
                    
nkeynes@991
  1059
    NEGL_r32( REG_ECX );      // 2
nkeynes@991
  1060
    ANDB_imms_r8( 0x1F, REG_CL ); // 3
nkeynes@991
  1061
    JE_label(emptysar);     // 2
nkeynes@991
  1062
    SARL_cl_r32( REG_EAX );       // 2
nkeynes@991
  1063
    JMP_label(end);          // 2
nkeynes@386
  1064
nkeynes@386
  1065
    JMP_TARGET(emptysar);
nkeynes@991
  1066
    SARL_imm_r32(31, REG_EAX );  // 3
nkeynes@991
  1067
    JMP_label(end2);
nkeynes@382
  1068
nkeynes@380
  1069
    JMP_TARGET(doshl);
nkeynes@991
  1070
    ANDB_imms_r8( 0x1F, REG_CL ); // 3
nkeynes@991
  1071
    SHLL_cl_r32( REG_EAX );       // 2
nkeynes@380
  1072
    JMP_TARGET(end);
nkeynes@386
  1073
    JMP_TARGET(end2);
nkeynes@991
  1074
    store_reg( REG_EAX, Rn );
nkeynes@417
  1075
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1076
:}
nkeynes@359
  1077
SHLD Rm, Rn {:  
nkeynes@671
  1078
    COUNT_INST(I_SHLD);
nkeynes@991
  1079
    load_reg( REG_EAX, Rn );
nkeynes@991
  1080
    load_reg( REG_ECX, Rm );
nkeynes@991
  1081
    CMPL_imms_r32( 0, REG_ECX );
nkeynes@991
  1082
    JGE_label(doshl);
nkeynes@368
  1083
nkeynes@991
  1084
    NEGL_r32( REG_ECX );      // 2
nkeynes@991
  1085
    ANDB_imms_r8( 0x1F, REG_CL ); // 3
nkeynes@991
  1086
    JE_label(emptyshr );
nkeynes@991
  1087
    SHRL_cl_r32( REG_EAX );       // 2
nkeynes@991
  1088
    JMP_label(end);          // 2
nkeynes@386
  1089
nkeynes@386
  1090
    JMP_TARGET(emptyshr);
nkeynes@991
  1091
    XORL_r32_r32( REG_EAX, REG_EAX );
nkeynes@991
  1092
    JMP_label(end2);
nkeynes@382
  1093
nkeynes@382
  1094
    JMP_TARGET(doshl);
nkeynes@991
  1095
    ANDB_imms_r8( 0x1F, REG_CL ); // 3
nkeynes@991
  1096
    SHLL_cl_r32( REG_EAX );       // 2
nkeynes@382
  1097
    JMP_TARGET(end);
nkeynes@386
  1098
    JMP_TARGET(end2);
nkeynes@991
  1099
    store_reg( REG_EAX, Rn );
nkeynes@417
  1100
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1101
:}
nkeynes@359
  1102
SHAL Rn {: 
nkeynes@671
  1103
    COUNT_INST(I_SHAL);
nkeynes@991
  1104
    load_reg( REG_EAX, Rn );
nkeynes@991
  1105
    SHLL_imm_r32( 1, REG_EAX );
nkeynes@397
  1106
    SETC_t();
nkeynes@991
  1107
    store_reg( REG_EAX, Rn );
nkeynes@417
  1108
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1109
:}
nkeynes@359
  1110
SHAR Rn {:  
nkeynes@671
  1111
    COUNT_INST(I_SHAR);
nkeynes@991
  1112
    load_reg( REG_EAX, Rn );
nkeynes@991
  1113
    SARL_imm_r32( 1, REG_EAX );
nkeynes@397
  1114
    SETC_t();
nkeynes@991
  1115
    store_reg( REG_EAX, Rn );
nkeynes@417
  1116
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1117
:}
nkeynes@359
  1118
SHLL Rn {:  
nkeynes@671
  1119
    COUNT_INST(I_SHLL);
nkeynes@991
  1120
    load_reg( REG_EAX, Rn );
nkeynes@991
  1121
    SHLL_imm_r32( 1, REG_EAX );
nkeynes@397
  1122
    SETC_t();
nkeynes@991
  1123
    store_reg( REG_EAX, Rn );
nkeynes@417
  1124
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1125
:}
nkeynes@359
  1126
SHLL2 Rn {:
nkeynes@671
  1127
    COUNT_INST(I_SHLL);
nkeynes@991
  1128
    load_reg( REG_EAX, Rn );
nkeynes@991
  1129
    SHLL_imm_r32( 2, REG_EAX );
nkeynes@991
  1130
    store_reg( REG_EAX, Rn );
nkeynes@417
  1131
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1132
:}
nkeynes@359
  1133
SHLL8 Rn {:  
nkeynes@671
  1134
    COUNT_INST(I_SHLL);
nkeynes@991
  1135
    load_reg( REG_EAX, Rn );
nkeynes@991
  1136
    SHLL_imm_r32( 8, REG_EAX );
nkeynes@991
  1137
    store_reg( REG_EAX, Rn );
nkeynes@417
  1138
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1139
:}
nkeynes@359
  1140
SHLL16 Rn {:  
nkeynes@671
  1141
    COUNT_INST(I_SHLL);
nkeynes@991
  1142
    load_reg( REG_EAX, Rn );
nkeynes@991
  1143
    SHLL_imm_r32( 16, REG_EAX );
nkeynes@991
  1144
    store_reg( REG_EAX, Rn );
nkeynes@417
  1145
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1146
:}
nkeynes@359
  1147
SHLR Rn {:  
nkeynes@671
  1148
    COUNT_INST(I_SHLR);
nkeynes@991
  1149
    load_reg( REG_EAX, Rn );
nkeynes@991
  1150
    SHRL_imm_r32( 1, REG_EAX );
nkeynes@397
  1151
    SETC_t();
nkeynes@991
  1152
    store_reg( REG_EAX, Rn );
nkeynes@417
  1153
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1154
:}
nkeynes@359
  1155
SHLR2 Rn {:  
nkeynes@671
  1156
    COUNT_INST(I_SHLR);
nkeynes@991
  1157
    load_reg( REG_EAX, Rn );
nkeynes@991
  1158
    SHRL_imm_r32( 2, REG_EAX );
nkeynes@991
  1159
    store_reg( REG_EAX, Rn );
nkeynes@417
  1160
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1161
:}
nkeynes@359
  1162
SHLR8 Rn {:  
nkeynes@671
  1163
    COUNT_INST(I_SHLR);
nkeynes@991
  1164
    load_reg( REG_EAX, Rn );
nkeynes@991
  1165
    SHRL_imm_r32( 8, REG_EAX );
nkeynes@991
  1166
    store_reg( REG_EAX, Rn );
nkeynes@417
  1167
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1168
:}
nkeynes@359
  1169
SHLR16 Rn {:  
nkeynes@671
  1170
    COUNT_INST(I_SHLR);
nkeynes@991
  1171
    load_reg( REG_EAX, Rn );
nkeynes@991
  1172
    SHRL_imm_r32( 16, REG_EAX );
nkeynes@991
  1173
    store_reg( REG_EAX, Rn );
nkeynes@417
  1174
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1175
:}
nkeynes@359
  1176
SUB Rm, Rn {:  
nkeynes@671
  1177
    COUNT_INST(I_SUB);
nkeynes@991
  1178
    load_reg( REG_EAX, Rm );
nkeynes@991
  1179
    load_reg( REG_ECX, Rn );
nkeynes@991
  1180
    SUBL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1181
    store_reg( REG_ECX, Rn );
nkeynes@417
  1182
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1183
:}
nkeynes@359
  1184
SUBC Rm, Rn {:  
nkeynes@671
  1185
    COUNT_INST(I_SUBC);
nkeynes@991
  1186
    load_reg( REG_EAX, Rm );
nkeynes@991
  1187
    load_reg( REG_ECX, Rn );
nkeynes@417
  1188
    if( sh4_x86.tstate != TSTATE_C ) {
nkeynes@417
  1189
	LDC_t();
nkeynes@417
  1190
    }
nkeynes@991
  1191
    SBBL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1192
    store_reg( REG_ECX, Rn );
nkeynes@394
  1193
    SETC_t();
nkeynes@417
  1194
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1195
:}
nkeynes@359
  1196
SUBV Rm, Rn {:  
nkeynes@671
  1197
    COUNT_INST(I_SUBV);
nkeynes@991
  1198
    load_reg( REG_EAX, Rm );
nkeynes@991
  1199
    load_reg( REG_ECX, Rn );
nkeynes@991
  1200
    SUBL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1201
    store_reg( REG_ECX, Rn );
nkeynes@359
  1202
    SETO_t();
nkeynes@417
  1203
    sh4_x86.tstate = TSTATE_O;
nkeynes@359
  1204
:}
nkeynes@359
  1205
SWAP.B Rm, Rn {:  
nkeynes@671
  1206
    COUNT_INST(I_SWAPB);
nkeynes@991
  1207
    load_reg( REG_EAX, Rm );
nkeynes@991
  1208
    XCHGB_r8_r8( REG_AL, REG_AH ); // NB: does not touch EFLAGS
nkeynes@991
  1209
    store_reg( REG_EAX, Rn );
nkeynes@359
  1210
:}
nkeynes@359
  1211
SWAP.W Rm, Rn {:  
nkeynes@671
  1212
    COUNT_INST(I_SWAPB);
nkeynes@991
  1213
    load_reg( REG_EAX, Rm );
nkeynes@991
  1214
    MOVL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1215
    SHLL_imm_r32( 16, REG_ECX );
nkeynes@991
  1216
    SHRL_imm_r32( 16, REG_EAX );
nkeynes@991
  1217
    ORL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1218
    store_reg( REG_ECX, Rn );
nkeynes@417
  1219
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1220
:}
nkeynes@361
  1221
TAS.B @Rn {:  
nkeynes@671
  1222
    COUNT_INST(I_TASB);
nkeynes@991
  1223
    load_reg( REG_EAX, Rn );
nkeynes@991
  1224
    MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
  1225
    MEM_READ_BYTE_FOR_WRITE( REG_EAX, REG_EDX );
nkeynes@991
  1226
    TESTB_r8_r8( REG_DL, REG_DL );
nkeynes@361
  1227
    SETE_t();
nkeynes@991
  1228
    ORB_imms_r8( 0x80, REG_DL );
nkeynes@991
  1229
    MOVL_rspdisp_r32( 0, REG_EAX );
nkeynes@991
  1230
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1231
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1232
:}
nkeynes@361
  1233
TST Rm, Rn {:  
nkeynes@671
  1234
    COUNT_INST(I_TST);
nkeynes@991
  1235
    load_reg( REG_EAX, Rm );
nkeynes@991
  1236
    load_reg( REG_ECX, Rn );
nkeynes@991
  1237
    TESTL_r32_r32( REG_EAX, REG_ECX );
nkeynes@361
  1238
    SETE_t();
nkeynes@417
  1239
    sh4_x86.tstate = TSTATE_E;
nkeynes@361
  1240
:}
nkeynes@368
  1241
TST #imm, R0 {:  
nkeynes@671
  1242
    COUNT_INST(I_TSTI);
nkeynes@991
  1243
    load_reg( REG_EAX, 0 );
nkeynes@991
  1244
    TESTL_imms_r32( imm, REG_EAX );
nkeynes@368
  1245
    SETE_t();
nkeynes@417
  1246
    sh4_x86.tstate = TSTATE_E;
nkeynes@368
  1247
:}
nkeynes@368
  1248
TST.B #imm, @(R0, GBR) {:  
nkeynes@671
  1249
    COUNT_INST(I_TSTB);
nkeynes@991
  1250
    load_reg( REG_EAX, 0);
nkeynes@991
  1251
    ADDL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1252
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@991
  1253
    TESTB_imms_r8( imm, REG_AL );
nkeynes@368
  1254
    SETE_t();
nkeynes@417
  1255
    sh4_x86.tstate = TSTATE_E;
nkeynes@368
  1256
:}
nkeynes@359
  1257
XOR Rm, Rn {:  
nkeynes@671
  1258
    COUNT_INST(I_XOR);
nkeynes@991
  1259
    load_reg( REG_EAX, Rm );
nkeynes@991
  1260
    load_reg( REG_ECX, Rn );
nkeynes@991
  1261
    XORL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1262
    store_reg( REG_ECX, Rn );
nkeynes@417
  1263
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1264
:}
nkeynes@359
  1265
XOR #imm, R0 {:  
nkeynes@671
  1266
    COUNT_INST(I_XORI);
nkeynes@991
  1267
    load_reg( REG_EAX, 0 );
nkeynes@991
  1268
    XORL_imms_r32( imm, REG_EAX );
nkeynes@991
  1269
    store_reg( REG_EAX, 0 );
nkeynes@417
  1270
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1271
:}
nkeynes@359
  1272
XOR.B #imm, @(R0, GBR) {:  
nkeynes@671
  1273
    COUNT_INST(I_XORB);
nkeynes@991
  1274
    load_reg( REG_EAX, 0 );
nkeynes@991
  1275
    ADDL_rbpdisp_r32( R_GBR, REG_EAX ); 
nkeynes@991
  1276
    MOVL_r32_rspdisp( REG_EAX, 0 );
nkeynes@991
  1277
    MEM_READ_BYTE_FOR_WRITE(REG_EAX, REG_EDX);
nkeynes@991
  1278
    MOVL_rspdisp_r32( 0, REG_EAX );
nkeynes@991
  1279
    XORL_imms_r32( imm, REG_EDX );
nkeynes@991
  1280
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1281
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1282
:}
nkeynes@361
  1283
XTRCT Rm, Rn {:
nkeynes@671
  1284
    COUNT_INST(I_XTRCT);
nkeynes@991
  1285
    load_reg( REG_EAX, Rm );
nkeynes@991
  1286
    load_reg( REG_ECX, Rn );
nkeynes@991
  1287
    SHLL_imm_r32( 16, REG_EAX );
nkeynes@991
  1288
    SHRL_imm_r32( 16, REG_ECX );
nkeynes@991
  1289
    ORL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1290
    store_reg( REG_ECX, Rn );
nkeynes@417
  1291
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1292
:}
nkeynes@359
  1293
nkeynes@359
  1294
/* Data move instructions */
nkeynes@359
  1295
MOV Rm, Rn {:  
nkeynes@671
  1296
    COUNT_INST(I_MOV);
nkeynes@991
  1297
    load_reg( REG_EAX, Rm );
nkeynes@991
  1298
    store_reg( REG_EAX, Rn );
nkeynes@359
  1299
:}
nkeynes@359
  1300
MOV #imm, Rn {:  
nkeynes@671
  1301
    COUNT_INST(I_MOVI);
nkeynes@995
  1302
    MOVL_imm32_r32( imm, REG_EAX );
nkeynes@991
  1303
    store_reg( REG_EAX, Rn );
nkeynes@359
  1304
:}
nkeynes@359
  1305
MOV.B Rm, @Rn {:  
nkeynes@671
  1306
    COUNT_INST(I_MOVB);
nkeynes@991
  1307
    load_reg( REG_EAX, Rn );
nkeynes@991
  1308
    load_reg( REG_EDX, Rm );
nkeynes@991
  1309
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1310
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1311
:}
nkeynes@359
  1312
MOV.B Rm, @-Rn {:  
nkeynes@671
  1313
    COUNT_INST(I_MOVB);
nkeynes@991
  1314
    load_reg( REG_EAX, Rn );
nkeynes@991
  1315
    LEAL_r32disp_r32( REG_EAX, -1, REG_EAX );
nkeynes@991
  1316
    load_reg( REG_EDX, Rm );
nkeynes@991
  1317
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@991
  1318
    ADDL_imms_rbpdisp( -1, REG_OFFSET(r[Rn]) );
nkeynes@417
  1319
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1320
:}
nkeynes@359
  1321
MOV.B Rm, @(R0, Rn) {:  
nkeynes@671
  1322
    COUNT_INST(I_MOVB);
nkeynes@991
  1323
    load_reg( REG_EAX, 0 );
nkeynes@991
  1324
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rn]), REG_EAX );
nkeynes@991
  1325
    load_reg( REG_EDX, Rm );
nkeynes@991
  1326
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1327
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1328
:}
nkeynes@359
  1329
MOV.B R0, @(disp, GBR) {:  
nkeynes@671
  1330
    COUNT_INST(I_MOVB);
nkeynes@995
  1331
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1332
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1333
    load_reg( REG_EDX, 0 );
nkeynes@991
  1334
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1335
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1336
:}
nkeynes@359
  1337
MOV.B R0, @(disp, Rn) {:  
nkeynes@671
  1338
    COUNT_INST(I_MOVB);
nkeynes@991
  1339
    load_reg( REG_EAX, Rn );
nkeynes@991
  1340
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1341
    load_reg( REG_EDX, 0 );
nkeynes@991
  1342
    MEM_WRITE_BYTE( REG_EAX, REG_EDX );
nkeynes@417
  1343
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1344
:}
nkeynes@359
  1345
MOV.B @Rm, Rn {:  
nkeynes@671
  1346
    COUNT_INST(I_MOVB);
nkeynes@991
  1347
    load_reg( REG_EAX, Rm );
nkeynes@991
  1348
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@991
  1349
    store_reg( REG_EAX, Rn );
nkeynes@417
  1350
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1351
:}
nkeynes@359
  1352
MOV.B @Rm+, Rn {:  
nkeynes@671
  1353
    COUNT_INST(I_MOVB);
nkeynes@991
  1354
    load_reg( REG_EAX, Rm );
nkeynes@991
  1355
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@953
  1356
    if( Rm != Rn ) {
nkeynes@991
  1357
    	ADDL_imms_rbpdisp( 1, REG_OFFSET(r[Rm]) );
nkeynes@953
  1358
    }
nkeynes@991
  1359
    store_reg( REG_EAX, Rn );
nkeynes@417
  1360
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1361
:}
nkeynes@359
  1362
MOV.B @(R0, Rm), Rn {:  
nkeynes@671
  1363
    COUNT_INST(I_MOVB);
nkeynes@991
  1364
    load_reg( REG_EAX, 0 );
nkeynes@991
  1365
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rm]), REG_EAX );
nkeynes@991
  1366
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@991
  1367
    store_reg( REG_EAX, Rn );
nkeynes@417
  1368
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1369
:}
nkeynes@359
  1370
MOV.B @(disp, GBR), R0 {:  
nkeynes@671
  1371
    COUNT_INST(I_MOVB);
nkeynes@995
  1372
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1373
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1374
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@991
  1375
    store_reg( REG_EAX, 0 );
nkeynes@417
  1376
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1377
:}
nkeynes@359
  1378
MOV.B @(disp, Rm), R0 {:  
nkeynes@671
  1379
    COUNT_INST(I_MOVB);
nkeynes@991
  1380
    load_reg( REG_EAX, Rm );
nkeynes@991
  1381
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1382
    MEM_READ_BYTE( REG_EAX, REG_EAX );
nkeynes@991
  1383
    store_reg( REG_EAX, 0 );
nkeynes@417
  1384
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1385
:}
nkeynes@374
  1386
MOV.L Rm, @Rn {:
nkeynes@671
  1387
    COUNT_INST(I_MOVL);
nkeynes@991
  1388
    load_reg( REG_EAX, Rn );
nkeynes@991
  1389
    check_walign32(REG_EAX);
nkeynes@991
  1390
    MOVL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1391
    ANDL_imms_r32( 0xFC000000, REG_ECX );
nkeynes@991
  1392
    CMPL_imms_r32( 0xE0000000, REG_ECX );
nkeynes@991
  1393
    JNE_label( notsq );
nkeynes@991
  1394
    ANDL_imms_r32( 0x3C, REG_EAX );
nkeynes@991
  1395
    load_reg( REG_EDX, Rm );
nkeynes@991
  1396
    MOVL_r32_sib( REG_EDX, 0, REG_EBP, REG_EAX, REG_OFFSET(store_queue) );
nkeynes@991
  1397
    JMP_label(end);
nkeynes@953
  1398
    JMP_TARGET(notsq);
nkeynes@991
  1399
    load_reg( REG_EDX, Rm );
nkeynes@991
  1400
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@953
  1401
    JMP_TARGET(end);
nkeynes@417
  1402
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1403
:}
nkeynes@361
  1404
MOV.L Rm, @-Rn {:  
nkeynes@671
  1405
    COUNT_INST(I_MOVL);
nkeynes@991
  1406
    load_reg( REG_EAX, Rn );
nkeynes@991
  1407
    ADDL_imms_r32( -4, REG_EAX );
nkeynes@991
  1408
    check_walign32( REG_EAX );
nkeynes@991
  1409
    load_reg( REG_EDX, Rm );
nkeynes@991
  1410
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  1411
    ADDL_imms_rbpdisp( -4, REG_OFFSET(r[Rn]) );
nkeynes@417
  1412
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1413
:}
nkeynes@361
  1414
MOV.L Rm, @(R0, Rn) {:  
nkeynes@671
  1415
    COUNT_INST(I_MOVL);
nkeynes@991
  1416
    load_reg( REG_EAX, 0 );
nkeynes@991
  1417
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rn]), REG_EAX );
nkeynes@991
  1418
    check_walign32( REG_EAX );
nkeynes@991
  1419
    load_reg( REG_EDX, Rm );
nkeynes@991
  1420
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@417
  1421
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1422
:}
nkeynes@361
  1423
MOV.L R0, @(disp, GBR) {:  
nkeynes@671
  1424
    COUNT_INST(I_MOVL);
nkeynes@995
  1425
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1426
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1427
    check_walign32( REG_EAX );
nkeynes@991
  1428
    load_reg( REG_EDX, 0 );
nkeynes@991
  1429
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@417
  1430
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1431
:}
nkeynes@361
  1432
MOV.L Rm, @(disp, Rn) {:  
nkeynes@671
  1433
    COUNT_INST(I_MOVL);
nkeynes@991
  1434
    load_reg( REG_EAX, Rn );
nkeynes@991
  1435
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1436
    check_walign32( REG_EAX );
nkeynes@991
  1437
    MOVL_r32_r32( REG_EAX, REG_ECX );
nkeynes@991
  1438
    ANDL_imms_r32( 0xFC000000, REG_ECX );
nkeynes@991
  1439
    CMPL_imms_r32( 0xE0000000, REG_ECX );
nkeynes@991
  1440
    JNE_label( notsq );
nkeynes@991
  1441
    ANDL_imms_r32( 0x3C, REG_EAX );
nkeynes@991
  1442
    load_reg( REG_EDX, Rm );
nkeynes@991
  1443
    MOVL_r32_sib( REG_EDX, 0, REG_EBP, REG_EAX, REG_OFFSET(store_queue) );
nkeynes@991
  1444
    JMP_label(end);
nkeynes@953
  1445
    JMP_TARGET(notsq);
nkeynes@991
  1446
    load_reg( REG_EDX, Rm );
nkeynes@991
  1447
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@953
  1448
    JMP_TARGET(end);
nkeynes@417
  1449
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1450
:}
nkeynes@361
  1451
MOV.L @Rm, Rn {:  
nkeynes@671
  1452
    COUNT_INST(I_MOVL);
nkeynes@991
  1453
    load_reg( REG_EAX, Rm );
nkeynes@991
  1454
    check_ralign32( REG_EAX );
nkeynes@991
  1455
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  1456
    store_reg( REG_EAX, Rn );
nkeynes@417
  1457
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1458
:}
nkeynes@361
  1459
MOV.L @Rm+, Rn {:  
nkeynes@671
  1460
    COUNT_INST(I_MOVL);
nkeynes@991
  1461
    load_reg( REG_EAX, Rm );
nkeynes@991
  1462
    check_ralign32( REG_EAX );
nkeynes@991
  1463
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@953
  1464
    if( Rm != Rn ) {
nkeynes@991
  1465
    	ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@953
  1466
    }
nkeynes@991
  1467
    store_reg( REG_EAX, Rn );
nkeynes@417
  1468
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1469
:}
nkeynes@361
  1470
MOV.L @(R0, Rm), Rn {:  
nkeynes@671
  1471
    COUNT_INST(I_MOVL);
nkeynes@991
  1472
    load_reg( REG_EAX, 0 );
nkeynes@991
  1473
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rm]), REG_EAX );
nkeynes@991
  1474
    check_ralign32( REG_EAX );
nkeynes@991
  1475
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  1476
    store_reg( REG_EAX, Rn );
nkeynes@417
  1477
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1478
:}
nkeynes@361
  1479
MOV.L @(disp, GBR), R0 {:
nkeynes@671
  1480
    COUNT_INST(I_MOVL);
nkeynes@995
  1481
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1482
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1483
    check_ralign32( REG_EAX );
nkeynes@991
  1484
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  1485
    store_reg( REG_EAX, 0 );
nkeynes@417
  1486
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1487
:}
nkeynes@361
  1488
MOV.L @(disp, PC), Rn {:  
nkeynes@671
  1489
    COUNT_INST(I_MOVLPC);
nkeynes@374
  1490
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1491
	SLOTILLEGAL();
nkeynes@374
  1492
    } else {
nkeynes@388
  1493
	uint32_t target = (pc & 0xFFFFFFFC) + disp + 4;
nkeynes@586
  1494
	if( IS_IN_ICACHE(target) ) {
nkeynes@586
  1495
	    // If the target address is in the same page as the code, it's
nkeynes@586
  1496
	    // pretty safe to just ref it directly and circumvent the whole
nkeynes@586
  1497
	    // memory subsystem. (this is a big performance win)
nkeynes@586
  1498
nkeynes@586
  1499
	    // FIXME: There's a corner-case that's not handled here when
nkeynes@586
  1500
	    // the current code-page is in the ITLB but not in the UTLB.
nkeynes@586
  1501
	    // (should generate a TLB miss although need to test SH4 
nkeynes@586
  1502
	    // behaviour to confirm) Unlikely to be anyone depending on this
nkeynes@586
  1503
	    // behaviour though.
nkeynes@586
  1504
	    sh4ptr_t ptr = GET_ICACHE_PTR(target);
nkeynes@991
  1505
	    MOVL_moffptr_eax( ptr );
nkeynes@388
  1506
	} else {
nkeynes@586
  1507
	    // Note: we use sh4r.pc for the calc as we could be running at a
nkeynes@586
  1508
	    // different virtual address than the translation was done with,
nkeynes@586
  1509
	    // but we can safely assume that the low bits are the same.
nkeynes@995
  1510
	    MOVL_imm32_r32( (pc-sh4_x86.block_start_pc) + disp + 4 - (pc&0x03), REG_EAX );
nkeynes@991
  1511
	    ADDL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1512
	    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@586
  1513
	    sh4_x86.tstate = TSTATE_NONE;
nkeynes@388
  1514
	}
nkeynes@991
  1515
	store_reg( REG_EAX, Rn );
nkeynes@374
  1516
    }
nkeynes@361
  1517
:}
nkeynes@361
  1518
MOV.L @(disp, Rm), Rn {:  
nkeynes@671
  1519
    COUNT_INST(I_MOVL);
nkeynes@991
  1520
    load_reg( REG_EAX, Rm );
nkeynes@991
  1521
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1522
    check_ralign32( REG_EAX );
nkeynes@991
  1523
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  1524
    store_reg( REG_EAX, Rn );
nkeynes@417
  1525
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1526
:}
nkeynes@361
  1527
MOV.W Rm, @Rn {:  
nkeynes@671
  1528
    COUNT_INST(I_MOVW);
nkeynes@991
  1529
    load_reg( REG_EAX, Rn );
nkeynes@991
  1530
    check_walign16( REG_EAX );
nkeynes@991
  1531
    load_reg( REG_EDX, Rm );
nkeynes@991
  1532
    MEM_WRITE_WORD( REG_EAX, REG_EDX );
nkeynes@417
  1533
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1534
:}
nkeynes@361
  1535
MOV.W Rm, @-Rn {:  
nkeynes@671
  1536
    COUNT_INST(I_MOVW);
nkeynes@991
  1537
    load_reg( REG_EAX, Rn );
nkeynes@991
  1538
    check_walign16( REG_EAX );
nkeynes@991
  1539
    LEAL_r32disp_r32( REG_EAX, -2, REG_EAX );
nkeynes@991
  1540
    load_reg( REG_EDX, Rm );
nkeynes@991
  1541
    MEM_WRITE_WORD( REG_EAX, REG_EDX );
nkeynes@991
  1542
    ADDL_imms_rbpdisp( -2, REG_OFFSET(r[Rn]) );
nkeynes@417
  1543
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1544
:}
nkeynes@361
  1545
MOV.W Rm, @(R0, Rn) {:  
nkeynes@671
  1546
    COUNT_INST(I_MOVW);
nkeynes@991
  1547
    load_reg( REG_EAX, 0 );
nkeynes@991
  1548
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rn]), REG_EAX );
nkeynes@991
  1549
    check_walign16( REG_EAX );
nkeynes@991
  1550
    load_reg( REG_EDX, Rm );
nkeynes@991
  1551
    MEM_WRITE_WORD( REG_EAX, REG_EDX );
nkeynes@417
  1552
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1553
:}
nkeynes@361
  1554
MOV.W R0, @(disp, GBR) {:  
nkeynes@671
  1555
    COUNT_INST(I_MOVW);
nkeynes@995
  1556
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1557
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1558
    check_walign16( REG_EAX );
nkeynes@991
  1559
    load_reg( REG_EDX, 0 );
nkeynes@991
  1560
    MEM_WRITE_WORD( REG_EAX, REG_EDX );
nkeynes@417
  1561
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1562
:}
nkeynes@361
  1563
MOV.W R0, @(disp, Rn) {:  
nkeynes@671
  1564
    COUNT_INST(I_MOVW);
nkeynes@991
  1565
    load_reg( REG_EAX, Rn );
nkeynes@991
  1566
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1567
    check_walign16( REG_EAX );
nkeynes@991
  1568
    load_reg( REG_EDX, 0 );
nkeynes@991
  1569
    MEM_WRITE_WORD( REG_EAX, REG_EDX );
nkeynes@417
  1570
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1571
:}
nkeynes@361
  1572
MOV.W @Rm, Rn {:  
nkeynes@671
  1573
    COUNT_INST(I_MOVW);
nkeynes@991
  1574
    load_reg( REG_EAX, Rm );
nkeynes@991
  1575
    check_ralign16( REG_EAX );
nkeynes@991
  1576
    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
  1577
    store_reg( REG_EAX, Rn );
nkeynes@417
  1578
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1579
:}
nkeynes@361
  1580
MOV.W @Rm+, Rn {:  
nkeynes@671
  1581
    COUNT_INST(I_MOVW);
nkeynes@991
  1582
    load_reg( REG_EAX, Rm );
nkeynes@991
  1583
    check_ralign16( REG_EAX );
nkeynes@991
  1584
    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@953
  1585
    if( Rm != Rn ) {
nkeynes@991
  1586
        ADDL_imms_rbpdisp( 2, REG_OFFSET(r[Rm]) );
nkeynes@953
  1587
    }
nkeynes@991
  1588
    store_reg( REG_EAX, Rn );
nkeynes@417
  1589
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1590
:}
nkeynes@361
  1591
MOV.W @(R0, Rm), Rn {:  
nkeynes@671
  1592
    COUNT_INST(I_MOVW);
nkeynes@991
  1593
    load_reg( REG_EAX, 0 );
nkeynes@991
  1594
    ADDL_rbpdisp_r32( REG_OFFSET(r[Rm]), REG_EAX );
nkeynes@991
  1595
    check_ralign16( REG_EAX );
nkeynes@991
  1596
    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
  1597
    store_reg( REG_EAX, Rn );
nkeynes@417
  1598
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1599
:}
nkeynes@361
  1600
MOV.W @(disp, GBR), R0 {:  
nkeynes@671
  1601
    COUNT_INST(I_MOVW);
nkeynes@995
  1602
    MOVL_rbpdisp_r32( R_GBR, REG_EAX );
nkeynes@991
  1603
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1604
    check_ralign16( REG_EAX );
nkeynes@991
  1605
    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
  1606
    store_reg( REG_EAX, 0 );
nkeynes@417
  1607
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1608
:}
nkeynes@361
  1609
MOV.W @(disp, PC), Rn {:  
nkeynes@671
  1610
    COUNT_INST(I_MOVW);
nkeynes@374
  1611
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1612
	SLOTILLEGAL();
nkeynes@374
  1613
    } else {
nkeynes@586
  1614
	// See comments for MOV.L @(disp, PC), Rn
nkeynes@586
  1615
	uint32_t target = pc + disp + 4;
nkeynes@586
  1616
	if( IS_IN_ICACHE(target) ) {
nkeynes@586
  1617
	    sh4ptr_t ptr = GET_ICACHE_PTR(target);
nkeynes@991
  1618
	    MOVL_moffptr_eax( ptr );
nkeynes@991
  1619
	    MOVSXL_r16_r32( REG_EAX, REG_EAX );
nkeynes@586
  1620
	} else {
nkeynes@995
  1621
	    MOVL_imm32_r32( (pc - sh4_x86.block_start_pc) + disp + 4, REG_EAX );
nkeynes@991
  1622
	    ADDL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1623
	    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@586
  1624
	    sh4_x86.tstate = TSTATE_NONE;
nkeynes@586
  1625
	}
nkeynes@991
  1626
	store_reg( REG_EAX, Rn );
nkeynes@374
  1627
    }
nkeynes@361
  1628
:}
nkeynes@361
  1629
MOV.W @(disp, Rm), R0 {:  
nkeynes@671
  1630
    COUNT_INST(I_MOVW);
nkeynes@991
  1631
    load_reg( REG_EAX, Rm );
nkeynes@991
  1632
    ADDL_imms_r32( disp, REG_EAX );
nkeynes@991
  1633
    check_ralign16( REG_EAX );
nkeynes@991
  1634
    MEM_READ_WORD( REG_EAX, REG_EAX );
nkeynes@991
  1635
    store_reg( REG_EAX, 0 );
nkeynes@417
  1636
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1637
:}
nkeynes@361
  1638
MOVA @(disp, PC), R0 {:  
nkeynes@671
  1639
    COUNT_INST(I_MOVA);
nkeynes@374
  1640
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1641
	SLOTILLEGAL();
nkeynes@374
  1642
    } else {
nkeynes@995
  1643
	MOVL_imm32_r32( (pc - sh4_x86.block_start_pc) + disp + 4 - (pc&0x03), REG_ECX );
nkeynes@991
  1644
	ADDL_rbpdisp_r32( R_PC, REG_ECX );
nkeynes@991
  1645
	store_reg( REG_ECX, 0 );
nkeynes@586
  1646
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@374
  1647
    }
nkeynes@361
  1648
:}
nkeynes@361
  1649
MOVCA.L R0, @Rn {:  
nkeynes@671
  1650
    COUNT_INST(I_MOVCA);
nkeynes@991
  1651
    load_reg( REG_EAX, Rn );
nkeynes@991
  1652
    check_walign32( REG_EAX );
nkeynes@991
  1653
    load_reg( REG_EDX, 0 );
nkeynes@991
  1654
    MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@417
  1655
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@361
  1656
:}
nkeynes@359
  1657
nkeynes@359
  1658
/* Control transfer instructions */
nkeynes@374
  1659
BF disp {:
nkeynes@671
  1660
    COUNT_INST(I_BF);
nkeynes@374
  1661
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1662
	SLOTILLEGAL();
nkeynes@374
  1663
    } else {
nkeynes@586
  1664
	sh4vma_t target = disp + pc + 4;
nkeynes@991
  1665
	JT_label( nottaken );
nkeynes@586
  1666
	exit_block_rel(target, pc+2 );
nkeynes@380
  1667
	JMP_TARGET(nottaken);
nkeynes@408
  1668
	return 2;
nkeynes@374
  1669
    }
nkeynes@374
  1670
:}
nkeynes@374
  1671
BF/S disp {:
nkeynes@671
  1672
    COUNT_INST(I_BFS);
nkeynes@374
  1673
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1674
	SLOTILLEGAL();
nkeynes@374
  1675
    } else {
nkeynes@590
  1676
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@601
  1677
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@995
  1678
	    MOVL_imm32_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@991
  1679
	    JT_label(nottaken);
nkeynes@991
  1680
	    ADDL_imms_r32( disp, REG_EAX );
nkeynes@601
  1681
	    JMP_TARGET(nottaken);
nkeynes@991
  1682
	    ADDL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@995
  1683
	    MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@601
  1684
	    exit_block_emu(pc+2);
nkeynes@601
  1685
	    sh4_x86.branch_taken = TRUE;
nkeynes@601
  1686
	    return 2;
nkeynes@601
  1687
	} else {
nkeynes@601
  1688
	    if( sh4_x86.tstate == TSTATE_NONE ) {
nkeynes@991
  1689
		CMPL_imms_rbpdisp( 1, R_T );
nkeynes@601
  1690
		sh4_x86.tstate = TSTATE_E;
nkeynes@601
  1691
	    }
nkeynes@601
  1692
	    sh4vma_t target = disp + pc + 4;
nkeynes@991
  1693
	    JCC_cc_rel32(sh4_x86.tstate,0);
nkeynes@991
  1694
	    uint32_t *patch = ((uint32_t *)xlat_output)-1;
nkeynes@879
  1695
	    int save_tstate = sh4_x86.tstate;
nkeynes@601
  1696
	    sh4_translate_instruction(pc+2);
nkeynes@601
  1697
	    exit_block_rel( target, pc+4 );
nkeynes@601
  1698
	    
nkeynes@601
  1699
	    // not taken
nkeynes@601
  1700
	    *patch = (xlat_output - ((uint8_t *)patch)) - 4;
nkeynes@879
  1701
	    sh4_x86.tstate = save_tstate;
nkeynes@601
  1702
	    sh4_translate_instruction(pc+2);
nkeynes@601
  1703
	    return 4;
nkeynes@417
  1704
	}
nkeynes@374
  1705
    }
nkeynes@374
  1706
:}
nkeynes@374
  1707
BRA disp {:  
nkeynes@671
  1708
    COUNT_INST(I_BRA);
nkeynes@374
  1709
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1710
	SLOTILLEGAL();
nkeynes@374
  1711
    } else {
nkeynes@590
  1712
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@409
  1713
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1714
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@995
  1715
	    MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1716
	    ADDL_imms_r32( pc + disp + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@995
  1717
	    MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@601
  1718
	    exit_block_emu(pc+2);
nkeynes@601
  1719
	    return 2;
nkeynes@601
  1720
	} else {
nkeynes@601
  1721
	    sh4_translate_instruction( pc + 2 );
nkeynes@601
  1722
	    exit_block_rel( disp + pc + 4, pc+4 );
nkeynes@601
  1723
	    return 4;
nkeynes@601
  1724
	}
nkeynes@374
  1725
    }
nkeynes@374
  1726
:}
nkeynes@374
  1727
BRAF Rn {:  
nkeynes@671
  1728
    COUNT_INST(I_BRAF);
nkeynes@374
  1729
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1730
	SLOTILLEGAL();
nkeynes@374
  1731
    } else {
nkeynes@995
  1732
	MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1733
	ADDL_imms_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@991
  1734
	ADDL_rbpdisp_r32( REG_OFFSET(r[Rn]), REG_EAX );
nkeynes@995
  1735
	MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@590
  1736
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@417
  1737
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@409
  1738
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1739
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1740
	    exit_block_emu(pc+2);
nkeynes@601
  1741
	    return 2;
nkeynes@601
  1742
	} else {
nkeynes@601
  1743
	    sh4_translate_instruction( pc + 2 );
nkeynes@974
  1744
	    exit_block_newpcset(pc+4);
nkeynes@601
  1745
	    return 4;
nkeynes@601
  1746
	}
nkeynes@374
  1747
    }
nkeynes@374
  1748
:}
nkeynes@374
  1749
BSR disp {:  
nkeynes@671
  1750
    COUNT_INST(I_BSR);
nkeynes@374
  1751
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1752
	SLOTILLEGAL();
nkeynes@374
  1753
    } else {
nkeynes@995
  1754
	MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1755
	ADDL_imms_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@995
  1756
	MOVL_r32_rbpdisp( REG_EAX, R_PR );
nkeynes@590
  1757
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@409
  1758
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1759
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@601
  1760
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@991
  1761
	    ADDL_imms_r32( disp, REG_EAX );
nkeynes@995
  1762
	    MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@601
  1763
	    exit_block_emu(pc+2);
nkeynes@601
  1764
	    return 2;
nkeynes@601
  1765
	} else {
nkeynes@601
  1766
	    sh4_translate_instruction( pc + 2 );
nkeynes@601
  1767
	    exit_block_rel( disp + pc + 4, pc+4 );
nkeynes@601
  1768
	    return 4;
nkeynes@601
  1769
	}
nkeynes@374
  1770
    }
nkeynes@374
  1771
:}
nkeynes@374
  1772
BSRF Rn {:  
nkeynes@671
  1773
    COUNT_INST(I_BSRF);
nkeynes@374
  1774
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1775
	SLOTILLEGAL();
nkeynes@374
  1776
    } else {
nkeynes@995
  1777
	MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1778
	ADDL_imms_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@995
  1779
	MOVL_r32_rbpdisp( REG_EAX, R_PR );
nkeynes@991
  1780
	ADDL_rbpdisp_r32( REG_OFFSET(r[Rn]), REG_EAX );
nkeynes@995
  1781
	MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@590
  1782
nkeynes@601
  1783
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@417
  1784
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@409
  1785
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1786
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1787
	    exit_block_emu(pc+2);
nkeynes@601
  1788
	    return 2;
nkeynes@601
  1789
	} else {
nkeynes@601
  1790
	    sh4_translate_instruction( pc + 2 );
nkeynes@974
  1791
	    exit_block_newpcset(pc+4);
nkeynes@601
  1792
	    return 4;
nkeynes@601
  1793
	}
nkeynes@374
  1794
    }
nkeynes@374
  1795
:}
nkeynes@374
  1796
BT disp {:
nkeynes@671
  1797
    COUNT_INST(I_BT);
nkeynes@374
  1798
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1799
	SLOTILLEGAL();
nkeynes@374
  1800
    } else {
nkeynes@586
  1801
	sh4vma_t target = disp + pc + 4;
nkeynes@991
  1802
	JF_label( nottaken );
nkeynes@586
  1803
	exit_block_rel(target, pc+2 );
nkeynes@380
  1804
	JMP_TARGET(nottaken);
nkeynes@408
  1805
	return 2;
nkeynes@374
  1806
    }
nkeynes@374
  1807
:}
nkeynes@374
  1808
BT/S disp {:
nkeynes@671
  1809
    COUNT_INST(I_BTS);
nkeynes@374
  1810
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1811
	SLOTILLEGAL();
nkeynes@374
  1812
    } else {
nkeynes@590
  1813
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@601
  1814
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@995
  1815
	    MOVL_imm32_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@991
  1816
	    JF_label(nottaken);
nkeynes@991
  1817
	    ADDL_imms_r32( disp, REG_EAX );
nkeynes@601
  1818
	    JMP_TARGET(nottaken);
nkeynes@991
  1819
	    ADDL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@995
  1820
	    MOVL_r32_rbpdisp( REG_EAX, R_NEW_PC );
nkeynes@601
  1821
	    exit_block_emu(pc+2);
nkeynes@601
  1822
	    sh4_x86.branch_taken = TRUE;
nkeynes@601
  1823
	    return 2;
nkeynes@601
  1824
	} else {
nkeynes@601
  1825
	    if( sh4_x86.tstate == TSTATE_NONE ) {
nkeynes@991
  1826
		CMPL_imms_rbpdisp( 1, R_T );
nkeynes@601
  1827
		sh4_x86.tstate = TSTATE_E;
nkeynes@601
  1828
	    }
nkeynes@991
  1829
	    JCC_cc_rel32(sh4_x86.tstate^1,0);
nkeynes@991
  1830
	    uint32_t *patch = ((uint32_t *)xlat_output)-1;
nkeynes@991
  1831
nkeynes@879
  1832
	    int save_tstate = sh4_x86.tstate;
nkeynes@601
  1833
	    sh4_translate_instruction(pc+2);
nkeynes@601
  1834
	    exit_block_rel( disp + pc + 4, pc+4 );
nkeynes@601
  1835
	    // not taken
nkeynes@601
  1836
	    *patch = (xlat_output - ((uint8_t *)patch)) - 4;
nkeynes@879
  1837
	    sh4_x86.tstate = save_tstate;
nkeynes@601
  1838
	    sh4_translate_instruction(pc+2);
nkeynes@601
  1839
	    return 4;
nkeynes@417
  1840
	}
nkeynes@374
  1841
    }
nkeynes@374
  1842
:}
nkeynes@374
  1843
JMP @Rn {:  
nkeynes@671
  1844
    COUNT_INST(I_JMP);
nkeynes@374
  1845
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1846
	SLOTILLEGAL();
nkeynes@374
  1847
    } else {
nkeynes@991
  1848
	load_reg( REG_ECX, Rn );
nkeynes@995
  1849
	MOVL_r32_rbpdisp( REG_ECX, R_NEW_PC );
nkeynes@590
  1850
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@409
  1851
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1852
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1853
	    exit_block_emu(pc+2);
nkeynes@601
  1854
	    return 2;
nkeynes@601
  1855
	} else {
nkeynes@601
  1856
	    sh4_translate_instruction(pc+2);
nkeynes@974
  1857
	    exit_block_newpcset(pc+4);
nkeynes@601
  1858
	    return 4;
nkeynes@601
  1859
	}
nkeynes@374
  1860
    }
nkeynes@374
  1861
:}
nkeynes@374
  1862
JSR @Rn {:  
nkeynes@671
  1863
    COUNT_INST(I_JSR);
nkeynes@374
  1864
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1865
	SLOTILLEGAL();
nkeynes@374
  1866
    } else {
nkeynes@995
  1867
	MOVL_rbpdisp_r32( R_PC, REG_EAX );
nkeynes@991
  1868
	ADDL_imms_r32( pc + 4 - sh4_x86.block_start_pc, REG_EAX );
nkeynes@995
  1869
	MOVL_r32_rbpdisp( REG_EAX, R_PR );
nkeynes@991
  1870
	load_reg( REG_ECX, Rn );
nkeynes@995
  1871
	MOVL_r32_rbpdisp( REG_ECX, R_NEW_PC );
nkeynes@601
  1872
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@409
  1873
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1874
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@601
  1875
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1876
	    exit_block_emu(pc+2);
nkeynes@601
  1877
	    return 2;
nkeynes@601
  1878
	} else {
nkeynes@601
  1879
	    sh4_translate_instruction(pc+2);
nkeynes@974
  1880
	    exit_block_newpcset(pc+4);
nkeynes@601
  1881
	    return 4;
nkeynes@601
  1882
	}
nkeynes@374
  1883
    }
nkeynes@374
  1884
:}
nkeynes@374
  1885
RTE {:  
nkeynes@671
  1886
    COUNT_INST(I_RTE);
nkeynes@374
  1887
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1888
	SLOTILLEGAL();
nkeynes@374
  1889
    } else {
nkeynes@408
  1890
	check_priv();
nkeynes@995
  1891
	MOVL_rbpdisp_r32( R_SPC, REG_ECX );
nkeynes@995
  1892
	MOVL_r32_rbpdisp( REG_ECX, R_NEW_PC );
nkeynes@995
  1893
	MOVL_rbpdisp_r32( R_SSR, REG_EAX );
nkeynes@995
  1894
	CALL1_ptr_r32( sh4_write_sr, REG_EAX );
nkeynes@590
  1895
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@377
  1896
	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  1897
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@409
  1898
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1899
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1900
	    exit_block_emu(pc+2);
nkeynes@601
  1901
	    return 2;
nkeynes@601
  1902
	} else {
nkeynes@601
  1903
	    sh4_translate_instruction(pc+2);
nkeynes@974
  1904
	    exit_block_newpcset(pc+4);
nkeynes@601
  1905
	    return 4;
nkeynes@601
  1906
	}
nkeynes@374
  1907
    }
nkeynes@374
  1908
:}
nkeynes@374
  1909
RTS {:  
nkeynes@671
  1910
    COUNT_INST(I_RTS);
nkeynes@374
  1911
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1912
	SLOTILLEGAL();
nkeynes@374
  1913
    } else {
nkeynes@995
  1914
	MOVL_rbpdisp_r32( R_PR, REG_ECX );
nkeynes@995
  1915
	MOVL_r32_rbpdisp( REG_ECX, R_NEW_PC );
nkeynes@590
  1916
	sh4_x86.in_delay_slot = DELAY_PC;
nkeynes@409
  1917
	sh4_x86.branch_taken = TRUE;
nkeynes@601
  1918
	if( UNTRANSLATABLE(pc+2) ) {
nkeynes@601
  1919
	    exit_block_emu(pc+2);
nkeynes@601
  1920
	    return 2;
nkeynes@601
  1921
	} else {
nkeynes@601
  1922
	    sh4_translate_instruction(pc+2);
nkeynes@974
  1923
	    exit_block_newpcset(pc+4);
nkeynes@601
  1924
	    return 4;
nkeynes@601
  1925
	}
nkeynes@374
  1926
    }
nkeynes@374
  1927
:}
nkeynes@374
  1928
TRAPA #imm {:  
nkeynes@671
  1929
    COUNT_INST(I_TRAPA);
nkeynes@374
  1930
    if( sh4_x86.in_delay_slot ) {
nkeynes@374
  1931
	SLOTILLEGAL();
nkeynes@374
  1932
    } else {
nkeynes@995
  1933
	MOVL_imm32_r32( pc+2 - sh4_x86.block_start_pc, REG_ECX );   // 5
nkeynes@991
  1934
	ADDL_r32_rbpdisp( REG_ECX, R_PC );
nkeynes@995
  1935
	MOVL_imm32_r32( imm, REG_EAX );
nkeynes@995
  1936
	CALL1_ptr_r32( sh4_raise_trap, REG_EAX );
nkeynes@417
  1937
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@974
  1938
	exit_block_pcset(pc+2);
nkeynes@409
  1939
	sh4_x86.branch_taken = TRUE;
nkeynes@408
  1940
	return 2;
nkeynes@374
  1941
    }
nkeynes@374
  1942
:}
nkeynes@374
  1943
UNDEF {:  
nkeynes@671
  1944
    COUNT_INST(I_UNDEF);
nkeynes@374
  1945
    if( sh4_x86.in_delay_slot ) {
nkeynes@956
  1946
	exit_block_exc(EXC_SLOT_ILLEGAL, pc-2);    
nkeynes@374
  1947
    } else {
nkeynes@956
  1948
	exit_block_exc(EXC_ILLEGAL, pc);    
nkeynes@408
  1949
	return 2;
nkeynes@374
  1950
    }
nkeynes@368
  1951
:}
nkeynes@374
  1952
nkeynes@374
  1953
CLRMAC {:  
nkeynes@671
  1954
    COUNT_INST(I_CLRMAC);
nkeynes@991
  1955
    XORL_r32_r32(REG_EAX, REG_EAX);
nkeynes@995
  1956
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@995
  1957
    MOVL_r32_rbpdisp( REG_EAX, R_MACH );
nkeynes@417
  1958
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@368
  1959
:}
nkeynes@374
  1960
CLRS {:
nkeynes@671
  1961
    COUNT_INST(I_CLRS);
nkeynes@374
  1962
    CLC();
nkeynes@991
  1963
    SETCCB_cc_rbpdisp(X86_COND_C, R_S);
nkeynes@872
  1964
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@368
  1965
:}
nkeynes@374
  1966
CLRT {:  
nkeynes@671
  1967
    COUNT_INST(I_CLRT);
nkeynes@374
  1968
    CLC();
nkeynes@374
  1969
    SETC_t();
nkeynes@417
  1970
    sh4_x86.tstate = TSTATE_C;
nkeynes@359
  1971
:}
nkeynes@374
  1972
SETS {:  
nkeynes@671
  1973
    COUNT_INST(I_SETS);
nkeynes@374
  1974
    STC();
nkeynes@991
  1975
    SETCCB_cc_rbpdisp(X86_COND_C, R_S);
nkeynes@872
  1976
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  1977
:}
nkeynes@374
  1978
SETT {:  
nkeynes@671
  1979
    COUNT_INST(I_SETT);
nkeynes@374
  1980
    STC();
nkeynes@374
  1981
    SETC_t();
nkeynes@417
  1982
    sh4_x86.tstate = TSTATE_C;
nkeynes@374
  1983
:}
nkeynes@359
  1984
nkeynes@375
  1985
/* Floating point moves */
nkeynes@375
  1986
FMOV FRm, FRn {:  
nkeynes@671
  1987
    COUNT_INST(I_FMOV1);
nkeynes@377
  1988
    check_fpuen();
nkeynes@901
  1989
    if( sh4_x86.double_size ) {
nkeynes@991
  1990
        load_dr0( REG_EAX, FRm );
nkeynes@991
  1991
        load_dr1( REG_ECX, FRm );
nkeynes@991
  1992
        store_dr0( REG_EAX, FRn );
nkeynes@991
  1993
        store_dr1( REG_ECX, FRn );
nkeynes@901
  1994
    } else {
nkeynes@991
  1995
        load_fr( REG_EAX, FRm ); // SZ=0 branch
nkeynes@991
  1996
        store_fr( REG_EAX, FRn );
nkeynes@901
  1997
    }
nkeynes@375
  1998
:}
nkeynes@416
  1999
FMOV FRm, @Rn {: 
nkeynes@671
  2000
    COUNT_INST(I_FMOV2);
nkeynes@586
  2001
    check_fpuen();
nkeynes@991
  2002
    load_reg( REG_EAX, Rn );
nkeynes@901
  2003
    if( sh4_x86.double_size ) {
nkeynes@991
  2004
        check_walign64( REG_EAX );
nkeynes@991
  2005
        load_dr0( REG_EDX, FRm );
nkeynes@991
  2006
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  2007
        load_reg( REG_EAX, Rn );
nkeynes@991
  2008
        LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
  2009
        load_dr1( REG_EDX, FRm );
nkeynes@991
  2010
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@901
  2011
    } else {
nkeynes@991
  2012
        check_walign32( REG_EAX );
nkeynes@991
  2013
        load_fr( REG_EDX, FRm );
nkeynes@991
  2014
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@901
  2015
    }
nkeynes@417
  2016
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@375
  2017
:}
nkeynes@375
  2018
FMOV @Rm, FRn {:  
nkeynes@671
  2019
    COUNT_INST(I_FMOV5);
nkeynes@586
  2020
    check_fpuen();
nkeynes@991
  2021
    load_reg( REG_EAX, Rm );
nkeynes@901
  2022
    if( sh4_x86.double_size ) {
nkeynes@991
  2023
        check_ralign64( REG_EAX );
nkeynes@991
  2024
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2025
        store_dr0( REG_EAX, FRn );
nkeynes@991
  2026
        load_reg( REG_EAX, Rm );
nkeynes@991
  2027
        LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
  2028
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2029
        store_dr1( REG_EAX, FRn );
nkeynes@901
  2030
    } else {
nkeynes@991
  2031
        check_ralign32( REG_EAX );
nkeynes@991
  2032
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2033
        store_fr( REG_EAX, FRn );
nkeynes@901
  2034
    }
nkeynes@417
  2035
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@375
  2036
:}
nkeynes@377
  2037
FMOV FRm, @-Rn {:  
nkeynes@671
  2038
    COUNT_INST(I_FMOV3);
nkeynes@586
  2039
    check_fpuen();
nkeynes@991
  2040
    load_reg( REG_EAX, Rn );
nkeynes@901
  2041
    if( sh4_x86.double_size ) {
nkeynes@991
  2042
        check_walign64( REG_EAX );
nkeynes@991
  2043
        LEAL_r32disp_r32( REG_EAX, -8, REG_EAX );
nkeynes@991
  2044
        load_dr0( REG_EDX, FRm );
nkeynes@991
  2045
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  2046
        load_reg( REG_EAX, Rn );
nkeynes@991
  2047
        LEAL_r32disp_r32( REG_EAX, -4, REG_EAX );
nkeynes@991
  2048
        load_dr1( REG_EDX, FRm );
nkeynes@991
  2049
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  2050
        ADDL_imms_rbpdisp(-8,REG_OFFSET(r[Rn]));
nkeynes@901
  2051
    } else {
nkeynes@991
  2052
        check_walign32( REG_EAX );
nkeynes@991
  2053
        LEAL_r32disp_r32( REG_EAX, -4, REG_EAX );
nkeynes@991
  2054
        load_fr( REG_EDX, FRm );
nkeynes@991
  2055
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  2056
        ADDL_imms_rbpdisp(-4,REG_OFFSET(r[Rn]));
nkeynes@901
  2057
    }
nkeynes@417
  2058
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2059
:}
nkeynes@416
  2060
FMOV @Rm+, FRn {:
nkeynes@671
  2061
    COUNT_INST(I_FMOV6);
nkeynes@586
  2062
    check_fpuen();
nkeynes@991
  2063
    load_reg( REG_EAX, Rm );
nkeynes@901
  2064
    if( sh4_x86.double_size ) {
nkeynes@991
  2065
        check_ralign64( REG_EAX );
nkeynes@991
  2066
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2067
        store_dr0( REG_EAX, FRn );
nkeynes@991
  2068
        load_reg( REG_EAX, Rm );
nkeynes@991
  2069
        LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
  2070
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2071
        store_dr1( REG_EAX, FRn );
nkeynes@991
  2072
        ADDL_imms_rbpdisp( 8, REG_OFFSET(r[Rm]) );
nkeynes@901
  2073
    } else {
nkeynes@991
  2074
        check_ralign32( REG_EAX );
nkeynes@991
  2075
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2076
        store_fr( REG_EAX, FRn );
nkeynes@991
  2077
        ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@901
  2078
    }
nkeynes@417
  2079
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2080
:}
nkeynes@377
  2081
FMOV FRm, @(R0, Rn) {:  
nkeynes@671
  2082
    COUNT_INST(I_FMOV4);
nkeynes@586
  2083
    check_fpuen();
nkeynes@991
  2084
    load_reg( REG_EAX, Rn );
nkeynes@991
  2085
    ADDL_rbpdisp_r32( REG_OFFSET(r[0]), REG_EAX );
nkeynes@901
  2086
    if( sh4_x86.double_size ) {
nkeynes@991
  2087
        check_walign64( REG_EAX );
nkeynes@991
  2088
        load_dr0( REG_EDX, FRm );
nkeynes@991
  2089
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@991
  2090
        load_reg( REG_EAX, Rn );
nkeynes@991
  2091
        ADDL_rbpdisp_r32( REG_OFFSET(r[0]), REG_EAX );
nkeynes@991
  2092
        LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
  2093
        load_dr1( REG_EDX, FRm );
nkeynes@991
  2094
        MEM_WRITE_LONG( REG_EAX, REG_EDX );
nkeynes@901
  2095
    } else {
nkeynes@991
  2096
        check_walign32( REG_EAX );
nkeynes@991
  2097
        load_fr( REG_EDX, FRm );
nkeynes@991
  2098
        MEM_WRITE_LONG( REG_EAX, REG_EDX ); // 12
nkeynes@901
  2099
    }
nkeynes@417
  2100
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2101
:}
nkeynes@377
  2102
FMOV @(R0, Rm), FRn {:  
nkeynes@671
  2103
    COUNT_INST(I_FMOV7);
nkeynes@586
  2104
    check_fpuen();
nkeynes@991
  2105
    load_reg( REG_EAX, Rm );
nkeynes@991
  2106
    ADDL_rbpdisp_r32( REG_OFFSET(r[0]), REG_EAX );
nkeynes@901
  2107
    if( sh4_x86.double_size ) {
nkeynes@991
  2108
        check_ralign64( REG_EAX );
nkeynes@991
  2109
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2110
        store_dr0( REG_EAX, FRn );
nkeynes@991
  2111
        load_reg( REG_EAX, Rm );
nkeynes@991
  2112
        ADDL_rbpdisp_r32( REG_OFFSET(r[0]), REG_EAX );
nkeynes@991
  2113
        LEAL_r32disp_r32( REG_EAX, 4, REG_EAX );
nkeynes@991
  2114
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2115
        store_dr1( REG_EAX, FRn );
nkeynes@901
  2116
    } else {
nkeynes@991
  2117
        check_ralign32( REG_EAX );
nkeynes@991
  2118
        MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2119
        store_fr( REG_EAX, FRn );
nkeynes@901
  2120
    }
nkeynes@417
  2121
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2122
:}
nkeynes@377
  2123
FLDI0 FRn {:  /* IFF PR=0 */
nkeynes@671
  2124
    COUNT_INST(I_FLDI0);
nkeynes@377
  2125
    check_fpuen();
nkeynes@901
  2126
    if( sh4_x86.double_prec == 0 ) {
nkeynes@991
  2127
        XORL_r32_r32( REG_EAX, REG_EAX );
nkeynes@991
  2128
        store_fr( REG_EAX, FRn );
nkeynes@901
  2129
    }
nkeynes@417
  2130
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2131
:}
nkeynes@377
  2132
FLDI1 FRn {:  /* IFF PR=0 */
nkeynes@671
  2133
    COUNT_INST(I_FLDI1);
nkeynes@377
  2134
    check_fpuen();
nkeynes@901
  2135
    if( sh4_x86.double_prec == 0 ) {
nkeynes@995
  2136
        MOVL_imm32_r32( 0x3F800000, REG_EAX );
nkeynes@991
  2137
        store_fr( REG_EAX, FRn );
nkeynes@901
  2138
    }
nkeynes@377
  2139
:}
nkeynes@377
  2140
nkeynes@377
  2141
FLOAT FPUL, FRn {:  
nkeynes@671
  2142
    COUNT_INST(I_FLOAT);
nkeynes@377
  2143
    check_fpuen();
nkeynes@991
  2144
    FILD_rbpdisp(R_FPUL);
nkeynes@901
  2145
    if( sh4_x86.double_prec ) {
nkeynes@901
  2146
        pop_dr( FRn );
nkeynes@901
  2147
    } else {
nkeynes@901
  2148
        pop_fr( FRn );
nkeynes@901
  2149
    }
nkeynes@377
  2150
:}
nkeynes@377
  2151
FTRC FRm, FPUL {:  
nkeynes@671
  2152
    COUNT_INST(I_FTRC);
nkeynes@377
  2153
    check_fpuen();
nkeynes@901
  2154
    if( sh4_x86.double_prec ) {
nkeynes@901
  2155
        push_dr( FRm );
nkeynes@901
  2156
    } else {
nkeynes@901
  2157
        push_fr( FRm );
nkeynes@901
  2158
    }
nkeynes@995
  2159
    MOVP_immptr_rptr( &max_int, REG_ECX );
nkeynes@991
  2160
    FILD_r32disp( REG_ECX, 0 );
nkeynes@388
  2161
    FCOMIP_st(1);
nkeynes@991
  2162
    JNA_label( sat );
nkeynes@995
  2163
    MOVP_immptr_rptr( &min_int, REG_ECX );
nkeynes@995
  2164
    FILD_r32disp( REG_ECX, 0 );
nkeynes@995
  2165
    FCOMIP_st(1);              
nkeynes@995
  2166
    JAE_label( sat2 );            
nkeynes@995
  2167
    MOVP_immptr_rptr( &save_fcw, REG_EAX );
nkeynes@991
  2168
    FNSTCW_r32disp( REG_EAX, 0 );
nkeynes@995
  2169
    MOVP_immptr_rptr( &trunc_fcw, REG_EDX );
nkeynes@991
  2170
    FLDCW_r32disp( REG_EDX, 0 );
nkeynes@995
  2171
    FISTP_rbpdisp(R_FPUL);             
nkeynes@991
  2172
    FLDCW_r32disp( REG_EAX, 0 );
nkeynes@995
  2173
    JMP_label(end);             
nkeynes@388
  2174
nkeynes@388
  2175
    JMP_TARGET(sat);
nkeynes@388
  2176
    JMP_TARGET(sat2);
nkeynes@991
  2177
    MOVL_r32disp_r32( REG_ECX, 0, REG_ECX ); // 2
nkeynes@995
  2178
    MOVL_r32_rbpdisp( REG_ECX, R_FPUL );
nkeynes@388
  2179
    FPOP_st();
nkeynes@388
  2180
    JMP_TARGET(end);
nkeynes@417
  2181
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2182
:}
nkeynes@377
  2183
FLDS FRm, FPUL {:  
nkeynes@671
  2184
    COUNT_INST(I_FLDS);
nkeynes@377
  2185
    check_fpuen();
nkeynes@991
  2186
    load_fr( REG_EAX, FRm );
nkeynes@995
  2187
    MOVL_r32_rbpdisp( REG_EAX, R_FPUL );
nkeynes@377
  2188
:}
nkeynes@377
  2189
FSTS FPUL, FRn {:  
nkeynes@671
  2190
    COUNT_INST(I_FSTS);
nkeynes@377
  2191
    check_fpuen();
nkeynes@995
  2192
    MOVL_rbpdisp_r32( R_FPUL, REG_EAX );
nkeynes@991
  2193
    store_fr( REG_EAX, FRn );
nkeynes@377
  2194
:}
nkeynes@377
  2195
FCNVDS FRm, FPUL {:  
nkeynes@671
  2196
    COUNT_INST(I_FCNVDS);
nkeynes@377
  2197
    check_fpuen();
nkeynes@901
  2198
    if( sh4_x86.double_prec ) {
nkeynes@901
  2199
        push_dr( FRm );
nkeynes@901
  2200
        pop_fpul();
nkeynes@901
  2201
    }
nkeynes@377
  2202
:}
nkeynes@377
  2203
FCNVSD FPUL, FRn {:  
nkeynes@671
  2204
    COUNT_INST(I_FCNVSD);
nkeynes@377
  2205
    check_fpuen();
nkeynes@901
  2206
    if( sh4_x86.double_prec ) {
nkeynes@901
  2207
        push_fpul();
nkeynes@901
  2208
        pop_dr( FRn );
nkeynes@901
  2209
    }
nkeynes@377
  2210
:}
nkeynes@375
  2211
nkeynes@359
  2212
/* Floating point instructions */
nkeynes@374
  2213
FABS FRn {:  
nkeynes@671
  2214
    COUNT_INST(I_FABS);
nkeynes@377
  2215
    check_fpuen();
nkeynes@901
  2216
    if( sh4_x86.double_prec ) {
nkeynes@901
  2217
        push_dr(FRn);
nkeynes@901
  2218
        FABS_st0();
nkeynes@901
  2219
        pop_dr(FRn);
nkeynes@901
  2220
    } else {
nkeynes@901
  2221
        push_fr(FRn);
nkeynes@901
  2222
        FABS_st0();
nkeynes@901
  2223
        pop_fr(FRn);
nkeynes@901
  2224
    }
nkeynes@374
  2225
:}
nkeynes@377
  2226
FADD FRm, FRn {:  
nkeynes@671
  2227
    COUNT_INST(I_FADD);
nkeynes@377
  2228
    check_fpuen();
nkeynes@901
  2229
    if( sh4_x86.double_prec ) {
nkeynes@901
  2230
        push_dr(FRm);
nkeynes@901
  2231
        push_dr(FRn);
nkeynes@901
  2232
        FADDP_st(1);
nkeynes@901
  2233
        pop_dr(FRn);
nkeynes@901
  2234
    } else {
nkeynes@901
  2235
        push_fr(FRm);
nkeynes@901
  2236
        push_fr(FRn);
nkeynes@901
  2237
        FADDP_st(1);
nkeynes@901
  2238
        pop_fr(FRn);
nkeynes@901
  2239
    }
nkeynes@375
  2240
:}
nkeynes@377
  2241
FDIV FRm, FRn {:  
nkeynes@671
  2242
    COUNT_INST(I_FDIV);
nkeynes@377
  2243
    check_fpuen();
nkeynes@901
  2244
    if( sh4_x86.double_prec ) {
nkeynes@901
  2245
        push_dr(FRn);
nkeynes@901
  2246
        push_dr(FRm);
nkeynes@901
  2247
        FDIVP_st(1);
nkeynes@901
  2248
        pop_dr(FRn);
nkeynes@901
  2249
    } else {
nkeynes@901
  2250
        push_fr(FRn);
nkeynes@901
  2251
        push_fr(FRm);
nkeynes@901
  2252
        FDIVP_st(1);
nkeynes@901
  2253
        pop_fr(FRn);
nkeynes@901
  2254
    }
nkeynes@375
  2255
:}
nkeynes@375
  2256
FMAC FR0, FRm, FRn {:  
nkeynes@671
  2257
    COUNT_INST(I_FMAC);
nkeynes@377
  2258
    check_fpuen();
nkeynes@901
  2259
    if( sh4_x86.double_prec ) {
nkeynes@901
  2260
        push_dr( 0 );
nkeynes@901
  2261
        push_dr( FRm );
nkeynes@901
  2262
        FMULP_st(1);
nkeynes@901
  2263
        push_dr( FRn );
nkeynes@901
  2264
        FADDP_st(1);
nkeynes@901
  2265
        pop_dr( FRn );
nkeynes@901
  2266
    } else {
nkeynes@901
  2267
        push_fr( 0 );
nkeynes@901
  2268
        push_fr( FRm );
nkeynes@901
  2269
        FMULP_st(1);
nkeynes@901
  2270
        push_fr( FRn );
nkeynes@901
  2271
        FADDP_st(1);
nkeynes@901
  2272
        pop_fr( FRn );
nkeynes@901
  2273
    }
nkeynes@375
  2274
:}
nkeynes@375
  2275
nkeynes@377
  2276
FMUL FRm, FRn {:  
nkeynes@671
  2277
    COUNT_INST(I_FMUL);
nkeynes@377
  2278
    check_fpuen();
nkeynes@901
  2279
    if( sh4_x86.double_prec ) {
nkeynes@901
  2280
        push_dr(FRm);
nkeynes@901
  2281
        push_dr(FRn);
nkeynes@901
  2282
        FMULP_st(1);
nkeynes@901
  2283
        pop_dr(FRn);
nkeynes@901
  2284
    } else {
nkeynes@901
  2285
        push_fr(FRm);
nkeynes@901
  2286
        push_fr(FRn);
nkeynes@901
  2287
        FMULP_st(1);
nkeynes@901
  2288
        pop_fr(FRn);
nkeynes@901
  2289
    }
nkeynes@377
  2290
:}
nkeynes@377
  2291
FNEG FRn {:  
nkeynes@671
  2292
    COUNT_INST(I_FNEG);
nkeynes@377
  2293
    check_fpuen();
nkeynes@901
  2294
    if( sh4_x86.double_prec ) {
nkeynes@901
  2295
        push_dr(FRn);
nkeynes@901
  2296
        FCHS_st0();
nkeynes@901
  2297
        pop_dr(FRn);
nkeynes@901
  2298
    } else {
nkeynes@901
  2299
        push_fr(FRn);
nkeynes@901
  2300
        FCHS_st0();
nkeynes@901
  2301
        pop_fr(FRn);
nkeynes@901
  2302
    }
nkeynes@377
  2303
:}
nkeynes@377
  2304
FSRRA FRn {:  
nkeynes@671
  2305
    COUNT_INST(I_FSRRA);
nkeynes@377
  2306
    check_fpuen();
nkeynes@901
  2307
    if( sh4_x86.double_prec == 0 ) {
nkeynes@901
  2308
        FLD1_st0();
nkeynes@901
  2309
        push_fr(FRn);
nkeynes@901
  2310
        FSQRT_st0();
nkeynes@901
  2311
        FDIVP_st(1);
nkeynes@901
  2312
        pop_fr(FRn);
nkeynes@901
  2313
    }
nkeynes@377
  2314
:}
nkeynes@377
  2315
FSQRT FRn {:  
nkeynes@671
  2316
    COUNT_INST(I_FSQRT);
nkeynes@377
  2317
    check_fpuen();
nkeynes@901
  2318
    if( sh4_x86.double_prec ) {
nkeynes@901
  2319
        push_dr(FRn);
nkeynes@901
  2320
        FSQRT_st0();
nkeynes@901
  2321
        pop_dr(FRn);
nkeynes@901
  2322
    } else {
nkeynes@901
  2323
        push_fr(FRn);
nkeynes@901
  2324
        FSQRT_st0();
nkeynes@901
  2325
        pop_fr(FRn);
nkeynes@901
  2326
    }
nkeynes@377
  2327
:}
nkeynes@377
  2328
FSUB FRm, FRn {:  
nkeynes@671
  2329
    COUNT_INST(I_FSUB);
nkeynes@377
  2330
    check_fpuen();
nkeynes@901
  2331
    if( sh4_x86.double_prec ) {
nkeynes@901
  2332
        push_dr(FRn);
nkeynes@901
  2333
        push_dr(FRm);
nkeynes@901
  2334
        FSUBP_st(1);
nkeynes@901
  2335
        pop_dr(FRn);
nkeynes@901
  2336
    } else {
nkeynes@901
  2337
        push_fr(FRn);
nkeynes@901
  2338
        push_fr(FRm);
nkeynes@901
  2339
        FSUBP_st(1);
nkeynes@901
  2340
        pop_fr(FRn);
nkeynes@901
  2341
    }
nkeynes@377
  2342
:}
nkeynes@377
  2343
nkeynes@377
  2344
FCMP/EQ FRm, FRn {:  
nkeynes@671
  2345
    COUNT_INST(I_FCMPEQ);
nkeynes@377
  2346
    check_fpuen();
nkeynes@901
  2347
    if( sh4_x86.double_prec ) {
nkeynes@901
  2348
        push_dr(FRm);
nkeynes@901
  2349
        push_dr(FRn);
nkeynes@901
  2350
    } else {
nkeynes@901
  2351
        push_fr(FRm);
nkeynes@901
  2352
        push_fr(FRn);
nkeynes@901
  2353
    }
nkeynes@377
  2354
    FCOMIP_st(1);
nkeynes@377
  2355
    SETE_t();
nkeynes@377
  2356
    FPOP_st();
nkeynes@901
  2357
    sh4_x86.tstate = TSTATE_E;
nkeynes@377
  2358
:}
nkeynes@377
  2359
FCMP/GT FRm, FRn {:  
nkeynes@671
  2360
    COUNT_INST(I_FCMPGT);
nkeynes@377
  2361
    check_fpuen();
nkeynes@901
  2362
    if( sh4_x86.double_prec ) {
nkeynes@901
  2363
        push_dr(FRm);
nkeynes@901
  2364
        push_dr(FRn);
nkeynes@901
  2365
    } else {
nkeynes@901
  2366
        push_fr(FRm);
nkeynes@901
  2367
        push_fr(FRn);
nkeynes@901
  2368
    }
nkeynes@377
  2369
    FCOMIP_st(1);
nkeynes@377
  2370
    SETA_t();
nkeynes@377
  2371
    FPOP_st();
nkeynes@901
  2372
    sh4_x86.tstate = TSTATE_A;
nkeynes@377
  2373
:}
nkeynes@377
  2374
nkeynes@377
  2375
FSCA FPUL, FRn {:  
nkeynes@671
  2376
    COUNT_INST(I_FSCA);
nkeynes@377
  2377
    check_fpuen();
nkeynes@901
  2378
    if( sh4_x86.double_prec == 0 ) {
nkeynes@991
  2379
        LEAP_rbpdisp_rptr( REG_OFFSET(fr[0][FRn&0x0E]), REG_EDX );
nkeynes@995
  2380
        MOVL_rbpdisp_r32( R_FPUL, REG_EAX );
nkeynes@995
  2381
        CALL2_ptr_r32_r32( sh4_fsca, REG_EAX, REG_EDX );
nkeynes@901
  2382
    }
nkeynes@417
  2383
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2384
:}
nkeynes@377
  2385
FIPR FVm, FVn {:  
nkeynes@671
  2386
    COUNT_INST(I_FIPR);
nkeynes@377
  2387
    check_fpuen();
nkeynes@901
  2388
    if( sh4_x86.double_prec == 0 ) {
nkeynes@904
  2389
        if( sh4_x86.sse3_enabled ) {
nkeynes@991
  2390
            MOVAPS_rbpdisp_xmm( REG_OFFSET(fr[0][FVm<<2]), 4 );
nkeynes@991
  2391
            MULPS_rbpdisp_xmm( REG_OFFSET(fr[0][FVn<<2]), 4 );
nkeynes@903
  2392
            HADDPS_xmm_xmm( 4, 4 ); 
nkeynes@903
  2393
            HADDPS_xmm_xmm( 4, 4 );
nkeynes@991
  2394
            MOVSS_xmm_rbpdisp( 4, REG_OFFSET(fr[0][(FVn<<2)+2]) );
nkeynes@903
  2395
        } else {
nkeynes@904
  2396
            push_fr( FVm<<2 );
nkeynes@903
  2397
            push_fr( FVn<<2 );
nkeynes@903
  2398
            FMULP_st(1);
nkeynes@903
  2399
            push_fr( (FVm<<2)+1);
nkeynes@903
  2400
            push_fr( (FVn<<2)+1);
nkeynes@903
  2401
            FMULP_st(1);
nkeynes@903
  2402
            FADDP_st(1);
nkeynes@903
  2403
            push_fr( (FVm<<2)+2);
nkeynes@903
  2404
            push_fr( (FVn<<2)+2);
nkeynes@903
  2405
            FMULP_st(1);
nkeynes@903
  2406
            FADDP_st(1);
nkeynes@903
  2407
            push_fr( (FVm<<2)+3);
nkeynes@903
  2408
            push_fr( (FVn<<2)+3);
nkeynes@903
  2409
            FMULP_st(1);
nkeynes@903
  2410
            FADDP_st(1);
nkeynes@903
  2411
            pop_fr( (FVn<<2)+3);
nkeynes@904
  2412
        }
nkeynes@901
  2413
    }
nkeynes@377
  2414
:}
nkeynes@377
  2415
FTRV XMTRX, FVn {:  
nkeynes@671
  2416
    COUNT_INST(I_FTRV);
nkeynes@377
  2417
    check_fpuen();
nkeynes@901
  2418
    if( sh4_x86.double_prec == 0 ) {
nkeynes@903
  2419
        if( sh4_x86.sse3_enabled ) {
nkeynes@991
  2420
            MOVAPS_rbpdisp_xmm( REG_OFFSET(fr[1][0]), 1 ); // M1  M0  M3  M2
nkeynes@991
  2421
            MOVAPS_rbpdisp_xmm( REG_OFFSET(fr[1][4]), 0 ); // M5  M4  M7  M6
nkeynes@991
  2422
            MOVAPS_rbpdisp_xmm( REG_OFFSET(fr[1][8]), 3 ); // M9  M8  M11 M10
nkeynes@991
  2423
            MOVAPS_rbpdisp_xmm( REG_OFFSET(fr[1][12]), 2 );// M13 M12 M15 M14
nkeynes@903
  2424
nkeynes@991
  2425
            MOVSLDUP_rbpdisp_xmm( REG_OFFSET(fr[0][FVn<<2]), 4 ); // V1 V1 V3 V3
nkeynes@991
  2426
            MOVSHDUP_rbpdisp_xmm( REG_OFFSET(fr[0][FVn<<2]), 5 ); // V0 V0 V2 V2
nkeynes@991
  2427
            MOV_xmm_xmm( 4, 6 );
nkeynes@991
  2428
            MOV_xmm_xmm( 5, 7 );
nkeynes@903
  2429
            MOVLHPS_xmm_xmm( 4, 4 );  // V1 V1 V1 V1
nkeynes@903
  2430
            MOVHLPS_xmm_xmm( 6, 6 );  // V3 V3 V3 V3
nkeynes@903
  2431
            MOVLHPS_xmm_xmm( 5, 5 );  // V0 V0 V0 V0
nkeynes@903
  2432
            MOVHLPS_xmm_xmm( 7, 7 );  // V2 V2 V2 V2
nkeynes@903
  2433
            MULPS_xmm_xmm( 0, 4 );
nkeynes@903
  2434
            MULPS_xmm_xmm( 1, 5 );
nkeynes@903
  2435
            MULPS_xmm_xmm( 2, 6 );
nkeynes@903
  2436
            MULPS_xmm_xmm( 3, 7 );
nkeynes@903
  2437
            ADDPS_xmm_xmm( 5, 4 );
nkeynes@903
  2438
            ADDPS_xmm_xmm( 7, 6 );
nkeynes@903
  2439
            ADDPS_xmm_xmm( 6, 4 );
nkeynes@991
  2440
            MOVAPS_xmm_rbpdisp( 4, REG_OFFSET(fr[0][FVn<<2]) );
nkeynes@903
  2441
        } else {
nkeynes@991
  2442
            LEAP_rbpdisp_rptr( REG_OFFSET(fr[0][FVn<<2]), REG_EAX );
nkeynes@995
  2443
            CALL1_ptr_r32( sh4_ftrv, REG_EAX );
nkeynes@903
  2444
        }
nkeynes@901
  2445
    }
nkeynes@417
  2446
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2447
:}
nkeynes@377
  2448
nkeynes@377
  2449
FRCHG {:  
nkeynes@671
  2450
    COUNT_INST(I_FRCHG);
nkeynes@377
  2451
    check_fpuen();
nkeynes@991
  2452
    XORL_imms_rbpdisp( FPSCR_FR, R_FPSCR );
nkeynes@995
  2453
    CALL_ptr( sh4_switch_fr_banks );
nkeynes@417
  2454
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@377
  2455
:}
nkeynes@377
  2456
FSCHG {:  
nkeynes@671
  2457
    COUNT_INST(I_FSCHG);
nkeynes@377
  2458
    check_fpuen();
nkeynes@991
  2459
    XORL_imms_rbpdisp( FPSCR_SZ, R_FPSCR);
nkeynes@991
  2460
    XORL_imms_rbpdisp( FPSCR_SZ, REG_OFFSET(xlat_sh4_mode) );
nkeynes@417
  2461
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@901
  2462
    sh4_x86.double_size = !sh4_x86.double_size;
nkeynes@377
  2463
:}
nkeynes@359
  2464
nkeynes@359
  2465
/* Processor control instructions */
nkeynes@368
  2466
LDC Rm, SR {:
nkeynes@671
  2467
    COUNT_INST(I_LDCSR);
nkeynes@386
  2468
    if( sh4_x86.in_delay_slot ) {
nkeynes@386
  2469
	SLOTILLEGAL();
nkeynes@386
  2470
    } else {
nkeynes@386
  2471
	check_priv();
nkeynes@991
  2472
	load_reg( REG_EAX, Rm );
nkeynes@995
  2473
	CALL1_ptr_r32( sh4_write_sr, REG_EAX );
nkeynes@386
  2474
	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  2475
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@953
  2476
	return 2;
nkeynes@386
  2477
    }
nkeynes@368
  2478
:}
nkeynes@359
  2479
LDC Rm, GBR {: 
nkeynes@671
  2480
    COUNT_INST(I_LDC);
nkeynes@991
  2481
    load_reg( REG_EAX, Rm );
nkeynes@995
  2482
    MOVL_r32_rbpdisp( REG_EAX, R_GBR );
nkeynes@359
  2483
:}
nkeynes@359
  2484
LDC Rm, VBR {:  
nkeynes@671
  2485
    COUNT_INST(I_LDC);
nkeynes@386
  2486
    check_priv();
nkeynes@991
  2487
    load_reg( REG_EAX, Rm );
nkeynes@995
  2488
    MOVL_r32_rbpdisp( REG_EAX, R_VBR );
nkeynes@417
  2489
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2490
:}
nkeynes@359
  2491
LDC Rm, SSR {:  
nkeynes@671
  2492
    COUNT_INST(I_LDC);
nkeynes@386
  2493
    check_priv();
nkeynes@991
  2494
    load_reg( REG_EAX, Rm );
nkeynes@995
  2495
    MOVL_r32_rbpdisp( REG_EAX, R_SSR );
nkeynes@417
  2496
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2497
:}
nkeynes@359
  2498
LDC Rm, SGR {:  
nkeynes@671
  2499
    COUNT_INST(I_LDC);
nkeynes@386
  2500
    check_priv();
nkeynes@991
  2501
    load_reg( REG_EAX, Rm );
nkeynes@995
  2502
    MOVL_r32_rbpdisp( REG_EAX, R_SGR );
nkeynes@417
  2503
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2504
:}
nkeynes@359
  2505
LDC Rm, SPC {:  
nkeynes@671
  2506
    COUNT_INST(I_LDC);
nkeynes@386
  2507
    check_priv();
nkeynes@991
  2508
    load_reg( REG_EAX, Rm );
nkeynes@995
  2509
    MOVL_r32_rbpdisp( REG_EAX, R_SPC );
nkeynes@417
  2510
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2511
:}
nkeynes@359
  2512
LDC Rm, DBR {:  
nkeynes@671
  2513
    COUNT_INST(I_LDC);
nkeynes@386
  2514
    check_priv();
nkeynes@991
  2515
    load_reg( REG_EAX, Rm );
nkeynes@995
  2516
    MOVL_r32_rbpdisp( REG_EAX, R_DBR );
nkeynes@417
  2517
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2518
:}
nkeynes@374
  2519
LDC Rm, Rn_BANK {:  
nkeynes@671
  2520
    COUNT_INST(I_LDC);
nkeynes@386
  2521
    check_priv();
nkeynes@991
  2522
    load_reg( REG_EAX, Rm );
nkeynes@995
  2523
    MOVL_r32_rbpdisp( REG_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
nkeynes@417
  2524
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@374
  2525
:}
nkeynes@359
  2526
LDC.L @Rm+, GBR {:  
nkeynes@671
  2527
    COUNT_INST(I_LDCM);
nkeynes@991
  2528
    load_reg( REG_EAX, Rm );
nkeynes@991
  2529
    check_ralign32( REG_EAX );
nkeynes@991
  2530
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2531
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2532
    MOVL_r32_rbpdisp( REG_EAX, R_GBR );
nkeynes@417
  2533
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2534
:}
nkeynes@368
  2535
LDC.L @Rm+, SR {:
nkeynes@671
  2536
    COUNT_INST(I_LDCSRM);
nkeynes@386
  2537
    if( sh4_x86.in_delay_slot ) {
nkeynes@386
  2538
	SLOTILLEGAL();
nkeynes@386
  2539
    } else {
nkeynes@586
  2540
	check_priv();
nkeynes@991
  2541
	load_reg( REG_EAX, Rm );
nkeynes@991
  2542
	check_ralign32( REG_EAX );
nkeynes@991
  2543
	MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2544
	ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2545
	CALL1_ptr_r32( sh4_write_sr, REG_EAX );
nkeynes@386
  2546
	sh4_x86.fpuen_checked = FALSE;
nkeynes@417
  2547
	sh4_x86.tstate = TSTATE_NONE;
nkeynes@953
  2548
	return 2;
nkeynes@386
  2549
    }
nkeynes@359
  2550
:}
nkeynes@359
  2551
LDC.L @Rm+, VBR {:  
nkeynes@671
  2552
    COUNT_INST(I_LDCM);
nkeynes@586
  2553
    check_priv();
nkeynes@991
  2554
    load_reg( REG_EAX, Rm );
nkeynes@991
  2555
    check_ralign32( REG_EAX );
nkeynes@991
  2556
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2557
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2558
    MOVL_r32_rbpdisp( REG_EAX, R_VBR );
nkeynes@417
  2559
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2560
:}
nkeynes@359
  2561
LDC.L @Rm+, SSR {:
nkeynes@671
  2562
    COUNT_INST(I_LDCM);
nkeynes@586
  2563
    check_priv();
nkeynes@991
  2564
    load_reg( REG_EAX, Rm );
nkeynes@991
  2565
    check_ralign32( REG_EAX );
nkeynes@991
  2566
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2567
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2568
    MOVL_r32_rbpdisp( REG_EAX, R_SSR );
nkeynes@417
  2569
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2570
:}
nkeynes@359
  2571
LDC.L @Rm+, SGR {:  
nkeynes@671
  2572
    COUNT_INST(I_LDCM);
nkeynes@586
  2573
    check_priv();
nkeynes@991
  2574
    load_reg( REG_EAX, Rm );
nkeynes@991
  2575
    check_ralign32( REG_EAX );
nkeynes@991
  2576
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2577
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2578
    MOVL_r32_rbpdisp( REG_EAX, R_SGR );
nkeynes@417
  2579
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2580
:}
nkeynes@359
  2581
LDC.L @Rm+, SPC {:  
nkeynes@671
  2582
    COUNT_INST(I_LDCM);
nkeynes@586
  2583
    check_priv();
nkeynes@991
  2584
    load_reg( REG_EAX, Rm );
nkeynes@991
  2585
    check_ralign32( REG_EAX );
nkeynes@991
  2586
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2587
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2588
    MOVL_r32_rbpdisp( REG_EAX, R_SPC );
nkeynes@417
  2589
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2590
:}
nkeynes@359
  2591
LDC.L @Rm+, DBR {:  
nkeynes@671
  2592
    COUNT_INST(I_LDCM);
nkeynes@586
  2593
    check_priv();
nkeynes@991
  2594
    load_reg( REG_EAX, Rm );
nkeynes@991
  2595
    check_ralign32( REG_EAX );
nkeynes@991
  2596
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2597
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2598
    MOVL_r32_rbpdisp( REG_EAX, R_DBR );
nkeynes@417
  2599
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2600
:}
nkeynes@359
  2601
LDC.L @Rm+, Rn_BANK {:  
nkeynes@671
  2602
    COUNT_INST(I_LDCM);
nkeynes@586
  2603
    check_priv();
nkeynes@991
  2604
    load_reg( REG_EAX, Rm );
nkeynes@991
  2605
    check_ralign32( REG_EAX );
nkeynes@991
  2606
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2607
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2608
    MOVL_r32_rbpdisp( REG_EAX, REG_OFFSET(r_bank[Rn_BANK]) );
nkeynes@417
  2609
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2610
:}
nkeynes@626
  2611
LDS Rm, FPSCR {:
nkeynes@673
  2612
    COUNT_INST(I_LDSFPSCR);
nkeynes@626
  2613
    check_fpuen();
nkeynes@991
  2614
    load_reg( REG_EAX, Rm );
nkeynes@995
  2615
    CALL1_ptr_r32( sh4_write_fpscr, REG_EAX );
nkeynes@417
  2616
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@901
  2617
    return 2;
nkeynes@359
  2618
:}
nkeynes@359
  2619
LDS.L @Rm+, FPSCR {:  
nkeynes@673
  2620
    COUNT_INST(I_LDSFPSCRM);
nkeynes@626
  2621
    check_fpuen();
nkeynes@991
  2622
    load_reg( REG_EAX, Rm );
nkeynes@991
  2623
    check_ralign32( REG_EAX );
nkeynes@991
  2624
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2625
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2626
    CALL1_ptr_r32( sh4_write_fpscr, REG_EAX );
nkeynes@417
  2627
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@901
  2628
    return 2;
nkeynes@359
  2629
:}
nkeynes@359
  2630
LDS Rm, FPUL {:  
nkeynes@671
  2631
    COUNT_INST(I_LDS);
nkeynes@626
  2632
    check_fpuen();
nkeynes@991
  2633
    load_reg( REG_EAX, Rm );
nkeynes@995
  2634
    MOVL_r32_rbpdisp( REG_EAX, R_FPUL );
nkeynes@359
  2635
:}
nkeynes@359
  2636
LDS.L @Rm+, FPUL {:  
nkeynes@671
  2637
    COUNT_INST(I_LDSM);
nkeynes@626
  2638
    check_fpuen();
nkeynes@991
  2639
    load_reg( REG_EAX, Rm );
nkeynes@991
  2640
    check_ralign32( REG_EAX );
nkeynes@991
  2641
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2642
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2643
    MOVL_r32_rbpdisp( REG_EAX, R_FPUL );
nkeynes@417
  2644
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2645
:}
nkeynes@359
  2646
LDS Rm, MACH {: 
nkeynes@671
  2647
    COUNT_INST(I_LDS);
nkeynes@991
  2648
    load_reg( REG_EAX, Rm );
nkeynes@995
  2649
    MOVL_r32_rbpdisp( REG_EAX, R_MACH );
nkeynes@359
  2650
:}
nkeynes@359
  2651
LDS.L @Rm+, MACH {:  
nkeynes@671
  2652
    COUNT_INST(I_LDSM);
nkeynes@991
  2653
    load_reg( REG_EAX, Rm );
nkeynes@991
  2654
    check_ralign32( REG_EAX );
nkeynes@991
  2655
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2656
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2657
    MOVL_r32_rbpdisp( REG_EAX, R_MACH );
nkeynes@417
  2658
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2659
:}
nkeynes@359
  2660
LDS Rm, MACL {:  
nkeynes@671
  2661
    COUNT_INST(I_LDS);
nkeynes@991
  2662
    load_reg( REG_EAX, Rm );
nkeynes@995
  2663
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@359
  2664
:}
nkeynes@359
  2665
LDS.L @Rm+, MACL {:  
nkeynes@671
  2666
    COUNT_INST(I_LDSM);
nkeynes@991
  2667
    load_reg( REG_EAX, Rm );
nkeynes@991
  2668
    check_ralign32( REG_EAX );
nkeynes@991
  2669
    MEM_READ_LONG( REG_EAX, REG_EAX );
nkeynes@991
  2670
    ADDL_imms_rbpdisp( 4, REG_OFFSET(r[Rm]) );
nkeynes@995
  2671
    MOVL_r32_rbpdisp( REG_EAX, R_MACL );
nkeynes@417
  2672
    sh4_x86.tstate = TSTATE_NONE;
nkeynes@359
  2673
:}
nkeynes@359
  2674
LDS Rm, PR {:  
nkeynes@671
  2675
    COUNT_INST(I_LDS);
nkeynes@991
  2676
    load_reg( REG_EAX, Rm );
nkeynes@995
  2677
    MOVL_r32_rbpdisp( REG_EAX, R_PR );
nkeynes@359
  2678
:}
nkeynes@359
  2679
LDS.L @Rm+, PR {:  
nkeynes@671
  2680
    COUNT_INST(I_LDSM);
nkeynes@991
  2681
    load_reg( REG_EAX, Rm );
nkeynes@991
  2682
    check_ralign32( REG_EAX );