From 41a80fce20a9d22279c5c5ee4f296c24beab17a9 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 17 Jan 2016 17:02:38 +0100 Subject: [PATCH] x86emitter: finally support 64 bits instructions Note: a couple of instructions don't support REX prefix. Some exception ought to be implemented later --- common/include/x86emitter/internal.h | 15 ++++++++++----- common/src/x86emitter/simd.cpp | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/include/x86emitter/internal.h b/common/include/x86emitter/internal.h index ef6eadc2e3..f24d660f27 100644 --- a/common/include/x86emitter/internal.h +++ b/common/include/x86emitter/internal.h @@ -50,10 +50,10 @@ namespace x86Emitter { template< typename T1, typename T2 > __emitinline void xOpWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) { - if( prefix != 0 ) - xWrite16( (opcode<<8) | prefix ); - else - xWrite8( opcode ); + if( prefix != 0 ) xWrite8( prefix ); + EmitRex( param1, param2 ); + + xWrite8( opcode ); EmitSibMagic( param1, param2 ); } @@ -62,6 +62,7 @@ namespace x86Emitter { void xOpAccWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) { if( prefix != 0 ) xWrite8( prefix ); + EmitRex( param1, param2 ); xWrite8( opcode ); } @@ -80,7 +81,11 @@ namespace x86Emitter { template< typename T1, typename T2 > __emitinline void xOpWrite0F( u8 prefix, u16 opcode, const T1& param1, const T2& param2 ) { - SimdPrefix( prefix, opcode ); + if( prefix != 0 ) xWrite8( prefix ); + EmitRex( param1, param2 ); + + SimdPrefix( 0, opcode ); + EmitSibMagic( param1, param2 ); } diff --git a/common/src/x86emitter/simd.cpp b/common/src/x86emitter/simd.cpp index 2ea553539d..00af27f0f3 100644 --- a/common/src/x86emitter/simd.cpp +++ b/common/src/x86emitter/simd.cpp @@ -90,6 +90,9 @@ namespace x86Emitter { // __emitinline void SimdPrefix( u8 prefix, u16 opcode ) { +#ifdef __x86_64__ + pxAssertMsg(prefix == 0, "REX prefix must be just before the opcode"); +#endif const bool is16BitOpcode = ((opcode & 0xff) == 0x38) || ((opcode & 0xff) == 0x3a); // If the lower byte is not a valid prefix and the upper byte is non-zero it