From: Julian Seward Date: Sat, 21 Apr 2012 08:18:02 +0000 (+0000) Subject: Ain_XDirect, Ain_XIndir: use short form encodings where possible. X-Git-Tag: svn/VALGRIND_3_8_1^2~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fea2e7594521f2ea7aefc3a6756bea2af909abbc;p=thirdparty%2Fvalgrind.git Ain_XDirect, Ain_XIndir: use short form encodings where possible. git-svn-id: svn://svn.valgrind.org/vex/trunk@2300 --- diff --git a/VEX/priv/host_amd64_defs.c b/VEX/priv/host_amd64_defs.c index 479a0c56b7..9a4f3105d7 100644 --- a/VEX/priv/host_amd64_defs.c +++ b/VEX/priv/host_amd64_defs.c @@ -2563,10 +2563,20 @@ Int emit_AMD64Instr ( /*MB_MOD*/Bool* is_profInc, } /* Update the guest RIP. */ - /* movabsq $dstGA, %r11 */ - *p++ = 0x49; - *p++ = 0xBB; - p = emit64(p, i->Ain.XDirect.dstGA); + if (fitsIn32Bits(i->Ain.XDirect.dstGA)) { + /* use a shorter encoding */ + /* movl sign-extend(dstGA), %r11 */ + *p++ = 0x49; + *p++ = 0xC7; + *p++ = 0xC3; + p = emit32(p, (UInt)i->Ain.XDirect.dstGA); + } else { + /* movabsq $dstGA, %r11 */ + *p++ = 0x49; + *p++ = 0xBB; + p = emit64(p, i->Ain.XDirect.dstGA); + } + /* movq %r11, amRIP */ *p++ = rexAMode_M(r11, i->Ain.XDirect.amRIP); *p++ = 0x89; @@ -2624,10 +2634,22 @@ Int emit_AMD64Instr ( /*MB_MOD*/Bool* is_profInc, *p++ = rexAMode_M(i->Ain.XIndir.dstGA, i->Ain.XIndir.amRIP); *p++ = 0x89; p = doAMode_M(p, i->Ain.XIndir.dstGA, i->Ain.XIndir.amRIP); - /* movabsq $disp_indir, %r11 */ - *p++ = 0x49; - *p++ = 0xBB; - p = emit64(p, Ptr_to_ULong(disp_cp_xindir)); + + /* get $disp_cp_xindir into %r11 */ + if (fitsIn32Bits(Ptr_to_ULong(disp_cp_xindir))) { + /* use a shorter encoding */ + /* movl sign-extend(disp_cp_xindir), %r11 */ + *p++ = 0x49; + *p++ = 0xC7; + *p++ = 0xC3; + p = emit32(p, (UInt)Ptr_to_ULong(disp_cp_xindir)); + } else { + /* movabsq $disp_cp_xindir, %r11 */ + *p++ = 0x49; + *p++ = 0xBB; + p = emit64(p, Ptr_to_ULong(disp_cp_xindir)); + } + /* jmp *%r11 */ *p++ = 0x41; *p++ = 0xFF;