]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Ain_XDirect, Ain_XIndir: use short form encodings where possible.
authorJulian Seward <jseward@acm.org>
Sat, 21 Apr 2012 08:18:02 +0000 (08:18 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 21 Apr 2012 08:18:02 +0000 (08:18 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@2300

VEX/priv/host_amd64_defs.c

index 479a0c56b714e628395e3645815a577a974e5b08..9a4f3105d7bf5e347aa58e95f54557933d3fb2b6 100644 (file)
@@ -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;