| OLD | NEW |
| 1 //===- subzero/unittest/IceAssemblerX8632.cpp - X8632 Assembler tests -----===// | 1 //===- subzero/unittest/IceAssemblerX8632.cpp - X8632 Assembler tests -----===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 | 9 |
| 10 #include "IceAssemblerX8632.h" | 10 #include "IceAssemblerX8632.h" |
| 11 | 11 |
| 12 #include "IceDefs.h" | 12 #include "IceDefs.h" |
| 13 | 13 |
| 14 #include "gtest/gtest.h" | 14 #include "gtest/gtest.h" |
| 15 | 15 |
| 16 #include <algorithm> |
| 16 #include <cstring> | 17 #include <cstring> |
| 17 #include <errno.h> | 18 #include <errno.h> |
| 18 #include <iostream> | 19 #include <iostream> |
| 20 #include <limits> |
| 19 #include <memory> | 21 #include <memory> |
| 20 #include <sys/mman.h> | 22 #include <sys/mman.h> |
| 21 #include <type_traits> | 23 #include <type_traits> |
| 22 | 24 |
| 23 namespace Ice { | 25 namespace Ice { |
| 24 namespace X8632 { | 26 namespace X8632 { |
| 25 namespace { | 27 namespace { |
| 26 | |
| 27 class AssemblerX8632TestBase : public ::testing::Test { | 28 class AssemblerX8632TestBase : public ::testing::Test { |
| 28 protected: | 29 protected: |
| 29 using Address = AssemblerX8632::Traits::Address; | 30 using Address = AssemblerX8632::Traits::Address; |
| 31 using ByteRegister = AssemblerX8632::Traits::ByteRegister; |
| 30 using Cond = AssemblerX8632::Traits::Cond; | 32 using Cond = AssemblerX8632::Traits::Cond; |
| 31 using GPRRegister = AssemblerX8632::Traits::GPRRegister; | 33 using GPRRegister = AssemblerX8632::Traits::GPRRegister; |
| 34 using Traits = AssemblerX8632::Traits; |
| 32 using XmmRegister = AssemblerX8632::Traits::XmmRegister; | 35 using XmmRegister = AssemblerX8632::Traits::XmmRegister; |
| 33 using X87STRegister = AssemblerX8632::Traits::X87STRegister; | 36 using X87STRegister = AssemblerX8632::Traits::X87STRegister; |
| 34 | 37 |
| 35 AssemblerX8632TestBase() { reset(); } | 38 AssemblerX8632TestBase() { reset(); } |
| 36 | 39 |
| 37 void reset() { Assembler.reset(new AssemblerX8632()); } | 40 void reset() { Assembler.reset(new AssemblerX8632()); } |
| 38 | 41 |
| 39 AssemblerX8632 *assembler() const { return Assembler.get(); } | 42 AssemblerX8632 *assembler() const { return Assembler.get(); } |
| 40 | 43 |
| 41 size_t codeBytesSize() const { return Assembler->getBufferView().size(); } | 44 size_t codeBytesSize() const { return Assembler->getBufferView().size(); } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 #define __ (this->assembler())-> | 62 #define __ (this->assembler())-> |
| 60 | 63 |
| 61 // AssemblerX8632LowLevelTest verify that the "basic" instructions the tests | 64 // AssemblerX8632LowLevelTest verify that the "basic" instructions the tests |
| 62 // rely on are encoded correctly. Therefore, instead of executing the assembled | 65 // rely on are encoded correctly. Therefore, instead of executing the assembled |
| 63 // code, these tests will verify that the assembled bytes are sane. | 66 // code, these tests will verify that the assembled bytes are sane. |
| 64 class AssemblerX8632LowLevelTest : public AssemblerX8632TestBase { | 67 class AssemblerX8632LowLevelTest : public AssemblerX8632TestBase { |
| 65 protected: | 68 protected: |
| 66 // verifyBytes is a template helper that takes a Buffer, and a variable number | 69 // verifyBytes is a template helper that takes a Buffer, and a variable number |
| 67 // of bytes. As the name indicates, it is used to verify the bytes for an | 70 // of bytes. As the name indicates, it is used to verify the bytes for an |
| 68 // instruction encoding. | 71 // instruction encoding. |
| 69 template <int N, int I> static void verifyBytes(const uint8_t *) { | 72 template <int N, int I> static bool verifyBytes(const uint8_t *) { |
| 70 static_assert(I == N, "Invalid template instantiation."); | 73 static_assert(I == N, "Invalid template instantiation."); |
| 74 return true; |
| 71 } | 75 } |
| 72 | 76 |
| 73 template <int N, int I = 0, typename... Args> | 77 template <int N, int I = 0, typename... Args> |
| 74 static void verifyBytes(const uint8_t *Buffer, uint8_t Byte, | 78 static bool verifyBytes(const uint8_t *Buffer, uint8_t Byte, |
| 75 Args... OtherBytes) { | 79 Args... OtherBytes) { |
| 76 static_assert(I < N, "Invalid template instantiation."); | 80 static_assert(I < N, "Invalid template instantiation."); |
| 77 EXPECT_EQ(Byte, Buffer[I]) << "Byte " << (I + 1) << " of " << N; | 81 EXPECT_EQ(Byte, Buffer[I]) << "Byte " << (I + 1) << " of " << N; |
| 78 verifyBytes<N, I + 1>(Buffer, OtherBytes...); | 82 return verifyBytes<N, I + 1>(Buffer, OtherBytes...) && Buffer[I] == Byte; |
| 79 assert(Buffer[I] == Byte); | |
| 80 } | 83 } |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 TEST_F(AssemblerX8632LowLevelTest, Ret) { | 86 TEST_F(AssemblerX8632LowLevelTest, Ret) { |
| 84 __ ret(); | 87 __ ret(); |
| 85 | 88 |
| 86 constexpr size_t ByteCount = 1; | 89 constexpr size_t ByteCount = 1; |
| 87 ASSERT_EQ(ByteCount, codeBytesSize()); | 90 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 88 | 91 |
| 89 verifyBytes<ByteCount>(codeBytes(), 0xc3); | 92 verifyBytes<ByteCount>(codeBytes(), 0xc3); |
| 90 } | 93 } |
| 91 | 94 |
| 95 TEST_F(AssemblerX8632LowLevelTest, RetImm) { |
| 96 __ ret(Immediate(0x20)); |
| 97 |
| 98 constexpr size_t ByteCount = 3; |
| 99 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 100 |
| 101 verifyBytes<ByteCount>(codeBytes(), 0xC2, 0x20, 0x00); |
| 102 } |
| 103 |
| 92 TEST_F(AssemblerX8632LowLevelTest, CallImm4) { | 104 TEST_F(AssemblerX8632LowLevelTest, CallImm4) { |
| 93 __ call(Immediate(4)); | 105 __ call(Immediate(4)); |
| 94 | 106 |
| 95 constexpr size_t ByteCount = 5; | 107 constexpr size_t ByteCount = 5; |
| 96 ASSERT_EQ(ByteCount, codeBytesSize()); | 108 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 97 | 109 |
| 98 verifyBytes<ByteCount>(codeBytes(), 0xe8, 0x00, 0x00, 0x00, 0x00); | 110 verifyBytes<ByteCount>(codeBytes(), 0xe8, 0x00, 0x00, 0x00, 0x00); |
| 99 } | 111 } |
| 100 | 112 |
| 101 TEST_F(AssemblerX8632LowLevelTest, PopRegs) { | 113 TEST_F(AssemblerX8632LowLevelTest, PopRegs) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 constexpr uint8_t MovOpcode = 0xb8; | 169 constexpr uint8_t MovOpcode = 0xb8; |
| 158 verifyBytes<ByteCount>( | 170 verifyBytes<ByteCount>( |
| 159 codeBytes(), MovOpcode | GPRRegister::Encoded_Reg_eax, 0x00, 0x00, 0x00, | 171 codeBytes(), MovOpcode | GPRRegister::Encoded_Reg_eax, 0x00, 0x00, 0x00, |
| 160 0x00, MovOpcode | GPRRegister::Encoded_Reg_ebx, 0x00, 0x00, 0x00, 0x00, | 172 0x00, MovOpcode | GPRRegister::Encoded_Reg_ebx, 0x00, 0x00, 0x00, 0x00, |
| 161 MovOpcode | GPRRegister::Encoded_Reg_ecx, 0x00, 0x00, 0x00, 0x00, | 173 MovOpcode | GPRRegister::Encoded_Reg_ecx, 0x00, 0x00, 0x00, 0x00, |
| 162 MovOpcode | GPRRegister::Encoded_Reg_edx, 0x00, 0x00, 0x00, 0x00, | 174 MovOpcode | GPRRegister::Encoded_Reg_edx, 0x00, 0x00, 0x00, 0x00, |
| 163 MovOpcode | GPRRegister::Encoded_Reg_edi, 0x00, 0x00, 0x00, 0x00, | 175 MovOpcode | GPRRegister::Encoded_Reg_edi, 0x00, 0x00, 0x00, 0x00, |
| 164 MovOpcode | GPRRegister::Encoded_Reg_esi, 0x00, 0x00, 0x00, 0x00); | 176 MovOpcode | GPRRegister::Encoded_Reg_esi, 0x00, 0x00, 0x00, 0x00); |
| 165 } | 177 } |
| 166 | 178 |
| 167 TEST_F(AssemblerX8632LowLevelTest, CmpRegReg) { | 179 TEST_F(AssemblerX8632LowLevelTest, Cmp) { |
| 168 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_eax, | 180 #define TestRegReg(Inst, Dst, Src, OpType, ByteCountUntyped, ...) \ |
| 169 GPRRegister::Encoded_Reg_ebx); | 181 do { \ |
| 170 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_ebx, | 182 static constexpr char TestString[] = \ |
| 171 GPRRegister::Encoded_Reg_ecx); | 183 "(" #Inst ", " #Dst ", " #Src ", " #OpType ", " #ByteCountUntyped \ |
| 172 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_ecx, | 184 ", " #__VA_ARGS__ ")"; \ |
| 173 GPRRegister::Encoded_Reg_edx); | 185 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 174 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_edx, | 186 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, \ |
| 175 GPRRegister::Encoded_Reg_edi); | 187 GPRRegister::Encoded_Reg_##Src); \ |
| 176 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_edi, | 188 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 177 GPRRegister::Encoded_Reg_esi); | 189 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 178 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_esi, | 190 << TestString; \ |
| 179 GPRRegister::Encoded_Reg_eax); | 191 reset(); \ |
| 180 | 192 } while (0) |
| 181 const size_t CmpRegRegBytes = 2; | 193 |
| 182 const size_t ByteCount = 6 * CmpRegRegBytes; | 194 #define TestRegImm(Inst, Dst, Imm, OpType, ByteCountUntyped, ...) \ |
| 195 do { \ |
| 196 static constexpr char TestString[] = \ |
| 197 "(" #Inst ", " #Dst ", " #Imm ", " #OpType ", " #ByteCountUntyped \ |
| 198 ", " #__VA_ARGS__ ")"; \ |
| 199 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 200 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, Immediate(Imm)); \ |
| 201 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 202 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 203 << TestString; \ |
| 204 reset(); \ |
| 205 } while (0) |
| 206 |
| 207 #define TestRegAbsoluteAddr(Inst, Dst, Disp, OpType, ByteCountUntyped, ...) \ |
| 208 do { \ |
| 209 static constexpr char TestString[] = \ |
| 210 "(" #Inst ", " #Dst ", " #Disp ", " #OpType ", " #ByteCountUntyped \ |
| 211 ", " #__VA_ARGS__ ")"; \ |
| 212 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 213 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, \ |
| 214 Address(Address::ABSOLUTE, Disp)); \ |
| 215 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 216 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 217 << TestString; \ |
| 218 reset(); \ |
| 219 } while (0) |
| 220 |
| 221 #define TestRegAddrBase(Inst, Dst, Base, Disp, OpType, ByteCountUntyped, ...) \ |
| 222 do { \ |
| 223 static constexpr char TestString[] = \ |
| 224 "(" #Inst ", " #Dst ", " #Base ", " #Disp ", " #OpType \ |
| 225 ", " #ByteCountUntyped ", " #__VA_ARGS__ ")"; \ |
| 226 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 227 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, \ |
| 228 Address(GPRRegister::Encoded_Reg_##Base, Disp)); \ |
| 229 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 230 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 231 << TestString; \ |
| 232 reset(); \ |
| 233 } while (0) |
| 234 |
| 235 #define TestRegAddrScaledIndex(Inst, Dst, Index, Scale, Disp, OpType, \ |
| 236 ByteCountUntyped, ...) \ |
| 237 do { \ |
| 238 static constexpr char TestString[] = \ |
| 239 "(" #Inst ", " #Dst ", " #Index ", " #Scale ", " #Disp ", " #OpType \ |
| 240 ", " #ByteCountUntyped ", " #__VA_ARGS__ ")"; \ |
| 241 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 242 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, \ |
| 243 Address(GPRRegister::Encoded_Reg_##Index, Traits::TIMES_##Scale, \ |
| 244 Disp)); \ |
| 245 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 246 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 247 << TestString; \ |
| 248 reset(); \ |
| 249 } while (0) |
| 250 |
| 251 #define TestRegAddrBaseScaledIndex(Inst, Dst, Base, Index, Scale, Disp, \ |
| 252 OpType, ByteCountUntyped, ...) \ |
| 253 do { \ |
| 254 static constexpr char TestString[] = \ |
| 255 "(" #Inst ", " #Dst ", " #Base ", " #Index ", " #Scale ", " #Disp \ |
| 256 ", " #OpType ", " #ByteCountUntyped ", " #__VA_ARGS__ ")"; \ |
| 257 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 258 __ Inst(IceType_##OpType, GPRRegister::Encoded_Reg_##Dst, \ |
| 259 Address(GPRRegister::Encoded_Reg_##Base, \ |
| 260 GPRRegister::Encoded_Reg_##Index, Traits::TIMES_##Scale, \ |
| 261 Disp)); \ |
| 262 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 263 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 264 << TestString; \ |
| 265 reset(); \ |
| 266 } while (0) |
| 267 |
| 268 #define TestAddrBaseScaledIndexImm(Inst, Base, Index, Scale, Disp, Imm, \ |
| 269 OpType, ByteCountUntyped, ...) \ |
| 270 do { \ |
| 271 static constexpr char TestString[] = \ |
| 272 "(" #Inst ", " #Base ", " #Index ", " #Scale ", " #Disp ", " #Imm \ |
| 273 ", " #OpType ", " #ByteCountUntyped ", " #__VA_ARGS__ ")"; \ |
| 274 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 275 __ Inst(IceType_##OpType, Address(GPRRegister::Encoded_Reg_##Base, \ |
| 276 GPRRegister::Encoded_Reg_##Index, \ |
| 277 Traits::TIMES_##Scale, Disp), \ |
| 278 Immediate(Imm)); \ |
| 279 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 280 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 281 << TestString; \ |
| 282 reset(); \ |
| 283 } while (0) |
| 284 |
| 285 #define TestAddrBaseScaledIndexReg(Inst, Base, Index, Scale, Disp, Src, \ |
| 286 OpType, ByteCountUntyped, ...) \ |
| 287 do { \ |
| 288 static constexpr char TestString[] = \ |
| 289 "(" #Inst ", " #Base ", " #Index ", " #Scale ", " #Disp ", " #Src \ |
| 290 ", " #OpType ", " #ByteCountUntyped ", " #__VA_ARGS__ ")"; \ |
| 291 static constexpr uint8_t ByteCount = ByteCountUntyped; \ |
| 292 __ Inst(IceType_##OpType, Address(GPRRegister::Encoded_Reg_##Base, \ |
| 293 GPRRegister::Encoded_Reg_##Index, \ |
| 294 Traits::TIMES_##Scale, Disp), \ |
| 295 GPRRegister::Encoded_Reg_##Src); \ |
| 296 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 297 ASSERT_TRUE(verifyBytes<ByteCount>(codeBytes(), __VA_ARGS__)) \ |
| 298 << TestString; \ |
| 299 reset(); \ |
| 300 } while (0) |
| 301 |
| 302 /* cmp GPR, GPR */ |
| 303 TestRegReg(cmp, eax, ecx, i32, 2, 0x3B, 0xC1); |
| 304 TestRegReg(cmp, ecx, edx, i32, 2, 0x3B, 0xCA); |
| 305 TestRegReg(cmp, edx, ebx, i32, 2, 0x3B, 0xD3); |
| 306 TestRegReg(cmp, ebx, esp, i32, 2, 0x3B, 0xDC); |
| 307 TestRegReg(cmp, esp, ebp, i32, 2, 0x3B, 0xE5); |
| 308 TestRegReg(cmp, ebp, esi, i32, 2, 0x3B, 0xEE); |
| 309 TestRegReg(cmp, esi, edi, i32, 2, 0x3B, 0xF7); |
| 310 TestRegReg(cmp, edi, eax, i32, 2, 0x3B, 0xF8); |
| 311 |
| 312 TestRegReg(cmp, eax, ecx, i16, 3, 0x66, 0x3B, 0xC1); |
| 313 TestRegReg(cmp, ecx, edx, i16, 3, 0x66, 0x3B, 0xCA); |
| 314 TestRegReg(cmp, edx, ebx, i16, 3, 0x66, 0x3B, 0xD3); |
| 315 TestRegReg(cmp, ebx, esp, i16, 3, 0x66, 0x3B, 0xDC); |
| 316 TestRegReg(cmp, esp, ebp, i16, 3, 0x66, 0x3B, 0xE5); |
| 317 TestRegReg(cmp, ebp, esi, i16, 3, 0x66, 0x3B, 0xEE); |
| 318 TestRegReg(cmp, esi, edi, i16, 3, 0x66, 0x3B, 0xF7); |
| 319 TestRegReg(cmp, edi, eax, i16, 3, 0x66, 0x3B, 0xF8); |
| 320 |
| 321 TestRegReg(cmp, eax, ecx, i8, 2, 0x3A, 0xC1); |
| 322 TestRegReg(cmp, ecx, edx, i8, 2, 0x3A, 0xCA); |
| 323 TestRegReg(cmp, edx, ebx, i8, 2, 0x3A, 0xD3); |
| 324 TestRegReg(cmp, ebx, esp, i8, 2, 0x3A, 0xDC); |
| 325 TestRegReg(cmp, esp, ebp, i8, 2, 0x3A, 0xE5); |
| 326 TestRegReg(cmp, ebp, esi, i8, 2, 0x3A, 0xEE); |
| 327 TestRegReg(cmp, esi, edi, i8, 2, 0x3A, 0xF7); |
| 328 TestRegReg(cmp, edi, eax, i8, 2, 0x3A, 0xF8); |
| 329 |
| 330 /* cmp GPR, Imm8 */ |
| 331 TestRegImm(cmp, eax, 5, i32, 3, 0x83, 0xF8, 0x05); |
| 332 TestRegImm(cmp, ecx, 5, i32, 3, 0x83, 0xF9, 0x05); |
| 333 TestRegImm(cmp, edx, 5, i32, 3, 0x83, 0xFA, 0x05); |
| 334 TestRegImm(cmp, ebx, 5, i32, 3, 0x83, 0xFB, 0x05); |
| 335 TestRegImm(cmp, esp, 5, i32, 3, 0x83, 0xFC, 0x05); |
| 336 TestRegImm(cmp, ebp, 5, i32, 3, 0x83, 0xFD, 0x05); |
| 337 TestRegImm(cmp, esi, 5, i32, 3, 0x83, 0xFE, 0x05); |
| 338 TestRegImm(cmp, edi, 5, i32, 3, 0x83, 0xFF, 0x05); |
| 339 |
| 340 TestRegImm(cmp, eax, 5, i16, 4, 0x66, 0x83, 0xF8, 0x05); |
| 341 TestRegImm(cmp, ecx, 5, i16, 4, 0x66, 0x83, 0xF9, 0x05); |
| 342 TestRegImm(cmp, edx, 5, i16, 4, 0x66, 0x83, 0xFA, 0x05); |
| 343 TestRegImm(cmp, ebx, 5, i16, 4, 0x66, 0x83, 0xFB, 0x05); |
| 344 TestRegImm(cmp, esp, 5, i16, 4, 0x66, 0x83, 0xFC, 0x05); |
| 345 TestRegImm(cmp, ebp, 5, i16, 4, 0x66, 0x83, 0xFD, 0x05); |
| 346 TestRegImm(cmp, esi, 5, i16, 4, 0x66, 0x83, 0xFE, 0x05); |
| 347 TestRegImm(cmp, edi, 5, i16, 4, 0x66, 0x83, 0xFF, 0x05); |
| 348 |
| 349 TestRegImm(cmp, eax, 5, i8, 2, 0x3C, 0x05); |
| 350 TestRegImm(cmp, ecx, 5, i8, 3, 0x80, 0xF9, 0x05); |
| 351 TestRegImm(cmp, edx, 5, i8, 3, 0x80, 0xFA, 0x05); |
| 352 TestRegImm(cmp, ebx, 5, i8, 3, 0x80, 0xFB, 0x05); |
| 353 TestRegImm(cmp, esp, 5, i8, 3, 0x80, 0xFC, 0x05); |
| 354 TestRegImm(cmp, ebp, 5, i8, 3, 0x80, 0xFD, 0x05); |
| 355 TestRegImm(cmp, esi, 5, i8, 3, 0x80, 0xFE, 0x05); |
| 356 TestRegImm(cmp, edi, 5, i8, 3, 0x80, 0xFF, 0x05); |
| 357 |
| 358 /* cmp GPR, Imm16 */ |
| 359 TestRegImm(cmp, eax, 0x100, i32, 5, 0x3D, 0x00, 0x01, 0x00, 0x00); |
| 360 TestRegImm(cmp, ecx, 0x100, i32, 6, 0x81, 0xF9, 0x00, 0x01, 0x00, 0x00); |
| 361 TestRegImm(cmp, edx, 0x100, i32, 6, 0x81, 0xFA, 0x00, 0x01, 0x00, 0x00); |
| 362 TestRegImm(cmp, ebx, 0x100, i32, 6, 0x81, 0xFB, 0x00, 0x01, 0x00, 0x00); |
| 363 TestRegImm(cmp, esp, 0x100, i32, 6, 0x81, 0xFC, 0x00, 0x01, 0x00, 0x00); |
| 364 TestRegImm(cmp, ebp, 0x100, i32, 6, 0x81, 0xFD, 0x00, 0x01, 0x00, 0x00); |
| 365 TestRegImm(cmp, esi, 0x100, i32, 6, 0x81, 0xFE, 0x00, 0x01, 0x00, 0x00); |
| 366 TestRegImm(cmp, edi, 0x100, i32, 6, 0x81, 0xFF, 0x00, 0x01, 0x00, 0x00); |
| 367 |
| 368 TestRegImm(cmp, eax, 0x100, i16, 4, 0x66, 0x3D, 0x00, 0x01); |
| 369 TestRegImm(cmp, ecx, 0x100, i16, 5, 0x66, 0x81, 0xF9, 0x00, 0x01); |
| 370 TestRegImm(cmp, edx, 0x100, i16, 5, 0x66, 0x81, 0xFA, 0x00, 0x01); |
| 371 TestRegImm(cmp, ebx, 0x100, i16, 5, 0x66, 0x81, 0xFB, 0x00, 0x01); |
| 372 TestRegImm(cmp, esp, 0x100, i16, 5, 0x66, 0x81, 0xFC, 0x00, 0x01); |
| 373 TestRegImm(cmp, ebp, 0x100, i16, 5, 0x66, 0x81, 0xFD, 0x00, 0x01); |
| 374 TestRegImm(cmp, esi, 0x100, i16, 5, 0x66, 0x81, 0xFE, 0x00, 0x01); |
| 375 TestRegImm(cmp, edi, 0x100, i16, 5, 0x66, 0x81, 0xFF, 0x00, 0x01); |
| 376 |
| 377 /* cmp GPR, Absolute */ |
| 378 TestRegAbsoluteAddr(cmp, eax, 0xF00FBEEF, i32, 6, 0x3B, 0x05, 0xEF, 0xBE, |
| 379 0x0F, 0xF0); |
| 380 TestRegAbsoluteAddr(cmp, eax, 0xF00FBEEF, i16, 7, 0x66, 0x3B, 0x05, 0xEF, |
| 381 0xBE, 0x0F, 0xF0); |
| 382 TestRegAbsoluteAddr(cmp, eax, 0xF00FBEEF, i8, 6, 0x3A, 0x05, 0xEF, 0xBE, 0x0F, |
| 383 0xF0); |
| 384 |
| 385 /* cmp GPR, 0(Base) */ |
| 386 TestRegAddrBase(cmp, eax, ecx, 0, i32, 2, 0x3B, 0x01); |
| 387 TestRegAddrBase(cmp, ecx, edx, 0, i32, 2, 0x3B, 0x0A); |
| 388 TestRegAddrBase(cmp, edx, ebx, 0, i32, 2, 0x3B, 0x13); |
| 389 TestRegAddrBase(cmp, ebx, esp, 0, i32, 3, 0x3B, 0x1C, 0x24); |
| 390 TestRegAddrBase(cmp, esp, ebp, 0, i32, 3, 0x3B, 0x65, 0x00); |
| 391 TestRegAddrBase(cmp, ebp, esi, 0, i32, 2, 0x3B, 0x2E); |
| 392 TestRegAddrBase(cmp, esi, edi, 0, i32, 2, 0x3B, 0x37); |
| 393 TestRegAddrBase(cmp, edi, eax, 0, i32, 2, 0x3B, 0x38); |
| 394 |
| 395 TestRegAddrBase(cmp, eax, ecx, 0, i16, 3, 0x66, 0x3B, 0x01); |
| 396 TestRegAddrBase(cmp, ecx, edx, 0, i16, 3, 0x66, 0x3B, 0x0A); |
| 397 TestRegAddrBase(cmp, edx, ebx, 0, i16, 3, 0x66, 0x3B, 0x13); |
| 398 TestRegAddrBase(cmp, ebx, esp, 0, i16, 4, 0x66, 0x3B, 0x1C, 0x24); |
| 399 TestRegAddrBase(cmp, esp, ebp, 0, i16, 4, 0x66, 0x3B, 0x65, 0x00); |
| 400 TestRegAddrBase(cmp, ebp, esi, 0, i16, 3, 0x66, 0x3B, 0x2E); |
| 401 TestRegAddrBase(cmp, esi, edi, 0, i16, 3, 0x66, 0x3B, 0x37); |
| 402 TestRegAddrBase(cmp, edi, eax, 0, i16, 3, 0x66, 0x3B, 0x38); |
| 403 |
| 404 TestRegAddrBase(cmp, eax, ecx, 0, i8, 2, 0x3A, 0x01); |
| 405 TestRegAddrBase(cmp, ecx, edx, 0, i8, 2, 0x3A, 0x0A); |
| 406 TestRegAddrBase(cmp, edx, ebx, 0, i8, 2, 0x3A, 0x13); |
| 407 TestRegAddrBase(cmp, ebx, esp, 0, i8, 3, 0x3A, 0x1C, 0x24); |
| 408 TestRegAddrBase(cmp, esp, ebp, 0, i8, 3, 0x3A, 0x65, 0x00); |
| 409 TestRegAddrBase(cmp, ebp, esi, 0, i8, 2, 0x3A, 0x2E); |
| 410 TestRegAddrBase(cmp, esi, edi, 0, i8, 2, 0x3A, 0x37); |
| 411 TestRegAddrBase(cmp, edi, eax, 0, i8, 2, 0x3A, 0x38); |
| 412 |
| 413 /* cmp GPR, Imm8(Base) */ |
| 414 TestRegAddrBase(cmp, eax, ecx, 0x40, i32, 3, 0x3B, 0x41, 0x40); |
| 415 TestRegAddrBase(cmp, ecx, edx, 0x40, i32, 3, 0x3B, 0x4A, 0x40); |
| 416 TestRegAddrBase(cmp, edx, ebx, 0x40, i32, 3, 0x3B, 0x53, 0x40); |
| 417 TestRegAddrBase(cmp, ebx, esp, 0x40, i32, 4, 0x3B, 0x5C, 0x24, 0x40); |
| 418 TestRegAddrBase(cmp, esp, ebp, 0x40, i32, 3, 0x3B, 0x65, 0x40); |
| 419 TestRegAddrBase(cmp, ebp, esi, 0x40, i32, 3, 0x3B, 0x6E, 0x40); |
| 420 TestRegAddrBase(cmp, esi, edi, 0x40, i32, 3, 0x3B, 0x77, 0x40); |
| 421 TestRegAddrBase(cmp, edi, eax, 0x40, i32, 3, 0x3B, 0x78, 0x40); |
| 422 |
| 423 TestRegAddrBase(cmp, eax, ecx, 0x40, i16, 4, 0x66, 0x3B, 0x41, 0x40); |
| 424 TestRegAddrBase(cmp, ecx, edx, 0x40, i16, 4, 0x66, 0x3B, 0x4A, 0x40); |
| 425 TestRegAddrBase(cmp, edx, ebx, 0x40, i16, 4, 0x66, 0x3B, 0x53, 0x40); |
| 426 TestRegAddrBase(cmp, ebx, esp, 0x40, i16, 5, 0x66, 0x3B, 0x5C, 0x24, 0x40); |
| 427 TestRegAddrBase(cmp, esp, ebp, 0x40, i16, 4, 0x66, 0x3B, 0x65, 0x40); |
| 428 TestRegAddrBase(cmp, ebp, esi, 0x40, i16, 4, 0x66, 0x3B, 0x6E, 0x40); |
| 429 TestRegAddrBase(cmp, esi, edi, 0x40, i16, 4, 0x66, 0x3B, 0x77, 0x40); |
| 430 TestRegAddrBase(cmp, edi, eax, 0x40, i16, 4, 0x66, 0x3B, 0x78, 0x40); |
| 431 |
| 432 TestRegAddrBase(cmp, eax, ecx, 0x40, i8, 3, 0x3A, 0x41, 0x40); |
| 433 TestRegAddrBase(cmp, ecx, edx, 0x40, i8, 3, 0x3A, 0x4A, 0x40); |
| 434 TestRegAddrBase(cmp, edx, ebx, 0x40, i8, 3, 0x3A, 0x53, 0x40); |
| 435 TestRegAddrBase(cmp, ebx, esp, 0x40, i8, 4, 0x3A, 0x5C, 0x24, 0x40); |
| 436 TestRegAddrBase(cmp, esp, ebp, 0x40, i8, 3, 0x3A, 0x65, 0x40); |
| 437 TestRegAddrBase(cmp, ebp, esi, 0x40, i8, 3, 0x3A, 0x6E, 0x40); |
| 438 TestRegAddrBase(cmp, esi, edi, 0x40, i8, 3, 0x3A, 0x77, 0x40); |
| 439 TestRegAddrBase(cmp, edi, eax, 0x40, i8, 3, 0x3A, 0x78, 0x40); |
| 440 |
| 441 /* cmp GPR, Imm32(Base) */ |
| 442 TestRegAddrBase(cmp, eax, ecx, 0xF0, i32, 6, 0x3B, 0x81, 0xF0, 0x00, 0x00, |
| 443 0x00); |
| 444 TestRegAddrBase(cmp, ecx, edx, 0xF0, i32, 6, 0x3B, 0x8A, 0xF0, 0x00, 0x00, |
| 445 0x00); |
| 446 TestRegAddrBase(cmp, edx, ebx, 0xF0, i32, 6, 0x3B, 0x93, 0xF0, 0x00, 0x00, |
| 447 0x00); |
| 448 TestRegAddrBase(cmp, ebx, esp, 0xF0, i32, 7, 0x3B, 0x9C, 0x24, 0xF0, 0x00, |
| 449 0x00, 0x00); |
| 450 TestRegAddrBase(cmp, esp, ebp, 0xF0, i32, 6, 0x3B, 0xA5, 0xF0, 0x00, 0x00, |
| 451 0x00); |
| 452 TestRegAddrBase(cmp, ebp, esi, 0xF0, i32, 6, 0x3B, 0xAE, 0xF0, 0x00, 0x00, |
| 453 0x00); |
| 454 TestRegAddrBase(cmp, esi, edi, 0xF0, i32, 6, 0x3B, 0xB7, 0xF0, 0x00, 0x00, |
| 455 0x00); |
| 456 TestRegAddrBase(cmp, edi, eax, 0xF0, i32, 6, 0x3B, 0xB8, 0xF0, 0x00, 0x00, |
| 457 0x00); |
| 458 |
| 459 TestRegAddrBase(cmp, eax, ecx, 0xF0, i16, 7, 0x66, 0x3B, 0x81, 0xF0, 0x00, |
| 460 0x00, 0x00); |
| 461 TestRegAddrBase(cmp, ecx, edx, 0xF0, i16, 7, 0x66, 0x3B, 0x8A, 0xF0, 0x00, |
| 462 0x00, 0x00); |
| 463 TestRegAddrBase(cmp, edx, ebx, 0xF0, i16, 7, 0x66, 0x3B, 0x93, 0xF0, 0x00, |
| 464 0x00, 0x00); |
| 465 TestRegAddrBase(cmp, ebx, esp, 0xF0, i16, 8, 0x66, 0x3B, 0x9C, 0x24, 0xF0, |
| 466 0x00, 0x00, 0x00); |
| 467 TestRegAddrBase(cmp, esp, ebp, 0xF0, i16, 7, 0x66, 0x3B, 0xa5, 0xF0, 0x00, |
| 468 0x00, 0x00); |
| 469 TestRegAddrBase(cmp, ebp, esi, 0xF0, i16, 7, 0x66, 0x3B, 0xaE, 0xF0, 0x00, |
| 470 0x00, 0x00); |
| 471 TestRegAddrBase(cmp, esi, edi, 0xF0, i16, 7, 0x66, 0x3B, 0xb7, 0xF0, 0x00, |
| 472 0x00, 0x00); |
| 473 TestRegAddrBase(cmp, edi, eax, 0xF0, i16, 7, 0x66, 0x3B, 0xb8, 0xF0, 0x00, |
| 474 0x00, 0x00); |
| 475 |
| 476 TestRegAddrBase(cmp, eax, ecx, 0xF0, i8, 6, 0x3A, 0x81, 0xF0, 0x00, 0x00, |
| 477 0x00); |
| 478 TestRegAddrBase(cmp, ecx, edx, 0xF0, i8, 6, 0x3A, 0x8A, 0xF0, 0x00, 0x00, |
| 479 0x00); |
| 480 TestRegAddrBase(cmp, edx, ebx, 0xF0, i8, 6, 0x3A, 0x93, 0xF0, 0x00, 0x00, |
| 481 0x00); |
| 482 TestRegAddrBase(cmp, ebx, esp, 0xF0, i8, 7, 0x3A, 0x9C, 0x24, 0xF0, 0x00, |
| 483 0x00, 0x00); |
| 484 TestRegAddrBase(cmp, esp, ebp, 0xF0, i8, 6, 0x3A, 0xA5, 0xF0, 0x00, 0x00, |
| 485 0x00); |
| 486 TestRegAddrBase(cmp, ebp, esi, 0xF0, i8, 6, 0x3A, 0xAE, 0xF0, 0x00, 0x00, |
| 487 0x00); |
| 488 TestRegAddrBase(cmp, esi, edi, 0xF0, i8, 6, 0x3A, 0xB7, 0xF0, 0x00, 0x00, |
| 489 0x00); |
| 490 TestRegAddrBase(cmp, edi, eax, 0xF0, i8, 6, 0x3A, 0xB8, 0xF0, 0x00, 0x00, |
| 491 0x00); |
| 492 |
| 493 /* cmp GPR, Imm(,Index,Scale) */ |
| 494 TestRegAddrScaledIndex(cmp, eax, ecx, 1, 0, i32, 7, 0x3B, 0x04, 0x0D, 0x00, |
| 495 0x00, 0x00, 0x00); |
| 496 TestRegAddrScaledIndex(cmp, ecx, edx, 2, 0, i32, 7, 0x3B, 0x0C, 0x55, 0x00, |
| 497 0x00, 0x00, 0x00); |
| 498 TestRegAddrScaledIndex(cmp, edx, ebx, 4, 0, i32, 7, 0x3B, 0x14, 0x9D, 0x00, |
| 499 0x00, 0x00, 0x00); |
| 500 // esp cannot be an scaled index. |
| 501 TestRegAddrScaledIndex(cmp, esp, ebp, 8, 0, i32, 7, 0x3B, 0x24, 0xED, 0x00, |
| 502 0x00, 0x00, 0x00); |
| 503 TestRegAddrScaledIndex(cmp, ebp, esi, 1, 0, i32, 7, 0x3B, 0x2C, 0x35, 0x00, |
| 504 0x00, 0x00, 0x00); |
| 505 TestRegAddrScaledIndex(cmp, esi, edi, 2, 0, i32, 7, 0x3B, 0x34, 0x7D, 0x00, |
| 506 0x00, 0x00, 0x00); |
| 507 TestRegAddrScaledIndex(cmp, edi, eax, 4, 0, i32, 7, 0x3B, 0x3C, 0x85, 0x00, |
| 508 0x00, 0x00, 0x00); |
| 509 TestRegAddrScaledIndex(cmp, ebx, ecx, 8, 0, i32, 7, 0x3B, 0x1C, 0xCD, 0x00, |
| 510 0x00, 0x00, 0x00); |
| 511 |
| 512 TestRegAddrScaledIndex(cmp, eax, ecx, 8, 0, i16, 8, 0x66, 0x3B, 0x04, 0xCD, |
| 513 0x00, 0x00, 0x00, 0x00); |
| 514 TestRegAddrScaledIndex(cmp, ecx, edx, 1, 0, i16, 8, 0x66, 0x3B, 0x0C, 0x15, |
| 515 0x00, 0x00, 0x00, 0x00); |
| 516 TestRegAddrScaledIndex(cmp, edx, ebx, 2, 0, i16, 8, 0x66, 0x3B, 0x14, 0x5D, |
| 517 0x00, 0x00, 0x00, 0x00); |
| 518 // esp cannot be an scaled index. |
| 519 TestRegAddrScaledIndex(cmp, esp, ebp, 4, 0, i16, 8, 0x66, 0x3B, 0x24, 0xAD, |
| 520 0x00, 0x00, 0x00, 0x00); |
| 521 TestRegAddrScaledIndex(cmp, ebp, esi, 8, 0, i16, 8, 0x66, 0x3B, 0x2C, 0xF5, |
| 522 0x00, 0x00, 0x00, 0x00); |
| 523 TestRegAddrScaledIndex(cmp, esi, edi, 1, 0, i16, 8, 0x66, 0x3B, 0x34, 0x3D, |
| 524 0x00, 0x00, 0x00, 0x00); |
| 525 TestRegAddrScaledIndex(cmp, edi, eax, 2, 0, i16, 8, 0x66, 0x3B, 0x3C, 0x45, |
| 526 0x00, 0x00, 0x00, 0x00); |
| 527 TestRegAddrScaledIndex(cmp, ebx, ecx, 8, 0, i16, 8, 0x66, 0x3B, 0x1C, 0xCD, |
| 528 0x00, 0x00, 0x00, 0x00); |
| 529 |
| 530 TestRegAddrScaledIndex(cmp, eax, ecx, 4, 0, i8, 7, 0x3A, 0x04, 0x8D, 0x00, |
| 531 0x00, 0x00, 0x00); |
| 532 TestRegAddrScaledIndex(cmp, ecx, edx, 8, 0, i8, 7, 0x3A, 0x0C, 0xD5, 0x00, |
| 533 0x00, 0x00, 0x00); |
| 534 TestRegAddrScaledIndex(cmp, edx, ebx, 1, 0, i8, 7, 0x3A, 0x14, 0x1D, 0x00, |
| 535 0x00, 0x00, 0x00); |
| 536 // esp cannot be an scaled index. |
| 537 TestRegAddrScaledIndex(cmp, esp, ebp, 2, 0, i8, 7, 0x3A, 0x24, 0x6D, 0x00, |
| 538 0x00, 0x00, 0x00); |
| 539 TestRegAddrScaledIndex(cmp, ebp, esi, 4, 0, i8, 7, 0x3A, 0x2C, 0xB5, 0x00, |
| 540 0x00, 0x00, 0x00); |
| 541 TestRegAddrScaledIndex(cmp, esi, edi, 8, 0, i8, 7, 0x3A, 0x34, 0xFD, 0x00, |
| 542 0x00, 0x00, 0x00); |
| 543 TestRegAddrScaledIndex(cmp, edi, eax, 1, 0, i8, 7, 0x3A, 0x3C, 0x05, 0x00, |
| 544 0x00, 0x00, 0x00); |
| 545 TestRegAddrScaledIndex(cmp, ebx, ecx, 8, 0, i8, 7, 0x3a, 0x1C, 0xCD, 0x00, |
| 546 0x00, 0x00, 0x00); |
| 547 |
| 548 /* cmp GPR, 0(Base,Index,Scale) */ |
| 549 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0, i32, 3, 0x3B, 0x04, |
| 550 0x11); |
| 551 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0, i32, 3, 0x3B, 0x0C, |
| 552 0x5A); |
| 553 // esp cannot be an scaled index. |
| 554 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0, i32, 3, 0x3B, 0x1C, |
| 555 0xAC); |
| 556 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0, i32, 4, 0x3B, 0x64, 0xF5, |
| 557 0x00); |
| 558 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0, i32, 3, 0x3B, 0x2C, |
| 559 0x3E); |
| 560 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0, i32, 3, 0x3B, 0x34, |
| 561 0x47); |
| 562 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0, i32, 3, 0x3B, 0x3C, |
| 563 0x98); |
| 564 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0, i32, 3, 0x3B, 0x1C, |
| 565 0xD1); |
| 566 |
| 567 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0, i16, 4, 0x66, 0x3B, 0x04, |
| 568 0x11); |
| 569 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0, i16, 4, 0x66, 0x3B, 0x0C, |
| 570 0x5A); |
| 571 // esp cannot be an scaled index. |
| 572 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0, i16, 4, 0x66, 0x3B, 0x1C, |
| 573 0xAC); |
| 574 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0, i16, 5, 0x66, 0x3B, 0x64, |
| 575 0xF5, 0x00); |
| 576 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0, i16, 4, 0x66, 0x3B, 0x2C, |
| 577 0x3E); |
| 578 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0, i16, 4, 0x66, 0x3B, 0x34, |
| 579 0x47); |
| 580 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0, i16, 4, 0x66, 0x3B, 0x3C, |
| 581 0x98); |
| 582 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0, i16, 4, 0x66, 0x3B, 0x1C, |
| 583 0xD1); |
| 584 |
| 585 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0, i8, 3, 0x3A, 0x04, 0x11); |
| 586 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0, i8, 3, 0x3A, 0x0C, 0x5A); |
| 587 // esp cannot be an scaled index. |
| 588 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0, i8, 3, 0x3A, 0x1C, 0xAC); |
| 589 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0, i8, 4, 0x3A, 0x64, 0xF5, |
| 590 0x00); |
| 591 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0, i8, 3, 0x3A, 0x2C, 0x3E); |
| 592 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0, i8, 3, 0x3A, 0x34, 0x47); |
| 593 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0, i8, 3, 0x3A, 0x3C, 0x98); |
| 594 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0, i8, 3, 0x3A, 0x1C, 0xD1); |
| 595 |
| 596 /* cmp GPR, Imm8(Base,Index,Scale) */ |
| 597 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0x40, i32, 4, 0x3B, 0x44, |
| 598 0x11, 0x40); |
| 599 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0x40, i32, 4, 0x3B, 0x4C, |
| 600 0x5A, 0x40); |
| 601 // esp cannot be an scaled index. |
| 602 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0x40, i32, 4, 0x3B, 0x5C, |
| 603 0xAC, 0x40); |
| 604 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0x40, i32, 4, 0x3B, 0x64, |
| 605 0xF5, 0x40); |
| 606 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0x40, i32, 4, 0x3B, 0x6C, |
| 607 0x3E, 0x40); |
| 608 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0x40, i32, 4, 0x3B, 0x74, |
| 609 0x47, 0x40); |
| 610 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0x40, i32, 4, 0x3B, 0x7C, |
| 611 0x98, 0x40); |
| 612 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0x40, i32, 4, 0x3B, 0x5C, |
| 613 0xD1, 0x40); |
| 614 |
| 615 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0x40, i16, 5, 0x66, 0x3B, |
| 616 0x44, 0x11, 0x40); |
| 617 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0x40, i16, 5, 0x66, 0x3B, |
| 618 0x4C, 0x5A, 0x40); |
| 619 // esp cannot be an scaled index. |
| 620 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0x40, i16, 5, 0x66, 0x3B, |
| 621 0x5C, 0xAC, 0x40); |
| 622 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0x40, i16, 5, 0x66, 0x3B, |
| 623 0x64, 0xF5, 0x40); |
| 624 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0x40, i16, 5, 0x66, 0x3B, |
| 625 0x6C, 0x3E, 0x40); |
| 626 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0x40, i16, 5, 0x66, 0x3B, |
| 627 0x74, 0x47, 0x40); |
| 628 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0x40, i16, 5, 0x66, 0x3B, |
| 629 0x7C, 0x98, 0x40); |
| 630 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0x40, i16, 5, 0x66, 0x3B, |
| 631 0x5C, 0xD1, 0x40); |
| 632 |
| 633 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0x40, i8, 4, 0x3A, 0x44, |
| 634 0x11, 0x40); |
| 635 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0x40, i8, 4, 0x3A, 0x4C, |
| 636 0x5A, 0x40); |
| 637 // esp cannot be an scaled index. |
| 638 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0x40, i8, 4, 0x3A, 0x5C, |
| 639 0xAC, 0x40); |
| 640 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0x40, i8, 4, 0x3A, 0x64, |
| 641 0xF5, 0x40); |
| 642 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0x40, i8, 4, 0x3A, 0x6C, |
| 643 0x3E, 0x40); |
| 644 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0x40, i8, 4, 0x3A, 0x74, |
| 645 0x47, 0x40); |
| 646 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0x40, i8, 4, 0x3A, 0x7C, |
| 647 0x98, 0x40); |
| 648 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0x40, i8, 4, 0x3A, 0x5C, |
| 649 0xD1, 0x40); |
| 650 |
| 651 /* cmp GPR, Imm32(Base,Index,Scale) */ |
| 652 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0xF0, i32, 7, 0x3B, 0x84, |
| 653 0x11, 0xF0, 0x00, 0x00, 0x00); |
| 654 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0xF0, i32, 7, 0x3B, 0x8C, |
| 655 0x5A, 0xF0, 0x00, 0x00, 0x00); |
| 656 // esp cannot be an scaled index. |
| 657 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0xF0, i32, 7, 0x3B, 0x9C, |
| 658 0xAC, 0xF0, 0x00, 0x00, 0x00); |
| 659 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0xF0, i32, 7, 0x3B, 0xA4, |
| 660 0xF5, 0xF0, 0x00, 0x00, 0x00); |
| 661 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0xF0, i32, 7, 0x3B, 0xAC, |
| 662 0x3E, 0xF0, 0x00, 0x00, 0x00); |
| 663 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0xF0, i32, 7, 0x3B, 0xB4, |
| 664 0x47, 0xF0, 0x00, 0x00, 0x00); |
| 665 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0xF0, i32, 7, 0x3B, 0xBC, |
| 666 0x98, 0xF0, 0x00, 0x00, 0x00); |
| 667 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0xF0, i32, 7, 0x3B, 0x9C, |
| 668 0xD1, 0xF0, 0x00, 0x00, 0x00); |
| 669 |
| 670 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0xF0, i16, 8, 0x66, 0x3B, |
| 671 0x84, 0x11, 0xF0, 0x00, 0x00, 0x00); |
| 672 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0xF0, i16, 8, 0x66, 0x3B, |
| 673 0x8C, 0x5A, 0xF0, 0x00, 0x00, 0x00); |
| 674 // esp cannot be an scaled index. |
| 675 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0xF0, i16, 8, 0x66, 0x3B, |
| 676 0x9C, 0xAC, 0xF0, 0x00, 0x00, 0x00); |
| 677 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0xF0, i16, 8, 0x66, 0x3B, |
| 678 0xA4, 0xF5, 0xF0, 0x00, 0x00, 0x00); |
| 679 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0xF0, i16, 8, 0x66, 0x3B, |
| 680 0xAC, 0x3E, 0xF0, 0x00, 0x00, 0x00); |
| 681 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0xF0, i16, 8, 0x66, 0x3B, |
| 682 0xB4, 0x47, 0xF0, 0x00, 0x00, 0x00); |
| 683 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0xF0, i16, 8, 0x66, 0x3B, |
| 684 0xBC, 0x98, 0xF0, 0x00, 0x00, 0x00); |
| 685 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0xF0, i16, 8, 0x66, 0x3B, |
| 686 0x9C, 0xD1, 0xF0, 0x00, 0x00, 0x00); |
| 687 |
| 688 TestRegAddrBaseScaledIndex(cmp, eax, ecx, edx, 1, 0xF0, i8, 7, 0x3A, 0x84, |
| 689 0x11, 0xF0, 0x00, 0x00, 0x00); |
| 690 TestRegAddrBaseScaledIndex(cmp, ecx, edx, ebx, 2, 0xF0, i8, 7, 0x3A, 0x8C, |
| 691 0x5A, 0xF0, 0x00, 0x00, 0x00); |
| 692 // esp cannot be an scaled index. |
| 693 TestRegAddrBaseScaledIndex(cmp, ebx, esp, ebp, 4, 0xF0, i8, 7, 0x3A, 0x9C, |
| 694 0xAC, 0xF0, 0x00, 0x00, 0x00); |
| 695 TestRegAddrBaseScaledIndex(cmp, esp, ebp, esi, 8, 0xF0, i8, 7, 0x3A, 0xA4, |
| 696 0xF5, 0xF0, 0x00, 0x00, 0x00); |
| 697 TestRegAddrBaseScaledIndex(cmp, ebp, esi, edi, 1, 0xF0, i8, 7, 0x3A, 0xAC, |
| 698 0x3E, 0xF0, 0x00, 0x00, 0x00); |
| 699 TestRegAddrBaseScaledIndex(cmp, esi, edi, eax, 2, 0xF0, i8, 7, 0x3A, 0xB4, |
| 700 0x47, 0xF0, 0x00, 0x00, 0x00); |
| 701 TestRegAddrBaseScaledIndex(cmp, edi, eax, ebx, 4, 0xF0, i8, 7, 0x3A, 0xBC, |
| 702 0x98, 0xF0, 0x00, 0x00, 0x00); |
| 703 TestRegAddrBaseScaledIndex(cmp, ebx, ecx, edx, 8, 0xF0, i8, 7, 0x3A, 0x9C, |
| 704 0xD1, 0xF0, 0x00, 0x00, 0x00); |
| 705 |
| 706 /* cmp Addr, Imm */ |
| 707 // Note: at this point we trust the assembler knows how to encode addresses, |
| 708 // so no more exhaustive addressing mode testing. |
| 709 TestAddrBaseScaledIndexImm(cmp, eax, ecx, 1, 0xF0, 0x12, i32, 8, 0x83, 0xBC, |
| 710 0x08, 0xF0, 0x00, 0x00, 0x00, 0x12); |
| 711 TestAddrBaseScaledIndexImm(cmp, ecx, edx, 1, 0xF0, 0xF0, i32, 11, 0x81, 0xBC, |
| 712 0x11, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, |
| 713 0x00); |
| 714 |
| 715 TestAddrBaseScaledIndexImm(cmp, eax, ecx, 1, 0xF0, 0x12, i16, 9, 0x66, 0x83, |
| 716 0xBC, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x12); |
| 717 TestAddrBaseScaledIndexImm(cmp, ecx, edx, 1, 0xF0, 0xF0, i16, 10, 0x66, 0x81, |
| 718 0xBC, 0x11, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00); |
| 719 |
| 720 TestAddrBaseScaledIndexImm(cmp, eax, ecx, 1, 0xF0, 0x12, i8, 8, 0x80, 0xBC, |
| 721 0x08, 0xF0, 0x00, 0x00, 0x00, 0x12); |
| 722 |
| 723 /* cmp Addr, GPR */ |
| 724 TestAddrBaseScaledIndexReg(cmp, eax, ecx, 1, 0xF0, edx, i32, 7, 0x39, 0x94, |
| 725 0x08, 0xF0, 0x00, 0x00, 0x00); |
| 726 |
| 727 TestAddrBaseScaledIndexReg(cmp, eax, ecx, 1, 0xF0, edx, i16, 8, 0x66, 0x39, |
| 728 0x94, 0x08, 0xF0, 0x00, 0x00, 0x00); |
| 729 |
| 730 TestAddrBaseScaledIndexReg(cmp, eax, ecx, 1, 0xF0, edx, i8, 7, 0x38, 0x94, |
| 731 0x08, 0xF0, 0x00, 0x00, 0x00); |
| 732 |
| 733 #undef TestAddrBaseScaledIndexReg |
| 734 #undef TestAddrBaseScaledIndexImm |
| 735 #undef TestRegAddrBaseScaledIndex |
| 736 #undef TestRegAddrScaledIndex |
| 737 #undef TestRegAddrBase |
| 738 #undef TestRegAbsoluteAddr |
| 739 #undef TestRegImm |
| 740 #undef TestRegReg |
| 741 } |
| 742 |
| 743 TEST_F(AssemblerX8632LowLevelTest, Fld) { |
| 744 __ fld(IceType_f32, Address(GPRRegister::Encoded_Reg_ebp, 1)); |
| 745 __ fld(IceType_f64, Address(GPRRegister::Encoded_Reg_ebp, 0x10000)); |
| 746 |
| 747 constexpr size_t ByteCount = 9; |
| 183 ASSERT_EQ(ByteCount, codeBytesSize()); | 748 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 184 | 749 |
| 185 constexpr size_t CmpOpcode = 0x3b; | 750 constexpr uint8_t Fld32Opcode = 0xd9; |
| 186 constexpr size_t ModRm = 0xC0 /* Register Addressing */; | 751 constexpr uint8_t Fld32ModRM = (/*mod*/ 1 << 6) | (/*reg*/ 0 << 3) | |
| 187 verifyBytes<ByteCount>( | 752 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 188 codeBytes(), CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_eax << 3) | | 753 constexpr uint8_t Fld64Opcode = 0xdd; |
| 189 GPRRegister::Encoded_Reg_ebx, | 754 constexpr uint8_t Fld64ModRM = (/*mod*/ 2 << 6) | (/*reg*/ 0 << 3) | |
| 190 CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_ebx << 3) | | 755 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 191 GPRRegister::Encoded_Reg_ecx, | 756 verifyBytes<ByteCount>(codeBytes(), Fld32Opcode, Fld32ModRM, 0x01, |
| 192 CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_ecx << 3) | | 757 Fld64Opcode, Fld64ModRM, 0x00, 0x00, 0x01, 0x00); |
| 193 GPRRegister::Encoded_Reg_edx, | 758 } |
| 194 CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_edx << 3) | | 759 |
| 195 GPRRegister::Encoded_Reg_edi, | 760 TEST_F(AssemblerX8632LowLevelTest, FstpAddr) { |
| 196 CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_edi << 3) | | 761 __ fstp(IceType_f32, Address(GPRRegister::Encoded_Reg_ebp, 1)); |
| 197 GPRRegister::Encoded_Reg_esi, | 762 __ fstp(IceType_f64, Address(GPRRegister::Encoded_Reg_ebp, 0x10000)); |
| 198 CmpOpcode, ModRm | (GPRRegister::Encoded_Reg_esi << 3) | | 763 |
| 199 GPRRegister::Encoded_Reg_eax); | 764 constexpr size_t ByteCount = 9; |
| 765 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 766 |
| 767 constexpr uint8_t Fld32Opcode = 0xd9; |
| 768 constexpr uint8_t Fld32ModRM = (/*mod*/ 1 << 6) | (/*reg*/ 3 << 3) | |
| 769 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 770 constexpr uint8_t Fld64Opcode = 0xdd; |
| 771 constexpr uint8_t Fld64ModRM = (/*mod*/ 2 << 6) | (/*reg*/ 3 << 3) | |
| 772 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 773 verifyBytes<ByteCount>(codeBytes(), Fld32Opcode, Fld32ModRM, 0x01, |
| 774 Fld64Opcode, Fld64ModRM, 0x00, 0x00, 0x01, 0x00); |
| 775 } |
| 776 |
| 777 TEST_F(AssemblerX8632LowLevelTest, Fincstp) { |
| 778 __ fincstp(); |
| 779 |
| 780 constexpr size_t ByteCount = 2; |
| 781 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 782 |
| 783 verifyBytes<ByteCount>(codeBytes(), 0xD9, 0XF7); |
| 784 } |
| 785 |
| 786 TEST_F(AssemblerX8632LowLevelTest, FnstcwAddr) { |
| 787 __ fnstcw(Address(GPRRegister::Encoded_Reg_ebp, 0x12345)); |
| 788 |
| 789 constexpr size_t ByteCount = 6; |
| 790 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 791 |
| 792 constexpr uint8_t Opcode = 0xd9; |
| 793 constexpr uint8_t ModRM = (/*mod*/ 2 << 6) | (/*reg*/ 7 << 3) | |
| 794 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 795 verifyBytes<ByteCount>(codeBytes(), Opcode, ModRM, 0x45, 0x23, 0x01, 0x00); |
| 796 } |
| 797 |
| 798 TEST_F(AssemblerX8632LowLevelTest, FldcwAddr) { |
| 799 __ fldcw(Address(GPRRegister::Encoded_Reg_ebp, 0x12345)); |
| 800 |
| 801 constexpr size_t ByteCount = 6; |
| 802 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 803 |
| 804 constexpr uint8_t Opcode = 0xd9; |
| 805 constexpr uint8_t ModRM = (/*mod*/ 2 << 6) | (/*reg*/ 5 << 3) | |
| 806 (/*rm*/ GPRRegister::Encoded_Reg_ebp); |
| 807 verifyBytes<ByteCount>(codeBytes(), Opcode, ModRM, 0x45, 0x23, 0x01, 0x00); |
| 808 } |
| 809 |
| 810 TEST_F(AssemblerX8632LowLevelTest, PushalPopal) { |
| 811 // These are invalid in x86-64, so we can't write tests which will execute |
| 812 // these instructions. |
| 813 __ pushal(); |
| 814 __ popal(); |
| 815 |
| 816 constexpr size_t ByteCount = 2; |
| 817 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 818 |
| 819 constexpr uint8_t Pushal = 0x60; |
| 820 constexpr uint8_t Popal = 0x61; |
| 821 |
| 822 verifyBytes<ByteCount>(codeBytes(), Pushal, Popal); |
| 200 } | 823 } |
| 201 | 824 |
| 202 // After these tests we should have a sane environment; we know the following | 825 // After these tests we should have a sane environment; we know the following |
| 203 // work: | 826 // work: |
| 204 // | 827 // |
| 205 // (*) zeroing eax, ebx, ecx, edx, edi, and esi; | 828 // (*) zeroing eax, ebx, ecx, edx, edi, and esi; |
| 206 // (*) call $4 instruction (used for ip materialization); | 829 // (*) call $4 instruction (used for ip materialization); |
| 207 // (*) register push and pop; | 830 // (*) register push and pop; |
| 208 // (*) cmp reg, reg; and | 831 // (*) cmp reg, reg; and |
| 209 // (*) returning from functions. | 832 // (*) returning from functions. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // mov $0, %esi | 898 // mov $0, %esi |
| 276 // | 899 // |
| 277 // << test code goes here >> | 900 // << test code goes here >> |
| 278 // | 901 // |
| 279 // mov %eax, { 0 + $ScratchpadOffset}(%ebp) | 902 // mov %eax, { 0 + $ScratchpadOffset}(%ebp) |
| 280 // mov %ebx, { 4 + $ScratchpadOffset}(%ebp) | 903 // mov %ebx, { 4 + $ScratchpadOffset}(%ebp) |
| 281 // mov %ecx, { 8 + $ScratchpadOffset}(%ebp) | 904 // mov %ecx, { 8 + $ScratchpadOffset}(%ebp) |
| 282 // mov %edx, {12 + $ScratchpadOffset}(%ebp) | 905 // mov %edx, {12 + $ScratchpadOffset}(%ebp) |
| 283 // mov %edi, {16 + $ScratchpadOffset}(%ebp) | 906 // mov %edi, {16 + $ScratchpadOffset}(%ebp) |
| 284 // mov %esi, {20 + $ScratchpadOffset}(%ebp) | 907 // mov %esi, {20 + $ScratchpadOffset}(%ebp) |
| 908 // mov %ebp, {24 + $ScratchpadOffset}(%ebp) |
| 909 // mov %esp, {28 + $ScratchpadOffset}(%ebp) |
| 910 // movups %xmm0, {32 + $ScratchpadOffset}(%ebp) |
| 911 // movups %xmm1, {48 + $ScratchpadOffset}(%ebp) |
| 912 // movups %xmm2, {64 + $ScratchpadOffset}(%ebp) |
| 913 // movusp %xmm3, {80 + $ScratchpadOffset}(%ebp) |
| 914 // movusp %xmm4, {96 + $ScratchpadOffset}(%ebp) |
| 915 // movusp %xmm5, {112 + $ScratchpadOffset}(%ebp) |
| 916 // movusp %xmm6, {128 + $ScratchpadOffset}(%ebp) |
| 917 // movusp %xmm7, {144 + $ScratchpadOffset}(%ebp) |
| 285 // | 918 // |
| 286 // pop %ebp | 919 // pop %ebp |
| 287 // pop %esi | 920 // pop %esi |
| 288 // pop %edi | 921 // pop %edi |
| 289 // pop %edx | 922 // pop %edx |
| 290 // pop %ecx | 923 // pop %ecx |
| 291 // pop %ebx | 924 // pop %ebx |
| 292 // pop %eax | 925 // pop %eax |
| 293 // ret | 926 // ret |
| 294 // | 927 // |
| 295 // << ... >> | 928 // << ... >> |
| 296 // | 929 // |
| 297 // scratchpad: <<------- accessed via $Offset(%ebp) | 930 // scratchpad: <<------- accessed via $Offset(%ebp) |
| 298 // | 931 // |
| 299 // << test scratch area >> | 932 // << test scratch area >> |
| 300 // | 933 // |
| 301 // TODO(jpp): test the | 934 // TODO(jpp): test the |
| 302 // | 935 // |
| 303 // mov %reg, $Offset(%ebp) | 936 // mov %reg, $Offset(%ebp) |
| 937 // movups %xmm, $Offset(%ebp) |
| 304 // | 938 // |
| 305 // encodings using the low level assembler test ensuring that the register | 939 // encodings using the low level assembler test ensuring that the register |
| 306 // values can be written to the scratchpad area. | 940 // values can be written to the scratchpad area. |
| 307 class AssemblerX8632Test : public AssemblerX8632TestBase { | 941 class AssemblerX8632Test : public AssemblerX8632TestBase { |
| 308 protected: | 942 protected: |
| 943 // Dqword is used to represent 128-bit data types. The Dqword's contents are |
| 944 // the same as the contents read from memory. Tests can then use the union |
| 945 // members to verify the tests' outputs. |
| 946 // |
| 947 // NOTE: We want sizeof(Dqword) == sizeof(uint64_t) * 2. In other words, we |
| 948 // want Dqword's contents to be **exactly** what the memory contents were so |
| 949 // that we can do, e.g., |
| 950 // |
| 951 // ... |
| 952 // float Ret[4]; |
| 953 // // populate Ret |
| 954 // return *reinterpret_cast<Dqword *>(&Ret); |
| 955 // |
| 956 // While being an ugly hack, this kind of return statements are used |
| 957 // extensively in the PackedArith (see below) class. |
| 958 union Dqword { |
| 959 template <typename T0, typename T1, typename T2, typename T3, |
| 960 typename = typename std::enable_if< |
| 961 std::is_floating_point<T0>::value>::type> |
| 962 Dqword(T0 F0, T1 F1, T2 F2, T3 F3) { |
| 963 F32[0] = F0; |
| 964 F32[1] = F1; |
| 965 F32[2] = F2; |
| 966 F32[3] = F3; |
| 967 } |
| 968 |
| 969 template <typename T> |
| 970 Dqword(typename std::enable_if<std::is_same<T, int32_t>::value, T>::type I0, |
| 971 T I1, T I2, T I3) { |
| 972 I32[0] = I0; |
| 973 I32[1] = I1; |
| 974 I32[2] = I2; |
| 975 I32[3] = I3; |
| 976 } |
| 977 |
| 978 template <typename T> |
| 979 Dqword(typename std::enable_if<std::is_same<T, uint64_t>::value, T>::type |
| 980 U64_0, |
| 981 T U64_1) { |
| 982 U64[0] = U64_0; |
| 983 U64[1] = U64_1; |
| 984 } |
| 985 |
| 986 template <typename T> |
| 987 Dqword(typename std::enable_if<std::is_same<T, double>::value, T>::type D0, |
| 988 T D1) { |
| 989 F64[0] = D0; |
| 990 F64[1] = D1; |
| 991 } |
| 992 |
| 993 bool operator==(const Dqword &Rhs) const { |
| 994 return std::memcmp(this, &Rhs, sizeof(*this)) == 0; |
| 995 } |
| 996 |
| 997 double F64[2]; |
| 998 uint64_t U64[2]; |
| 999 int64_t I64[2]; |
| 1000 |
| 1001 float F32[4]; |
| 1002 uint32_t U32[4]; |
| 1003 int32_t I32[4]; |
| 1004 |
| 1005 uint16_t U16[8]; |
| 1006 int16_t I16[8]; |
| 1007 |
| 1008 uint8_t U8[16]; |
| 1009 int8_t I8[16]; |
| 1010 |
| 1011 private: |
| 1012 Dqword() = delete; |
| 1013 }; |
| 1014 |
| 1015 // As stated, we want this condition to hold, so we assert. |
| 1016 static_assert(sizeof(Dqword) == 2 * sizeof(uint64_t), |
| 1017 "Dqword has the wrong size."); |
| 1018 |
| 1019 // PackedArith is an interface provider for Dqwords. PackedArith's C argument |
| 1020 // is the undelying Dqword's type, which is then used so that we can define |
| 1021 // operators in terms of C++ operators on the underlying elements' type. |
| 1022 template <typename C> class PackedArith { |
| 1023 public: |
| 1024 static constexpr uint32_t N = sizeof(Dqword) / sizeof(C); |
| 1025 static_assert(N * sizeof(C) == sizeof(Dqword), |
| 1026 "Invalid template paramenter."); |
| 1027 static_assert((N & 1) == 0, "N should be divisible by 2"); |
| 1028 |
| 1029 #define DefinePackedComparisonOperator(Op) \ |
| 1030 template <typename Container = C, int Size = N> \ |
| 1031 typename std::enable_if<std::is_floating_point<Container>::value, \ |
| 1032 Dqword>::type \ |
| 1033 operator Op(const Dqword &Rhs) const { \ |
| 1034 using ElemType = \ |
| 1035 typename std::conditional<std::is_same<float, Container>::value, \ |
| 1036 int32_t, int64_t>::type; \ |
| 1037 static_assert(sizeof(ElemType) == sizeof(Container), \ |
| 1038 "Check ElemType definition."); \ |
| 1039 const ElemType *const RhsPtr = \ |
| 1040 reinterpret_cast<const ElemType *const>(&Rhs); \ |
| 1041 const ElemType *const LhsPtr = \ |
| 1042 reinterpret_cast<const ElemType *const>(&Lhs); \ |
| 1043 ElemType Ret[N]; \ |
| 1044 for (uint32_t i = 0; i < N; ++i) { \ |
| 1045 Ret[i] = (LhsPtr[i] Op RhsPtr[i]) ? -1 : 0; \ |
| 1046 } \ |
| 1047 return *reinterpret_cast<Dqword *>(&Ret); \ |
| 1048 } |
| 1049 |
| 1050 DefinePackedComparisonOperator(< ); |
| 1051 DefinePackedComparisonOperator(<= ); |
| 1052 DefinePackedComparisonOperator(> ); |
| 1053 DefinePackedComparisonOperator(>= ); |
| 1054 DefinePackedComparisonOperator(== ); |
| 1055 DefinePackedComparisonOperator(!= ); |
| 1056 |
| 1057 #undef DefinePackedComparisonOperator |
| 1058 |
| 1059 #define DefinePackedOrdUnordComparisonOperator(Op, Ordered) \ |
| 1060 template <typename Container = C, int Size = N> \ |
| 1061 typename std::enable_if<std::is_floating_point<Container>::value, \ |
| 1062 Dqword>::type \ |
| 1063 Op(const Dqword &Rhs) const { \ |
| 1064 using ElemType = \ |
| 1065 typename std::conditional<std::is_same<float, Container>::value, \ |
| 1066 int32_t, int64_t>::type; \ |
| 1067 static_assert(sizeof(ElemType) == sizeof(Container), \ |
| 1068 "Check ElemType definition."); \ |
| 1069 const Container *const RhsPtr = \ |
| 1070 reinterpret_cast<const Container *const>(&Rhs); \ |
| 1071 const Container *const LhsPtr = \ |
| 1072 reinterpret_cast<const Container *const>(&Lhs); \ |
| 1073 ElemType Ret[N]; \ |
| 1074 for (uint32_t i = 0; i < N; ++i) { \ |
| 1075 Ret[i] = (!(LhsPtr[i] == LhsPtr[i]) || !(RhsPtr[i] == RhsPtr[i])) != \ |
| 1076 (Ordered) \ |
| 1077 ? -1 \ |
| 1078 : 0; \ |
| 1079 } \ |
| 1080 return *reinterpret_cast<Dqword *>(&Ret); \ |
| 1081 } |
| 1082 |
| 1083 DefinePackedOrdUnordComparisonOperator(ord, true); |
| 1084 DefinePackedOrdUnordComparisonOperator(unord, false); |
| 1085 #undef DefinePackedOrdUnordComparisonOperator |
| 1086 |
| 1087 #define DefinePackedArithOperator(Op, RhsIndexChanges, NeedsInt) \ |
| 1088 template <typename Container = C, int Size = N> \ |
| 1089 Dqword operator Op(const Dqword &Rhs) const { \ |
| 1090 using ElemTypeForFp = typename std::conditional< \ |
| 1091 !(NeedsInt), Container, \ |
| 1092 typename std::conditional< \ |
| 1093 std::is_same<Container, float>::value, uint32_t, \ |
| 1094 typename std::conditional<std::is_same<Container, double>::value, \ |
| 1095 uint64_t, void>::type>::type>::type; \ |
| 1096 using ElemType = \ |
| 1097 typename std::conditional<std::is_integral<Container>::value, \ |
| 1098 Container, ElemTypeForFp>::type; \ |
| 1099 static_assert(!std::is_same<void, ElemType>::value, \ |
| 1100 "Check ElemType definition."); \ |
| 1101 const ElemType *const RhsPtr = \ |
| 1102 reinterpret_cast<const ElemType *const>(&Rhs); \ |
| 1103 const ElemType *const LhsPtr = \ |
| 1104 reinterpret_cast<const ElemType *const>(&Lhs); \ |
| 1105 ElemType Ret[N]; \ |
| 1106 for (uint32_t i = 0; i < N; ++i) { \ |
| 1107 Ret[i] = LhsPtr[i] Op RhsPtr[(RhsIndexChanges) ? i : 0]; \ |
| 1108 } \ |
| 1109 return *reinterpret_cast<Dqword *>(&Ret); \ |
| 1110 } |
| 1111 |
| 1112 DefinePackedArithOperator(>>, false, true); |
| 1113 DefinePackedArithOperator(<<, false, true); |
| 1114 DefinePackedArithOperator(+, true, false); |
| 1115 DefinePackedArithOperator(-, true, false); |
| 1116 DefinePackedArithOperator(/, true, false); |
| 1117 DefinePackedArithOperator(&, true, true); |
| 1118 DefinePackedArithOperator(|, true, true); |
| 1119 DefinePackedArithOperator (^, true, true); |
| 1120 |
| 1121 #undef DefinePackedArithOperator |
| 1122 |
| 1123 #define DefinePackedArithShiftImm(Op) \ |
| 1124 template <typename Container = C, int Size = N> \ |
| 1125 Dqword operator Op(uint8_t imm) const { \ |
| 1126 const Container *const LhsPtr = \ |
| 1127 reinterpret_cast<const Container *const>(&Lhs); \ |
| 1128 Container Ret[N]; \ |
| 1129 for (uint32_t i = 0; i < N; ++i) { \ |
| 1130 Ret[i] = LhsPtr[i] Op imm; \ |
| 1131 } \ |
| 1132 return *reinterpret_cast<Dqword *>(&Ret); \ |
| 1133 } |
| 1134 |
| 1135 DefinePackedArithShiftImm(>> ); |
| 1136 DefinePackedArithShiftImm(<< ); |
| 1137 |
| 1138 #undef DefinePackedArithShiftImm |
| 1139 |
| 1140 template <typename Container = C, int Size = N> |
| 1141 typename std::enable_if<std::is_signed<Container>::value || |
| 1142 std::is_floating_point<Container>::value, |
| 1143 Dqword>::type |
| 1144 operator*(const Dqword &Rhs) const { |
| 1145 static_assert((std::is_integral<Container>::value && |
| 1146 sizeof(Container) < sizeof(uint64_t)) || |
| 1147 std::is_floating_point<Container>::value, |
| 1148 "* is only defined for i(8|16|32), and fp types."); |
| 1149 |
| 1150 const Container *const RhsPtr = |
| 1151 reinterpret_cast<const Container *const>(&Rhs); |
| 1152 const Container *const LhsPtr = |
| 1153 reinterpret_cast<const Container *const>(&Lhs); |
| 1154 Container Ret[Size]; |
| 1155 for (uint32_t i = 0; i < Size; ++i) { |
| 1156 Ret[i] = LhsPtr[i] * RhsPtr[i]; |
| 1157 } |
| 1158 return *reinterpret_cast<Dqword *>(&Ret); |
| 1159 } |
| 1160 |
| 1161 template <typename Container = C, int Size = N, |
| 1162 typename = typename std::enable_if< |
| 1163 !std::is_signed<Container>::value>::type> |
| 1164 Dqword operator*(const Dqword &Rhs) const { |
| 1165 static_assert(std::is_integral<Container>::value && |
| 1166 sizeof(Container) < sizeof(uint64_t), |
| 1167 "* is only defined for ui(8|16|32)"); |
| 1168 using NextType = typename std::conditional< |
| 1169 sizeof(Container) == 1, uint16_t, |
| 1170 typename std::conditional<sizeof(Container) == 2, uint32_t, |
| 1171 uint64_t>::type>::type; |
| 1172 static_assert(sizeof(Container) * 2 == sizeof(NextType), |
| 1173 "Unexpected size"); |
| 1174 |
| 1175 const Container *const RhsPtr = |
| 1176 reinterpret_cast<const Container *const>(&Rhs); |
| 1177 const Container *const LhsPtr = |
| 1178 reinterpret_cast<const Container *const>(&Lhs); |
| 1179 NextType Ret[Size / 2]; |
| 1180 for (uint32_t i = 0; i < Size; i += 2) { |
| 1181 Ret[i / 2] = |
| 1182 static_cast<NextType>(LhsPtr[i]) * static_cast<NextType>(RhsPtr[i]); |
| 1183 } |
| 1184 return *reinterpret_cast<Dqword *>(&Ret); |
| 1185 } |
| 1186 |
| 1187 template <typename Container = C, int Size = N> |
| 1188 PackedArith<Container> operator~() const { |
| 1189 const Container *const LhsPtr = |
| 1190 reinterpret_cast<const Container *const>(&Lhs); |
| 1191 Container Ret[Size]; |
| 1192 for (uint32_t i = 0; i < Size; ++i) { |
| 1193 Ret[i] = ~LhsPtr[i]; |
| 1194 } |
| 1195 return PackedArith<Container>(*reinterpret_cast<Dqword *>(&Ret)); |
| 1196 } |
| 1197 |
| 1198 #define MinMaxOperations(Name, Suffix) \ |
| 1199 template <typename Container = C, int Size = N> \ |
| 1200 Dqword Name##Suffix(const Dqword &Rhs) const { \ |
| 1201 static_assert(std::is_floating_point<Container>::value, \ |
| 1202 #Name #Suffix "ps is only available for fp."); \ |
| 1203 const Container *const RhsPtr = \ |
| 1204 reinterpret_cast<const Container *const>(&Rhs); \ |
| 1205 const Container *const LhsPtr = \ |
| 1206 reinterpret_cast<const Container *const>(&Lhs); \ |
| 1207 Container Ret[Size]; \ |
| 1208 for (uint32_t i = 0; i < Size; ++i) { \ |
| 1209 Ret[i] = std::Name(LhsPtr[i], RhsPtr[i]); \ |
| 1210 } \ |
| 1211 return *reinterpret_cast<Dqword *>(&Ret); \ |
| 1212 } |
| 1213 |
| 1214 MinMaxOperations(max, ps); |
| 1215 MinMaxOperations(max, pd); |
| 1216 MinMaxOperations(min, ps); |
| 1217 MinMaxOperations(min, pd); |
| 1218 #undef MinMaxOperations |
| 1219 |
| 1220 template <typename Container = C, int Size = N> |
| 1221 Dqword blendWith(const Dqword &Rhs, const Dqword &Mask) const { |
| 1222 using MaskType = typename std::conditional< |
| 1223 sizeof(Container) == 1, int8_t, |
| 1224 typename std::conditional<sizeof(Container) == 2, int16_t, |
| 1225 int32_t>::type>::type; |
| 1226 static_assert(sizeof(MaskType) == sizeof(Container), |
| 1227 "MaskType has the wrong size."); |
| 1228 const Container *const RhsPtr = |
| 1229 reinterpret_cast<const Container *const>(&Rhs); |
| 1230 const Container *const LhsPtr = |
| 1231 reinterpret_cast<const Container *const>(&Lhs); |
| 1232 const MaskType *const MaskPtr = |
| 1233 reinterpret_cast<const MaskType *const>(&Mask); |
| 1234 Container Ret[Size]; |
| 1235 for (int i = 0; i < Size; ++i) { |
| 1236 Ret[i] = ((MaskPtr[i] < 0) ? RhsPtr : LhsPtr)[i]; |
| 1237 } |
| 1238 return *reinterpret_cast<Dqword *>(&Ret); |
| 1239 } |
| 1240 |
| 1241 private: |
| 1242 // The AssemblerX8632Test class needs to be a friend so that it can create |
| 1243 // PackedArith objects (see below.) |
| 1244 friend class AssemblerX8632Test; |
| 1245 |
| 1246 explicit PackedArith(const Dqword &MyLhs) : Lhs(MyLhs) {} |
| 1247 |
| 1248 // Lhs can't be a & because operator~ returns a temporary object that needs |
| 1249 // access to its own Dqword. |
| 1250 const Dqword Lhs; |
| 1251 }; |
| 1252 |
| 1253 // Named constructor for PackedArith objects. |
| 1254 template <typename C> static PackedArith<C> packedAs(const Dqword &D) { |
| 1255 return PackedArith<C>(D); |
| 1256 } |
| 1257 |
| 309 AssemblerX8632Test() { reset(); } | 1258 AssemblerX8632Test() { reset(); } |
| 310 | 1259 |
| 311 void reset() { | 1260 void reset() { |
| 312 AssemblerX8632TestBase::reset(); | 1261 AssemblerX8632TestBase::reset(); |
| 313 | 1262 |
| 314 NeedsEpilogue = true; | 1263 NeedsEpilogue = true; |
| 315 // 6 dwords are allocated for saving the GPR state after the jitted code | 1264 // These dwords are allocated for saving the GPR state after the jitted code |
| 316 // runs. | 1265 // runs. |
| 317 NumAllocatedDwords = 6; | 1266 NumAllocatedDwords = AssembledTest::ScratchpadSlots; |
| 318 addPrologue(); | 1267 addPrologue(); |
| 319 } | 1268 } |
| 320 | 1269 |
| 321 // AssembledBuffer is a wrapper around a PROT_EXEC mmap'ed buffer. This buffer | 1270 // AssembledTest is a wrapper around a PROT_EXEC mmap'ed buffer. This buffer |
| 322 // contains both the test code as well as prologue/epilogue, and the | 1271 // contains both the test code as well as prologue/epilogue, and the |
| 323 // scratchpad area that tests may use -- all tests use this scratchpad area | 1272 // scratchpad area that tests may use -- all tests use this scratchpad area |
| 324 // for storing the processor's registers after the tests executed. This class | 1273 // for storing the processor's registers after the tests executed. This class |
| 325 // also exposes helper methods for reading the register state after test | 1274 // also exposes helper methods for reading the register state after test |
| 326 // execution, as well as for reading the scratchpad area. | 1275 // execution, as well as for reading the scratchpad area. |
| 327 class AssembledBuffer { | 1276 class AssembledTest { |
| 328 AssembledBuffer() = delete; | 1277 AssembledTest() = delete; |
| 329 AssembledBuffer(const AssembledBuffer &) = delete; | 1278 AssembledTest(const AssembledTest &) = delete; |
| 330 AssembledBuffer &operator=(const AssembledBuffer &) = delete; | 1279 AssembledTest &operator=(const AssembledTest &) = delete; |
| 331 | 1280 |
| 332 public: | 1281 public: |
| 333 static constexpr uint32_t MaximumCodeSize = 1 << 20; | 1282 static constexpr uint32_t MaximumCodeSize = 1 << 20; |
| 334 static constexpr uint32_t EaxSlot = 0; | 1283 static constexpr uint32_t EaxSlot = 0; |
| 335 static constexpr uint32_t EbxSlot = 1; | 1284 static constexpr uint32_t EbxSlot = 1; |
| 336 static constexpr uint32_t EcxSlot = 2; | 1285 static constexpr uint32_t EcxSlot = 2; |
| 337 static constexpr uint32_t EdxSlot = 3; | 1286 static constexpr uint32_t EdxSlot = 3; |
| 338 static constexpr uint32_t EdiSlot = 4; | 1287 static constexpr uint32_t EdiSlot = 4; |
| 339 static constexpr uint32_t EsiSlot = 5; | 1288 static constexpr uint32_t EsiSlot = 5; |
| 1289 static constexpr uint32_t EbpSlot = 6; |
| 1290 static constexpr uint32_t EspSlot = 7; |
| 1291 // save 4 dwords for each xmm registers. |
| 1292 static constexpr uint32_t Xmm0Slot = 8; |
| 1293 static constexpr uint32_t Xmm1Slot = 12; |
| 1294 static constexpr uint32_t Xmm2Slot = 16; |
| 1295 static constexpr uint32_t Xmm3Slot = 20; |
| 1296 static constexpr uint32_t Xmm4Slot = 24; |
| 1297 static constexpr uint32_t Xmm5Slot = 28; |
| 1298 static constexpr uint32_t Xmm6Slot = 32; |
| 1299 static constexpr uint32_t Xmm7Slot = 36; |
| 1300 static constexpr uint32_t ScratchpadSlots = 40; |
| 340 | 1301 |
| 341 AssembledBuffer(const uint8_t *Data, const size_t MySize, | 1302 AssembledTest(const uint8_t *Data, const size_t MySize, |
| 342 const size_t ExtraStorageDwords) | 1303 const size_t ExtraStorageDwords) |
| 343 : Size(MaximumCodeSize + 4 * ExtraStorageDwords) { | 1304 : Size(MaximumCodeSize + 4 * ExtraStorageDwords) { |
| 344 // MaxCodeSize is needed because EXPECT_LT needs a symbol with a name -- | 1305 // MaxCodeSize is needed because EXPECT_LT needs a symbol with a name -- |
| 345 // probably a compiler bug? | 1306 // probably a compiler bug? |
| 346 uint32_t MaxCodeSize = MaximumCodeSize; | 1307 uint32_t MaxCodeSize = MaximumCodeSize; |
| 347 EXPECT_LT(MySize, MaxCodeSize); | 1308 EXPECT_LT(MySize, MaxCodeSize); |
| 348 assert(MySize < MaximumCodeSize); | 1309 assert(MySize < MaximumCodeSize); |
| 349 ExecutableData = mmap(nullptr, Size, PROT_WRITE | PROT_READ | PROT_EXEC, | 1310 ExecutableData = mmap(nullptr, Size, PROT_WRITE | PROT_READ | PROT_EXEC, |
| 350 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 1311 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 351 EXPECT_NE(MAP_FAILED, ExecutableData) << strerror(errno); | 1312 EXPECT_NE(MAP_FAILED, ExecutableData) << strerror(errno); |
| 352 assert(MAP_FAILED != ExecutableData); | 1313 assert(MAP_FAILED != ExecutableData); |
| 353 std::memcpy(ExecutableData, Data, MySize); | 1314 std::memcpy(ExecutableData, Data, MySize); |
| 354 } | 1315 } |
| 355 | 1316 |
| 356 // We allow AssembledBuffer to be moved so that we can return objects of | 1317 // We allow AssembledTest to be moved so that we can return objects of |
| 357 // this type. | 1318 // this type. |
| 358 AssembledBuffer(AssembledBuffer &&Buffer) | 1319 AssembledTest(AssembledTest &&Buffer) |
| 359 : ExecutableData(Buffer.ExecutableData), Size(Buffer.Size) { | 1320 : ExecutableData(Buffer.ExecutableData), Size(Buffer.Size) { |
| 360 Buffer.ExecutableData = nullptr; | 1321 Buffer.ExecutableData = nullptr; |
| 361 Buffer.Size = 0; | 1322 Buffer.Size = 0; |
| 362 } | 1323 } |
| 363 | 1324 |
| 364 AssembledBuffer &operator=(AssembledBuffer &&Buffer) { | 1325 AssembledTest &operator=(AssembledTest &&Buffer) { |
| 365 ExecutableData = Buffer.ExecutableData; | 1326 ExecutableData = Buffer.ExecutableData; |
| 366 Buffer.ExecutableData = nullptr; | 1327 Buffer.ExecutableData = nullptr; |
| 367 Size = Buffer.Size; | 1328 Size = Buffer.Size; |
| 368 Buffer.Size = 0; | 1329 Buffer.Size = 0; |
| 369 return *this; | 1330 return *this; |
| 370 } | 1331 } |
| 371 | 1332 |
| 372 ~AssembledBuffer() { | 1333 ~AssembledTest() { |
| 373 if (ExecutableData != nullptr) { | 1334 if (ExecutableData != nullptr) { |
| 374 munmap(ExecutableData, Size); | 1335 munmap(ExecutableData, Size); |
| 375 ExecutableData = nullptr; | 1336 ExecutableData = nullptr; |
| 376 } | 1337 } |
| 377 } | 1338 } |
| 378 | 1339 |
| 379 void run() const { reinterpret_cast<void (*)()>(ExecutableData)(); } | 1340 void run() const { reinterpret_cast<void (*)()>(ExecutableData)(); } |
| 380 | 1341 |
| 381 uint32_t eax() const { return contentsOfDword(AssembledBuffer::EaxSlot); } | 1342 uint32_t eax() const { return contentsOfDword(AssembledTest::EaxSlot); } |
| 382 | 1343 |
| 383 uint32_t ebx() const { return contentsOfDword(AssembledBuffer::EbxSlot); } | 1344 uint32_t ebx() const { return contentsOfDword(AssembledTest::EbxSlot); } |
| 384 | 1345 |
| 385 uint32_t ecx() const { return contentsOfDword(AssembledBuffer::EcxSlot); } | 1346 uint32_t ecx() const { return contentsOfDword(AssembledTest::EcxSlot); } |
| 386 | 1347 |
| 387 uint32_t edx() const { return contentsOfDword(AssembledBuffer::EdxSlot); } | 1348 uint32_t edx() const { return contentsOfDword(AssembledTest::EdxSlot); } |
| 388 | 1349 |
| 389 uint32_t edi() const { return contentsOfDword(AssembledBuffer::EdiSlot); } | 1350 uint32_t edi() const { return contentsOfDword(AssembledTest::EdiSlot); } |
| 390 | 1351 |
| 391 uint32_t esi() const { return contentsOfDword(AssembledBuffer::EsiSlot); } | 1352 uint32_t esi() const { return contentsOfDword(AssembledTest::EsiSlot); } |
| 1353 |
| 1354 uint32_t ebp() const { return contentsOfDword(AssembledTest::EbpSlot); } |
| 1355 |
| 1356 uint32_t esp() const { return contentsOfDword(AssembledTest::EspSlot); } |
| 1357 |
| 1358 template <typename T> T xmm0() const { |
| 1359 return xmm<T>(AssembledTest::Xmm0Slot); |
| 1360 } |
| 1361 |
| 1362 template <typename T> T xmm1() const { |
| 1363 return xmm<T>(AssembledTest::Xmm1Slot); |
| 1364 } |
| 1365 |
| 1366 template <typename T> T xmm2() const { |
| 1367 return xmm<T>(AssembledTest::Xmm2Slot); |
| 1368 } |
| 1369 |
| 1370 template <typename T> T xmm3() const { |
| 1371 return xmm<T>(AssembledTest::Xmm3Slot); |
| 1372 } |
| 1373 |
| 1374 template <typename T> T xmm4() const { |
| 1375 return xmm<T>(AssembledTest::Xmm4Slot); |
| 1376 } |
| 1377 |
| 1378 template <typename T> T xmm5() const { |
| 1379 return xmm<T>(AssembledTest::Xmm5Slot); |
| 1380 } |
| 1381 |
| 1382 template <typename T> T xmm6() const { |
| 1383 return xmm<T>(AssembledTest::Xmm6Slot); |
| 1384 } |
| 1385 |
| 1386 template <typename T> T xmm7() const { |
| 1387 return xmm<T>(AssembledTest::Xmm7Slot); |
| 1388 } |
| 392 | 1389 |
| 393 // contentsOfDword is used for reading the values in the scratchpad area. | 1390 // contentsOfDword is used for reading the values in the scratchpad area. |
| 394 // Valid arguments are the dword ids returned by | 1391 // Valid arguments are the dword ids returned by |
| 395 // AssemblerX8632Test::allocateDword() -- other inputs are considered | 1392 // AssemblerX8632Test::allocateDword() -- other inputs are considered |
| 396 // invalid, and are not guaranteed to work if the implementation changes. | 1393 // invalid, and are not guaranteed to work if the implementation changes. |
| 397 uint32_t contentsOfDword(uint32_t Dword) const { | 1394 template <typename T = uint32_t, typename = typename std::enable_if< |
| 398 return *reinterpret_cast<uint32_t *>( | 1395 sizeof(T) == sizeof(uint32_t)>::type> |
| 399 static_cast<uint8_t *>(ExecutableData) + dwordOffset(Dword)); | 1396 T contentsOfDword(uint32_t Dword) const { |
| 1397 return *reinterpret_cast<T *>(static_cast<uint8_t *>(ExecutableData) + |
| 1398 dwordOffset(Dword)); |
| 1399 } |
| 1400 |
| 1401 template <typename T = uint64_t, typename = typename std::enable_if< |
| 1402 sizeof(T) == sizeof(uint64_t)>::type> |
| 1403 T contentsOfQword(uint32_t InitialDword) const { |
| 1404 return *reinterpret_cast<T *>(static_cast<uint8_t *>(ExecutableData) + |
| 1405 dwordOffset(InitialDword)); |
| 1406 } |
| 1407 |
| 1408 Dqword contentsOfDqword(uint32_t InitialDword) const { |
| 1409 return *reinterpret_cast<Dqword *>( |
| 1410 static_cast<uint8_t *>(ExecutableData) + |
| 1411 dwordOffset(InitialDword)); |
| 1412 } |
| 1413 |
| 1414 template <typename T = uint32_t, typename = typename std::enable_if< |
| 1415 sizeof(T) == sizeof(uint32_t)>::type> |
| 1416 void setDwordTo(uint32_t Dword, T value) { |
| 1417 *reinterpret_cast<uint32_t *>(static_cast<uint8_t *>(ExecutableData) + |
| 1418 dwordOffset(Dword)) = |
| 1419 *reinterpret_cast<uint32_t *>(&value); |
| 1420 } |
| 1421 |
| 1422 template <typename T = uint64_t, typename = typename std::enable_if< |
| 1423 sizeof(T) == sizeof(uint64_t)>::type> |
| 1424 void setQwordTo(uint32_t InitialDword, T value) { |
| 1425 *reinterpret_cast<uint64_t *>(static_cast<uint8_t *>(ExecutableData) + |
| 1426 dwordOffset(InitialDword)) = |
| 1427 *reinterpret_cast<uint64_t *>(&value); |
| 1428 } |
| 1429 |
| 1430 void setDqwordTo(uint32_t InitialDword, const Dqword &qdword) { |
| 1431 setQwordTo(InitialDword, qdword.U64[0]); |
| 1432 setQwordTo(InitialDword + 2, qdword.U64[1]); |
| 400 } | 1433 } |
| 401 | 1434 |
| 402 private: | 1435 private: |
| 1436 template <typename T> |
| 1437 typename std::enable_if<std::is_same<T, Dqword>::value, Dqword>::type |
| 1438 xmm(uint8_t Slot) const { |
| 1439 return contentsOfDqword(Slot); |
| 1440 } |
| 1441 |
| 1442 template <typename T> |
| 1443 typename std::enable_if<!std::is_same<T, Dqword>::value, T>::type |
| 1444 xmm(uint8_t Slot) const { |
| 1445 constexpr bool TIs64Bit = sizeof(T) == sizeof(uint64_t); |
| 1446 using _64BitType = typename std::conditional<TIs64Bit, T, uint64_t>::type; |
| 1447 using _32BitType = typename std::conditional<TIs64Bit, uint32_t, T>::type; |
| 1448 if (TIs64Bit) { |
| 1449 return contentsOfQword<_64BitType>(Slot); |
| 1450 } |
| 1451 return contentsOfDword<_32BitType>(Slot); |
| 1452 } |
| 1453 |
| 403 static uint32_t dwordOffset(uint32_t Index) { | 1454 static uint32_t dwordOffset(uint32_t Index) { |
| 404 return MaximumCodeSize + (Index * 4); | 1455 return MaximumCodeSize + (Index * 4); |
| 405 } | 1456 } |
| 406 | 1457 |
| 407 void *ExecutableData = nullptr; | 1458 void *ExecutableData = nullptr; |
| 408 size_t Size; | 1459 size_t Size; |
| 409 }; | 1460 }; |
| 410 | 1461 |
| 411 // assemble created an AssembledBuffer with the jitted code. The first time | 1462 // assemble created an AssembledTest with the jitted code. The first time |
| 412 // assemble is executed it will add the epilogue to the jitted code (which is | 1463 // assemble is executed it will add the epilogue to the jitted code (which is |
| 413 // the reason why this method is not const qualified. | 1464 // the reason why this method is not const qualified. |
| 414 AssembledBuffer assemble() { | 1465 AssembledTest assemble() { |
| 415 if (NeedsEpilogue) { | 1466 if (NeedsEpilogue) { |
| 416 addEpilogue(); | 1467 addEpilogue(); |
| 417 } | 1468 } |
| 418 | 1469 |
| 419 NeedsEpilogue = false; | 1470 NeedsEpilogue = false; |
| 420 return AssembledBuffer(codeBytes(), codeBytesSize(), NumAllocatedDwords); | 1471 return AssembledTest(codeBytes(), codeBytesSize(), NumAllocatedDwords); |
| 421 } | 1472 } |
| 422 | 1473 |
| 423 // Allocates a new dword slot in the test's scratchpad area. | 1474 // Allocates a new dword slot in the test's scratchpad area. |
| 424 uint32_t allocateDword() { return NumAllocatedDwords++; } | 1475 uint32_t allocateDword() { return NumAllocatedDwords++; } |
| 425 | 1476 |
| 1477 // Allocates a new qword slot in the test's scratchpad area. |
| 1478 uint32_t allocateQword() { |
| 1479 uint32_t InitialDword = allocateDword(); |
| 1480 allocateDword(); |
| 1481 return InitialDword; |
| 1482 } |
| 1483 |
| 1484 // Allocates a new dqword slot in the test's scratchpad area. |
| 1485 uint32_t allocateDqword() { |
| 1486 uint32_t InitialDword = allocateQword(); |
| 1487 allocateQword(); |
| 1488 return InitialDword; |
| 1489 } |
| 1490 |
| 426 Address dwordAddress(uint32_t Dword) { | 1491 Address dwordAddress(uint32_t Dword) { |
| 427 return Address(GPRRegister::Encoded_Reg_ebp, dwordDisp(Dword)); | 1492 return Address(GPRRegister::Encoded_Reg_ebp, dwordDisp(Dword)); |
| 428 } | 1493 } |
| 429 | 1494 |
| 430 private: | 1495 private: |
| 431 // e??SlotAddress returns an AssemblerX8632::Traits::Address that can be used | 1496 // e??SlotAddress returns an AssemblerX8632::Traits::Address that can be used |
| 432 // by the test cases to encode an address operand for accessing the slot for | 1497 // by the test cases to encode an address operand for accessing the slot for |
| 433 // the specified register. These are all private for, when jitting the test | 1498 // the specified register. These are all private for, when jitting the test |
| 434 // code, tests should not tamper with these values. Besides, during the test | 1499 // code, tests should not tamper with these values. Besides, during the test |
| 435 // execution these slots' contents are undefined and should not be accessed. | 1500 // execution these slots' contents are undefined and should not be accessed. |
| 436 Address eaxSlotAddress() { return dwordAddress(AssembledBuffer::EaxSlot); } | 1501 Address eaxSlotAddress() { return dwordAddress(AssembledTest::EaxSlot); } |
| 437 Address ebxSlotAddress() { return dwordAddress(AssembledBuffer::EbxSlot); } | 1502 Address ebxSlotAddress() { return dwordAddress(AssembledTest::EbxSlot); } |
| 438 Address ecxSlotAddress() { return dwordAddress(AssembledBuffer::EcxSlot); } | 1503 Address ecxSlotAddress() { return dwordAddress(AssembledTest::EcxSlot); } |
| 439 Address edxSlotAddress() { return dwordAddress(AssembledBuffer::EdxSlot); } | 1504 Address edxSlotAddress() { return dwordAddress(AssembledTest::EdxSlot); } |
| 440 Address ediSlotAddress() { return dwordAddress(AssembledBuffer::EdiSlot); } | 1505 Address ediSlotAddress() { return dwordAddress(AssembledTest::EdiSlot); } |
| 441 Address esiSlotAddress() { return dwordAddress(AssembledBuffer::EsiSlot); } | 1506 Address esiSlotAddress() { return dwordAddress(AssembledTest::EsiSlot); } |
| 1507 Address ebpSlotAddress() { return dwordAddress(AssembledTest::EbpSlot); } |
| 1508 Address espSlotAddress() { return dwordAddress(AssembledTest::EspSlot); } |
| 1509 Address xmm0SlotAddress() { return dwordAddress(AssembledTest::Xmm0Slot); } |
| 1510 Address xmm1SlotAddress() { return dwordAddress(AssembledTest::Xmm1Slot); } |
| 1511 Address xmm2SlotAddress() { return dwordAddress(AssembledTest::Xmm2Slot); } |
| 1512 Address xmm3SlotAddress() { return dwordAddress(AssembledTest::Xmm3Slot); } |
| 1513 Address xmm4SlotAddress() { return dwordAddress(AssembledTest::Xmm4Slot); } |
| 1514 Address xmm5SlotAddress() { return dwordAddress(AssembledTest::Xmm5Slot); } |
| 1515 Address xmm6SlotAddress() { return dwordAddress(AssembledTest::Xmm6Slot); } |
| 1516 Address xmm7SlotAddress() { return dwordAddress(AssembledTest::Xmm7Slot); } |
| 442 | 1517 |
| 443 // Returns the displacement that should be used when accessing the specified | 1518 // Returns the displacement that should be used when accessing the specified |
| 444 // Dword in the scratchpad area. It needs to adjust for the initial | 1519 // Dword in the scratchpad area. It needs to adjust for the initial |
| 445 // instructions that are emitted before the call that materializes the IP | 1520 // instructions that are emitted before the call that materializes the IP |
| 446 // register. | 1521 // register. |
| 447 uint32_t dwordDisp(uint32_t Dword) const { | 1522 uint32_t dwordDisp(uint32_t Dword) const { |
| 448 EXPECT_LT(Dword, NumAllocatedDwords); | 1523 EXPECT_LT(Dword, NumAllocatedDwords); |
| 449 assert(Dword < NumAllocatedDwords); | 1524 assert(Dword < NumAllocatedDwords); |
| 450 static constexpr uint8_t PushBytes = 1; | 1525 static constexpr uint8_t PushBytes = 1; |
| 451 static constexpr uint8_t CallImmBytes = 5; | 1526 static constexpr uint8_t CallImmBytes = 5; |
| 452 return AssembledBuffer::MaximumCodeSize + (Dword * 4) - | 1527 return AssembledTest::MaximumCodeSize + (Dword * 4) - |
| 453 (7 * PushBytes + CallImmBytes); | 1528 (7 * PushBytes + CallImmBytes); |
| 454 } | 1529 } |
| 455 | 1530 |
| 456 void addPrologue() { | 1531 void addPrologue() { |
| 457 __ pushl(GPRRegister::Encoded_Reg_eax); | 1532 __ pushl(GPRRegister::Encoded_Reg_eax); |
| 458 __ pushl(GPRRegister::Encoded_Reg_ebx); | 1533 __ pushl(GPRRegister::Encoded_Reg_ebx); |
| 459 __ pushl(GPRRegister::Encoded_Reg_ecx); | 1534 __ pushl(GPRRegister::Encoded_Reg_ecx); |
| 460 __ pushl(GPRRegister::Encoded_Reg_edx); | 1535 __ pushl(GPRRegister::Encoded_Reg_edx); |
| 461 __ pushl(GPRRegister::Encoded_Reg_edi); | 1536 __ pushl(GPRRegister::Encoded_Reg_edi); |
| 462 __ pushl(GPRRegister::Encoded_Reg_esi); | 1537 __ pushl(GPRRegister::Encoded_Reg_esi); |
| 463 __ pushl(GPRRegister::Encoded_Reg_ebp); | 1538 __ pushl(GPRRegister::Encoded_Reg_ebp); |
| 464 | 1539 |
| 465 __ call(Immediate(4)); | 1540 __ call(Immediate(4)); |
| 466 __ popl(GPRRegister::Encoded_Reg_ebp); | 1541 __ popl(GPRRegister::Encoded_Reg_ebp); |
| 467 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0x00)); | 1542 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0x00)); |
| 468 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, Immediate(0x00)); | 1543 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, Immediate(0x00)); |
| 469 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(0x00)); | 1544 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(0x00)); |
| 470 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(0x00)); | 1545 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(0x00)); |
| 471 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(0x00)); | 1546 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(0x00)); |
| 472 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(0x00)); | 1547 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(0x00)); |
| 473 } | 1548 } |
| 474 | 1549 |
| 475 void addEpilogue() { | 1550 void addEpilogue() { |
| 476 __ mov(IceType_i32, eaxSlotAddress(), GPRRegister::Encoded_Reg_eax); | 1551 __ mov(IceType_i32, eaxSlotAddress(), GPRRegister::Encoded_Reg_eax); |
| 477 __ mov(IceType_i32, ebxSlotAddress(), GPRRegister::Encoded_Reg_ebx); | 1552 __ mov(IceType_i32, ebxSlotAddress(), GPRRegister::Encoded_Reg_ebx); |
| 478 __ mov(IceType_i32, ecxSlotAddress(), GPRRegister::Encoded_Reg_ecx); | 1553 __ mov(IceType_i32, ecxSlotAddress(), GPRRegister::Encoded_Reg_ecx); |
| 479 __ mov(IceType_i32, edxSlotAddress(), GPRRegister::Encoded_Reg_edx); | 1554 __ mov(IceType_i32, edxSlotAddress(), GPRRegister::Encoded_Reg_edx); |
| 480 __ mov(IceType_i32, ediSlotAddress(), GPRRegister::Encoded_Reg_edi); | 1555 __ mov(IceType_i32, ediSlotAddress(), GPRRegister::Encoded_Reg_edi); |
| 481 __ mov(IceType_i32, esiSlotAddress(), GPRRegister::Encoded_Reg_esi); | 1556 __ mov(IceType_i32, esiSlotAddress(), GPRRegister::Encoded_Reg_esi); |
| 1557 __ mov(IceType_i32, ebpSlotAddress(), GPRRegister::Encoded_Reg_ebp); |
| 1558 __ mov(IceType_i32, espSlotAddress(), GPRRegister::Encoded_Reg_esp); |
| 1559 __ movups(xmm0SlotAddress(), XmmRegister::Encoded_Reg_xmm0); |
| 1560 __ movups(xmm1SlotAddress(), XmmRegister::Encoded_Reg_xmm1); |
| 1561 __ movups(xmm2SlotAddress(), XmmRegister::Encoded_Reg_xmm2); |
| 1562 __ movups(xmm3SlotAddress(), XmmRegister::Encoded_Reg_xmm3); |
| 1563 __ movups(xmm4SlotAddress(), XmmRegister::Encoded_Reg_xmm4); |
| 1564 __ movups(xmm5SlotAddress(), XmmRegister::Encoded_Reg_xmm5); |
| 1565 __ movups(xmm6SlotAddress(), XmmRegister::Encoded_Reg_xmm6); |
| 1566 __ movups(xmm7SlotAddress(), XmmRegister::Encoded_Reg_xmm7); |
| 482 | 1567 |
| 483 __ popl(GPRRegister::Encoded_Reg_ebp); | 1568 __ popl(GPRRegister::Encoded_Reg_ebp); |
| 484 __ popl(GPRRegister::Encoded_Reg_esi); | 1569 __ popl(GPRRegister::Encoded_Reg_esi); |
| 485 __ popl(GPRRegister::Encoded_Reg_edi); | 1570 __ popl(GPRRegister::Encoded_Reg_edi); |
| 486 __ popl(GPRRegister::Encoded_Reg_edx); | 1571 __ popl(GPRRegister::Encoded_Reg_edx); |
| 487 __ popl(GPRRegister::Encoded_Reg_ecx); | 1572 __ popl(GPRRegister::Encoded_Reg_ecx); |
| 488 __ popl(GPRRegister::Encoded_Reg_ebx); | 1573 __ popl(GPRRegister::Encoded_Reg_ebx); |
| 489 __ popl(GPRRegister::Encoded_Reg_eax); | 1574 __ popl(GPRRegister::Encoded_Reg_eax); |
| 490 | 1575 |
| 491 __ ret(); | 1576 __ ret(); |
| 492 } | 1577 } |
| 493 | 1578 |
| 494 bool NeedsEpilogue; | 1579 bool NeedsEpilogue; |
| 495 uint32_t NumAllocatedDwords; | 1580 uint32_t NumAllocatedDwords; |
| 496 }; | 1581 }; |
| 497 | 1582 |
| 1583 TEST_F(AssemblerX8632Test, ScratchpadGettersAndSetters) { |
| 1584 const uint32_t S0 = allocateDword(); |
| 1585 const uint32_t S1 = allocateDword(); |
| 1586 const uint32_t S2 = allocateDword(); |
| 1587 const uint32_t S3 = allocateDword(); |
| 1588 AssembledTest test = assemble(); |
| 1589 test.setDwordTo(S0, 0xBEEF0000u); |
| 1590 test.setDwordTo(S1, 0xDEADu); |
| 1591 test.setDwordTo(S2, 0x20406080u); |
| 1592 ASSERT_EQ(0xBEEF0000u, test.contentsOfDword(S0)); |
| 1593 ASSERT_EQ(0xDEADu, test.contentsOfDword(S1)); |
| 1594 ASSERT_EQ(0x20406080u, test.contentsOfDword(S2)); |
| 1595 ASSERT_EQ(0xDEADBEEF0000ull, test.contentsOfQword(S0)); |
| 1596 ASSERT_EQ(0x204060800000DEADull, test.contentsOfQword(S1)); |
| 1597 |
| 1598 test.setQwordTo(S1, 0x1234567890ABCDEFull); |
| 1599 ASSERT_EQ(0x1234567890ABCDEFull, test.contentsOfQword(S1)); |
| 1600 test.setDwordTo(S0, 0xBEEF0000u); |
| 1601 ASSERT_EQ(0x90ABCDEFull, test.contentsOfDword(S1)); |
| 1602 ASSERT_EQ(0x12345678ull, test.contentsOfDword(S2)); |
| 1603 |
| 1604 test.setDwordTo(S0, 1.0f); |
| 1605 ASSERT_FLOAT_EQ(1.0f, test.contentsOfDword<float>(S0)); |
| 1606 test.setQwordTo(S0, 3.14); |
| 1607 ASSERT_DOUBLE_EQ(3.14, test.contentsOfQword<double>(S0)); |
| 1608 |
| 1609 test.setDqwordTo(S0, Dqword(1.0f, 2.0f, 3.0f, 4.0f)); |
| 1610 ASSERT_EQ(Dqword(1.0f, 2.0f, 3.0f, 4.0f), test.contentsOfDqword(S0)); |
| 1611 EXPECT_FLOAT_EQ(1.0f, test.contentsOfDword<float>(S0)); |
| 1612 EXPECT_FLOAT_EQ(2.0f, test.contentsOfDword<float>(S1)); |
| 1613 EXPECT_FLOAT_EQ(3.0f, test.contentsOfDword<float>(S2)); |
| 1614 EXPECT_FLOAT_EQ(4.0f, test.contentsOfDword<float>(S3)); |
| 1615 } |
| 1616 |
| 498 TEST_F(AssemblerX8632Test, MovRegImm) { | 1617 TEST_F(AssemblerX8632Test, MovRegImm) { |
| 499 constexpr uint32_t ExpectedEax = 0x000000FFul; | 1618 constexpr uint32_t ExpectedEax = 0x000000FFul; |
| 500 constexpr uint32_t ExpectedEbx = 0x0000FF00ul; | 1619 constexpr uint32_t ExpectedEbx = 0x0000FF00ul; |
| 501 constexpr uint32_t ExpectedEcx = 0x00FF0000ul; | 1620 constexpr uint32_t ExpectedEcx = 0x00FF0000ul; |
| 502 constexpr uint32_t ExpectedEdx = 0xFF000000ul; | 1621 constexpr uint32_t ExpectedEdx = 0xFF000000ul; |
| 503 constexpr uint32_t ExpectedEdi = 0x6AAA0006ul; | 1622 constexpr uint32_t ExpectedEdi = 0x6AAA0006ul; |
| 504 constexpr uint32_t ExpectedEsi = 0x6000AAA6ul; | 1623 constexpr uint32_t ExpectedEsi = 0x6000AAA6ul; |
| 505 | 1624 |
| 506 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ExpectedEax)); | 1625 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ExpectedEax)); |
| 507 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, Immediate(ExpectedEbx)); | 1626 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, Immediate(ExpectedEbx)); |
| 508 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(ExpectedEcx)); | 1627 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(ExpectedEcx)); |
| 509 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(ExpectedEdx)); | 1628 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(ExpectedEdx)); |
| 510 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(ExpectedEdi)); | 1629 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(ExpectedEdi)); |
| 511 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(ExpectedEsi)); | 1630 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(ExpectedEsi)); |
| 512 | 1631 |
| 513 AssembledBuffer test = assemble(); | 1632 AssembledTest test = assemble(); |
| 514 test.run(); | 1633 test.run(); |
| 515 EXPECT_EQ(ExpectedEax, test.eax()); | 1634 EXPECT_EQ(ExpectedEax, test.eax()); |
| 516 EXPECT_EQ(ExpectedEbx, test.ebx()); | 1635 EXPECT_EQ(ExpectedEbx, test.ebx()); |
| 517 EXPECT_EQ(ExpectedEcx, test.ecx()); | 1636 EXPECT_EQ(ExpectedEcx, test.ecx()); |
| 518 EXPECT_EQ(ExpectedEdx, test.edx()); | 1637 EXPECT_EQ(ExpectedEdx, test.edx()); |
| 519 EXPECT_EQ(ExpectedEdi, test.edi()); | 1638 EXPECT_EQ(ExpectedEdi, test.edi()); |
| 520 EXPECT_EQ(ExpectedEsi, test.esi()); | 1639 EXPECT_EQ(ExpectedEsi, test.esi()); |
| 521 } | 1640 } |
| 522 | 1641 |
| 523 TEST_F(AssemblerX8632Test, MovMemImm) { | 1642 TEST_F(AssemblerX8632Test, MovMemImm) { |
| 524 const uint32_t T0 = allocateDword(); | 1643 const uint32_t T0 = allocateDword(); |
| 525 constexpr uint32_t ExpectedT0 = 0x00111100ul; | 1644 constexpr uint32_t ExpectedT0 = 0x00111100ul; |
| 526 const uint32_t T1 = allocateDword(); | 1645 const uint32_t T1 = allocateDword(); |
| 527 constexpr uint32_t ExpectedT1 = 0x00222200ul; | 1646 constexpr uint32_t ExpectedT1 = 0x00222200ul; |
| 528 const uint32_t T2 = allocateDword(); | 1647 const uint32_t T2 = allocateDword(); |
| 529 constexpr uint32_t ExpectedT2 = 0x03333000ul; | 1648 constexpr uint32_t ExpectedT2 = 0x03333000ul; |
| 530 const uint32_t T3 = allocateDword(); | 1649 const uint32_t T3 = allocateDword(); |
| 531 constexpr uint32_t ExpectedT3 = 0x00444400ul; | 1650 constexpr uint32_t ExpectedT3 = 0x00444400ul; |
| 532 | 1651 |
| 533 __ mov(IceType_i32, dwordAddress(T0), Immediate(ExpectedT0)); | 1652 __ mov(IceType_i32, dwordAddress(T0), Immediate(ExpectedT0)); |
| 534 __ mov(IceType_i32, dwordAddress(T1), Immediate(ExpectedT1)); | 1653 __ mov(IceType_i32, dwordAddress(T1), Immediate(ExpectedT1)); |
| 535 __ mov(IceType_i32, dwordAddress(T2), Immediate(ExpectedT2)); | 1654 __ mov(IceType_i32, dwordAddress(T2), Immediate(ExpectedT2)); |
| 536 __ mov(IceType_i32, dwordAddress(T3), Immediate(ExpectedT3)); | 1655 __ mov(IceType_i32, dwordAddress(T3), Immediate(ExpectedT3)); |
| 537 | 1656 |
| 538 AssembledBuffer test = assemble(); | 1657 AssembledTest test = assemble(); |
| 539 test.run(); | 1658 test.run(); |
| 540 EXPECT_EQ(0ul, test.eax()); | 1659 EXPECT_EQ(0ul, test.eax()); |
| 541 EXPECT_EQ(0ul, test.ebx()); | 1660 EXPECT_EQ(0ul, test.ebx()); |
| 542 EXPECT_EQ(0ul, test.ecx()); | 1661 EXPECT_EQ(0ul, test.ecx()); |
| 543 EXPECT_EQ(0ul, test.edx()); | 1662 EXPECT_EQ(0ul, test.edx()); |
| 544 EXPECT_EQ(0ul, test.edi()); | 1663 EXPECT_EQ(0ul, test.edi()); |
| 545 EXPECT_EQ(0ul, test.esi()); | 1664 EXPECT_EQ(0ul, test.esi()); |
| 546 EXPECT_EQ(ExpectedT0, test.contentsOfDword(T0)); | 1665 EXPECT_EQ(ExpectedT0, test.contentsOfDword(T0)); |
| 547 EXPECT_EQ(ExpectedT1, test.contentsOfDword(T1)); | 1666 EXPECT_EQ(ExpectedT1, test.contentsOfDword(T1)); |
| 548 EXPECT_EQ(ExpectedT2, test.contentsOfDword(T2)); | 1667 EXPECT_EQ(ExpectedT2, test.contentsOfDword(T2)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 569 __ mov(IceType_i32, dwordAddress(T1), GPRRegister::Encoded_Reg_ebx); | 1688 __ mov(IceType_i32, dwordAddress(T1), GPRRegister::Encoded_Reg_ebx); |
| 570 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(ExpectedT2)); | 1689 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, Immediate(ExpectedT2)); |
| 571 __ mov(IceType_i32, dwordAddress(T2), GPRRegister::Encoded_Reg_ecx); | 1690 __ mov(IceType_i32, dwordAddress(T2), GPRRegister::Encoded_Reg_ecx); |
| 572 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(ExpectedT3)); | 1691 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, Immediate(ExpectedT3)); |
| 573 __ mov(IceType_i32, dwordAddress(T3), GPRRegister::Encoded_Reg_edx); | 1692 __ mov(IceType_i32, dwordAddress(T3), GPRRegister::Encoded_Reg_edx); |
| 574 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(ExpectedT4)); | 1693 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, Immediate(ExpectedT4)); |
| 575 __ mov(IceType_i32, dwordAddress(T4), GPRRegister::Encoded_Reg_edi); | 1694 __ mov(IceType_i32, dwordAddress(T4), GPRRegister::Encoded_Reg_edi); |
| 576 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(ExpectedT5)); | 1695 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(ExpectedT5)); |
| 577 __ mov(IceType_i32, dwordAddress(T5), GPRRegister::Encoded_Reg_esi); | 1696 __ mov(IceType_i32, dwordAddress(T5), GPRRegister::Encoded_Reg_esi); |
| 578 | 1697 |
| 579 AssembledBuffer test = assemble(); | 1698 AssembledTest test = assemble(); |
| 580 test.run(); | 1699 test.run(); |
| 581 EXPECT_EQ(ExpectedT0, test.contentsOfDword(T0)); | 1700 EXPECT_EQ(ExpectedT0, test.contentsOfDword(T0)); |
| 582 EXPECT_EQ(ExpectedT1, test.contentsOfDword(T1)); | 1701 EXPECT_EQ(ExpectedT1, test.contentsOfDword(T1)); |
| 583 EXPECT_EQ(ExpectedT2, test.contentsOfDword(T2)); | 1702 EXPECT_EQ(ExpectedT2, test.contentsOfDword(T2)); |
| 584 EXPECT_EQ(ExpectedT3, test.contentsOfDword(T3)); | 1703 EXPECT_EQ(ExpectedT3, test.contentsOfDword(T3)); |
| 585 EXPECT_EQ(ExpectedT4, test.contentsOfDword(T4)); | 1704 EXPECT_EQ(ExpectedT4, test.contentsOfDword(T4)); |
| 586 EXPECT_EQ(ExpectedT5, test.contentsOfDword(T5)); | 1705 EXPECT_EQ(ExpectedT5, test.contentsOfDword(T5)); |
| 587 } | 1706 } |
| 588 | 1707 |
| 589 TEST_F(AssemblerX8632Test, MovRegReg) { | 1708 TEST_F(AssemblerX8632Test, MovRegReg) { |
| 590 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0x20)); | 1709 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0x20)); |
| 591 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, | 1710 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, |
| 592 GPRRegister::Encoded_Reg_eax); | 1711 GPRRegister::Encoded_Reg_eax); |
| 593 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, | 1712 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, |
| 594 GPRRegister::Encoded_Reg_ebx); | 1713 GPRRegister::Encoded_Reg_ebx); |
| 595 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, | 1714 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, |
| 596 GPRRegister::Encoded_Reg_ecx); | 1715 GPRRegister::Encoded_Reg_ecx); |
| 597 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, | 1716 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, |
| 598 GPRRegister::Encoded_Reg_edx); | 1717 GPRRegister::Encoded_Reg_edx); |
| 599 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, | 1718 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, |
| 600 GPRRegister::Encoded_Reg_edi); | 1719 GPRRegister::Encoded_Reg_edi); |
| 601 | 1720 |
| 602 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(0x55000000ul)); | 1721 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, Immediate(0x55000000ul)); |
| 603 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, | 1722 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, |
| 604 GPRRegister::Encoded_Reg_esi); | 1723 GPRRegister::Encoded_Reg_esi); |
| 605 | 1724 |
| 606 AssembledBuffer test = assemble(); | 1725 AssembledTest test = assemble(); |
| 607 test.run(); | 1726 test.run(); |
| 608 EXPECT_EQ(0x55000000ul, test.eax()); | 1727 EXPECT_EQ(0x55000000ul, test.eax()); |
| 609 EXPECT_EQ(0x20ul, test.ebx()); | 1728 EXPECT_EQ(0x20ul, test.ebx()); |
| 610 EXPECT_EQ(0x20ul, test.ecx()); | 1729 EXPECT_EQ(0x20ul, test.ecx()); |
| 611 EXPECT_EQ(0x20ul, test.edx()); | 1730 EXPECT_EQ(0x20ul, test.edx()); |
| 612 EXPECT_EQ(0x20ul, test.edi()); | 1731 EXPECT_EQ(0x20ul, test.edi()); |
| 613 EXPECT_EQ(0x55000000ul, test.esi()); | 1732 EXPECT_EQ(0x55000000ul, test.esi()); |
| 614 } | 1733 } |
| 615 | 1734 |
| 616 TEST_F(AssemblerX8632Test, MovRegMem) { | 1735 TEST_F(AssemblerX8632Test, MovRegMem) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 638 | 1757 |
| 639 __ mov(IceType_i32, dwordAddress(T3), Immediate(ExpectedT3)); | 1758 __ mov(IceType_i32, dwordAddress(T3), Immediate(ExpectedT3)); |
| 640 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, dwordAddress(T3)); | 1759 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, dwordAddress(T3)); |
| 641 | 1760 |
| 642 __ mov(IceType_i32, dwordAddress(T4), Immediate(ExpectedT4)); | 1761 __ mov(IceType_i32, dwordAddress(T4), Immediate(ExpectedT4)); |
| 643 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, dwordAddress(T4)); | 1762 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edi, dwordAddress(T4)); |
| 644 | 1763 |
| 645 __ mov(IceType_i32, dwordAddress(T5), Immediate(ExpectedT5)); | 1764 __ mov(IceType_i32, dwordAddress(T5), Immediate(ExpectedT5)); |
| 646 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, dwordAddress(T5)); | 1765 __ mov(IceType_i32, GPRRegister::Encoded_Reg_esi, dwordAddress(T5)); |
| 647 | 1766 |
| 648 AssembledBuffer test = assemble(); | 1767 AssembledTest test = assemble(); |
| 649 test.run(); | 1768 test.run(); |
| 650 EXPECT_EQ(ExpectedT0, test.eax()); | 1769 EXPECT_EQ(ExpectedT0, test.eax()); |
| 651 EXPECT_EQ(ExpectedT1, test.ebx()); | 1770 EXPECT_EQ(ExpectedT1, test.ebx()); |
| 652 EXPECT_EQ(ExpectedT2, test.ecx()); | 1771 EXPECT_EQ(ExpectedT2, test.ecx()); |
| 653 EXPECT_EQ(ExpectedT3, test.edx()); | 1772 EXPECT_EQ(ExpectedT3, test.edx()); |
| 654 EXPECT_EQ(ExpectedT4, test.edi()); | 1773 EXPECT_EQ(ExpectedT4, test.edi()); |
| 655 EXPECT_EQ(ExpectedT5, test.esi()); | 1774 EXPECT_EQ(ExpectedT5, test.esi()); |
| 656 } | 1775 } |
| 657 | 1776 |
| 658 TEST_F(AssemblerX8632Test, J) { | 1777 TEST_F(AssemblerX8632Test, J) { |
| 659 #define TestJ(C, Near, Src0, Value0, Src1, Value1, Dest) \ | 1778 #define TestJ(C, Near, Src0, Value0, Src1, Value1, Dest) \ |
| 660 do { \ | 1779 do { \ |
| 661 const bool NearJmp = std::strcmp(#Near, "Near") == 0; \ | 1780 const bool NearJmp = AssemblerX8632::k##Near##Jump; \ |
| 662 Label ShouldBeTaken; \ | 1781 Label ShouldBeTaken; \ |
| 663 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src0, Immediate(Value0)); \ | 1782 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src0, Immediate(Value0)); \ |
| 664 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src1, Immediate(Value1)); \ | 1783 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src1, Immediate(Value1)); \ |
| 665 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(0xBEEF)); \ | 1784 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(0xBEEF)); \ |
| 666 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_##Src0, \ | 1785 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_##Src0, \ |
| 667 GPRRegister::Encoded_Reg_##Src1); \ | 1786 GPRRegister::Encoded_Reg_##Src1); \ |
| 668 __ j(Cond::Br_##C, &ShouldBeTaken, NearJmp); \ | 1787 __ j(Cond::Br_##C, &ShouldBeTaken, NearJmp); \ |
| 669 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(0xC0FFEE)); \ | 1788 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(0xC0FFEE)); \ |
| 670 __ bind(&ShouldBeTaken); \ | 1789 __ bind(&ShouldBeTaken); \ |
| 671 AssembledBuffer test = assemble(); \ | 1790 AssembledTest test = assemble(); \ |
| 672 test.run(); \ | 1791 test.run(); \ |
| 673 EXPECT_EQ(Value0, test.Src0()) << "Br_" #C ", " #Near; \ | 1792 EXPECT_EQ(Value0, test.Src0()) << "Br_" #C ", " #Near; \ |
| 674 EXPECT_EQ(Value1, test.Src1()) << "Br_" #C ", " #Near; \ | 1793 EXPECT_EQ(Value1, test.Src1()) << "Br_" #C ", " #Near; \ |
| 675 EXPECT_EQ(0xBEEFul, test.Dest()) << "Br_" #C ", " #Near; \ | 1794 EXPECT_EQ(0xBEEFul, test.Dest()) << "Br_" #C ", " #Near; \ |
| 676 reset(); \ | 1795 reset(); \ |
| 677 } while (0) | 1796 } while (0) |
| 678 | 1797 |
| 679 TestJ(o, Near, eax, 0x80000000ul, ebx, 0x1ul, ecx); | 1798 TestJ(o, Near, eax, 0x80000000ul, ebx, 0x1ul, ecx); |
| 680 TestJ(o, Far, ebx, 0x80000000ul, ecx, 0x1ul, edx); | 1799 TestJ(o, Far, ebx, 0x80000000ul, ecx, 0x1ul, edx); |
| 681 TestJ(no, Near, ecx, 0x1ul, edx, 0x1ul, edi); | 1800 TestJ(no, Near, ecx, 0x1ul, edx, 0x1ul, edi); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 705 TestJ(ge, Near, ecx, 0x1ul, edx, 0x80000000ul, edi); | 1824 TestJ(ge, Near, ecx, 0x1ul, edx, 0x80000000ul, edi); |
| 706 TestJ(ge, Far, edx, 0x1ul, edi, 0x80000000ul, esi); | 1825 TestJ(ge, Far, edx, 0x1ul, edi, 0x80000000ul, esi); |
| 707 TestJ(le, Near, edi, 0x80000000ul, esi, 0x1ul, eax); | 1826 TestJ(le, Near, edi, 0x80000000ul, esi, 0x1ul, eax); |
| 708 TestJ(le, Far, esi, 0x80000000ul, eax, 0x1ul, ebx); | 1827 TestJ(le, Far, esi, 0x80000000ul, eax, 0x1ul, ebx); |
| 709 TestJ(g, Near, eax, 0x1ul, ebx, 0x80000000ul, ecx); | 1828 TestJ(g, Near, eax, 0x1ul, ebx, 0x80000000ul, ecx); |
| 710 TestJ(g, Far, ebx, 0x1ul, ecx, 0x80000000ul, edx); | 1829 TestJ(g, Far, ebx, 0x1ul, ecx, 0x80000000ul, edx); |
| 711 | 1830 |
| 712 #undef TestJ | 1831 #undef TestJ |
| 713 } | 1832 } |
| 714 | 1833 |
| 1834 TEST_F(AssemblerX8632Test, FstpSt) { |
| 1835 #define TestFstpSt(Size, MemorySize, Type) \ |
| 1836 do { \ |
| 1837 const uint32_t T1 = allocate##MemorySize(); \ |
| 1838 const Type OldValue1 = -1.0f; \ |
| 1839 const uint32_t T2 = allocate##MemorySize(); \ |
| 1840 const Type OldValue2 = -2.0f; \ |
| 1841 const uint32_t T3 = allocate##MemorySize(); \ |
| 1842 const Type OldValue3 = -3.0f; \ |
| 1843 const uint32_t T4 = allocate##MemorySize(); \ |
| 1844 const Type OldValue4 = -4.0f; \ |
| 1845 const uint32_t T5 = allocate##MemorySize(); \ |
| 1846 const Type OldValue5 = -5.0f; \ |
| 1847 const uint32_t T6 = allocate##MemorySize(); \ |
| 1848 const Type OldValue6 = -6.0f; \ |
| 1849 const uint32_t T7 = allocate##MemorySize(); \ |
| 1850 const Type OldValue7 = -7.0f; \ |
| 1851 \ |
| 1852 const uint32_t N7 = allocate##MemorySize(); \ |
| 1853 constexpr Type NewValue7 = 777.77f; \ |
| 1854 const uint32_t N6 = allocate##MemorySize(); \ |
| 1855 constexpr Type NewValue6 = 666.66f; \ |
| 1856 const uint32_t N5 = allocate##MemorySize(); \ |
| 1857 constexpr Type NewValue5 = 555.55f; \ |
| 1858 const uint32_t N4 = allocate##MemorySize(); \ |
| 1859 constexpr Type NewValue4 = 444.44f; \ |
| 1860 const uint32_t N3 = allocate##MemorySize(); \ |
| 1861 constexpr Type NewValue3 = 333.33f; \ |
| 1862 const uint32_t N2 = allocate##MemorySize(); \ |
| 1863 constexpr Type NewValue2 = 222.22f; \ |
| 1864 const uint32_t N1 = allocate##MemorySize(); \ |
| 1865 constexpr Type NewValue1 = 111.11f; \ |
| 1866 \ |
| 1867 __ fincstp(); \ |
| 1868 __ fincstp(); \ |
| 1869 __ fincstp(); \ |
| 1870 __ fincstp(); \ |
| 1871 __ fincstp(); \ |
| 1872 __ fincstp(); \ |
| 1873 __ fincstp(); \ |
| 1874 \ |
| 1875 __ fld(IceType_f##Size, dwordAddress(N7)); \ |
| 1876 __ fstp(X87STRegister::Encoded_X87ST_7); \ |
| 1877 __ fld(IceType_f##Size, dwordAddress(N6)); \ |
| 1878 __ fstp(X87STRegister::Encoded_X87ST_6); \ |
| 1879 __ fld(IceType_f##Size, dwordAddress(N5)); \ |
| 1880 __ fstp(X87STRegister::Encoded_X87ST_5); \ |
| 1881 __ fld(IceType_f##Size, dwordAddress(N4)); \ |
| 1882 __ fstp(X87STRegister::Encoded_X87ST_4); \ |
| 1883 __ fld(IceType_f##Size, dwordAddress(N3)); \ |
| 1884 __ fstp(X87STRegister::Encoded_X87ST_3); \ |
| 1885 __ fld(IceType_f##Size, dwordAddress(N2)); \ |
| 1886 __ fstp(X87STRegister::Encoded_X87ST_2); \ |
| 1887 __ fld(IceType_f##Size, dwordAddress(N1)); \ |
| 1888 __ fstp(X87STRegister::Encoded_X87ST_1); \ |
| 1889 \ |
| 1890 __ fstp(IceType_f##Size, dwordAddress(T1)); \ |
| 1891 __ fstp(IceType_f##Size, dwordAddress(T2)); \ |
| 1892 __ fstp(IceType_f##Size, dwordAddress(T3)); \ |
| 1893 __ fstp(IceType_f##Size, dwordAddress(T4)); \ |
| 1894 __ fstp(IceType_f##Size, dwordAddress(T5)); \ |
| 1895 __ fstp(IceType_f##Size, dwordAddress(T6)); \ |
| 1896 __ fstp(IceType_f##Size, dwordAddress(T7)); \ |
| 1897 \ |
| 1898 AssembledTest test = assemble(); \ |
| 1899 test.set##MemorySize##To(T1, OldValue1); \ |
| 1900 test.set##MemorySize##To(N1, NewValue1); \ |
| 1901 test.set##MemorySize##To(T2, OldValue2); \ |
| 1902 test.set##MemorySize##To(N2, NewValue2); \ |
| 1903 test.set##MemorySize##To(T3, OldValue3); \ |
| 1904 test.set##MemorySize##To(N3, NewValue3); \ |
| 1905 test.set##MemorySize##To(T4, OldValue4); \ |
| 1906 test.set##MemorySize##To(N4, NewValue4); \ |
| 1907 test.set##MemorySize##To(T5, OldValue5); \ |
| 1908 test.set##MemorySize##To(N5, NewValue5); \ |
| 1909 test.set##MemorySize##To(T6, OldValue6); \ |
| 1910 test.set##MemorySize##To(N6, NewValue6); \ |
| 1911 test.set##MemorySize##To(T7, OldValue7); \ |
| 1912 test.set##MemorySize##To(N7, NewValue7); \ |
| 1913 \ |
| 1914 test.run(); \ |
| 1915 \ |
| 1916 ASSERT_FLOAT_EQ(NewValue1, test.contentsOf##MemorySize<Type>(T1)) \ |
| 1917 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1918 ASSERT_FLOAT_EQ(NewValue1, test.contentsOf##MemorySize<Type>(N1)) \ |
| 1919 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1920 ASSERT_FLOAT_EQ(NewValue2, test.contentsOf##MemorySize<Type>(T2)) \ |
| 1921 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1922 ASSERT_FLOAT_EQ(NewValue2, test.contentsOf##MemorySize<Type>(N2)) \ |
| 1923 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1924 ASSERT_FLOAT_EQ(NewValue3, test.contentsOf##MemorySize<Type>(T3)) \ |
| 1925 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1926 ASSERT_FLOAT_EQ(NewValue3, test.contentsOf##MemorySize<Type>(N3)) \ |
| 1927 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1928 ASSERT_FLOAT_EQ(NewValue4, test.contentsOf##MemorySize<Type>(T4)) \ |
| 1929 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1930 ASSERT_FLOAT_EQ(NewValue4, test.contentsOf##MemorySize<Type>(N4)) \ |
| 1931 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1932 ASSERT_FLOAT_EQ(NewValue5, test.contentsOf##MemorySize<Type>(T5)) \ |
| 1933 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1934 ASSERT_FLOAT_EQ(NewValue5, test.contentsOf##MemorySize<Type>(N5)) \ |
| 1935 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1936 ASSERT_FLOAT_EQ(NewValue6, test.contentsOf##MemorySize<Type>(T6)) \ |
| 1937 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1938 ASSERT_FLOAT_EQ(NewValue6, test.contentsOf##MemorySize<Type>(N6)) \ |
| 1939 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1940 ASSERT_FLOAT_EQ(NewValue7, test.contentsOf##MemorySize<Type>(T7)) \ |
| 1941 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1942 ASSERT_FLOAT_EQ(NewValue7, test.contentsOf##MemorySize<Type>(N7)) \ |
| 1943 << "(" #Size ", " #MemorySize ", " #Type ")"; \ |
| 1944 \ |
| 1945 reset(); \ |
| 1946 } while (0) |
| 1947 |
| 1948 TestFstpSt(32, Dword, float); |
| 1949 TestFstpSt(64, Qword, double); |
| 1950 |
| 1951 #undef TestFstpSt |
| 1952 } |
| 1953 |
| 1954 TEST_F(AssemblerX8632Test, Fild) { |
| 1955 #define TestFild(OperandType, Size, MemorySize, FpType, IntType) \ |
| 1956 do { \ |
| 1957 const uint32_t T0 = allocate##MemorySize(); \ |
| 1958 constexpr IntType V0 = 0x1234; \ |
| 1959 \ |
| 1960 __ fild##OperandType(dwordAddress(T0)); \ |
| 1961 __ fstp(IceType_f##Size, dwordAddress(T0)); \ |
| 1962 \ |
| 1963 AssembledTest test = assemble(); \ |
| 1964 \ |
| 1965 test.set##MemorySize##To(T0, V0); \ |
| 1966 test.run(); \ |
| 1967 \ |
| 1968 ASSERT_FLOAT_EQ(static_cast<FpType>(V0), \ |
| 1969 test.contentsOf##MemorySize<FpType>(T0)) \ |
| 1970 << "(" #OperandType ", " #Size ", " #MemorySize ", " #FpType \ |
| 1971 ", " #IntType ")"; \ |
| 1972 \ |
| 1973 reset(); \ |
| 1974 } while (0) |
| 1975 |
| 1976 TestFild(s, 32, Dword, float, uint32_t); |
| 1977 TestFild(l, 64, Qword, double, uint64_t); |
| 1978 #undef TestFild |
| 1979 } |
| 1980 |
| 1981 TEST_F(AssemblerX8632Test, Fistp) { |
| 1982 #define TestFistp(OperandType, Size, MemorySize, FpType, IntType) \ |
| 1983 do { \ |
| 1984 const uint32_t T0 = allocate##MemorySize(); \ |
| 1985 constexpr IntType V0 = 0x1234; \ |
| 1986 const uint32_t T1 = allocate##MemorySize(); \ |
| 1987 constexpr IntType V1 = 0xFFFF; \ |
| 1988 \ |
| 1989 __ fild##OperandType(dwordAddress(T0)); \ |
| 1990 __ fistp##OperandType(dwordAddress(T1)); \ |
| 1991 \ |
| 1992 AssembledTest test = assemble(); \ |
| 1993 \ |
| 1994 test.set##MemorySize##To(T0, V0); \ |
| 1995 test.set##MemorySize##To(T1, V1); \ |
| 1996 test.run(); \ |
| 1997 \ |
| 1998 ASSERT_EQ(static_cast<IntType>(V0), \ |
| 1999 test.contentsOf##MemorySize<IntType>(T0)) \ |
| 2000 << "(" #OperandType ", " #Size ", " #MemorySize ", " #FpType \ |
| 2001 ", " #IntType ")"; \ |
| 2002 ASSERT_EQ(static_cast<IntType>(V0), \ |
| 2003 test.contentsOf##MemorySize<IntType>(T1)) \ |
| 2004 << "(" #OperandType ", " #Size ", " #MemorySize ", " #FpType \ |
| 2005 ", " #IntType ")"; \ |
| 2006 \ |
| 2007 reset(); \ |
| 2008 } while (0) |
| 2009 |
| 2010 TestFistp(s, 32, Dword, float, uint32_t); |
| 2011 TestFistp(l, 64, Qword, double, uint64_t); |
| 2012 #undef TestFistp |
| 2013 } |
| 2014 |
| 2015 TEST_F(AssemblerX8632Test, PopAddr) { |
| 2016 const uint32_t T0 = allocateDword(); |
| 2017 constexpr uint32_t V0 = 0xEFAB; |
| 2018 |
| 2019 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0xC0FFEE)); |
| 2020 __ pushl(GPRRegister::Encoded_Reg_eax); |
| 2021 __ popl(dwordAddress(T0)); |
| 2022 |
| 2023 AssembledTest test = assemble(); |
| 2024 test.setDwordTo(T0, V0); |
| 2025 |
| 2026 test.run(); |
| 2027 |
| 2028 ASSERT_EQ(0xC0FFEEul, test.contentsOfDword(T0)); |
| 2029 } |
| 2030 |
| 2031 TEST_F(AssemblerX8632Test, SetCC) { |
| 2032 #define TestSetCC(C, Src0, Value0, Src1, Value1, Dest, IsTrue) \ |
| 2033 do { \ |
| 2034 const uint32_t T0 = allocateDword(); \ |
| 2035 constexpr uint32_t V0 = 0xF00F00; \ |
| 2036 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src0, Immediate(Value0)); \ |
| 2037 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src1, Immediate(Value1)); \ |
| 2038 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_##Src0, \ |
| 2039 GPRRegister::Encoded_Reg_##Src1); \ |
| 2040 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(0)); \ |
| 2041 __ setcc(Cond::Br_##C, \ |
| 2042 RegX8632::getEncodedByteReg(GPRRegister::Encoded_Reg_##Dest)); \ |
| 2043 __ setcc(Cond::Br_##C, dwordAddress(T0)); \ |
| 2044 \ |
| 2045 AssembledTest test = assemble(); \ |
| 2046 test.setDwordTo(T0, V0); \ |
| 2047 \ |
| 2048 test.run(); \ |
| 2049 \ |
| 2050 EXPECT_EQ(IsTrue, test.Dest()) \ |
| 2051 << "(" #C ", " #Src0 ", " #Value0 ", " #Src1 ", " #Value1 ", " #Dest \ |
| 2052 ", " #IsTrue ")"; \ |
| 2053 EXPECT_EQ((0xF00F00 | IsTrue), test.contentsOfDword(T0)) \ |
| 2054 << "(" #C ", " #Src0 ", " #Value0 ", " #Src1 ", " #Value1 ", " #Dest \ |
| 2055 ", " #IsTrue ")"; \ |
| 2056 \ |
| 2057 reset(); \ |
| 2058 } while (0) |
| 2059 |
| 2060 TestSetCC(o, eax, 0x80000000u, ebx, 0x1u, ecx, 1u); |
| 2061 TestSetCC(o, eax, 0x1u, ebx, 0x10000000u, ecx, 0u); |
| 2062 |
| 2063 TestSetCC(no, ebx, 0x1u, ecx, 0x10000000u, edx, 1u); |
| 2064 TestSetCC(no, ebx, 0x80000000u, ecx, 0x1u, edx, 0u); |
| 2065 |
| 2066 TestSetCC(b, ecx, 0x1, edx, 0x80000000u, eax, 1u); |
| 2067 TestSetCC(b, ecx, 0x80000000u, edx, 0x1u, eax, 0u); |
| 2068 |
| 2069 TestSetCC(ae, edx, 0x80000000u, edi, 0x1u, ebx, 1u); |
| 2070 TestSetCC(ae, edx, 0x1u, edi, 0x80000000u, ebx, 0u); |
| 2071 |
| 2072 TestSetCC(e, edi, 0x1u, esi, 0x1u, ecx, 1u); |
| 2073 TestSetCC(e, edi, 0x1u, esi, 0x11111u, ecx, 0u); |
| 2074 |
| 2075 TestSetCC(ne, esi, 0x80000000u, eax, 0x1u, edx, 1u); |
| 2076 TestSetCC(ne, esi, 0x1u, eax, 0x1u, edx, 0u); |
| 2077 |
| 2078 TestSetCC(be, eax, 0x1u, ebx, 0x80000000u, eax, 1u); |
| 2079 TestSetCC(be, eax, 0x80000000u, ebx, 0x1u, eax, 0u); |
| 2080 |
| 2081 TestSetCC(a, ebx, 0x80000000u, ecx, 0x1u, ebx, 1u); |
| 2082 TestSetCC(a, ebx, 0x1u, ecx, 0x80000000u, ebx, 0u); |
| 2083 |
| 2084 TestSetCC(s, ecx, 0x1u, edx, 0x80000000u, ecx, 1u); |
| 2085 TestSetCC(s, ecx, 0x80000000u, edx, 0x1u, ecx, 0u); |
| 2086 |
| 2087 TestSetCC(ns, edx, 0x80000000u, edi, 0x1u, ecx, 1u); |
| 2088 TestSetCC(ns, edx, 0x1u, edi, 0x80000000u, ecx, 0u); |
| 2089 |
| 2090 TestSetCC(p, edi, 0x80000000u, esi, 0x1u, edx, 1u); |
| 2091 TestSetCC(p, edi, 0x1u, esi, 0x80000000u, edx, 0u); |
| 2092 |
| 2093 TestSetCC(np, esi, 0x1u, edi, 0x80000000u, eax, 1u); |
| 2094 TestSetCC(np, esi, 0x80000000u, edi, 0x1u, eax, 0u); |
| 2095 |
| 2096 TestSetCC(l, edi, 0x80000000u, eax, 0x1u, ebx, 1u); |
| 2097 TestSetCC(l, edi, 0x1u, eax, 0x80000000u, ebx, 0u); |
| 2098 |
| 2099 TestSetCC(ge, eax, 0x1u, ebx, 0x80000000u, ecx, 1u); |
| 2100 TestSetCC(ge, eax, 0x80000000u, ebx, 0x1u, ecx, 0u); |
| 2101 |
| 2102 TestSetCC(le, ebx, 0x80000000u, ecx, 0x1u, edx, 1u); |
| 2103 TestSetCC(le, ebx, 0x1u, ecx, 0x80000000u, edx, 0u); |
| 2104 |
| 2105 #undef TestSetCC |
| 2106 } |
| 2107 |
| 2108 TEST_F(AssemblerX8632Test, CallImm) { |
| 2109 __ call(Immediate(16)); |
| 2110 __ hlt(); |
| 2111 __ hlt(); |
| 2112 __ hlt(); |
| 2113 __ hlt(); |
| 2114 __ hlt(); |
| 2115 __ hlt(); |
| 2116 __ hlt(); |
| 2117 __ hlt(); |
| 2118 __ hlt(); |
| 2119 __ hlt(); |
| 2120 __ hlt(); |
| 2121 __ hlt(); |
| 2122 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0xf00f)); |
| 2123 __ popl(GPRRegister::Encoded_Reg_ebx); |
| 2124 |
| 2125 AssembledTest test = assemble(); |
| 2126 |
| 2127 test.run(); |
| 2128 |
| 2129 EXPECT_EQ(0xF00Fu, test.eax()); |
| 2130 } |
| 2131 |
| 2132 TEST_F(AssemblerX8632Test, CallReg) { |
| 2133 __ call(Immediate(16)); |
| 2134 __ popl(GPRRegister::Encoded_Reg_edx); |
| 2135 __ pushl(GPRRegister::Encoded_Reg_edx); |
| 2136 __ ret(); |
| 2137 __ hlt(); |
| 2138 __ hlt(); |
| 2139 __ hlt(); |
| 2140 __ hlt(); |
| 2141 __ hlt(); |
| 2142 __ hlt(); |
| 2143 __ hlt(); |
| 2144 __ hlt(); |
| 2145 __ hlt(); |
| 2146 __ popl(GPRRegister::Encoded_Reg_ebx); |
| 2147 __ call(GPRRegister::Encoded_Reg_ebx); |
| 2148 |
| 2149 AssembledTest test = assemble(); |
| 2150 |
| 2151 test.run(); |
| 2152 |
| 2153 EXPECT_EQ(15u, test.edx() - test.ebx()); |
| 2154 } |
| 2155 |
| 2156 TEST_F(AssemblerX8632Test, CallAddr) { |
| 2157 __ call(Immediate(16)); |
| 2158 __ mov(IceType_i8, GPRRegister::Encoded_Reg_eax, Immediate(0xf4)); |
| 2159 __ ret(); |
| 2160 __ hlt(); |
| 2161 __ hlt(); |
| 2162 __ hlt(); |
| 2163 __ hlt(); |
| 2164 __ hlt(); |
| 2165 __ hlt(); |
| 2166 __ hlt(); |
| 2167 __ hlt(); |
| 2168 __ hlt(); |
| 2169 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0xf1f2f300)); |
| 2170 __ call(Address(GPRRegister::Encoded_Reg_esp, 0)); |
| 2171 __ popl(GPRRegister::Encoded_Reg_edx); |
| 2172 |
| 2173 AssembledTest test = assemble(); |
| 2174 |
| 2175 test.run(); |
| 2176 |
| 2177 EXPECT_EQ(0xf1f2f3f4, test.eax()); |
| 2178 } |
| 2179 |
| 2180 TEST_F(AssemblerX8632Test, Movzx) { |
| 2181 #define TestMovzx8bitWithRegDest(Src, Dst, Imm) \ |
| 2182 do { \ |
| 2183 static_assert(((Imm)&0xFF) == (Imm), #Imm " is not an 8bit immediate"); \ |
| 2184 __ mov(IceType_i8, GPRRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 2185 __ movzx(IceType_i8, GPRRegister::Encoded_Reg_##Dst, \ |
| 2186 GPRRegister::Encoded_Reg_##Src); \ |
| 2187 AssembledTest test = assemble(); \ |
| 2188 test.run(); \ |
| 2189 ASSERT_EQ(Imm, test.Dst()) << "(" #Src ", " #Dst ", " #Imm ")"; \ |
| 2190 reset(); \ |
| 2191 } while (0) |
| 2192 |
| 2193 #define TestMovzx16bitWithRegDest(Src, Dst, Imm) \ |
| 2194 do { \ |
| 2195 static_assert(((Imm)&0xFFFF) == (Imm), #Imm " is not a 16bit immediate"); \ |
| 2196 __ mov(IceType_i16, GPRRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 2197 __ movzx(IceType_i16, GPRRegister::Encoded_Reg_##Dst, \ |
| 2198 GPRRegister::Encoded_Reg_##Src); \ |
| 2199 AssembledTest test = assemble(); \ |
| 2200 test.run(); \ |
| 2201 ASSERT_EQ(Imm, test.Dst()) << "(" #Src ", " #Dst ", " #Imm ")"; \ |
| 2202 reset(); \ |
| 2203 } while (0) |
| 2204 |
| 2205 #define TestMovzx8bitWithAddrSrc(Dst, Imm) \ |
| 2206 do { \ |
| 2207 static_assert(((Imm)&0xFF) == (Imm), #Imm " is not an 8bit immediate"); \ |
| 2208 const uint32_t T0 = allocateDword(); \ |
| 2209 const uint32_t V0 = Imm; \ |
| 2210 __ movzx(IceType_i8, GPRRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2211 AssembledTest test = assemble(); \ |
| 2212 test.setDwordTo(T0, V0); \ |
| 2213 test.run(); \ |
| 2214 ASSERT_EQ(Imm, test.Dst()) << "(Addr, " #Dst ", " #Imm ")"; \ |
| 2215 reset(); \ |
| 2216 } while (0) |
| 2217 |
| 2218 #define TestMovzx16bitWithAddrSrc(Dst, Imm) \ |
| 2219 do { \ |
| 2220 static_assert(((Imm)&0xFFFF) == (Imm), #Imm " is not a 16bit immediate"); \ |
| 2221 const uint32_t T0 = allocateDword(); \ |
| 2222 const uint32_t V0 = Imm; \ |
| 2223 __ movzx(IceType_i16, GPRRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2224 AssembledTest test = assemble(); \ |
| 2225 test.setDwordTo(T0, V0); \ |
| 2226 test.run(); \ |
| 2227 ASSERT_EQ(Imm, test.Dst()) << "(Addr, " #Dst ", " #Imm ")"; \ |
| 2228 reset(); \ |
| 2229 } while (0) |
| 2230 |
| 2231 #define TestMovzx(Dst) \ |
| 2232 do { \ |
| 2233 TestMovzx8bitWithRegDest(eax, Dst, 0x81u); \ |
| 2234 TestMovzx8bitWithRegDest(ebx, Dst, 0x82u); \ |
| 2235 TestMovzx8bitWithRegDest(ecx, Dst, 0x83u); \ |
| 2236 TestMovzx8bitWithRegDest(edx, Dst, 0x84u); \ |
| 2237 /* esi is encoded as dh */ \ |
| 2238 TestMovzx8bitWithRegDest(esi, Dst, 0x85u); \ |
| 2239 /* edi is encoded as bh */ \ |
| 2240 TestMovzx8bitWithRegDest(edi, Dst, 0x86u); \ |
| 2241 /* ebp is encoded as ch */ \ |
| 2242 TestMovzx8bitWithRegDest(ebp, Dst, 0x87u); \ |
| 2243 /* esp is encoded as ah */ \ |
| 2244 TestMovzx8bitWithRegDest(esp, Dst, 0x88u); \ |
| 2245 TestMovzx8bitWithAddrSrc(Dst, 0x8Fu); \ |
| 2246 \ |
| 2247 TestMovzx16bitWithRegDest(eax, Dst, 0x8118u); \ |
| 2248 TestMovzx16bitWithRegDest(ebx, Dst, 0x8228u); \ |
| 2249 TestMovzx16bitWithRegDest(ecx, Dst, 0x8338u); \ |
| 2250 TestMovzx16bitWithRegDest(edx, Dst, 0x8448u); \ |
| 2251 TestMovzx16bitWithAddrSrc(Dst, 0x8FF8u); \ |
| 2252 } while (0) |
| 2253 |
| 2254 TestMovzx(eax); |
| 2255 TestMovzx(ebx); |
| 2256 TestMovzx(ecx); |
| 2257 TestMovzx(edx); |
| 2258 TestMovzx(esi); |
| 2259 TestMovzx(edi); |
| 2260 |
| 2261 #undef TestMovzx |
| 2262 #undef TestMovzx16bitWithAddrDest |
| 2263 #undef TestMovzx8bitWithAddrDest |
| 2264 #undef TestMovzx16bitWithRegDest |
| 2265 #undef TestMovzx8bitWithRegDest |
| 2266 } |
| 2267 |
| 2268 TEST_F(AssemblerX8632Test, Movsx) { |
| 2269 #define TestMovsx8bitWithRegDest(Src, Dst, Imm) \ |
| 2270 do { \ |
| 2271 static_assert(((Imm)&0xFF) == (Imm), #Imm " is not an 8bit immediate"); \ |
| 2272 __ mov(IceType_i8, GPRRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 2273 __ movsx(IceType_i8, GPRRegister::Encoded_Reg_##Dst, \ |
| 2274 GPRRegister::Encoded_Reg_##Src); \ |
| 2275 AssembledTest test = assemble(); \ |
| 2276 test.run(); \ |
| 2277 ASSERT_EQ((0xFFFFFF00 | (Imm)), test.Dst()) \ |
| 2278 << "(" #Src ", " #Dst ", " #Imm ")"; \ |
| 2279 reset(); \ |
| 2280 } while (0) |
| 2281 |
| 2282 #define TestMovsx16bitWithRegDest(Src, Dst, Imm) \ |
| 2283 do { \ |
| 2284 static_assert(((Imm)&0xFFFF) == (Imm), #Imm " is not a 16bit immediate"); \ |
| 2285 __ mov(IceType_i16, GPRRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 2286 __ movsx(IceType_i16, GPRRegister::Encoded_Reg_##Dst, \ |
| 2287 GPRRegister::Encoded_Reg_##Src); \ |
| 2288 AssembledTest test = assemble(); \ |
| 2289 test.run(); \ |
| 2290 ASSERT_EQ((0xFFFF0000 | (Imm)), test.Dst()) \ |
| 2291 << "(" #Src ", " #Dst ", " #Imm ")"; \ |
| 2292 reset(); \ |
| 2293 } while (0) |
| 2294 |
| 2295 #define TestMovsx8bitWithAddrSrc(Dst, Imm) \ |
| 2296 do { \ |
| 2297 static_assert(((Imm)&0xFF) == (Imm), #Imm " is not an 8bit immediate"); \ |
| 2298 const uint32_t T0 = allocateDword(); \ |
| 2299 const uint32_t V0 = Imm; \ |
| 2300 __ movsx(IceType_i8, GPRRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2301 AssembledTest test = assemble(); \ |
| 2302 test.setDwordTo(T0, V0); \ |
| 2303 test.run(); \ |
| 2304 ASSERT_EQ((0xFFFFFF00 | (Imm)), test.Dst()) \ |
| 2305 << "(Addr, " #Dst ", " #Imm ")"; \ |
| 2306 reset(); \ |
| 2307 } while (0) |
| 2308 |
| 2309 #define TestMovsx16bitWithAddrSrc(Dst, Imm) \ |
| 2310 do { \ |
| 2311 static_assert(((Imm)&0xFFFF) == (Imm), #Imm " is not a 16bit immediate"); \ |
| 2312 const uint32_t T0 = allocateDword(); \ |
| 2313 const uint32_t V0 = Imm; \ |
| 2314 __ movsx(IceType_i16, GPRRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2315 AssembledTest test = assemble(); \ |
| 2316 test.setDwordTo(T0, V0); \ |
| 2317 test.run(); \ |
| 2318 ASSERT_EQ((0xFFFF0000 | (Imm)), test.Dst()) \ |
| 2319 << "(Addr, " #Dst ", " #Imm ")"; \ |
| 2320 reset(); \ |
| 2321 } while (0) |
| 2322 |
| 2323 #define TestMovsx(Dst) \ |
| 2324 do { \ |
| 2325 TestMovsx8bitWithRegDest(eax, Dst, 0x81u); \ |
| 2326 TestMovsx8bitWithRegDest(ebx, Dst, 0x82u); \ |
| 2327 TestMovsx8bitWithRegDest(ecx, Dst, 0x83u); \ |
| 2328 TestMovsx8bitWithRegDest(edx, Dst, 0x84u); \ |
| 2329 /* esi is encoded as dh */ \ |
| 2330 TestMovsx8bitWithRegDest(esi, Dst, 0x85u); \ |
| 2331 /* edi is encoded as bh */ \ |
| 2332 TestMovsx8bitWithRegDest(edi, Dst, 0x86u); \ |
| 2333 /* ebp is encoded as ch */ \ |
| 2334 TestMovsx8bitWithRegDest(ebp, Dst, 0x87u); \ |
| 2335 /* esp is encoded as ah */ \ |
| 2336 TestMovsx8bitWithRegDest(esp, Dst, 0x88u); \ |
| 2337 TestMovsx8bitWithAddrSrc(Dst, 0x8Fu); \ |
| 2338 \ |
| 2339 TestMovsx16bitWithRegDest(eax, Dst, 0x8118u); \ |
| 2340 TestMovsx16bitWithRegDest(ebx, Dst, 0x8228u); \ |
| 2341 TestMovsx16bitWithRegDest(ecx, Dst, 0x8338u); \ |
| 2342 TestMovsx16bitWithRegDest(edx, Dst, 0x8448u); \ |
| 2343 TestMovsx16bitWithAddrSrc(Dst, 0x8FF8u); \ |
| 2344 } while (0) |
| 2345 |
| 2346 TestMovsx(eax); |
| 2347 TestMovsx(ebx); |
| 2348 TestMovsx(ecx); |
| 2349 TestMovsx(edx); |
| 2350 TestMovsx(esi); |
| 2351 TestMovsx(edi); |
| 2352 |
| 2353 #undef TestMovsx |
| 2354 #undef TestMovsx16bitWithAddrDest |
| 2355 #undef TestMovsx8bitWithAddrDest |
| 2356 #undef TestMovsx16bitWithRegDest |
| 2357 #undef TestMovsx8bitWithRegDest |
| 2358 } |
| 2359 |
| 2360 TEST_F(AssemblerX8632Test, Lea) { |
| 2361 #define TestLeaBaseDisp(Base, BaseValue, Disp, Dst) \ |
| 2362 do { \ |
| 2363 static constexpr char TestString[] = \ |
| 2364 "(" #Base ", " #BaseValue ", " #Dst ")"; \ |
| 2365 if (GPRRegister::Encoded_Reg_##Base != GPRRegister::Encoded_Reg_esp && \ |
| 2366 GPRRegister::Encoded_Reg_##Base != GPRRegister::Encoded_Reg_ebp) { \ |
| 2367 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Base, \ |
| 2368 Immediate(BaseValue)); \ |
| 2369 } \ |
| 2370 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 2371 Address(GPRRegister::Encoded_Reg_##Base, Disp)); \ |
| 2372 AssembledTest test = assemble(); \ |
| 2373 test.run(); \ |
| 2374 ASSERT_EQ(test.Base() + (Disp), test.Dst()) << TestString << " with Disp " \ |
| 2375 << Disp; \ |
| 2376 reset(); \ |
| 2377 } while (0) |
| 2378 |
| 2379 #define TestLeaIndex32bitDisp(Index, IndexValue, Disp, Dst0, Dst1, Dst2, Dst3) \ |
| 2380 do { \ |
| 2381 static constexpr char TestString[] = \ |
| 2382 "(" #Index ", " #IndexValue ", " #Dst0 ", " #Dst1 ", " #Dst2 \ |
| 2383 ", " #Dst3 ")"; \ |
| 2384 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Index, \ |
| 2385 Immediate(IndexValue)); \ |
| 2386 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst0, \ |
| 2387 Address(GPRRegister::Encoded_Reg_##Index, Traits::TIMES_1, Disp)); \ |
| 2388 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ |
| 2389 Address(GPRRegister::Encoded_Reg_##Index, Traits::TIMES_2, Disp)); \ |
| 2390 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst2, \ |
| 2391 Address(GPRRegister::Encoded_Reg_##Index, Traits::TIMES_4, Disp)); \ |
| 2392 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst3, \ |
| 2393 Address(GPRRegister::Encoded_Reg_##Index, Traits::TIMES_8, Disp)); \ |
| 2394 AssembledTest test = assemble(); \ |
| 2395 test.run(); \ |
| 2396 ASSERT_EQ((test.Index() << Traits::TIMES_1) + (Disp), test.Dst0()) \ |
| 2397 << TestString << " " << Disp; \ |
| 2398 ASSERT_EQ((test.Index() << Traits::TIMES_2) + (Disp), test.Dst1()) \ |
| 2399 << TestString << " " << Disp; \ |
| 2400 ASSERT_EQ((test.Index() << Traits::TIMES_4) + (Disp), test.Dst2()) \ |
| 2401 << TestString << " " << Disp; \ |
| 2402 ASSERT_EQ((test.Index() << Traits::TIMES_8) + (Disp), test.Dst3()) \ |
| 2403 << TestString << " " << Disp; \ |
| 2404 reset(); \ |
| 2405 } while (0) |
| 2406 |
| 2407 #define TestLeaBaseIndexDisp(Base, BaseValue, Index, IndexValue, Disp, Dst0, \ |
| 2408 Dst1, Dst2, Dst3) \ |
| 2409 do { \ |
| 2410 static constexpr char TestString[] = \ |
| 2411 "(" #Base ", " #BaseValue ", " #Index ", " #IndexValue ", " #Dst0 \ |
| 2412 ", " #Dst1 ", " #Dst2 ", " #Dst3 ")"; \ |
| 2413 if (GPRRegister::Encoded_Reg_##Base != GPRRegister::Encoded_Reg_esp && \ |
| 2414 GPRRegister::Encoded_Reg_##Base != GPRRegister::Encoded_Reg_ebp) { \ |
| 2415 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Base, \ |
| 2416 Immediate(BaseValue)); \ |
| 2417 } \ |
| 2418 /* esp is not a valid index register. */ \ |
| 2419 if (GPRRegister::Encoded_Reg_##Index != GPRRegister::Encoded_Reg_ebp) { \ |
| 2420 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Index, \ |
| 2421 Immediate(IndexValue)); \ |
| 2422 } \ |
| 2423 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst0, \ |
| 2424 Address(GPRRegister::Encoded_Reg_##Base, \ |
| 2425 GPRRegister::Encoded_Reg_##Index, Traits::TIMES_1, Disp)); \ |
| 2426 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ |
| 2427 Address(GPRRegister::Encoded_Reg_##Base, \ |
| 2428 GPRRegister::Encoded_Reg_##Index, Traits::TIMES_2, Disp)); \ |
| 2429 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst2, \ |
| 2430 Address(GPRRegister::Encoded_Reg_##Base, \ |
| 2431 GPRRegister::Encoded_Reg_##Index, Traits::TIMES_4, Disp)); \ |
| 2432 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst3, \ |
| 2433 Address(GPRRegister::Encoded_Reg_##Base, \ |
| 2434 GPRRegister::Encoded_Reg_##Index, Traits::TIMES_8, Disp)); \ |
| 2435 AssembledTest test = assemble(); \ |
| 2436 test.run(); \ |
| 2437 uint32_t ExpectedIndexValue = test.Index(); \ |
| 2438 if (GPRRegister::Encoded_Reg_##Index == GPRRegister::Encoded_Reg_esp) { \ |
| 2439 ExpectedIndexValue = 0; \ |
| 2440 } \ |
| 2441 ASSERT_EQ(test.Base() + (ExpectedIndexValue << Traits::TIMES_1) + (Disp), \ |
| 2442 test.Dst0()) \ |
| 2443 << TestString << " " << Disp; \ |
| 2444 ASSERT_EQ(test.Base() + (ExpectedIndexValue << Traits::TIMES_2) + (Disp), \ |
| 2445 test.Dst1()) \ |
| 2446 << TestString << " " << Disp; \ |
| 2447 ASSERT_EQ(test.Base() + (ExpectedIndexValue << Traits::TIMES_4) + (Disp), \ |
| 2448 test.Dst2()) \ |
| 2449 << TestString << " " << Disp; \ |
| 2450 ASSERT_EQ(test.Base() + (ExpectedIndexValue << Traits::TIMES_8) + (Disp), \ |
| 2451 test.Dst3()) \ |
| 2452 << TestString << " " << Disp; \ |
| 2453 reset(); \ |
| 2454 } while (0) |
| 2455 |
| 2456 for (const int32_t Disp : |
| 2457 {0x00, 0x06, -0x06, 0x0600, -0x6000, 0x6000000, -0x6000000}) { |
| 2458 TestLeaBaseDisp(eax, 0x10000Fu, Disp, ebx); |
| 2459 TestLeaBaseDisp(ebx, 0x20000Fu, Disp, ecx); |
| 2460 TestLeaBaseDisp(ecx, 0x30000Fu, Disp, edx); |
| 2461 TestLeaBaseDisp(edx, 0x40000Fu, Disp, esi); |
| 2462 TestLeaBaseDisp(esi, 0x50000Fu, Disp, edi); |
| 2463 TestLeaBaseDisp(edi, 0x60000Fu, Disp, eax); |
| 2464 TestLeaBaseDisp(esp, 0x11000Fu, Disp, eax); |
| 2465 TestLeaBaseDisp(ebp, 0x22000Fu, Disp, ecx); |
| 2466 } |
| 2467 |
| 2468 // esp is not a valid index register. |
| 2469 // ebp is not valid in this addressing mode (rm = 0). |
| 2470 for (const int32_t Disp : |
| 2471 {0x00, 0x06, -0x06, 0x0600, -0x6000, 0x6000000, -0x6000000}) { |
| 2472 TestLeaIndex32bitDisp(eax, 0x2000u, Disp, ebx, ecx, edx, esi); |
| 2473 TestLeaIndex32bitDisp(ebx, 0x4000u, Disp, ecx, edx, esi, edi); |
| 2474 TestLeaIndex32bitDisp(ecx, 0x6000u, Disp, edx, esi, edi, eax); |
| 2475 TestLeaIndex32bitDisp(edx, 0x8000u, Disp, esi, edi, eax, ebx); |
| 2476 TestLeaIndex32bitDisp(esi, 0xA000u, Disp, edi, eax, ebx, ecx); |
| 2477 TestLeaIndex32bitDisp(edi, 0xC000u, Disp, eax, ebx, ecx, edx); |
| 2478 } |
| 2479 |
| 2480 for (const int32_t Disp : |
| 2481 {0x00, 0x06, -0x06, 0x0600, -0x6000, 0x6000000, -0x6000000}) { |
| 2482 TestLeaBaseIndexDisp(eax, 0x100000u, ebx, 0x600u, Disp, ecx, edx, esi, edi); |
| 2483 TestLeaBaseIndexDisp(ebx, 0x200000u, ecx, 0x500u, Disp, edx, esi, edi, eax); |
| 2484 TestLeaBaseIndexDisp(ecx, 0x300000u, edx, 0x400u, Disp, esi, edi, eax, ebx); |
| 2485 TestLeaBaseIndexDisp(edx, 0x400000u, esi, 0x300u, Disp, edi, eax, ebx, ecx); |
| 2486 TestLeaBaseIndexDisp(esi, 0x500000u, edi, 0x200u, Disp, eax, ebx, ecx, edx); |
| 2487 TestLeaBaseIndexDisp(edi, 0x600000u, eax, 0x100u, Disp, ebx, ecx, edx, esi); |
| 2488 |
| 2489 /* Initializers are ignored when Src[01] is ebp/esp. */ |
| 2490 TestLeaBaseIndexDisp(esp, 0, ebx, 0x6000u, Disp, ecx, edx, esi, edi); |
| 2491 TestLeaBaseIndexDisp(esp, 0, ecx, 0x5000u, Disp, edx, esi, edi, eax); |
| 2492 TestLeaBaseIndexDisp(esp, 0, edx, 0x4000u, Disp, esi, edi, eax, ebx); |
| 2493 TestLeaBaseIndexDisp(esp, 0, esi, 0x3000u, Disp, edi, eax, ebx, ecx); |
| 2494 TestLeaBaseIndexDisp(esp, 0, edi, 0x2000u, Disp, eax, ebx, ecx, edx); |
| 2495 TestLeaBaseIndexDisp(esp, 0, eax, 0x1000u, Disp, ebx, ecx, edx, esi); |
| 2496 |
| 2497 TestLeaBaseIndexDisp(ebp, 0, ebx, 0x6000u, Disp, ecx, edx, esi, edi); |
| 2498 TestLeaBaseIndexDisp(ebp, 0, ecx, 0x5000u, Disp, edx, esi, edi, eax); |
| 2499 TestLeaBaseIndexDisp(ebp, 0, edx, 0x4000u, Disp, esi, edi, eax, ebx); |
| 2500 TestLeaBaseIndexDisp(ebp, 0, esi, 0x3000u, Disp, edi, eax, ebx, ecx); |
| 2501 TestLeaBaseIndexDisp(ebp, 0, edi, 0x2000u, Disp, eax, ebx, ecx, edx); |
| 2502 TestLeaBaseIndexDisp(ebp, 0, eax, 0x1000u, Disp, ebx, ecx, edx, esi); |
| 2503 |
| 2504 TestLeaBaseIndexDisp(eax, 0x1000000u, ebp, 0, Disp, ecx, edx, esi, edi); |
| 2505 TestLeaBaseIndexDisp(ebx, 0x2000000u, ebp, 0, Disp, edx, esi, edi, eax); |
| 2506 TestLeaBaseIndexDisp(ecx, 0x3000000u, ebp, 0, Disp, esi, edi, eax, ebx); |
| 2507 TestLeaBaseIndexDisp(edx, 0x4000000u, ebp, 0, Disp, edi, eax, ebx, ecx); |
| 2508 TestLeaBaseIndexDisp(esi, 0x5000000u, ebp, 0, Disp, eax, ebx, ecx, edx); |
| 2509 TestLeaBaseIndexDisp(edi, 0x6000000u, ebp, 0, Disp, ebx, ecx, edx, esi); |
| 2510 |
| 2511 TestLeaBaseIndexDisp(esp, 0, ebp, 0, Disp, ebx, ecx, edx, esi); |
| 2512 } |
| 2513 |
| 2514 // Absolute addressing mode is tested in the Low Level tests. The encoding used |
| 2515 // by the assembler has different meanings in x86-32 and x86-64. |
| 2516 #undef TestLeaBaseIndexDisp |
| 2517 #undef TestLeaScaled32bitDisp |
| 2518 #undef TestLeaBaseDisp |
| 2519 } |
| 2520 |
| 2521 TEST_F(AssemblerX8632LowLevelTest, LeaAbsolute) { |
| 2522 #define TestLeaAbsolute(Dst, Value) \ |
| 2523 do { \ |
| 2524 static constexpr char TestString[] = "(" #Dst ", " #Value ")"; \ |
| 2525 __ lea(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 2526 Address(Address::ABSOLUTE, Value)); \ |
| 2527 static constexpr uint32_t ByteCount = 6; \ |
| 2528 ASSERT_EQ(ByteCount, codeBytesSize()) << TestString; \ |
| 2529 static constexpr uint8_t Opcode = 0x8D; \ |
| 2530 static constexpr uint8_t ModRM = \ |
| 2531 /*mod=*/0x00 | /*reg*/ (GPRRegister::Encoded_Reg_##Dst << 3) | \ |
| 2532 /*rm*/ GPRRegister::Encoded_Reg_ebp; \ |
| 2533 verifyBytes<ByteCount>(codeBytes(), Opcode, ModRM, (Value)&0xFF, \ |
| 2534 (Value >> 8) & 0xFF, (Value >> 16) & 0xFF, \ |
| 2535 (Value >> 24) & 0xFF); \ |
| 2536 reset(); \ |
| 2537 } while (0) |
| 2538 |
| 2539 TestLeaAbsolute(eax, 0x11BEEF22); |
| 2540 TestLeaAbsolute(ebx, 0x33BEEF44); |
| 2541 TestLeaAbsolute(ecx, 0x55BEEF66); |
| 2542 TestLeaAbsolute(edx, 0x77BEEF88); |
| 2543 TestLeaAbsolute(esi, 0x99BEEFAA); |
| 2544 TestLeaAbsolute(edi, 0xBBBEEFBB); |
| 2545 |
| 2546 #undef TesLeaAbsolute |
| 2547 } |
| 2548 |
| 2549 TEST_F(AssemblerX8632Test, CmovRegReg) { |
| 2550 #define TestCmovRegReg(C, Src0, Value0, Src1, Value1, Dest, IsTrue) \ |
| 2551 do { \ |
| 2552 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src0, Immediate(Value0)); \ |
| 2553 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src1, Immediate(Value1)); \ |
| 2554 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(Value0)); \ |
| 2555 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_##Src0, \ |
| 2556 GPRRegister::Encoded_Reg_##Src1); \ |
| 2557 __ cmov(IceType_i32, Cond::Br_##C, GPRRegister::Encoded_Reg_##Dest, \ |
| 2558 GPRRegister::Encoded_Reg_##Src1); \ |
| 2559 \ |
| 2560 AssembledTest test = assemble(); \ |
| 2561 test.run(); \ |
| 2562 ASSERT_EQ((IsTrue) ? (Value1) : (Value0), test.Dest()) \ |
| 2563 << "(" #C ", " #Src0 ", " #Value0 ", " #Src1 ", " #Value1 ", " #Dest \ |
| 2564 ", " #IsTrue ")"; \ |
| 2565 \ |
| 2566 reset(); \ |
| 2567 } while (0) |
| 2568 |
| 2569 TestCmovRegReg(o, eax, 0x80000000u, ebx, 0x1u, ecx, 1u); |
| 2570 TestCmovRegReg(o, eax, 0x1u, ebx, 0x10000000u, ecx, 0u); |
| 2571 |
| 2572 TestCmovRegReg(no, ebx, 0x1u, ecx, 0x10000000u, edx, 1u); |
| 2573 TestCmovRegReg(no, ebx, 0x80000000u, ecx, 0x1u, edx, 0u); |
| 2574 |
| 2575 TestCmovRegReg(b, ecx, 0x1, edx, 0x80000000u, eax, 1u); |
| 2576 TestCmovRegReg(b, ecx, 0x80000000u, edx, 0x1u, eax, 0u); |
| 2577 |
| 2578 TestCmovRegReg(ae, edx, 0x80000000u, edi, 0x1u, ebx, 1u); |
| 2579 TestCmovRegReg(ae, edx, 0x1u, edi, 0x80000000u, ebx, 0u); |
| 2580 |
| 2581 TestCmovRegReg(e, edi, 0x1u, esi, 0x1u, ecx, 1u); |
| 2582 TestCmovRegReg(e, edi, 0x1u, esi, 0x11111u, ecx, 0u); |
| 2583 |
| 2584 TestCmovRegReg(ne, esi, 0x80000000u, eax, 0x1u, edx, 1u); |
| 2585 TestCmovRegReg(ne, esi, 0x1u, eax, 0x1u, edx, 0u); |
| 2586 |
| 2587 TestCmovRegReg(be, eax, 0x1u, ebx, 0x80000000u, eax, 1u); |
| 2588 TestCmovRegReg(be, eax, 0x80000000u, ebx, 0x1u, eax, 0u); |
| 2589 |
| 2590 TestCmovRegReg(a, ebx, 0x80000000u, ecx, 0x1u, ebx, 1u); |
| 2591 TestCmovRegReg(a, ebx, 0x1u, ecx, 0x80000000u, ebx, 0u); |
| 2592 |
| 2593 TestCmovRegReg(s, ecx, 0x1u, edx, 0x80000000u, ecx, 1u); |
| 2594 TestCmovRegReg(s, ecx, 0x80000000u, edx, 0x1u, ecx, 0u); |
| 2595 |
| 2596 TestCmovRegReg(ns, edx, 0x80000000u, edi, 0x1u, ecx, 1u); |
| 2597 TestCmovRegReg(ns, edx, 0x1u, edi, 0x80000000u, ecx, 0u); |
| 2598 |
| 2599 TestCmovRegReg(p, edi, 0x80000000u, esi, 0x1u, edx, 1u); |
| 2600 TestCmovRegReg(p, edi, 0x1u, esi, 0x80000000u, edx, 0u); |
| 2601 |
| 2602 TestCmovRegReg(np, esi, 0x1u, edi, 0x80000000u, eax, 1u); |
| 2603 TestCmovRegReg(np, esi, 0x80000000u, edi, 0x1u, eax, 0u); |
| 2604 |
| 2605 TestCmovRegReg(l, edi, 0x80000000u, eax, 0x1u, ebx, 1u); |
| 2606 TestCmovRegReg(l, edi, 0x1u, eax, 0x80000000u, ebx, 0u); |
| 2607 |
| 2608 TestCmovRegReg(ge, eax, 0x1u, ebx, 0x80000000u, ecx, 1u); |
| 2609 TestCmovRegReg(ge, eax, 0x80000000u, ebx, 0x1u, ecx, 0u); |
| 2610 |
| 2611 TestCmovRegReg(le, ebx, 0x80000000u, ecx, 0x1u, edx, 1u); |
| 2612 TestCmovRegReg(le, ebx, 0x1u, ecx, 0x80000000u, edx, 0u); |
| 2613 |
| 2614 #undef TestCmovRegReg |
| 2615 } |
| 2616 |
| 2617 TEST_F(AssemblerX8632Test, CmovRegAddr) { |
| 2618 #define TestCmovRegAddr(C, Src0, Value0, Value1, Dest, IsTrue) \ |
| 2619 do { \ |
| 2620 const uint32_t T0 = allocateDword(); \ |
| 2621 const uint32_t V0 = Value1; \ |
| 2622 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src0, Immediate(Value0)); \ |
| 2623 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dest, Immediate(Value0)); \ |
| 2624 __ cmp(IceType_i32, GPRRegister::Encoded_Reg_##Src0, dwordAddress(T0)); \ |
| 2625 __ cmov(IceType_i32, Cond::Br_##C, GPRRegister::Encoded_Reg_##Dest, \ |
| 2626 dwordAddress(T0)); \ |
| 2627 \ |
| 2628 AssembledTest test = assemble(); \ |
| 2629 test.setDwordTo(T0, V0); \ |
| 2630 test.run(); \ |
| 2631 ASSERT_EQ((IsTrue) ? (Value1) : (Value0), test.Dest()) \ |
| 2632 << "(" #C ", " #Src0 ", " #Value0 ", " #Value1 ", " #Dest ", " #IsTrue \ |
| 2633 ")"; \ |
| 2634 \ |
| 2635 reset(); \ |
| 2636 } while (0) |
| 2637 |
| 2638 TestCmovRegAddr(o, eax, 0x80000000u, 0x1u, ecx, 1u); |
| 2639 TestCmovRegAddr(o, eax, 0x1u, 0x10000000u, ecx, 0u); |
| 2640 |
| 2641 TestCmovRegAddr(no, ebx, 0x1u, 0x10000000u, edx, 1u); |
| 2642 TestCmovRegAddr(no, ebx, 0x80000000u, 0x1u, edx, 0u); |
| 2643 |
| 2644 TestCmovRegAddr(b, ecx, 0x1, 0x80000000u, eax, 1u); |
| 2645 TestCmovRegAddr(b, ecx, 0x80000000u, 0x1u, eax, 0u); |
| 2646 |
| 2647 TestCmovRegAddr(ae, edx, 0x80000000u, 0x1u, ebx, 1u); |
| 2648 TestCmovRegAddr(ae, edx, 0x1u, 0x80000000u, ebx, 0u); |
| 2649 |
| 2650 TestCmovRegAddr(e, edi, 0x1u, 0x1u, ecx, 1u); |
| 2651 TestCmovRegAddr(e, edi, 0x1u, 0x11111u, ecx, 0u); |
| 2652 |
| 2653 TestCmovRegAddr(ne, esi, 0x80000000u, 0x1u, edx, 1u); |
| 2654 TestCmovRegAddr(ne, esi, 0x1u, 0x1u, edx, 0u); |
| 2655 |
| 2656 TestCmovRegAddr(be, eax, 0x1u, 0x80000000u, eax, 1u); |
| 2657 TestCmovRegAddr(be, eax, 0x80000000u, 0x1u, eax, 0u); |
| 2658 |
| 2659 TestCmovRegAddr(a, ebx, 0x80000000u, 0x1u, ebx, 1u); |
| 2660 TestCmovRegAddr(a, ebx, 0x1u, 0x80000000u, ebx, 0u); |
| 2661 |
| 2662 TestCmovRegAddr(s, ecx, 0x1u, 0x80000000u, ecx, 1u); |
| 2663 TestCmovRegAddr(s, ecx, 0x80000000u, 0x1u, ecx, 0u); |
| 2664 |
| 2665 TestCmovRegAddr(ns, edx, 0x80000000u, 0x1u, ecx, 1u); |
| 2666 TestCmovRegAddr(ns, edx, 0x1u, 0x80000000u, ecx, 0u); |
| 2667 |
| 2668 TestCmovRegAddr(p, edi, 0x80000000u, 0x1u, edx, 1u); |
| 2669 TestCmovRegAddr(p, edi, 0x1u, 0x80000000u, edx, 0u); |
| 2670 |
| 2671 TestCmovRegAddr(np, esi, 0x1u, 0x80000000u, eax, 1u); |
| 2672 TestCmovRegAddr(np, esi, 0x80000000u, 0x1u, eax, 0u); |
| 2673 |
| 2674 TestCmovRegAddr(l, edi, 0x80000000u, 0x1u, ebx, 1u); |
| 2675 TestCmovRegAddr(l, edi, 0x1u, 0x80000000u, ebx, 0u); |
| 2676 |
| 2677 TestCmovRegAddr(ge, eax, 0x1u, 0x80000000u, ecx, 1u); |
| 2678 TestCmovRegAddr(ge, eax, 0x80000000u, 0x1u, ecx, 0u); |
| 2679 |
| 2680 TestCmovRegAddr(le, ebx, 0x80000000u, 0x1u, edx, 1u); |
| 2681 TestCmovRegAddr(le, ebx, 0x1u, 0x80000000u, edx, 0u); |
| 2682 |
| 2683 #undef TestCmovRegAddr |
| 2684 } |
| 2685 |
| 2686 TEST_F(AssemblerX8632LowLevelTest, RepMovsb) { |
| 2687 __ rep_movsb(); |
| 2688 |
| 2689 static constexpr uint32_t ByteCount = 2; |
| 2690 static constexpr uint8_t Prefix = 0xF3; |
| 2691 static constexpr uint8_t Opcode = 0xA4; |
| 2692 |
| 2693 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 2694 verifyBytes<ByteCount>(codeBytes(), Prefix, Opcode); |
| 2695 } |
| 2696 |
| 2697 TEST_F(AssemblerX8632Test, MovssXmmAddr) { |
| 2698 #define TestMovssXmmAddrFloatLength(FloatLength, Xmm, Value) \ |
| 2699 do { \ |
| 2700 static_assert((FloatLength) == 32 || (FloatLength) == 64, \ |
| 2701 "Invalid fp length #FloatLength"); \ |
| 2702 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2703 \ |
| 2704 static constexpr char TestString[] = "(" #FloatLength ", " #Xmm ")"; \ |
| 2705 static constexpr bool IsDouble = std::is_same<Type, double>::value; \ |
| 2706 const uint32_t T0 = allocateQword(); \ |
| 2707 const Type V0 = Value; \ |
| 2708 \ |
| 2709 __ movss(IceType_f##FloatLength, XmmRegister::Encoded_Reg_##Xmm, \ |
| 2710 dwordAddress(T0)); \ |
| 2711 \ |
| 2712 AssembledTest test = assemble(); \ |
| 2713 if (IsDouble) { \ |
| 2714 test.setQwordTo(T0, static_cast<double>(V0)); \ |
| 2715 } else { \ |
| 2716 test.setDwordTo(T0, static_cast<float>(V0)); \ |
| 2717 } \ |
| 2718 test.run(); \ |
| 2719 ASSERT_DOUBLE_EQ(Value, test.Xmm<Type>()) << TestString << " value is " \ |
| 2720 << Value; \ |
| 2721 reset(); \ |
| 2722 } while (0) |
| 2723 |
| 2724 #define TestMovssXmmAddr(FloatLength) \ |
| 2725 do { \ |
| 2726 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2727 for (const Type Value : {0.0, -0.0, 1.0, -1.0, 3.14, 99999.9999}) { \ |
| 2728 TestMovssXmmAddrFloatLength(FloatLength, xmm0, Value); \ |
| 2729 TestMovssXmmAddrFloatLength(FloatLength, xmm1, Value); \ |
| 2730 TestMovssXmmAddrFloatLength(FloatLength, xmm2, Value); \ |
| 2731 TestMovssXmmAddrFloatLength(FloatLength, xmm3, Value); \ |
| 2732 TestMovssXmmAddrFloatLength(FloatLength, xmm4, Value); \ |
| 2733 TestMovssXmmAddrFloatLength(FloatLength, xmm5, Value); \ |
| 2734 TestMovssXmmAddrFloatLength(FloatLength, xmm6, Value); \ |
| 2735 TestMovssXmmAddrFloatLength(FloatLength, xmm7, Value); \ |
| 2736 } \ |
| 2737 } while (0) |
| 2738 |
| 2739 TestMovssXmmAddr(32); |
| 2740 TestMovssXmmAddr(64); |
| 2741 |
| 2742 #undef TestMovssXmmAddr |
| 2743 #undef TestMovssXmmAddrType |
| 2744 } |
| 2745 |
| 2746 TEST_F(AssemblerX8632Test, MovssAddrXmm) { |
| 2747 #define TestMovssAddrXmmFloatLength(FloatLength, Xmm, Value) \ |
| 2748 do { \ |
| 2749 static_assert((FloatLength) == 32 || (FloatLength) == 64, \ |
| 2750 "Invalid fp length #FloatLength"); \ |
| 2751 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2752 \ |
| 2753 static constexpr char TestString[] = "(" #FloatLength ", " #Xmm ")"; \ |
| 2754 static constexpr bool IsDouble = std::is_same<Type, double>::value; \ |
| 2755 const uint32_t T0 = allocateQword(); \ |
| 2756 const Type V0 = Value; \ |
| 2757 const uint32_t T1 = allocateQword(); \ |
| 2758 static_assert(std::numeric_limits<Type>::has_quiet_NaN, \ |
| 2759 "f" #FloatLength " does not have quiet nan."); \ |
| 2760 const Type V1 = std::numeric_limits<Type>::quiet_NaN(); \ |
| 2761 \ |
| 2762 __ movss(IceType_f##FloatLength, XmmRegister::Encoded_Reg_##Xmm, \ |
| 2763 dwordAddress(T0)); \ |
| 2764 \ |
| 2765 AssembledTest test = assemble(); \ |
| 2766 if (IsDouble) { \ |
| 2767 test.setQwordTo(T0, static_cast<double>(V0)); \ |
| 2768 test.setQwordTo(T1, static_cast<double>(V1)); \ |
| 2769 } else { \ |
| 2770 test.setDwordTo(T0, static_cast<float>(V0)); \ |
| 2771 test.setDwordTo(T1, static_cast<float>(V1)); \ |
| 2772 } \ |
| 2773 test.run(); \ |
| 2774 ASSERT_DOUBLE_EQ(Value, test.Xmm<Type>()) << TestString << " value is " \ |
| 2775 << Value; \ |
| 2776 reset(); \ |
| 2777 } while (0) |
| 2778 |
| 2779 #define TestMovssAddrXmm(FloatLength) \ |
| 2780 do { \ |
| 2781 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2782 for (const Type Value : {0.0, -0.0, 1.0, -1.0, 3.14, 99999.9999}) { \ |
| 2783 TestMovssAddrXmmFloatLength(FloatLength, xmm0, Value); \ |
| 2784 TestMovssAddrXmmFloatLength(FloatLength, xmm1, Value); \ |
| 2785 TestMovssAddrXmmFloatLength(FloatLength, xmm2, Value); \ |
| 2786 TestMovssAddrXmmFloatLength(FloatLength, xmm3, Value); \ |
| 2787 TestMovssAddrXmmFloatLength(FloatLength, xmm4, Value); \ |
| 2788 TestMovssAddrXmmFloatLength(FloatLength, xmm5, Value); \ |
| 2789 TestMovssAddrXmmFloatLength(FloatLength, xmm6, Value); \ |
| 2790 TestMovssAddrXmmFloatLength(FloatLength, xmm7, Value); \ |
| 2791 } \ |
| 2792 } while (0) |
| 2793 |
| 2794 TestMovssAddrXmm(32); |
| 2795 TestMovssAddrXmm(64); |
| 2796 |
| 2797 #undef TestMovssAddrXmm |
| 2798 #undef TestMovssAddrXmmType |
| 2799 } |
| 2800 |
| 2801 TEST_F(AssemblerX8632Test, MovssXmmXmm) { |
| 2802 #define TestMovssXmmXmmFloatLength(FloatLength, Src, Dst, Value) \ |
| 2803 do { \ |
| 2804 static_assert((FloatLength) == 32 || (FloatLength) == 64, \ |
| 2805 "Invalid fp length #FloatLength"); \ |
| 2806 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2807 \ |
| 2808 static constexpr char TestString[] = \ |
| 2809 "(" #FloatLength ", " #Src ", " #Dst ")"; \ |
| 2810 static constexpr bool IsDouble = std::is_same<Type, double>::value; \ |
| 2811 const uint32_t T0 = allocateQword(); \ |
| 2812 const Type V0 = Value; \ |
| 2813 const uint32_t T1 = allocateQword(); \ |
| 2814 static_assert(std::numeric_limits<Type>::has_quiet_NaN, \ |
| 2815 "f" #FloatLength " does not have quiet nan."); \ |
| 2816 const Type V1 = std::numeric_limits<Type>::quiet_NaN(); \ |
| 2817 \ |
| 2818 __ movss(IceType_f##FloatLength, XmmRegister::Encoded_Reg_##Src, \ |
| 2819 dwordAddress(T0)); \ |
| 2820 __ movss(IceType_f##FloatLength, XmmRegister::Encoded_Reg_##Dst, \ |
| 2821 dwordAddress(T1)); \ |
| 2822 __ movss(IceType_f##FloatLength, XmmRegister::Encoded_Reg_##Dst, \ |
| 2823 XmmRegister::Encoded_Reg_##Src); \ |
| 2824 \ |
| 2825 AssembledTest test = assemble(); \ |
| 2826 if (IsDouble) { \ |
| 2827 test.setQwordTo(T0, static_cast<double>(V0)); \ |
| 2828 test.setQwordTo(T1, static_cast<double>(V1)); \ |
| 2829 } else { \ |
| 2830 test.setDwordTo(T0, static_cast<float>(V0)); \ |
| 2831 test.setDwordTo(T1, static_cast<float>(V1)); \ |
| 2832 } \ |
| 2833 test.run(); \ |
| 2834 ASSERT_DOUBLE_EQ(Value, test.Dst<Type>()) << TestString << " value is " \ |
| 2835 << Value; \ |
| 2836 reset(); \ |
| 2837 } while (0) |
| 2838 |
| 2839 #define TestMovssXmmXmm(FloatLength) \ |
| 2840 do { \ |
| 2841 using Type = std::conditional<FloatLength == 32, float, double>::type; \ |
| 2842 for (const Type Value : {0.0, -0.0, 1.0, -1.0, 3.14, 99999.9999}) { \ |
| 2843 TestMovssXmmXmmFloatLength(FloatLength, xmm0, xmm1, Value); \ |
| 2844 TestMovssXmmXmmFloatLength(FloatLength, xmm1, xmm2, Value); \ |
| 2845 TestMovssXmmXmmFloatLength(FloatLength, xmm2, xmm3, Value); \ |
| 2846 TestMovssXmmXmmFloatLength(FloatLength, xmm3, xmm4, Value); \ |
| 2847 TestMovssXmmXmmFloatLength(FloatLength, xmm4, xmm5, Value); \ |
| 2848 TestMovssXmmXmmFloatLength(FloatLength, xmm5, xmm6, Value); \ |
| 2849 TestMovssXmmXmmFloatLength(FloatLength, xmm6, xmm7, Value); \ |
| 2850 TestMovssXmmXmmFloatLength(FloatLength, xmm7, xmm0, Value); \ |
| 2851 } \ |
| 2852 } while (0) |
| 2853 |
| 2854 TestMovssXmmXmm(32); |
| 2855 TestMovssXmmXmm(64); |
| 2856 |
| 2857 #undef TestMovssXmmXmm |
| 2858 #undef TestMovssXmmXmmType |
| 2859 } |
| 2860 |
| 2861 TEST_F(AssemblerX8632Test, MovdToXmm) { |
| 2862 #define TestMovdXmmReg(Src, Dst, Value) \ |
| 2863 do { \ |
| 2864 assert(((Value)&0xFFFFFFFF) == (Value)); \ |
| 2865 static constexpr char TestString[] = "(" #Src ", " #Dst ")"; \ |
| 2866 const uint32_t T0 = allocateQword(); \ |
| 2867 const uint64_t V0 = 0xFFFFFFFF00000000ull; \ |
| 2868 \ |
| 2869 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src, Immediate(Value)); \ |
| 2870 __ movss(IceType_f64, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2871 __ movd(XmmRegister::Encoded_Reg_##Dst, GPRRegister::Encoded_Reg_##Src); \ |
| 2872 \ |
| 2873 AssembledTest test = assemble(); \ |
| 2874 \ |
| 2875 test.setQwordTo(T0, V0); \ |
| 2876 test.run(); \ |
| 2877 \ |
| 2878 ASSERT_EQ(Value, test.Dst<uint64_t>()) << TestString << " value is " \ |
| 2879 << Value; \ |
| 2880 reset(); \ |
| 2881 } while (0) |
| 2882 |
| 2883 #define TestMovdXmmAddr(Dst, Value) \ |
| 2884 do { \ |
| 2885 assert(((Value)&0xFFFFFFFF) == (Value)); \ |
| 2886 static constexpr char TestString[] = "(" #Dst ", Addr)"; \ |
| 2887 const uint32_t T0 = allocateQword(); \ |
| 2888 const uint32_t V0 = Value; \ |
| 2889 const uint32_t T1 = allocateQword(); \ |
| 2890 const uint64_t V1 = 0xFFFFFFFF00000000ull; \ |
| 2891 \ |
| 2892 __ movss(IceType_f64, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 2893 __ movd(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 2894 \ |
| 2895 AssembledTest test = assemble(); \ |
| 2896 \ |
| 2897 test.setDwordTo(T0, V0); \ |
| 2898 test.setQwordTo(T1, V1); \ |
| 2899 test.run(); \ |
| 2900 \ |
| 2901 ASSERT_EQ(Value, test.Dst<uint64_t>()) << TestString << " value is " \ |
| 2902 << Value; \ |
| 2903 reset(); \ |
| 2904 } while (0) |
| 2905 |
| 2906 #define TestMovd(Dst) \ |
| 2907 do { \ |
| 2908 for (uint32_t Value : {0u, 1u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu}) { \ |
| 2909 TestMovdXmmReg(eax, Dst, Value); \ |
| 2910 TestMovdXmmReg(ebx, Dst, Value); \ |
| 2911 TestMovdXmmReg(ecx, Dst, Value); \ |
| 2912 TestMovdXmmReg(edx, Dst, Value); \ |
| 2913 TestMovdXmmReg(esi, Dst, Value); \ |
| 2914 TestMovdXmmReg(edi, Dst, Value); \ |
| 2915 TestMovdXmmAddr(Dst, Value); \ |
| 2916 } \ |
| 2917 } while (0) |
| 2918 |
| 2919 TestMovd(xmm0); |
| 2920 TestMovd(xmm1); |
| 2921 TestMovd(xmm2); |
| 2922 TestMovd(xmm3); |
| 2923 TestMovd(xmm4); |
| 2924 TestMovd(xmm5); |
| 2925 TestMovd(xmm6); |
| 2926 TestMovd(xmm7); |
| 2927 |
| 2928 #undef TestMovdXmmAddr |
| 2929 #undef TestMovdXmmReg |
| 2930 #undef TestMovd |
| 2931 } |
| 2932 |
| 2933 TEST_F(AssemblerX8632Test, MovdFromXmm) { |
| 2934 #define TestMovdRegXmm(Src, Dst, Value) \ |
| 2935 do { \ |
| 2936 assert(((Value)&0xFFFFFFFF) == (Value)); \ |
| 2937 static constexpr char TestString[] = "(" #Src ", " #Dst ")"; \ |
| 2938 const uint32_t T0 = allocateDword(); \ |
| 2939 const uint32_t V0 = Value; \ |
| 2940 \ |
| 2941 __ movss(IceType_f64, XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 2942 __ movd(GPRRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 2943 \ |
| 2944 AssembledTest test = assemble(); \ |
| 2945 \ |
| 2946 test.setDwordTo(T0, V0); \ |
| 2947 test.run(); \ |
| 2948 \ |
| 2949 ASSERT_EQ(Value, test.contentsOfDword(T0)) << TestString << " value is " \ |
| 2950 << Value; \ |
| 2951 reset(); \ |
| 2952 } while (0) |
| 2953 |
| 2954 #define TestMovdAddrXmm(Src, Value) \ |
| 2955 do { \ |
| 2956 assert(((Value)&0xFFFFFFFF) == (Value)); \ |
| 2957 static constexpr char TestString[] = "(" #Src ", Addr)"; \ |
| 2958 const uint32_t T0 = allocateDword(); \ |
| 2959 const uint32_t V0 = Value; \ |
| 2960 const uint32_t T1 = allocateDword(); \ |
| 2961 const uint32_t V1 = ~(Value); \ |
| 2962 \ |
| 2963 __ movss(IceType_f64, XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 2964 __ movd(dwordAddress(T1), XmmRegister::Encoded_Reg_##Src); \ |
| 2965 \ |
| 2966 AssembledTest test = assemble(); \ |
| 2967 \ |
| 2968 test.setDwordTo(T0, V0); \ |
| 2969 test.setDwordTo(T1, V1); \ |
| 2970 test.run(); \ |
| 2971 \ |
| 2972 ASSERT_EQ(Value, test.contentsOfDword(T1)) << TestString << " value is " \ |
| 2973 << Value; \ |
| 2974 reset(); \ |
| 2975 } while (0) |
| 2976 |
| 2977 #define TestMovd(Src) \ |
| 2978 do { \ |
| 2979 for (uint32_t Value : {0u, 1u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu}) { \ |
| 2980 TestMovdRegXmm(Src, eax, Value); \ |
| 2981 TestMovdRegXmm(Src, ebx, Value); \ |
| 2982 TestMovdRegXmm(Src, ecx, Value); \ |
| 2983 TestMovdRegXmm(Src, edx, Value); \ |
| 2984 TestMovdRegXmm(Src, esi, Value); \ |
| 2985 TestMovdRegXmm(Src, edi, Value); \ |
| 2986 TestMovdAddrXmm(Src, Value); \ |
| 2987 } \ |
| 2988 } while (0) |
| 2989 |
| 2990 TestMovd(xmm0); |
| 2991 TestMovd(xmm1); |
| 2992 TestMovd(xmm2); |
| 2993 TestMovd(xmm3); |
| 2994 TestMovd(xmm4); |
| 2995 TestMovd(xmm5); |
| 2996 TestMovd(xmm6); |
| 2997 TestMovd(xmm7); |
| 2998 |
| 2999 #undef TestMovdAddrXmm |
| 3000 #undef TestMovdRegXmm |
| 3001 #undef TestMovd |
| 3002 } |
| 3003 |
| 3004 TEST_F(AssemblerX8632Test, MovqXmmAddr) { |
| 3005 #define TestMovd(Dst, Value) \ |
| 3006 do { \ |
| 3007 static constexpr char TestString[] = "(" #Dst ", Addr)"; \ |
| 3008 const uint32_t T0 = allocateQword(); \ |
| 3009 const uint64_t V0 = Value; \ |
| 3010 const uint32_t T1 = allocateQword(); \ |
| 3011 const uint64_t V1 = ~(Value); \ |
| 3012 \ |
| 3013 __ movss(IceType_f64, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3014 __ movq(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3015 \ |
| 3016 AssembledTest test = assemble(); \ |
| 3017 \ |
| 3018 test.setQwordTo(T0, V0); \ |
| 3019 test.setQwordTo(T1, V1); \ |
| 3020 test.run(); \ |
| 3021 \ |
| 3022 ASSERT_EQ(Value, test.Dst<uint64_t>()) << TestString << " value is " \ |
| 3023 << Value; \ |
| 3024 reset(); \ |
| 3025 } while (0) |
| 3026 |
| 3027 for (uint32_t Value : {0u, 1u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu}) { |
| 3028 TestMovd(xmm0, Value); |
| 3029 TestMovd(xmm1, Value); |
| 3030 TestMovd(xmm2, Value); |
| 3031 TestMovd(xmm3, Value); |
| 3032 TestMovd(xmm4, Value); |
| 3033 TestMovd(xmm5, Value); |
| 3034 TestMovd(xmm6, Value); |
| 3035 TestMovd(xmm7, Value); |
| 3036 } |
| 3037 |
| 3038 #undef TestMovd |
| 3039 } |
| 3040 |
| 3041 TEST_F(AssemblerX8632Test, MovqAddrXmm) { |
| 3042 #define TestMovd(Dst, Value) \ |
| 3043 do { \ |
| 3044 static constexpr char TestString[] = "(" #Dst ", Addr)"; \ |
| 3045 const uint32_t T0 = allocateQword(); \ |
| 3046 const uint64_t V0 = Value; \ |
| 3047 const uint32_t T1 = allocateQword(); \ |
| 3048 const uint64_t V1 = ~(Value); \ |
| 3049 \ |
| 3050 __ movq(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3051 __ movq(dwordAddress(T1), XmmRegister::Encoded_Reg_##Dst); \ |
| 3052 \ |
| 3053 AssembledTest test = assemble(); \ |
| 3054 \ |
| 3055 test.setQwordTo(T0, V0); \ |
| 3056 test.setQwordTo(T1, V1); \ |
| 3057 test.run(); \ |
| 3058 \ |
| 3059 ASSERT_EQ(Value, test.Dst<uint64_t>()) << TestString << " value is " \ |
| 3060 << Value; \ |
| 3061 reset(); \ |
| 3062 } while (0) |
| 3063 |
| 3064 for (uint32_t Value : {0u, 1u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu}) { |
| 3065 TestMovd(xmm0, Value); |
| 3066 TestMovd(xmm1, Value); |
| 3067 TestMovd(xmm2, Value); |
| 3068 TestMovd(xmm3, Value); |
| 3069 TestMovd(xmm4, Value); |
| 3070 TestMovd(xmm5, Value); |
| 3071 TestMovd(xmm6, Value); |
| 3072 TestMovd(xmm7, Value); |
| 3073 } |
| 3074 |
| 3075 #undef TestMovd |
| 3076 } |
| 3077 |
| 3078 TEST_F(AssemblerX8632Test, MovqXmmXmm) { |
| 3079 #define TestMovd(Src, Dst, Value) \ |
| 3080 do { \ |
| 3081 static constexpr char TestString[] = "(" #Src ", " #Dst ")"; \ |
| 3082 const uint32_t T0 = allocateQword(); \ |
| 3083 const uint64_t V0 = Value; \ |
| 3084 const uint32_t T1 = allocateQword(); \ |
| 3085 const uint64_t V1 = ~(Value); \ |
| 3086 \ |
| 3087 __ movq(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 3088 __ movq(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3089 __ movq(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 3090 \ |
| 3091 AssembledTest test = assemble(); \ |
| 3092 \ |
| 3093 test.setQwordTo(T0, V0); \ |
| 3094 test.setQwordTo(T1, V1); \ |
| 3095 test.run(); \ |
| 3096 \ |
| 3097 ASSERT_EQ(Value, test.Dst<uint64_t>()) << TestString << " value is " \ |
| 3098 << Value; \ |
| 3099 reset(); \ |
| 3100 } while (0) |
| 3101 |
| 3102 for (uint32_t Value : {0u, 1u, 0x7FFFFFFFu, 0x80000000u, 0xFFFFFFFFu}) { |
| 3103 TestMovd(xmm0, xmm1, Value); |
| 3104 TestMovd(xmm1, xmm2, Value); |
| 3105 TestMovd(xmm2, xmm3, Value); |
| 3106 TestMovd(xmm3, xmm4, Value); |
| 3107 TestMovd(xmm4, xmm5, Value); |
| 3108 TestMovd(xmm5, xmm6, Value); |
| 3109 TestMovd(xmm6, xmm7, Value); |
| 3110 TestMovd(xmm7, xmm0, Value); |
| 3111 } |
| 3112 |
| 3113 #undef TestMovd |
| 3114 } |
| 3115 |
| 3116 TEST_F(AssemblerX8632Test, ArithSS) { |
| 3117 #define TestArithSSXmmXmm(FloatSize, Src, Value0, Dst, Value1, Inst, Op) \ |
| 3118 do { \ |
| 3119 static_assert(FloatSize == 32 || FloatSize == 64, \ |
| 3120 "Invalid fp size " #FloatSize); \ |
| 3121 static constexpr char TestString[] = \ |
| 3122 "(" #FloatSize ", " #Src ", " #Value0 ", " #Dst ", " #Value1 \ |
| 3123 ", " #Inst ", " #Op ")"; \ |
| 3124 static constexpr bool IsDouble = FloatSize == 64; \ |
| 3125 using Type = std::conditional<IsDouble, double, float>::type; \ |
| 3126 const uint32_t T0 = allocateQword(); \ |
| 3127 const Type V0 = Value0; \ |
| 3128 const uint32_t T1 = allocateQword(); \ |
| 3129 const Type V1 = Value1; \ |
| 3130 \ |
| 3131 __ movss(IceType_f##FloatSize, XmmRegister::Encoded_Reg_##Dst, \ |
| 3132 dwordAddress(T0)); \ |
| 3133 __ movss(IceType_f##FloatSize, XmmRegister::Encoded_Reg_##Src, \ |
| 3134 dwordAddress(T1)); \ |
| 3135 __ Inst(IceType_f##FloatSize, XmmRegister::Encoded_Reg_##Dst, \ |
| 3136 XmmRegister::Encoded_Reg_##Src); \ |
| 3137 \ |
| 3138 AssembledTest test = assemble(); \ |
| 3139 if (IsDouble) { \ |
| 3140 test.setQwordTo(T0, static_cast<double>(V0)); \ |
| 3141 test.setQwordTo(T1, static_cast<double>(V1)); \ |
| 3142 } else { \ |
| 3143 test.setDwordTo(T0, static_cast<float>(V0)); \ |
| 3144 test.setDwordTo(T1, static_cast<float>(V1)); \ |
| 3145 } \ |
| 3146 \ |
| 3147 test.run(); \ |
| 3148 \ |
| 3149 ASSERT_DOUBLE_EQ(V0 Op V1, test.Dst<Type>()) << TestString; \ |
| 3150 reset(); \ |
| 3151 } while (0) |
| 3152 |
| 3153 #define TestArithSSXmmAddr(FloatSize, Value0, Dst, Value1, Inst, Op) \ |
| 3154 do { \ |
| 3155 static_assert(FloatSize == 32 || FloatSize == 64, \ |
| 3156 "Invalid fp size " #FloatSize); \ |
| 3157 static constexpr char TestString[] = \ |
| 3158 "(" #FloatSize ", Addr, " #Value0 ", " #Dst ", " #Value1 ", " #Inst \ |
| 3159 ", " #Op ")"; \ |
| 3160 static constexpr bool IsDouble = FloatSize == 64; \ |
| 3161 using Type = std::conditional<IsDouble, double, float>::type; \ |
| 3162 const uint32_t T0 = allocateQword(); \ |
| 3163 const Type V0 = Value0; \ |
| 3164 const uint32_t T1 = allocateQword(); \ |
| 3165 const Type V1 = Value1; \ |
| 3166 \ |
| 3167 __ movss(IceType_f##FloatSize, XmmRegister::Encoded_Reg_##Dst, \ |
| 3168 dwordAddress(T0)); \ |
| 3169 __ Inst(IceType_f##FloatSize, XmmRegister::Encoded_Reg_##Dst, \ |
| 3170 dwordAddress(T1)); \ |
| 3171 \ |
| 3172 AssembledTest test = assemble(); \ |
| 3173 if (IsDouble) { \ |
| 3174 test.setQwordTo(T0, static_cast<double>(V0)); \ |
| 3175 test.setQwordTo(T1, static_cast<double>(V1)); \ |
| 3176 } else { \ |
| 3177 test.setDwordTo(T0, static_cast<float>(V0)); \ |
| 3178 test.setDwordTo(T1, static_cast<float>(V1)); \ |
| 3179 } \ |
| 3180 \ |
| 3181 test.run(); \ |
| 3182 \ |
| 3183 ASSERT_DOUBLE_EQ(V0 Op V1, test.Dst<Type>()) << TestString; \ |
| 3184 reset(); \ |
| 3185 } while (0) |
| 3186 |
| 3187 #define TestArithSS(FloatSize, Src, Dst0, Dst1) \ |
| 3188 do { \ |
| 3189 TestArithSSXmmXmm(FloatSize, Src, 1.0, Dst0, 10.0, addss, +); \ |
| 3190 TestArithSSXmmAddr(FloatSize, 2.0, Dst1, 20.0, addss, +); \ |
| 3191 TestArithSSXmmXmm(FloatSize, Src, 3.0, Dst0, 30.0, subss, -); \ |
| 3192 TestArithSSXmmAddr(FloatSize, 4.0, Dst1, 40.0, subss, -); \ |
| 3193 TestArithSSXmmXmm(FloatSize, Src, 5.0, Dst0, 50.0, mulss, *); \ |
| 3194 TestArithSSXmmAddr(FloatSize, 6.0, Dst1, 60.0, mulss, *); \ |
| 3195 TestArithSSXmmXmm(FloatSize, Src, 7.0, Dst0, 70.0, divss, / ); \ |
| 3196 TestArithSSXmmAddr(FloatSize, 8.0, Dst1, 80.0, divss, / ); \ |
| 3197 } while (0) |
| 3198 |
| 3199 TestArithSS(32, xmm0, xmm1, xmm2); |
| 3200 TestArithSS(32, xmm1, xmm2, xmm3); |
| 3201 TestArithSS(32, xmm2, xmm3, xmm4); |
| 3202 TestArithSS(32, xmm3, xmm4, xmm5); |
| 3203 TestArithSS(32, xmm4, xmm5, xmm6); |
| 3204 TestArithSS(32, xmm5, xmm6, xmm7); |
| 3205 TestArithSS(32, xmm6, xmm7, xmm0); |
| 3206 TestArithSS(32, xmm7, xmm0, xmm1); |
| 3207 |
| 3208 TestArithSS(64, xmm0, xmm1, xmm2); |
| 3209 TestArithSS(64, xmm1, xmm2, xmm3); |
| 3210 TestArithSS(64, xmm2, xmm3, xmm4); |
| 3211 TestArithSS(64, xmm3, xmm4, xmm5); |
| 3212 TestArithSS(64, xmm4, xmm5, xmm6); |
| 3213 TestArithSS(64, xmm5, xmm6, xmm7); |
| 3214 TestArithSS(64, xmm6, xmm7, xmm0); |
| 3215 TestArithSS(64, xmm7, xmm0, xmm1); |
| 3216 |
| 3217 #undef TestArithSS |
| 3218 #undef TestArithSSXmmAddr |
| 3219 #undef TestArithSSXmmXmm |
| 3220 } |
| 3221 |
| 3222 TEST_F(AssemblerX8632Test, MovupsXmmAddr) { |
| 3223 #define TestMovups(Dst) \ |
| 3224 do { \ |
| 3225 static constexpr char TestString[] = "(" #Dst ")"; \ |
| 3226 const uint32_t T0 = allocateDqword(); \ |
| 3227 const Dqword V0(1.0f, -1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3228 std::numeric_limits<float>::infinity()); \ |
| 3229 \ |
| 3230 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3231 \ |
| 3232 AssembledTest test = assemble(); \ |
| 3233 test.setDqwordTo(T0, V0); \ |
| 3234 test.run(); \ |
| 3235 \ |
| 3236 ASSERT_EQ(V0, test.Dst<Dqword>()) << TestString; \ |
| 3237 reset(); \ |
| 3238 } while (0) |
| 3239 |
| 3240 TestMovups(xmm0); |
| 3241 TestMovups(xmm1); |
| 3242 TestMovups(xmm2); |
| 3243 TestMovups(xmm3); |
| 3244 TestMovups(xmm4); |
| 3245 TestMovups(xmm5); |
| 3246 TestMovups(xmm6); |
| 3247 TestMovups(xmm7); |
| 3248 |
| 3249 #undef TestMovups |
| 3250 } |
| 3251 |
| 3252 TEST_F(AssemblerX8632Test, MovupsAddrXmm) { |
| 3253 #define TestMovups(Src) \ |
| 3254 do { \ |
| 3255 static constexpr char TestString[] = "(" #Src ")"; \ |
| 3256 const uint32_t T0 = allocateDqword(); \ |
| 3257 const Dqword V0(1.0f, -1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3258 std::numeric_limits<float>::infinity()); \ |
| 3259 const uint32_t T1 = allocateDqword(); \ |
| 3260 const Dqword V1(0.0, 0.0, 0.0, 0.0); \ |
| 3261 \ |
| 3262 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 3263 __ movups(dwordAddress(T1), XmmRegister::Encoded_Reg_##Src); \ |
| 3264 \ |
| 3265 AssembledTest test = assemble(); \ |
| 3266 test.setDqwordTo(T0, V0); \ |
| 3267 test.setDqwordTo(T1, V1); \ |
| 3268 test.run(); \ |
| 3269 \ |
| 3270 ASSERT_EQ(V0, test.contentsOfDqword(T1)) << TestString; \ |
| 3271 reset(); \ |
| 3272 } while (0) |
| 3273 |
| 3274 TestMovups(xmm0); |
| 3275 TestMovups(xmm1); |
| 3276 TestMovups(xmm2); |
| 3277 TestMovups(xmm3); |
| 3278 TestMovups(xmm4); |
| 3279 TestMovups(xmm5); |
| 3280 TestMovups(xmm6); |
| 3281 TestMovups(xmm7); |
| 3282 |
| 3283 #undef TestMovups |
| 3284 } |
| 3285 |
| 3286 TEST_F(AssemblerX8632Test, MovupsXmmXmm) { |
| 3287 #define TestMovups(Dst, Src) \ |
| 3288 do { \ |
| 3289 static constexpr char TestString[] = "(" #Dst ", " #Src ")"; \ |
| 3290 const uint32_t T0 = allocateDqword(); \ |
| 3291 const Dqword V0(1.0f, -1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3292 std::numeric_limits<float>::infinity()); \ |
| 3293 const uint32_t T1 = allocateDqword(); \ |
| 3294 const Dqword V1(0.0, 0.0, 0.0, 0.0); \ |
| 3295 \ |
| 3296 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 3297 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3298 __ movups(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 3299 \ |
| 3300 AssembledTest test = assemble(); \ |
| 3301 test.setDqwordTo(T0, V0); \ |
| 3302 test.setDqwordTo(T1, V1); \ |
| 3303 test.run(); \ |
| 3304 \ |
| 3305 ASSERT_EQ(V0, test.Dst<Dqword>()) << TestString; \ |
| 3306 reset(); \ |
| 3307 } while (0) |
| 3308 |
| 3309 TestMovups(xmm0, xmm1); |
| 3310 TestMovups(xmm1, xmm2); |
| 3311 TestMovups(xmm2, xmm3); |
| 3312 TestMovups(xmm3, xmm4); |
| 3313 TestMovups(xmm4, xmm5); |
| 3314 TestMovups(xmm5, xmm6); |
| 3315 TestMovups(xmm6, xmm7); |
| 3316 TestMovups(xmm7, xmm0); |
| 3317 |
| 3318 #undef TestMovups |
| 3319 } |
| 3320 |
| 3321 TEST_F(AssemblerX8632Test, MovapsXmmXmm) { |
| 3322 #define TestMovaps(Dst, Src) \ |
| 3323 do { \ |
| 3324 static constexpr char TestString[] = "(" #Dst ", " #Src ")"; \ |
| 3325 const uint32_t T0 = allocateDqword(); \ |
| 3326 const Dqword V0(1.0f, -1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3327 std::numeric_limits<float>::infinity()); \ |
| 3328 const uint32_t T1 = allocateDqword(); \ |
| 3329 const Dqword V1(0.0, 0.0, 0.0, 0.0); \ |
| 3330 \ |
| 3331 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 3332 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3333 __ movaps(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 3334 \ |
| 3335 AssembledTest test = assemble(); \ |
| 3336 test.setDqwordTo(T0, V0); \ |
| 3337 test.setDqwordTo(T1, V1); \ |
| 3338 test.run(); \ |
| 3339 \ |
| 3340 ASSERT_EQ(V0, test.Dst<Dqword>()) << TestString; \ |
| 3341 reset(); \ |
| 3342 } while (0) |
| 3343 |
| 3344 TestMovaps(xmm0, xmm1); |
| 3345 TestMovaps(xmm1, xmm2); |
| 3346 TestMovaps(xmm2, xmm3); |
| 3347 TestMovaps(xmm3, xmm4); |
| 3348 TestMovaps(xmm4, xmm5); |
| 3349 TestMovaps(xmm5, xmm6); |
| 3350 TestMovaps(xmm6, xmm7); |
| 3351 TestMovaps(xmm7, xmm0); |
| 3352 |
| 3353 #undef TestMovaps |
| 3354 } |
| 3355 |
| 3356 TEST_F(AssemblerX8632Test, PArith) { |
| 3357 #define TestPArithXmmXmm(Dst, Value0, Src, Value1, Inst, Op, Type, Size) \ |
| 3358 do { \ |
| 3359 static constexpr char TestString[] = \ |
| 3360 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Inst ", " #Op \ |
| 3361 ", " #Type ", " #Size ")"; \ |
| 3362 const uint32_t T0 = allocateDqword(); \ |
| 3363 const Dqword V0 Value0; \ |
| 3364 \ |
| 3365 const uint32_t T1 = allocateDqword(); \ |
| 3366 const Dqword V1 Value1; \ |
| 3367 \ |
| 3368 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3369 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3370 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 3371 XmmRegister::Encoded_Reg_##Src); \ |
| 3372 \ |
| 3373 AssembledTest test = assemble(); \ |
| 3374 test.setDqwordTo(T0, V0); \ |
| 3375 test.setDqwordTo(T1, V1); \ |
| 3376 test.run(); \ |
| 3377 \ |
| 3378 ASSERT_EQ(packedAs<Type##Size##_t>(V0) Op V1, test.Dst<Dqword>()) \ |
| 3379 << TestString; \ |
| 3380 reset(); \ |
| 3381 } while (0) |
| 3382 |
| 3383 #define TestPArithXmmAddr(Dst, Value0, Value1, Inst, Op, Type, Size) \ |
| 3384 do { \ |
| 3385 static constexpr char TestString[] = \ |
| 3386 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Inst ", " #Op \ |
| 3387 ", " #Type ", " #Size ")"; \ |
| 3388 const uint32_t T0 = allocateDqword(); \ |
| 3389 const Dqword V0 Value0; \ |
| 3390 \ |
| 3391 const uint32_t T1 = allocateDqword(); \ |
| 3392 const Dqword V1 Value1; \ |
| 3393 \ |
| 3394 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3395 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 3396 dwordAddress(T1)); \ |
| 3397 \ |
| 3398 AssembledTest test = assemble(); \ |
| 3399 test.setDqwordTo(T0, V0); \ |
| 3400 test.setDqwordTo(T1, V1); \ |
| 3401 test.run(); \ |
| 3402 \ |
| 3403 ASSERT_EQ(packedAs<Type##Size##_t>(V0) Op V1, test.Dst<Dqword>()) \ |
| 3404 << TestString; \ |
| 3405 reset(); \ |
| 3406 } while (0) |
| 3407 |
| 3408 #define TestPArithXmmImm(Dst, Value0, Imm, Inst, Op, Type, Size) \ |
| 3409 do { \ |
| 3410 static constexpr char TestString[] = \ |
| 3411 "(" #Dst ", " #Value0 ", " #Imm ", " #Inst ", " #Op ", " #Type \ |
| 3412 ", " #Size ")"; \ |
| 3413 const uint32_t T0 = allocateDqword(); \ |
| 3414 const Dqword V0 Value0; \ |
| 3415 \ |
| 3416 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3417 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, Immediate(Imm)); \ |
| 3418 \ |
| 3419 AssembledTest test = assemble(); \ |
| 3420 test.setDqwordTo(T0, V0); \ |
| 3421 test.run(); \ |
| 3422 \ |
| 3423 ASSERT_EQ(packedAs<Type##Size##_t>(V0) Op Imm, test.Dst<Dqword>()) \ |
| 3424 << TestString; \ |
| 3425 reset(); \ |
| 3426 } while (0) |
| 3427 |
| 3428 #define TestPAndnXmmXmm(Dst, Value0, Src, Value1, Type, Size) \ |
| 3429 do { \ |
| 3430 static constexpr char TestString[] = \ |
| 3431 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", pandn, " #Type \ |
| 3432 ", " #Size ")"; \ |
| 3433 const uint32_t T0 = allocateDqword(); \ |
| 3434 const Dqword V0 Value0; \ |
| 3435 \ |
| 3436 const uint32_t T1 = allocateDqword(); \ |
| 3437 const Dqword V1 Value1; \ |
| 3438 \ |
| 3439 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3440 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3441 __ pandn(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 3442 XmmRegister::Encoded_Reg_##Src); \ |
| 3443 \ |
| 3444 AssembledTest test = assemble(); \ |
| 3445 test.setDqwordTo(T0, V0); \ |
| 3446 test.setDqwordTo(T1, V1); \ |
| 3447 test.run(); \ |
| 3448 \ |
| 3449 ASSERT_EQ(~(packedAs<Type##Size##_t>(V0)) & V1, test.Dst<Dqword>()) \ |
| 3450 << TestString; \ |
| 3451 reset(); \ |
| 3452 } while (0) |
| 3453 |
| 3454 #define TestPAndnXmmAddr(Dst, Value0, Value1, Type, Size) \ |
| 3455 do { \ |
| 3456 static constexpr char TestString[] = \ |
| 3457 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", pandn, " #Type ", " #Size \ |
| 3458 ")"; \ |
| 3459 const uint32_t T0 = allocateDqword(); \ |
| 3460 const Dqword V0 Value0; \ |
| 3461 \ |
| 3462 const uint32_t T1 = allocateDqword(); \ |
| 3463 const Dqword V1 Value1; \ |
| 3464 \ |
| 3465 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3466 __ pandn(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 3467 dwordAddress(T1)); \ |
| 3468 \ |
| 3469 AssembledTest test = assemble(); \ |
| 3470 test.setDqwordTo(T0, V0); \ |
| 3471 test.setDqwordTo(T1, V1); \ |
| 3472 test.run(); \ |
| 3473 \ |
| 3474 ASSERT_EQ((~packedAs<Type##Size##_t>(V0)) & V1, test.Dst<Dqword>()) \ |
| 3475 << TestString; \ |
| 3476 reset(); \ |
| 3477 } while (0) |
| 3478 |
| 3479 #define TestPArithSize(Dst, Src, Size) \ |
| 3480 do { \ |
| 3481 static_assert(Size == 8 || Size == 16 || Size == 32, "Invalid size."); \ |
| 3482 if (Size != 8) { \ |
| 3483 TestPArithXmmXmm( \ |
| 3484 Dst, \ |
| 3485 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3486 Src, (uint64_t(3u), uint64_t(0u)), psra, >>, int, Size); \ |
| 3487 TestPArithXmmAddr(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3488 uint64_t(0x8080404002020101ull)), \ |
| 3489 (uint64_t(3u), uint64_t(0u)), psra, >>, int, Size); \ |
| 3490 TestPArithXmmImm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3491 uint64_t(0x8080404002020101ull)), \ |
| 3492 3u, psra, >>, int, Size); \ |
| 3493 TestPArithXmmXmm( \ |
| 3494 Dst, \ |
| 3495 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3496 Src, (uint64_t(3u), uint64_t(0u)), psrl, >>, uint, Size); \ |
| 3497 TestPArithXmmAddr(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3498 uint64_t(0x8080404002020101ull)), \ |
| 3499 (uint64_t(3u), uint64_t(0u)), psrl, >>, uint, Size); \ |
| 3500 TestPArithXmmImm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3501 uint64_t(0x8080404002020101ull)), \ |
| 3502 3u, psrl, >>, uint, Size); \ |
| 3503 TestPArithXmmXmm( \ |
| 3504 Dst, \ |
| 3505 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3506 Src, (uint64_t(3u), uint64_t(0u)), psll, <<, uint, Size); \ |
| 3507 TestPArithXmmAddr(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3508 uint64_t(0x8080404002020101ull)), \ |
| 3509 (uint64_t(3u), uint64_t(0u)), psll, <<, uint, Size); \ |
| 3510 TestPArithXmmImm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3511 uint64_t(0x8080404002020101ull)), \ |
| 3512 3u, psll, <<, uint, Size); \ |
| 3513 \ |
| 3514 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3515 uint64_t(0x8080404002020101ull)), \ |
| 3516 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3517 uint64_t(0x0123456789ABCDEull)), \ |
| 3518 pmull, *, int, Size); \ |
| 3519 TestPArithXmmAddr( \ |
| 3520 Dst, \ |
| 3521 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3522 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3523 pmull, *, int, Size); \ |
| 3524 if (Size != 16) { \ |
| 3525 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3526 uint64_t(0x8080404002020101ull)), \ |
| 3527 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3528 uint64_t(0x0123456789ABCDEull)), \ |
| 3529 pmuludq, *, uint, Size); \ |
| 3530 TestPArithXmmAddr( \ |
| 3531 Dst, (uint64_t(0x8040201008040201ull), \ |
| 3532 uint64_t(0x8080404002020101ull)), \ |
| 3533 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3534 pmuludq, *, uint, Size); \ |
| 3535 } \ |
| 3536 } \ |
| 3537 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3538 uint64_t(0x8080404002020101ull)), \ |
| 3539 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3540 uint64_t(0x0123456789ABCDEull)), \ |
| 3541 padd, +, int, Size); \ |
| 3542 TestPArithXmmAddr( \ |
| 3543 Dst, \ |
| 3544 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3545 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3546 padd, +, int, Size); \ |
| 3547 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3548 uint64_t(0x8080404002020101ull)), \ |
| 3549 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3550 uint64_t(0x0123456789ABCDEull)), \ |
| 3551 psub, -, int, Size); \ |
| 3552 TestPArithXmmAddr( \ |
| 3553 Dst, \ |
| 3554 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3555 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3556 psub, -, int, Size); \ |
| 3557 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3558 uint64_t(0x8080404002020101ull)), \ |
| 3559 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3560 uint64_t(0x0123456789ABCDEull)), \ |
| 3561 pand, &, int, Size); \ |
| 3562 TestPArithXmmAddr( \ |
| 3563 Dst, \ |
| 3564 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3565 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3566 pand, &, int, Size); \ |
| 3567 \ |
| 3568 TestPAndnXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3569 uint64_t(0x8080404002020101ull)), \ |
| 3570 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3571 uint64_t(0x0123456789ABCDEull)), \ |
| 3572 int, Size); \ |
| 3573 TestPAndnXmmAddr( \ |
| 3574 Dst, \ |
| 3575 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3576 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3577 int, Size); \ |
| 3578 \ |
| 3579 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3580 uint64_t(0x8080404002020101ull)), \ |
| 3581 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3582 uint64_t(0x0123456789ABCDEull)), \ |
| 3583 por, |, int, Size); \ |
| 3584 TestPArithXmmAddr( \ |
| 3585 Dst, \ |
| 3586 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3587 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3588 por, |, int, Size); \ |
| 3589 TestPArithXmmXmm(Dst, (uint64_t(0x8040201008040201ull), \ |
| 3590 uint64_t(0x8080404002020101ull)), \ |
| 3591 Src, (uint64_t(0xFFFFFFFF00000000ull), \ |
| 3592 uint64_t(0x0123456789ABCDEull)), \ |
| 3593 pxor, ^, int, Size); \ |
| 3594 TestPArithXmmAddr( \ |
| 3595 Dst, \ |
| 3596 (uint64_t(0x8040201008040201ull), uint64_t(0x8080404002020101ull)), \ |
| 3597 (uint64_t(0xFFFFFFFF00000000ull), uint64_t(0x0123456789ABCDEull)), \ |
| 3598 pxor, ^, int, Size); \ |
| 3599 } while (0) |
| 3600 |
| 3601 #define TestPArith(Src, Dst) \ |
| 3602 do { \ |
| 3603 TestPArithSize(Src, Dst, 8); \ |
| 3604 TestPArithSize(Src, Dst, 16); \ |
| 3605 TestPArithSize(Src, Dst, 32); \ |
| 3606 } while (0) |
| 3607 |
| 3608 TestPArith(xmm0, xmm1); |
| 3609 TestPArith(xmm1, xmm2); |
| 3610 TestPArith(xmm2, xmm3); |
| 3611 TestPArith(xmm3, xmm4); |
| 3612 TestPArith(xmm4, xmm5); |
| 3613 TestPArith(xmm5, xmm6); |
| 3614 TestPArith(xmm6, xmm7); |
| 3615 TestPArith(xmm7, xmm0); |
| 3616 |
| 3617 #undef TestPArith |
| 3618 #undef TestPArithSize |
| 3619 #undef TestPAndnXmmAddr |
| 3620 #undef TestPAndnXmmXmm |
| 3621 #undef TestPArithXmmImm |
| 3622 #undef TestPArithXmmAddr |
| 3623 #undef TestPArithXmmXmm |
| 3624 } |
| 3625 |
| 3626 TEST_F(AssemblerX8632Test, ArithPS) { |
| 3627 #define TestArithPSXmmXmm(Dst, Value0, Src, Value1, Inst, Op, Type) \ |
| 3628 do { \ |
| 3629 static constexpr char TestString[] = \ |
| 3630 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Inst ", " #Op \ |
| 3631 ", " #Type ")"; \ |
| 3632 const uint32_t T0 = allocateDqword(); \ |
| 3633 const Dqword V0 Value0; \ |
| 3634 const uint32_t T1 = allocateDqword(); \ |
| 3635 const Dqword V1 Value1; \ |
| 3636 \ |
| 3637 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3638 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3639 __ Inst(IceType_f32, XmmRegister::Encoded_Reg_##Dst, \ |
| 3640 XmmRegister::Encoded_Reg_##Src); \ |
| 3641 \ |
| 3642 AssembledTest test = assemble(); \ |
| 3643 test.setDqwordTo(T0, V0); \ |
| 3644 test.setDqwordTo(T1, V1); \ |
| 3645 test.run(); \ |
| 3646 \ |
| 3647 ASSERT_EQ(packedAs<Type>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3648 \ |
| 3649 reset(); \ |
| 3650 } while (0) |
| 3651 |
| 3652 #define TestArithPSXmmXmmUntyped(Dst, Value0, Src, Value1, Inst, Op, Type) \ |
| 3653 do { \ |
| 3654 static constexpr char TestString[] = \ |
| 3655 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Inst ", " #Op \ |
| 3656 ", " #Type ")"; \ |
| 3657 const uint32_t T0 = allocateDqword(); \ |
| 3658 const Dqword V0 Value0; \ |
| 3659 const uint32_t T1 = allocateDqword(); \ |
| 3660 const Dqword V1 Value1; \ |
| 3661 \ |
| 3662 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3663 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3664 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 3665 \ |
| 3666 AssembledTest test = assemble(); \ |
| 3667 test.setDqwordTo(T0, V0); \ |
| 3668 test.setDqwordTo(T1, V1); \ |
| 3669 test.run(); \ |
| 3670 \ |
| 3671 ASSERT_EQ(packedAs<Type>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3672 \ |
| 3673 reset(); \ |
| 3674 } while (0) |
| 3675 |
| 3676 #define TestArithPSXmmAddrUntyped(Dst, Value0, Value1, Inst, Op, Type) \ |
| 3677 do { \ |
| 3678 static constexpr char TestString[] = \ |
| 3679 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Inst ", " #Op \ |
| 3680 ", " #Type ")"; \ |
| 3681 const uint32_t T0 = allocateDqword(); \ |
| 3682 const Dqword V0 Value0; \ |
| 3683 const uint32_t T1 = allocateDqword(); \ |
| 3684 const Dqword V1 Value1; \ |
| 3685 \ |
| 3686 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3687 __ Inst(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3688 \ |
| 3689 AssembledTest test = assemble(); \ |
| 3690 test.setDqwordTo(T0, V0); \ |
| 3691 test.setDqwordTo(T1, V1); \ |
| 3692 test.run(); \ |
| 3693 \ |
| 3694 ASSERT_EQ(packedAs<Type>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3695 \ |
| 3696 reset(); \ |
| 3697 } while (0) |
| 3698 |
| 3699 #define TestMinMaxPS(Dst, Value0, Src, Value1, Inst, Type) \ |
| 3700 do { \ |
| 3701 static constexpr char TestString[] = \ |
| 3702 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Inst ", " #Type \ |
| 3703 ")"; \ |
| 3704 const uint32_t T0 = allocateDqword(); \ |
| 3705 const Dqword V0 Value0; \ |
| 3706 const uint32_t T1 = allocateDqword(); \ |
| 3707 const Dqword V1 Value1; \ |
| 3708 \ |
| 3709 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3710 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3711 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 3712 \ |
| 3713 AssembledTest test = assemble(); \ |
| 3714 test.setDqwordTo(T0, V0); \ |
| 3715 test.setDqwordTo(T1, V1); \ |
| 3716 test.run(); \ |
| 3717 \ |
| 3718 ASSERT_EQ(packedAs<Type>(V0).Inst(V1), test.Dst<Dqword>()) << TestString; \ |
| 3719 \ |
| 3720 reset(); \ |
| 3721 } while (0) |
| 3722 |
| 3723 #define TestArithPSXmmAddr(Dst, Value0, Value1, Inst, Op, Type) \ |
| 3724 do { \ |
| 3725 static constexpr char TestString[] = \ |
| 3726 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Inst ", " #Op \ |
| 3727 ", " #Type ")"; \ |
| 3728 const uint32_t T0 = allocateDqword(); \ |
| 3729 const Dqword V0 Value0; \ |
| 3730 const uint32_t T1 = allocateDqword(); \ |
| 3731 const Dqword V1 Value1; \ |
| 3732 \ |
| 3733 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3734 __ Inst(IceType_f32, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3735 \ |
| 3736 AssembledTest test = assemble(); \ |
| 3737 test.setDqwordTo(T0, V0); \ |
| 3738 test.setDqwordTo(T1, V1); \ |
| 3739 test.run(); \ |
| 3740 \ |
| 3741 ASSERT_EQ(packedAs<Type>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3742 \ |
| 3743 reset(); \ |
| 3744 } while (0) |
| 3745 |
| 3746 #define TestArithPS(Dst, Src) \ |
| 3747 do { \ |
| 3748 TestArithPSXmmXmm(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3749 (0.55, 0.43, 0.23, 1.21), addps, +, float); \ |
| 3750 TestArithPSXmmAddr(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3751 (0.55, 0.43, 0.23, 1.21), addps, +, float); \ |
| 3752 TestArithPSXmmXmm(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3753 (0.55, 0.43, 0.23, 1.21), subps, -, float); \ |
| 3754 TestArithPSXmmAddr(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3755 (0.55, 0.43, 0.23, 1.21), subps, -, float); \ |
| 3756 TestArithPSXmmXmm(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3757 (0.55, 0.43, 0.23, 1.21), mulps, *, float); \ |
| 3758 TestArithPSXmmAddr(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3759 (0.55, 0.43, 0.23, 1.21), mulps, *, float); \ |
| 3760 TestArithPSXmmXmm(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3761 (0.55, 0.43, 0.23, 1.21), divps, /, float); \ |
| 3762 TestArithPSXmmAddr(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3763 (0.55, 0.43, 0.23, 1.21), divps, /, float); \ |
| 3764 TestArithPSXmmXmmUntyped(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3765 (0.55, 0.43, 0.23, 1.21), andps, &, float); \ |
| 3766 TestArithPSXmmAddrUntyped(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3767 (0.55, 0.43, 0.23, 1.21), andps, &, float); \ |
| 3768 TestArithPSXmmXmmUntyped(Dst, (1.0, -1000.0), Src, (0.55, 1.21), andpd, &, \ |
| 3769 double); \ |
| 3770 TestArithPSXmmAddrUntyped(Dst, (1.0, -1000.0), (0.55, 1.21), andpd, &, \ |
| 3771 double); \ |
| 3772 TestArithPSXmmXmmUntyped(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3773 (0.55, 0.43, 0.23, 1.21), orps, |, float); \ |
| 3774 TestArithPSXmmXmmUntyped(Dst, (1.0, -1000.0), Src, (0.55, 1.21), orpd, |, \ |
| 3775 double); \ |
| 3776 TestMinMaxPS(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3777 (0.55, 0.43, 0.23, 1.21), minps, float); \ |
| 3778 TestMinMaxPS(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3779 (0.55, 0.43, 0.23, 1.21), maxps, float); \ |
| 3780 TestMinMaxPS(Dst, (1.0, -1000.0), Src, (0.55, 1.21), minpd, double); \ |
| 3781 TestMinMaxPS(Dst, (1.0, -1000.0), Src, (0.55, 1.21), maxpd, double); \ |
| 3782 TestArithPSXmmXmmUntyped(Dst, (1.0, 100.0, -1000.0, 20.0), Src, \ |
| 3783 (0.55, 0.43, 0.23, 1.21), xorps, ^, float); \ |
| 3784 TestArithPSXmmAddrUntyped(Dst, (1.0, 100.0, -1000.0, 20.0), \ |
| 3785 (0.55, 0.43, 0.23, 1.21), xorps, ^, float); \ |
| 3786 TestArithPSXmmXmmUntyped(Dst, (1.0, -1000.0), Src, (0.55, 1.21), xorpd, ^, \ |
| 3787 double); \ |
| 3788 TestArithPSXmmAddrUntyped(Dst, (1.0, -1000.0), (0.55, 1.21), xorpd, ^, \ |
| 3789 double); \ |
| 3790 } while (0) |
| 3791 |
| 3792 #if 0 |
| 3793 |
| 3794 #endif |
| 3795 |
| 3796 TestArithPS(xmm0, xmm1); |
| 3797 TestArithPS(xmm1, xmm2); |
| 3798 TestArithPS(xmm2, xmm3); |
| 3799 TestArithPS(xmm3, xmm4); |
| 3800 TestArithPS(xmm4, xmm5); |
| 3801 TestArithPS(xmm5, xmm6); |
| 3802 TestArithPS(xmm6, xmm7); |
| 3803 TestArithPS(xmm7, xmm0); |
| 3804 |
| 3805 #undef TestArithPs |
| 3806 #undef TestMinMaxPS |
| 3807 #undef TestArithPSXmmXmmUntyped |
| 3808 #undef TestArithPSXmmAddr |
| 3809 #undef TestArithPSXmmXmm |
| 3810 } |
| 3811 |
| 3812 TEST_F(AssemblerX8632Test, Blending) { |
| 3813 using f32 = float; |
| 3814 using i8 = uint8_t; |
| 3815 |
| 3816 #define TestBlendingXmmXmm(Dst, Value0, Src, Value1, M /*ask*/, Inst, Type) \ |
| 3817 do { \ |
| 3818 static constexpr char TestString[] = \ |
| 3819 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #M ", " #Inst \ |
| 3820 ", " #Type ")"; \ |
| 3821 const uint32_t T0 = allocateDqword(); \ |
| 3822 const Dqword V0 Value0; \ |
| 3823 const uint32_t T1 = allocateDqword(); \ |
| 3824 const Dqword V1 Value1; \ |
| 3825 const uint32_t Mask = allocateDqword(); \ |
| 3826 const Dqword MaskValue M; \ |
| 3827 \ |
| 3828 __ movups(XmmRegister::Encoded_Reg_xmm0, dwordAddress(Mask)); \ |
| 3829 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3830 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3831 __ Inst(IceType_##Type, XmmRegister::Encoded_Reg_##Dst, \ |
| 3832 XmmRegister::Encoded_Reg_##Src); \ |
| 3833 \ |
| 3834 AssembledTest test = assemble(); \ |
| 3835 test.setDqwordTo(T0, V0); \ |
| 3836 test.setDqwordTo(T1, V1); \ |
| 3837 test.setDqwordTo(Mask, MaskValue); \ |
| 3838 test.run(); \ |
| 3839 \ |
| 3840 ASSERT_EQ(packedAs<Type>(V0).blendWith(V1, MaskValue), test.Dst<Dqword>()) \ |
| 3841 << TestString; \ |
| 3842 reset(); \ |
| 3843 } while (0) |
| 3844 |
| 3845 #define TestBlendingXmmAddr(Dst, Value0, Value1, M /*ask*/, Inst, Type) \ |
| 3846 do { \ |
| 3847 static constexpr char TestString[] = \ |
| 3848 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #M ", " #Inst ", " #Type \ |
| 3849 ")"; \ |
| 3850 const uint32_t T0 = allocateDqword(); \ |
| 3851 const Dqword V0 Value0; \ |
| 3852 const uint32_t T1 = allocateDqword(); \ |
| 3853 const Dqword V1 Value1; \ |
| 3854 const uint32_t Mask = allocateDqword(); \ |
| 3855 const Dqword MaskValue M; \ |
| 3856 \ |
| 3857 __ movups(XmmRegister::Encoded_Reg_xmm0, dwordAddress(Mask)); \ |
| 3858 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3859 __ Inst(IceType_##Type, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 3860 \ |
| 3861 AssembledTest test = assemble(); \ |
| 3862 test.setDqwordTo(T0, V0); \ |
| 3863 test.setDqwordTo(T1, V1); \ |
| 3864 test.setDqwordTo(Mask, MaskValue); \ |
| 3865 test.run(); \ |
| 3866 \ |
| 3867 ASSERT_EQ(packedAs<Type>(V0).blendWith(V1, MaskValue), test.Dst<Dqword>()) \ |
| 3868 << TestString; \ |
| 3869 reset(); \ |
| 3870 } while (0) |
| 3871 |
| 3872 #define TestBlending(Src, Dst) \ |
| 3873 do { \ |
| 3874 TestBlendingXmmXmm( \ |
| 3875 Dst, (1.0, 2.0, 1.0, 2.0), Src, (-1.0, -2.0, -1.0, -2.0), \ |
| 3876 (uint64_t(0x8000000000000000ull), uint64_t(0x0000000080000000ull)), \ |
| 3877 blendvps, f32); \ |
| 3878 TestBlendingXmmAddr( \ |
| 3879 Dst, (1.0, 2.0, 1.0, 2.0), (-1.0, -2.0, -1.0, -2.0), \ |
| 3880 (uint64_t(0x8000000000000000ull), uint64_t(0x0000000080000000ull)), \ |
| 3881 blendvps, f32); \ |
| 3882 TestBlendingXmmXmm( \ |
| 3883 Dst, \ |
| 3884 (uint64_t(0xFFFFFFFFFFFFFFFFull), uint64_t(0xBBBBBBBBBBBBBBBBull)), \ |
| 3885 Src, \ |
| 3886 (uint64_t(0xAAAAAAAAAAAAAAAAull), uint64_t(0xEEEEEEEEEEEEEEEEull)), \ |
| 3887 (uint64_t(0x8000000000000080ull), uint64_t(0x8080808000000000ull)), \ |
| 3888 pblendvb, i8); \ |
| 3889 TestBlendingXmmAddr( \ |
| 3890 Dst, \ |
| 3891 (uint64_t(0xFFFFFFFFFFFFFFFFull), uint64_t(0xBBBBBBBBBBBBBBBBull)), \ |
| 3892 (uint64_t(0xAAAAAAAAAAAAAAAAull), uint64_t(0xEEEEEEEEEEEEEEEEull)), \ |
| 3893 (uint64_t(0x8000000000000080ull), uint64_t(0x8080808000000000ull)), \ |
| 3894 pblendvb, i8); \ |
| 3895 } while (0) |
| 3896 |
| 3897 /* xmm0 is taken. It is the implicit mask . */ |
| 3898 TestBlending(xmm1, xmm2); |
| 3899 TestBlending(xmm2, xmm3); |
| 3900 TestBlending(xmm3, xmm4); |
| 3901 TestBlending(xmm4, xmm5); |
| 3902 TestBlending(xmm5, xmm6); |
| 3903 TestBlending(xmm6, xmm7); |
| 3904 TestBlending(xmm7, xmm1); |
| 3905 |
| 3906 #undef TestBlending |
| 3907 #undef TestBlendingXmmAddr |
| 3908 #undef TestBlendingXmmXmm |
| 3909 } |
| 3910 |
| 3911 TEST_F(AssemblerX8632Test, Cmpps) { |
| 3912 #define TestCmppsXmmXmm(Dst, Src, C, Op) \ |
| 3913 do { \ |
| 3914 static constexpr char TestString[] = \ |
| 3915 "(" #Src ", " #Dst ", " #C ", " #Op ")"; \ |
| 3916 const uint32_t T0 = allocateDqword(); \ |
| 3917 const Dqword V0(-1.0, 1.0, 3.14, 1024.5); \ |
| 3918 const uint32_t T1 = allocateDqword(); \ |
| 3919 const Dqword V1(-1.0, 1.0, 3.14, 1024.5); \ |
| 3920 \ |
| 3921 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3922 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3923 __ cmpps(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ |
| 3924 Cond::Cmpps_##C); \ |
| 3925 \ |
| 3926 AssembledTest test = assemble(); \ |
| 3927 test.setDqwordTo(T0, V0); \ |
| 3928 test.setDqwordTo(T1, V1); \ |
| 3929 test.run(); \ |
| 3930 \ |
| 3931 ASSERT_EQ(packedAs<float>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3932 ; \ |
| 3933 reset(); \ |
| 3934 } while (0) |
| 3935 |
| 3936 #define TestCmppsXmmAddr(Dst, C, Op) \ |
| 3937 do { \ |
| 3938 static constexpr char TestString[] = "(" #Dst ", Addr, " #C ", " #Op ")"; \ |
| 3939 const uint32_t T0 = allocateDqword(); \ |
| 3940 const Dqword V0(-1.0, 1.0, 3.14, 1024.5); \ |
| 3941 const uint32_t T1 = allocateDqword(); \ |
| 3942 const Dqword V1(-1.0, 1.0, 3.14, 1024.5); \ |
| 3943 \ |
| 3944 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3945 __ cmpps(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1), \ |
| 3946 Cond::Cmpps_##C); \ |
| 3947 \ |
| 3948 AssembledTest test = assemble(); \ |
| 3949 test.setDqwordTo(T0, V0); \ |
| 3950 test.setDqwordTo(T1, V1); \ |
| 3951 test.run(); \ |
| 3952 \ |
| 3953 ASSERT_EQ(packedAs<float>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ |
| 3954 ; \ |
| 3955 reset(); \ |
| 3956 } while (0) |
| 3957 |
| 3958 #define TestCmppsOrdUnordXmmXmm(Dst, Src, C) \ |
| 3959 do { \ |
| 3960 static constexpr char TestString[] = "(" #Src ", " #Dst ", " #C ")"; \ |
| 3961 const uint32_t T0 = allocateDqword(); \ |
| 3962 const Dqword V0(1.0, 1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3963 std::numeric_limits<float>::quiet_NaN()); \ |
| 3964 const uint32_t T1 = allocateDqword(); \ |
| 3965 const Dqword V1(1.0, std::numeric_limits<float>::quiet_NaN(), 1.0, \ |
| 3966 std::numeric_limits<float>::quiet_NaN()); \ |
| 3967 \ |
| 3968 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3969 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 3970 __ cmpps(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ |
| 3971 Cond::Cmpps_##C); \ |
| 3972 \ |
| 3973 AssembledTest test = assemble(); \ |
| 3974 test.setDqwordTo(T0, V0); \ |
| 3975 test.setDqwordTo(T1, V1); \ |
| 3976 test.run(); \ |
| 3977 \ |
| 3978 ASSERT_EQ(packedAs<float>(V0).C(V1), test.Dst<Dqword>()) << TestString; \ |
| 3979 ; \ |
| 3980 reset(); \ |
| 3981 } while (0) |
| 3982 |
| 3983 #define TestCmppsOrdUnordXmmAddr(Dst, C) \ |
| 3984 do { \ |
| 3985 static constexpr char TestString[] = "(" #Dst ", " #C ")"; \ |
| 3986 const uint32_t T0 = allocateDqword(); \ |
| 3987 const Dqword V0(1.0, 1.0, std::numeric_limits<float>::quiet_NaN(), \ |
| 3988 std::numeric_limits<float>::quiet_NaN()); \ |
| 3989 const uint32_t T1 = allocateDqword(); \ |
| 3990 const Dqword V1(1.0, std::numeric_limits<float>::quiet_NaN(), 1.0, \ |
| 3991 std::numeric_limits<float>::quiet_NaN()); \ |
| 3992 \ |
| 3993 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 3994 __ cmpps(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1), \ |
| 3995 Cond::Cmpps_##C); \ |
| 3996 \ |
| 3997 AssembledTest test = assemble(); \ |
| 3998 test.setDqwordTo(T0, V0); \ |
| 3999 test.setDqwordTo(T1, V1); \ |
| 4000 test.run(); \ |
| 4001 \ |
| 4002 ASSERT_EQ(packedAs<float>(V0).C(V1), test.Dst<Dqword>()) << TestString; \ |
| 4003 ; \ |
| 4004 reset(); \ |
| 4005 } while (0) |
| 4006 |
| 4007 #define TestCmpps(Dst, Src) \ |
| 4008 do { \ |
| 4009 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4010 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4011 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4012 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4013 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4014 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4015 TestCmppsOrdUnordXmmXmm(Dst, Src, unord); \ |
| 4016 TestCmppsOrdUnordXmmAddr(Dst, unord); \ |
| 4017 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4018 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4019 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4020 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4021 TestCmppsXmmXmm(Dst, Src, eq, == ); \ |
| 4022 TestCmppsXmmAddr(Dst, eq, == ); \ |
| 4023 TestCmppsOrdUnordXmmXmm(Dst, Src, unord); \ |
| 4024 TestCmppsOrdUnordXmmAddr(Dst, unord); \ |
| 4025 } while (0) |
| 4026 |
| 4027 TestCmpps(xmm0, xmm1); |
| 4028 TestCmpps(xmm1, xmm2); |
| 4029 TestCmpps(xmm2, xmm3); |
| 4030 TestCmpps(xmm3, xmm4); |
| 4031 TestCmpps(xmm4, xmm5); |
| 4032 TestCmpps(xmm5, xmm6); |
| 4033 TestCmpps(xmm6, xmm7); |
| 4034 TestCmpps(xmm7, xmm0); |
| 4035 |
| 4036 #undef TestCmpps |
| 4037 #undef TestCmppsOrdUnordXmmAddr |
| 4038 #undef TestCmppsOrdUnordXmmXmm |
| 4039 #undef TestCmppsXmmAddr |
| 4040 #undef TestCmppsXmmXmm |
| 4041 } |
| 4042 |
| 4043 TEST_F(AssemblerX8632Test, Sqrtps_Rsqrtps_Reciprocalps_Sqrtpd) { |
| 4044 #define TestImplSingle(Dst, Inst, Expect) \ |
| 4045 do { \ |
| 4046 static constexpr char TestString[] = "(" #Dst ", " #Inst ")"; \ |
| 4047 const uint32_t T0 = allocateDqword(); \ |
| 4048 const Dqword V0(1.0, 4.0, 20.0, 3.14); \ |
| 4049 \ |
| 4050 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4051 __ Inst(XmmRegister::Encoded_Reg_##Dst); \ |
| 4052 \ |
| 4053 AssembledTest test = assemble(); \ |
| 4054 test.setDqwordTo(T0, V0); \ |
| 4055 test.run(); \ |
| 4056 ASSERT_EQ(Dqword Expect, test.Dst<Dqword>()) << TestString; \ |
| 4057 reset(); \ |
| 4058 } while (0) |
| 4059 |
| 4060 #define TestImpl(Dst) \ |
| 4061 do { \ |
| 4062 TestImplSingle(Dst, sqrtps, (uint64_t(0x400000003F800000ull), \ |
| 4063 uint64_t(0x3FE2D10B408F1BBDull))); \ |
| 4064 TestImplSingle(Dst, rsqrtps, (uint64_t(0x3EFFF0003F7FF000ull), \ |
| 4065 uint64_t(0x3F1078003E64F000ull))); \ |
| 4066 TestImplSingle(Dst, reciprocalps, (uint64_t(0x3E7FF0003F7FF000ull), \ |
| 4067 uint64_t(0x3EA310003D4CC000ull))); \ |
| 4068 \ |
| 4069 TestImplSingle(Dst, sqrtpd, (uint64_t(0x4036A09E9365F5F3ull), \ |
| 4070 uint64_t(0x401C42FAE40282A8ull))); \ |
| 4071 } while (0) |
| 4072 |
| 4073 TestImpl(xmm0); |
| 4074 TestImpl(xmm1); |
| 4075 TestImpl(xmm2); |
| 4076 TestImpl(xmm3); |
| 4077 TestImpl(xmm4); |
| 4078 TestImpl(xmm5); |
| 4079 TestImpl(xmm6); |
| 4080 TestImpl(xmm7); |
| 4081 |
| 4082 #undef TestImpl |
| 4083 #undef TestImplSingle |
| 4084 } |
| 4085 |
| 4086 TEST_F(AssemblerX8632Test, Movhlps_Movlhps) { |
| 4087 #define TestImplSingle(Dst, Src, Inst, Expect) \ |
| 4088 do { \ |
| 4089 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Inst ")"; \ |
| 4090 const uint32_t T0 = allocateDqword(); \ |
| 4091 const Dqword V0(uint64_t(0xAAAAAAAABBBBBBBBull), \ |
| 4092 uint64_t(0xCCCCCCCCDDDDDDDDull)); \ |
| 4093 const uint32_t T1 = allocateDqword(); \ |
| 4094 const Dqword V1(uint64_t(0xEEEEEEEEFFFFFFFFull), \ |
| 4095 uint64_t(0x9999999988888888ull)); \ |
| 4096 \ |
| 4097 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4098 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4099 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 4100 \ |
| 4101 AssembledTest test = assemble(); \ |
| 4102 test.setDqwordTo(T0, V0); \ |
| 4103 test.setDqwordTo(T1, V1); \ |
| 4104 test.run(); \ |
| 4105 \ |
| 4106 ASSERT_EQ(Dqword Expect, test.Dst<Dqword>()) << TestString; \ |
| 4107 reset(); \ |
| 4108 } while (0) |
| 4109 |
| 4110 #define TestImpl(Dst, Src) \ |
| 4111 do { \ |
| 4112 TestImplSingle(Dst, Src, movhlps, (uint64_t(0x9999999988888888ull), \ |
| 4113 uint64_t(0xCCCCCCCCDDDDDDDDull))); \ |
| 4114 TestImplSingle(Dst, Src, movlhps, (uint64_t(0xAAAAAAAABBBBBBBBull), \ |
| 4115 uint64_t(0xEEEEEEEEFFFFFFFFull))); \ |
| 4116 } while (0) |
| 4117 |
| 4118 TestImpl(xmm0, xmm1); |
| 4119 TestImpl(xmm1, xmm2); |
| 4120 TestImpl(xmm2, xmm3); |
| 4121 TestImpl(xmm3, xmm4); |
| 4122 TestImpl(xmm4, xmm5); |
| 4123 TestImpl(xmm5, xmm6); |
| 4124 TestImpl(xmm6, xmm7); |
| 4125 TestImpl(xmm7, xmm0); |
| 4126 |
| 4127 #undef TestImpl |
| 4128 #undef TestImplSingle |
| 4129 } |
| 4130 |
| 4131 TEST_F(AssemblerX8632Test, Unpck) { |
| 4132 const Dqword V0(uint64_t(0xAAAAAAAABBBBBBBBull), |
| 4133 uint64_t(0xCCCCCCCCDDDDDDDDull)); |
| 4134 const Dqword V1(uint64_t(0xEEEEEEEEFFFFFFFFull), |
| 4135 uint64_t(0x9999999988888888ull)); |
| 4136 |
| 4137 const Dqword unpcklpsExpected(uint64_t(0xFFFFFFFFBBBBBBBBull), |
| 4138 uint64_t(0xEEEEEEEEAAAAAAAAull)); |
| 4139 const Dqword unpcklpdExpected(uint64_t(0xAAAAAAAABBBBBBBBull), |
| 4140 uint64_t(0xEEEEEEEEFFFFFFFFull)); |
| 4141 const Dqword unpckhpsExpected(uint64_t(0x88888888DDDDDDDDull), |
| 4142 uint64_t(0x99999999CCCCCCCCull)); |
| 4143 const Dqword unpckhpdExpected(uint64_t(0xCCCCCCCCDDDDDDDDull), |
| 4144 uint64_t(0x9999999988888888ull)); |
| 4145 |
| 4146 #define TestImplSingle(Dst, Src, Inst) \ |
| 4147 do { \ |
| 4148 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Inst ")"; \ |
| 4149 const uint32_t T0 = allocateDqword(); \ |
| 4150 const uint32_t T1 = allocateDqword(); \ |
| 4151 \ |
| 4152 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4153 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4154 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ |
| 4155 \ |
| 4156 AssembledTest test = assemble(); \ |
| 4157 test.setDqwordTo(T0, V0); \ |
| 4158 test.setDqwordTo(T1, V1); \ |
| 4159 test.run(); \ |
| 4160 \ |
| 4161 ASSERT_EQ(Inst##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4162 reset(); \ |
| 4163 } while (0) |
| 4164 |
| 4165 #define TestImpl(Dst, Src) \ |
| 4166 do { \ |
| 4167 TestImplSingle(Dst, Src, unpcklps); \ |
| 4168 TestImplSingle(Dst, Src, unpcklpd); \ |
| 4169 TestImplSingle(Dst, Src, unpckhps); \ |
| 4170 TestImplSingle(Dst, Src, unpckhpd); \ |
| 4171 } while (0) |
| 4172 |
| 4173 TestImpl(xmm0, xmm1); |
| 4174 TestImpl(xmm1, xmm2); |
| 4175 TestImpl(xmm2, xmm3); |
| 4176 TestImpl(xmm3, xmm4); |
| 4177 TestImpl(xmm4, xmm5); |
| 4178 TestImpl(xmm5, xmm6); |
| 4179 TestImpl(xmm6, xmm7); |
| 4180 TestImpl(xmm7, xmm0); |
| 4181 |
| 4182 #undef TestImpl |
| 4183 #undef TestImplSingle |
| 4184 } |
| 4185 |
| 4186 TEST_F(AssemblerX8632Test, Shufp) { |
| 4187 const Dqword V0(uint64_t(0x1111111122222222ull), |
| 4188 uint64_t(0x5555555577777777ull)); |
| 4189 const Dqword V1(uint64_t(0xAAAAAAAABBBBBBBBull), |
| 4190 uint64_t(0xCCCCCCCCDDDDDDDDull)); |
| 4191 |
| 4192 const uint8_t pshufdImm = 0x63; |
| 4193 const Dqword pshufdExpected(uint64_t(0xBBBBBBBBCCCCCCCCull), |
| 4194 uint64_t(0xAAAAAAAADDDDDDDDull)); |
| 4195 |
| 4196 const uint8_t shufpsImm = 0xf9; |
| 4197 const Dqword shufpsExpected(uint64_t(0x7777777711111111ull), |
| 4198 uint64_t(0xCCCCCCCCCCCCCCCCull)); |
| 4199 |
| 4200 #define TestImplSingleXmmXmm(Dst, Src, Inst) \ |
| 4201 do { \ |
| 4202 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Inst ")"; \ |
| 4203 const uint32_t T0 = allocateDqword(); \ |
| 4204 const uint32_t T1 = allocateDqword(); \ |
| 4205 \ |
| 4206 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4207 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4208 __ Inst(IceType_f32, XmmRegister::Encoded_Reg_##Dst, \ |
| 4209 XmmRegister::Encoded_Reg_##Src, Immediate(Inst##Imm)); \ |
| 4210 \ |
| 4211 AssembledTest test = assemble(); \ |
| 4212 test.setDqwordTo(T0, V0); \ |
| 4213 test.setDqwordTo(T1, V1); \ |
| 4214 test.run(); \ |
| 4215 \ |
| 4216 ASSERT_EQ(Inst##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4217 reset(); \ |
| 4218 } while (0) |
| 4219 |
| 4220 #define TestImplSingleXmmAddr(Dst, Inst) \ |
| 4221 do { \ |
| 4222 static constexpr char TestString[] = "(" #Dst ", Addr, " #Inst ")"; \ |
| 4223 const uint32_t T0 = allocateDqword(); \ |
| 4224 const uint32_t T1 = allocateDqword(); \ |
| 4225 \ |
| 4226 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4227 __ Inst(IceType_f32, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1), \ |
| 4228 Immediate(Inst##Imm)); \ |
| 4229 \ |
| 4230 AssembledTest test = assemble(); \ |
| 4231 test.setDqwordTo(T0, V0); \ |
| 4232 test.setDqwordTo(T1, V1); \ |
| 4233 test.run(); \ |
| 4234 \ |
| 4235 ASSERT_EQ(Inst##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4236 reset(); \ |
| 4237 } while (0) |
| 4238 |
| 4239 #define TestImplSingleXmmXmmUntyped(Dst, Src, Inst) \ |
| 4240 do { \ |
| 4241 static constexpr char TestString[] = \ |
| 4242 "(" #Dst ", " #Src ", " #Inst ", Untyped)"; \ |
| 4243 const uint32_t T0 = allocateDqword(); \ |
| 4244 const uint32_t T1 = allocateDqword(); \ |
| 4245 \ |
| 4246 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4247 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4248 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ |
| 4249 Immediate(Inst##Imm)); \ |
| 4250 \ |
| 4251 AssembledTest test = assemble(); \ |
| 4252 test.setDqwordTo(T0, V0); \ |
| 4253 test.setDqwordTo(T1, V1); \ |
| 4254 test.run(); \ |
| 4255 \ |
| 4256 ASSERT_EQ(Inst##UntypedExpected, test.Dst<Dqword>()) << TestString; \ |
| 4257 reset(); \ |
| 4258 } while (0) |
| 4259 |
| 4260 #define TestImpl(Dst, Src) \ |
| 4261 do { \ |
| 4262 TestImplSingleXmmXmm(Dst, Src, pshufd); \ |
| 4263 TestImplSingleXmmAddr(Dst, pshufd); \ |
| 4264 TestImplSingleXmmXmm(Dst, Src, shufps); \ |
| 4265 TestImplSingleXmmAddr(Dst, shufps); \ |
| 4266 } while (0) |
| 4267 |
| 4268 TestImpl(xmm0, xmm1); |
| 4269 TestImpl(xmm1, xmm2); |
| 4270 TestImpl(xmm2, xmm3); |
| 4271 TestImpl(xmm3, xmm4); |
| 4272 TestImpl(xmm4, xmm5); |
| 4273 TestImpl(xmm5, xmm6); |
| 4274 TestImpl(xmm6, xmm7); |
| 4275 TestImpl(xmm7, xmm0); |
| 4276 |
| 4277 #undef TestImpl |
| 4278 #undef TestImplSingleXmmXmmUntyped |
| 4279 #undef TestImplSingleXmmAddr |
| 4280 #undef TestImplSingleXmmXmm |
| 4281 } |
| 4282 |
| 4283 TEST_F(AssemblerX8632Test, Cvt) { |
| 4284 const Dqword dq2ps32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); |
| 4285 const Dqword dq2ps32SrcValue(-5, 3, 100, 200); |
| 4286 const Dqword dq2ps32Expected(-5.0f, 3.0f, 100.0, 200.0); |
| 4287 |
| 4288 const Dqword dq2ps64DstValue(0.0f, 0.0f, -1.0f, -1.0f); |
| 4289 const Dqword dq2ps64SrcValue(-5, 3, 100, 200); |
| 4290 const Dqword dq2ps64Expected(-5.0f, 3.0f, 100.0, 200.0); |
| 4291 |
| 4292 const Dqword tps2dq32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); |
| 4293 const Dqword tps2dq32SrcValue(-5.0f, 3.0f, 100.0, 200.0); |
| 4294 const Dqword tps2dq32Expected(-5, 3, 100, 200); |
| 4295 |
| 4296 const Dqword tps2dq64DstValue(-1.0f, -1.0f, -1.0f, -1.0f); |
| 4297 const Dqword tps2dq64SrcValue(-5.0f, 3.0f, 100.0, 200.0); |
| 4298 const Dqword tps2dq64Expected(-5, 3, 100, 200); |
| 4299 |
| 4300 const Dqword si2ss32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); |
| 4301 const int32_t si2ss32SrcValue = 5; |
| 4302 const Dqword si2ss32Expected(5.0f, -1.0f, -1.0f, -1.0f); |
| 4303 |
| 4304 const Dqword si2ss64DstValue(-1.0, -1.0); |
| 4305 const int32_t si2ss64SrcValue = 5; |
| 4306 const Dqword si2ss64Expected(5.0, -1.0); |
| 4307 |
| 4308 const int32_t tss2si32DstValue = 0xF00F0FF0; |
| 4309 const Dqword tss2si32SrcValue(-5.0f, -1.0f, -1.0f, -1.0f); |
| 4310 const int32_t tss2si32Expected = -5; |
| 4311 |
| 4312 const int32_t tss2si64DstValue = 0xF00F0FF0; |
| 4313 const Dqword tss2si64SrcValue(-5.0, -1.0); |
| 4314 const int32_t tss2si64Expected = -5; |
| 4315 |
| 4316 const Dqword float2float32DstValue(-1.0, -1.0); |
| 4317 const Dqword float2float32SrcValue(-5.0, 3, 100, 200); |
| 4318 const Dqword float2float32Expected(-5.0, -1.0); |
| 4319 |
| 4320 const Dqword float2float64DstValue(-1.0, -1.0, -1.0, -1.0); |
| 4321 const Dqword float2float64SrcValue(-5.0, 3.0); |
| 4322 const Dqword float2float64Expected(-5.0, -1.0, -1.0, -1.0); |
| 4323 |
| 4324 #define TestImplPXmmXmm(Dst, Src, Inst, Size) \ |
| 4325 do { \ |
| 4326 static constexpr char TestString[] = \ |
| 4327 "(" #Dst ", " #Src ", cvt" #Inst ", f" #Size ")"; \ |
| 4328 const uint32_t T0 = allocateDqword(); \ |
| 4329 const uint32_t T1 = allocateDqword(); \ |
| 4330 \ |
| 4331 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4332 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4333 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4334 XmmRegister::Encoded_Reg_##Src); \ |
| 4335 \ |
| 4336 AssembledTest test = assemble(); \ |
| 4337 test.setDqwordTo(T0, Inst##Size##DstValue); \ |
| 4338 test.setDqwordTo(T1, Inst##Size##SrcValue); \ |
| 4339 test.run(); \ |
| 4340 \ |
| 4341 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4342 reset(); \ |
| 4343 } while (0) |
| 4344 |
| 4345 #define TestImplSXmmReg(Dst, GPR, Inst, Size) \ |
| 4346 do { \ |
| 4347 static constexpr char TestString[] = \ |
| 4348 "(" #Dst ", " #GPR ", cvt" #Inst ", f" #Size ")"; \ |
| 4349 const uint32_t T0 = allocateDqword(); \ |
| 4350 \ |
| 4351 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4352 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ |
| 4353 Immediate(Inst##Size##SrcValue)); \ |
| 4354 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4355 GPRRegister::Encoded_Reg_##GPR); \ |
| 4356 \ |
| 4357 AssembledTest test = assemble(); \ |
| 4358 test.setDqwordTo(T0, Inst##Size##DstValue); \ |
| 4359 test.run(); \ |
| 4360 \ |
| 4361 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4362 reset(); \ |
| 4363 } while (0) |
| 4364 |
| 4365 #define TestImplSRegXmm(GPR, Src, Inst, Size) \ |
| 4366 do { \ |
| 4367 static constexpr char TestString[] = \ |
| 4368 "(" #GPR ", " #Src ", cvt" #Inst ", f" #Size ")"; \ |
| 4369 const uint32_t T0 = allocateDqword(); \ |
| 4370 \ |
| 4371 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ |
| 4372 Immediate(Inst##Size##DstValue)); \ |
| 4373 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 4374 __ cvt##Inst(IceType_f##Size, GPRRegister::Encoded_Reg_##GPR, \ |
| 4375 XmmRegister::Encoded_Reg_##Src); \ |
| 4376 \ |
| 4377 AssembledTest test = assemble(); \ |
| 4378 test.setDqwordTo(T0, Inst##Size##SrcValue); \ |
| 4379 test.run(); \ |
| 4380 \ |
| 4381 ASSERT_EQ(static_cast<uint32_t>(Inst##Size##Expected), test.GPR()) \ |
| 4382 << TestString; \ |
| 4383 reset(); \ |
| 4384 } while (0) |
| 4385 |
| 4386 #define TestImplPXmmAddr(Dst, Inst, Size) \ |
| 4387 do { \ |
| 4388 static constexpr char TestString[] = \ |
| 4389 "(" #Dst ", Addr, cvt" #Inst ", f" #Size ")"; \ |
| 4390 const uint32_t T0 = allocateDqword(); \ |
| 4391 const uint32_t T1 = allocateDqword(); \ |
| 4392 \ |
| 4393 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4394 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4395 dwordAddress(T1)); \ |
| 4396 \ |
| 4397 AssembledTest test = assemble(); \ |
| 4398 test.setDqwordTo(T0, Inst##Size##DstValue); \ |
| 4399 test.setDqwordTo(T1, Inst##Size##SrcValue); \ |
| 4400 test.run(); \ |
| 4401 \ |
| 4402 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4403 reset(); \ |
| 4404 } while (0) |
| 4405 |
| 4406 #define TestImplSXmmAddr(Dst, Inst, Size) \ |
| 4407 do { \ |
| 4408 static constexpr char TestString[] = \ |
| 4409 "(" #Dst ", Addr, cvt" #Inst ", f" #Size ")"; \ |
| 4410 const uint32_t T0 = allocateDqword(); \ |
| 4411 const uint32_t T1 = allocateDword(); \ |
| 4412 \ |
| 4413 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4414 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4415 dwordAddress(T1)); \ |
| 4416 \ |
| 4417 AssembledTest test = assemble(); \ |
| 4418 test.setDqwordTo(T0, Inst##Size##DstValue); \ |
| 4419 test.setDwordTo(T1, Inst##Size##SrcValue); \ |
| 4420 test.run(); \ |
| 4421 \ |
| 4422 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ |
| 4423 reset(); \ |
| 4424 } while (0) |
| 4425 |
| 4426 #define TestImplSRegAddr(GPR, Inst, Size) \ |
| 4427 do { \ |
| 4428 static constexpr char TestString[] = \ |
| 4429 "(" #GPR ", Addr, cvt" #Inst ", f" #Size ")"; \ |
| 4430 const uint32_t T0 = allocateDqword(); \ |
| 4431 \ |
| 4432 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ |
| 4433 Immediate(Inst##Size##DstValue)); \ |
| 4434 __ cvt##Inst(IceType_f##Size, GPRRegister::Encoded_Reg_##GPR, \ |
| 4435 dwordAddress(T0)); \ |
| 4436 \ |
| 4437 AssembledTest test = assemble(); \ |
| 4438 test.setDqwordTo(T0, Inst##Size##SrcValue); \ |
| 4439 test.run(); \ |
| 4440 \ |
| 4441 ASSERT_EQ(static_cast<uint32_t>(Inst##Size##Expected), test.GPR()) \ |
| 4442 << TestString; \ |
| 4443 reset(); \ |
| 4444 } while (0) |
| 4445 |
| 4446 #define TestImplSize(Dst, Src, GPR, Size) \ |
| 4447 do { \ |
| 4448 TestImplPXmmXmm(Dst, Src, dq2ps, Size); \ |
| 4449 TestImplPXmmAddr(Src, dq2ps, Size); \ |
| 4450 TestImplPXmmXmm(Dst, Src, tps2dq, Size); \ |
| 4451 TestImplPXmmAddr(Src, tps2dq, Size); \ |
| 4452 TestImplSXmmReg(Dst, GPR, si2ss, Size); \ |
| 4453 TestImplSXmmAddr(Dst, si2ss, Size); \ |
| 4454 TestImplSRegXmm(GPR, Src, tss2si, Size); \ |
| 4455 TestImplSRegAddr(GPR, tss2si, Size); \ |
| 4456 TestImplPXmmXmm(Dst, Src, float2float, Size); \ |
| 4457 TestImplPXmmAddr(Src, float2float, Size); \ |
| 4458 } while (0) |
| 4459 |
| 4460 #define TestImpl(Dst, Src, GPR) \ |
| 4461 do { \ |
| 4462 TestImplSize(Dst, Src, GPR, 32); \ |
| 4463 TestImplSize(Dst, Src, GPR, 64); \ |
| 4464 } while (0) |
| 4465 |
| 4466 TestImpl(xmm0, xmm1, eax); |
| 4467 TestImpl(xmm1, xmm2, ebx); |
| 4468 TestImpl(xmm2, xmm3, ecx); |
| 4469 TestImpl(xmm3, xmm4, edx); |
| 4470 TestImpl(xmm4, xmm5, esi); |
| 4471 TestImpl(xmm5, xmm6, edi); |
| 4472 TestImpl(xmm6, xmm7, eax); |
| 4473 TestImpl(xmm7, xmm0, ebx); |
| 4474 |
| 4475 #undef TestImpl |
| 4476 #undef TestImplSize |
| 4477 #undef TestImplSRegAddr |
| 4478 #undef TestImplSXmmAddr |
| 4479 #undef TestImplPXmmAddr |
| 4480 #undef TestImplSRegXmm |
| 4481 #undef TestImplSXmmReg |
| 4482 #undef TestImplPXmmXmm |
| 4483 } |
| 4484 |
| 4485 TEST_F(AssemblerX8632Test, Ucomiss) { |
| 4486 static constexpr float qnan32 = std::numeric_limits<float>::quiet_NaN(); |
| 4487 static constexpr double qnan64 = std::numeric_limits<float>::quiet_NaN(); |
| 4488 |
| 4489 Dqword test32DstValue(0.0, qnan32, qnan32, qnan32); |
| 4490 Dqword test32SrcValue(0.0, qnan32, qnan32, qnan32); |
| 4491 |
| 4492 Dqword test64DstValue(0.0, qnan64); |
| 4493 Dqword test64SrcValue(0.0, qnan64); |
| 4494 |
| 4495 #define TestImplXmmXmm(Dst, Value0, Src, Value1, Size, CompType, BParity, \ |
| 4496 BOther) \ |
| 4497 do { \ |
| 4498 static constexpr char NearBranch = AssemblerX8632::kNearJump; \ |
| 4499 static constexpr char TestString[] = \ |
| 4500 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ", " #CompType \ |
| 4501 ", " #BParity ", " #BOther ")"; \ |
| 4502 const uint32_t T0 = allocateDqword(); \ |
| 4503 test##Size##DstValue.F##Size[0] = Value0; \ |
| 4504 const uint32_t T1 = allocateDqword(); \ |
| 4505 test##Size##SrcValue.F##Size[0] = Value1; \ |
| 4506 const uint32_t ImmIfTrue = 0xBEEF; \ |
| 4507 const uint32_t ImmIfFalse = 0xC0FFE; \ |
| 4508 \ |
| 4509 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4510 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4511 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfFalse)); \ |
| 4512 __ ucomiss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4513 XmmRegister::Encoded_Reg_##Src); \ |
| 4514 Label Done; \ |
| 4515 __ j(Cond::Br_##BParity, &Done, NearBranch); \ |
| 4516 __ j(Cond::Br_##BOther, &Done, NearBranch); \ |
| 4517 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfTrue)); \ |
| 4518 __ bind(&Done); \ |
| 4519 \ |
| 4520 AssembledTest test = assemble(); \ |
| 4521 test.setDqwordTo(T0, test##Size##DstValue); \ |
| 4522 test.setDqwordTo(T1, test##Size##SrcValue); \ |
| 4523 test.run(); \ |
| 4524 \ |
| 4525 ASSERT_EQ(ImmIfTrue, test.eax()) << TestString; \ |
| 4526 reset(); \ |
| 4527 } while (0) |
| 4528 |
| 4529 #define TestImplXmmAddr(Dst, Value0, Value1, Size, CompType, BParity, BOther) \ |
| 4530 do { \ |
| 4531 static constexpr char NearBranch = AssemblerX8632::kNearJump; \ |
| 4532 static constexpr char TestString[] = \ |
| 4533 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Size ", " #CompType \ |
| 4534 ", " #BParity ", " #BOther ")"; \ |
| 4535 const uint32_t T0 = allocateDqword(); \ |
| 4536 test##Size##DstValue.F##Size[0] = Value0; \ |
| 4537 const uint32_t T1 = allocateDqword(); \ |
| 4538 test##Size##SrcValue.F##Size[0] = Value1; \ |
| 4539 const uint32_t ImmIfTrue = 0xBEEF; \ |
| 4540 const uint32_t ImmIfFalse = 0xC0FFE; \ |
| 4541 \ |
| 4542 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4543 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfFalse)); \ |
| 4544 __ ucomiss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4545 dwordAddress(T1)); \ |
| 4546 Label Done; \ |
| 4547 __ j(Cond::Br_##BParity, &Done, NearBranch); \ |
| 4548 __ j(Cond::Br_##BOther, &Done, NearBranch); \ |
| 4549 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfTrue)); \ |
| 4550 __ bind(&Done); \ |
| 4551 \ |
| 4552 AssembledTest test = assemble(); \ |
| 4553 test.setDqwordTo(T0, test##Size##DstValue); \ |
| 4554 test.setDqwordTo(T1, test##Size##SrcValue); \ |
| 4555 test.run(); \ |
| 4556 \ |
| 4557 ASSERT_EQ(ImmIfTrue, test.eax()) << TestString; \ |
| 4558 reset(); \ |
| 4559 } while (0) |
| 4560 |
| 4561 #define TestImplCond(Dst, Value0, Src, Value1, Size, CompType, BParity, \ |
| 4562 BOther) \ |
| 4563 do { \ |
| 4564 TestImplXmmXmm(Dst, Value0, Src, Value1, Size, CompType, BParity, BOther); \ |
| 4565 TestImplXmmAddr(Dst, Value0, Value1, Size, CompType, BParity, BOther); \ |
| 4566 } while (0) |
| 4567 |
| 4568 #define TestImplSize(Dst, Src, Size) \ |
| 4569 do { \ |
| 4570 TestImplCond(Dst, 1.0, Src, 1.0, Size, isEq, p, ne); \ |
| 4571 TestImplCond(Dst, 1.0, Src, 2.0, Size, isNe, p, e); \ |
| 4572 TestImplCond(Dst, 1.0, Src, 2.0, Size, isLe, p, a); \ |
| 4573 TestImplCond(Dst, 1.0, Src, 1.0, Size, isLe, p, a); \ |
| 4574 TestImplCond(Dst, 1.0, Src, 2.0, Size, isLt, p, ae); \ |
| 4575 TestImplCond(Dst, 2.0, Src, 1.0, Size, isGe, p, b); \ |
| 4576 TestImplCond(Dst, 1.0, Src, 1.0, Size, isGe, p, b); \ |
| 4577 TestImplCond(Dst, 2.0, Src, 1.0, Size, isGt, p, be); \ |
| 4578 TestImplCond(Dst, qnan##Size, Src, 1.0, Size, isUnord, np, o); \ |
| 4579 TestImplCond(Dst, 1.0, Src, qnan##Size, Size, isUnord, np, s); \ |
| 4580 TestImplCond(Dst, qnan##Size, Src, qnan##Size, Size, isUnord, np, s); \ |
| 4581 } while (0) |
| 4582 |
| 4583 #define TestImpl(Dst, Src) \ |
| 4584 do { \ |
| 4585 TestImplSize(Dst, Src, 32); \ |
| 4586 TestImplSize(Dst, Src, 64); \ |
| 4587 } while (0) |
| 4588 |
| 4589 TestImpl(xmm0, xmm1); |
| 4590 TestImpl(xmm1, xmm2); |
| 4591 TestImpl(xmm2, xmm3); |
| 4592 TestImpl(xmm3, xmm4); |
| 4593 TestImpl(xmm4, xmm5); |
| 4594 TestImpl(xmm5, xmm6); |
| 4595 TestImpl(xmm6, xmm7); |
| 4596 TestImpl(xmm7, xmm0); |
| 4597 |
| 4598 #undef TestImpl |
| 4599 #undef TestImplSize |
| 4600 #undef TestImplCond |
| 4601 #undef TestImplXmmAddr |
| 4602 #undef TestImplXmmXmm |
| 4603 } |
| 4604 |
| 4605 TEST_F(AssemblerX8632Test, Movmsk) { |
| 4606 #define TestMovmskGPRXmm(GPR, Src, Value1, Expected, Inst) \ |
| 4607 do { \ |
| 4608 static constexpr char TestString[] = \ |
| 4609 "(" #GPR ", " #Src ", " #Value1 ", " #Expected ", " #Inst ")"; \ |
| 4610 const uint32_t T0 = allocateDqword(); \ |
| 4611 const Dqword V0 Value1; \ |
| 4612 \ |
| 4613 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 4614 __ Inst(GPRRegister::Encoded_Reg_##GPR, XmmRegister::Encoded_Reg_##Src); \ |
| 4615 \ |
| 4616 AssembledTest test = assemble(); \ |
| 4617 test.setDqwordTo(T0, V0); \ |
| 4618 test.run(); \ |
| 4619 \ |
| 4620 ASSERT_EQ(Expected, test.GPR()) << TestString; \ |
| 4621 reset(); \ |
| 4622 } while (0) |
| 4623 |
| 4624 #define TestMovmsk(GPR, Src) \ |
| 4625 do { \ |
| 4626 TestMovmskGPRXmm(GPR, Src, (-1.0, 1.0, -1.0, 1.0), 0x05ul, movmskps); \ |
| 4627 TestMovmskGPRXmm(GPR, Src, (1.0, -1.0), 0x02ul, movmskpd); \ |
| 4628 } while (0) |
| 4629 |
| 4630 TestMovmsk(eax, xmm0); |
| 4631 TestMovmsk(ebx, xmm1); |
| 4632 TestMovmsk(ecx, xmm2); |
| 4633 TestMovmsk(edx, xmm3); |
| 4634 TestMovmsk(esi, xmm4); |
| 4635 TestMovmsk(edi, xmm5); |
| 4636 TestMovmsk(eax, xmm6); |
| 4637 TestMovmsk(ebx, xmm7); |
| 4638 |
| 4639 #undef TestMovmskGPRXmm |
| 4640 #undef TestMovmsk |
| 4641 } |
| 4642 |
| 4643 TEST_F(AssemblerX8632Test, Sqrtss) { |
| 4644 Dqword test32SrcValue(-100.0, -100.0, -100.0, -100.0); |
| 4645 Dqword test32DstValue(-1.0, -1.0, -1.0, -1.0); |
| 4646 |
| 4647 Dqword test64SrcValue(-100.0, -100.0); |
| 4648 Dqword test64DstValue(-1.0, -1.0); |
| 4649 |
| 4650 #define TestSqrtssXmmXmm(Dst, Src, Value1, Result, Size) \ |
| 4651 do { \ |
| 4652 static constexpr char TestString[] = \ |
| 4653 "(" #Dst ", " #Src ", " #Value1 ", " #Result ", " #Size ")"; \ |
| 4654 const uint32_t T0 = allocateDqword(); \ |
| 4655 test##Size##SrcValue.F##Size[0] = Value1; \ |
| 4656 const uint32_t T1 = allocateDqword(); \ |
| 4657 \ |
| 4658 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 4659 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 4660 __ sqrtss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4661 XmmRegister::Encoded_Reg_##Src); \ |
| 4662 \ |
| 4663 AssembledTest test = assemble(); \ |
| 4664 test.setDqwordTo(T0, test##Size##SrcValue); \ |
| 4665 test.setDqwordTo(T1, test##Size##DstValue); \ |
| 4666 test.run(); \ |
| 4667 \ |
| 4668 Dqword Expected = test##Size##DstValue; \ |
| 4669 Expected.F##Size[0] = Result; \ |
| 4670 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 4671 reset(); \ |
| 4672 } while (0) |
| 4673 |
| 4674 #define TestSqrtssXmmAddr(Dst, Value1, Result, Size) \ |
| 4675 do { \ |
| 4676 static constexpr char TestString[] = \ |
| 4677 "(" #Dst ", Addr, " #Value1 ", " #Result ", " #Size ")"; \ |
| 4678 const uint32_t T0 = allocateDqword(); \ |
| 4679 test##Size##SrcValue.F##Size[0] = Value1; \ |
| 4680 const uint32_t T1 = allocateDqword(); \ |
| 4681 \ |
| 4682 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 4683 __ sqrtss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4684 dwordAddress(T0)); \ |
| 4685 \ |
| 4686 AssembledTest test = assemble(); \ |
| 4687 test.setDqwordTo(T0, test##Size##SrcValue); \ |
| 4688 test.setDqwordTo(T1, test##Size##DstValue); \ |
| 4689 test.run(); \ |
| 4690 \ |
| 4691 Dqword Expected = test##Size##DstValue; \ |
| 4692 Expected.F##Size[0] = Result; \ |
| 4693 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 4694 reset(); \ |
| 4695 } while (0) |
| 4696 |
| 4697 #define TestSqrtssSize(Dst, Src, Size) \ |
| 4698 do { \ |
| 4699 TestSqrtssXmmXmm(Dst, Src, 4.0, 2.0, Size); \ |
| 4700 TestSqrtssXmmAddr(Dst, 4.0, 2.0, Size); \ |
| 4701 TestSqrtssXmmXmm(Dst, Src, 9.0, 3.0, Size); \ |
| 4702 TestSqrtssXmmAddr(Dst, 9.0, 3.0, Size); \ |
| 4703 TestSqrtssXmmXmm(Dst, Src, 100.0, 10.0, Size); \ |
| 4704 TestSqrtssXmmAddr(Dst, 100.0, 10.0, Size); \ |
| 4705 } while (0) |
| 4706 |
| 4707 #define TestSqrtss(Dst, Src) \ |
| 4708 do { \ |
| 4709 TestSqrtssSize(Dst, Src, 32); \ |
| 4710 TestSqrtssSize(Dst, Src, 64); \ |
| 4711 } while (0) |
| 4712 |
| 4713 TestSqrtss(xmm0, xmm1); |
| 4714 TestSqrtss(xmm1, xmm2); |
| 4715 TestSqrtss(xmm2, xmm3); |
| 4716 TestSqrtss(xmm3, xmm4); |
| 4717 TestSqrtss(xmm4, xmm5); |
| 4718 TestSqrtss(xmm5, xmm6); |
| 4719 TestSqrtss(xmm6, xmm7); |
| 4720 TestSqrtss(xmm7, xmm0); |
| 4721 |
| 4722 #undef TestSqrtss |
| 4723 #undef TestSqrtssSize |
| 4724 #undef TestSqrtssXmmAddr |
| 4725 #undef TestSqrtssXmmXmm |
| 4726 } |
| 4727 |
| 4728 TEST_F(AssemblerX8632Test, Insertps) { |
| 4729 #define TestInsertpsXmmXmmImm(Dst, Value0, Src, Value1, Imm, Expected) \ |
| 4730 do { \ |
| 4731 static constexpr char TestString[] = \ |
| 4732 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Imm ", " #Expected \ |
| 4733 ")"; \ |
| 4734 const uint32_t T0 = allocateDqword(); \ |
| 4735 const Dqword V0 Value0; \ |
| 4736 const uint32_t T1 = allocateDqword(); \ |
| 4737 const Dqword V1 Value1; \ |
| 4738 \ |
| 4739 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4740 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 4741 __ insertps(IceType_v4f32, XmmRegister::Encoded_Reg_##Dst, \ |
| 4742 XmmRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 4743 \ |
| 4744 AssembledTest test = assemble(); \ |
| 4745 test.setDqwordTo(T0, V0); \ |
| 4746 test.setDqwordTo(T1, V1); \ |
| 4747 test.run(); \ |
| 4748 \ |
| 4749 ASSERT_EQ(Dqword Expected, test.Dst<Dqword>()) << TestString; \ |
| 4750 reset(); \ |
| 4751 } while (0) |
| 4752 |
| 4753 #define TestInsertpsXmmAddrImm(Dst, Value0, Value1, Imm, Expected) \ |
| 4754 do { \ |
| 4755 static constexpr char TestString[] = \ |
| 4756 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Imm ", " #Expected ")"; \ |
| 4757 const uint32_t T0 = allocateDqword(); \ |
| 4758 const Dqword V0 Value0; \ |
| 4759 const uint32_t T1 = allocateDqword(); \ |
| 4760 const Dqword V1 Value1; \ |
| 4761 \ |
| 4762 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4763 __ insertps(IceType_v4f32, XmmRegister::Encoded_Reg_##Dst, \ |
| 4764 dwordAddress(T1), Immediate(Imm)); \ |
| 4765 \ |
| 4766 AssembledTest test = assemble(); \ |
| 4767 test.setDqwordTo(T0, V0); \ |
| 4768 test.setDqwordTo(T1, V1); \ |
| 4769 test.run(); \ |
| 4770 \ |
| 4771 ASSERT_EQ(Dqword Expected, test.Dst<Dqword>()) << TestString; \ |
| 4772 reset(); \ |
| 4773 } while (0) |
| 4774 |
| 4775 #define TestInsertps(Dst, Src) \ |
| 4776 do { \ |
| 4777 TestInsertpsXmmXmmImm( \ |
| 4778 Dst, (uint64_t(-1), uint64_t(-1)), Src, \ |
| 4779 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ |
| 4780 0x99, \ |
| 4781 (uint64_t(0xDDDDDDDD00000000ull), uint64_t(0x00000000FFFFFFFFull))); \ |
| 4782 TestInsertpsXmmAddrImm( \ |
| 4783 Dst, (uint64_t(-1), uint64_t(-1)), \ |
| 4784 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ |
| 4785 0x99, \ |
| 4786 (uint64_t(0xBBBBBBBB00000000ull), uint64_t(0x00000000FFFFFFFFull))); \ |
| 4787 TestInsertpsXmmXmmImm( \ |
| 4788 Dst, (uint64_t(-1), uint64_t(-1)), Src, \ |
| 4789 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ |
| 4790 0x9D, \ |
| 4791 (uint64_t(0xDDDDDDDD00000000ull), uint64_t(0x0000000000000000ull))); \ |
| 4792 TestInsertpsXmmAddrImm( \ |
| 4793 Dst, (uint64_t(-1), uint64_t(-1)), \ |
| 4794 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ |
| 4795 0x9D, \ |
| 4796 (uint64_t(0xBBBBBBBB00000000ull), uint64_t(0x0000000000000000ull))); \ |
| 4797 } while (0) |
| 4798 |
| 4799 TestInsertps(xmm0, xmm1); |
| 4800 TestInsertps(xmm1, xmm2); |
| 4801 TestInsertps(xmm2, xmm3); |
| 4802 TestInsertps(xmm3, xmm4); |
| 4803 TestInsertps(xmm4, xmm5); |
| 4804 TestInsertps(xmm5, xmm6); |
| 4805 TestInsertps(xmm6, xmm7); |
| 4806 TestInsertps(xmm7, xmm0); |
| 4807 |
| 4808 #undef TestInsertps |
| 4809 #undef TestInsertpsXmmXmmAddr |
| 4810 #undef TestInsertpsXmmXmmImm |
| 4811 } |
| 4812 |
| 4813 TEST_F(AssemblerX8632Test, Pinsr) { |
| 4814 static constexpr uint8_t Mask32 = 0x03; |
| 4815 static constexpr uint8_t Mask16 = 0x07; |
| 4816 static constexpr uint8_t Mask8 = 0x0F; |
| 4817 |
| 4818 #define TestPinsrXmmGPRImm(Dst, Value0, GPR, Value1, Imm, Size) \ |
| 4819 do { \ |
| 4820 static constexpr char TestString[] = \ |
| 4821 "(" #Dst ", " #Value0 ", " #GPR ", " #Value1 ", " #Imm ", " #Size ")"; \ |
| 4822 const uint32_t T0 = allocateDqword(); \ |
| 4823 const Dqword V0 Value0; \ |
| 4824 \ |
| 4825 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4826 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, Immediate(Value1)); \ |
| 4827 __ pinsr(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4828 GPRRegister::Encoded_Reg_##GPR, Immediate(Imm)); \ |
| 4829 \ |
| 4830 AssembledTest test = assemble(); \ |
| 4831 test.setDqwordTo(T0, V0); \ |
| 4832 test.run(); \ |
| 4833 \ |
| 4834 constexpr uint8_t sel = (Imm)&Mask##Size; \ |
| 4835 Dqword Expected = V0; \ |
| 4836 Expected.U##Size[sel] = Value1; \ |
| 4837 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 4838 reset(); \ |
| 4839 } while (0) |
| 4840 |
| 4841 #define TestPinsrXmmAddrImm(Dst, Value0, Value1, Imm, Size) \ |
| 4842 do { \ |
| 4843 static constexpr char TestString[] = \ |
| 4844 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Imm ", " #Size ")"; \ |
| 4845 const uint32_t T0 = allocateDqword(); \ |
| 4846 const Dqword V0 Value0; \ |
| 4847 const uint32_t T1 = allocateDword(); \ |
| 4848 const uint32_t V1 = Value1; \ |
| 4849 \ |
| 4850 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 4851 __ pinsr(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 4852 dwordAddress(T1), Immediate(Imm)); \ |
| 4853 \ |
| 4854 AssembledTest test = assemble(); \ |
| 4855 test.setDqwordTo(T0, V0); \ |
| 4856 test.setDwordTo(T1, V1); \ |
| 4857 test.run(); \ |
| 4858 \ |
| 4859 constexpr uint8_t sel = (Imm)&Mask##Size; \ |
| 4860 Dqword Expected = V0; \ |
| 4861 Expected.U##Size[sel] = Value1; \ |
| 4862 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 4863 reset(); \ |
| 4864 } while (0) |
| 4865 |
| 4866 #define TestPinsrSize(Dst, GPR, Value1, Imm, Size) \ |
| 4867 do { \ |
| 4868 TestPinsrXmmGPRImm(Dst, (uint64_t(0xAAAAAAAABBBBBBBBull), \ |
| 4869 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ |
| 4870 GPR, Value1, Imm, Size); \ |
| 4871 TestPinsrXmmAddrImm(Dst, (uint64_t(0xAAAAAAAABBBBBBBBull), \ |
| 4872 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ |
| 4873 Value1, Imm, Size); \ |
| 4874 } while (0) |
| 4875 |
| 4876 #define TestPinsr(Src, Dst) \ |
| 4877 do { \ |
| 4878 TestPinsrSize(Src, Dst, 0xEE, 0x03, 8); \ |
| 4879 TestPinsrSize(Src, Dst, 0xFFEE, 0x03, 16); \ |
| 4880 TestPinsrSize(Src, Dst, 0xC0FFEE, 0x03, 32); \ |
| 4881 } while (0) |
| 4882 |
| 4883 TestPinsr(xmm0, eax); |
| 4884 TestPinsr(xmm1, ebx); |
| 4885 TestPinsr(xmm2, ecx); |
| 4886 TestPinsr(xmm3, edx); |
| 4887 TestPinsr(xmm4, esi); |
| 4888 TestPinsr(xmm5, edi); |
| 4889 TestPinsr(xmm6, eax); |
| 4890 TestPinsr(xmm7, ebx); |
| 4891 |
| 4892 #undef TestPinsr |
| 4893 #undef TestPinsrSize |
| 4894 #undef TestPinsrXmmAddrImm |
| 4895 #undef TestPinsrXmmGPRImm |
| 4896 } |
| 4897 |
| 4898 TEST_F(AssemblerX8632Test, Pextr) { |
| 4899 static constexpr uint8_t Mask32 = 0x03; |
| 4900 static constexpr uint8_t Mask16 = 0x07; |
| 4901 static constexpr uint8_t Mask8 = 0x0F; |
| 4902 |
| 4903 #define TestPextrGPRXmmImm(GPR, Src, Value1, Imm, Size) \ |
| 4904 do { \ |
| 4905 static constexpr char TestString[] = \ |
| 4906 "(" #GPR ", " #Src ", " #Value1 ", " #Imm ", " #Size ")"; \ |
| 4907 const uint32_t T0 = allocateDqword(); \ |
| 4908 const Dqword V0 Value1; \ |
| 4909 \ |
| 4910 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 4911 __ pextr(IceType_i##Size, GPRRegister::Encoded_Reg_##GPR, \ |
| 4912 XmmRegister::Encoded_Reg_##Src, Immediate(Imm)); \ |
| 4913 \ |
| 4914 AssembledTest test = assemble(); \ |
| 4915 test.setDqwordTo(T0, V0); \ |
| 4916 test.run(); \ |
| 4917 \ |
| 4918 constexpr uint8_t sel = (Imm)&Mask##Size; \ |
| 4919 ASSERT_EQ(V0.U##Size[sel], test.GPR()) << TestString; \ |
| 4920 reset(); \ |
| 4921 } while (0) |
| 4922 |
| 4923 #define TestPextrSize(GPR, Src, Value1, Imm, Size) \ |
| 4924 do { \ |
| 4925 TestPextrGPRXmmImm(GPR, Src, (uint64_t(0xAAAAAAAABBBBBBBBull), \ |
| 4926 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ |
| 4927 Imm, Size); \ |
| 4928 } while (0) |
| 4929 |
| 4930 #define TestPextr(Src, Dst) \ |
| 4931 do { \ |
| 4932 TestPextrSize(Src, Dst, 0xEE, 0x03, 8); \ |
| 4933 TestPextrSize(Src, Dst, 0xFFEE, 0x03, 16); \ |
| 4934 TestPextrSize(Src, Dst, 0xC0FFEE, 0x03, 32); \ |
| 4935 } while (0) |
| 4936 |
| 4937 TestPextr(eax, xmm0); |
| 4938 TestPextr(ebx, xmm1); |
| 4939 TestPextr(ecx, xmm2); |
| 4940 TestPextr(edx, xmm3); |
| 4941 TestPextr(esi, xmm4); |
| 4942 TestPextr(edi, xmm5); |
| 4943 TestPextr(eax, xmm6); |
| 4944 TestPextr(ebx, xmm7); |
| 4945 |
| 4946 #undef TestPextr |
| 4947 #undef TestPextrSize |
| 4948 #undef TestPextrXmmGPRImm |
| 4949 } |
| 4950 |
| 4951 TEST_F(AssemblerX8632Test, Pmovsxdq) { |
| 4952 #define TestPmovsxdqXmmXmm(Dst, Src, Value1) \ |
| 4953 do { \ |
| 4954 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Value1 ")"; \ |
| 4955 const uint32_t T0 = allocateDqword(); \ |
| 4956 const Dqword V0 Value1; \ |
| 4957 const uint32_t T1 = allocateDqword(); \ |
| 4958 const Dqword V1(uint64_t(0), uint64_t(0)); \ |
| 4959 \ |
| 4960 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ |
| 4961 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ |
| 4962 __ pmovsxdq(XmmRegister::Encoded_Reg_##Dst, \ |
| 4963 XmmRegister::Encoded_Reg_##Src); \ |
| 4964 \ |
| 4965 AssembledTest test = assemble(); \ |
| 4966 test.setDqwordTo(T0, V0); \ |
| 4967 test.setDqwordTo(T1, V1); \ |
| 4968 test.run(); \ |
| 4969 \ |
| 4970 const Dqword Expected(uint64_t(V0.I32[0]), uint64_t(V0.I32[1])); \ |
| 4971 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 4972 reset(); \ |
| 4973 } while (0) |
| 4974 |
| 4975 #define TestPmovsxdq(Dst, Src) \ |
| 4976 do { \ |
| 4977 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x700000007FFFFFFFull), \ |
| 4978 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ |
| 4979 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x800000007FFFFFFFull), \ |
| 4980 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ |
| 4981 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x70000000FFFFFFFFull), \ |
| 4982 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ |
| 4983 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x80000000FFFFFFFFull), \ |
| 4984 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ |
| 4985 } while (0) |
| 4986 |
| 4987 TestPmovsxdq(xmm0, xmm1); |
| 4988 TestPmovsxdq(xmm1, xmm2); |
| 4989 TestPmovsxdq(xmm2, xmm3); |
| 4990 TestPmovsxdq(xmm3, xmm4); |
| 4991 TestPmovsxdq(xmm4, xmm5); |
| 4992 TestPmovsxdq(xmm5, xmm6); |
| 4993 TestPmovsxdq(xmm6, xmm7); |
| 4994 TestPmovsxdq(xmm7, xmm0); |
| 4995 |
| 4996 #undef TestPmovsxdq |
| 4997 #undef TestPmovsxdqXmmXmm |
| 4998 } |
| 4999 |
| 5000 TEST_F(AssemblerX8632Test, Pcmpeq_Pcmpgt) { |
| 5001 #define TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, Inst, Op) \ |
| 5002 do { \ |
| 5003 static constexpr char TestString[] = \ |
| 5004 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ", " #Op ")"; \ |
| 5005 const uint32_t T0 = allocateDqword(); \ |
| 5006 const Dqword V0 Value0; \ |
| 5007 const uint32_t T1 = allocateDqword(); \ |
| 5008 const Dqword V1 Value1; \ |
| 5009 \ |
| 5010 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 5011 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 5012 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 5013 XmmRegister::Encoded_Reg_##Src); \ |
| 5014 \ |
| 5015 AssembledTest test = assemble(); \ |
| 5016 test.setDqwordTo(T0, V0); \ |
| 5017 test.setDqwordTo(T1, V1); \ |
| 5018 test.run(); \ |
| 5019 \ |
| 5020 Dqword Expected(uint64_t(0), uint64_t(0)); \ |
| 5021 static constexpr uint8_t ArraySize = \ |
| 5022 sizeof(Dqword) / sizeof(uint##Size##_t); \ |
| 5023 for (uint8_t i = 0; i < ArraySize; ++i) { \ |
| 5024 Expected.I##Size[i] = (V1.I##Size[i] Op V0.I##Size[i]) ? -1 : 0; \ |
| 5025 } \ |
| 5026 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 5027 reset(); \ |
| 5028 } while (0) |
| 5029 |
| 5030 #define TestPcmpXmmAddr(Dst, Value0, Value1, Size, Inst, Op) \ |
| 5031 do { \ |
| 5032 static constexpr char TestString[] = \ |
| 5033 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Size ", " #Op ")"; \ |
| 5034 const uint32_t T0 = allocateDqword(); \ |
| 5035 const Dqword V0 Value0; \ |
| 5036 const uint32_t T1 = allocateDqword(); \ |
| 5037 const Dqword V1 Value1; \ |
| 5038 \ |
| 5039 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 5040 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ |
| 5041 dwordAddress(T1)); \ |
| 5042 \ |
| 5043 AssembledTest test = assemble(); \ |
| 5044 test.setDqwordTo(T0, V0); \ |
| 5045 test.setDqwordTo(T1, V1); \ |
| 5046 test.run(); \ |
| 5047 \ |
| 5048 Dqword Expected(uint64_t(0), uint64_t(0)); \ |
| 5049 static constexpr uint8_t ArraySize = \ |
| 5050 sizeof(Dqword) / sizeof(uint##Size##_t); \ |
| 5051 for (uint8_t i = 0; i < ArraySize; ++i) { \ |
| 5052 Expected.I##Size[i] = (V1.I##Size[i] Op V0.I##Size[i]) ? -1 : 0; \ |
| 5053 } \ |
| 5054 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 5055 reset(); \ |
| 5056 } while (0) |
| 5057 |
| 5058 #define TestPcmpValues(Dst, Value0, Src, Value1, Size) \ |
| 5059 do { \ |
| 5060 TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, pcmpeq, == ); \ |
| 5061 TestPcmpXmmAddr(Dst, Value0, Value1, Size, pcmpeq, == ); \ |
| 5062 TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, pcmpgt, < ); \ |
| 5063 TestPcmpXmmAddr(Dst, Value0, Value1, Size, pcmpgt, < ); \ |
| 5064 } while (0) |
| 5065 |
| 5066 #define TestPcmpSize(Dst, Src, Size) \ |
| 5067 do { \ |
| 5068 TestPcmpValues(Dst, (uint64_t(0x8888888888888888ull), \ |
| 5069 uint64_t(0x0000000000000000ull)), \ |
| 5070 Src, (uint64_t(0x0000008800008800ull), \ |
| 5071 uint64_t(0xFFFFFFFFFFFFFFFFull)), \ |
| 5072 Size); \ |
| 5073 TestPcmpValues(Dst, (uint64_t(0x123567ABAB55DE01ull), \ |
| 5074 uint64_t(0x12345abcde12345Aull)), \ |
| 5075 Src, (uint64_t(0x0000008800008800ull), \ |
| 5076 uint64_t(0xAABBCCDD1234321Aull)), \ |
| 5077 Size); \ |
| 5078 } while (0) |
| 5079 |
| 5080 #define TestPcmp(Dst, Src) \ |
| 5081 do { \ |
| 5082 TestPcmpSize(xmm0, xmm1, 8); \ |
| 5083 TestPcmpSize(xmm0, xmm1, 16); \ |
| 5084 TestPcmpSize(xmm0, xmm1, 32); \ |
| 5085 } while (0) |
| 5086 |
| 5087 TestPcmp(xmm0, xmm1); |
| 5088 TestPcmp(xmm1, xmm2); |
| 5089 TestPcmp(xmm2, xmm3); |
| 5090 TestPcmp(xmm3, xmm4); |
| 5091 TestPcmp(xmm4, xmm5); |
| 5092 TestPcmp(xmm5, xmm6); |
| 5093 TestPcmp(xmm6, xmm7); |
| 5094 TestPcmp(xmm7, xmm0); |
| 5095 |
| 5096 #undef TestPcmp |
| 5097 #undef TestPcmpSize |
| 5098 #undef TestPcmpValues |
| 5099 #undef TestPcmpXmmAddr |
| 5100 #undef TestPcmpXmmXmm |
| 5101 } |
| 5102 |
| 5103 TEST_F(AssemblerX8632Test, Roundsd) { |
| 5104 #define TestRoundsdXmmXmm(Dst, Src, Mode, Input, RN) \ |
| 5105 do { \ |
| 5106 static constexpr char TestString[] = \ |
| 5107 "(" #Dst ", " #Src ", " #Mode ", " #Input ", " #RN ")"; \ |
| 5108 const uint32_t T0 = allocateDqword(); \ |
| 5109 const Dqword V0(-3.0, -3.0); \ |
| 5110 const uint32_t T1 = allocateDqword(); \ |
| 5111 const Dqword V1(double(Input), -123.4); \ |
| 5112 \ |
| 5113 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ |
| 5114 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ |
| 5115 __ roundsd(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ |
| 5116 AssemblerX8632::k##Mode); \ |
| 5117 \ |
| 5118 AssembledTest test = assemble(); \ |
| 5119 test.setDqwordTo(T0, V0); \ |
| 5120 test.setDqwordTo(T1, V1); \ |
| 5121 test.run(); \ |
| 5122 \ |
| 5123 const Dqword Expected(double(RN), -3.0); \ |
| 5124 EXPECT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ |
| 5125 reset(); \ |
| 5126 } while (0) |
| 5127 |
| 5128 #define TestRoundsd(Dst, Src) \ |
| 5129 do { \ |
| 5130 TestRoundsdXmmXmm(Dst, Src, RoundToNearest, 5.51, 6); \ |
| 5131 TestRoundsdXmmXmm(Dst, Src, RoundToNearest, 5.49, 5); \ |
| 5132 TestRoundsdXmmXmm(Dst, Src, RoundDown, 5.51, 5); \ |
| 5133 TestRoundsdXmmXmm(Dst, Src, RoundUp, 5.49, 6); \ |
| 5134 TestRoundsdXmmXmm(Dst, Src, RoundToZero, 5.49, 5); \ |
| 5135 TestRoundsdXmmXmm(Dst, Src, RoundToZero, 5.51, 5); \ |
| 5136 } while (0) |
| 5137 |
| 5138 TestRoundsd(xmm0, xmm1); |
| 5139 TestRoundsd(xmm1, xmm2); |
| 5140 TestRoundsd(xmm2, xmm3); |
| 5141 TestRoundsd(xmm3, xmm4); |
| 5142 TestRoundsd(xmm4, xmm5); |
| 5143 TestRoundsd(xmm5, xmm6); |
| 5144 TestRoundsd(xmm6, xmm7); |
| 5145 TestRoundsd(xmm7, xmm0); |
| 5146 |
| 5147 #undef TestRoundsd |
| 5148 #undef TestRoundsdXmmXmm |
| 5149 } |
| 5150 |
| 5151 TEST_F(AssemblerX8632Test, Test) { |
| 5152 static constexpr uint32_t Mask8 = 0xFF; |
| 5153 static constexpr uint32_t Mask16 = 0xFFFF; |
| 5154 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 5155 |
| 5156 #define TestImplRegReg(Dst, Value0, Src, Value1, Size) \ |
| 5157 do { \ |
| 5158 static constexpr bool NearJump = true; \ |
| 5159 static constexpr char TestString[] = \ |
| 5160 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ |
| 5161 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ |
| 5162 static constexpr uint32_t ValueIfFalse = 0x11111111; \ |
| 5163 \ |
| 5164 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5165 Immediate(Value0)); \ |
| 5166 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5167 Immediate(Value1)); \ |
| 5168 __ test(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5169 GPRRegister::Encoded_Reg_##Src); \ |
| 5170 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 5171 Immediate(ValueIfFalse)); \ |
| 5172 Label Done; \ |
| 5173 __ j(Cond::Br_e, &Done, NearJump); \ |
| 5174 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 5175 Immediate(ValueIfTrue)); \ |
| 5176 __ bind(&Done); \ |
| 5177 \ |
| 5178 AssembledTest test = assemble(); \ |
| 5179 test.run(); \ |
| 5180 \ |
| 5181 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ |
| 5182 : ValueIfFalse, \ |
| 5183 test.Dst()) \ |
| 5184 << TestString; \ |
| 5185 reset(); \ |
| 5186 } while (0) |
| 5187 |
| 5188 #define TestImplRegImm(Dst, Value0, Imm, Size) \ |
| 5189 do { \ |
| 5190 static constexpr bool NearJump = true; \ |
| 5191 static constexpr char TestString[] = \ |
| 5192 "(" #Dst ", " #Value0 ", " #Imm ", " #Size ")"; \ |
| 5193 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ |
| 5194 static constexpr uint32_t ValueIfFalse = 0x11111111; \ |
| 5195 \ |
| 5196 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5197 Immediate(Value0)); \ |
| 5198 __ test(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5199 Immediate((Imm)&Mask##Size)); \ |
| 5200 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 5201 Immediate(ValueIfFalse)); \ |
| 5202 Label Done; \ |
| 5203 __ j(Cond::Br_e, &Done, NearJump); \ |
| 5204 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ |
| 5205 Immediate(ValueIfTrue)); \ |
| 5206 __ bind(&Done); \ |
| 5207 \ |
| 5208 AssembledTest test = assemble(); \ |
| 5209 test.run(); \ |
| 5210 \ |
| 5211 ASSERT_EQ(((Value0)&Mask##Size) & ((Imm)&Mask##Size) ? ValueIfTrue \ |
| 5212 : ValueIfFalse, \ |
| 5213 test.Dst()) \ |
| 5214 << TestString; \ |
| 5215 reset(); \ |
| 5216 } while (0) |
| 5217 |
| 5218 #define TestImplAddrReg(Value0, Src, Value1, Size) \ |
| 5219 do { \ |
| 5220 static constexpr bool NearJump = true; \ |
| 5221 static constexpr char TestString[] = \ |
| 5222 "(Addr, " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ |
| 5223 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ |
| 5224 static constexpr uint32_t ValueIfFalse = 0x11111111; \ |
| 5225 const uint32_t T0 = allocateDword(); \ |
| 5226 \ |
| 5227 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5228 Immediate(Value1)); \ |
| 5229 __ test(IceType_i##Size, dwordAddress(T0), \ |
| 5230 GPRRegister::Encoded_Reg_##Src); \ |
| 5231 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfFalse)); \ |
| 5232 Label Done; \ |
| 5233 __ j(Cond::Br_e, &Done, NearJump); \ |
| 5234 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfTrue)); \ |
| 5235 __ bind(&Done); \ |
| 5236 \ |
| 5237 AssembledTest test = assemble(); \ |
| 5238 test.setDwordTo(T0, uint32_t(Value0)); \ |
| 5239 test.run(); \ |
| 5240 \ |
| 5241 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ |
| 5242 : ValueIfFalse, \ |
| 5243 test.contentsOfDword(T0)) \ |
| 5244 << TestString; \ |
| 5245 reset(); \ |
| 5246 } while (0) |
| 5247 |
| 5248 #define TestImplAddrImm(Value0, Value1, Size) \ |
| 5249 do { \ |
| 5250 static constexpr bool NearJump = true; \ |
| 5251 static constexpr char TestString[] = \ |
| 5252 "(Addr, " #Value0 ", " #Value1 ", " #Size ")"; \ |
| 5253 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ |
| 5254 static constexpr uint32_t ValueIfFalse = 0x11111111; \ |
| 5255 const uint32_t T0 = allocateDword(); \ |
| 5256 \ |
| 5257 __ test(IceType_i##Size, dwordAddress(T0), \ |
| 5258 Immediate((Value1)&Mask##Size)); \ |
| 5259 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfFalse)); \ |
| 5260 Label Done; \ |
| 5261 __ j(Cond::Br_e, &Done, NearJump); \ |
| 5262 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfTrue)); \ |
| 5263 __ bind(&Done); \ |
| 5264 \ |
| 5265 AssembledTest test = assemble(); \ |
| 5266 test.setDwordTo(T0, uint32_t(Value0)); \ |
| 5267 test.run(); \ |
| 5268 \ |
| 5269 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ |
| 5270 : ValueIfFalse, \ |
| 5271 test.contentsOfDword(T0)) \ |
| 5272 << TestString; \ |
| 5273 reset(); \ |
| 5274 } while (0) |
| 5275 |
| 5276 #define TestImplValues(Dst, Value0, Src, Value1, Size) \ |
| 5277 do { \ |
| 5278 TestImplRegReg(Dst, Value0, Src, Value1, Size); \ |
| 5279 TestImplRegImm(Dst, Value0, Value1, Size); \ |
| 5280 TestImplAddrReg(Value0, Src, Value1, Size); \ |
| 5281 TestImplAddrImm(Value0, Value1, Size); \ |
| 5282 } while (0) |
| 5283 |
| 5284 #define TestImplSize(Dst, Src, Size) \ |
| 5285 do { \ |
| 5286 TestImplValues(Dst, 0xF0F12101, Src, 0x00000000, Size); \ |
| 5287 TestImplValues(Dst, 0xF0000000, Src, 0xF0000000, Size); \ |
| 5288 TestImplValues(Dst, 0x0F00000F, Src, 0xF00000F0, Size); \ |
| 5289 } while (0) |
| 5290 |
| 5291 #define TestImpl(Dst, Src) \ |
| 5292 do { \ |
| 5293 TestImplSize(Dst, Src, 8); \ |
| 5294 TestImplSize(Dst, Src, 16); \ |
| 5295 TestImplSize(Dst, Src, 32); \ |
| 5296 } while (0) |
| 5297 |
| 5298 TestImpl(eax, ebx); |
| 5299 TestImpl(ebx, ecx); |
| 5300 TestImpl(ecx, edx); |
| 5301 TestImpl(edx, esi); |
| 5302 TestImpl(esi, edi); |
| 5303 TestImpl(edi, eax); |
| 5304 |
| 5305 #undef TestImpl |
| 5306 #undef TestImplSize |
| 5307 #undef TestImplValues |
| 5308 #undef TestImplAddrImm |
| 5309 #undef TestImplAddrReg |
| 5310 #undef TestImplRegImm |
| 5311 #undef TestImplRegReg |
| 5312 } |
| 5313 |
| 5314 // No mull/div because x86. |
| 5315 // No shift because x86. |
| 5316 TEST_F(AssemblerX8632Test, Arith_most) { |
| 5317 static constexpr uint32_t Mask8 = 0xFF; |
| 5318 static constexpr uint32_t Mask16 = 0xFFFF; |
| 5319 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 5320 |
| 5321 #define TestImplRegReg(Inst, Dst, Value0, Src, Value1, Type, Size, Op) \ |
| 5322 do { \ |
| 5323 static constexpr char TestString[] = \ |
| 5324 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 \ |
| 5325 ", " #Type #Size "_t, " #Op ")"; \ |
| 5326 \ |
| 5327 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5328 Immediate(Value0)); \ |
| 5329 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5330 Immediate(Value1)); \ |
| 5331 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5332 GPRRegister::Encoded_Reg_##Src); \ |
| 5333 \ |
| 5334 AssembledTest test = assemble(); \ |
| 5335 test.run(); \ |
| 5336 \ |
| 5337 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ |
| 5338 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ |
| 5339 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ |
| 5340 Mask##Size &test.Dst()) \ |
| 5341 << TestString; \ |
| 5342 reset(); \ |
| 5343 } while (0) |
| 5344 |
| 5345 #define TestImplRegAddr(Inst, Dst, Value0, Value1, Type, Size, Op) \ |
| 5346 do { \ |
| 5347 static constexpr char TestString[] = \ |
| 5348 "(" #Inst ", " #Dst ", " #Value0 ", Addr, " #Value1 ", " #Type #Size \ |
| 5349 "_t, " #Op ")"; \ |
| 5350 const uint32_t T0 = allocateDword(); \ |
| 5351 const uint32_t V0 = Value1; \ |
| 5352 \ |
| 5353 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5354 Immediate(Value0)); \ |
| 5355 __ mov(IceType_i##Size, dwordAddress(T0), Immediate(Value1)); \ |
| 5356 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5357 dwordAddress(T0)); \ |
| 5358 \ |
| 5359 AssembledTest test = assemble(); \ |
| 5360 test.setDwordTo(T0, V0); \ |
| 5361 test.run(); \ |
| 5362 \ |
| 5363 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ |
| 5364 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ |
| 5365 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ |
| 5366 Mask##Size &test.Dst()) \ |
| 5367 << TestString; \ |
| 5368 reset(); \ |
| 5369 } while (0) |
| 5370 |
| 5371 #define TestImplRegImm(Inst, Dst, Value0, Imm, Type, Size, Op) \ |
| 5372 do { \ |
| 5373 static constexpr char TestString[] = \ |
| 5374 "(" #Inst ", " #Dst ", " #Value0 ", Imm(" #Imm "), " #Type #Size \ |
| 5375 "_t, " #Op ")"; \ |
| 5376 \ |
| 5377 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5378 Immediate(Value0)); \ |
| 5379 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5380 Immediate((Imm)&Mask##Size)); \ |
| 5381 \ |
| 5382 AssembledTest test = assemble(); \ |
| 5383 test.run(); \ |
| 5384 \ |
| 5385 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ |
| 5386 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ |
| 5387 Op static_cast<Type##Size##_t>((Imm)&Mask##Size)), \ |
| 5388 Mask##Size &test.Dst()) \ |
| 5389 << TestString; \ |
| 5390 reset(); \ |
| 5391 } while (0) |
| 5392 |
| 5393 #define TestImplAddrReg(Inst, Value0, Src, Value1, Type, Size, Op) \ |
| 5394 do { \ |
| 5395 static constexpr char TestString[] = \ |
| 5396 "(" #Inst ", Addr, " #Value0 ", " #Src ", " #Value1 ", " #Type #Size \ |
| 5397 "_t, " #Op ")"; \ |
| 5398 const uint32_t T0 = allocateDword(); \ |
| 5399 const uint32_t V0 = Value0; \ |
| 5400 \ |
| 5401 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5402 Immediate(Value1)); \ |
| 5403 __ Inst(IceType_i##Size, dwordAddress(T0), \ |
| 5404 GPRRegister::Encoded_Reg_##Src); \ |
| 5405 \ |
| 5406 AssembledTest test = assemble(); \ |
| 5407 test.setDwordTo(T0, V0); \ |
| 5408 test.run(); \ |
| 5409 \ |
| 5410 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ |
| 5411 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ |
| 5412 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ |
| 5413 Mask##Size &test.contentsOfDword(T0)) \ |
| 5414 << TestString; \ |
| 5415 reset(); \ |
| 5416 } while (0) |
| 5417 |
| 5418 #define TestImplAddrImm(Inst, Value0, Imm, Type, Size, Op) \ |
| 5419 do { \ |
| 5420 static constexpr char TestString[] = \ |
| 5421 "(" #Inst ", Addr, " #Value0 ", Imm, " #Imm ", " #Type #Size \ |
| 5422 "_t, " #Op ")"; \ |
| 5423 const uint32_t T0 = allocateDword(); \ |
| 5424 const uint32_t V0 = Value0; \ |
| 5425 \ |
| 5426 __ Inst(IceType_i##Size, dwordAddress(T0), Immediate((Imm)&Mask##Size)); \ |
| 5427 \ |
| 5428 AssembledTest test = assemble(); \ |
| 5429 test.setDwordTo(T0, V0); \ |
| 5430 test.run(); \ |
| 5431 \ |
| 5432 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ |
| 5433 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ |
| 5434 Op static_cast<Type##Size##_t>((Imm)&Mask##Size)), \ |
| 5435 Mask##Size &test.contentsOfDword(T0)) \ |
| 5436 << TestString; \ |
| 5437 reset(); \ |
| 5438 } while (0) |
| 5439 |
| 5440 #define TestImplOp(Inst, Dst, Value0, Src, Value1, Type, Size, Op) \ |
| 5441 do { \ |
| 5442 TestImplRegReg(Inst, Dst, Value0, Src, Value1, Type, Size, Op); \ |
| 5443 TestImplRegAddr(Inst, Dst, Value0, Value1, Type, Size, Op); \ |
| 5444 TestImplRegImm(Inst, Dst, Value0, Value1, Type, Size, Op); \ |
| 5445 TestImplAddrReg(Inst, Value0, Src, Value1, Type, Size, Op); \ |
| 5446 TestImplAddrImm(Inst, Value0, Value1, Type, Size, Op); \ |
| 5447 } while (0) |
| 5448 |
| 5449 #define TestImplValues(Dst, Value0, Src, Value1, Size) \ |
| 5450 do { \ |
| 5451 TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \ |
| 5452 TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \ |
| 5453 TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, | ); \ |
| 5454 TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, | ); \ |
| 5455 TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \ |
| 5456 TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \ |
| 5457 TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \ |
| 5458 TestImplOp(add, Dst, Value0, Src, Value1, uint, Size, +); \ |
| 5459 TestImplOp(sub, Dst, Value0, Src, Value1, int, Size, -); \ |
| 5460 TestImplOp(sub, Dst, Value0, Src, Value1, uint, Size, -); \ |
| 5461 } while (0) |
| 5462 |
| 5463 #define TestImplSize(Dst, Src, Size) \ |
| 5464 do { \ |
| 5465 TestImplValues(Dst, 0xF0F12101, Src, 0x00000000, Size); \ |
| 5466 TestImplValues(Dst, 0xF0000000, Src, 0xF0000000, Size); \ |
| 5467 TestImplValues(Dst, 0x0F00000F, Src, 0xF0000070, Size); \ |
| 5468 TestImplValues(Dst, 0x0F00F00F, Src, 0xF000F070, Size); \ |
| 5469 } while (0) |
| 5470 |
| 5471 #define TestImpl(Dst, Src) \ |
| 5472 do { \ |
| 5473 if (GPRRegister::Encoded_Reg_##Src <= 3 && \ |
| 5474 GPRRegister::Encoded_Reg_##Dst <= 3) { \ |
| 5475 TestImplSize(Dst, Src, 8); \ |
| 5476 } \ |
| 5477 TestImplSize(Dst, Src, 16); \ |
| 5478 TestImplSize(Dst, Src, 32); \ |
| 5479 } while (0) |
| 5480 |
| 5481 TestImpl(eax, ebx); |
| 5482 TestImpl(ebx, ecx); |
| 5483 TestImpl(ecx, edx); |
| 5484 TestImpl(edx, esi); |
| 5485 TestImpl(esi, edi); |
| 5486 TestImpl(edi, eax); |
| 5487 |
| 5488 #undef TestImpl |
| 5489 #undef TestImplSize |
| 5490 #undef TestImplValues |
| 5491 #undef TestImplOp |
| 5492 #undef TestImplAddrImm |
| 5493 #undef TestImplAddrReg |
| 5494 #undef TestImplRegImm |
| 5495 #undef TestImplRegAddr |
| 5496 #undef TestImplRegReg |
| 5497 } |
| 5498 |
| 5499 TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { |
| 5500 const uint32_t Mask8 = 0x000000FF; |
| 5501 const uint32_t Mask16 = 0x0000FFFF; |
| 5502 const uint32_t Mask32 = 0xFFFFFFFF; |
| 5503 |
| 5504 const uint64_t ResultMask8 = 0x000000000000FFFFull; |
| 5505 const uint64_t ResultMask16 = 0x00000000FFFFFFFFull; |
| 5506 const uint64_t ResultMask32 = 0xFFFFFFFFFFFFFFFFull; |
| 5507 |
| 5508 #define TestImplRegReg(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, \ |
| 5509 Op, Size) \ |
| 5510 do { \ |
| 5511 static_assert(Size == 8 || Size == 16 || Size == 32, \ |
| 5512 "Invalid size " #Size); \ |
| 5513 static constexpr char TestString[] = \ |
| 5514 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 ", " #Src0 \ |
| 5515 ", " #Src1 ", " #Value1 ", " #Op ", " #Size ")"; \ |
| 5516 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5517 Immediate(uint64_t(Value0) & Mask##Size)); \ |
| 5518 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5519 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ |
| 5520 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src0, \ |
| 5521 Immediate(uint64_t(Value1) & Mask##Size)); \ |
| 5522 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src1, \ |
| 5523 Immediate((uint64_t(Value1) >> Size) & Mask##Size)); \ |
| 5524 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5525 GPRRegister::Encoded_Reg_##Src0); \ |
| 5526 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5527 GPRRegister::Encoded_Reg_##Src1); \ |
| 5528 \ |
| 5529 AssembledTest test = assemble(); \ |
| 5530 test.run(); \ |
| 5531 \ |
| 5532 static constexpr uint64_t Result = \ |
| 5533 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ |
| 5534 ResultMask##Size); \ |
| 5535 static constexpr uint32_t Expected0 = Result & Mask##Size; \ |
| 5536 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ |
| 5537 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ |
| 5538 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ |
| 5539 reset(); \ |
| 5540 } while (0) |
| 5541 |
| 5542 #define TestImplRegAddr(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size) \ |
| 5543 do { \ |
| 5544 static_assert(Size == 8 || Size == 16 || Size == 32, \ |
| 5545 "Invalid size " #Size); \ |
| 5546 static constexpr char TestString[] = \ |
| 5547 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 \ |
| 5548 ", Addr, " #Value1 ", " #Op ", " #Size ")"; \ |
| 5549 const uint32_t T0 = allocateDword(); \ |
| 5550 const uint32_t V0 = uint64_t(Value1) & Mask##Size; \ |
| 5551 const uint32_t T1 = allocateDword(); \ |
| 5552 const uint32_t V1 = (uint64_t(Value1) >> Size) & Mask##Size; \ |
| 5553 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5554 Immediate(uint64_t(Value0) & Mask##Size)); \ |
| 5555 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5556 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ |
| 5557 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5558 dwordAddress(T0)); \ |
| 5559 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5560 dwordAddress(T1)); \ |
| 5561 \ |
| 5562 AssembledTest test = assemble(); \ |
| 5563 test.setDwordTo(T0, V0); \ |
| 5564 test.setDwordTo(T1, V1); \ |
| 5565 test.run(); \ |
| 5566 \ |
| 5567 static constexpr uint64_t Result = \ |
| 5568 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ |
| 5569 ResultMask##Size); \ |
| 5570 static constexpr uint32_t Expected0 = Result & Mask##Size; \ |
| 5571 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ |
| 5572 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ |
| 5573 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ |
| 5574 reset(); \ |
| 5575 } while (0) |
| 5576 |
| 5577 #define TestImplRegImm(Inst0, Inst1, Dst0, Dst1, Value0, Imm, Op, Size) \ |
| 5578 do { \ |
| 5579 static_assert(Size == 8 || Size == 16 || Size == 32, \ |
| 5580 "Invalid size " #Size); \ |
| 5581 static constexpr char TestString[] = \ |
| 5582 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 \ |
| 5583 ", Imm(" #Imm "), " #Op ", " #Size ")"; \ |
| 5584 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5585 Immediate(uint64_t(Value0) & Mask##Size)); \ |
| 5586 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5587 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ |
| 5588 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ |
| 5589 Immediate(uint64_t(Imm) & Mask##Size)); \ |
| 5590 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 5591 Immediate((uint64_t(Imm) >> Size) & Mask##Size)); \ |
| 5592 \ |
| 5593 AssembledTest test = assemble(); \ |
| 5594 test.run(); \ |
| 5595 \ |
| 5596 static constexpr uint64_t Result = \ |
| 5597 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ |
| 5598 ResultMask##Size); \ |
| 5599 static constexpr uint32_t Expected0 = Result & Mask##Size; \ |
| 5600 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ |
| 5601 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ |
| 5602 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ |
| 5603 reset(); \ |
| 5604 } while (0) |
| 5605 |
| 5606 #define TestImplAddrReg(Inst0, Inst1, Value0, Src0, Src1, Value1, Op, Size) \ |
| 5607 do { \ |
| 5608 static_assert(Size == 8 || Size == 16 || Size == 32, \ |
| 5609 "Invalid size " #Size); \ |
| 5610 static constexpr char TestString[] = \ |
| 5611 "(" #Inst0 ", " #Inst1 ", Addr, " #Value0 ", " #Src0 ", " #Src1 \ |
| 5612 ", " #Value1 ", " #Op ", " #Size ")"; \ |
| 5613 const uint32_t T0 = allocateDword(); \ |
| 5614 const uint32_t V0 = uint64_t(Value0) & Mask##Size; \ |
| 5615 const uint32_t T1 = allocateDword(); \ |
| 5616 const uint32_t V1 = (uint64_t(Value0) >> Size) & Mask##Size; \ |
| 5617 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src0, \ |
| 5618 Immediate(uint64_t(Value1) & Mask##Size)); \ |
| 5619 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src1, \ |
| 5620 Immediate((uint64_t(Value1) >> Size) & Mask##Size)); \ |
| 5621 __ Inst0(IceType_i##Size, dwordAddress(T0), \ |
| 5622 GPRRegister::Encoded_Reg_##Src0); \ |
| 5623 __ Inst1(IceType_i##Size, dwordAddress(T1), \ |
| 5624 GPRRegister::Encoded_Reg_##Src1); \ |
| 5625 \ |
| 5626 AssembledTest test = assemble(); \ |
| 5627 test.setDwordTo(T0, V0); \ |
| 5628 test.setDwordTo(T1, V1); \ |
| 5629 test.run(); \ |
| 5630 \ |
| 5631 static constexpr uint64_t Result = \ |
| 5632 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ |
| 5633 ResultMask##Size); \ |
| 5634 static constexpr uint32_t Expected0 = Result & Mask##Size; \ |
| 5635 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ |
| 5636 ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ |
| 5637 ASSERT_EQ(Expected1, test.contentsOfDword(T1)) << TestString << ": 1"; \ |
| 5638 reset(); \ |
| 5639 } while (0) |
| 5640 |
| 5641 #define TestImplAddrImm(Inst0, Inst1, Value0, Imm, Op, Size) \ |
| 5642 do { \ |
| 5643 static_assert(Size == 8 || Size == 16 || Size == 32, \ |
| 5644 "Invalid size " #Size); \ |
| 5645 static constexpr char TestString[] = \ |
| 5646 "(" #Inst0 ", " #Inst1 ", Addr, " #Value0 ", Imm(" #Imm "), " #Op \ |
| 5647 ", " #Size ")"; \ |
| 5648 const uint32_t T0 = allocateDword(); \ |
| 5649 const uint32_t V0 = uint64_t(Value0) & Mask##Size; \ |
| 5650 const uint32_t T1 = allocateDword(); \ |
| 5651 const uint32_t V1 = (uint64_t(Value0) >> Size) & Mask##Size; \ |
| 5652 __ Inst0(IceType_i##Size, dwordAddress(T0), \ |
| 5653 Immediate(uint64_t(Imm) & Mask##Size)); \ |
| 5654 __ Inst1(IceType_i##Size, dwordAddress(T1), \ |
| 5655 Immediate((uint64_t(Imm) >> Size) & Mask##Size)); \ |
| 5656 \ |
| 5657 AssembledTest test = assemble(); \ |
| 5658 test.setDwordTo(T0, V0); \ |
| 5659 test.setDwordTo(T1, V1); \ |
| 5660 test.run(); \ |
| 5661 \ |
| 5662 static constexpr uint64_t Result = \ |
| 5663 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ |
| 5664 ResultMask##Size); \ |
| 5665 static constexpr uint32_t Expected0 = Result & Mask##Size; \ |
| 5666 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ |
| 5667 ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ |
| 5668 ASSERT_EQ(Expected1, test.contentsOfDword(T1)) << TestString << ": 1"; \ |
| 5669 reset(); \ |
| 5670 } while (0) |
| 5671 |
| 5672 #define TestImplOp(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, Op, \ |
| 5673 Size) \ |
| 5674 do { \ |
| 5675 TestImplRegReg(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, Op, \ |
| 5676 Size); \ |
| 5677 TestImplRegAddr(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size); \ |
| 5678 TestImplRegImm(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size); \ |
| 5679 TestImplAddrReg(Inst0, Inst1, Value0, Src0, Src1, Value1, Op, Size); \ |
| 5680 TestImplAddrImm(Inst0, Inst1, Value0, Value1, Op, Size); \ |
| 5681 } while (0) |
| 5682 |
| 5683 #define TestImplValues(Dst0, Dst1, Value0, Src0, Src1, Value1, Size) \ |
| 5684 do { \ |
| 5685 TestImplOp(add, adc, Dst0, Dst1, Value0, Src0, Src1, Value1, +, Size); \ |
| 5686 TestImplOp(sub, sbb, Dst0, Dst1, Value0, Src0, Src1, Value1, -, Size); \ |
| 5687 } while (0) |
| 5688 |
| 5689 #define TestImplSize(Dst0, Dst1, Src0, Src1, Size) \ |
| 5690 do { \ |
| 5691 TestImplValues(Dst0, Dst1, 0xFFFFFFFFFFFFFF00ull, Src0, Src1, \ |
| 5692 0xFFFFFFFF0000017Full, Size); \ |
| 5693 } while (0) |
| 5694 |
| 5695 #define TestImpl(Dst0, Dst1, Src0, Src1) \ |
| 5696 do { \ |
| 5697 if (GPRRegister::Encoded_Reg_##Dst0 <= 3 && \ |
| 5698 GPRRegister::Encoded_Reg_##Dst1 <= 3 && \ |
| 5699 GPRRegister::Encoded_Reg_##Src0 <= 3 && \ |
| 5700 GPRRegister::Encoded_Reg_##Src1 <= 3) { \ |
| 5701 TestImplSize(Dst0, Dst1, Src0, Src1, 8); \ |
| 5702 } \ |
| 5703 TestImplSize(Dst0, Dst1, Src0, Src1, 16); \ |
| 5704 TestImplSize(Dst0, Dst1, Src0, Src1, 32); \ |
| 5705 } while (0) |
| 5706 |
| 5707 TestImpl(eax, ebx, ecx, edx); |
| 5708 TestImpl(ebx, ecx, edx, esi); |
| 5709 TestImpl(ecx, edx, esi, edi); |
| 5710 TestImpl(edx, esi, edi, eax); |
| 5711 TestImpl(esi, edi, eax, ebx); |
| 5712 TestImpl(edi, eax, ebx, ecx); |
| 5713 |
| 5714 #undef TestImpl |
| 5715 #undef TestImplSize |
| 5716 #undef TestImplValues |
| 5717 #undef TestImplOp |
| 5718 #undef TestImplAddrImm |
| 5719 #undef TestImplAddrReg |
| 5720 #undef TestImplRegImm |
| 5721 #undef TestImplRegAddr |
| 5722 #undef TestImplRegReg |
| 5723 } |
| 5724 |
| 5725 TEST_F(AssemblerX8632LowLevelTest, Cbw_Cwd_Cdq) { |
| 5726 #define TestImpl(Inst, BytesSize, ...) \ |
| 5727 do { \ |
| 5728 __ Inst(); \ |
| 5729 ASSERT_EQ(BytesSize, codeBytesSize()) << #Inst; \ |
| 5730 verifyBytes<BytesSize>(codeBytes(), __VA_ARGS__); \ |
| 5731 reset(); \ |
| 5732 } while (0) |
| 5733 |
| 5734 TestImpl(cbw, 2u, 0x66, 0x98); |
| 5735 TestImpl(cwd, 2u, 0x66, 0x99); |
| 5736 TestImpl(cdq, 1u, 0x99); |
| 5737 |
| 5738 #undef TestImpl |
| 5739 } |
| 5740 |
| 5741 TEST_F(AssemblerX8632Test, SingleOperandMul) { |
| 5742 static constexpr uint32_t Mask8 = 0x000000FF; |
| 5743 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 5744 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 5745 |
| 5746 #define TestImplReg(Inst, Value0, Src, Value1, Type, Size) \ |
| 5747 do { \ |
| 5748 static_assert(GPRRegister::Encoded_Reg_eax != \ |
| 5749 GPRRegister::Encoded_Reg_##Src, \ |
| 5750 "eax can not be src1."); \ |
| 5751 \ |
| 5752 static constexpr char TestString[] = \ |
| 5753 "(" #Inst ", " #Value0 ", " #Src ", " #Value1 ", " #Type ", " #Size \ |
| 5754 ")"; \ |
| 5755 static constexpr Type##64_t OperandEax = \ |
| 5756 static_cast<Type##Size##_t>((Value0)&Mask##Size); \ |
| 5757 static constexpr Type##64_t OperandOther = \ |
| 5758 static_cast<Type##Size##_t>((Value1)&Mask##Size); \ |
| 5759 static constexpr uint32_t ExpectedEax = \ |
| 5760 Mask##Size & (OperandEax * OperandOther); \ |
| 5761 static constexpr uint32_t ExpectedEdx = \ |
| 5762 Mask##Size & ((OperandEax * OperandOther) >> Size); \ |
| 5763 \ |
| 5764 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 5765 Immediate((Value0)&Mask##Size)); \ |
| 5766 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5767 Immediate((Value1)&Mask##Size)); \ |
| 5768 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Src); \ |
| 5769 \ |
| 5770 if (Size == 8) { \ |
| 5771 /* mov %ah, %dl */ \ |
| 5772 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 5773 GPRRegister::Encoded_Reg_esp); \ |
| 5774 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 5775 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ |
| 5776 /* src == dh; clear dx's upper 8 bits. */ \ |
| 5777 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ |
| 5778 } \ |
| 5779 } \ |
| 5780 \ |
| 5781 AssembledTest test = assemble(); \ |
| 5782 test.run(); \ |
| 5783 \ |
| 5784 ASSERT_EQ(ExpectedEax, test.eax()) << TestString; \ |
| 5785 ASSERT_EQ(ExpectedEdx, test.edx()) << TestString; \ |
| 5786 reset(); \ |
| 5787 } while (0) |
| 5788 |
| 5789 #define TestImplAddr(Inst, Value0, Value1, Type, Size) \ |
| 5790 do { \ |
| 5791 static constexpr char TestString[] = \ |
| 5792 "(" #Inst ", " #Value0 ", Addr, " #Value1 ", " #Type ", " #Size ")"; \ |
| 5793 static const uint32_t T0 = allocateDword(); \ |
| 5794 static constexpr uint32_t V0 = Value1; \ |
| 5795 static constexpr Type##64_t OperandEax = \ |
| 5796 static_cast<Type##Size##_t>((Value0)&Mask##Size); \ |
| 5797 static constexpr Type##64_t OperandOther = \ |
| 5798 static_cast<Type##Size##_t>((Value1)&Mask##Size); \ |
| 5799 static constexpr uint32_t ExpectedEax = \ |
| 5800 Mask##Size & (OperandEax * OperandOther); \ |
| 5801 static constexpr uint32_t ExpectedEdx = \ |
| 5802 Mask##Size & ((OperandEax * OperandOther) >> Size); \ |
| 5803 \ |
| 5804 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 5805 Immediate((Value0)&Mask##Size)); \ |
| 5806 __ Inst(IceType_i##Size, dwordAddress(T0)); \ |
| 5807 \ |
| 5808 if (Size == 8) { \ |
| 5809 /* mov %ah, %dl */ \ |
| 5810 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 5811 GPRRegister::Encoded_Reg_esp); \ |
| 5812 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 5813 } \ |
| 5814 \ |
| 5815 AssembledTest test = assemble(); \ |
| 5816 test.setDwordTo(T0, V0); \ |
| 5817 test.run(); \ |
| 5818 \ |
| 5819 ASSERT_EQ(ExpectedEax, test.eax()) << TestString; \ |
| 5820 ASSERT_EQ(ExpectedEdx, test.edx()) << TestString; \ |
| 5821 reset(); \ |
| 5822 } while (0) |
| 5823 |
| 5824 #define TestImplOp(Inst, Value0, Src, Value1, Type, Size) \ |
| 5825 do { \ |
| 5826 TestImplReg(Inst, Value0, Src, Value1, Type, Size); \ |
| 5827 TestImplAddr(Inst, Value0, Value1, Type, Size); \ |
| 5828 } while (0) |
| 5829 |
| 5830 #define TestImplValue(Value0, Src, Value1, Size) \ |
| 5831 do { \ |
| 5832 TestImplOp(mul, Value0, Src, Value1, uint, Size); \ |
| 5833 TestImplOp(imul, Value0, Src, Value1, int, Size); \ |
| 5834 } while (0) |
| 5835 |
| 5836 #define TestImplSize(Src, Size) \ |
| 5837 do { \ |
| 5838 TestImplValue(10, Src, 1, Size); \ |
| 5839 TestImplValue(10, Src, -1, Size); \ |
| 5840 TestImplValue(-10, Src, 37, Size); \ |
| 5841 TestImplValue(-10, Src, -15, Size); \ |
| 5842 } while (0) |
| 5843 |
| 5844 #define TestImpl(Src) \ |
| 5845 do { \ |
| 5846 TestImplSize(Src, 8); \ |
| 5847 TestImplSize(Src, 16); \ |
| 5848 TestImplSize(Src, 32); \ |
| 5849 } while (0) |
| 5850 |
| 5851 TestImpl(ebx); |
| 5852 TestImpl(ecx); |
| 5853 TestImpl(edx); |
| 5854 TestImpl(esi); |
| 5855 TestImpl(edi); |
| 5856 |
| 5857 #undef TestImpl |
| 5858 #undef TestImplSize |
| 5859 #undef TestImplValue |
| 5860 #undef TestImplOp |
| 5861 #undef TestImplAddr |
| 5862 #undef TestImplReg |
| 5863 } |
| 5864 |
| 5865 TEST_F(AssemblerX8632Test, TwoOperandImul) { |
| 5866 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 5867 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 5868 |
| 5869 #define TestImplRegReg(Dst, Value0, Src, Value1, Size) \ |
| 5870 do { \ |
| 5871 static constexpr char TestString[] = \ |
| 5872 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ |
| 5873 static constexpr int64_t Operand0 = \ |
| 5874 static_cast<int##Size##_t>((Value0)&Mask##Size); \ |
| 5875 static constexpr int64_t Operand1 = \ |
| 5876 static_cast<int##Size##_t>((Value1)&Mask##Size); \ |
| 5877 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ |
| 5878 \ |
| 5879 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5880 Immediate((Value0)&Mask##Size)); \ |
| 5881 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 5882 Immediate((Value1)&Mask##Size)); \ |
| 5883 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5884 GPRRegister::Encoded_Reg_##Src); \ |
| 5885 \ |
| 5886 if (Size == 8) { \ |
| 5887 /* mov %ah, %dl */ \ |
| 5888 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 5889 GPRRegister::Encoded_Reg_esp); \ |
| 5890 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 5891 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ |
| 5892 /* src == dh; clear dx's upper 8 bits. */ \ |
| 5893 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ |
| 5894 } \ |
| 5895 } \ |
| 5896 \ |
| 5897 AssembledTest test = assemble(); \ |
| 5898 test.run(); \ |
| 5899 \ |
| 5900 ASSERT_EQ(Expected, test.Dst()) << TestString; \ |
| 5901 reset(); \ |
| 5902 } while (0) |
| 5903 |
| 5904 #define TestImplRegImm(Dst, Value0, Imm, Size) \ |
| 5905 do { \ |
| 5906 static constexpr char TestString[] = \ |
| 5907 "(" #Dst ", " #Value0 ", Imm(" #Imm "), " #Size ")"; \ |
| 5908 static constexpr int64_t Operand0 = \ |
| 5909 static_cast<int##Size##_t>((Value0)&Mask##Size); \ |
| 5910 static constexpr int64_t Operand1 = \ |
| 5911 static_cast<int##Size##_t>((Imm)&Mask##Size); \ |
| 5912 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ |
| 5913 \ |
| 5914 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5915 Immediate((Value0)&Mask##Size)); \ |
| 5916 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, Immediate(Imm)); \ |
| 5917 \ |
| 5918 if (Size == 8) { \ |
| 5919 /* mov %ah, %dl */ \ |
| 5920 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 5921 GPRRegister::Encoded_Reg_esp); \ |
| 5922 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 5923 } \ |
| 5924 \ |
| 5925 AssembledTest test = assemble(); \ |
| 5926 test.run(); \ |
| 5927 \ |
| 5928 ASSERT_EQ(Expected, test.Dst()) << TestString; \ |
| 5929 reset(); \ |
| 5930 } while (0) |
| 5931 |
| 5932 #define TestImplRegAddr(Dst, Value0, Value1, Size) \ |
| 5933 do { \ |
| 5934 static constexpr char TestString[] = \ |
| 5935 "(" #Dst ", " #Value0 ", Addr," #Value1 ", " #Size ")"; \ |
| 5936 static constexpr int64_t Operand0 = \ |
| 5937 static_cast<int##Size##_t>((Value0)&Mask##Size); \ |
| 5938 static constexpr int64_t Operand1 = \ |
| 5939 static_cast<int##Size##_t>((Value1)&Mask##Size); \ |
| 5940 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ |
| 5941 const uint32_t T0 = allocateDword(); \ |
| 5942 \ |
| 5943 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5944 Immediate((Value0)&Mask##Size)); \ |
| 5945 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 5946 dwordAddress(T0)); \ |
| 5947 \ |
| 5948 if (Size == 8) { \ |
| 5949 /* mov %ah, %dl */ \ |
| 5950 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 5951 GPRRegister::Encoded_Reg_esp); \ |
| 5952 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 5953 } \ |
| 5954 \ |
| 5955 AssembledTest test = assemble(); \ |
| 5956 test.setDwordTo(T0, static_cast<uint32_t>(Operand1)); \ |
| 5957 test.run(); \ |
| 5958 \ |
| 5959 ASSERT_EQ(Expected, test.Dst()) << TestString; \ |
| 5960 reset(); \ |
| 5961 } while (0) |
| 5962 |
| 5963 #define TestImplValue(Dst, Value0, Src, Value1, Size) \ |
| 5964 do { \ |
| 5965 TestImplRegReg(Dst, Value0, Src, Value1, Size); \ |
| 5966 TestImplRegImm(Dst, Value0, Value1, Size); \ |
| 5967 TestImplRegAddr(Dst, Value0, Value1, Size); \ |
| 5968 } while (0) |
| 5969 |
| 5970 #define TestImplSize(Dst, Src, Size) \ |
| 5971 do { \ |
| 5972 TestImplValue(Dst, 1, Src, 1, Size); \ |
| 5973 TestImplValue(Dst, -10, Src, 0x4050AA20, Size); \ |
| 5974 TestImplValue(Dst, -2, Src, -55, Size); \ |
| 5975 } while (0) |
| 5976 |
| 5977 #define TestImpl(Dst, Src) \ |
| 5978 do { \ |
| 5979 TestImplSize(Dst, Src, 16); \ |
| 5980 TestImplSize(Dst, Src, 32); \ |
| 5981 } while (0) |
| 5982 |
| 5983 TestImpl(eax, ebx); |
| 5984 TestImpl(ebx, ecx); |
| 5985 TestImpl(ecx, edx); |
| 5986 TestImpl(edx, esi); |
| 5987 TestImpl(esi, edi); |
| 5988 TestImpl(edi, eax); |
| 5989 |
| 5990 #undef TestImpl |
| 5991 #undef TestImplSize |
| 5992 #undef TestImplValue |
| 5993 #undef TestImplRegAddr |
| 5994 #undef TestImplRegImm |
| 5995 #undef TestImplRegReg |
| 5996 } |
| 5997 |
| 5998 TEST_F(AssemblerX8632Test, Div) { |
| 5999 static constexpr uint32_t Mask8 = 0x000000FF; |
| 6000 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 6001 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 6002 |
| 6003 static constexpr uint64_t Operand0Mask8 = 0x00000000000000FFull; |
| 6004 static constexpr uint64_t Operand0Mask16 = 0x00000000FFFFFFFFull; |
| 6005 static constexpr uint64_t Operand0Mask32 = 0xFFFFFFFFFFFFFFFFull; |
| 6006 |
| 6007 using Operand0Type_int8 = int16_t; |
| 6008 using Operand0Type_uint8 = uint16_t; |
| 6009 using Operand0Type_int16 = int32_t; |
| 6010 using Operand0Type_uint16 = uint32_t; |
| 6011 using Operand0Type_int32 = int64_t; |
| 6012 using Operand0Type_uint32 = uint64_t; |
| 6013 |
| 6014 #define TestImplReg(Inst, Value0, Src, Value1, Type, Size) \ |
| 6015 do { \ |
| 6016 static_assert(GPRRegister::Encoded_Reg_eax != \ |
| 6017 GPRRegister::Encoded_Reg_##Src, \ |
| 6018 "eax can not be src1."); \ |
| 6019 static_assert(GPRRegister::Encoded_Reg_edx != \ |
| 6020 GPRRegister::Encoded_Reg_##Src, \ |
| 6021 "edx can not be src1."); \ |
| 6022 \ |
| 6023 static constexpr char TestString[] = \ |
| 6024 "(" #Inst ", " #Value0 ", " #Src ", " #Value1 ", " #Type ", " #Size \ |
| 6025 ")"; \ |
| 6026 static constexpr Operand0Type_##Type##Size Operand0 = \ |
| 6027 static_cast<Type##64_t>(Value0) & Operand0Mask##Size; \ |
| 6028 static constexpr Type##Size##_t Operand0Lo = Operand0 & Mask##Size; \ |
| 6029 static constexpr Type##Size##_t Operand0Hi = \ |
| 6030 (Operand0 >> Size) & Mask##Size; \ |
| 6031 static constexpr Type##Size##_t Operand1 = \ |
| 6032 static_cast<Type##Size##_t>(Value1) & Mask##Size; \ |
| 6033 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 6034 Immediate(Operand0Lo)); \ |
| 6035 if (Size == 8) { \ |
| 6036 /* mov Operand0Hi, %ah */ \ |
| 6037 __ mov(IceType_i8, GPRRegister::Encoded_Reg_esp, Immediate(Operand0Hi)); \ |
| 6038 } else { \ |
| 6039 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 6040 Immediate(Operand0Hi)); \ |
| 6041 } \ |
| 6042 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 6043 Immediate(Operand1)); \ |
| 6044 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Src); \ |
| 6045 if (Size == 8) { \ |
| 6046 /* mov %ah, %dl */ \ |
| 6047 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 6048 GPRRegister::Encoded_Reg_esp); \ |
| 6049 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 6050 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ |
| 6051 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ |
| 6052 } \ |
| 6053 } \ |
| 6054 \ |
| 6055 AssembledTest test = assemble(); \ |
| 6056 test.run(); \ |
| 6057 \ |
| 6058 static constexpr uint32_t Quocient = (Operand0 / Operand1) & Mask##Size; \ |
| 6059 static constexpr uint32_t Reminder = (Operand0 % Operand1) & Mask##Size; \ |
| 6060 EXPECT_EQ(Quocient, test.eax()) << TestString; \ |
| 6061 EXPECT_EQ(Reminder, test.edx()) << TestString; \ |
| 6062 reset(); \ |
| 6063 } while (0) |
| 6064 |
| 6065 #define TestImplAddr(Inst, Value0, Value1, Type, Size) \ |
| 6066 do { \ |
| 6067 static constexpr char TestString[] = \ |
| 6068 "(" #Inst ", " #Value0 ", Addr, " #Value1 ", " #Type ", " #Size ")"; \ |
| 6069 static constexpr Operand0Type_##Type##Size Operand0 = \ |
| 6070 static_cast<Type##64_t>(Value0) & Operand0Mask##Size; \ |
| 6071 static constexpr Type##Size##_t Operand0Lo = Operand0 & Mask##Size; \ |
| 6072 static constexpr Type##Size##_t Operand0Hi = \ |
| 6073 (Operand0 >> Size) & Mask##Size; \ |
| 6074 const uint32_t T0 = allocateDword(); \ |
| 6075 static constexpr Type##Size##_t V0 = \ |
| 6076 static_cast<Type##Size##_t>(Value1) & Mask##Size; \ |
| 6077 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 6078 Immediate(Operand0Lo)); \ |
| 6079 if (Size == 8) { \ |
| 6080 /* mov Operand0Hi, %ah */ \ |
| 6081 __ mov(IceType_i8, GPRRegister::Encoded_Reg_esp, Immediate(Operand0Hi)); \ |
| 6082 } else { \ |
| 6083 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 6084 Immediate(Operand0Hi)); \ |
| 6085 } \ |
| 6086 __ Inst(IceType_i##Size, dwordAddress(T0)); \ |
| 6087 if (Size == 8) { \ |
| 6088 /* mov %ah, %dl */ \ |
| 6089 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ |
| 6090 GPRRegister::Encoded_Reg_esp); \ |
| 6091 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ |
| 6092 } \ |
| 6093 \ |
| 6094 AssembledTest test = assemble(); \ |
| 6095 test.setDwordTo(T0, static_cast<uint32_t>(V0)); \ |
| 6096 test.run(); \ |
| 6097 \ |
| 6098 static constexpr uint32_t Quocient = (Operand0 / V0) & Mask##Size; \ |
| 6099 static constexpr uint32_t Reminder = (Operand0 % V0) & Mask##Size; \ |
| 6100 EXPECT_EQ(Quocient, test.eax()) << TestString; \ |
| 6101 EXPECT_EQ(Reminder, test.edx()) << TestString; \ |
| 6102 reset(); \ |
| 6103 } while (0) |
| 6104 |
| 6105 #define TestImplOp(Inst, Value0, Src, Value1, Type, Size) \ |
| 6106 do { \ |
| 6107 TestImplReg(Inst, Value0, Src, Value1, Type, Size); \ |
| 6108 TestImplAddr(Inst, Value0, Value1, Type, Size); \ |
| 6109 } while (0) |
| 6110 |
| 6111 #define TestImplValue(Value0, Src, Value1, Size) \ |
| 6112 do { \ |
| 6113 TestImplOp(div, Value0, Src, Value1, uint, Size); \ |
| 6114 TestImplOp(idiv, Value0, Src, Value1, int, Size); \ |
| 6115 } while (0) |
| 6116 |
| 6117 #define TestImplSize(Src, Size) \ |
| 6118 do { \ |
| 6119 TestImplValue(10, Src, 1, Size); \ |
| 6120 TestImplValue(10, Src, -1, Size); \ |
| 6121 } while (0) |
| 6122 |
| 6123 #define TestImpl(Src) \ |
| 6124 do { \ |
| 6125 TestImplSize(Src, 8); \ |
| 6126 TestImplSize(Src, 16); \ |
| 6127 TestImplSize(Src, 32); \ |
| 6128 } while (0) |
| 6129 |
| 6130 TestImpl(ebx); |
| 6131 TestImpl(ecx); |
| 6132 TestImpl(esi); |
| 6133 TestImpl(edi); |
| 6134 |
| 6135 #undef TestImpl |
| 6136 #undef TestImplSize |
| 6137 #undef TestImplValue |
| 6138 #undef TestImplOp |
| 6139 #undef TestImplAddr |
| 6140 #undef TestImplReg |
| 6141 } |
| 6142 |
| 6143 // This is not executable in x86-64 because the one byte inc/dec instructions |
| 6144 // became the REX prefixes. Therefore, these are tested with the low-level test |
| 6145 // infrastructure. |
| 6146 TEST_F(AssemblerX8632LowLevelTest, Incl_Decl_Reg) { |
| 6147 #define TestImpl(Inst, Dst, BaseOpcode) \ |
| 6148 do { \ |
| 6149 __ Inst(GPRRegister::Encoded_Reg_##Dst); \ |
| 6150 static constexpr uint8_t ByteCount = 1; \ |
| 6151 ASSERT_EQ(ByteCount, codeBytesSize()); \ |
| 6152 verifyBytes<ByteCount>(codeBytes(), \ |
| 6153 BaseOpcode | GPRRegister::Encoded_Reg_##Dst); \ |
| 6154 reset(); \ |
| 6155 } while (0) |
| 6156 |
| 6157 #define TestInc(Dst) \ |
| 6158 do { \ |
| 6159 constexpr uint8_t InclOpcode = 0x40; \ |
| 6160 TestImpl(incl, Dst, InclOpcode); \ |
| 6161 } while (0) |
| 6162 |
| 6163 #define TestDec(Dst) \ |
| 6164 do { \ |
| 6165 constexpr uint8_t DeclOpcode = 0x48; \ |
| 6166 TestImpl(decl, Dst, DeclOpcode); \ |
| 6167 } while (0) |
| 6168 |
| 6169 TestInc(eax); |
| 6170 TestInc(ecx); |
| 6171 TestInc(edx); |
| 6172 TestInc(ebx); |
| 6173 TestInc(esp); |
| 6174 TestInc(ebp); |
| 6175 TestInc(esi); |
| 6176 TestInc(esi); |
| 6177 |
| 6178 TestDec(eax); |
| 6179 TestDec(ecx); |
| 6180 TestDec(edx); |
| 6181 TestDec(ebx); |
| 6182 TestDec(esp); |
| 6183 TestDec(ebp); |
| 6184 TestDec(esi); |
| 6185 TestDec(esi); |
| 6186 |
| 6187 #undef TestInc |
| 6188 #undef TestDec |
| 6189 #undef TestImpl |
| 6190 } |
| 6191 |
| 6192 TEST_F(AssemblerX8632Test, Incl_Decl_Addr) { |
| 6193 #define TestImpl(Inst, Value0) \ |
| 6194 do { \ |
| 6195 const bool IsInc = std::string(#Inst).find("incl") != std::string::npos; \ |
| 6196 const uint32_t T0 = allocateDword(); \ |
| 6197 const uint32_t V0 = Value0; \ |
| 6198 \ |
| 6199 __ Inst(dwordAddress(T0)); \ |
| 6200 \ |
| 6201 AssembledTest test = assemble(); \ |
| 6202 test.setDwordTo(T0, V0); \ |
| 6203 test.run(); \ |
| 6204 \ |
| 6205 ASSERT_EQ(static_cast<uint32_t>(Value0 + (IsInc ? 1 : -1)), \ |
| 6206 test.contentsOfDword(T0)); \ |
| 6207 reset(); \ |
| 6208 } while (0) |
| 6209 |
| 6210 #define TestInc(Value0) \ |
| 6211 do { \ |
| 6212 TestImpl(incl, Value0); \ |
| 6213 } while (0) |
| 6214 |
| 6215 #define TestDec(Value0) \ |
| 6216 do { \ |
| 6217 TestImpl(decl, Value0); \ |
| 6218 } while (0) |
| 6219 |
| 6220 TestInc(230); |
| 6221 |
| 6222 TestDec(30); |
| 6223 |
| 6224 #undef TestInc |
| 6225 #undef TestDec |
| 6226 #undef TestImpl |
| 6227 } |
| 6228 |
| 6229 TEST_F(AssemblerX8632Test, Shifts) { |
| 6230 static constexpr uint32_t Mask8 = 0x000000FF; |
| 6231 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 6232 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 6233 |
| 6234 #define TestImplRegImm(Inst, Dst, Value0, Imm, Op, Type, Size) \ |
| 6235 do { \ |
| 6236 static constexpr char TestString[] = \ |
| 6237 "(" #Inst ", " #Dst ", " #Value0 ", Imm(" #Imm "), " #Op ", " #Type \ |
| 6238 ", " #Size ")"; \ |
| 6239 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ |
| 6240 const uint##Size##_t Expected = \ |
| 6241 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Imm) | \ |
| 6242 (!IsRol ? 0 : (Value0) >> (Size - Imm))); \ |
| 6243 \ |
| 6244 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6245 Immediate((Value0)&Mask##Size)); \ |
| 6246 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6247 Immediate((Imm)&Mask##Size)); \ |
| 6248 \ |
| 6249 AssembledTest test = assemble(); \ |
| 6250 test.run(); \ |
| 6251 \ |
| 6252 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ |
| 6253 reset(); \ |
| 6254 } while (0) |
| 6255 |
| 6256 #define TestImplRegRegImm(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, \ |
| 6257 Type, Size) \ |
| 6258 do { \ |
| 6259 static constexpr char TestString[] = \ |
| 6260 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 \ |
| 6261 ", Imm(" #Count "), " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ |
| 6262 const uint##Size##_t Expected = \ |
| 6263 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ |
| 6264 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ |
| 6265 \ |
| 6266 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6267 Immediate((Value0)&Mask##Size)); \ |
| 6268 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 6269 Immediate((Value1)&Mask##Size)); \ |
| 6270 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6271 GPRRegister::Encoded_Reg_##Src, Immediate(Count)); \ |
| 6272 \ |
| 6273 AssembledTest test = assemble(); \ |
| 6274 test.run(); \ |
| 6275 \ |
| 6276 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ |
| 6277 reset(); \ |
| 6278 } while (0) |
| 6279 |
| 6280 #define TestImplRegCl(Inst, Dst, Value0, Count, Op, Type, Size) \ |
| 6281 do { \ |
| 6282 static constexpr char TestString[] = \ |
| 6283 "(" #Inst ", " #Dst ", " #Value0 ", " #Count ", " #Op ", " #Type \ |
| 6284 ", " #Size ")"; \ |
| 6285 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ |
| 6286 const uint##Size##_t Expected = \ |
| 6287 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Count) | \ |
| 6288 (!IsRol ? 0 : Value0 >> (Size - Count))); \ |
| 6289 \ |
| 6290 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6291 Immediate((Value0)&Mask##Size)); \ |
| 6292 __ mov(IceType_i8, GPRRegister::Encoded_Reg_ecx, \ |
| 6293 Immediate((Count)&Mask##Size)); \ |
| 6294 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6295 GPRRegister::Encoded_Reg_ecx); \ |
| 6296 \ |
| 6297 AssembledTest test = assemble(); \ |
| 6298 test.run(); \ |
| 6299 \ |
| 6300 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ |
| 6301 reset(); \ |
| 6302 } while (0) |
| 6303 |
| 6304 #define TestImplRegRegCl(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, \ |
| 6305 Type, Size) \ |
| 6306 do { \ |
| 6307 static constexpr char TestString[] = \ |
| 6308 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Count \ |
| 6309 ", " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ |
| 6310 const uint##Size##_t Expected = \ |
| 6311 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ |
| 6312 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ |
| 6313 \ |
| 6314 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6315 Immediate((Value0)&Mask##Size)); \ |
| 6316 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 6317 Immediate((Value1)&Mask##Size)); \ |
| 6318 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_ecx, \ |
| 6319 Immediate((Count)&0x7F)); \ |
| 6320 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6321 GPRRegister::Encoded_Reg_##Src); \ |
| 6322 \ |
| 6323 AssembledTest test = assemble(); \ |
| 6324 test.run(); \ |
| 6325 \ |
| 6326 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ |
| 6327 reset(); \ |
| 6328 } while (0) |
| 6329 |
| 6330 #define TestImplAddrCl(Inst, Value0, Count, Op, Type, Size) \ |
| 6331 do { \ |
| 6332 static constexpr char TestString[] = \ |
| 6333 "(" #Inst ", Addr, " #Value0 ", " #Count ", " #Op ", " #Type \ |
| 6334 ", " #Size ")"; \ |
| 6335 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ |
| 6336 const uint##Size##_t Expected = \ |
| 6337 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Count) | \ |
| 6338 (!IsRol ? 0 : Value0 >> (Size - Count))); \ |
| 6339 const uint32_t T0 = allocateDword(); \ |
| 6340 const uint32_t V0 = Value0; \ |
| 6341 \ |
| 6342 __ mov(IceType_i8, GPRRegister::Encoded_Reg_ecx, \ |
| 6343 Immediate((Count)&Mask##Size)); \ |
| 6344 __ Inst(IceType_i##Size, dwordAddress(T0), GPRRegister::Encoded_Reg_ecx); \ |
| 6345 \ |
| 6346 AssembledTest test = assemble(); \ |
| 6347 test.setDwordTo(T0, V0); \ |
| 6348 test.run(); \ |
| 6349 \ |
| 6350 ASSERT_EQ(static_cast<uint32_t>(Expected), \ |
| 6351 Mask##Size &test.contentsOfDword(T0)) \ |
| 6352 << TestString; \ |
| 6353 reset(); \ |
| 6354 } while (0) |
| 6355 |
| 6356 #define TestImplAddrRegCl(Inst, Value0, Src, Value1, Count, Op0, Op1, Type, \ |
| 6357 Size) \ |
| 6358 do { \ |
| 6359 static constexpr char TestString[] = \ |
| 6360 "(" #Inst ", Addr, " #Value0 ", " #Src ", " #Value1 ", " #Count \ |
| 6361 ", " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ |
| 6362 const uint##Size##_t Expected = \ |
| 6363 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ |
| 6364 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ |
| 6365 const uint32_t T0 = allocateDword(); \ |
| 6366 \ |
| 6367 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 6368 Immediate((Value1)&Mask##Size)); \ |
| 6369 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_ecx, \ |
| 6370 Immediate((Count)&0x7F)); \ |
| 6371 __ Inst(IceType_i##Size, dwordAddress(T0), \ |
| 6372 GPRRegister::Encoded_Reg_##Src); \ |
| 6373 \ |
| 6374 AssembledTest test = assemble(); \ |
| 6375 test.setDwordTo(T0, static_cast<uint32_t>(Value0)); \ |
| 6376 test.run(); \ |
| 6377 \ |
| 6378 ASSERT_EQ(static_cast<uint32_t>(Expected), test.contentsOfDword(T0)) \ |
| 6379 << TestString; \ |
| 6380 reset(); \ |
| 6381 } while (0) |
| 6382 |
| 6383 #define TestImplOp(Inst, Dst, Value0, Count, Op, Type, Size) \ |
| 6384 do { \ |
| 6385 static_assert(GPRRegister::Encoded_Reg_##Dst != \ |
| 6386 GPRRegister::Encoded_Reg_ecx, \ |
| 6387 "ecx should not be specified as Dst"); \ |
| 6388 TestImplRegImm(Inst, Dst, Value0, Count, Op, Type, Size); \ |
| 6389 TestImplRegImm(Inst, ecx, Value0, Count, Op, Type, Size); \ |
| 6390 TestImplRegCl(Inst, Dst, Value0, Count, Op, Type, Size); \ |
| 6391 TestImplAddrCl(Inst, Value0, Count, Op, Type, Size); \ |
| 6392 } while (0) |
| 6393 |
| 6394 #define TestImplThreeOperandOp(Inst, Dst, Value0, Src, Value1, Count, Op0, \ |
| 6395 Op1, Type, Size) \ |
| 6396 do { \ |
| 6397 static_assert(GPRRegister::Encoded_Reg_##Dst != \ |
| 6398 GPRRegister::Encoded_Reg_ecx, \ |
| 6399 "ecx should not be specified as Dst"); \ |
| 6400 static_assert(GPRRegister::Encoded_Reg_##Src != \ |
| 6401 GPRRegister::Encoded_Reg_ecx, \ |
| 6402 "ecx should not be specified as Src"); \ |
| 6403 TestImplRegRegImm(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, Type, \ |
| 6404 Size); \ |
| 6405 TestImplRegRegCl(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, Type, \ |
| 6406 Size); \ |
| 6407 TestImplAddrRegCl(Inst, Value0, Src, Value1, Count, Op0, Op1, Type, Size); \ |
| 6408 } while (0) |
| 6409 |
| 6410 #define TestImplValue(Dst, Value0, Count, Size) \ |
| 6411 do { \ |
| 6412 TestImplOp(rol, Dst, Value0, Count, <<, uint, Size); \ |
| 6413 TestImplOp(shl, Dst, Value0, Count, <<, uint, Size); \ |
| 6414 TestImplOp(shr, Dst, Value0, Count, >>, uint, Size); \ |
| 6415 TestImplOp(sar, Dst, Value0, Count, >>, int, Size); \ |
| 6416 } while (0) |
| 6417 |
| 6418 #define TestImplThreeOperandValue(Dst, Value0, Src, Value1, Count, Size) \ |
| 6419 do { \ |
| 6420 TestImplThreeOperandOp(shld, Dst, Value0, Src, Value1, Count, <<, >>, \ |
| 6421 uint, Size); \ |
| 6422 TestImplThreeOperandOp(shrd, Dst, Value0, Src, Value1, Count, >>, <<, \ |
| 6423 uint, Size); \ |
| 6424 } while (0) |
| 6425 |
| 6426 #define TestImplSize(Dst, Size) \ |
| 6427 do { \ |
| 6428 TestImplValue(Dst, 0x8F, 3, Size); \ |
| 6429 TestImplValue(Dst, 0x8FFF, 7, Size); \ |
| 6430 TestImplValue(Dst, 0x8FFFF, 7, Size); \ |
| 6431 } while (0) |
| 6432 |
| 6433 #define TestImplThreeOperandSize(Dst, Src, Size) \ |
| 6434 do { \ |
| 6435 TestImplThreeOperandValue(Dst, 0xFFF3, Src, 0xA000, 8, Size); \ |
| 6436 } while (0) |
| 6437 |
| 6438 #define TestImpl(Dst, Src) \ |
| 6439 do { \ |
| 6440 if (GPRRegister::Encoded_Reg_##Dst < 4) { \ |
| 6441 TestImplSize(Dst, 8); \ |
| 6442 } \ |
| 6443 TestImplSize(Dst, 16); \ |
| 6444 TestImplThreeOperandSize(Dst, Src, 16); \ |
| 6445 TestImplSize(Dst, 32); \ |
| 6446 TestImplThreeOperandSize(Dst, Src, 32); \ |
| 6447 } while (0) |
| 6448 |
| 6449 TestImpl(eax, ebx); |
| 6450 TestImpl(ebx, edx); |
| 6451 TestImpl(edx, esi); |
| 6452 TestImpl(esi, edi); |
| 6453 TestImpl(edi, eax); |
| 6454 |
| 6455 #undef TestImpl |
| 6456 #undef TestImplThreeOperandSize |
| 6457 #undef TestImplSize |
| 6458 #undef TestImplValue |
| 6459 #undef TestImplThreeOperandValue |
| 6460 #undef TestImplOp |
| 6461 #undef TestImplThreeOperandOp |
| 6462 #undef TestImplAddrCl |
| 6463 #undef TestImplRegRegCl |
| 6464 #undef TestImplRegCl |
| 6465 #undef TestImplRegRegImm |
| 6466 #undef TestImplRegImm |
| 6467 } |
| 6468 |
| 6469 TEST_F(AssemblerX8632Test, Neg) { |
| 6470 static constexpr uint32_t Mask8 = 0x000000ff; |
| 6471 static constexpr uint32_t Mask16 = 0x0000ffff; |
| 6472 static constexpr uint32_t Mask32 = 0xffffffff; |
| 6473 |
| 6474 #define TestImplReg(Dst, Size) \ |
| 6475 do { \ |
| 6476 static constexpr int32_t Value = 0xFF00A543; \ |
| 6477 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6478 Immediate(static_cast<int##Size##_t>(Value) & Mask##Size)); \ |
| 6479 __ neg(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst); \ |
| 6480 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 6481 GPRRegister::Encoded_Reg_##Dst); \ |
| 6482 __ And(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(Mask##Size)); \ |
| 6483 \ |
| 6484 AssembledTest test = assemble(); \ |
| 6485 test.run(); \ |
| 6486 \ |
| 6487 ASSERT_EQ(1 + (~static_cast<int##Size##_t>(Value) & Mask##Size), \ |
| 6488 test.eax()) \ |
| 6489 << "(" #Dst ", " #Size ")"; \ |
| 6490 reset(); \ |
| 6491 } while (0) |
| 6492 |
| 6493 #define TestImplAddr(Size) \ |
| 6494 do { \ |
| 6495 static constexpr int32_t Value = 0xFF00A543; \ |
| 6496 const uint32_t T0 = allocateDword(); \ |
| 6497 __ neg(IceType_i##Size, dwordAddress(T0)); \ |
| 6498 \ |
| 6499 AssembledTest test = assemble(); \ |
| 6500 test.setDwordTo(T0, Value &Mask##Size); \ |
| 6501 test.run(); \ |
| 6502 \ |
| 6503 ASSERT_EQ(1 + (~static_cast<int##Size##_t>(Value) & Mask##Size), \ |
| 6504 test.contentsOfDword(T0)) \ |
| 6505 << "(Addr, " #Size ")"; \ |
| 6506 reset(); \ |
| 6507 } while (0) |
| 6508 |
| 6509 #define TestImpl(Size) \ |
| 6510 do { \ |
| 6511 TestImplAddr(Size); \ |
| 6512 TestImplReg(eax, Size); \ |
| 6513 TestImplReg(ebx, Size); \ |
| 6514 TestImplReg(ecx, Size); \ |
| 6515 TestImplReg(edx, Size); \ |
| 6516 TestImplReg(esi, Size); \ |
| 6517 TestImplReg(edi, Size); \ |
| 6518 } while (0) |
| 6519 |
| 6520 TestImpl(8); |
| 6521 TestImpl(16); |
| 6522 TestImpl(32); |
| 6523 |
| 6524 #undef TestImpl |
| 6525 #undef TestImplAddr |
| 6526 #undef TestImplReg |
| 6527 } |
| 6528 |
| 6529 TEST_F(AssemblerX8632Test, Not) { |
| 6530 #define TestImpl(Dst) \ |
| 6531 do { \ |
| 6532 static constexpr uint32_t Value = 0xFF00A543; \ |
| 6533 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value)); \ |
| 6534 __ notl(GPRRegister::Encoded_Reg_##Dst); \ |
| 6535 \ |
| 6536 AssembledTest test = assemble(); \ |
| 6537 test.run(); \ |
| 6538 \ |
| 6539 ASSERT_EQ(~Value, test.Dst()) << "(" #Dst ")"; \ |
| 6540 reset(); \ |
| 6541 } while (0) |
| 6542 |
| 6543 TestImpl(eax); |
| 6544 TestImpl(ebx); |
| 6545 TestImpl(ecx); |
| 6546 TestImpl(edx); |
| 6547 TestImpl(esi); |
| 6548 TestImpl(edi); |
| 6549 |
| 6550 #undef TestImpl |
| 6551 } |
| 6552 |
| 6553 TEST_F(AssemblerX8632Test, Bswap) { |
| 6554 #define TestImpl(Dst) \ |
| 6555 do { \ |
| 6556 static constexpr uint32_t Value = 0xFF00A543; \ |
| 6557 static constexpr uint32_t Expected = 0x43A500FF; \ |
| 6558 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value)); \ |
| 6559 __ bswap(IceType_i32, GPRRegister::Encoded_Reg_##Dst); \ |
| 6560 \ |
| 6561 AssembledTest test = assemble(); \ |
| 6562 test.run(); \ |
| 6563 \ |
| 6564 ASSERT_EQ(Expected, test.Dst()) << "(" #Dst ")"; \ |
| 6565 reset(); \ |
| 6566 } while (0) |
| 6567 |
| 6568 TestImpl(eax); |
| 6569 TestImpl(ebx); |
| 6570 TestImpl(ecx); |
| 6571 TestImpl(edx); |
| 6572 TestImpl(esi); |
| 6573 TestImpl(edi); |
| 6574 |
| 6575 #undef TestImpl |
| 6576 } |
| 6577 |
| 6578 TEST_F(AssemblerX8632Test, Bt) { |
| 6579 #define TestImpl(Dst, Value0, Src, Value1) \ |
| 6580 do { \ |
| 6581 static constexpr char TestString[] = \ |
| 6582 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ")"; \ |
| 6583 static constexpr uint32_t Expected = ((Value0) & (1u << (Value1))) != 0; \ |
| 6584 \ |
| 6585 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value0)); \ |
| 6586 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src, Immediate(Value1)); \ |
| 6587 __ bt(GPRRegister::Encoded_Reg_##Dst, GPRRegister::Encoded_Reg_##Src); \ |
| 6588 __ setcc(Cond::Br_b, ByteRegister::Encoded_Reg_al); \ |
| 6589 __ And(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0xFFu)); \ |
| 6590 \ |
| 6591 AssembledTest test = assemble(); \ |
| 6592 test.run(); \ |
| 6593 \ |
| 6594 ASSERT_EQ(Expected, test.eax()) << TestString; \ |
| 6595 reset(); \ |
| 6596 } while (0) |
| 6597 |
| 6598 TestImpl(eax, 0x08000000, ebx, 27u); |
| 6599 TestImpl(ebx, 0x08000000, ecx, 23u); |
| 6600 TestImpl(ecx, 0x00000000, edx, 1u); |
| 6601 TestImpl(edx, 0x08000300, esi, 9u); |
| 6602 TestImpl(esi, 0x08000300, edi, 10u); |
| 6603 TestImpl(edi, 0x7FFFEFFF, eax, 13u); |
| 6604 |
| 6605 #undef TestImpl |
| 6606 } |
| 6607 |
| 6608 template <uint32_t Value, uint32_t Bits> class BitScanHelper { |
| 6609 BitScanHelper() = delete; |
| 6610 |
| 6611 public: |
| 6612 static_assert(Bits == 16 || Bits == 32, "Bits must be 16 or 32"); |
| 6613 using ValueType = |
| 6614 typename std::conditional<Bits == 16, uint16_t, uint32_t>::type; |
| 6615 |
| 6616 private: |
| 6617 static constexpr ValueType BitIndex(bool Forward, ValueType Index) { |
| 6618 return (Value == 0) |
| 6619 ? BitScanHelper<Value, Bits>::NoBitSet |
| 6620 : (Value & (1u << Index) |
| 6621 ? Index |
| 6622 : BitIndex(Forward, (Forward ? Index + 1 : Index - 1))); |
| 6623 } |
| 6624 |
| 6625 public: |
| 6626 static constexpr ValueType NoBitSet = static_cast<ValueType>(-1); |
| 6627 static constexpr ValueType bsf = BitIndex(/*Forward*/ true, /*Index=*/0); |
| 6628 static constexpr ValueType bsr = |
| 6629 BitIndex(/*Forward*/ false, /*Index=*/Bits - 1); |
| 6630 }; |
| 6631 |
| 6632 TEST_F(AssemblerX8632Test, BitScanOperations) { |
| 6633 #define TestImplRegReg(Inst, Dst, Src, Value1, Size) \ |
| 6634 do { \ |
| 6635 static constexpr char TestString[] = \ |
| 6636 "(" #Inst ", " #Dst ", " #Src ", " #Value1 ", " #Size ")"; \ |
| 6637 static constexpr uint32_t Expected = BitScanHelper<Value1, Size>::Inst; \ |
| 6638 const uint32_t ZeroFlag = allocateDword(); \ |
| 6639 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 6640 Immediate(Value1)); \ |
| 6641 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6642 GPRRegister::Encoded_Reg_##Src); \ |
| 6643 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ |
| 6644 \ |
| 6645 AssembledTest test = assemble(); \ |
| 6646 test.setDwordTo(ZeroFlag, 0u); \ |
| 6647 test.run(); \ |
| 6648 \ |
| 6649 ASSERT_EQ((Expected == BitScanHelper<Value1, Size>::NoBitSet), \ |
| 6650 test.contentsOfDword(ZeroFlag)) \ |
| 6651 << TestString; \ |
| 6652 if ((Expected != BitScanHelper<Value1, Size>::NoBitSet)) { \ |
| 6653 ASSERT_EQ(Expected, test.Dst()) << TestString; \ |
| 6654 } \ |
| 6655 reset(); \ |
| 6656 } while (0) |
| 6657 |
| 6658 #define TestImplRegAddr(Inst, Dst, Value1, Size) \ |
| 6659 do { \ |
| 6660 static constexpr char TestString[] = \ |
| 6661 "(" #Inst ", " #Dst ", Addr, " #Value1 ", " #Size ")"; \ |
| 6662 static constexpr uint32_t Expected = BitScanHelper<Value1, Size>::Inst; \ |
| 6663 const uint32_t T0 = allocateDword(); \ |
| 6664 const uint32_t ZeroFlag = allocateDword(); \ |
| 6665 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ |
| 6666 dwordAddress(T0)); \ |
| 6667 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ |
| 6668 \ |
| 6669 AssembledTest test = assemble(); \ |
| 6670 test.setDwordTo(T0, Value1); \ |
| 6671 test.setDwordTo(ZeroFlag, 0u); \ |
| 6672 test.run(); \ |
| 6673 \ |
| 6674 ASSERT_EQ((Expected == BitScanHelper<Value1, Size>::NoBitSet), \ |
| 6675 test.contentsOfDword(ZeroFlag)) \ |
| 6676 << TestString; \ |
| 6677 if (Expected != BitScanHelper<Value1, Size>::NoBitSet) { \ |
| 6678 ASSERT_EQ(Expected, test.Dst()) << TestString; \ |
| 6679 } \ |
| 6680 reset(); \ |
| 6681 } while (0) |
| 6682 |
| 6683 #define TestImplSize(Dst, Src, Value1, Size) \ |
| 6684 do { \ |
| 6685 TestImplRegReg(bsf, Dst, Src, Value1, Size); \ |
| 6686 TestImplRegAddr(bsf, Dst, Value1, Size); \ |
| 6687 TestImplRegReg(bsr, Dst, Src, Value1, Size); \ |
| 6688 TestImplRegAddr(bsf, Dst, Value1, Size); \ |
| 6689 } while (0) |
| 6690 |
| 6691 #define TestImplValue(Dst, Src, Value1) \ |
| 6692 do { \ |
| 6693 TestImplSize(Dst, Src, Value1, 16); \ |
| 6694 TestImplSize(Dst, Src, Value1, 32); \ |
| 6695 } while (0) |
| 6696 |
| 6697 #define TestImpl(Dst, Src) \ |
| 6698 do { \ |
| 6699 TestImplValue(Dst, Src, 0x80000001); \ |
| 6700 TestImplValue(Dst, Src, 0x00000000); \ |
| 6701 TestImplValue(Dst, Src, 0x80001000); \ |
| 6702 TestImplValue(Dst, Src, 0x00FFFF00); \ |
| 6703 } while (0) |
| 6704 |
| 6705 TestImpl(eax, ebx); |
| 6706 TestImpl(ebx, ecx); |
| 6707 TestImpl(ecx, edx); |
| 6708 TestImpl(edx, esi); |
| 6709 TestImpl(esi, edi); |
| 6710 TestImpl(edi, eax); |
| 6711 |
| 6712 #undef TestImpl |
| 6713 #undef TestImplValue |
| 6714 #undef TestImplSize |
| 6715 #undef TestImplRegAddr |
| 6716 #undef TestImplRegReg |
| 6717 } |
| 6718 |
| 6719 TEST_F(AssemblerX8632LowLevelTest, Nop) { |
| 6720 #define TestImpl(Size, ...) \ |
| 6721 do { \ |
| 6722 static constexpr char TestString[] = "(" #Size ", " #__VA_ARGS__ ")"; \ |
| 6723 __ nop(Size); \ |
| 6724 ASSERT_EQ(Size##u, codeBytesSize()) << TestString; \ |
| 6725 ASSERT_TRUE(verifyBytes<Size>(codeBytes(), __VA_ARGS__)) << TestString; \ |
| 6726 reset(); \ |
| 6727 } while (0); |
| 6728 |
| 6729 TestImpl(1, 0x90); |
| 6730 TestImpl(2, 0x66, 0x90); |
| 6731 TestImpl(3, 0x0F, 0x1F, 0x00); |
| 6732 TestImpl(4, 0x0F, 0x1F, 0x40, 0x00); |
| 6733 TestImpl(5, 0x0F, 0x1F, 0x44, 0x00, 0x00); |
| 6734 TestImpl(6, 0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00); |
| 6735 TestImpl(7, 0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00); |
| 6736 TestImpl(8, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00); |
| 6737 |
| 6738 #undef TestImpl |
| 6739 } |
| 6740 |
| 6741 TEST_F(AssemblerX8632LowLevelTest, Int3) { |
| 6742 __ int3(); |
| 6743 static constexpr uint32_t ByteCount = 1; |
| 6744 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 6745 verifyBytes<ByteCount>(codeBytes(), 0xCC); |
| 6746 } |
| 6747 |
| 6748 TEST_F(AssemblerX8632LowLevelTest, Hlt) { |
| 6749 __ hlt(); |
| 6750 static constexpr uint32_t ByteCount = 1; |
| 6751 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 6752 verifyBytes<ByteCount>(codeBytes(), 0xF4); |
| 6753 } |
| 6754 |
| 6755 TEST_F(AssemblerX8632LowLevelTest, Ud2) { |
| 6756 __ ud2(); |
| 6757 static constexpr uint32_t ByteCount = 2; |
| 6758 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 6759 verifyBytes<ByteCount>(codeBytes(), 0x0F, 0x0B); |
| 6760 } |
| 6761 |
| 6762 TEST_F(AssemblerX8632Test, Jmp) { |
| 6763 // TestImplReg uses jmp(Label), so jmp(Label) needs to be tested before it. |
| 6764 #define TestImplAddr(Near) \ |
| 6765 do { \ |
| 6766 Label ForwardJmp; \ |
| 6767 Label BackwardJmp; \ |
| 6768 Label Done; \ |
| 6769 \ |
| 6770 __ jmp(&ForwardJmp, AssemblerX8632::k##Near##Jump); \ |
| 6771 __ hlt(); \ |
| 6772 __ hlt(); \ |
| 6773 __ hlt(); \ |
| 6774 __ hlt(); \ |
| 6775 __ hlt(); \ |
| 6776 __ hlt(); \ |
| 6777 __ hlt(); \ |
| 6778 __ hlt(); \ |
| 6779 __ hlt(); \ |
| 6780 __ hlt(); \ |
| 6781 __ bind(&BackwardJmp); \ |
| 6782 __ jmp(&Done, AssemblerX8632::k##Near##Jump); \ |
| 6783 __ hlt(); \ |
| 6784 __ hlt(); \ |
| 6785 __ hlt(); \ |
| 6786 __ hlt(); \ |
| 6787 __ hlt(); \ |
| 6788 __ hlt(); \ |
| 6789 __ hlt(); \ |
| 6790 __ hlt(); \ |
| 6791 __ hlt(); \ |
| 6792 __ hlt(); \ |
| 6793 __ bind(&ForwardJmp); \ |
| 6794 __ jmp(&BackwardJmp, AssemblerX8632::k##NearJump); \ |
| 6795 __ hlt(); \ |
| 6796 __ hlt(); \ |
| 6797 __ hlt(); \ |
| 6798 __ hlt(); \ |
| 6799 __ hlt(); \ |
| 6800 __ hlt(); \ |
| 6801 __ hlt(); \ |
| 6802 __ hlt(); \ |
| 6803 __ hlt(); \ |
| 6804 __ hlt(); \ |
| 6805 __ bind(&Done); \ |
| 6806 } while (0) |
| 6807 |
| 6808 #define TestImplReg(Dst) \ |
| 6809 do { \ |
| 6810 __ call(Immediate(16)); \ |
| 6811 Label Done; \ |
| 6812 __ jmp(&Done, AssemblerX8632::kNearJump); \ |
| 6813 __ hlt(); \ |
| 6814 __ hlt(); \ |
| 6815 __ hlt(); \ |
| 6816 __ hlt(); \ |
| 6817 __ hlt(); \ |
| 6818 __ hlt(); \ |
| 6819 __ hlt(); \ |
| 6820 __ hlt(); \ |
| 6821 __ hlt(); \ |
| 6822 __ hlt(); \ |
| 6823 __ popl(GPRRegister::Encoded_Reg_##Dst); \ |
| 6824 __ jmp(GPRRegister::Encoded_Reg_##Dst); \ |
| 6825 __ hlt(); \ |
| 6826 __ hlt(); \ |
| 6827 __ hlt(); \ |
| 6828 __ hlt(); \ |
| 6829 __ hlt(); \ |
| 6830 __ hlt(); \ |
| 6831 __ hlt(); \ |
| 6832 __ hlt(); \ |
| 6833 __ hlt(); \ |
| 6834 __ hlt(); \ |
| 6835 __ bind(&Done); \ |
| 6836 \ |
| 6837 AssembledTest test = assemble(); \ |
| 6838 test.run(); \ |
| 6839 \ |
| 6840 reset(); \ |
| 6841 } while (0) |
| 6842 |
| 6843 TestImplAddr(Near); |
| 6844 TestImplAddr(Far); |
| 6845 |
| 6846 TestImplReg(eax); |
| 6847 TestImplReg(ebx); |
| 6848 TestImplReg(ecx); |
| 6849 TestImplReg(edx); |
| 6850 TestImplReg(esi); |
| 6851 TestImplReg(edi); |
| 6852 |
| 6853 #undef TestImplReg |
| 6854 #undef TestImplAddr |
| 6855 } |
| 6856 |
| 6857 TEST_F(AssemblerX8632LowLevelTest, Mfence) { |
| 6858 __ mfence(); |
| 6859 |
| 6860 static constexpr uint8_t ByteCount = 3; |
| 6861 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 6862 verifyBytes<ByteCount>(codeBytes(), 0x0F, 0xAE, 0xF0); |
| 6863 } |
| 6864 |
| 6865 TEST_F(AssemblerX8632LowLevelTest, Lock) { |
| 6866 __ lock(); |
| 6867 |
| 6868 static constexpr uint8_t ByteCount = 1; |
| 6869 ASSERT_EQ(ByteCount, codeBytesSize()); |
| 6870 verifyBytes<ByteCount>(codeBytes(), 0xF0); |
| 6871 } |
| 6872 |
| 6873 TEST_F(AssemblerX8632Test, Xchg) { |
| 6874 static constexpr uint32_t Mask8 = 0x000000FF; |
| 6875 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 6876 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 6877 |
| 6878 #define TestImplAddrReg(Value0, Dst1, Value1, Size) \ |
| 6879 do { \ |
| 6880 static constexpr char TestString[] = \ |
| 6881 "(" #Value0 ", " #Dst1 ", " #Value1 ", " #Size ")"; \ |
| 6882 const uint32_t T0 = allocateDword(); \ |
| 6883 const uint32_t V0 = (Value0)&Mask##Size; \ |
| 6884 const uint32_t V1 = (Value1)&Mask##Size; \ |
| 6885 \ |
| 6886 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 6887 Immediate(Value1)); \ |
| 6888 __ xchg(IceType_i##Size, dwordAddress(T0), \ |
| 6889 GPRRegister::Encoded_Reg_##Dst1); \ |
| 6890 __ And(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ |
| 6891 Immediate(Mask##Size)); \ |
| 6892 \ |
| 6893 AssembledTest test = assemble(); \ |
| 6894 test.setDwordTo(T0, V0); \ |
| 6895 test.run(); \ |
| 6896 \ |
| 6897 ASSERT_EQ(V0, test.Dst1()) << TestString; \ |
| 6898 ASSERT_EQ(V1, test.contentsOfDword(T0)) << TestString; \ |
| 6899 reset(); \ |
| 6900 } while (0) |
| 6901 |
| 6902 #define TestImplSize(Dst1, Size) \ |
| 6903 do { \ |
| 6904 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, Size); \ |
| 6905 } while (0) |
| 6906 |
| 6907 #define TestImpl(Dst1) \ |
| 6908 do { \ |
| 6909 if (GPRRegister::Encoded_Reg_##Dst1 < 4) { \ |
| 6910 TestImplSize(Dst1, 8); \ |
| 6911 } \ |
| 6912 TestImplSize(Dst1, 16); \ |
| 6913 TestImplSize(Dst1, 32); \ |
| 6914 } while (0) |
| 6915 |
| 6916 TestImpl(eax); |
| 6917 TestImpl(ebx); |
| 6918 TestImpl(ecx); |
| 6919 TestImpl(edx); |
| 6920 TestImpl(esi); |
| 6921 TestImpl(edi); |
| 6922 |
| 6923 #undef TestImpl |
| 6924 #undef TestImplSize |
| 6925 #undef TestImplAddrReg |
| 6926 } |
| 6927 |
| 6928 TEST_F(AssemblerX8632Test, Xadd) { |
| 6929 static constexpr bool NotLocked = false; |
| 6930 static constexpr bool Locked = true; |
| 6931 |
| 6932 static constexpr uint32_t Mask8 = 0x000000FF; |
| 6933 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 6934 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 6935 |
| 6936 #define TestImplAddrReg(Value0, Dst1, Value1, LockedOrNot, Size) \ |
| 6937 do { \ |
| 6938 static constexpr char TestString[] = \ |
| 6939 "(" #Value0 ", " #Dst1 ", " #Value1 ", " #Size ")"; \ |
| 6940 const uint32_t T0 = allocateDword(); \ |
| 6941 const uint32_t V0 = (Value0)&Mask##Size; \ |
| 6942 const uint32_t V1 = (Value1)&Mask##Size; \ |
| 6943 \ |
| 6944 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ |
| 6945 Immediate(Value1)); \ |
| 6946 __ xadd(IceType_i##Size, dwordAddress(T0), \ |
| 6947 GPRRegister::Encoded_Reg_##Dst1, LockedOrNot); \ |
| 6948 __ And(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ |
| 6949 Immediate(Mask##Size)); \ |
| 6950 \ |
| 6951 AssembledTest test = assemble(); \ |
| 6952 test.setDwordTo(T0, V0); \ |
| 6953 test.run(); \ |
| 6954 \ |
| 6955 ASSERT_EQ(V0, test.Dst1()) << TestString; \ |
| 6956 ASSERT_EQ(Mask##Size &(V1 + V0), test.contentsOfDword(T0)) << TestString; \ |
| 6957 reset(); \ |
| 6958 } while (0) |
| 6959 |
| 6960 #define TestImplSize(Dst1, Size) \ |
| 6961 do { \ |
| 6962 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, NotLocked, Size); \ |
| 6963 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, Locked, Size); \ |
| 6964 } while (0) |
| 6965 |
| 6966 #define TestImpl(Dst1) \ |
| 6967 do { \ |
| 6968 if (GPRRegister::Encoded_Reg_##Dst1 < 4) { \ |
| 6969 TestImplSize(Dst1, 8); \ |
| 6970 } \ |
| 6971 TestImplSize(Dst1, 16); \ |
| 6972 TestImplSize(Dst1, 32); \ |
| 6973 } while (0) |
| 6974 |
| 6975 TestImpl(eax); |
| 6976 TestImpl(ebx); |
| 6977 TestImpl(ecx); |
| 6978 TestImpl(edx); |
| 6979 TestImpl(esi); |
| 6980 TestImpl(edi); |
| 6981 |
| 6982 #undef TestImpl |
| 6983 #undef TestImplSize |
| 6984 #undef TestImplAddrReg |
| 6985 } |
| 6986 |
| 6987 TEST_F(AssemblerX8632LowLevelTest, Xadd) { |
| 6988 static constexpr bool NotLocked = false; |
| 6989 static constexpr bool Locked = true; |
| 6990 |
| 6991 // Ensures that xadd emits a lock prefix accordingly. |
| 6992 { |
| 6993 __ xadd(IceType_i8, Address::Absolute(0x1FF00), |
| 6994 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 6995 static constexpr uint8_t ByteCountNotLocked8 = 7; |
| 6996 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
| 6997 verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x0F, 0xC0, 0x35, 0x00, 0xFF, |
| 6998 0x01, 0x00); |
| 6999 reset(); |
| 7000 |
| 7001 __ xadd(IceType_i8, Address::Absolute(0x1FF00), |
| 7002 GPRRegister::Encoded_Reg_esi, Locked); |
| 7003 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
| 7004 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
| 7005 verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x0F, 0xC0, 0x35, 0x00, |
| 7006 0xFF, 0x01, 0x00); |
| 7007 reset(); |
| 7008 } |
| 7009 |
| 7010 { |
| 7011 __ xadd(IceType_i16, Address::Absolute(0x1FF00), |
| 7012 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 7013 static constexpr uint8_t ByteCountNotLocked16 = 8; |
| 7014 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
| 7015 verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x0F, 0xC1, 0x35, 0x00, |
| 7016 0xFF, 0x01, 0x00); |
| 7017 reset(); |
| 7018 |
| 7019 __ xadd(IceType_i16, Address::Absolute(0x1FF00), |
| 7020 GPRRegister::Encoded_Reg_esi, Locked); |
| 7021 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
| 7022 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
| 7023 verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x0F, 0xC1, 0x35, |
| 7024 0x00, 0xFF, 0x01, 0x00); |
| 7025 reset(); |
| 7026 } |
| 7027 |
| 7028 { |
| 7029 __ xadd(IceType_i32, Address::Absolute(0x1FF00), |
| 7030 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 7031 static constexpr uint8_t ByteCountNotLocked32 = 7; |
| 7032 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
| 7033 verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x0F, 0xC1, 0x35, 0x00, 0xFF, |
| 7034 0x01, 0x00); |
| 7035 reset(); |
| 7036 |
| 7037 __ xadd(IceType_i32, Address::Absolute(0x1FF00), |
| 7038 GPRRegister::Encoded_Reg_esi, Locked); |
| 7039 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
| 7040 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
| 7041 verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x0F, 0xC1, 0x35, 0x00, |
| 7042 0xFF, 0x01, 0x00); |
| 7043 reset(); |
| 7044 } |
| 7045 } |
| 7046 |
| 7047 TEST_F(AssemblerX8632LowLevelTest, EmitSegmentOverride) { |
| 7048 #define TestImpl(Prefix) \ |
| 7049 do { \ |
| 7050 static constexpr uint8_t ByteCount = 1; \ |
| 7051 __ emitSegmentOverride(Prefix); \ |
| 7052 ASSERT_EQ(ByteCount, codeBytesSize()) << Prefix; \ |
| 7053 verifyBytes<ByteCount>(codeBytes(), Prefix); \ |
| 7054 reset(); \ |
| 7055 } while (0) |
| 7056 |
| 7057 TestImpl(0x26); |
| 7058 TestImpl(0x2E); |
| 7059 TestImpl(0x36); |
| 7060 TestImpl(0x3E); |
| 7061 TestImpl(0x64); |
| 7062 TestImpl(0x65); |
| 7063 TestImpl(0x66); |
| 7064 TestImpl(0x67); |
| 7065 |
| 7066 #undef TestImpl |
| 7067 } |
| 7068 |
| 7069 TEST_F(AssemblerX8632Test, Cmpxchg8b) { |
| 7070 static constexpr bool NotLocked = false; |
| 7071 static constexpr bool Locked = true; |
| 7072 |
| 7073 #define TestImpl(Value0, Value1, ValueMem, LockedOrNot) \ |
| 7074 do { \ |
| 7075 static constexpr char TestString[] = \ |
| 7076 "(" #Value0 ", " #Value1 ", " #ValueMem ", " #LockedOrNot ")"; \ |
| 7077 const uint32_t T0 = allocateQword(); \ |
| 7078 static constexpr uint64_t V0 = ValueMem; \ |
| 7079 const uint32_t ZeroFlag = allocateDword(); \ |
| 7080 \ |
| 7081 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, \ |
| 7082 Immediate(uint64_t(Value0) & 0xFFFFFFFF)); \ |
| 7083 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, \ |
| 7084 Immediate(uint64_t(Value0) >> 32)); \ |
| 7085 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, \ |
| 7086 Immediate(uint64_t(Value1) & 0xFFFFFFFF)); \ |
| 7087 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, \ |
| 7088 Immediate(uint64_t(Value1) >> 32)); \ |
| 7089 __ cmpxchg8b(dwordAddress(T0), LockedOrNot); \ |
| 7090 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ |
| 7091 \ |
| 7092 AssembledTest test = assemble(); \ |
| 7093 test.setQwordTo(T0, V0); \ |
| 7094 test.setDwordTo(ZeroFlag, uint32_t(0xFF)); \ |
| 7095 test.run(); \ |
| 7096 \ |
| 7097 if (V0 == (Value0)) { \ |
| 7098 ASSERT_EQ(uint64_t(Value1), test.contentsOfQword(T0)) << TestString; \ |
| 7099 ASSERT_EQ(1u, test.contentsOfDword(ZeroFlag)) << TestString; \ |
| 7100 } else { \ |
| 7101 ASSERT_EQ(uint64_t(ValueMem) & 0xFFFFFFFF, test.eax()) << TestString; \ |
| 7102 ASSERT_EQ((uint64_t(ValueMem) >> 32) & 0xFFFFFFFF, test.edx()) \ |
| 7103 << TestString; \ |
| 7104 ASSERT_EQ(0u, test.contentsOfDword(ZeroFlag)) << TestString; \ |
| 7105 } \ |
| 7106 reset(); \ |
| 7107 } while (0) |
| 7108 |
| 7109 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, NotLocked); |
| 7110 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, Locked); |
| 7111 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, NotLocked); |
| 7112 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); |
| 7113 |
| 7114 #undef TestImpl |
| 7115 } |
| 7116 |
| 7117 TEST_F(AssemblerX8632LowLevelTest, Cmpxchg8b) { |
| 7118 static constexpr bool NotLocked = false; |
| 7119 static constexpr bool Locked = true; |
| 7120 |
| 7121 // Ensures that cmpxchg8b emits a lock prefix accordingly. |
| 7122 __ cmpxchg8b(Address::Absolute(0x1FF00), NotLocked); |
| 7123 static constexpr uint8_t ByteCountNotLocked = 7; |
| 7124 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); |
| 7125 verifyBytes<ByteCountNotLocked>(codeBytes(), 0x0F, 0xC7, 0x0D, 0x00, 0xFF, |
| 7126 0x01, 0x00); |
| 7127 reset(); |
| 7128 |
| 7129 __ cmpxchg8b(Address::Absolute(0x1FF00), Locked); |
| 7130 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; |
| 7131 ASSERT_EQ(ByteCountLocked, codeBytesSize()); |
| 7132 verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x0F, 0xC7, 0x0D, 0x00, 0xFF, |
| 7133 0x01, 0x00); |
| 7134 reset(); |
| 7135 } |
| 7136 |
| 7137 TEST_F(AssemblerX8632Test, Cmpxchg) { |
| 7138 static constexpr bool NotLocked = false; |
| 7139 static constexpr bool Locked = true; |
| 7140 |
| 7141 static constexpr uint32_t Mask8 = 0x000000FF; |
| 7142 static constexpr uint32_t Mask16 = 0x0000FFFF; |
| 7143 static constexpr uint32_t Mask32 = 0xFFFFFFFF; |
| 7144 |
| 7145 #define TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, Size) \ |
| 7146 do { \ |
| 7147 static constexpr char TestString[] = \ |
| 7148 "(" #Value0 ", " #Src ", " #Value1 ", " #ValueMem ", " #LockedOrNot \ |
| 7149 ", " #Size ")"; \ |
| 7150 const uint32_t T0 = allocateDword(); \ |
| 7151 static constexpr uint32_t V0 = (ValueMem)&Mask##Size; \ |
| 7152 const uint32_t ZeroFlag = allocateDword(); \ |
| 7153 \ |
| 7154 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ |
| 7155 Immediate((Value0)&Mask##Size)); \ |
| 7156 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ |
| 7157 Immediate((Value1)&Mask##Size)); \ |
| 7158 __ cmpxchg(IceType_i##Size, dwordAddress(T0), \ |
| 7159 GPRRegister::Encoded_Reg_##Src, LockedOrNot); \ |
| 7160 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ |
| 7161 \ |
| 7162 AssembledTest test = assemble(); \ |
| 7163 test.setDwordTo(T0, V0); \ |
| 7164 test.setDwordTo(ZeroFlag, uint32_t(0xFF)); \ |
| 7165 test.run(); \ |
| 7166 \ |
| 7167 if (V0 == (Mask##Size & (Value0))) { \ |
| 7168 ASSERT_EQ(uint32_t((Value1)&Mask##Size), test.contentsOfDword(T0)) \ |
| 7169 << TestString; \ |
| 7170 ASSERT_EQ(1u, test.contentsOfDword(ZeroFlag)) << TestString; \ |
| 7171 } else { \ |
| 7172 ASSERT_EQ(uint32_t((ValueMem)&Mask##Size), test.eax()) << TestString; \ |
| 7173 ASSERT_EQ(0u, test.contentsOfDword(ZeroFlag)) << TestString; \ |
| 7174 } \ |
| 7175 reset(); \ |
| 7176 } while (0) |
| 7177 |
| 7178 #define TestImplValue(Value0, Src, Value1, ValueMem, LockedOrNot) \ |
| 7179 do { \ |
| 7180 if (GPRRegister::Encoded_Reg_##Src < 4) { \ |
| 7181 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 8); \ |
| 7182 } \ |
| 7183 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 16); \ |
| 7184 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 32); \ |
| 7185 } while (0) |
| 7186 |
| 7187 #define TestImpl(Src, LockedOrNot) \ |
| 7188 do { \ |
| 7189 TestImplValue(0xFFFFFFFF, Src, 0x1, 0xFFFFFFFF, LockedOrNot); \ |
| 7190 TestImplValue(0x0FFF0F0F, Src, 0x1, 0xFFFFFFFF, LockedOrNot); \ |
| 7191 } while (0) |
| 7192 |
| 7193 TestImpl(ebx, Locked); |
| 7194 TestImpl(edx, NotLocked); |
| 7195 TestImpl(ecx, Locked); |
| 7196 TestImpl(ecx, NotLocked); |
| 7197 TestImpl(edx, Locked); |
| 7198 TestImpl(edx, NotLocked); |
| 7199 TestImpl(esi, Locked); |
| 7200 TestImpl(esi, NotLocked); |
| 7201 TestImpl(edi, Locked); |
| 7202 TestImpl(edi, NotLocked); |
| 7203 |
| 7204 #undef TestImpl |
| 7205 #undef TestImplValue |
| 7206 #undef TestImplAddrReg |
| 7207 } |
| 7208 |
| 7209 TEST_F(AssemblerX8632LowLevelTest, Cmpxchg) { |
| 7210 static constexpr bool NotLocked = false; |
| 7211 static constexpr bool Locked = true; |
| 7212 |
| 7213 // Ensures that cmpxchg emits a lock prefix accordingly. |
| 7214 { |
| 7215 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), |
| 7216 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 7217 static constexpr uint8_t ByteCountNotLocked8 = 7; |
| 7218 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
| 7219 verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x0F, 0xB0, 0x35, 0x00, 0xFF, |
| 7220 0x01, 0x00); |
| 7221 reset(); |
| 7222 |
| 7223 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), |
| 7224 GPRRegister::Encoded_Reg_esi, Locked); |
| 7225 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
| 7226 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
| 7227 verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x0F, 0xB0, 0x35, 0x00, |
| 7228 0xFF, 0x01, 0x00); |
| 7229 reset(); |
| 7230 } |
| 7231 |
| 7232 { |
| 7233 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), |
| 7234 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 7235 static constexpr uint8_t ByteCountNotLocked16 = 8; |
| 7236 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
| 7237 verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x0F, 0xB1, 0x35, 0x00, |
| 7238 0xFF, 0x01, 0x00); |
| 7239 reset(); |
| 7240 |
| 7241 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), |
| 7242 GPRRegister::Encoded_Reg_esi, Locked); |
| 7243 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
| 7244 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
| 7245 verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x0F, 0xB1, 0x35, |
| 7246 0x00, 0xFF, 0x01, 0x00); |
| 7247 reset(); |
| 7248 } |
| 7249 |
| 7250 { |
| 7251 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), |
| 7252 GPRRegister::Encoded_Reg_esi, NotLocked); |
| 7253 static constexpr uint8_t ByteCountNotLocked32 = 7; |
| 7254 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
| 7255 verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x0F, 0xB1, 0x35, 0x00, 0xFF, |
| 7256 0x01, 0x00); |
| 7257 reset(); |
| 7258 |
| 7259 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), |
| 7260 GPRRegister::Encoded_Reg_esi, Locked); |
| 7261 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
| 7262 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
| 7263 verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x0F, 0xB1, 0x35, 0x00, |
| 7264 0xFF, 0x01, 0x00); |
| 7265 reset(); |
| 7266 } |
| 7267 } |
| 7268 |
| 7269 TEST_F(AssemblerX8632Test, Set1ps) { |
| 7270 #define TestImpl(Xmm, Src, Imm) \ |
| 7271 do { \ |
| 7272 __ set1ps(XmmRegister::Encoded_Reg_##Xmm, GPRRegister::Encoded_Reg_##Src, \ |
| 7273 Immediate(Imm)); \ |
| 7274 \ |
| 7275 AssembledTest test = assemble(); \ |
| 7276 test.run(); \ |
| 7277 \ |
| 7278 const Dqword Expected((uint64_t(Imm) << 32) | uint32_t(Imm), \ |
| 7279 (uint64_t(Imm) << 32) | uint32_t(Imm)); \ |
| 7280 ASSERT_EQ(Expected, test.Xmm<Dqword>()) \ |
| 7281 << "(" #Xmm ", " #Src ", " #Imm ")"; \ |
| 7282 reset(); \ |
| 7283 } while (0) |
| 7284 |
| 7285 TestImpl(xmm0, ebx, 1); |
| 7286 TestImpl(xmm1, ecx, 2); |
| 7287 TestImpl(xmm2, edx, 3); |
| 7288 TestImpl(xmm3, esi, 4); |
| 7289 TestImpl(xmm4, edi, 5); |
| 7290 TestImpl(xmm5, eax, 6); |
| 7291 TestImpl(xmm6, ebx, 7); |
| 7292 TestImpl(xmm7, ecx, 8); |
| 7293 |
| 7294 #undef TestImpl |
| 7295 } |
| 7296 |
| 715 #undef __ | 7297 #undef __ |
| 716 | 7298 |
| 717 } // end of anonymous namespace | 7299 } // end of anonymous namespace |
| 718 } // end of namespace X8632 | 7300 } // end of namespace X8632 |
| 719 } // end of namespace Ice | 7301 } // end of namespace Ice |
| OLD | NEW |