From 38eb7e031480024bb1bccae990d79c4d10dd1166 Mon Sep 17 00:00:00 2001
From: Yuri Kunde Schlesner <yuriks@yuriks.net>
Date: Sun, 11 Jun 2017 17:17:04 -0700
Subject: [PATCH] emit_x64: Use alternative Xbyak names for and, or, xor

Also enabled XBYAK_NO_OP_NAMES, allowing us to stop using
-fno-operator-names.
---
 CMakeLists.txt               |  6 +--
 externals/CMakeLists.txt     |  1 +
 src/backend_x64/emit_x64.cpp | 80 ++++++++++++++++++------------------
 3 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96456ce9..62ba5429 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,8 +58,7 @@ if (MSVC)
     if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "LLVM-vs[0-9]+")
         list(APPEND DYNARMIC_CXX_FLAGS
              -Qunused-arguments
-             -Wno-missing-braces
-             -Xclang -fno-operator-names)
+             -Wno-missing-braces)
     endif()
 else()
     set(DYNARMIC_CXX_FLAGS
@@ -69,8 +68,7 @@ else()
         -pedantic
         -pedantic-errors
         -Wfatal-errors
-        -Wno-missing-braces
-        -fno-operator-names)
+        -Wno-missing-braces)
 
     if (DYNARMIC_WARNINGS_AS_ERRORS)
         list(APPEND DYNARMIC_CXX_FLAGS
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
index 73a1a6f0..d3d7b4d6 100644
--- a/externals/CMakeLists.txt
+++ b/externals/CMakeLists.txt
@@ -11,6 +11,7 @@ if (NOT TARGET xbyak)
     if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
         add_library(xbyak INTERFACE)
         target_include_directories(xbyak INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xbyak/xbyak)
+        target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES)
     endif()
 endif()
 
diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp
index d75f9a6d..184dd93c 100644
--- a/src/backend_x64/emit_x64.cpp
+++ b/src/backend_x64/emit_x64.cpp
@@ -1763,10 +1763,10 @@ void EmitX64::EmitPackedHalvingAddU8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
         Xbyak::Reg32 result = reg_a;
 
         code->mov(xor_a_b, reg_a);
-        code->and(and_a_b, reg_b);
-        code->xor(xor_a_b, reg_b);
+        code->and_(and_a_b, reg_b);
+        code->xor_(xor_a_b, reg_b);
         code->shr(xor_a_b, 1);
-        code->and(xor_a_b, 0x7F7F7F7F);
+        code->and_(xor_a_b, 0x7F7F7F7F);
         code->add(result, xor_a_b);
 
         reg_alloc.DefineValue(inst, result);
@@ -1788,10 +1788,10 @@ void EmitX64::EmitPackedHalvingAddU16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // We mask by 0x7FFF to remove the LSB so that it doesn't leak into the field below.
 
     code->mov(xor_a_b, reg_a);
-    code->and(and_a_b, reg_b);
-    code->xor(xor_a_b, reg_b);
+    code->and_(and_a_b, reg_b);
+    code->xor_(xor_a_b, reg_b);
     code->shr(xor_a_b, 1);
-    code->and(xor_a_b, 0x7FFF7FFF);
+    code->and_(xor_a_b, 0x7FFF7FFF);
     code->add(result, xor_a_b);
 
     reg_alloc.DefineValue(inst, result);
@@ -1814,14 +1814,14 @@ void EmitX64::EmitPackedHalvingAddS8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // carry propagates the sign bit from (x^y)>>1 upwards by one.
 
     code->mov(xor_a_b, reg_a);
-    code->and(and_a_b, reg_b);
-    code->xor(xor_a_b, reg_b);
+    code->and_(and_a_b, reg_b);
+    code->xor_(xor_a_b, reg_b);
     code->mov(carry, xor_a_b);
-    code->and(carry, 0x80808080);
+    code->and_(carry, 0x80808080);
     code->shr(xor_a_b, 1);
-    code->and(xor_a_b, 0x7F7F7F7F);
+    code->and_(xor_a_b, 0x7F7F7F7F);
     code->add(result, xor_a_b);
-    code->xor(result, carry);
+    code->xor_(result, carry);
 
     reg_alloc.DefineValue(inst, result);
 }
@@ -1843,14 +1843,14 @@ void EmitX64::EmitPackedHalvingAddS16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // carry propagates the sign bit from (x^y)>>1 upwards by one.
 
     code->mov(xor_a_b, reg_a);
-    code->and(and_a_b, reg_b);
-    code->xor(xor_a_b, reg_b);
+    code->and_(and_a_b, reg_b);
+    code->xor_(xor_a_b, reg_b);
     code->mov(carry, xor_a_b);
-    code->and(carry, 0x80008000);
+    code->and_(carry, 0x80008000);
     code->shr(xor_a_b, 1);
-    code->and(xor_a_b, 0x7FFF7FFF);
+    code->and_(xor_a_b, 0x7FFF7FFF);
     code->add(result, xor_a_b);
-    code->xor(result, carry);
+    code->xor_(result, carry);
 
     reg_alloc.DefineValue(inst, result);
 }
@@ -1865,8 +1865,8 @@ void EmitX64::EmitPackedHalvingSubU8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // Note that x^y always contains the LSB of the result.
     // Since we want to calculate (x+y)/2, we can instead calculate ((x^y)>>1) - ((x^y)&y).
 
