AArch64: Fix and enable reverseBytes intrinsic.

There is no revsh on arm64, use rev16 and sxth instead.

Change-Id: I5f9879352f0ad76b386c82cbf476894af888a64c
diff --git a/compiler/dex/quick/arm64/utility_arm64.cc b/compiler/dex/quick/arm64/utility_arm64.cc
index 22a4ec4..b2f5142 100644
--- a/compiler/dex/quick/arm64/utility_arm64.cc
+++ b/compiler/dex/quick/arm64/utility_arm64.cc
@@ -488,7 +488,9 @@
       break;
     case kOpRevsh:
       // Binary, but rm is encoded twice.
-      return NewLIR2(kA64Rev162rr | wide, r_dest_src1.GetReg(), r_src2.GetReg());
+      NewLIR2(kA64Rev162rr | wide, r_dest_src1.GetReg(), r_src2.GetReg());
+      // "sxth r1, r2" is "sbfm r1, r2, #0, #15"
+      return NewLIR4(kA64Sbfm4rrdd | wide, r_dest_src1.GetReg(), r_dest_src1.GetReg(), 0, 15);
       break;
     case kOp2Byte:
       DCHECK_EQ(shift, ENCODE_NO_SHIFT);
diff --git a/compiler/dex/quick/gen_invoke.cc b/compiler/dex/quick/gen_invoke.cc
index 55b68e6..b821fb3 100755
--- a/compiler/dex/quick/gen_invoke.cc
+++ b/compiler/dex/quick/gen_invoke.cc
@@ -1385,8 +1385,8 @@
 }
 
 bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
-  if (cu_->instruction_set == kMips || cu_->instruction_set == kArm64) {
-    // TODO - add Mips implementation; Enable Arm64.
+  if (cu_->instruction_set == kMips) {
+    // TODO - add Mips implementation.
     return false;
   }
   RegLocation rl_src_i = info->args[0];
diff --git a/test/082-inline-execute/src/Main.java b/test/082-inline-execute/src/Main.java
index f412034..cb7b0b3 100644
--- a/test/082-inline-execute/src/Main.java
+++ b/test/082-inline-execute/src/Main.java
@@ -34,6 +34,9 @@
     test_Math_max_F();
     test_Math_min_D();
     test_Math_max_D();
+    test_Short_reverseBytes();
+    test_Integer_reverseBytes();
+    test_Long_reverseBytes();
     test_Integer_reverse();
     test_Long_reverse();
     test_StrictMath_abs_I();
@@ -556,6 +559,34 @@
     Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
   }
 
+  public static void test_Short_reverseBytes() {
+      Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
+      Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
+      Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
+      Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
+      Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
+      Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
+      Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
+      Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
+  }
+
+  public static void test_Integer_reverseBytes() {
+      Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
+      Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
+      Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
+      Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
+      Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
+      Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
+  }
+
+  public static void test_Long_reverseBytes() {
+      Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
+      Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
+      Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
+      Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
+      Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
+  }
+
   public static void test_Integer_reverse() {
     Assert.assertEquals(Integer.reverse(1), 0x80000000);
     Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
@@ -570,11 +601,9 @@
     Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
     Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
     Assert.assertEquals(Long.reverse(0L), 0L);
-    // FIXME: This asserts fail with or without this patch. I have collected
-    // the expected results on my host machine.
-    // Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
-    // Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
-    // Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
+    Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
+    Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
+    Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
     Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
   }