OSDN Git Service

Fix movw on x86/x86_64 to accept any 16bits immediate.
authorNicolas Geoffray <ngeoffray@google.com>
Tue, 7 Oct 2014 13:54:48 +0000 (14:54 +0100)
committerNicolas Geoffray <ngeoffray@google.com>
Tue, 7 Oct 2014 13:54:48 +0000 (14:54 +0100)
Change-Id: I282eece0cd497431f207cec61852b4585ed3655c

compiler/utils/x86/assembler_x86.cc
compiler/utils/x86_64/assembler_x86_64.cc
test/407-arrays/src/Main.java

index a2cbd8b..4c7c4e9 100644 (file)
@@ -248,7 +248,7 @@ void X86Assembler::movw(const Address& dst, const Immediate& imm) {
   EmitOperandSizeOverride();
   EmitUint8(0xC7);
   EmitOperand(0, dst);
-  CHECK(imm.is_int16());
+  CHECK(imm.is_uint16() || imm.is_int16());
   EmitUint8(imm.value() & 0xFF);
   EmitUint8(imm.value() >> 8);
 }
index ade7a13..17339ae 100644 (file)
@@ -298,7 +298,7 @@ void X86_64Assembler::movw(const Address& dst, const Immediate& imm) {
   EmitOptionalRex32(dst);
   EmitUint8(0xC7);
   EmitOperand(Register::RAX, dst);
-  CHECK(imm.is_int16());
+  CHECK(imm.is_uint16() || imm.is_int16());
   EmitUint8(imm.value() & 0xFF);
   EmitUint8(imm.value() >> 8);
 }
index b5e95b0..d5c5604 100644 (file)
@@ -70,6 +70,15 @@ public class Main extends TestCase {
     chars[index] = 'd';
     assertEquals('d', chars[index]);
 
+    chars[0] = 65535;
+    assertEquals(65535, chars[0]);
+    // Do an update between the two max value updates, to avoid
+    // optimizing the second away.
+    chars[index] = 0;
+    assertEquals(0, chars[index]);
+    chars[index] = 65535;
+    assertEquals(65535, chars[index]);
+
     shorts[0] = -42;
     assertEquals(-42, shorts[0]);
     shorts[index] = -84;
@@ -86,7 +95,13 @@ public class Main extends TestCase {
     Object o2 = new Object();
     objects[index] = o2;
     assertEquals(o2, objects[index]);
+    // Longs are initially not supported in the linear scan register allocator
+    // on 32bits. So we call out a long helper to ensure this method gets
+    // optimized.
+    $opt$testLongWrites(longs, index);
+  }
 
+  public static void $opt$testLongWrites(long[] longs, int index) {
     long l = -21876876876876876L;
     longs[0] = l;
     assertEquals(l, longs[0]);