diff --git a/pcsx2/x86/ix86/ix86.inl b/pcsx2/x86/ix86/ix86.inl index 15068f4823..606eaed417 100644 --- a/pcsx2/x86/ix86/ix86.inl +++ b/pcsx2/x86/ix86/ix86.inl @@ -41,7 +41,7 @@ emitterT void WriteRmOffset(x86IntRegType to, s32 offset) ModRM( 0, 0, 4 ); SibSB( 0, ESP, 4 ); } - else if( offset < 128 && offset >= -128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM( 1, 0, 4 ); SibSB( 0, ESP, 4 ); write8(offset); @@ -56,7 +56,7 @@ emitterT void WriteRmOffset(x86IntRegType to, s32 offset) if( offset == 0 ) { ModRM( 0, 0, to ); } - else if( offset < 128 && offset >= -128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM( 1, 0, to ); write8(offset); } @@ -74,7 +74,7 @@ emitterT void WriteRmOffsetFrom(x86IntRegType to, x86IntRegType from, int offset ModRM( 0, to, 0x4 ); SibSB( 0, 0x4, 0x4 ); } - else if( offset < 128 && offset >= -128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM( 1, to, 0x4 ); SibSB( 0, 0x4, 0x4 ); write8(offset); @@ -89,7 +89,7 @@ emitterT void WriteRmOffsetFrom(x86IntRegType to, x86IntRegType from, int offset if( offset == 0 ) { ModRM( 0, to, from ); } - else if( offset < 128 && offset >= -128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM( 1, to, from ); write8(offset); } @@ -401,8 +401,12 @@ emitterT void eMOV32RtoR( x86IntRegType to, x86IntRegType from ) emitterT void eMOV32RtoM( uptr to, x86IntRegType from ) { RexR(0, from); - write8( 0x89 ); - ModRM( 0, from, DISP32 ); + if (from == EAX) { + write8(0xA3); + } else { + write8( 0x89 ); + ModRM( 0, from, DISP32 ); + } write32( MEMADDR(to, 4) ); } @@ -410,8 +414,12 @@ emitterT void eMOV32RtoM( uptr to, x86IntRegType from ) emitterT void eMOV32MtoR( x86IntRegType to, uptr from ) { RexR(0, to); - write8( 0x8B ); - ModRM( 0, to, DISP32 ); + if (to == EAX) { + write8(0xA1); + } else { + write8( 0x8B ); + ModRM( 0, to, DISP32 ); + } write32( MEMADDR(from, 4) ); } @@ -1038,69 +1046,69 @@ emitterT void eADD64RtoR( x86IntRegType to, x86IntRegType from ) } /* add imm32 to EAX */ -emitterT void eADD32ItoEAX( u32 from ) +emitterT void eADD32ItoEAX( s32 imm ) { write8( 0x05 ); - write32( from ); + write32( imm ); } /* add imm32 to r32 */ -emitterT void eADD32ItoR( x86IntRegType to, u32 from ) +emitterT void eADD32ItoR( x86IntRegType to, s32 imm ) { RexB(0, to); - if(from < 0x80) + if (imm <= 127 && imm >= -128) { write8( 0x83 ); ModRM( 3, 0, to ); - write8( from ); + write8( (s8)imm ); } else { if ( to == EAX ) { - eADD32ItoEAX(from); + eADD32ItoEAX(imm); } else { write8( 0x81 ); ModRM( 3, 0, to ); - write32( from ); + write32( imm ); } } } /* add imm32 to m32 */ -emitterT void eADD32ItoM( uptr to, u32 from ) +emitterT void eADD32ItoM( uptr to, s32 imm ) { - /*if(from < 0x80) // crashes games in 64bit build; TODO: figure out why. + if(imm <= 127 && imm >= -128) { write8( 0x83 ); ModRM( 0, 0, DISP32 ); write32( MEMADDR(to, 8) ); - write8( from ); - } - else*/ + write8( imm ); + } + else { write8( 0x81 ); ModRM( 0, 0, DISP32 ); write32( MEMADDR(to, 8) ); - write32( from ); + write32( imm ); } } // add imm32 to [r32+off] -emitterT void eADD32ItoRmOffset( x86IntRegType to, u32 from, s32 offset) +emitterT void eADD32ItoRmOffset( x86IntRegType to, s32 imm, s32 offset) { RexB(0,to); - if(from < 0x80) + if(imm <= 127 && imm >= -128) { write8( 0x83 ); WriteRmOffset(to,offset); - write8(from); + write8(imm); } else { write8( 0x81 ); WriteRmOffset(to,offset); - write32(from); + write32(imm); } } @@ -1140,7 +1148,7 @@ emitterT void eADD16RtoR( x86IntRegType to , x86IntRegType from ) } /* add imm16 to r16 */ -emitterT void eADD16ItoR( x86IntRegType to, u16 from ) +emitterT void eADD16ItoR( x86IntRegType to, s16 imm ) { write8( 0x66 ); RexB(0,to); @@ -1148,39 +1156,39 @@ emitterT void eADD16ItoR( x86IntRegType to, u16 from ) if ( to == EAX) { write8( 0x05 ); - write16( from ); + write16( imm ); } - else if(from < 0x80) + else if(imm <= 127 && imm >= -128) { write8( 0x83 ); ModRM( 3, 0, to ); - write8((u8)from ); + write8((u8)imm ); } else { write8( 0x81 ); ModRM( 3, 0, to ); - write16( from ); + write16( imm ); } } /* add imm16 to m16 */ -emitterT void eADD16ItoM( uptr to, u16 from ) +emitterT void eADD16ItoM( uptr to, s16 imm ) { write8( 0x66 ); - if(from < 0x80) + if(imm <= 127 && imm >= -128) { write8( 0x83 ); ModRM( 0, 0, DISP32 ); write32( MEMADDR(to, 6) ); - write8((u8)from ); + write8((u8)imm ); } else { write8( 0x81 ); ModRM( 0, 0, DISP32 ); write32( MEMADDR(to, 6) ); - write16( from ); + write16( imm ); } } @@ -3250,7 +3258,7 @@ emitterT void eLEA16RtoR(x86IntRegType to, x86IntRegType from, u16 offset) eLEA32RtoR(to, from, offset); } -emitterT void eLEA32RtoR(x86IntRegType to, x86IntRegType from, u32 offset) +emitterT void eLEA32RtoR(x86IntRegType to, x86IntRegType from, s32 offset) { RexRB(0,to,from); write8(0x8d); @@ -3260,7 +3268,7 @@ emitterT void eLEA32RtoR(x86IntRegType to, x86IntRegType from, u32 offset) ModRM(1, to, from); write8(0x24); } - else if( offset < 128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM(1, to, from); write8(0x24); write8(offset); @@ -3275,7 +3283,7 @@ emitterT void eLEA32RtoR(x86IntRegType to, x86IntRegType from, u32 offset) if( offset == 0 && from != EBP && from!=ESP ) { ModRM(0, to, from); } - else if( offset < 128 ) { + else if( offset <= 127 && offset >= -128 ) { ModRM(1, to, from); write8(offset); }