OSDN Git Service

Fix braino in x64 assembler.
authorNicolas Geoffray <ngeoffray@google.com>
Thu, 18 Dec 2014 20:25:18 +0000 (20:25 +0000)
committerNicolas Geoffray <ngeoffray@google.com>
Thu, 18 Dec 2014 20:57:37 +0000 (20:57 +0000)
We need to compare the low bits, not the register directly.

Change-Id: I0a8f3901bacbc6002f904543bac9a2fbd7972305

compiler/utils/x86_64/assembler_x86_64.h
compiler/utils/x86_64/assembler_x86_64_test.cc

index 60ab475..b331712 100644 (file)
@@ -178,7 +178,7 @@ class Address : public Operand {
   }
 
   void Init(CpuRegister base_in, int32_t disp) {
-    if (disp == 0 && base_in.AsRegister() != RBP) {
+    if (disp == 0 && base_in.LowBits() != RBP) {
       SetModRM(0, base_in);
       if (base_in.LowBits() == RSP) {
         SetSIB(TIMES_1, CpuRegister(RSP), base_in);
@@ -208,7 +208,7 @@ class Address : public Operand {
 
   Address(CpuRegister base_in, CpuRegister index_in, ScaleFactor scale_in, int32_t disp) {
     CHECK_NE(index_in.AsRegister(), RSP);  // Illegal addressing mode.
-    if (disp == 0 && base_in.AsRegister() != RBP) {
+    if (disp == 0 && base_in.LowBits() != RBP) {
       SetModRM(0, CpuRegister(RSP));
       SetSIB(scale_in, index_in, base_in);
     } else if (disp >= -128 && disp <= 127) {
index 0ce809c..53827a9 100644 (file)
@@ -536,10 +536,16 @@ TEST_F(AssemblerX86_64Test, Movl) {
       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
   GetAssembler()->movl(x86_64::CpuRegister(x86_64::R8), x86_64::Address(
       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
+  GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
+      x86_64::CpuRegister(x86_64::R13), 0));
+  GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
+      x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0));
   const char* expected =
     "movl 0xc(%RDI,%RBX,4), %EAX\n"
     "movl 0xc(%RDI,%R9,4), %EAX\n"
-    "movl 0xc(%RDI,%R9,4), %R8d\n";
+    "movl 0xc(%RDI,%R9,4), %R8d\n"
+    "movl (%R13), %EAX\n"
+    "movl (%R13,%R9,1), %EAX\n";
 
   DriverStr(expected, "movl");
 }