x86emitter: align EmitRex interface on EmitSibMagic

This commit is contained in:
Gregory Hainaut 2016-01-17 12:06:08 +01:00
parent e50e9a5e65
commit f2ecfc99ad
2 changed files with 57 additions and 36 deletions

View File

@ -31,11 +31,12 @@ namespace x86Emitter {
extern void EmitSibMagic( const xRegisterBase& reg1, const void* src ); extern void EmitSibMagic( const xRegisterBase& reg1, const void* src );
extern void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib ); extern void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib );
void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 ); extern void EmitRex( uint regfield, const void* address );
void EmitRex( const xRegisterBase& reg1, const void* src ); extern void EmitRex( uint regfield, const xIndirectVoid& info );
void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ); extern void EmitRex( uint reg1, const xRegisterBase& reg2 );
void EmitRex( const xRegisterBase& reg1 ); extern void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 );
void EmitRex( const xIndirectVoid& sib ); extern void EmitRex( const xRegisterBase& reg1, const void* src );
extern void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib );
extern void _xMovRtoR( const xRegisterInt& to, const xRegisterInt& from ); extern void _xMovRtoR( const xRegisterInt& to, const xRegisterInt& from );

View File

@ -406,51 +406,71 @@ void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib )
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
__emitinline static void EmitRex(bool w, bool r, bool x, bool b)
{
#ifdef __x86_64__
u8 rex = 0x40 | (w << 3) | (r << 2) | (x << 1) | b;
if (rex != 0x40)
xWrite8(rex);
#endif
}
void EmitRex( uint regfield, const void* address )
{
pxAssert(0);
bool w = false;
bool r = false;
bool x = false;
bool b = false;
EmitRex(w, r, x, b);
}
void EmitRex( uint regfield, const xIndirectVoid& info )
{
bool w = info.Base.IsWide();
bool r = false;
bool x = false;
bool b = info.IsExtended();
EmitRex(w, r, x, b);
}
void EmitRex( uint reg1, const xRegisterBase& reg2 )
{
bool w = reg2.IsWide();
bool r = false;
bool x = false;
bool b = reg2.IsExtended();
EmitRex(w, r, x, b);
}
void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 ) void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 )
{ {
u8 w = reg1.IsWide() << 3; bool w = reg1.IsWide();
u8 r = reg1.IsExtended() << 2; bool r = reg1.IsExtended();
u8 x = 0; bool x = false;
u8 b = reg2.IsExtended(); bool b = reg2.IsExtended();
xWrite8( 0x40 | w | r | x | b ); EmitRex(w, r, x, b);
} }
void EmitRex( const xRegisterBase& reg1, const void* src ) void EmitRex( const xRegisterBase& reg1, const void* src )
{ {
pxAssert(0); //see fixme pxAssert(0); //see fixme
u8 w = reg1.IsWide() << 3; bool w = reg1.IsWide();
u8 r = reg1.IsExtended() << 2; bool r = reg1.IsExtended();
u8 x = 0; bool x = false;
u8 b = 0; // FIXME src.IsExtended(); bool b = false; // FIXME src.IsExtended();
xWrite8( 0x40 | w | r | x | b ); EmitRex(w, r, x, b);
} }
void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ) void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib )
{ {
u8 w = reg1.IsWide() << 3; u8 w = reg1.IsWide();
u8 r = reg1.IsExtended() << 2; u8 r = reg1.IsExtended();
u8 x = sib.Index.IsExtended() << 1; u8 x = sib.Index.IsExtended();
u8 b = sib.Base.IsExtended(); u8 b = sib.Base.IsExtended();
xWrite8( 0x40 | w | r | x | b ); EmitRex(w, r, x, b);
} }
void EmitRex( const xRegisterBase& reg1)
{
u8 w = reg1.IsWide() << 3;
u8 r = 0;
u8 x = 0;
u8 b = reg1.IsExtended();
xWrite8( 0x40 | w | r | x | b );
}
void EmitRex( const xIndirectVoid& sib)
{
u8 w = sib.Base.IsWide() << 3;
u8 r = 0;
u8 x = 0;
u8 b = sib.IsExtended();
xWrite8( 0x40 | w | r | x | b );
}
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// xSetPtr / xAlignPtr / xGetPtr / xAdvancePtr // xSetPtr / xAlignPtr / xGetPtr / xAdvancePtr