-    code->xor(minuend, subtrahend);
-    code->and(subtrahend, minuend);
+    code->xor_(minuend, subtrahend);
+    code->and_(subtrahend, minuend);
     code->shr(minuend, 1);
 
     // At this point,
@@ -1877,9 +1877,9 @@ void EmitX64::EmitPackedHalvingSubU8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // We can do this because minuend contains 7 bit fields.
     // We use the extra bit in minuend as a bit to borrow from; we set this bit.
     // We invert this bit at the end as this tells us if that bit was borrowed from.
-    code->or(minuend, 0x80808080);
+    code->or_(minuend, 0x80808080);
     code->sub(minuend, subtrahend);
-    code->xor(minuend, 0x80808080);
+    code->xor_(minuend, 0x80808080);
 
     // minuend now contains the desired result.
     reg_alloc.DefineValue(inst, minuend);
@@ -1897,10 +1897,10 @@ void EmitX64::EmitPackedHalvingSubS8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // Note that x^y always contains the LSB of the result.
     // Since we want to calculate (x-y)/2, we can instead calculate ((x^y)>>1) - ((x^y)&y).
 
-    code->xor(minuend, subtrahend);
-    code->and(subtrahend, minuend);
+    code->xor_(minuend, subtrahend);
+    code->and_(subtrahend, minuend);
     code->mov(carry, minuend);
-    code->and(carry, 0x80808080);
+    code->and_(carry, 0x80808080);
     code->shr(minuend, 1);
 
     // At this point,
@@ -1913,10 +1913,10 @@ void EmitX64::EmitPackedHalvingSubS8(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // We use the extra bit in minuend as a bit to borrow from; we set this bit.
     // We invert this bit at the end as this tells us if that bit was borrowed from.
     // We then sign extend the result into this bit.
-    code->or(minuend, 0x80808080);
+    code->or_(minuend, 0x80808080);
     code->sub(minuend, subtrahend);
-    code->xor(minuend, 0x80808080);
-    code->xor(minuend, carry);
+    code->xor_(minuend, 0x80808080);
+    code->xor_(minuend, carry);
 
     reg_alloc.DefineValue(inst, minuend);
 }
@@ -1931,8 +1931,8 @@ void EmitX64::EmitPackedHalvingSubU16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // Note that x^y always contains the LSB of the result.
     // Since we want to calculate (x+y)/2, we can instead calculate ((x^y)>>1) - ((x^y)&y).
 
-    code->xor(minuend, subtrahend);
-    code->and(subtrahend, minuend);
+    code->xor_(minuend, subtrahend);
+    code->and_(subtrahend, minuend);
     code->shr(minuend, 1);
 
     // At this point,
@@ -1943,9 +1943,9 @@ void EmitX64::EmitPackedHalvingSubU16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // We can do this because minuend contains 15 bit fields.
     // We use the extra bit in minuend as a bit to borrow from; we set this bit.
     // We invert this bit at the end as this tells us if that bit was borrowed from.
-    code->or(minuend, 0x80008000);
+    code->or_(minuend, 0x80008000);
     code->sub(minuend, subtrahend);
-    code->xor(minuend, 0x80008000);
+    code->xor_(minuend, 0x80008000);
 
     reg_alloc.DefineValue(inst, minuend);
 }
@@ -1962,10 +1962,10 @@ void EmitX64::EmitPackedHalvingSubS16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // Note that x^y always contains the LSB of the result.
     // Since we want to calculate (x-y)/2, we can instead calculate ((x^y)>>1) - ((x^y)&y).
 
-    code->xor(minuend, subtrahend);
-    code->and(subtrahend, minuend);
+    code->xor_(minuend, subtrahend);
+    code->and_(subtrahend, minuend);
     code->mov(carry, minuend);
-    code->and(carry, 0x80008000);
+    code->and_(carry, 0x80008000);
     code->shr(minuend, 1);
 
     // At this point,
@@ -1978,10 +1978,10 @@ void EmitX64::EmitPackedHalvingSubS16(RegAlloc& reg_alloc, IR::Block&, IR::Inst*
     // We use the extra bit in minuend as a bit to borrow from; we set this bit.
     // We invert this bit at the end as this tells us if that bit was borrowed from.
     // We then sign extend the result into this bit.
-    code->or(minuend, 0x80008000);
+    code->or_(minuend, 0x80008000);
     code->sub(minuend, subtrahend);
-    code->xor(minuend, 0x80008000);
-    code->xor(minuend, carry);
+    code->xor_(minuend, 0x80008000);
+    code->xor_(minuend, carry);
 
     reg_alloc.DefineValue(inst, minuend);
 }
@@ -2034,11 +2034,11 @@ void EmitPackedSubAdd(BlockOfCode* code, RegAlloc& reg_alloc, IR::Block& block,
             code->shl(ge_sum, 15);
             code->sar(ge_sum, 16);
         } else {
-            code->not(ge_sum);
+            code->not_(ge_sum);
         }
-        code->not(ge_diff);
-        code->and(ge_sum, hi_is_sum ? 0xC0000000 : 0x30000000);
-        code->and(ge_diff, hi_is_sum ? 0x30000000 : 0xC0000000);
+        code->not_(ge_diff);
+        code->and_(ge_sum, hi_is_sum ? 0xC0000000 : 0x30000000);
+        code->and_(ge_diff, hi_is_sum ? 0x30000000 : 0xC0000000);
         code->or_(ge_sum, ge_diff);
         code->shr(ge_sum, 28);