x86: Add tests for CMPXCHG (without LOCK prefix).

For 8/32/64-bit variants LOCK CMPXCHG is implemented via CMPXCHG, so the
tests for LOCK CMPXCHG cover CMPXCHG as well. But the 16-bit variant of
LOCK CMPXCHG does not use CMPXCHG, because it has to reorder prefixes:
the operand size override prefix must go before the LOCK prefix to match
clang order. Therefore 16-bit CMPXCHG was not tested previously.

Also, change helpers that convert `ByteRegister` to `Register` for
testing to call the actual function rather than reimplement it.

Bug: 65872996
Test: m test-art-host-gtest  # new test cases for CMPXCHG
Change-Id: I234b7a7e69da49be310b1e89c83447f8b11af93d
diff --git a/compiler/utils/x86/assembler_x86.h b/compiler/utils/x86/assembler_x86.h
index 5ac5667..db92a80 100644
--- a/compiler/utils/x86/assembler_x86.h
+++ b/compiler/utils/x86/assembler_x86.h
@@ -888,9 +888,14 @@
   void LoadLongConstant(XmmRegister dst, int64_t value);
   void LoadDoubleConstant(XmmRegister dst, double value);
 
+  // For testing purpose (Repeat* functions expect Register rather than ByteRegister).
+  void cmpxchgb(const Address& address, Register reg) {
+    cmpxchgb(address, static_cast<ByteRegister>(reg));
+  }
+
+  // For testing purpose (Repeat* functions expect Register rather than ByteRegister).
   void LockCmpxchgb(const Address& address, Register reg) {
-    // For testing purpose
-    lock()->cmpxchgb(address, static_cast<ByteRegister>(reg));
+    LockCmpxchgb(address, static_cast<ByteRegister>(reg));
   }
 
   void LockCmpxchgb(const Address& address, ByteRegister reg) {
@@ -916,9 +921,9 @@
     lock()->cmpxchg8b(address);
   }
 
+  // For testing purpose (Repeat* functions expect Register rather than ByteRegister).
   void LockXaddb(const Address& address, Register reg) {
-    // For testing purpose
-    lock()->xaddb(address, static_cast<ByteRegister>(reg));
+    LockXaddb(address, static_cast<ByteRegister>(reg));
   }
 
   void LockXaddb(const Address& address, ByteRegister reg) {
diff --git a/compiler/utils/x86/assembler_x86_test.cc b/compiler/utils/x86/assembler_x86_test.cc
index c6a181a..b7b1d33 100644
--- a/compiler/utils/x86/assembler_x86_test.cc
+++ b/compiler/utils/x86/assembler_x86_test.cc
@@ -346,6 +346,22 @@
                      "xchgl {mem}, %{reg}"), "xchgl");
 }
 
+TEST_F(AssemblerX86Test, Cmpxchgb) {
+  DriverStr(RepeatAw(&x86::X86Assembler::cmpxchgb, "cmpxchgb %{reg}, {mem}"), "cmpxchgb");
+}
+
+TEST_F(AssemblerX86Test, Cmpxchgw) {
+  DriverStr(RepeatAr(&x86::X86Assembler::cmpxchgw, "cmpxchgw %{reg}, {mem}"), "cmpxchgw");
+}
+
+TEST_F(AssemblerX86Test, Cmpxchgl) {
+  DriverStr(RepeatAR(&x86::X86Assembler::cmpxchgl, "cmpxchgl %{reg}, {mem}"), "cmpxchgl");
+}
+
+TEST_F(AssemblerX86Test, Cmpxchg8b) {
+  DriverStr(RepeatA(&x86::X86Assembler::cmpxchg8b, "cmpxchg8b {mem}"), "cmpxchg8b");
+}
+
 TEST_F(AssemblerX86Test, LockCmpxchgb) {
   DriverStr(RepeatAw(&x86::X86Assembler::LockCmpxchgb,
                      "lock cmpxchgb %{reg}, {mem}"), "lock_cmpxchgb");