Chromium Code Reviews| 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); |
|
jvoung (off chromium)
2015/07/23 17:59:36
Now that verifyBytes returns a bool, does this nee
John
2015/07/27 20:35:58
See the comment below.
| |
| 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(Src, Dst) \ | |
| 3747 do { \ | |
| 3748 TestArithPSXmmXmm(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3749 (0.55, 0.43, 0.23, 1.21), addps, +, float); \ | |
| 3750 TestArithPSXmmAddr(Src, (1.0, 100.0, -1000.0, 20.0), \ | |
| 3751 (0.55, 0.43, 0.23, 1.21), addps, +, float); \ | |
| 3752 TestArithPSXmmXmm(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3753 (0.55, 0.43, 0.23, 1.21), subps, -, float); \ | |
| 3754 TestArithPSXmmAddr(Src, (1.0, 100.0, -1000.0, 20.0), \ | |
| 3755 (0.55, 0.43, 0.23, 1.21), subps, -, float); \ | |
| 3756 TestArithPSXmmXmm(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3757 (0.55, 0.43, 0.23, 1.21), mulps, *, float); \ | |
| 3758 TestArithPSXmmAddr(Src, (1.0, 100.0, -1000.0, 20.0), \ | |
| 3759 (0.55, 0.43, 0.23, 1.21), mulps, *, float); \ | |
| 3760 TestArithPSXmmXmmUntyped(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3761 (0.55, 0.43, 0.23, 1.21), andps, &, float); \ | |
| 3762 TestArithPSXmmXmmUntyped(Src, (1.0, -1000.0), Dst, (0.55, 1.21), andpd, &, \ | |
| 3763 double); \ | |
| 3764 TestArithPSXmmAddrUntyped(Src, (1.0, -1000.0), (0.55, 1.21), andpd, &, \ | |
| 3765 double); \ | |
| 3766 TestArithPSXmmXmmUntyped(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3767 (0.55, 0.43, 0.23, 1.21), orps, |, float); \ | |
| 3768 TestArithPSXmmXmmUntyped(Src, (1.0, -1000.0), Dst, (0.55, 1.21), orpd, |, \ | |
| 3769 double); \ | |
| 3770 TestMinMaxPS(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3771 (0.55, 0.43, 0.23, 1.21), minps, float); \ | |
| 3772 TestMinMaxPS(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3773 (0.55, 0.43, 0.23, 1.21), maxps, float); \ | |
| 3774 TestMinMaxPS(Src, (1.0, -1000.0), Dst, (0.55, 1.21), minpd, double); \ | |
| 3775 TestMinMaxPS(Src, (1.0, -1000.0), Dst, (0.55, 1.21), maxpd, double); \ | |
| 3776 TestArithPSXmmXmmUntyped(Src, (1.0, 100.0, -1000.0, 20.0), Dst, \ | |
| 3777 (0.55, 0.43, 0.23, 1.21), xorps, ^, float); \ | |
| 3778 TestArithPSXmmAddrUntyped(Src, (1.0, 100.0, -1000.0, 20.0), \ | |
| 3779 (0.55, 0.43, 0.23, 1.21), xorps, ^, float); \ | |
| 3780 TestArithPSXmmXmmUntyped(Src, (1.0, -1000.0), Dst, (0.55, 1.21), xorpd, ^, \ | |
| 3781 double); \ | |
| 3782 TestArithPSXmmAddrUntyped(Src, (1.0, -1000.0), (0.55, 1.21), xorpd, ^, \ | |
| 3783 double); \ | |
| 3784 } while (0) | |
| 3785 | |
| 3786 #if 0 | |
| 3787 | |
| 3788 #endif | |
| 3789 | |
| 3790 TestArithPS(xmm0, xmm1); | |
| 3791 TestArithPS(xmm1, xmm2); | |
| 3792 TestArithPS(xmm2, xmm3); | |
| 3793 TestArithPS(xmm3, xmm4); | |
| 3794 TestArithPS(xmm4, xmm5); | |
| 3795 TestArithPS(xmm5, xmm6); | |
| 3796 TestArithPS(xmm6, xmm7); | |
| 3797 TestArithPS(xmm7, xmm0); | |
| 3798 | |
| 3799 #undef TestArithPs | |
| 3800 #undef TestMinMaxPS | |
| 3801 #undef TestArithPSXmmXmmUntyped | |
| 3802 #undef TestArithPSXmmAddr | |
| 3803 #undef TestArithPSXmmXmm | |
| 3804 } | |
| 3805 | |
| 3806 TEST_F(AssemblerX8632Test, Blending) { | |
| 3807 using f32 = float; | |
| 3808 using i8 = uint8_t; | |
| 3809 | |
| 3810 #define TestBlendingXmmXmm(Dst, Value0, Src, Value1, M /*ask*/, Inst, Type) \ | |
| 3811 do { \ | |
| 3812 static constexpr char TestString[] = \ | |
| 3813 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #M ", " #Inst \ | |
| 3814 ", " #Type ")"; \ | |
| 3815 const uint32_t T0 = allocateDqword(); \ | |
| 3816 const Dqword V0 Value0; \ | |
| 3817 const uint32_t T1 = allocateDqword(); \ | |
| 3818 const Dqword V1 Value1; \ | |
| 3819 const uint32_t Mask = allocateDqword(); \ | |
| 3820 const Dqword MaskValue M; \ | |
| 3821 \ | |
| 3822 __ movups(XmmRegister::Encoded_Reg_xmm0, dwordAddress(Mask)); \ | |
| 3823 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3824 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 3825 __ Inst(IceType_##Type, XmmRegister::Encoded_Reg_##Dst, \ | |
| 3826 XmmRegister::Encoded_Reg_##Src); \ | |
| 3827 \ | |
| 3828 AssembledTest test = assemble(); \ | |
| 3829 test.setDqwordTo(T0, V0); \ | |
| 3830 test.setDqwordTo(T1, V1); \ | |
| 3831 test.setDqwordTo(Mask, MaskValue); \ | |
| 3832 test.run(); \ | |
| 3833 \ | |
| 3834 ASSERT_EQ(packedAs<Type>(V0).blendWith(V1, MaskValue), test.Dst<Dqword>()) \ | |
| 3835 << TestString; \ | |
| 3836 reset(); \ | |
| 3837 } while (0) | |
| 3838 | |
| 3839 #define TestBlendingXmmAddr(Dst, Value0, Value1, M /*ask*/, Inst, Type) \ | |
| 3840 do { \ | |
| 3841 static constexpr char TestString[] = \ | |
| 3842 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #M ", " #Inst ", " #Type \ | |
| 3843 ")"; \ | |
| 3844 const uint32_t T0 = allocateDqword(); \ | |
| 3845 const Dqword V0 Value0; \ | |
| 3846 const uint32_t T1 = allocateDqword(); \ | |
| 3847 const Dqword V1 Value1; \ | |
| 3848 const uint32_t Mask = allocateDqword(); \ | |
| 3849 const Dqword MaskValue M; \ | |
| 3850 \ | |
| 3851 __ movups(XmmRegister::Encoded_Reg_xmm0, dwordAddress(Mask)); \ | |
| 3852 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3853 __ Inst(IceType_##Type, XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ | |
| 3854 \ | |
| 3855 AssembledTest test = assemble(); \ | |
| 3856 test.setDqwordTo(T0, V0); \ | |
| 3857 test.setDqwordTo(T1, V1); \ | |
| 3858 test.setDqwordTo(Mask, MaskValue); \ | |
| 3859 test.run(); \ | |
| 3860 \ | |
| 3861 ASSERT_EQ(packedAs<Type>(V0).blendWith(V1, MaskValue), test.Dst<Dqword>()) \ | |
| 3862 << TestString; \ | |
| 3863 reset(); \ | |
| 3864 } while (0) | |
| 3865 | |
| 3866 #define TestBlending(Src, Dst) \ | |
| 3867 do { \ | |
| 3868 TestBlendingXmmXmm( \ | |
| 3869 Dst, (1.0, 2.0, 1.0, 2.0), Src, (-1.0, -2.0, -1.0, -2.0), \ | |
| 3870 (uint64_t(0x8000000000000000ull), uint64_t(0x0000000080000000ull)), \ | |
| 3871 blendvps, f32); \ | |
| 3872 TestBlendingXmmAddr( \ | |
| 3873 Dst, (1.0, 2.0, 1.0, 2.0), (-1.0, -2.0, -1.0, -2.0), \ | |
| 3874 (uint64_t(0x8000000000000000ull), uint64_t(0x0000000080000000ull)), \ | |
| 3875 blendvps, f32); \ | |
| 3876 TestBlendingXmmXmm( \ | |
| 3877 Dst, \ | |
| 3878 (uint64_t(0xFFFFFFFFFFFFFFFFull), uint64_t(0xBBBBBBBBBBBBBBBBull)), \ | |
| 3879 Src, \ | |
| 3880 (uint64_t(0xAAAAAAAAAAAAAAAAull), uint64_t(0xEEEEEEEEEEEEEEEEull)), \ | |
| 3881 (uint64_t(0x8000000000000080ull), uint64_t(0x8080808000000000ull)), \ | |
| 3882 pblendvb, i8); \ | |
| 3883 TestBlendingXmmAddr( \ | |
| 3884 Dst, \ | |
| 3885 (uint64_t(0xFFFFFFFFFFFFFFFFull), uint64_t(0xBBBBBBBBBBBBBBBBull)), \ | |
| 3886 (uint64_t(0xAAAAAAAAAAAAAAAAull), uint64_t(0xEEEEEEEEEEEEEEEEull)), \ | |
| 3887 (uint64_t(0x8000000000000080ull), uint64_t(0x8080808000000000ull)), \ | |
| 3888 pblendvb, i8); \ | |
| 3889 } while (0) | |
| 3890 | |
| 3891 /* xmm0 is taken. It is the implicit mask . */ | |
| 3892 TestBlending(xmm1, xmm2); | |
| 3893 TestBlending(xmm2, xmm3); | |
| 3894 TestBlending(xmm3, xmm4); | |
| 3895 TestBlending(xmm4, xmm5); | |
| 3896 TestBlending(xmm5, xmm6); | |
| 3897 TestBlending(xmm6, xmm7); | |
| 3898 TestBlending(xmm7, xmm1); | |
| 3899 | |
| 3900 #undef TestBlending | |
| 3901 #undef TestBlendingXmmAddr | |
| 3902 #undef TestBlendingXmmXmm | |
| 3903 } | |
| 3904 | |
| 3905 TEST_F(AssemblerX8632Test, Cmpps) { | |
| 3906 #define TestCmppsXmmXmm(Dst, Src, C, Op) \ | |
| 3907 do { \ | |
| 3908 static constexpr char TestString[] = \ | |
| 3909 "(" #Src ", " #Dst ", " #C ", " #Op ")"; \ | |
| 3910 const uint32_t T0 = allocateDqword(); \ | |
| 3911 const Dqword V0(-1.0, 1.0, 3.14, 1024.5); \ | |
| 3912 const uint32_t T1 = allocateDqword(); \ | |
| 3913 const Dqword V1(-1.0, 1.0, 3.14, 1024.5); \ | |
| 3914 \ | |
| 3915 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3916 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 3917 __ cmpps(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ | |
| 3918 Cond::Cmpps_##C); \ | |
| 3919 \ | |
| 3920 AssembledTest test = assemble(); \ | |
| 3921 test.setDqwordTo(T0, V0); \ | |
| 3922 test.setDqwordTo(T1, V1); \ | |
| 3923 test.run(); \ | |
| 3924 \ | |
| 3925 ASSERT_EQ(packedAs<float>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ | |
| 3926 ; \ | |
| 3927 reset(); \ | |
| 3928 } while (0) | |
| 3929 | |
| 3930 #define TestCmppsXmmAddr(Dst, C, Op) \ | |
| 3931 do { \ | |
| 3932 static constexpr char TestString[] = "(" #Dst ", Addr, " #C ", " #Op ")"; \ | |
| 3933 const uint32_t T0 = allocateDqword(); \ | |
| 3934 const Dqword V0(-1.0, 1.0, 3.14, 1024.5); \ | |
| 3935 const uint32_t T1 = allocateDqword(); \ | |
| 3936 const Dqword V1(-1.0, 1.0, 3.14, 1024.5); \ | |
| 3937 \ | |
| 3938 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3939 __ cmpps(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1), \ | |
| 3940 Cond::Cmpps_##C); \ | |
| 3941 \ | |
| 3942 AssembledTest test = assemble(); \ | |
| 3943 test.setDqwordTo(T0, V0); \ | |
| 3944 test.setDqwordTo(T1, V1); \ | |
| 3945 test.run(); \ | |
| 3946 \ | |
| 3947 ASSERT_EQ(packedAs<float>(V0) Op V1, test.Dst<Dqword>()) << TestString; \ | |
| 3948 ; \ | |
| 3949 reset(); \ | |
| 3950 } while (0) | |
| 3951 | |
| 3952 #define TestCmppsOrdUnordXmmXmm(Dst, Src, C) \ | |
| 3953 do { \ | |
| 3954 static constexpr char TestString[] = "(" #Src ", " #Dst ", " #C ")"; \ | |
| 3955 const uint32_t T0 = allocateDqword(); \ | |
| 3956 const Dqword V0(1.0, 1.0, std::numeric_limits<float>::quiet_NaN(), \ | |
| 3957 std::numeric_limits<float>::quiet_NaN()); \ | |
| 3958 const uint32_t T1 = allocateDqword(); \ | |
| 3959 const Dqword V1(1.0, std::numeric_limits<float>::quiet_NaN(), 1.0, \ | |
| 3960 std::numeric_limits<float>::quiet_NaN()); \ | |
| 3961 \ | |
| 3962 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3963 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 3964 __ cmpps(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ | |
| 3965 Cond::Cmpps_##C); \ | |
| 3966 \ | |
| 3967 AssembledTest test = assemble(); \ | |
| 3968 test.setDqwordTo(T0, V0); \ | |
| 3969 test.setDqwordTo(T1, V1); \ | |
| 3970 test.run(); \ | |
| 3971 \ | |
| 3972 ASSERT_EQ(packedAs<float>(V0).C(V1), test.Dst<Dqword>()) << TestString; \ | |
| 3973 ; \ | |
| 3974 reset(); \ | |
| 3975 } while (0) | |
| 3976 | |
| 3977 #define TestCmppsOrdUnordXmmAddr(Dst, C) \ | |
| 3978 do { \ | |
| 3979 static constexpr char TestString[] = "(" #Dst ", " #C ")"; \ | |
| 3980 const uint32_t T0 = allocateDqword(); \ | |
| 3981 const Dqword V0(1.0, 1.0, std::numeric_limits<float>::quiet_NaN(), \ | |
| 3982 std::numeric_limits<float>::quiet_NaN()); \ | |
| 3983 const uint32_t T1 = allocateDqword(); \ | |
| 3984 const Dqword V1(1.0, std::numeric_limits<float>::quiet_NaN(), 1.0, \ | |
| 3985 std::numeric_limits<float>::quiet_NaN()); \ | |
| 3986 \ | |
| 3987 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 3988 __ cmpps(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1), \ | |
| 3989 Cond::Cmpps_##C); \ | |
| 3990 \ | |
| 3991 AssembledTest test = assemble(); \ | |
| 3992 test.setDqwordTo(T0, V0); \ | |
| 3993 test.setDqwordTo(T1, V1); \ | |
| 3994 test.run(); \ | |
| 3995 \ | |
| 3996 ASSERT_EQ(packedAs<float>(V0).C(V1), test.Dst<Dqword>()) << TestString; \ | |
| 3997 ; \ | |
| 3998 reset(); \ | |
| 3999 } while (0) | |
| 4000 | |
| 4001 #define TestCmpps(Dst, Src) \ | |
| 4002 do { \ | |
| 4003 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4004 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4005 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4006 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4007 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4008 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4009 TestCmppsOrdUnordXmmXmm(Dst, Src, unord); \ | |
| 4010 TestCmppsOrdUnordXmmAddr(Dst, unord); \ | |
| 4011 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4012 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4013 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4014 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4015 TestCmppsXmmXmm(Dst, Src, eq, == ); \ | |
| 4016 TestCmppsXmmAddr(Dst, eq, == ); \ | |
| 4017 TestCmppsOrdUnordXmmXmm(Dst, Src, unord); \ | |
| 4018 TestCmppsOrdUnordXmmAddr(Dst, unord); \ | |
| 4019 } while (0) | |
| 4020 | |
| 4021 TestCmpps(xmm0, xmm1); | |
| 4022 TestCmpps(xmm1, xmm2); | |
| 4023 TestCmpps(xmm2, xmm3); | |
| 4024 TestCmpps(xmm3, xmm4); | |
| 4025 TestCmpps(xmm4, xmm5); | |
| 4026 TestCmpps(xmm5, xmm6); | |
| 4027 TestCmpps(xmm6, xmm7); | |
| 4028 TestCmpps(xmm7, xmm0); | |
| 4029 | |
| 4030 #undef TestCmpps | |
| 4031 #undef TestCmppsOrdUnordXmmAddr | |
| 4032 #undef TestCmppsOrdUnordXmmXmm | |
| 4033 #undef TestCmppsXmmAddr | |
| 4034 #undef TestCmppsXmmXmm | |
| 4035 } | |
| 4036 | |
| 4037 TEST_F(AssemblerX8632Test, Sqrtps_Rsqrtps_Reciprocalps_Sqrtpd) { | |
| 4038 #define TestImplSingle(Dst, Inst, Expect) \ | |
| 4039 do { \ | |
| 4040 static constexpr char TestString[] = "(" #Dst ", " #Inst ")"; \ | |
| 4041 const uint32_t T0 = allocateDqword(); \ | |
| 4042 const Dqword V0(1.0, 4.0, 20.0, 3.14); \ | |
| 4043 \ | |
| 4044 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4045 __ Inst(XmmRegister::Encoded_Reg_##Dst); \ | |
| 4046 \ | |
| 4047 AssembledTest test = assemble(); \ | |
| 4048 test.setDqwordTo(T0, V0); \ | |
| 4049 test.run(); \ | |
| 4050 ASSERT_EQ(Dqword Expect, test.Dst<Dqword>()) << TestString; \ | |
| 4051 reset(); \ | |
| 4052 } while (0) | |
| 4053 | |
| 4054 #define TestImpl(Dst) \ | |
| 4055 do { \ | |
| 4056 TestImplSingle(Dst, sqrtps, (uint64_t(0x400000003F800000ull), \ | |
| 4057 uint64_t(0x3FE2D10B408F1BBDull))); \ | |
| 4058 TestImplSingle(Dst, rsqrtps, (uint64_t(0x3EFFF0003F7FF000ull), \ | |
| 4059 uint64_t(0x3F1078003E64F000ull))); \ | |
| 4060 TestImplSingle(Dst, reciprocalps, (uint64_t(0x3E7FF0003F7FF000ull), \ | |
| 4061 uint64_t(0x3EA310003D4CC000ull))); \ | |
| 4062 \ | |
| 4063 TestImplSingle(Dst, sqrtpd, (uint64_t(0x4036A09E9365F5F3ull), \ | |
| 4064 uint64_t(0x401C42FAE40282A8ull))); \ | |
| 4065 } while (0) | |
| 4066 | |
| 4067 TestImpl(xmm0); | |
| 4068 TestImpl(xmm1); | |
| 4069 TestImpl(xmm2); | |
| 4070 TestImpl(xmm3); | |
| 4071 TestImpl(xmm4); | |
| 4072 TestImpl(xmm5); | |
| 4073 TestImpl(xmm6); | |
| 4074 TestImpl(xmm7); | |
| 4075 | |
| 4076 #undef TestImpl | |
| 4077 #undef TestImplSingle | |
| 4078 } | |
| 4079 | |
| 4080 TEST_F(AssemblerX8632Test, Movhlps_Movlhps) { | |
| 4081 #define TestImplSingle(Dst, Src, Inst, Expect) \ | |
| 4082 do { \ | |
| 4083 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Inst ")"; \ | |
| 4084 const uint32_t T0 = allocateDqword(); \ | |
| 4085 const Dqword V0(uint64_t(0xAAAAAAAABBBBBBBBull), \ | |
| 4086 uint64_t(0xCCCCCCCCDDDDDDDDull)); \ | |
| 4087 const uint32_t T1 = allocateDqword(); \ | |
| 4088 const Dqword V1(uint64_t(0xEEEEEEEEFFFFFFFFull), \ | |
| 4089 uint64_t(0x9999999988888888ull)); \ | |
| 4090 \ | |
| 4091 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4092 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4093 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ | |
| 4094 \ | |
| 4095 AssembledTest test = assemble(); \ | |
| 4096 test.setDqwordTo(T0, V0); \ | |
| 4097 test.setDqwordTo(T1, V1); \ | |
| 4098 test.run(); \ | |
| 4099 \ | |
| 4100 ASSERT_EQ(Dqword Expect, test.Dst<Dqword>()) << TestString; \ | |
| 4101 reset(); \ | |
| 4102 } while (0) | |
| 4103 | |
| 4104 #define TestImpl(Dst, Src) \ | |
| 4105 do { \ | |
| 4106 TestImplSingle(Dst, Src, movhlps, (uint64_t(0x9999999988888888ull), \ | |
| 4107 uint64_t(0xCCCCCCCCDDDDDDDDull))); \ | |
| 4108 TestImplSingle(Dst, Src, movlhps, (uint64_t(0xAAAAAAAABBBBBBBBull), \ | |
| 4109 uint64_t(0xEEEEEEEEFFFFFFFFull))); \ | |
| 4110 } while (0) | |
| 4111 | |
| 4112 TestImpl(xmm0, xmm1); | |
| 4113 TestImpl(xmm1, xmm2); | |
| 4114 TestImpl(xmm2, xmm3); | |
| 4115 TestImpl(xmm3, xmm4); | |
| 4116 TestImpl(xmm4, xmm5); | |
| 4117 TestImpl(xmm5, xmm6); | |
| 4118 TestImpl(xmm6, xmm7); | |
| 4119 TestImpl(xmm7, xmm0); | |
| 4120 | |
| 4121 #undef TestImpl | |
| 4122 #undef TestImplSingle | |
| 4123 } | |
| 4124 | |
| 4125 TEST_F(AssemblerX8632Test, Unpck) { | |
| 4126 const Dqword V0(uint64_t(0xAAAAAAAABBBBBBBBull), | |
| 4127 uint64_t(0xCCCCCCCCDDDDDDDDull)); | |
| 4128 const Dqword V1(uint64_t(0xEEEEEEEEFFFFFFFFull), | |
| 4129 uint64_t(0x9999999988888888ull)); | |
| 4130 | |
| 4131 const Dqword unpcklpsExpected(uint64_t(0xFFFFFFFFBBBBBBBBull), | |
| 4132 uint64_t(0xEEEEEEEEAAAAAAAAull)); | |
| 4133 const Dqword unpcklpdExpected(uint64_t(0xAAAAAAAABBBBBBBBull), | |
| 4134 uint64_t(0xEEEEEEEEFFFFFFFFull)); | |
| 4135 const Dqword unpckhpsExpected(uint64_t(0x88888888DDDDDDDDull), | |
| 4136 uint64_t(0x99999999CCCCCCCCull)); | |
| 4137 const Dqword unpckhpdExpected(uint64_t(0xCCCCCCCCDDDDDDDDull), | |
| 4138 uint64_t(0x9999999988888888ull)); | |
| 4139 | |
| 4140 #define TestImplSingle(Dst, Src, Inst) \ | |
| 4141 do { \ | |
| 4142 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Inst ")"; \ | |
| 4143 const uint32_t T0 = allocateDqword(); \ | |
| 4144 const uint32_t T1 = allocateDqword(); \ | |
| 4145 \ | |
| 4146 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4147 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4148 __ Inst(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src); \ | |
| 4149 \ | |
| 4150 AssembledTest test = assemble(); \ | |
| 4151 test.setDqwordTo(T0, V0); \ | |
| 4152 test.setDqwordTo(T1, V1); \ | |
| 4153 test.run(); \ | |
| 4154 \ | |
| 4155 ASSERT_EQ(Inst##Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4156 reset(); \ | |
| 4157 } while (0) | |
| 4158 | |
| 4159 #define TestImpl(Dst, Src) \ | |
| 4160 do { \ | |
| 4161 TestImplSingle(Dst, Src, unpcklps); \ | |
| 4162 TestImplSingle(Dst, Src, unpcklpd); \ | |
| 4163 TestImplSingle(Dst, Src, unpckhps); \ | |
| 4164 TestImplSingle(Dst, Src, unpckhpd); \ | |
| 4165 } while (0) | |
| 4166 | |
| 4167 TestImpl(xmm0, xmm1); | |
| 4168 TestImpl(xmm1, xmm2); | |
| 4169 TestImpl(xmm2, xmm3); | |
| 4170 TestImpl(xmm3, xmm4); | |
| 4171 TestImpl(xmm4, xmm5); | |
| 4172 TestImpl(xmm5, xmm6); | |
| 4173 TestImpl(xmm6, xmm7); | |
| 4174 TestImpl(xmm7, xmm0); | |
| 4175 | |
| 4176 #undef TestImpl | |
| 4177 #undef TestImplSingle | |
| 4178 } | |
| 4179 | |
| 4180 TEST_F(AssemblerX8632Test, Shufp) { | |
| 4181 const Dqword V0(uint64_t(0x1111111122222222ull), | |
| 4182 uint64_t(0x5555555577777777ull)); | |
| 4183 const Dqword V1(uint64_t(0xAAAAAAAABBBBBBBBull), | |
| 4184 uint64_t(0xCCCCCCCCDDDDDDDDull)); | |
| 4185 | |
| 4186 const uint8_t pshufdImm = 0x63; | |
| 4187 const Dqword pshufdExpected(uint64_t(0xBBBBBBBBCCCCCCCCull), | |
| 4188 uint64_t(0xAAAAAAAADDDDDDDDull)); | |
| 4189 | |
| 4190 const uint8_t shufpsImm = 0xf9; | |
| 4191 const Dqword shufpsExpected(uint64_t(0x7777777711111111ull), | |
| 4192 uint64_t(0xCCCCCCCCCCCCCCCCull)); | |
| 4193 const Dqword shufpsUntypedExpected(uint64_t(0x7777777711111111ull), | |
| 4194 uint64_t(0xCCCCCCCCCCCCCCCCull)); | |
| 4195 | |
| 4196 const uint8_t shufpdImm = 0x02; | |
| 4197 const Dqword shufpdUntypedExpected(uint64_t(0x1111111122222222ull), | |
| 4198 uint64_t(0xCCCCCCCCDDDDDDDDull)); | |
| 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 TestImplSingleXmmXmmUntyped(Dst, Src, shufps); \ | |
| 4267 TestImplSingleXmmXmmUntyped(Dst, Src, shufpd); \ | |
| 4268 } while (0) | |
| 4269 | |
| 4270 TestImpl(xmm0, xmm1); | |
| 4271 TestImpl(xmm1, xmm2); | |
| 4272 TestImpl(xmm2, xmm3); | |
| 4273 TestImpl(xmm3, xmm4); | |
| 4274 TestImpl(xmm4, xmm5); | |
| 4275 TestImpl(xmm5, xmm6); | |
| 4276 TestImpl(xmm6, xmm7); | |
| 4277 TestImpl(xmm7, xmm0); | |
| 4278 | |
| 4279 #undef TestImpl | |
| 4280 #undef TestImplSingleXmmXmmUntyped | |
| 4281 #undef TestImplSingleXmmAddr | |
| 4282 #undef TestImplSingleXmmXmm | |
| 4283 } | |
| 4284 | |
| 4285 TEST_F(AssemblerX8632Test, Cvt) { | |
| 4286 const Dqword dq2ps32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); | |
| 4287 const Dqword dq2ps32SrcValue(-5, 3, 100, 200); | |
| 4288 const Dqword dq2ps32Expected(-5.0f, 3.0f, 100.0, 200.0); | |
| 4289 | |
| 4290 const Dqword dq2ps64DstValue(0.0f, 0.0f, -1.0f, -1.0f); | |
| 4291 const Dqword dq2ps64SrcValue(-5, 3, 100, 200); | |
| 4292 const Dqword dq2ps64Expected(-5.0f, 3.0f, 100.0, 200.0); | |
| 4293 | |
| 4294 const Dqword tps2dq32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); | |
| 4295 const Dqword tps2dq32SrcValue(-5.0f, 3.0f, 100.0, 200.0); | |
| 4296 const Dqword tps2dq32Expected(-5, 3, 100, 200); | |
| 4297 | |
| 4298 const Dqword tps2dq64DstValue(-1.0f, -1.0f, -1.0f, -1.0f); | |
| 4299 const Dqword tps2dq64SrcValue(-5.0f, 3.0f, 100.0, 200.0); | |
| 4300 const Dqword tps2dq64Expected(-5, 3, 100, 200); | |
| 4301 | |
| 4302 const Dqword si2ss32DstValue(-1.0f, -1.0f, -1.0f, -1.0f); | |
| 4303 const int32_t si2ss32SrcValue = 5; | |
| 4304 const Dqword si2ss32Expected(5.0f, -1.0f, -1.0f, -1.0f); | |
| 4305 | |
| 4306 const Dqword si2ss64DstValue(-1.0, -1.0); | |
| 4307 const int32_t si2ss64SrcValue = 5; | |
| 4308 const Dqword si2ss64Expected(5.0, -1.0); | |
| 4309 | |
| 4310 const int32_t tss2si32DstValue = 0xF00F0FF0; | |
| 4311 const Dqword tss2si32SrcValue(-5.0f, -1.0f, -1.0f, -1.0f); | |
| 4312 const int32_t tss2si32Expected = -5; | |
| 4313 | |
| 4314 const int32_t tss2si64DstValue = 0xF00F0FF0; | |
| 4315 const Dqword tss2si64SrcValue(-5.0, -1.0); | |
| 4316 const int32_t tss2si64Expected = -5; | |
| 4317 | |
| 4318 const Dqword float2float32DstValue(-1.0, -1.0); | |
| 4319 const Dqword float2float32SrcValue(-5.0, 3, 100, 200); | |
| 4320 const Dqword float2float32Expected(-5.0, -1.0); | |
| 4321 | |
| 4322 const Dqword float2float64DstValue(-1.0, -1.0, -1.0, -1.0); | |
| 4323 const Dqword float2float64SrcValue(-5.0, 3.0); | |
| 4324 const Dqword float2float64Expected(-5.0, -1.0, -1.0, -1.0); | |
| 4325 | |
| 4326 #define TestImplPXmmXmm(Dst, Src, Inst, Size) \ | |
| 4327 do { \ | |
| 4328 static constexpr char TestString[] = \ | |
| 4329 "(" #Dst ", " #Src ", cvt" #Inst ", f" #Size ")"; \ | |
| 4330 const uint32_t T0 = allocateDqword(); \ | |
| 4331 const uint32_t T1 = allocateDqword(); \ | |
| 4332 \ | |
| 4333 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4334 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4335 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4336 XmmRegister::Encoded_Reg_##Src); \ | |
| 4337 \ | |
| 4338 AssembledTest test = assemble(); \ | |
| 4339 test.setDqwordTo(T0, Inst##Size##DstValue); \ | |
| 4340 test.setDqwordTo(T1, Inst##Size##SrcValue); \ | |
| 4341 test.run(); \ | |
| 4342 \ | |
| 4343 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4344 reset(); \ | |
| 4345 } while (0) | |
| 4346 | |
| 4347 #define TestImplSXmmReg(Dst, GPR, Inst, Size) \ | |
| 4348 do { \ | |
| 4349 static constexpr char TestString[] = \ | |
| 4350 "(" #Dst ", " #GPR ", cvt" #Inst ", f" #Size ")"; \ | |
| 4351 const uint32_t T0 = allocateDqword(); \ | |
| 4352 \ | |
| 4353 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4354 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4355 Immediate(Inst##Size##SrcValue)); \ | |
| 4356 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4357 GPRRegister::Encoded_Reg_##GPR); \ | |
| 4358 \ | |
| 4359 AssembledTest test = assemble(); \ | |
| 4360 test.setDqwordTo(T0, Inst##Size##DstValue); \ | |
| 4361 test.run(); \ | |
| 4362 \ | |
| 4363 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4364 reset(); \ | |
| 4365 } while (0) | |
| 4366 | |
| 4367 #define TestImplSRegXmm(GPR, Src, Inst, Size) \ | |
| 4368 do { \ | |
| 4369 static constexpr char TestString[] = \ | |
| 4370 "(" #GPR ", " #Src ", cvt" #Inst ", f" #Size ")"; \ | |
| 4371 const uint32_t T0 = allocateDqword(); \ | |
| 4372 \ | |
| 4373 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4374 Immediate(Inst##Size##DstValue)); \ | |
| 4375 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ | |
| 4376 __ cvt##Inst(IceType_f##Size, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4377 XmmRegister::Encoded_Reg_##Src); \ | |
| 4378 \ | |
| 4379 AssembledTest test = assemble(); \ | |
| 4380 test.setDqwordTo(T0, Inst##Size##SrcValue); \ | |
| 4381 test.run(); \ | |
| 4382 \ | |
| 4383 ASSERT_EQ(static_cast<uint32_t>(Inst##Size##Expected), test.GPR()) \ | |
| 4384 << TestString; \ | |
| 4385 reset(); \ | |
| 4386 } while (0) | |
| 4387 | |
| 4388 #define TestImplPXmmAddr(Dst, Inst, Size) \ | |
| 4389 do { \ | |
| 4390 static constexpr char TestString[] = \ | |
| 4391 "(" #Dst ", Addr, cvt" #Inst ", f" #Size ")"; \ | |
| 4392 const uint32_t T0 = allocateDqword(); \ | |
| 4393 const uint32_t T1 = allocateDqword(); \ | |
| 4394 \ | |
| 4395 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4396 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4397 dwordAddress(T1)); \ | |
| 4398 \ | |
| 4399 AssembledTest test = assemble(); \ | |
| 4400 test.setDqwordTo(T0, Inst##Size##DstValue); \ | |
| 4401 test.setDqwordTo(T1, Inst##Size##SrcValue); \ | |
| 4402 test.run(); \ | |
| 4403 \ | |
| 4404 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4405 reset(); \ | |
| 4406 } while (0) | |
| 4407 | |
| 4408 #define TestImplSXmmAddr(Dst, Inst, Size) \ | |
| 4409 do { \ | |
| 4410 static constexpr char TestString[] = \ | |
| 4411 "(" #Dst ", Addr, cvt" #Inst ", f" #Size ")"; \ | |
| 4412 const uint32_t T0 = allocateDqword(); \ | |
| 4413 const uint32_t T1 = allocateDword(); \ | |
| 4414 \ | |
| 4415 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4416 __ cvt##Inst(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4417 dwordAddress(T1)); \ | |
| 4418 \ | |
| 4419 AssembledTest test = assemble(); \ | |
| 4420 test.setDqwordTo(T0, Inst##Size##DstValue); \ | |
| 4421 test.setDwordTo(T1, Inst##Size##SrcValue); \ | |
| 4422 test.run(); \ | |
| 4423 \ | |
| 4424 ASSERT_EQ(Inst##Size##Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4425 reset(); \ | |
| 4426 } while (0) | |
| 4427 | |
| 4428 #define TestImplSRegAddr(GPR, Inst, Size) \ | |
| 4429 do { \ | |
| 4430 static constexpr char TestString[] = \ | |
| 4431 "(" #GPR ", Addr, cvt" #Inst ", f" #Size ")"; \ | |
| 4432 const uint32_t T0 = allocateDqword(); \ | |
| 4433 \ | |
| 4434 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4435 Immediate(Inst##Size##DstValue)); \ | |
| 4436 __ cvt##Inst(IceType_f##Size, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4437 dwordAddress(T0)); \ | |
| 4438 \ | |
| 4439 AssembledTest test = assemble(); \ | |
| 4440 test.setDqwordTo(T0, Inst##Size##SrcValue); \ | |
| 4441 test.run(); \ | |
| 4442 \ | |
| 4443 ASSERT_EQ(static_cast<uint32_t>(Inst##Size##Expected), test.GPR()) \ | |
| 4444 << TestString; \ | |
| 4445 reset(); \ | |
| 4446 } while (0) | |
| 4447 | |
| 4448 #define TestImplSize(Dst, Src, GPR, Size) \ | |
| 4449 do { \ | |
| 4450 TestImplPXmmXmm(Dst, Src, dq2ps, Size); \ | |
| 4451 TestImplPXmmAddr(Src, dq2ps, Size); \ | |
| 4452 TestImplPXmmXmm(Dst, Src, tps2dq, Size); \ | |
| 4453 TestImplPXmmAddr(Src, tps2dq, Size); \ | |
| 4454 TestImplSXmmReg(Dst, GPR, si2ss, Size); \ | |
| 4455 TestImplSXmmAddr(Dst, si2ss, Size); \ | |
| 4456 TestImplSRegXmm(GPR, Src, tss2si, Size); \ | |
| 4457 TestImplSRegAddr(GPR, tss2si, Size); \ | |
| 4458 TestImplPXmmXmm(Dst, Src, float2float, Size); \ | |
| 4459 TestImplPXmmAddr(Src, float2float, Size); \ | |
| 4460 } while (0) | |
| 4461 | |
| 4462 #define TestImpl(Dst, Src, GPR) \ | |
| 4463 do { \ | |
| 4464 TestImplSize(Dst, Src, GPR, 32); \ | |
| 4465 TestImplSize(Dst, Src, GPR, 64); \ | |
| 4466 } while (0) | |
| 4467 | |
| 4468 TestImpl(xmm0, xmm1, eax); | |
| 4469 TestImpl(xmm1, xmm2, ebx); | |
| 4470 TestImpl(xmm2, xmm3, ecx); | |
| 4471 TestImpl(xmm3, xmm4, edx); | |
| 4472 TestImpl(xmm4, xmm5, esi); | |
| 4473 TestImpl(xmm5, xmm6, edi); | |
| 4474 TestImpl(xmm6, xmm7, eax); | |
| 4475 TestImpl(xmm7, xmm0, ebx); | |
| 4476 | |
| 4477 #undef TestImpl | |
| 4478 #undef TestImplSize | |
| 4479 #undef TestImplSRegAddr | |
| 4480 #undef TestImplSXmmAddr | |
| 4481 #undef TestImplPXmmAddr | |
| 4482 #undef TestImplSRegXmm | |
| 4483 #undef TestImplSXmmReg | |
| 4484 #undef TestImplPXmmXmm | |
| 4485 } | |
| 4486 | |
| 4487 TEST_F(AssemblerX8632Test, Ucomiss) { | |
| 4488 static constexpr float qnan32 = std::numeric_limits<float>::quiet_NaN(); | |
| 4489 static constexpr double qnan64 = std::numeric_limits<float>::quiet_NaN(); | |
| 4490 | |
| 4491 Dqword test32DstValue(0.0, qnan32, qnan32, qnan32); | |
| 4492 Dqword test32SrcValue(0.0, qnan32, qnan32, qnan32); | |
| 4493 | |
| 4494 Dqword test64DstValue(0.0, qnan64); | |
| 4495 Dqword test64SrcValue(0.0, qnan64); | |
| 4496 | |
| 4497 #define TestImplXmmXmm(Dst, Value0, Src, Value1, Size, CompType, BParity, \ | |
| 4498 BOther) \ | |
| 4499 do { \ | |
| 4500 static constexpr char NearBranch = AssemblerX8632::kNearJump; \ | |
| 4501 static constexpr char TestString[] = \ | |
| 4502 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ", " #CompType \ | |
| 4503 ", " #BParity ", " #BOther ")"; \ | |
| 4504 const uint32_t T0 = allocateDqword(); \ | |
| 4505 test##Size##DstValue.F##Size[0] = Value0; \ | |
| 4506 const uint32_t T1 = allocateDqword(); \ | |
| 4507 test##Size##SrcValue.F##Size[0] = Value1; \ | |
| 4508 const uint32_t ImmIfTrue = 0xBEEF; \ | |
| 4509 const uint32_t ImmIfFalse = 0xC0FFE; \ | |
| 4510 \ | |
| 4511 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4512 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4513 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfFalse)); \ | |
| 4514 __ ucomiss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4515 XmmRegister::Encoded_Reg_##Src); \ | |
| 4516 Label Done; \ | |
| 4517 __ j(Cond::Br_##BParity, &Done, NearBranch); \ | |
| 4518 __ j(Cond::Br_##BOther, &Done, NearBranch); \ | |
| 4519 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfTrue)); \ | |
| 4520 __ bind(&Done); \ | |
| 4521 \ | |
| 4522 AssembledTest test = assemble(); \ | |
| 4523 test.setDqwordTo(T0, test##Size##DstValue); \ | |
| 4524 test.setDqwordTo(T1, test##Size##SrcValue); \ | |
| 4525 test.run(); \ | |
| 4526 \ | |
| 4527 ASSERT_EQ(ImmIfTrue, test.eax()) << TestString; \ | |
| 4528 reset(); \ | |
| 4529 } while (0) | |
| 4530 | |
| 4531 #define TestImplXmmAddr(Dst, Value0, Value1, Size, CompType, BParity, BOther) \ | |
| 4532 do { \ | |
| 4533 static constexpr char NearBranch = AssemblerX8632::kNearJump; \ | |
| 4534 static constexpr char TestString[] = \ | |
| 4535 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Size ", " #CompType \ | |
| 4536 ", " #BParity ", " #BOther ")"; \ | |
| 4537 const uint32_t T0 = allocateDqword(); \ | |
| 4538 test##Size##DstValue.F##Size[0] = Value0; \ | |
| 4539 const uint32_t T1 = allocateDqword(); \ | |
| 4540 test##Size##SrcValue.F##Size[0] = Value1; \ | |
| 4541 const uint32_t ImmIfTrue = 0xBEEF; \ | |
| 4542 const uint32_t ImmIfFalse = 0xC0FFE; \ | |
| 4543 \ | |
| 4544 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4545 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfFalse)); \ | |
| 4546 __ ucomiss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4547 dwordAddress(T1)); \ | |
| 4548 Label Done; \ | |
| 4549 __ j(Cond::Br_##BParity, &Done, NearBranch); \ | |
| 4550 __ j(Cond::Br_##BOther, &Done, NearBranch); \ | |
| 4551 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(ImmIfTrue)); \ | |
| 4552 __ bind(&Done); \ | |
| 4553 \ | |
| 4554 AssembledTest test = assemble(); \ | |
| 4555 test.setDqwordTo(T0, test##Size##DstValue); \ | |
| 4556 test.setDqwordTo(T1, test##Size##SrcValue); \ | |
| 4557 test.run(); \ | |
| 4558 \ | |
| 4559 ASSERT_EQ(ImmIfTrue, test.eax()) << TestString; \ | |
| 4560 reset(); \ | |
| 4561 } while (0) | |
| 4562 | |
| 4563 #define TestImplCond(Dst, Value0, Src, Value1, Size, CompType, BParity, \ | |
| 4564 BOther) \ | |
| 4565 do { \ | |
| 4566 TestImplXmmXmm(Dst, Value0, Src, Value1, Size, CompType, BParity, BOther); \ | |
| 4567 TestImplXmmAddr(Dst, Value0, Value1, Size, CompType, BParity, BOther); \ | |
| 4568 } while (0) | |
| 4569 | |
| 4570 #define TestImplSize(Dst, Src, Size) \ | |
| 4571 do { \ | |
| 4572 TestImplCond(Dst, 1.0, Src, 1.0, Size, isEq, p, ne); \ | |
| 4573 TestImplCond(Dst, 1.0, Src, 2.0, Size, isNe, p, e); \ | |
| 4574 TestImplCond(Dst, 1.0, Src, 2.0, Size, isLe, p, a); \ | |
| 4575 TestImplCond(Dst, 1.0, Src, 1.0, Size, isLe, p, a); \ | |
| 4576 TestImplCond(Dst, 1.0, Src, 2.0, Size, isLt, p, ae); \ | |
| 4577 TestImplCond(Dst, 2.0, Src, 1.0, Size, isGe, p, b); \ | |
| 4578 TestImplCond(Dst, 1.0, Src, 1.0, Size, isGe, p, b); \ | |
| 4579 TestImplCond(Dst, 2.0, Src, 1.0, Size, isGt, p, be); \ | |
| 4580 TestImplCond(Dst, qnan##Size, Src, 1.0, Size, isUnord, np, o); \ | |
| 4581 TestImplCond(Dst, 1.0, Src, qnan##Size, Size, isUnord, np, s); \ | |
| 4582 TestImplCond(Dst, qnan##Size, Src, qnan##Size, Size, isUnord, np, s); \ | |
| 4583 } while (0) | |
| 4584 | |
| 4585 #define TestImpl(Dst, Src) \ | |
| 4586 do { \ | |
| 4587 TestImplSize(Dst, Src, 32); \ | |
| 4588 TestImplSize(Dst, Src, 64); \ | |
| 4589 } while (0) | |
| 4590 | |
| 4591 TestImpl(xmm0, xmm1); | |
| 4592 TestImpl(xmm1, xmm2); | |
| 4593 TestImpl(xmm2, xmm3); | |
| 4594 TestImpl(xmm3, xmm4); | |
| 4595 TestImpl(xmm4, xmm5); | |
| 4596 TestImpl(xmm5, xmm6); | |
| 4597 TestImpl(xmm6, xmm7); | |
| 4598 TestImpl(xmm7, xmm0); | |
| 4599 | |
| 4600 #undef TestImpl | |
| 4601 #undef TestImplSize | |
| 4602 #undef TestImplCond | |
| 4603 #undef TestImplXmmAddr | |
| 4604 #undef TestImplXmmXmm | |
| 4605 } | |
| 4606 | |
| 4607 TEST_F(AssemblerX8632Test, Movmsk) { | |
| 4608 #define TestMovmskGPRXmm(GPR, Src, Value1, Expected, Inst) \ | |
| 4609 do { \ | |
| 4610 static constexpr char TestString[] = \ | |
| 4611 "(" #GPR ", " #Src ", " #Value1 ", " #Expected ", " #Inst ")"; \ | |
| 4612 const uint32_t T0 = allocateDqword(); \ | |
| 4613 const Dqword V0 Value1; \ | |
| 4614 \ | |
| 4615 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ | |
| 4616 __ Inst(GPRRegister::Encoded_Reg_##GPR, XmmRegister::Encoded_Reg_##Src); \ | |
| 4617 \ | |
| 4618 AssembledTest test = assemble(); \ | |
| 4619 test.setDqwordTo(T0, V0); \ | |
| 4620 test.run(); \ | |
| 4621 \ | |
| 4622 ASSERT_EQ(Expected, test.GPR()) << TestString; \ | |
| 4623 reset(); \ | |
| 4624 } while (0) | |
| 4625 | |
| 4626 #define TestMovmsk(GPR, Src) \ | |
| 4627 do { \ | |
| 4628 TestMovmskGPRXmm(GPR, Src, (-1.0, 1.0, -1.0, 1.0), 0x05ul, movmskps); \ | |
| 4629 TestMovmskGPRXmm(GPR, Src, (1.0, -1.0), 0x02ul, movmskpd); \ | |
| 4630 } while (0) | |
| 4631 | |
| 4632 TestMovmsk(eax, xmm0); | |
| 4633 TestMovmsk(ebx, xmm1); | |
| 4634 TestMovmsk(ecx, xmm2); | |
| 4635 TestMovmsk(edx, xmm3); | |
| 4636 TestMovmsk(esi, xmm4); | |
| 4637 TestMovmsk(edi, xmm5); | |
| 4638 TestMovmsk(eax, xmm6); | |
| 4639 TestMovmsk(ebx, xmm7); | |
| 4640 | |
| 4641 #undef TestMovmskGPRXmm | |
| 4642 #undef TestMovmsk | |
| 4643 } | |
| 4644 | |
| 4645 TEST_F(AssemblerX8632Test, Sqrtss) { | |
| 4646 Dqword test32SrcValue(-100.0, -100.0, -100.0, -100.0); | |
| 4647 Dqword test32DstValue(-1.0, -1.0, -1.0, -1.0); | |
| 4648 | |
| 4649 Dqword test64SrcValue(-100.0, -100.0); | |
| 4650 Dqword test64DstValue(-1.0, -1.0); | |
| 4651 | |
| 4652 #define TestSqrtssXmmXmm(Dst, Src, Value1, Result, Size) \ | |
| 4653 do { \ | |
| 4654 static constexpr char TestString[] = \ | |
| 4655 "(" #Dst ", " #Src ", " #Value1 ", " #Result ", " #Size ")"; \ | |
| 4656 const uint32_t T0 = allocateDqword(); \ | |
| 4657 test##Size##SrcValue.F##Size[0] = Value1; \ | |
| 4658 const uint32_t T1 = allocateDqword(); \ | |
| 4659 \ | |
| 4660 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ | |
| 4661 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ | |
| 4662 __ sqrtss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4663 XmmRegister::Encoded_Reg_##Src); \ | |
| 4664 \ | |
| 4665 AssembledTest test = assemble(); \ | |
| 4666 test.setDqwordTo(T0, test##Size##SrcValue); \ | |
| 4667 test.setDqwordTo(T1, test##Size##DstValue); \ | |
| 4668 test.run(); \ | |
| 4669 \ | |
| 4670 Dqword Expected = test##Size##DstValue; \ | |
| 4671 Expected.F##Size[0] = Result; \ | |
| 4672 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4673 reset(); \ | |
| 4674 } while (0) | |
| 4675 | |
| 4676 #define TestSqrtssXmmAddr(Dst, Value1, Result, Size) \ | |
| 4677 do { \ | |
| 4678 static constexpr char TestString[] = \ | |
| 4679 "(" #Dst ", Addr, " #Value1 ", " #Result ", " #Size ")"; \ | |
| 4680 const uint32_t T0 = allocateDqword(); \ | |
| 4681 test##Size##SrcValue.F##Size[0] = Value1; \ | |
| 4682 const uint32_t T1 = allocateDqword(); \ | |
| 4683 \ | |
| 4684 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ | |
| 4685 __ sqrtss(IceType_f##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4686 dwordAddress(T0)); \ | |
| 4687 \ | |
| 4688 AssembledTest test = assemble(); \ | |
| 4689 test.setDqwordTo(T0, test##Size##SrcValue); \ | |
| 4690 test.setDqwordTo(T1, test##Size##DstValue); \ | |
| 4691 test.run(); \ | |
| 4692 \ | |
| 4693 Dqword Expected = test##Size##DstValue; \ | |
| 4694 Expected.F##Size[0] = Result; \ | |
| 4695 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4696 reset(); \ | |
| 4697 } while (0) | |
| 4698 | |
| 4699 #define TestSqrtssSize(Dst, Src, Size) \ | |
| 4700 do { \ | |
| 4701 TestSqrtssXmmXmm(Dst, Src, 4.0, 2.0, Size); \ | |
| 4702 TestSqrtssXmmAddr(Dst, 4.0, 2.0, Size); \ | |
| 4703 TestSqrtssXmmXmm(Dst, Src, 9.0, 3.0, Size); \ | |
| 4704 TestSqrtssXmmAddr(Dst, 9.0, 3.0, Size); \ | |
| 4705 TestSqrtssXmmXmm(Dst, Src, 100.0, 10.0, Size); \ | |
| 4706 TestSqrtssXmmAddr(Dst, 100.0, 10.0, Size); \ | |
| 4707 } | |
| 4708 | |
| 4709 #define TestSqrtss(Dst, Src) \ | |
| 4710 do { \ | |
| 4711 TestSqrtssSizeS(Dst, Src, 32); \ | |
| 4712 TestSqrtssSizeS(Dst, Src, 64); \ | |
| 4713 } while (0) | |
| 4714 | |
| 4715 #undef TestSqrtss | |
| 4716 #undef TestSqrtssSize | |
| 4717 #undef TestSqrtssXmmAddr | |
| 4718 #undef TestSqrtssXmmXmm | |
| 4719 } | |
| 4720 | |
| 4721 TEST_F(AssemblerX8632Test, Insertps) { | |
| 4722 #define TestInsertpsXmmXmmImm(Dst, Value0, Src, Value1, Imm, Expected) \ | |
| 4723 do { \ | |
| 4724 static constexpr char TestString[] = \ | |
| 4725 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Imm ", " #Expected \ | |
| 4726 ")"; \ | |
| 4727 const uint32_t T0 = allocateDqword(); \ | |
| 4728 const Dqword V0 Value0; \ | |
| 4729 const uint32_t T1 = allocateDqword(); \ | |
| 4730 const Dqword V1 Value1; \ | |
| 4731 \ | |
| 4732 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4733 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4734 __ insertps(IceType_v4f32, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4735 XmmRegister::Encoded_Reg_##Src, Immediate(Imm)); \ | |
| 4736 \ | |
| 4737 AssembledTest test = assemble(); \ | |
| 4738 test.setDqwordTo(T0, V0); \ | |
| 4739 test.setDqwordTo(T1, V1); \ | |
| 4740 test.run(); \ | |
| 4741 \ | |
| 4742 ASSERT_EQ(Dqword Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4743 reset(); \ | |
| 4744 } while (0) | |
| 4745 | |
| 4746 #define TestInsertpsXmmAddrImm(Dst, Value0, Value1, Imm, Expected) \ | |
| 4747 do { \ | |
| 4748 static constexpr char TestString[] = \ | |
| 4749 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Imm ", " #Expected ")"; \ | |
| 4750 const uint32_t T0 = allocateDqword(); \ | |
| 4751 const Dqword V0 Value0; \ | |
| 4752 const uint32_t T1 = allocateDqword(); \ | |
| 4753 const Dqword V1 Value1; \ | |
| 4754 \ | |
| 4755 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4756 __ insertps(IceType_v4f32, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4757 dwordAddress(T1), Immediate(Imm)); \ | |
| 4758 \ | |
| 4759 AssembledTest test = assemble(); \ | |
| 4760 test.setDqwordTo(T0, V0); \ | |
| 4761 test.setDqwordTo(T1, V1); \ | |
| 4762 test.run(); \ | |
| 4763 \ | |
| 4764 ASSERT_EQ(Dqword Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4765 reset(); \ | |
| 4766 } while (0) | |
| 4767 | |
| 4768 #define TestInsertps(Dst, Src) \ | |
| 4769 do { \ | |
| 4770 TestInsertpsXmmXmmImm( \ | |
| 4771 Dst, (uint64_t(-1), uint64_t(-1)), Src, \ | |
| 4772 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ | |
| 4773 0x99, \ | |
| 4774 (uint64_t(0xDDDDDDDD00000000ull), uint64_t(0x00000000FFFFFFFFull))); \ | |
| 4775 TestInsertpsXmmAddrImm( \ | |
| 4776 Dst, (uint64_t(-1), uint64_t(-1)), \ | |
| 4777 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ | |
| 4778 0x99, \ | |
| 4779 (uint64_t(0xBBBBBBBB00000000ull), uint64_t(0x00000000FFFFFFFFull))); \ | |
| 4780 TestInsertpsXmmXmmImm( \ | |
| 4781 Dst, (uint64_t(-1), uint64_t(-1)), Src, \ | |
| 4782 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ | |
| 4783 0x9D, \ | |
| 4784 (uint64_t(0xDDDDDDDD00000000ull), uint64_t(0x0000000000000000ull))); \ | |
| 4785 TestInsertpsXmmAddrImm( \ | |
| 4786 Dst, (uint64_t(-1), uint64_t(-1)), \ | |
| 4787 (uint64_t(0xAAAAAAAABBBBBBBBull), uint64_t(0xCCCCCCCCDDDDDDDDull)), \ | |
| 4788 0x9D, \ | |
| 4789 (uint64_t(0xBBBBBBBB00000000ull), uint64_t(0x0000000000000000ull))); \ | |
| 4790 } while (0) | |
| 4791 | |
| 4792 TestInsertps(xmm0, xmm1); | |
| 4793 | |
| 4794 #undef TestInsertps | |
| 4795 #undef TestInsertpsXmmXmmAddr | |
| 4796 #undef TestInsertpsXmmXmmImm | |
| 4797 } | |
| 4798 | |
| 4799 TEST_F(AssemblerX8632Test, Pinsr) { | |
| 4800 static constexpr uint8_t Mask32 = 0x03; | |
| 4801 static constexpr uint8_t Mask16 = 0x07; | |
| 4802 static constexpr uint8_t Mask8 = 0x0F; | |
| 4803 | |
| 4804 #define TestPinsrXmmGPRImm(Dst, Value0, GPR, Value1, Imm, Size) \ | |
| 4805 do { \ | |
| 4806 static constexpr char TestString[] = \ | |
| 4807 "(" #Dst ", " #Value0 ", " #GPR ", " #Value1 ", " #Imm ", " #Size ")"; \ | |
| 4808 const uint32_t T0 = allocateDqword(); \ | |
| 4809 const Dqword V0 Value0; \ | |
| 4810 \ | |
| 4811 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4812 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##GPR, Immediate(Value1)); \ | |
| 4813 __ pinsr(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4814 GPRRegister::Encoded_Reg_##GPR, Immediate(Imm)); \ | |
| 4815 \ | |
| 4816 AssembledTest test = assemble(); \ | |
| 4817 test.setDqwordTo(T0, V0); \ | |
| 4818 test.run(); \ | |
| 4819 \ | |
| 4820 constexpr uint8_t sel = (Imm)&Mask##Size; \ | |
| 4821 Dqword Expected = V0; \ | |
| 4822 Expected.U##Size[sel] = Value1; \ | |
| 4823 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4824 reset(); \ | |
| 4825 } while (0) | |
| 4826 | |
| 4827 #define TestPinsrXmmAddrImm(Dst, Value0, Value1, Imm, Size) \ | |
| 4828 do { \ | |
| 4829 static constexpr char TestString[] = \ | |
| 4830 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Imm ", " #Size ")"; \ | |
| 4831 const uint32_t T0 = allocateDqword(); \ | |
| 4832 const Dqword V0 Value0; \ | |
| 4833 const uint32_t T1 = allocateDword(); \ | |
| 4834 const uint32_t V1 = Value1; \ | |
| 4835 \ | |
| 4836 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4837 __ pinsr(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4838 dwordAddress(T1), Immediate(Imm)); \ | |
| 4839 \ | |
| 4840 AssembledTest test = assemble(); \ | |
| 4841 test.setDqwordTo(T0, V0); \ | |
| 4842 test.setDwordTo(T1, V1); \ | |
| 4843 test.run(); \ | |
| 4844 \ | |
| 4845 constexpr uint8_t sel = (Imm)&Mask##Size; \ | |
| 4846 Dqword Expected = V0; \ | |
| 4847 Expected.U##Size[sel] = Value1; \ | |
| 4848 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4849 reset(); \ | |
| 4850 } while (0) | |
| 4851 | |
| 4852 #define TestPinsrSize(Dst, GPR, Value1, Imm, Size) \ | |
| 4853 do { \ | |
| 4854 TestPinsrXmmGPRImm(Dst, (uint64_t(0xAAAAAAAABBBBBBBBull), \ | |
| 4855 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ | |
| 4856 GPR, Value1, Imm, Size); \ | |
| 4857 TestPinsrXmmAddrImm(Dst, (uint64_t(0xAAAAAAAABBBBBBBBull), \ | |
| 4858 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ | |
| 4859 Value1, Imm, Size); \ | |
| 4860 } while (0) | |
| 4861 | |
| 4862 #define TestPinsr(Src, Dst) \ | |
| 4863 do { \ | |
| 4864 TestPinsrSize(Src, Dst, 0xEE, 0x03, 8); \ | |
| 4865 TestPinsrSize(Src, Dst, 0xFFEE, 0x03, 16); \ | |
| 4866 TestPinsrSize(Src, Dst, 0xC0FFEE, 0x03, 32); \ | |
| 4867 } while (0) | |
| 4868 | |
| 4869 TestPinsr(xmm0, eax); | |
| 4870 TestPinsr(xmm1, ebx); | |
| 4871 TestPinsr(xmm2, ecx); | |
| 4872 TestPinsr(xmm3, edx); | |
| 4873 TestPinsr(xmm4, esi); | |
| 4874 TestPinsr(xmm5, edi); | |
| 4875 TestPinsr(xmm6, eax); | |
| 4876 TestPinsr(xmm7, ebx); | |
| 4877 | |
| 4878 #undef TestPinsr | |
| 4879 #undef TestPinsrSize | |
| 4880 #undef TestPinsrXmmAddrImm | |
| 4881 #undef TestPinsrXmmGPRImm | |
| 4882 } | |
| 4883 | |
| 4884 TEST_F(AssemblerX8632Test, Pextr) { | |
| 4885 static constexpr uint8_t Mask32 = 0x03; | |
| 4886 static constexpr uint8_t Mask16 = 0x07; | |
| 4887 static constexpr uint8_t Mask8 = 0x0F; | |
| 4888 | |
| 4889 #define TestPextrGPRXmmImm(GPR, Src, Value1, Imm, Size) \ | |
| 4890 do { \ | |
| 4891 static constexpr char TestString[] = \ | |
| 4892 "(" #GPR ", " #Src ", " #Value1 ", " #Imm ", " #Size ")"; \ | |
| 4893 const uint32_t T0 = allocateDqword(); \ | |
| 4894 const Dqword V0 Value1; \ | |
| 4895 \ | |
| 4896 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ | |
| 4897 __ pextr(IceType_i##Size, GPRRegister::Encoded_Reg_##GPR, \ | |
| 4898 XmmRegister::Encoded_Reg_##Src, Immediate(Imm)); \ | |
| 4899 \ | |
| 4900 AssembledTest test = assemble(); \ | |
| 4901 test.setDqwordTo(T0, V0); \ | |
| 4902 test.run(); \ | |
| 4903 \ | |
| 4904 constexpr uint8_t sel = (Imm)&Mask##Size; \ | |
| 4905 ASSERT_EQ(V0.U##Size[sel], test.GPR()) << TestString; \ | |
| 4906 reset(); \ | |
| 4907 } while (0) | |
| 4908 | |
| 4909 #define TestPextrSize(GPR, Src, Value1, Imm, Size) \ | |
| 4910 do { \ | |
| 4911 TestPextrGPRXmmImm(GPR, Src, (uint64_t(0xAAAAAAAABBBBBBBBull), \ | |
| 4912 uint64_t(0xFFFFFFFFDDDDDDDDull)), \ | |
| 4913 Imm, Size); \ | |
| 4914 } while (0) | |
| 4915 | |
| 4916 #define TestPextr(Src, Dst) \ | |
| 4917 do { \ | |
| 4918 TestPextrSize(Src, Dst, 0xEE, 0x03, 8); \ | |
| 4919 TestPextrSize(Src, Dst, 0xFFEE, 0x03, 16); \ | |
| 4920 TestPextrSize(Src, Dst, 0xC0FFEE, 0x03, 32); \ | |
| 4921 } while (0) | |
| 4922 | |
| 4923 TestPextr(eax, xmm0); | |
| 4924 TestPextr(ebx, xmm1); | |
| 4925 TestPextr(ecx, xmm2); | |
| 4926 TestPextr(edx, xmm3); | |
| 4927 TestPextr(esi, xmm4); | |
| 4928 TestPextr(edi, xmm5); | |
| 4929 TestPextr(eax, xmm6); | |
| 4930 TestPextr(ebx, xmm7); | |
| 4931 | |
| 4932 #undef TestPextr | |
| 4933 #undef TestPextrSize | |
| 4934 #undef TestPextrXmmGPRImm | |
| 4935 } | |
| 4936 | |
| 4937 TEST_F(AssemblerX8632Test, Pmovsxdq) { | |
| 4938 #define TestPmovsxdqXmmXmm(Dst, Src, Value1) \ | |
| 4939 do { \ | |
| 4940 static constexpr char TestString[] = "(" #Dst ", " #Src ", " #Value1 ")"; \ | |
| 4941 const uint32_t T0 = allocateDqword(); \ | |
| 4942 const Dqword V0 Value1; \ | |
| 4943 const uint32_t T1 = allocateDqword(); \ | |
| 4944 const Dqword V1(uint64_t(0), uint64_t(0)); \ | |
| 4945 \ | |
| 4946 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T0)); \ | |
| 4947 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T1)); \ | |
| 4948 __ pmovsxdq(XmmRegister::Encoded_Reg_##Dst, \ | |
| 4949 XmmRegister::Encoded_Reg_##Src); \ | |
| 4950 \ | |
| 4951 AssembledTest test = assemble(); \ | |
| 4952 test.setDqwordTo(T0, V0); \ | |
| 4953 test.setDqwordTo(T1, V1); \ | |
| 4954 test.run(); \ | |
| 4955 \ | |
| 4956 const Dqword Expected(uint64_t(V0.I32[0]), uint64_t(V0.I32[1])); \ | |
| 4957 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 4958 reset(); \ | |
| 4959 } while (0) | |
| 4960 | |
| 4961 #define TestPmovsxdq(Dst, Src) \ | |
| 4962 do { \ | |
| 4963 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x700000007FFFFFFFull), \ | |
| 4964 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ | |
| 4965 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x800000007FFFFFFFull), \ | |
| 4966 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ | |
| 4967 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x70000000FFFFFFFFull), \ | |
| 4968 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ | |
| 4969 TestPmovsxdqXmmXmm(Dst, Src, (uint64_t(0x80000000FFFFFFFFull), \ | |
| 4970 uint64_t(0xAAAAAAAAEEEEEEEEull))); \ | |
| 4971 } while (0) | |
| 4972 | |
| 4973 TestPmovsxdq(xmm0, xmm1); | |
| 4974 TestPmovsxdq(xmm1, xmm2); | |
| 4975 TestPmovsxdq(xmm2, xmm3); | |
| 4976 TestPmovsxdq(xmm3, xmm4); | |
| 4977 TestPmovsxdq(xmm4, xmm5); | |
| 4978 TestPmovsxdq(xmm5, xmm6); | |
| 4979 TestPmovsxdq(xmm6, xmm7); | |
| 4980 TestPmovsxdq(xmm7, xmm0); | |
| 4981 | |
| 4982 #undef TestPmovsxdq | |
| 4983 #undef TestPmovsxdqXmmXmm | |
| 4984 } | |
| 4985 | |
| 4986 TEST_F(AssemblerX8632Test, Pcmpeq_Pcmpgt) { | |
| 4987 #define TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, Inst, Op) \ | |
| 4988 do { \ | |
| 4989 static constexpr char TestString[] = \ | |
| 4990 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ", " #Op ")"; \ | |
| 4991 const uint32_t T0 = allocateDqword(); \ | |
| 4992 const Dqword V0 Value0; \ | |
| 4993 const uint32_t T1 = allocateDqword(); \ | |
| 4994 const Dqword V1 Value1; \ | |
| 4995 \ | |
| 4996 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 4997 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 4998 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 4999 XmmRegister::Encoded_Reg_##Src); \ | |
| 5000 \ | |
| 5001 AssembledTest test = assemble(); \ | |
| 5002 test.setDqwordTo(T0, V0); \ | |
| 5003 test.setDqwordTo(T1, V1); \ | |
| 5004 test.run(); \ | |
| 5005 \ | |
| 5006 Dqword Expected(uint64_t(0), uint64_t(0)); \ | |
| 5007 static constexpr uint8_t ArraySize = \ | |
| 5008 sizeof(Dqword) / sizeof(uint##Size##_t); \ | |
| 5009 for (uint8_t i = 0; i < ArraySize; ++i) { \ | |
| 5010 Expected.I##Size[i] = (V1.I##Size[i] Op V0.I##Size[i]) ? -1 : 0; \ | |
| 5011 } \ | |
| 5012 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 5013 reset(); \ | |
| 5014 } while (0) | |
| 5015 | |
| 5016 #define TestPcmpXmmAddr(Dst, Value0, Value1, Size, Inst, Op) \ | |
| 5017 do { \ | |
| 5018 static constexpr char TestString[] = \ | |
| 5019 "(" #Dst ", " #Value0 ", Addr, " #Value1 ", " #Size ", " #Op ")"; \ | |
| 5020 const uint32_t T0 = allocateDqword(); \ | |
| 5021 const Dqword V0 Value0; \ | |
| 5022 const uint32_t T1 = allocateDqword(); \ | |
| 5023 const Dqword V1 Value1; \ | |
| 5024 \ | |
| 5025 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 5026 __ Inst(IceType_i##Size, XmmRegister::Encoded_Reg_##Dst, \ | |
| 5027 dwordAddress(T1)); \ | |
| 5028 \ | |
| 5029 AssembledTest test = assemble(); \ | |
| 5030 test.setDqwordTo(T0, V0); \ | |
| 5031 test.setDqwordTo(T1, V1); \ | |
| 5032 test.run(); \ | |
| 5033 \ | |
| 5034 Dqword Expected(uint64_t(0), uint64_t(0)); \ | |
| 5035 static constexpr uint8_t ArraySize = \ | |
| 5036 sizeof(Dqword) / sizeof(uint##Size##_t); \ | |
| 5037 for (uint8_t i = 0; i < ArraySize; ++i) { \ | |
| 5038 Expected.I##Size[i] = (V1.I##Size[i] Op V0.I##Size[i]) ? -1 : 0; \ | |
| 5039 } \ | |
| 5040 ASSERT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 5041 reset(); \ | |
| 5042 } while (0) | |
| 5043 | |
| 5044 #define TestPcmpValues(Dst, Value0, Src, Value1, Size) \ | |
| 5045 do { \ | |
| 5046 TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, pcmpeq, == ); \ | |
| 5047 TestPcmpXmmAddr(Dst, Value0, Value1, Size, pcmpeq, == ); \ | |
| 5048 TestPcmpXmmXmm(Dst, Value0, Src, Value1, Size, pcmpgt, < ); \ | |
| 5049 TestPcmpXmmAddr(Dst, Value0, Value1, Size, pcmpgt, < ); \ | |
| 5050 } while (0) | |
| 5051 | |
| 5052 #define TestPcmpSize(Dst, Src, Size) \ | |
| 5053 do { \ | |
| 5054 TestPcmpValues(Dst, (uint64_t(0x8888888888888888ull), \ | |
| 5055 uint64_t(0x0000000000000000ull)), \ | |
| 5056 Src, (uint64_t(0x0000008800008800ull), \ | |
| 5057 uint64_t(0xFFFFFFFFFFFFFFFFull)), \ | |
| 5058 Size); \ | |
| 5059 TestPcmpValues(Dst, (uint64_t(0x123567ABAB55DE01ull), \ | |
| 5060 uint64_t(0x12345abcde12345Aull)), \ | |
| 5061 Src, (uint64_t(0x0000008800008800ull), \ | |
| 5062 uint64_t(0xAABBCCDD1234321Aull)), \ | |
| 5063 Size); \ | |
| 5064 } while (0) | |
| 5065 | |
| 5066 #define TestPcmp(Dst, Src) \ | |
| 5067 do { \ | |
| 5068 TestPcmpSize(xmm0, xmm1, 8); \ | |
| 5069 TestPcmpSize(xmm0, xmm1, 16); \ | |
| 5070 TestPcmpSize(xmm0, xmm1, 32); \ | |
| 5071 } while (0) | |
| 5072 | |
| 5073 TestPcmp(xmm0, xmm1); | |
| 5074 TestPcmp(xmm1, xmm2); | |
| 5075 TestPcmp(xmm2, xmm3); | |
| 5076 TestPcmp(xmm3, xmm4); | |
| 5077 TestPcmp(xmm4, xmm5); | |
| 5078 TestPcmp(xmm5, xmm6); | |
| 5079 TestPcmp(xmm6, xmm7); | |
| 5080 TestPcmp(xmm7, xmm0); | |
| 5081 | |
| 5082 #undef TestPcmp | |
| 5083 #undef TestPcmpSize | |
| 5084 #undef TestPcmpValues | |
| 5085 #undef TestPcmpXmmAddr | |
| 5086 #undef TestPcmpXmmXmm | |
| 5087 } | |
| 5088 | |
| 5089 TEST_F(AssemblerX8632Test, Roundsd) { | |
| 5090 #define TestRoundsdXmmXmm(Dst, Src, Mode, Input, RN) \ | |
| 5091 do { \ | |
| 5092 static constexpr char TestString[] = \ | |
| 5093 "(" #Dst ", " #Src ", " #Mode ", " #Input ", " #RN ")"; \ | |
| 5094 const uint32_t T0 = allocateDqword(); \ | |
| 5095 const Dqword V0(-3.0, -3.0); \ | |
| 5096 const uint32_t T1 = allocateDqword(); \ | |
| 5097 const Dqword V1(double(Input), -123.4); \ | |
| 5098 \ | |
| 5099 __ movups(XmmRegister::Encoded_Reg_##Dst, dwordAddress(T0)); \ | |
| 5100 __ movups(XmmRegister::Encoded_Reg_##Src, dwordAddress(T1)); \ | |
| 5101 __ roundsd(XmmRegister::Encoded_Reg_##Dst, XmmRegister::Encoded_Reg_##Src, \ | |
| 5102 AssemblerX8632::k##Mode); \ | |
| 5103 \ | |
| 5104 AssembledTest test = assemble(); \ | |
| 5105 test.setDqwordTo(T0, V0); \ | |
| 5106 test.setDqwordTo(T1, V1); \ | |
| 5107 test.run(); \ | |
| 5108 \ | |
| 5109 const Dqword Expected(double(RN), -3.0); \ | |
| 5110 EXPECT_EQ(Expected, test.Dst<Dqword>()) << TestString; \ | |
| 5111 reset(); \ | |
| 5112 } while (0) | |
| 5113 | |
| 5114 #define TestRoundsd(Dst, Src) \ | |
| 5115 do { \ | |
| 5116 TestRoundsdXmmXmm(Dst, Src, RoundToNearest, 5.51, 6); \ | |
| 5117 TestRoundsdXmmXmm(Dst, Src, RoundToNearest, 5.49, 5); \ | |
| 5118 TestRoundsdXmmXmm(Dst, Src, RoundDown, 5.51, 5); \ | |
| 5119 TestRoundsdXmmXmm(Dst, Src, RoundUp, 5.49, 6); \ | |
| 5120 TestRoundsdXmmXmm(Dst, Src, RoundToZero, 5.49, 5); \ | |
| 5121 TestRoundsdXmmXmm(Dst, Src, RoundToZero, 5.51, 5); \ | |
| 5122 } while (0) | |
| 5123 | |
| 5124 TestRoundsd(xmm0, xmm1); | |
| 5125 TestRoundsd(xmm1, xmm2); | |
| 5126 TestRoundsd(xmm2, xmm3); | |
| 5127 TestRoundsd(xmm3, xmm4); | |
| 5128 TestRoundsd(xmm4, xmm5); | |
| 5129 TestRoundsd(xmm5, xmm6); | |
| 5130 TestRoundsd(xmm6, xmm7); | |
| 5131 TestRoundsd(xmm7, xmm0); | |
| 5132 | |
| 5133 #undef TestRoundsd | |
| 5134 #undef TestRoundsdXmmXmm | |
| 5135 } | |
| 5136 | |
| 5137 TEST_F(AssemblerX8632Test, Test) { | |
| 5138 static constexpr uint32_t Mask8 = 0xFF; | |
| 5139 static constexpr uint32_t Mask16 = 0xFFFF; | |
| 5140 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 5141 | |
| 5142 #define TestImplRegReg(Dst, Value0, Src, Value1, Size) \ | |
| 5143 do { \ | |
| 5144 static constexpr bool NearJump = true; \ | |
| 5145 static constexpr char TestString[] = \ | |
| 5146 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ | |
| 5147 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ | |
| 5148 static constexpr uint32_t ValueIfFalse = 0x11111111; \ | |
| 5149 \ | |
| 5150 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5151 Immediate(Value0)); \ | |
| 5152 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5153 Immediate(Value1)); \ | |
| 5154 __ test(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5155 GPRRegister::Encoded_Reg_##Src); \ | |
| 5156 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5157 Immediate(ValueIfFalse)); \ | |
| 5158 Label Done; \ | |
| 5159 __ j(Cond::Br_e, &Done, NearJump); \ | |
| 5160 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5161 Immediate(ValueIfTrue)); \ | |
| 5162 __ bind(&Done); \ | |
| 5163 \ | |
| 5164 AssembledTest test = assemble(); \ | |
| 5165 test.run(); \ | |
| 5166 \ | |
| 5167 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ | |
| 5168 : ValueIfFalse, \ | |
| 5169 test.Dst()) \ | |
| 5170 << TestString; \ | |
| 5171 reset(); \ | |
| 5172 } while (0) | |
| 5173 | |
| 5174 #define TestImplRegImm(Dst, Value0, Imm, Size) \ | |
| 5175 do { \ | |
| 5176 static constexpr bool NearJump = true; \ | |
| 5177 static constexpr char TestString[] = \ | |
| 5178 "(" #Dst ", " #Value0 ", " #Imm ", " #Size ")"; \ | |
| 5179 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ | |
| 5180 static constexpr uint32_t ValueIfFalse = 0x11111111; \ | |
| 5181 \ | |
| 5182 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5183 Immediate(Value0)); \ | |
| 5184 __ test(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5185 Immediate((Imm)&Mask##Size)); \ | |
| 5186 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5187 Immediate(ValueIfFalse)); \ | |
| 5188 Label Done; \ | |
| 5189 __ j(Cond::Br_e, &Done, NearJump); \ | |
| 5190 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5191 Immediate(ValueIfTrue)); \ | |
| 5192 __ bind(&Done); \ | |
| 5193 \ | |
| 5194 AssembledTest test = assemble(); \ | |
| 5195 test.run(); \ | |
| 5196 \ | |
| 5197 ASSERT_EQ(((Value0)&Mask##Size) & ((Imm)&Mask##Size) ? ValueIfTrue \ | |
| 5198 : ValueIfFalse, \ | |
| 5199 test.Dst()) \ | |
| 5200 << TestString; \ | |
| 5201 reset(); \ | |
| 5202 } while (0) | |
| 5203 | |
| 5204 #define TestImplAddrReg(Value0, Src, Value1, Size) \ | |
| 5205 do { \ | |
| 5206 static constexpr bool NearJump = true; \ | |
| 5207 static constexpr char TestString[] = \ | |
| 5208 "(Addr, " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ | |
| 5209 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ | |
| 5210 static constexpr uint32_t ValueIfFalse = 0x11111111; \ | |
| 5211 const uint32_t T0 = allocateDword(); \ | |
| 5212 \ | |
| 5213 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5214 Immediate(Value1)); \ | |
| 5215 __ test(IceType_i##Size, dwordAddress(T0), \ | |
| 5216 GPRRegister::Encoded_Reg_##Src); \ | |
| 5217 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfFalse)); \ | |
| 5218 Label Done; \ | |
| 5219 __ j(Cond::Br_e, &Done, NearJump); \ | |
| 5220 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfTrue)); \ | |
| 5221 __ bind(&Done); \ | |
| 5222 \ | |
| 5223 AssembledTest test = assemble(); \ | |
| 5224 test.setDwordTo(T0, uint32_t(Value0)); \ | |
| 5225 test.run(); \ | |
| 5226 \ | |
| 5227 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ | |
| 5228 : ValueIfFalse, \ | |
| 5229 test.contentsOfDword(T0)) \ | |
| 5230 << TestString; \ | |
| 5231 reset(); \ | |
| 5232 } while (0) | |
| 5233 | |
| 5234 #define TestImplAddrImm(Value0, Value1, Size) \ | |
| 5235 do { \ | |
| 5236 static constexpr bool NearJump = true; \ | |
| 5237 static constexpr char TestString[] = \ | |
| 5238 "(Addr, " #Value0 ", " #Value1 ", " #Size ")"; \ | |
| 5239 static constexpr uint32_t ValueIfTrue = 0xBEEFFEEB; \ | |
| 5240 static constexpr uint32_t ValueIfFalse = 0x11111111; \ | |
| 5241 const uint32_t T0 = allocateDword(); \ | |
| 5242 \ | |
| 5243 __ test(IceType_i##Size, dwordAddress(T0), \ | |
| 5244 Immediate((Value1)&Mask##Size)); \ | |
| 5245 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfFalse)); \ | |
| 5246 Label Done; \ | |
| 5247 __ j(Cond::Br_e, &Done, NearJump); \ | |
| 5248 __ mov(IceType_i32, dwordAddress(T0), Immediate(ValueIfTrue)); \ | |
| 5249 __ bind(&Done); \ | |
| 5250 \ | |
| 5251 AssembledTest test = assemble(); \ | |
| 5252 test.setDwordTo(T0, uint32_t(Value0)); \ | |
| 5253 test.run(); \ | |
| 5254 \ | |
| 5255 ASSERT_EQ(((Value0)&Mask##Size) & ((Value1)&Mask##Size) ? ValueIfTrue \ | |
| 5256 : ValueIfFalse, \ | |
| 5257 test.contentsOfDword(T0)) \ | |
| 5258 << TestString; \ | |
| 5259 reset(); \ | |
| 5260 } while (0) | |
| 5261 | |
| 5262 #define TestImplValues(Dst, Value0, Src, Value1, Size) \ | |
| 5263 do { \ | |
| 5264 TestImplRegReg(Dst, Value0, Src, Value1, Size); \ | |
| 5265 TestImplRegImm(Dst, Value0, Value1, Size); \ | |
| 5266 TestImplAddrReg(Value0, Src, Value1, Size); \ | |
| 5267 TestImplAddrImm(Value0, Value1, Size); \ | |
| 5268 } while (0) | |
| 5269 | |
| 5270 #define TestImplSize(Dst, Src, Size) \ | |
| 5271 do { \ | |
| 5272 TestImplValues(Dst, 0xF0F12101, Src, 0x00000000, Size); \ | |
| 5273 TestImplValues(Dst, 0xF0000000, Src, 0xF0000000, Size); \ | |
| 5274 TestImplValues(Dst, 0x0F00000F, Src, 0xF00000F0, Size); \ | |
| 5275 } while (0) | |
| 5276 | |
| 5277 #define TestImpl(Dst, Src) \ | |
| 5278 do { \ | |
| 5279 TestImplSize(Dst, Src, 8); \ | |
| 5280 TestImplSize(Dst, Src, 16); \ | |
| 5281 TestImplSize(Dst, Src, 32); \ | |
| 5282 } while (0) | |
| 5283 | |
| 5284 TestImpl(eax, ebx); | |
| 5285 TestImpl(ebx, ecx); | |
| 5286 TestImpl(ecx, edx); | |
| 5287 TestImpl(edx, esi); | |
| 5288 TestImpl(esi, edi); | |
| 5289 TestImpl(edi, eax); | |
| 5290 | |
| 5291 #undef TestImpl | |
| 5292 #undef TestImplSize | |
| 5293 #undef TestImplValues | |
| 5294 #undef TestImplAddrImm | |
| 5295 #undef TestImplAddrReg | |
| 5296 #undef TestImplRegImm | |
| 5297 #undef TestImplRegReg | |
| 5298 } | |
| 5299 | |
| 5300 // No mull/div because x86. | |
| 5301 // No shift because x86. | |
| 5302 TEST_F(AssemblerX8632Test, Arith_most) { | |
| 5303 static constexpr uint32_t Mask8 = 0xFF; | |
| 5304 static constexpr uint32_t Mask16 = 0xFFFF; | |
| 5305 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 5306 | |
| 5307 #define TestImplRegReg(Inst, Dst, Value0, Src, Value1, Type, Size, Op) \ | |
| 5308 do { \ | |
| 5309 static constexpr char TestString[] = \ | |
| 5310 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 \ | |
| 5311 ", " #Type #Size "_t, " #Op ")"; \ | |
| 5312 \ | |
| 5313 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5314 Immediate(Value0)); \ | |
| 5315 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5316 Immediate(Value1)); \ | |
| 5317 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5318 GPRRegister::Encoded_Reg_##Src); \ | |
| 5319 \ | |
| 5320 AssembledTest test = assemble(); \ | |
| 5321 test.run(); \ | |
| 5322 \ | |
| 5323 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ | |
| 5324 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ | |
| 5325 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ | |
| 5326 Mask##Size &test.Dst()) \ | |
| 5327 << TestString; \ | |
| 5328 reset(); \ | |
| 5329 } while (0) | |
| 5330 | |
| 5331 #define TestImplRegAddr(Inst, Dst, Value0, Value1, Type, Size, Op) \ | |
| 5332 do { \ | |
| 5333 static constexpr char TestString[] = \ | |
| 5334 "(" #Inst ", " #Dst ", " #Value0 ", Addr, " #Value1 ", " #Type #Size \ | |
| 5335 "_t, " #Op ")"; \ | |
| 5336 const uint32_t T0 = allocateDword(); \ | |
| 5337 const uint32_t V0 = Value1; \ | |
| 5338 \ | |
| 5339 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5340 Immediate(Value0)); \ | |
| 5341 __ mov(IceType_i##Size, dwordAddress(T0), Immediate(Value1)); \ | |
| 5342 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5343 dwordAddress(T0)); \ | |
| 5344 \ | |
| 5345 AssembledTest test = assemble(); \ | |
| 5346 test.setDwordTo(T0, V0); \ | |
| 5347 test.run(); \ | |
| 5348 \ | |
| 5349 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ | |
| 5350 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ | |
| 5351 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ | |
| 5352 Mask##Size &test.Dst()) \ | |
| 5353 << TestString; \ | |
| 5354 reset(); \ | |
| 5355 } while (0) | |
| 5356 | |
| 5357 #define TestImplRegImm(Inst, Dst, Value0, Imm, Type, Size, Op) \ | |
| 5358 do { \ | |
| 5359 static constexpr char TestString[] = \ | |
| 5360 "(" #Inst ", " #Dst ", " #Value0 ", Imm(" #Imm "), " #Type #Size \ | |
| 5361 "_t, " #Op ")"; \ | |
| 5362 \ | |
| 5363 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5364 Immediate(Value0)); \ | |
| 5365 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5366 Immediate((Imm)&Mask##Size)); \ | |
| 5367 \ | |
| 5368 AssembledTest test = assemble(); \ | |
| 5369 test.run(); \ | |
| 5370 \ | |
| 5371 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ | |
| 5372 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ | |
| 5373 Op static_cast<Type##Size##_t>((Imm)&Mask##Size)), \ | |
| 5374 Mask##Size &test.Dst()) \ | |
| 5375 << TestString; \ | |
| 5376 reset(); \ | |
| 5377 } while (0) | |
| 5378 | |
| 5379 #define TestImplAddrReg(Inst, Value0, Src, Value1, Type, Size, Op) \ | |
| 5380 do { \ | |
| 5381 static constexpr char TestString[] = \ | |
| 5382 "(" #Inst ", Addr, " #Value0 ", " #Src ", " #Value1 ", " #Type #Size \ | |
| 5383 "_t, " #Op ")"; \ | |
| 5384 const uint32_t T0 = allocateDword(); \ | |
| 5385 const uint32_t V0 = Value0; \ | |
| 5386 \ | |
| 5387 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5388 Immediate(Value1)); \ | |
| 5389 __ Inst(IceType_i##Size, dwordAddress(T0), \ | |
| 5390 GPRRegister::Encoded_Reg_##Src); \ | |
| 5391 \ | |
| 5392 AssembledTest test = assemble(); \ | |
| 5393 test.setDwordTo(T0, V0); \ | |
| 5394 test.run(); \ | |
| 5395 \ | |
| 5396 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ | |
| 5397 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ | |
| 5398 Op static_cast<Type##Size##_t>((Value1)&Mask##Size)), \ | |
| 5399 Mask##Size &test.contentsOfDword(T0)) \ | |
| 5400 << TestString; \ | |
| 5401 reset(); \ | |
| 5402 } while (0) | |
| 5403 | |
| 5404 #define TestImplAddrImm(Inst, Value0, Imm, Type, Size, Op) \ | |
| 5405 do { \ | |
| 5406 static constexpr char TestString[] = \ | |
| 5407 "(" #Inst ", Addr, " #Value0 ", Imm, " #Imm ", " #Type #Size \ | |
| 5408 "_t, " #Op ")"; \ | |
| 5409 const uint32_t T0 = allocateDword(); \ | |
| 5410 const uint32_t V0 = Value0; \ | |
| 5411 \ | |
| 5412 __ Inst(IceType_i##Size, dwordAddress(T0), Immediate((Imm)&Mask##Size)); \ | |
| 5413 \ | |
| 5414 AssembledTest test = assemble(); \ | |
| 5415 test.setDwordTo(T0, V0); \ | |
| 5416 test.run(); \ | |
| 5417 \ | |
| 5418 ASSERT_EQ(Mask##Size &static_cast<uint32_t>( \ | |
| 5419 static_cast<Type##Size##_t>((Value0)&Mask##Size) \ | |
| 5420 Op static_cast<Type##Size##_t>((Imm)&Mask##Size)), \ | |
| 5421 Mask##Size &test.contentsOfDword(T0)) \ | |
| 5422 << TestString; \ | |
| 5423 reset(); \ | |
| 5424 } while (0) | |
| 5425 | |
| 5426 #define TestImplOp(Inst, Dst, Value0, Src, Value1, Type, Size, Op) \ | |
| 5427 do { \ | |
| 5428 TestImplRegReg(Inst, Dst, Value0, Src, Value1, Type, Size, Op); \ | |
| 5429 TestImplRegAddr(Inst, Dst, Value0, Value1, Type, Size, Op); \ | |
| 5430 TestImplRegImm(Inst, Dst, Value0, Value1, Type, Size, Op); \ | |
| 5431 TestImplAddrReg(Inst, Value0, Src, Value1, Type, Size, Op); \ | |
| 5432 TestImplAddrImm(Inst, Value0, Value1, Type, Size, Op); \ | |
| 5433 } while (0) | |
| 5434 | |
| 5435 #define TestImplValues(Dst, Value0, Src, Value1, Size) \ | |
| 5436 do { \ | |
| 5437 TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \ | |
| 5438 TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \ | |
| 5439 TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, | ); \ | |
| 5440 TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, | ); \ | |
| 5441 TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \ | |
| 5442 TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \ | |
| 5443 TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \ | |
| 5444 TestImplOp(add, Dst, Value0, Src, Value1, uint, Size, +); \ | |
| 5445 TestImplOp(sub, Dst, Value0, Src, Value1, int, Size, -); \ | |
| 5446 TestImplOp(sub, Dst, Value0, Src, Value1, uint, Size, -); \ | |
| 5447 } while (0) | |
| 5448 | |
| 5449 #define TestImplSize(Dst, Src, Size) \ | |
| 5450 do { \ | |
| 5451 TestImplValues(Dst, 0xF0F12101, Src, 0x00000000, Size); \ | |
| 5452 TestImplValues(Dst, 0xF0000000, Src, 0xF0000000, Size); \ | |
| 5453 TestImplValues(Dst, 0x0F00000F, Src, 0xF0000070, Size); \ | |
| 5454 TestImplValues(Dst, 0x0F00F00F, Src, 0xF000F070, Size); \ | |
| 5455 } while (0) | |
| 5456 | |
| 5457 #define TestImpl(Dst, Src) \ | |
| 5458 do { \ | |
| 5459 if (GPRRegister::Encoded_Reg_##Src <= 3 && \ | |
| 5460 GPRRegister::Encoded_Reg_##Dst <= 3) { \ | |
| 5461 TestImplSize(Dst, Src, 8); \ | |
| 5462 } \ | |
| 5463 TestImplSize(Dst, Src, 16); \ | |
| 5464 TestImplSize(Dst, Src, 32); \ | |
| 5465 } while (0) | |
| 5466 | |
| 5467 TestImpl(eax, ebx); | |
| 5468 TestImpl(ebx, ecx); | |
| 5469 TestImpl(ecx, edx); | |
| 5470 TestImpl(edx, esi); | |
| 5471 TestImpl(esi, edi); | |
| 5472 TestImpl(edi, eax); | |
| 5473 | |
| 5474 #undef TestImpl | |
| 5475 #undef TestImplSize | |
| 5476 #undef TestImplValues | |
| 5477 #undef TestImplOp | |
| 5478 #undef TestImplAddrImm | |
| 5479 #undef TestImplAddrReg | |
| 5480 #undef TestImplRegImm | |
| 5481 #undef TestImplRegAddr | |
| 5482 #undef TestImplRegReg | |
| 5483 } | |
| 5484 | |
| 5485 TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { | |
| 5486 const uint32_t Mask8 = 0x000000FF; | |
| 5487 const uint32_t Mask16 = 0x0000FFFF; | |
| 5488 const uint32_t Mask32 = 0xFFFFFFFF; | |
| 5489 | |
| 5490 const uint64_t ResultMask8 = 0x000000000000FFFFull; | |
| 5491 const uint64_t ResultMask16 = 0x00000000FFFFFFFFull; | |
| 5492 const uint64_t ResultMask32 = 0xFFFFFFFFFFFFFFFFull; | |
| 5493 | |
| 5494 #define TestImplRegReg(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, \ | |
| 5495 Op, Size) \ | |
| 5496 do { \ | |
| 5497 static_assert(Size == 8 || Size == 16 || Size == 32, \ | |
| 5498 "Invalid size " #Size); \ | |
| 5499 static constexpr char TestString[] = \ | |
| 5500 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 ", " #Src0 \ | |
| 5501 ", " #Src1 ", " #Value1 ", " #Op ", " #Size ")"; \ | |
| 5502 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5503 Immediate(uint64_t(Value0) & Mask##Size)); \ | |
| 5504 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5505 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ | |
| 5506 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src0, \ | |
| 5507 Immediate(uint64_t(Value1) & Mask##Size)); \ | |
| 5508 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src1, \ | |
| 5509 Immediate((uint64_t(Value1) >> Size) & Mask##Size)); \ | |
| 5510 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5511 GPRRegister::Encoded_Reg_##Src0); \ | |
| 5512 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5513 GPRRegister::Encoded_Reg_##Src1); \ | |
| 5514 \ | |
| 5515 AssembledTest test = assemble(); \ | |
| 5516 test.run(); \ | |
| 5517 \ | |
| 5518 static constexpr uint64_t Result = \ | |
| 5519 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ | |
| 5520 ResultMask##Size); \ | |
| 5521 static constexpr uint32_t Expected0 = Result & Mask##Size; \ | |
| 5522 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ | |
| 5523 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ | |
| 5524 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ | |
| 5525 reset(); \ | |
| 5526 } while (0) | |
| 5527 | |
| 5528 #define TestImplRegAddr(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size) \ | |
| 5529 do { \ | |
| 5530 static_assert(Size == 8 || Size == 16 || Size == 32, \ | |
| 5531 "Invalid size " #Size); \ | |
| 5532 static constexpr char TestString[] = \ | |
| 5533 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 \ | |
| 5534 ", Addr, " #Value1 ", " #Op ", " #Size ")"; \ | |
| 5535 const uint32_t T0 = allocateDword(); \ | |
| 5536 const uint32_t V0 = uint64_t(Value1) & Mask##Size; \ | |
| 5537 const uint32_t T1 = allocateDword(); \ | |
| 5538 const uint32_t V1 = (uint64_t(Value1) >> Size) & Mask##Size; \ | |
| 5539 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5540 Immediate(uint64_t(Value0) & Mask##Size)); \ | |
| 5541 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5542 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ | |
| 5543 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5544 dwordAddress(T0)); \ | |
| 5545 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5546 dwordAddress(T1)); \ | |
| 5547 \ | |
| 5548 AssembledTest test = assemble(); \ | |
| 5549 test.setDwordTo(T0, V0); \ | |
| 5550 test.setDwordTo(T1, V1); \ | |
| 5551 test.run(); \ | |
| 5552 \ | |
| 5553 static constexpr uint64_t Result = \ | |
| 5554 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ | |
| 5555 ResultMask##Size); \ | |
| 5556 static constexpr uint32_t Expected0 = Result & Mask##Size; \ | |
| 5557 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ | |
| 5558 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ | |
| 5559 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ | |
| 5560 reset(); \ | |
| 5561 } while (0) | |
| 5562 | |
| 5563 #define TestImplRegImm(Inst0, Inst1, Dst0, Dst1, Value0, Imm, Op, Size) \ | |
| 5564 do { \ | |
| 5565 static_assert(Size == 8 || Size == 16 || Size == 32, \ | |
| 5566 "Invalid size " #Size); \ | |
| 5567 static constexpr char TestString[] = \ | |
| 5568 "(" #Inst0 ", " #Inst1 ", " #Dst0 ", " #Dst1 ", " #Value0 \ | |
| 5569 ", Imm(" #Imm "), " #Op ", " #Size ")"; \ | |
| 5570 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5571 Immediate(uint64_t(Value0) & Mask##Size)); \ | |
| 5572 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5573 Immediate((uint64_t(Value0) >> Size) & Mask##Size)); \ | |
| 5574 __ Inst0(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst0, \ | |
| 5575 Immediate(uint64_t(Imm) & Mask##Size)); \ | |
| 5576 __ Inst1(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 5577 Immediate((uint64_t(Imm) >> Size) & Mask##Size)); \ | |
| 5578 \ | |
| 5579 AssembledTest test = assemble(); \ | |
| 5580 test.run(); \ | |
| 5581 \ | |
| 5582 static constexpr uint64_t Result = \ | |
| 5583 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ | |
| 5584 ResultMask##Size); \ | |
| 5585 static constexpr uint32_t Expected0 = Result & Mask##Size; \ | |
| 5586 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ | |
| 5587 ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ | |
| 5588 ASSERT_EQ(Expected1, test.Dst1()) << TestString << ": 1"; \ | |
| 5589 reset(); \ | |
| 5590 } while (0) | |
| 5591 | |
| 5592 #define TestImplAddrReg(Inst0, Inst1, Value0, Src0, Src1, Value1, Op, Size) \ | |
| 5593 do { \ | |
| 5594 static_assert(Size == 8 || Size == 16 || Size == 32, \ | |
| 5595 "Invalid size " #Size); \ | |
| 5596 static constexpr char TestString[] = \ | |
| 5597 "(" #Inst0 ", " #Inst1 ", Addr, " #Value0 ", " #Src0 ", " #Src1 \ | |
| 5598 ", " #Value1 ", " #Op ", " #Size ")"; \ | |
| 5599 const uint32_t T0 = allocateDword(); \ | |
| 5600 const uint32_t V0 = uint64_t(Value0) & Mask##Size; \ | |
| 5601 const uint32_t T1 = allocateDword(); \ | |
| 5602 const uint32_t V1 = (uint64_t(Value0) >> Size) & Mask##Size; \ | |
| 5603 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src0, \ | |
| 5604 Immediate(uint64_t(Value1) & Mask##Size)); \ | |
| 5605 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src1, \ | |
| 5606 Immediate((uint64_t(Value1) >> Size) & Mask##Size)); \ | |
| 5607 __ Inst0(IceType_i##Size, dwordAddress(T0), \ | |
| 5608 GPRRegister::Encoded_Reg_##Src0); \ | |
| 5609 __ Inst1(IceType_i##Size, dwordAddress(T1), \ | |
| 5610 GPRRegister::Encoded_Reg_##Src1); \ | |
| 5611 \ | |
| 5612 AssembledTest test = assemble(); \ | |
| 5613 test.setDwordTo(T0, V0); \ | |
| 5614 test.setDwordTo(T1, V1); \ | |
| 5615 test.run(); \ | |
| 5616 \ | |
| 5617 static constexpr uint64_t Result = \ | |
| 5618 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ | |
| 5619 ResultMask##Size); \ | |
| 5620 static constexpr uint32_t Expected0 = Result & Mask##Size; \ | |
| 5621 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ | |
| 5622 ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ | |
| 5623 ASSERT_EQ(Expected1, test.contentsOfDword(T1)) << TestString << ": 1"; \ | |
| 5624 reset(); \ | |
| 5625 } while (0) | |
| 5626 | |
| 5627 #define TestImplAddrImm(Inst0, Inst1, Value0, Imm, Op, Size) \ | |
| 5628 do { \ | |
| 5629 static_assert(Size == 8 || Size == 16 || Size == 32, \ | |
| 5630 "Invalid size " #Size); \ | |
| 5631 static constexpr char TestString[] = \ | |
| 5632 "(" #Inst0 ", " #Inst1 ", Addr, " #Value0 ", Imm(" #Imm "), " #Op \ | |
| 5633 ", " #Size ")"; \ | |
| 5634 const uint32_t T0 = allocateDword(); \ | |
| 5635 const uint32_t V0 = uint64_t(Value0) & Mask##Size; \ | |
| 5636 const uint32_t T1 = allocateDword(); \ | |
| 5637 const uint32_t V1 = (uint64_t(Value0) >> Size) & Mask##Size; \ | |
| 5638 __ Inst0(IceType_i##Size, dwordAddress(T0), \ | |
| 5639 Immediate(uint64_t(Imm) & Mask##Size)); \ | |
| 5640 __ Inst1(IceType_i##Size, dwordAddress(T1), \ | |
| 5641 Immediate((uint64_t(Imm) >> Size) & Mask##Size)); \ | |
| 5642 \ | |
| 5643 AssembledTest test = assemble(); \ | |
| 5644 test.setDwordTo(T0, V0); \ | |
| 5645 test.setDwordTo(T1, V1); \ | |
| 5646 test.run(); \ | |
| 5647 \ | |
| 5648 static constexpr uint64_t Result = \ | |
| 5649 (uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ | |
| 5650 ResultMask##Size); \ | |
| 5651 static constexpr uint32_t Expected0 = Result & Mask##Size; \ | |
| 5652 static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ | |
| 5653 ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ | |
| 5654 ASSERT_EQ(Expected1, test.contentsOfDword(T1)) << TestString << ": 1"; \ | |
| 5655 reset(); \ | |
| 5656 } while (0) | |
| 5657 | |
| 5658 #define TestImplOp(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, Op, \ | |
| 5659 Size) \ | |
| 5660 do { \ | |
| 5661 TestImplRegReg(Inst0, Inst1, Dst0, Dst1, Value0, Src0, Src1, Value1, Op, \ | |
| 5662 Size); \ | |
| 5663 TestImplRegAddr(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size); \ | |
| 5664 TestImplRegImm(Inst0, Inst1, Dst0, Dst1, Value0, Value1, Op, Size); \ | |
| 5665 TestImplAddrReg(Inst0, Inst1, Value0, Src0, Src1, Value1, Op, Size); \ | |
| 5666 TestImplAddrImm(Inst0, Inst1, Value0, Value1, Op, Size); \ | |
| 5667 } while (0) | |
| 5668 | |
| 5669 #define TestImplValues(Dst0, Dst1, Value0, Src0, Src1, Value1, Size) \ | |
| 5670 do { \ | |
| 5671 TestImplOp(add, adc, Dst0, Dst1, Value0, Src0, Src1, Value1, +, Size); \ | |
| 5672 TestImplOp(sub, sbb, Dst0, Dst1, Value0, Src0, Src1, Value1, -, Size); \ | |
| 5673 } while (0) | |
| 5674 | |
| 5675 #define TestImplSize(Dst0, Dst1, Src0, Src1, Size) \ | |
| 5676 do { \ | |
| 5677 TestImplValues(Dst0, Dst1, 0xFFFFFFFFFFFFFF00ull, Src0, Src1, \ | |
| 5678 0xFFFFFFFF0000017Full, Size); \ | |
| 5679 } while (0) | |
| 5680 | |
| 5681 #define TestImpl(Dst0, Dst1, Src0, Src1) \ | |
| 5682 do { \ | |
| 5683 if (GPRRegister::Encoded_Reg_##Dst0 <= 3 && \ | |
| 5684 GPRRegister::Encoded_Reg_##Dst1 <= 3 && \ | |
| 5685 GPRRegister::Encoded_Reg_##Src0 <= 3 && \ | |
| 5686 GPRRegister::Encoded_Reg_##Src1 <= 3) { \ | |
| 5687 TestImplSize(Dst0, Dst1, Src0, Src1, 8); \ | |
| 5688 } \ | |
| 5689 TestImplSize(Dst0, Dst1, Src0, Src1, 16); \ | |
| 5690 TestImplSize(Dst0, Dst1, Src0, Src1, 32); \ | |
| 5691 } while (0) | |
| 5692 | |
| 5693 TestImpl(eax, ebx, ecx, edx); | |
| 5694 TestImpl(ebx, ecx, edx, esi); | |
| 5695 TestImpl(ecx, edx, esi, edi); | |
| 5696 TestImpl(edx, esi, edi, eax); | |
| 5697 TestImpl(esi, edi, eax, ebx); | |
| 5698 TestImpl(edi, eax, ebx, ecx); | |
| 5699 | |
| 5700 #undef TestImpl | |
| 5701 #undef TestImplSize | |
| 5702 #undef TestImplValues | |
| 5703 #undef TestImplOp | |
| 5704 #undef TestImplAddrImm | |
| 5705 #undef TestImplAddrReg | |
| 5706 #undef TestImplRegImm | |
| 5707 #undef TestImplRegAddr | |
| 5708 #undef TestImplRegReg | |
| 5709 } | |
| 5710 | |
| 5711 TEST_F(AssemblerX8632LowLevelTest, Cbw_Cwd_Cdq) { | |
| 5712 #define TestImpl(Inst, BytesSize, ...) \ | |
| 5713 do { \ | |
| 5714 __ Inst(); \ | |
| 5715 ASSERT_EQ(BytesSize, codeBytesSize()) << #Inst; \ | |
| 5716 verifyBytes<BytesSize>(codeBytes(), __VA_ARGS__); \ | |
|
jvoung (off chromium)
2015/07/23 17:59:36
Similar question about ASSERT_TRUE, except now it'
John
2015/07/27 20:35:58
Having the ASSERT_TRUE outside verifyFunction help
| |
| 5717 reset(); \ | |
| 5718 } while (0) | |
| 5719 | |
| 5720 TestImpl(cbw, 2u, 0x66, 0x98); | |
| 5721 TestImpl(cwd, 2u, 0x66, 0x99); | |
| 5722 TestImpl(cdq, 1u, 0x99); | |
| 5723 | |
| 5724 #undef TestImpl | |
| 5725 } | |
| 5726 | |
| 5727 TEST_F(AssemblerX8632Test, SingleOperandMul) { | |
| 5728 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 5729 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 5730 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 5731 | |
| 5732 #define TestImplReg(Inst, Value0, Src, Value1, Type, Size) \ | |
| 5733 do { \ | |
| 5734 static_assert(GPRRegister::Encoded_Reg_eax != \ | |
| 5735 GPRRegister::Encoded_Reg_##Src, \ | |
| 5736 "eax can not be src1."); \ | |
| 5737 \ | |
| 5738 static constexpr char TestString[] = \ | |
| 5739 "(" #Inst ", " #Value0 ", " #Src ", " #Value1 ", " #Type ", " #Size \ | |
| 5740 ")"; \ | |
| 5741 static constexpr Type##64_t OperandEax = \ | |
| 5742 static_cast<Type##Size##_t>((Value0)&Mask##Size); \ | |
| 5743 static constexpr Type##64_t OperandOther = \ | |
| 5744 static_cast<Type##Size##_t>((Value1)&Mask##Size); \ | |
| 5745 static constexpr uint32_t ExpectedEax = \ | |
| 5746 Mask##Size & (OperandEax * OperandOther); \ | |
| 5747 static constexpr uint32_t ExpectedEdx = \ | |
| 5748 Mask##Size & ((OperandEax * OperandOther) >> Size); \ | |
| 5749 \ | |
| 5750 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 5751 Immediate((Value0)&Mask##Size)); \ | |
| 5752 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5753 Immediate((Value1)&Mask##Size)); \ | |
| 5754 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Src); \ | |
| 5755 \ | |
| 5756 if (Size == 8) { \ | |
| 5757 /* mov %ah, %dl */ \ | |
| 5758 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 5759 GPRRegister::Encoded_Reg_esp); \ | |
| 5760 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 5761 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ | |
| 5762 /* src == dh; clear dx's upper 8 bits. */ \ | |
| 5763 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ | |
| 5764 } \ | |
| 5765 } \ | |
| 5766 \ | |
| 5767 AssembledTest test = assemble(); \ | |
| 5768 test.run(); \ | |
| 5769 \ | |
| 5770 ASSERT_EQ(ExpectedEax, test.eax()) << TestString; \ | |
| 5771 ASSERT_EQ(ExpectedEdx, test.edx()) << TestString; \ | |
| 5772 reset(); \ | |
| 5773 } while (0) | |
| 5774 | |
| 5775 #define TestImplAddr(Inst, Value0, Value1, Type, Size) \ | |
| 5776 do { \ | |
| 5777 static constexpr char TestString[] = \ | |
| 5778 "(" #Inst ", " #Value0 ", Addr, " #Value1 ", " #Type ", " #Size ")"; \ | |
| 5779 static const uint32_t T0 = allocateDword(); \ | |
| 5780 static constexpr uint32_t V0 = Value1; \ | |
| 5781 static constexpr Type##64_t OperandEax = \ | |
| 5782 static_cast<Type##Size##_t>((Value0)&Mask##Size); \ | |
| 5783 static constexpr Type##64_t OperandOther = \ | |
| 5784 static_cast<Type##Size##_t>((Value1)&Mask##Size); \ | |
| 5785 static constexpr uint32_t ExpectedEax = \ | |
| 5786 Mask##Size & (OperandEax * OperandOther); \ | |
| 5787 static constexpr uint32_t ExpectedEdx = \ | |
| 5788 Mask##Size & ((OperandEax * OperandOther) >> Size); \ | |
| 5789 \ | |
| 5790 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 5791 Immediate((Value0)&Mask##Size)); \ | |
| 5792 __ Inst(IceType_i##Size, dwordAddress(T0)); \ | |
| 5793 \ | |
| 5794 if (Size == 8) { \ | |
| 5795 /* mov %ah, %dl */ \ | |
| 5796 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 5797 GPRRegister::Encoded_Reg_esp); \ | |
| 5798 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 5799 } \ | |
| 5800 \ | |
| 5801 AssembledTest test = assemble(); \ | |
| 5802 test.setDwordTo(T0, V0); \ | |
| 5803 test.run(); \ | |
| 5804 \ | |
| 5805 ASSERT_EQ(ExpectedEax, test.eax()) << TestString; \ | |
| 5806 ASSERT_EQ(ExpectedEdx, test.edx()) << TestString; \ | |
| 5807 reset(); \ | |
| 5808 } while (0) | |
| 5809 | |
| 5810 #define TestImplOp(Inst, Value0, Src, Value1, Type, Size) \ | |
| 5811 do { \ | |
| 5812 TestImplReg(Inst, Value0, Src, Value1, Type, Size); \ | |
| 5813 TestImplAddr(Inst, Value0, Value1, Type, Size); \ | |
| 5814 } while (0) | |
| 5815 | |
| 5816 #define TestImplValue(Value0, Src, Value1, Size) \ | |
| 5817 do { \ | |
| 5818 TestImplOp(mul, Value0, Src, Value1, uint, Size); \ | |
| 5819 TestImplOp(imul, Value0, Src, Value1, int, Size); \ | |
| 5820 } while (0) | |
| 5821 | |
| 5822 #define TestImplSize(Src, Size) \ | |
| 5823 do { \ | |
| 5824 TestImplValue(10, Src, 1, Size); \ | |
| 5825 TestImplValue(10, Src, -1, Size); \ | |
| 5826 TestImplValue(-10, Src, 37, Size); \ | |
| 5827 TestImplValue(-10, Src, -15, Size); \ | |
| 5828 } while (0) | |
| 5829 | |
| 5830 #define TestImpl(Src) \ | |
| 5831 do { \ | |
| 5832 TestImplSize(Src, 8); \ | |
| 5833 TestImplSize(Src, 16); \ | |
| 5834 TestImplSize(Src, 32); \ | |
| 5835 } while (0) | |
| 5836 | |
| 5837 TestImpl(ebx); | |
| 5838 TestImpl(ecx); | |
| 5839 TestImpl(edx); | |
| 5840 TestImpl(esi); | |
| 5841 TestImpl(edi); | |
| 5842 | |
| 5843 #undef TestImpl | |
| 5844 #undef TestImplSize | |
| 5845 #undef TestImplValue | |
| 5846 #undef TestImplOp | |
| 5847 #undef TestImplAddr | |
| 5848 #undef TestImplReg | |
| 5849 } | |
| 5850 | |
| 5851 TEST_F(AssemblerX8632Test, TwoOperandImul) { | |
| 5852 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 5853 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 5854 | |
| 5855 #define TestImplRegReg(Dst, Value0, Src, Value1, Size) \ | |
| 5856 do { \ | |
| 5857 static constexpr char TestString[] = \ | |
| 5858 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Size ")"; \ | |
| 5859 static constexpr int64_t Operand0 = \ | |
| 5860 static_cast<int##Size##_t>((Value0)&Mask##Size); \ | |
| 5861 static constexpr int64_t Operand1 = \ | |
| 5862 static_cast<int##Size##_t>((Value1)&Mask##Size); \ | |
| 5863 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ | |
| 5864 \ | |
| 5865 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5866 Immediate((Value0)&Mask##Size)); \ | |
| 5867 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 5868 Immediate((Value1)&Mask##Size)); \ | |
| 5869 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5870 GPRRegister::Encoded_Reg_##Src); \ | |
| 5871 \ | |
| 5872 if (Size == 8) { \ | |
| 5873 /* mov %ah, %dl */ \ | |
| 5874 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 5875 GPRRegister::Encoded_Reg_esp); \ | |
| 5876 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 5877 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ | |
| 5878 /* src == dh; clear dx's upper 8 bits. */ \ | |
| 5879 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ | |
| 5880 } \ | |
| 5881 } \ | |
| 5882 \ | |
| 5883 AssembledTest test = assemble(); \ | |
| 5884 test.run(); \ | |
| 5885 \ | |
| 5886 ASSERT_EQ(Expected, test.Dst()) << TestString; \ | |
| 5887 reset(); \ | |
| 5888 } while (0) | |
| 5889 | |
| 5890 #define TestImplRegImm(Dst, Value0, Imm, Size) \ | |
| 5891 do { \ | |
| 5892 static constexpr char TestString[] = \ | |
| 5893 "(" #Dst ", " #Value0 ", Imm(" #Imm "), " #Size ")"; \ | |
| 5894 static constexpr int64_t Operand0 = \ | |
| 5895 static_cast<int##Size##_t>((Value0)&Mask##Size); \ | |
| 5896 static constexpr int64_t Operand1 = \ | |
| 5897 static_cast<int##Size##_t>((Imm)&Mask##Size); \ | |
| 5898 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ | |
| 5899 \ | |
| 5900 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5901 Immediate((Value0)&Mask##Size)); \ | |
| 5902 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, Immediate(Imm)); \ | |
| 5903 \ | |
| 5904 if (Size == 8) { \ | |
| 5905 /* mov %ah, %dl */ \ | |
| 5906 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 5907 GPRRegister::Encoded_Reg_esp); \ | |
| 5908 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 5909 } \ | |
| 5910 \ | |
| 5911 AssembledTest test = assemble(); \ | |
| 5912 test.run(); \ | |
| 5913 \ | |
| 5914 ASSERT_EQ(Expected, test.Dst()) << TestString; \ | |
| 5915 reset(); \ | |
| 5916 } while (0) | |
| 5917 | |
| 5918 #define TestImplRegAddr(Dst, Value0, Value1, Size) \ | |
| 5919 do { \ | |
| 5920 static constexpr char TestString[] = \ | |
| 5921 "(" #Dst ", " #Value0 ", Addr," #Value1 ", " #Size ")"; \ | |
| 5922 static constexpr int64_t Operand0 = \ | |
| 5923 static_cast<int##Size##_t>((Value0)&Mask##Size); \ | |
| 5924 static constexpr int64_t Operand1 = \ | |
| 5925 static_cast<int##Size##_t>((Value1)&Mask##Size); \ | |
| 5926 static constexpr uint32_t Expected = Mask##Size & (Operand0 * Operand1); \ | |
| 5927 const uint32_t T0 = allocateDword(); \ | |
| 5928 \ | |
| 5929 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5930 Immediate((Value0)&Mask##Size)); \ | |
| 5931 __ imul(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 5932 dwordAddress(T0)); \ | |
| 5933 \ | |
| 5934 if (Size == 8) { \ | |
| 5935 /* mov %ah, %dl */ \ | |
| 5936 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 5937 GPRRegister::Encoded_Reg_esp); \ | |
| 5938 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 5939 } \ | |
| 5940 \ | |
| 5941 AssembledTest test = assemble(); \ | |
| 5942 test.setDwordTo(T0, static_cast<uint32_t>(Operand1)); \ | |
| 5943 test.run(); \ | |
| 5944 \ | |
| 5945 ASSERT_EQ(Expected, test.Dst()) << TestString; \ | |
| 5946 reset(); \ | |
| 5947 } while (0) | |
| 5948 | |
| 5949 #define TestImplValue(Dst, Value0, Src, Value1, Size) \ | |
| 5950 do { \ | |
| 5951 TestImplRegReg(Dst, Value0, Src, Value1, Size); \ | |
| 5952 TestImplRegImm(Dst, Value0, Value1, Size); \ | |
| 5953 TestImplRegAddr(Dst, Value0, Value1, Size); \ | |
| 5954 } while (0) | |
| 5955 | |
| 5956 #define TestImplSize(Dst, Src, Size) \ | |
| 5957 do { \ | |
| 5958 TestImplValue(Dst, 1, Src, 1, Size); \ | |
| 5959 TestImplValue(Dst, -10, Src, 0x4050AA20, Size); \ | |
| 5960 TestImplValue(Dst, -2, Src, -55, Size); \ | |
| 5961 } while (0) | |
| 5962 | |
| 5963 #define TestImpl(Dst, Src) \ | |
| 5964 do { \ | |
| 5965 TestImplSize(Dst, Src, 16); \ | |
| 5966 TestImplSize(Dst, Src, 32); \ | |
| 5967 } while (0) | |
| 5968 | |
| 5969 TestImpl(eax, ebx); | |
| 5970 TestImpl(ebx, ecx); | |
| 5971 TestImpl(ecx, edx); | |
| 5972 TestImpl(edx, esi); | |
| 5973 TestImpl(esi, edi); | |
| 5974 TestImpl(edi, eax); | |
| 5975 | |
| 5976 #undef TestImpl | |
| 5977 #undef TestImplSize | |
| 5978 #undef TestImplValue | |
| 5979 #undef TestImplRegAddr | |
| 5980 #undef TestImplRegImm | |
| 5981 #undef TestImplRegReg | |
| 5982 } | |
| 5983 | |
| 5984 TEST_F(AssemblerX8632Test, Div) { | |
| 5985 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 5986 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 5987 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 5988 | |
| 5989 static constexpr uint64_t Operand0Mask8 = 0x00000000000000FFull; | |
| 5990 static constexpr uint64_t Operand0Mask16 = 0x00000000FFFFFFFFull; | |
| 5991 static constexpr uint64_t Operand0Mask32 = 0xFFFFFFFFFFFFFFFFull; | |
| 5992 | |
| 5993 using Operand0Type_int8 = int16_t; | |
| 5994 using Operand0Type_uint8 = uint16_t; | |
| 5995 using Operand0Type_int16 = int32_t; | |
| 5996 using Operand0Type_uint16 = uint32_t; | |
| 5997 using Operand0Type_int32 = int64_t; | |
| 5998 using Operand0Type_uint32 = uint64_t; | |
| 5999 | |
| 6000 #define TestImplReg(Inst, Value0, Src, Value1, Type, Size) \ | |
| 6001 do { \ | |
| 6002 static_assert(GPRRegister::Encoded_Reg_eax != \ | |
| 6003 GPRRegister::Encoded_Reg_##Src, \ | |
| 6004 "eax can not be src1."); \ | |
| 6005 static_assert(GPRRegister::Encoded_Reg_edx != \ | |
| 6006 GPRRegister::Encoded_Reg_##Src, \ | |
| 6007 "edx can not be src1."); \ | |
| 6008 \ | |
| 6009 static constexpr char TestString[] = \ | |
| 6010 "(" #Inst ", " #Value0 ", " #Src ", " #Value1 ", " #Type ", " #Size \ | |
| 6011 ")"; \ | |
| 6012 static constexpr Operand0Type_##Type##Size Operand0 = \ | |
| 6013 static_cast<Type##64_t>(Value0) & Operand0Mask##Size; \ | |
| 6014 static constexpr Type##Size##_t Operand0Lo = Operand0 & Mask##Size; \ | |
| 6015 static constexpr Type##Size##_t Operand0Hi = \ | |
| 6016 (Operand0 >> Size) & Mask##Size; \ | |
| 6017 static constexpr Type##Size##_t Operand1 = \ | |
| 6018 static_cast<Type##Size##_t>(Value1) & Mask##Size; \ | |
| 6019 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 6020 Immediate(Operand0Lo)); \ | |
| 6021 if (Size == 8) { \ | |
| 6022 /* mov Operand0Hi, %al */ \ | |
| 6023 __ mov(IceType_i8, GPRRegister::Encoded_Reg_esp, Immediate(Operand0Hi)); \ | |
| 6024 } else { \ | |
| 6025 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 6026 Immediate(Operand0Hi)); \ | |
| 6027 } \ | |
| 6028 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 6029 Immediate(Operand1)); \ | |
| 6030 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Src); \ | |
| 6031 if (Size == 8) { \ | |
| 6032 /* mov %ah, %dl */ \ | |
| 6033 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 6034 GPRRegister::Encoded_Reg_esp); \ | |
| 6035 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 6036 if (GPRRegister::Encoded_Reg_##Src == GPRRegister::Encoded_Reg_esi) { \ | |
| 6037 __ And(IceType_i16, GPRRegister::Encoded_Reg_edx, Immediate(0x00FF)); \ | |
| 6038 } \ | |
| 6039 } \ | |
| 6040 \ | |
| 6041 AssembledTest test = assemble(); \ | |
| 6042 test.run(); \ | |
| 6043 \ | |
| 6044 static constexpr uint32_t Quocient = (Operand0 / Operand1) & Mask##Size; \ | |
| 6045 static constexpr uint32_t Reminder = (Operand0 % Operand1) & Mask##Size; \ | |
| 6046 EXPECT_EQ(Quocient, test.eax()) << TestString; \ | |
| 6047 EXPECT_EQ(Reminder, test.edx()) << TestString; \ | |
| 6048 reset(); \ | |
| 6049 } while (0) | |
| 6050 | |
| 6051 #define TestImplAddr(Inst, Value0, Value1, Type, Size) \ | |
| 6052 do { \ | |
| 6053 static constexpr char TestString[] = \ | |
| 6054 "(" #Inst ", " #Value0 ", Addr, " #Value1 ", " #Type ", " #Size ")"; \ | |
| 6055 static constexpr Operand0Type_##Type##Size Operand0 = \ | |
| 6056 static_cast<Type##64_t>(Value0) & Operand0Mask##Size; \ | |
| 6057 static constexpr Type##Size##_t Operand0Lo = Operand0 & Mask##Size; \ | |
| 6058 static constexpr Type##Size##_t Operand0Hi = \ | |
| 6059 (Operand0 >> Size) & Mask##Size; \ | |
| 6060 const uint32_t T0 = allocateDword(); \ | |
| 6061 static constexpr Type##Size##_t V0 = \ | |
| 6062 static_cast<Type##Size##_t>(Value1) & Mask##Size; \ | |
| 6063 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 6064 Immediate(Operand0Lo)); \ | |
| 6065 if (Size == 8) { \ | |
| 6066 /* mov Operand0Hi, %al */ \ | |
| 6067 __ mov(IceType_i8, GPRRegister::Encoded_Reg_esp, Immediate(Operand0Hi)); \ | |
| 6068 } else { \ | |
| 6069 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 6070 Immediate(Operand0Hi)); \ | |
| 6071 } \ | |
| 6072 __ Inst(IceType_i##Size, dwordAddress(T0)); \ | |
| 6073 if (Size == 8) { \ | |
| 6074 /* mov %ah, %dl */ \ | |
| 6075 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_edx, \ | |
| 6076 GPRRegister::Encoded_Reg_esp); \ | |
| 6077 __ And(IceType_i16, GPRRegister::Encoded_Reg_eax, Immediate(0x00FF)); \ | |
| 6078 } \ | |
| 6079 \ | |
| 6080 AssembledTest test = assemble(); \ | |
| 6081 test.setDwordTo(T0, static_cast<uint32_t>(V0)); \ | |
| 6082 test.run(); \ | |
| 6083 \ | |
| 6084 static constexpr uint32_t Quocient = (Operand0 / V0) & Mask##Size; \ | |
| 6085 static constexpr uint32_t Reminder = (Operand0 % V0) & Mask##Size; \ | |
| 6086 EXPECT_EQ(Quocient, test.eax()) << TestString; \ | |
| 6087 EXPECT_EQ(Reminder, test.edx()) << TestString; \ | |
| 6088 reset(); \ | |
| 6089 } while (0) | |
| 6090 | |
| 6091 #define TestImplOp(Inst, Value0, Src, Value1, Type, Size) \ | |
| 6092 do { \ | |
| 6093 TestImplReg(Inst, Value0, Src, Value1, Type, Size); \ | |
| 6094 TestImplAddr(Inst, Value0, Value1, Type, Size); \ | |
| 6095 } while (0) | |
| 6096 | |
| 6097 #define TestImplValue(Value0, Src, Value1, Size) \ | |
| 6098 do { \ | |
| 6099 TestImplOp(div, Value0, Src, Value1, uint, Size); \ | |
| 6100 TestImplOp(idiv, Value0, Src, Value1, int, Size); \ | |
| 6101 } while (0) | |
| 6102 | |
| 6103 #define TestImplSize(Src, Size) \ | |
| 6104 do { \ | |
| 6105 TestImplValue(10, Src, 1, Size); \ | |
| 6106 TestImplValue(10, Src, -1, Size); \ | |
| 6107 } while (0) | |
| 6108 | |
| 6109 #define TestImpl(Src) \ | |
| 6110 do { \ | |
| 6111 TestImplSize(Src, 8); \ | |
| 6112 TestImplSize(Src, 16); \ | |
| 6113 TestImplSize(Src, 32); \ | |
| 6114 } while (0) | |
| 6115 | |
| 6116 TestImpl(ebx); | |
| 6117 TestImpl(ecx); | |
| 6118 TestImpl(esi); | |
| 6119 TestImpl(edi); | |
| 6120 | |
| 6121 #undef TestImpl | |
| 6122 #undef TestImplSize | |
| 6123 #undef TestImplValue | |
| 6124 #undef TestImplOp | |
| 6125 #undef TestImplAddr | |
| 6126 #undef TestImplReg | |
| 6127 } | |
| 6128 | |
| 6129 // This is not executable in x86-64 because the one byte inc/dec instructions | |
| 6130 // became the REX prefixes. Therefore, these are tested with the low-level test | |
| 6131 // infrastructure. | |
| 6132 TEST_F(AssemblerX8632LowLevelTest, Incl_Decl_Reg) { | |
| 6133 #define TestImpl(Inst, Dst, BaseOpcode) \ | |
| 6134 do { \ | |
| 6135 __ Inst(GPRRegister::Encoded_Reg_##Dst); \ | |
| 6136 static constexpr uint8_t ByteCount = 1; \ | |
| 6137 ASSERT_EQ(ByteCount, codeBytesSize()); \ | |
| 6138 verifyBytes<ByteCount>(codeBytes(), \ | |
| 6139 BaseOpcode | GPRRegister::Encoded_Reg_##Dst); \ | |
| 6140 reset(); \ | |
| 6141 } while (0) | |
| 6142 | |
| 6143 #define TestInc(Dst) \ | |
| 6144 do { \ | |
| 6145 constexpr uint8_t InclOpcode = 0x40; \ | |
| 6146 TestImpl(incl, Dst, InclOpcode); \ | |
| 6147 } while (0) | |
| 6148 | |
| 6149 #define TestDec(Dst) \ | |
| 6150 do { \ | |
| 6151 constexpr uint8_t DeclOpcode = 0x48; \ | |
| 6152 TestImpl(decl, Dst, DeclOpcode); \ | |
| 6153 } while (0) | |
| 6154 | |
| 6155 TestInc(eax); | |
| 6156 TestInc(ecx); | |
| 6157 TestInc(edx); | |
| 6158 TestInc(ebx); | |
| 6159 TestInc(esp); | |
| 6160 TestInc(ebp); | |
| 6161 TestInc(esi); | |
| 6162 TestInc(esi); | |
| 6163 | |
| 6164 TestDec(eax); | |
| 6165 TestDec(ecx); | |
| 6166 TestDec(edx); | |
| 6167 TestDec(ebx); | |
| 6168 TestDec(esp); | |
| 6169 TestDec(ebp); | |
| 6170 TestDec(esi); | |
| 6171 TestDec(esi); | |
| 6172 | |
| 6173 #undef TestInc | |
| 6174 #undef TestDec | |
| 6175 #undef TestImpl | |
| 6176 } | |
| 6177 | |
| 6178 TEST_F(AssemblerX8632Test, Incl_Decl_Addr) { | |
| 6179 #define TestImpl(Inst, Value0) \ | |
| 6180 do { \ | |
| 6181 const bool IsInc = std::string(#Inst).find("incl") != std::string::npos; \ | |
| 6182 const uint32_t T0 = allocateDword(); \ | |
| 6183 const uint32_t V0 = Value0; \ | |
| 6184 \ | |
| 6185 __ Inst(dwordAddress(T0)); \ | |
| 6186 \ | |
| 6187 AssembledTest test = assemble(); \ | |
| 6188 test.setDwordTo(T0, V0); \ | |
| 6189 test.run(); \ | |
| 6190 \ | |
| 6191 ASSERT_EQ(static_cast<uint32_t>(Value0 + (IsInc ? 1 : -1)), \ | |
| 6192 test.contentsOfDword(T0)); \ | |
| 6193 reset(); \ | |
| 6194 } while (0) | |
| 6195 | |
| 6196 #define TestInc(Value0) \ | |
| 6197 do { \ | |
| 6198 TestImpl(incl, Value0); \ | |
| 6199 } while (0) | |
| 6200 | |
| 6201 #define TestDec(Value0) \ | |
| 6202 do { \ | |
| 6203 TestImpl(decl, Value0); \ | |
| 6204 } while (0) | |
| 6205 | |
| 6206 TestInc(230); | |
| 6207 | |
| 6208 TestDec(30); | |
| 6209 | |
| 6210 #undef TestInc | |
| 6211 #undef TestDec | |
| 6212 #undef TestImpl | |
| 6213 } | |
| 6214 | |
| 6215 TEST_F(AssemblerX8632Test, Shifts) { | |
| 6216 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 6217 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 6218 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 6219 | |
| 6220 #define TestImplRegImm(Inst, Dst, Value0, Imm, Op, Type, Size) \ | |
| 6221 do { \ | |
| 6222 static constexpr char TestString[] = \ | |
| 6223 "(" #Inst ", " #Dst ", " #Value0 ", Imm(" #Imm "), " #Op ", " #Type \ | |
| 6224 ", " #Size ")"; \ | |
| 6225 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ | |
| 6226 const uint##Size##_t Expected = \ | |
| 6227 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Imm) | \ | |
| 6228 (!IsRol ? 0 : (Value0) >> (Size - Imm))); \ | |
| 6229 \ | |
| 6230 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6231 Immediate((Value0)&Mask##Size)); \ | |
| 6232 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6233 Immediate((Imm)&Mask##Size)); \ | |
| 6234 \ | |
| 6235 AssembledTest test = assemble(); \ | |
| 6236 test.run(); \ | |
| 6237 \ | |
| 6238 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ | |
| 6239 reset(); \ | |
| 6240 } while (0) | |
| 6241 | |
| 6242 #define TestImplRegRegImm(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, \ | |
| 6243 Type, Size) \ | |
| 6244 do { \ | |
| 6245 static constexpr char TestString[] = \ | |
| 6246 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 \ | |
| 6247 ", Imm(" #Count "), " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ | |
| 6248 const uint##Size##_t Expected = \ | |
| 6249 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ | |
| 6250 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ | |
| 6251 \ | |
| 6252 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6253 Immediate((Value0)&Mask##Size)); \ | |
| 6254 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 6255 Immediate((Value1)&Mask##Size)); \ | |
| 6256 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6257 GPRRegister::Encoded_Reg_##Src, Immediate(Count)); \ | |
| 6258 \ | |
| 6259 AssembledTest test = assemble(); \ | |
| 6260 test.run(); \ | |
| 6261 \ | |
| 6262 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ | |
| 6263 reset(); \ | |
| 6264 } while (0) | |
| 6265 | |
| 6266 #define TestImplRegCl(Inst, Dst, Value0, Count, Op, Type, Size) \ | |
| 6267 do { \ | |
| 6268 static constexpr char TestString[] = \ | |
| 6269 "(" #Inst ", " #Dst ", " #Value0 ", " #Count ", " #Op ", " #Type \ | |
| 6270 ", " #Size ")"; \ | |
| 6271 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ | |
| 6272 const uint##Size##_t Expected = \ | |
| 6273 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Count) | \ | |
| 6274 (!IsRol ? 0 : Value0 >> (Size - Count))); \ | |
| 6275 \ | |
| 6276 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6277 Immediate((Value0)&Mask##Size)); \ | |
| 6278 __ mov(IceType_i8, GPRRegister::Encoded_Reg_ecx, \ | |
| 6279 Immediate((Count)&Mask##Size)); \ | |
| 6280 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6281 GPRRegister::Encoded_Reg_ecx); \ | |
| 6282 \ | |
| 6283 AssembledTest test = assemble(); \ | |
| 6284 test.run(); \ | |
| 6285 \ | |
| 6286 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ | |
| 6287 reset(); \ | |
| 6288 } while (0) | |
| 6289 | |
| 6290 #define TestImplRegRegCl(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, \ | |
| 6291 Type, Size) \ | |
| 6292 do { \ | |
| 6293 static constexpr char TestString[] = \ | |
| 6294 "(" #Inst ", " #Dst ", " #Value0 ", " #Src ", " #Value1 ", " #Count \ | |
| 6295 ", " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ | |
| 6296 const uint##Size##_t Expected = \ | |
| 6297 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ | |
| 6298 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ | |
| 6299 \ | |
| 6300 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6301 Immediate((Value0)&Mask##Size)); \ | |
| 6302 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 6303 Immediate((Value1)&Mask##Size)); \ | |
| 6304 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_ecx, \ | |
| 6305 Immediate((Count)&0x7F)); \ | |
| 6306 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6307 GPRRegister::Encoded_Reg_##Src); \ | |
| 6308 \ | |
| 6309 AssembledTest test = assemble(); \ | |
| 6310 test.run(); \ | |
| 6311 \ | |
| 6312 ASSERT_EQ(static_cast<uint32_t>(Expected), test.Dst()) << TestString; \ | |
| 6313 reset(); \ | |
| 6314 } while (0) | |
| 6315 | |
| 6316 #define TestImplAddrCl(Inst, Value0, Count, Op, Type, Size) \ | |
| 6317 do { \ | |
| 6318 static constexpr char TestString[] = \ | |
| 6319 "(" #Inst ", Addr, " #Value0 ", " #Count ", " #Op ", " #Type \ | |
| 6320 ", " #Size ")"; \ | |
| 6321 const bool IsRol = std::string(#Inst).find("rol") != std::string::npos; \ | |
| 6322 const uint##Size##_t Expected = \ | |
| 6323 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op(Count) | \ | |
| 6324 (!IsRol ? 0 : Value0 >> (Size - Count))); \ | |
| 6325 const uint32_t T0 = allocateDword(); \ | |
| 6326 const uint32_t V0 = Value0; \ | |
| 6327 \ | |
| 6328 __ mov(IceType_i8, GPRRegister::Encoded_Reg_ecx, \ | |
| 6329 Immediate((Count)&Mask##Size)); \ | |
| 6330 __ Inst(IceType_i##Size, dwordAddress(T0), GPRRegister::Encoded_Reg_ecx); \ | |
| 6331 \ | |
| 6332 AssembledTest test = assemble(); \ | |
| 6333 test.setDwordTo(T0, V0); \ | |
| 6334 test.run(); \ | |
| 6335 \ | |
| 6336 ASSERT_EQ(static_cast<uint32_t>(Expected), \ | |
| 6337 Mask##Size &test.contentsOfDword(T0)) \ | |
| 6338 << TestString; \ | |
| 6339 reset(); \ | |
| 6340 } while (0) | |
| 6341 | |
| 6342 #define TestImplAddrRegCl(Inst, Value0, Src, Value1, Count, Op0, Op1, Type, \ | |
| 6343 Size) \ | |
| 6344 do { \ | |
| 6345 static constexpr char TestString[] = \ | |
| 6346 "(" #Inst ", Addr, " #Value0 ", " #Src ", " #Value1 ", " #Count \ | |
| 6347 ", " #Op0 ", " #Op1 ", " #Type ", " #Size ")"; \ | |
| 6348 const uint##Size##_t Expected = \ | |
| 6349 Mask##Size & (static_cast<Type##Size##_t>(Value0) Op0(Count) | \ | |
| 6350 (static_cast<Type##64_t>(Value1) Op1(Size - Count))); \ | |
| 6351 const uint32_t T0 = allocateDword(); \ | |
| 6352 \ | |
| 6353 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 6354 Immediate((Value1)&Mask##Size)); \ | |
| 6355 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_ecx, \ | |
| 6356 Immediate((Count)&0x7F)); \ | |
| 6357 __ Inst(IceType_i##Size, dwordAddress(T0), \ | |
| 6358 GPRRegister::Encoded_Reg_##Src); \ | |
| 6359 \ | |
| 6360 AssembledTest test = assemble(); \ | |
| 6361 test.setDwordTo(T0, static_cast<uint32_t>(Value0)); \ | |
| 6362 test.run(); \ | |
| 6363 \ | |
| 6364 ASSERT_EQ(static_cast<uint32_t>(Expected), test.contentsOfDword(T0)) \ | |
| 6365 << TestString; \ | |
| 6366 reset(); \ | |
| 6367 } while (0) | |
| 6368 | |
| 6369 #define TestImplOp(Inst, Dst, Value0, Count, Op, Type, Size) \ | |
| 6370 do { \ | |
| 6371 static_assert(GPRRegister::Encoded_Reg_##Dst != \ | |
| 6372 GPRRegister::Encoded_Reg_ecx, \ | |
| 6373 "ecx should not be specified as Dst"); \ | |
| 6374 TestImplRegImm(Inst, Dst, Value0, Count, Op, Type, Size); \ | |
| 6375 TestImplRegImm(Inst, ecx, Value0, Count, Op, Type, Size); \ | |
| 6376 TestImplRegCl(Inst, Dst, Value0, Count, Op, Type, Size); \ | |
| 6377 TestImplAddrCl(Inst, Value0, Count, Op, Type, Size); \ | |
| 6378 } while (0) | |
| 6379 | |
| 6380 #define TestImplThreeOperandOp(Inst, Dst, Value0, Src, Value1, Count, Op0, \ | |
| 6381 Op1, Type, Size) \ | |
| 6382 do { \ | |
| 6383 static_assert(GPRRegister::Encoded_Reg_##Dst != \ | |
| 6384 GPRRegister::Encoded_Reg_ecx, \ | |
| 6385 "ecx should not be specified as Dst"); \ | |
| 6386 static_assert(GPRRegister::Encoded_Reg_##Src != \ | |
| 6387 GPRRegister::Encoded_Reg_ecx, \ | |
| 6388 "ecx should not be specified as Src"); \ | |
| 6389 TestImplRegRegImm(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, Type, \ | |
| 6390 Size); \ | |
| 6391 TestImplRegRegCl(Inst, Dst, Value0, Src, Value1, Count, Op0, Op1, Type, \ | |
| 6392 Size); \ | |
| 6393 TestImplAddrRegCl(Inst, Value0, Src, Value1, Count, Op0, Op1, Type, Size); \ | |
| 6394 } while (0) | |
| 6395 | |
| 6396 #define TestImplValue(Dst, Value0, Count, Size) \ | |
| 6397 do { \ | |
| 6398 TestImplOp(rol, Dst, Value0, Count, <<, uint, Size); \ | |
| 6399 TestImplOp(shl, Dst, Value0, Count, <<, uint, Size); \ | |
| 6400 TestImplOp(shr, Dst, Value0, Count, >>, uint, Size); \ | |
| 6401 TestImplOp(sar, Dst, Value0, Count, >>, int, Size); \ | |
| 6402 } while (0) | |
| 6403 | |
| 6404 #define TestImplThreeOperandValue(Dst, Value0, Src, Value1, Count, Size) \ | |
| 6405 do { \ | |
| 6406 TestImplThreeOperandOp(shld, Dst, Value0, Src, Value1, Count, <<, >>, \ | |
| 6407 uint, Size); \ | |
| 6408 TestImplThreeOperandOp(shrd, Dst, Value0, Src, Value1, Count, >>, <<, \ | |
| 6409 uint, Size); \ | |
| 6410 } while (0) | |
| 6411 | |
| 6412 #define TestImplSize(Dst, Size) \ | |
| 6413 do { \ | |
| 6414 TestImplValue(Dst, 0x8F, 3, Size); \ | |
| 6415 TestImplValue(Dst, 0x8FFF, 7, Size); \ | |
| 6416 TestImplValue(Dst, 0x8FFFF, 7, Size); \ | |
| 6417 } while (0) | |
| 6418 | |
| 6419 #define TestImplThreeOperandSize(Dst, Src, Size) \ | |
| 6420 do { \ | |
| 6421 TestImplThreeOperandValue(Dst, 0xFFF3, Src, 0xA000, 8, Size); \ | |
| 6422 } while (0) | |
| 6423 | |
| 6424 #define TestImpl(Dst, Src) \ | |
| 6425 do { \ | |
| 6426 if (GPRRegister::Encoded_Reg_##Dst < 4) { \ | |
| 6427 TestImplSize(Dst, 8); \ | |
| 6428 } \ | |
| 6429 TestImplSize(Dst, 16); \ | |
| 6430 TestImplThreeOperandSize(Dst, Src, 16); \ | |
| 6431 TestImplSize(Dst, 32); \ | |
| 6432 TestImplThreeOperandSize(Dst, Src, 32); \ | |
| 6433 } while (0) | |
| 6434 | |
| 6435 TestImpl(eax, ebx); | |
| 6436 TestImpl(ebx, edx); | |
| 6437 TestImpl(edx, esi); | |
| 6438 TestImpl(esi, edi); | |
| 6439 TestImpl(edi, eax); | |
| 6440 | |
| 6441 #undef TestImpl | |
| 6442 #undef TestImplThreeOperandSize | |
| 6443 #undef TestImplSize | |
| 6444 #undef TestImplValue | |
| 6445 #undef TestImplThreeOperandValue | |
| 6446 #undef TestImplOp | |
| 6447 #undef TestImplThreeOperandOp | |
| 6448 #undef TestImplAddrCl | |
| 6449 #undef TestImplRegRegCl | |
| 6450 #undef TestImplRegCl | |
| 6451 #undef TestImplRegRegImm | |
| 6452 #undef TestImplRegImm | |
| 6453 } | |
| 6454 | |
| 6455 TEST_F(AssemblerX8632Test, Neg) { | |
| 6456 static constexpr uint32_t Mask8 = 0x000000ff; | |
| 6457 static constexpr uint32_t Mask16 = 0x0000ffff; | |
| 6458 static constexpr uint32_t Mask32 = 0xffffffff; | |
| 6459 | |
| 6460 #define TestImplReg(Dst, Size) \ | |
| 6461 do { \ | |
| 6462 static constexpr int32_t Value = 0xFF00A543; \ | |
| 6463 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6464 Immediate(static_cast<int##Size##_t>(Value) & Mask##Size)); \ | |
| 6465 __ neg(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst); \ | |
| 6466 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 6467 GPRRegister::Encoded_Reg_##Dst); \ | |
| 6468 __ And(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(Mask##Size)); \ | |
| 6469 \ | |
| 6470 AssembledTest test = assemble(); \ | |
| 6471 test.run(); \ | |
| 6472 \ | |
| 6473 ASSERT_EQ(1 + (~static_cast<int##Size##_t>(Value) & Mask##Size), \ | |
| 6474 test.eax()) \ | |
| 6475 << "(" #Dst ", " #Size ")"; \ | |
| 6476 reset(); \ | |
| 6477 } while (0) | |
| 6478 | |
| 6479 #define TestImplAddr(Size) \ | |
| 6480 do { \ | |
| 6481 static constexpr int32_t Value = 0xFF00A543; \ | |
| 6482 const uint32_t T0 = allocateDword(); \ | |
| 6483 __ neg(IceType_i##Size, dwordAddress(T0)); \ | |
| 6484 \ | |
| 6485 AssembledTest test = assemble(); \ | |
| 6486 test.setDwordTo(T0, Value &Mask##Size); \ | |
| 6487 test.run(); \ | |
| 6488 \ | |
| 6489 ASSERT_EQ(1 + (~static_cast<int##Size##_t>(Value) & Mask##Size), \ | |
| 6490 test.contentsOfDword(T0)) \ | |
| 6491 << "(Addr, " #Size ")"; \ | |
| 6492 reset(); \ | |
| 6493 } while (0) | |
| 6494 | |
| 6495 #define TestImpl(Size) \ | |
| 6496 do { \ | |
| 6497 TestImplAddr(Size); \ | |
| 6498 TestImplReg(eax, Size); \ | |
| 6499 TestImplReg(ebx, Size); \ | |
| 6500 TestImplReg(ecx, Size); \ | |
| 6501 TestImplReg(edx, Size); \ | |
| 6502 TestImplReg(esi, Size); \ | |
| 6503 TestImplReg(edi, Size); \ | |
| 6504 } while (0) | |
| 6505 | |
| 6506 TestImpl(8); | |
| 6507 TestImpl(16); | |
| 6508 TestImpl(32); | |
| 6509 | |
| 6510 #undef TestImpl | |
| 6511 #undef TestImplAddr | |
| 6512 #undef TestImplReg | |
| 6513 } | |
| 6514 | |
| 6515 TEST_F(AssemblerX8632Test, Not) { | |
| 6516 #define TestImpl(Dst) \ | |
| 6517 do { \ | |
| 6518 static constexpr uint32_t Value = 0xFF00A543; \ | |
| 6519 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value)); \ | |
| 6520 __ notl(GPRRegister::Encoded_Reg_##Dst); \ | |
| 6521 \ | |
| 6522 AssembledTest test = assemble(); \ | |
| 6523 test.run(); \ | |
| 6524 \ | |
| 6525 ASSERT_EQ(~Value, test.Dst()) << "(" #Dst ")"; \ | |
| 6526 reset(); \ | |
| 6527 } while (0) | |
| 6528 | |
| 6529 TestImpl(eax); | |
| 6530 TestImpl(ebx); | |
| 6531 TestImpl(ecx); | |
| 6532 TestImpl(edx); | |
| 6533 TestImpl(esi); | |
| 6534 TestImpl(edi); | |
| 6535 | |
| 6536 #undef TestImpl | |
| 6537 } | |
| 6538 | |
| 6539 TEST_F(AssemblerX8632Test, Bswap) { | |
| 6540 #define TestImpl(Dst) \ | |
| 6541 do { \ | |
| 6542 static constexpr uint32_t Value = 0xFF00A543; \ | |
| 6543 static constexpr uint32_t Expected = 0x43A500FF; \ | |
| 6544 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value)); \ | |
| 6545 __ bswap(IceType_i32, GPRRegister::Encoded_Reg_##Dst); \ | |
| 6546 \ | |
| 6547 AssembledTest test = assemble(); \ | |
| 6548 test.run(); \ | |
| 6549 \ | |
| 6550 ASSERT_EQ(Expected, test.Dst()) << "(" #Dst ")"; \ | |
| 6551 reset(); \ | |
| 6552 } while (0) | |
| 6553 | |
| 6554 TestImpl(eax); | |
| 6555 TestImpl(ebx); | |
| 6556 TestImpl(ecx); | |
| 6557 TestImpl(edx); | |
| 6558 TestImpl(esi); | |
| 6559 TestImpl(edi); | |
| 6560 | |
| 6561 #undef TestImpl | |
| 6562 } | |
| 6563 | |
| 6564 TEST_F(AssemblerX8632Test, Bt) { | |
| 6565 #define TestImpl(Dst, Value0, Src, Value1) \ | |
| 6566 do { \ | |
| 6567 static constexpr char TestString[] = \ | |
| 6568 "(" #Dst ", " #Value0 ", " #Src ", " #Value1 ")"; \ | |
| 6569 static constexpr uint32_t Expected = ((Value0) & (1u << (Value1))) != 0; \ | |
| 6570 \ | |
| 6571 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Dst, Immediate(Value0)); \ | |
| 6572 __ mov(IceType_i32, GPRRegister::Encoded_Reg_##Src, Immediate(Value1)); \ | |
| 6573 __ bt(GPRRegister::Encoded_Reg_##Dst, GPRRegister::Encoded_Reg_##Src); \ | |
| 6574 __ setcc(Cond::Br_b, ByteRegister::Encoded_Reg_al); \ | |
| 6575 __ And(IceType_i32, GPRRegister::Encoded_Reg_eax, Immediate(0xFFu)); \ | |
| 6576 \ | |
| 6577 AssembledTest test = assemble(); \ | |
| 6578 test.run(); \ | |
| 6579 \ | |
| 6580 ASSERT_EQ(Expected, test.eax()) << TestString; \ | |
| 6581 reset(); \ | |
| 6582 } while (0) | |
| 6583 | |
| 6584 TestImpl(eax, 0x08000000, ebx, 27u); | |
| 6585 TestImpl(ebx, 0x08000000, ecx, 23u); | |
| 6586 TestImpl(ecx, 0x00000000, edx, 1u); | |
| 6587 TestImpl(edx, 0x08000300, esi, 9u); | |
| 6588 TestImpl(esi, 0x08000300, edi, 10u); | |
| 6589 TestImpl(edi, 0x7FFFEFFF, eax, 13u); | |
| 6590 | |
| 6591 #undef TestImpl | |
| 6592 } | |
| 6593 | |
| 6594 template <uint32_t Value, uint32_t Bits> class BitScanHelper { | |
| 6595 BitScanHelper() = delete; | |
| 6596 | |
| 6597 public: | |
| 6598 static_assert(Bits == 16 || Bits == 32, "Bits must be 16 or 32"); | |
| 6599 using ValueType = | |
| 6600 typename std::conditional<Bits == 16, uint16_t, uint32_t>::type; | |
| 6601 | |
| 6602 private: | |
| 6603 static constexpr ValueType BitIndex(bool Forward, ValueType Index) { | |
| 6604 return (Value == 0) | |
| 6605 ? BitScanHelper<Value, Bits>::NoBitSet | |
| 6606 : (Value & (1u << Index) | |
| 6607 ? Index | |
| 6608 : BitIndex(Forward, (Forward ? Index + 1 : Index - 1))); | |
| 6609 } | |
| 6610 | |
| 6611 public: | |
| 6612 static constexpr ValueType NoBitSet = static_cast<ValueType>(-1); | |
| 6613 static constexpr ValueType bsf = BitIndex(/*Forward*/ true, /*Index=*/0); | |
| 6614 static constexpr ValueType bsr = | |
| 6615 BitIndex(/*Forward*/ false, /*Index=*/Bits - 1); | |
| 6616 }; | |
| 6617 | |
| 6618 TEST_F(AssemblerX8632Test, BitScanOperations) { | |
| 6619 #define TestImplRegReg(Inst, Dst, Src, Value1, Size) \ | |
| 6620 do { \ | |
| 6621 static constexpr char TestString[] = \ | |
| 6622 "(" #Inst ", " #Dst ", " #Src ", " #Value1 ", " #Size ")"; \ | |
| 6623 static constexpr uint32_t Expected = BitScanHelper<Value1, Size>::Inst; \ | |
| 6624 const uint32_t ZeroFlag = allocateDword(); \ | |
| 6625 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 6626 Immediate(Value1)); \ | |
| 6627 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6628 GPRRegister::Encoded_Reg_##Src); \ | |
| 6629 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ | |
| 6630 \ | |
| 6631 AssembledTest test = assemble(); \ | |
| 6632 test.setDwordTo(ZeroFlag, 0u); \ | |
| 6633 test.run(); \ | |
| 6634 \ | |
| 6635 ASSERT_EQ((Expected == BitScanHelper<Value1, Size>::NoBitSet), \ | |
| 6636 test.contentsOfDword(ZeroFlag)) \ | |
| 6637 << TestString; \ | |
| 6638 if ((Expected != BitScanHelper<Value1, Size>::NoBitSet)) { \ | |
| 6639 ASSERT_EQ(Expected, test.Dst()) << TestString; \ | |
| 6640 } \ | |
| 6641 reset(); \ | |
| 6642 } while (0) | |
| 6643 | |
| 6644 #define TestImplRegAddr(Inst, Dst, Value1, Size) \ | |
| 6645 do { \ | |
| 6646 static constexpr char TestString[] = \ | |
| 6647 "(" #Inst ", " #Dst ", Addr, " #Value1 ", " #Size ")"; \ | |
| 6648 static constexpr uint32_t Expected = BitScanHelper<Value1, Size>::Inst; \ | |
| 6649 const uint32_t T0 = allocateDword(); \ | |
| 6650 const uint32_t ZeroFlag = allocateDword(); \ | |
| 6651 __ Inst(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst, \ | |
| 6652 dwordAddress(T0)); \ | |
| 6653 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ | |
| 6654 \ | |
| 6655 AssembledTest test = assemble(); \ | |
| 6656 test.setDwordTo(T0, Value1); \ | |
| 6657 test.setDwordTo(ZeroFlag, 0u); \ | |
| 6658 test.run(); \ | |
| 6659 \ | |
| 6660 ASSERT_EQ((Expected == BitScanHelper<Value1, Size>::NoBitSet), \ | |
| 6661 test.contentsOfDword(ZeroFlag)) \ | |
| 6662 << TestString; \ | |
| 6663 if (Expected != BitScanHelper<Value1, Size>::NoBitSet) { \ | |
| 6664 ASSERT_EQ(Expected, test.Dst()) << TestString; \ | |
| 6665 } \ | |
| 6666 reset(); \ | |
| 6667 } while (0) | |
| 6668 | |
| 6669 #define TestImplSize(Dst, Src, Value1, Size) \ | |
| 6670 do { \ | |
| 6671 TestImplRegReg(bsf, Dst, Src, Value1, Size); \ | |
| 6672 TestImplRegAddr(bsf, Dst, Value1, Size); \ | |
| 6673 TestImplRegReg(bsr, Dst, Src, Value1, Size); \ | |
| 6674 TestImplRegAddr(bsf, Dst, Value1, Size); \ | |
| 6675 } while (0) | |
| 6676 | |
| 6677 #define TestImplValue(Dst, Src, Value1) \ | |
| 6678 do { \ | |
| 6679 TestImplSize(Dst, Src, Value1, 16); \ | |
| 6680 TestImplSize(Dst, Src, Value1, 32); \ | |
| 6681 } while (0) | |
| 6682 | |
| 6683 #define TestImpl(Dst, Src) \ | |
| 6684 do { \ | |
| 6685 TestImplValue(Dst, Src, 0x80000001); \ | |
| 6686 TestImplValue(Dst, Src, 0x00000000); \ | |
| 6687 TestImplValue(Dst, Src, 0x80001000); \ | |
| 6688 TestImplValue(Dst, Src, 0x00FFFF00); \ | |
| 6689 } while (0) | |
| 6690 | |
| 6691 TestImpl(eax, ebx); | |
| 6692 TestImpl(ebx, ecx); | |
| 6693 TestImpl(ecx, edx); | |
| 6694 TestImpl(edx, esi); | |
| 6695 TestImpl(esi, edi); | |
| 6696 TestImpl(edi, eax); | |
| 6697 | |
| 6698 #undef TestImpl | |
| 6699 #undef TestImplValue | |
| 6700 #undef TestImplSize | |
| 6701 #undef TestImplRegAddr | |
| 6702 #undef TestImplRegReg | |
| 6703 } | |
| 6704 | |
| 6705 TEST_F(AssemblerX8632LowLevelTest, Nop) { | |
| 6706 #define TestImpl(Size, ...) \ | |
| 6707 do { \ | |
| 6708 static constexpr char TestString[] = "(" #Size ", " #__VA_ARGS__ ")"; \ | |
| 6709 __ nop(Size); \ | |
| 6710 ASSERT_EQ(Size##u, codeBytesSize()) << TestString; \ | |
| 6711 ASSERT_TRUE(verifyBytes<Size>(codeBytes(), __VA_ARGS__)) << TestString; \ | |
| 6712 reset(); \ | |
| 6713 } while (0); | |
| 6714 | |
| 6715 TestImpl(1, 0x90); | |
| 6716 TestImpl(2, 0x66, 0x90); | |
| 6717 TestImpl(3, 0x0F, 0x1F, 0x00); | |
| 6718 TestImpl(4, 0x0F, 0x1F, 0x40, 0x00); | |
| 6719 TestImpl(5, 0x0F, 0x1F, 0x44, 0x00, 0x00); | |
| 6720 TestImpl(6, 0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00); | |
| 6721 TestImpl(7, 0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00); | |
| 6722 TestImpl(8, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00); | |
| 6723 | |
| 6724 #undef TestImpl | |
| 6725 } | |
| 6726 | |
| 6727 TEST_F(AssemblerX8632LowLevelTest, Int3) { | |
| 6728 __ int3(); | |
| 6729 static constexpr uint32_t ByteCount = 1; | |
| 6730 ASSERT_EQ(ByteCount, codeBytesSize()); | |
| 6731 verifyBytes<ByteCount>(codeBytes(), 0xCC); | |
| 6732 } | |
| 6733 | |
| 6734 TEST_F(AssemblerX8632LowLevelTest, Hlt) { | |
| 6735 __ hlt(); | |
| 6736 static constexpr uint32_t ByteCount = 1; | |
| 6737 ASSERT_EQ(ByteCount, codeBytesSize()); | |
| 6738 verifyBytes<ByteCount>(codeBytes(), 0xF4); | |
| 6739 } | |
| 6740 | |
| 6741 TEST_F(AssemblerX8632LowLevelTest, Ud2) { | |
| 6742 __ ud2(); | |
| 6743 static constexpr uint32_t ByteCount = 2; | |
| 6744 ASSERT_EQ(ByteCount, codeBytesSize()); | |
| 6745 verifyBytes<ByteCount>(codeBytes(), 0x0F, 0x0B); | |
| 6746 } | |
| 6747 | |
| 6748 TEST_F(AssemblerX8632Test, Jmp) { | |
| 6749 // TestImplReg uses jmp(Label), so jmp(Label) needs to be tested before it. | |
| 6750 #define TestImplAddr(Near) \ | |
| 6751 do { \ | |
| 6752 Label ForwardJmp; \ | |
| 6753 Label BackwardJmp; \ | |
| 6754 Label Done; \ | |
| 6755 \ | |
| 6756 __ jmp(&ForwardJmp, AssemblerX8632::k##Near##Jump); \ | |
| 6757 __ hlt(); \ | |
| 6758 __ hlt(); \ | |
| 6759 __ hlt(); \ | |
| 6760 __ hlt(); \ | |
| 6761 __ hlt(); \ | |
| 6762 __ hlt(); \ | |
| 6763 __ hlt(); \ | |
| 6764 __ hlt(); \ | |
| 6765 __ hlt(); \ | |
| 6766 __ hlt(); \ | |
| 6767 __ bind(&BackwardJmp); \ | |
| 6768 __ jmp(&Done, AssemblerX8632::k##Near##Jump); \ | |
| 6769 __ hlt(); \ | |
| 6770 __ hlt(); \ | |
| 6771 __ hlt(); \ | |
| 6772 __ hlt(); \ | |
| 6773 __ hlt(); \ | |
| 6774 __ hlt(); \ | |
| 6775 __ hlt(); \ | |
| 6776 __ hlt(); \ | |
| 6777 __ hlt(); \ | |
| 6778 __ hlt(); \ | |
| 6779 __ bind(&ForwardJmp); \ | |
| 6780 __ jmp(&BackwardJmp, AssemblerX8632::k##NearJump); \ | |
| 6781 __ hlt(); \ | |
| 6782 __ hlt(); \ | |
| 6783 __ hlt(); \ | |
| 6784 __ hlt(); \ | |
| 6785 __ hlt(); \ | |
| 6786 __ hlt(); \ | |
| 6787 __ hlt(); \ | |
| 6788 __ hlt(); \ | |
| 6789 __ hlt(); \ | |
| 6790 __ hlt(); \ | |
| 6791 __ bind(&Done); \ | |
| 6792 } while (0) | |
| 6793 | |
| 6794 #define TestImplReg(Dst) \ | |
| 6795 do { \ | |
| 6796 __ call(Immediate(16)); \ | |
| 6797 Label Done; \ | |
| 6798 __ jmp(&Done, AssemblerX8632::kNearJump); \ | |
| 6799 __ hlt(); \ | |
| 6800 __ hlt(); \ | |
| 6801 __ hlt(); \ | |
| 6802 __ hlt(); \ | |
| 6803 __ hlt(); \ | |
| 6804 __ hlt(); \ | |
| 6805 __ hlt(); \ | |
| 6806 __ hlt(); \ | |
| 6807 __ hlt(); \ | |
| 6808 __ hlt(); \ | |
| 6809 __ popl(GPRRegister::Encoded_Reg_##Dst); \ | |
| 6810 __ jmp(GPRRegister::Encoded_Reg_##Dst); \ | |
| 6811 __ hlt(); \ | |
| 6812 __ hlt(); \ | |
| 6813 __ hlt(); \ | |
| 6814 __ hlt(); \ | |
| 6815 __ hlt(); \ | |
| 6816 __ hlt(); \ | |
| 6817 __ hlt(); \ | |
| 6818 __ hlt(); \ | |
| 6819 __ hlt(); \ | |
| 6820 __ hlt(); \ | |
| 6821 __ bind(&Done); \ | |
| 6822 \ | |
| 6823 AssembledTest test = assemble(); \ | |
| 6824 test.run(); \ | |
| 6825 \ | |
| 6826 reset(); \ | |
| 6827 } while (0) | |
| 6828 | |
| 6829 TestImplAddr(Near); | |
| 6830 TestImplAddr(Far); | |
| 6831 | |
| 6832 TestImplReg(eax); | |
| 6833 TestImplReg(ebx); | |
| 6834 TestImplReg(ecx); | |
| 6835 TestImplReg(edx); | |
| 6836 TestImplReg(esi); | |
| 6837 TestImplReg(edi); | |
| 6838 | |
| 6839 #undef TestImplReg | |
| 6840 #undef TestImplAddr | |
| 6841 } | |
| 6842 | |
| 6843 TEST_F(AssemblerX8632LowLevelTest, Mfence) { | |
| 6844 __ mfence(); | |
| 6845 | |
| 6846 static constexpr uint8_t ByteCount = 3; | |
| 6847 ASSERT_EQ(ByteCount, codeBytesSize()); | |
| 6848 verifyBytes<ByteCount>(codeBytes(), 0x0F, 0xAE, 0xF0); | |
| 6849 } | |
| 6850 | |
| 6851 TEST_F(AssemblerX8632LowLevelTest, Lock) { | |
| 6852 __ lock(); | |
| 6853 | |
| 6854 static constexpr uint8_t ByteCount = 1; | |
| 6855 ASSERT_EQ(ByteCount, codeBytesSize()); | |
| 6856 verifyBytes<ByteCount>(codeBytes(), 0xF0); | |
| 6857 } | |
| 6858 | |
| 6859 TEST_F(AssemblerX8632Test, Xchg) { | |
| 6860 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 6861 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 6862 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 6863 | |
| 6864 #define TestImplAddrReg(Value0, Dst1, Value1, Size) \ | |
| 6865 do { \ | |
| 6866 static constexpr char TestString[] = \ | |
| 6867 "(" #Value0 ", " #Dst1 ", " #Value1 ", " #Size ")"; \ | |
| 6868 const uint32_t T0 = allocateDword(); \ | |
| 6869 const uint32_t V0 = (Value0)&Mask##Size; \ | |
| 6870 const uint32_t V1 = (Value1)&Mask##Size; \ | |
| 6871 \ | |
| 6872 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 6873 Immediate(Value1)); \ | |
| 6874 __ xchg(IceType_i##Size, dwordAddress(T0), \ | |
| 6875 GPRRegister::Encoded_Reg_##Dst1); \ | |
| 6876 __ And(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 6877 Immediate(Mask##Size)); \ | |
| 6878 \ | |
| 6879 AssembledTest test = assemble(); \ | |
| 6880 test.setDwordTo(T0, V0); \ | |
| 6881 test.run(); \ | |
| 6882 \ | |
| 6883 ASSERT_EQ(V0, test.Dst1()) << TestString; \ | |
| 6884 ASSERT_EQ(V1, test.contentsOfDword(T0)) << TestString; \ | |
| 6885 reset(); \ | |
| 6886 } while (0) | |
| 6887 | |
| 6888 #define TestImplSize(Dst1, Size) \ | |
| 6889 do { \ | |
| 6890 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, Size); \ | |
| 6891 } while (0) | |
| 6892 | |
| 6893 #define TestImpl(Dst1) \ | |
| 6894 do { \ | |
| 6895 if (GPRRegister::Encoded_Reg_##Dst1 < 4) { \ | |
| 6896 TestImplSize(Dst1, 8); \ | |
| 6897 } \ | |
| 6898 TestImplSize(Dst1, 16); \ | |
| 6899 TestImplSize(Dst1, 32); \ | |
| 6900 } while (0) | |
| 6901 | |
| 6902 TestImpl(eax); | |
| 6903 TestImpl(ebx); | |
| 6904 TestImpl(ecx); | |
| 6905 TestImpl(edx); | |
| 6906 TestImpl(esi); | |
| 6907 TestImpl(edi); | |
| 6908 | |
| 6909 #undef TestImpl | |
| 6910 #undef TestImplSize | |
| 6911 #undef TestImplAddrReg | |
| 6912 } | |
| 6913 | |
| 6914 TEST_F(AssemblerX8632Test, Xadd) { | |
| 6915 static constexpr bool NotLocked = false; | |
| 6916 static constexpr bool Locked = true; | |
| 6917 | |
| 6918 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 6919 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 6920 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 6921 | |
| 6922 #define TestImplAddrReg(Value0, Dst1, Value1, LockedOrNot, Size) \ | |
| 6923 do { \ | |
| 6924 static constexpr char TestString[] = \ | |
| 6925 "(" #Value0 ", " #Dst1 ", " #Value1 ", " #Size ")"; \ | |
| 6926 const uint32_t T0 = allocateDword(); \ | |
| 6927 const uint32_t V0 = (Value0)&Mask##Size; \ | |
| 6928 const uint32_t V1 = (Value1)&Mask##Size; \ | |
| 6929 \ | |
| 6930 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 6931 Immediate(Value1)); \ | |
| 6932 __ xadd(IceType_i##Size, dwordAddress(T0), \ | |
| 6933 GPRRegister::Encoded_Reg_##Dst1, LockedOrNot); \ | |
| 6934 __ And(IceType_i32, GPRRegister::Encoded_Reg_##Dst1, \ | |
| 6935 Immediate(Mask##Size)); \ | |
| 6936 \ | |
| 6937 AssembledTest test = assemble(); \ | |
| 6938 test.setDwordTo(T0, V0); \ | |
| 6939 test.run(); \ | |
| 6940 \ | |
| 6941 ASSERT_EQ(V0, test.Dst1()) << TestString; \ | |
| 6942 ASSERT_EQ(Mask##Size &(V1 + V0), test.contentsOfDword(T0)) << TestString; \ | |
| 6943 reset(); \ | |
| 6944 } while (0) | |
| 6945 | |
| 6946 #define TestImplSize(Dst1, Size) \ | |
| 6947 do { \ | |
| 6948 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, NotLocked, Size); \ | |
| 6949 TestImplAddrReg(0xa2b34567, Dst1, 0x0507ddee, Locked, Size); \ | |
| 6950 } while (0) | |
| 6951 | |
| 6952 #define TestImpl(Dst1) \ | |
| 6953 do { \ | |
| 6954 if (GPRRegister::Encoded_Reg_##Dst1 < 4) { \ | |
| 6955 TestImplSize(Dst1, 8); \ | |
| 6956 } \ | |
| 6957 TestImplSize(Dst1, 16); \ | |
| 6958 TestImplSize(Dst1, 32); \ | |
| 6959 } while (0) | |
| 6960 | |
| 6961 TestImpl(eax); | |
| 6962 TestImpl(ebx); | |
| 6963 TestImpl(ecx); | |
| 6964 TestImpl(edx); | |
| 6965 TestImpl(esi); | |
| 6966 TestImpl(edi); | |
| 6967 | |
| 6968 #undef TestImpl | |
| 6969 #undef TestImplSize | |
| 6970 #undef TestImplAddrReg | |
| 6971 } | |
| 6972 | |
| 6973 TEST_F(AssemblerX8632LowLevelTest, Xadd) { | |
| 6974 static constexpr bool NotLocked = false; | |
| 6975 static constexpr bool Locked = true; | |
| 6976 | |
| 6977 // Ensures that xadd emits a lock prefix accordingly. | |
| 6978 { | |
| 6979 __ xadd(IceType_i8, Address::Absolute(0x1FF00), | |
| 6980 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 6981 static constexpr uint8_t ByteCountNotLocked8 = 7; | |
| 6982 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | |
| 6983 verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x0F, 0xC0, 0x35, 0x00, 0xFF, | |
| 6984 0x01, 0x00); | |
| 6985 reset(); | |
| 6986 | |
| 6987 __ xadd(IceType_i8, Address::Absolute(0x1FF00), | |
| 6988 GPRRegister::Encoded_Reg_esi, Locked); | |
| 6989 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | |
| 6990 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | |
| 6991 verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x0F, 0xC0, 0x35, 0x00, | |
| 6992 0xFF, 0x01, 0x00); | |
| 6993 reset(); | |
| 6994 } | |
| 6995 | |
| 6996 { | |
| 6997 __ xadd(IceType_i16, Address::Absolute(0x1FF00), | |
| 6998 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 6999 static constexpr uint8_t ByteCountNotLocked16 = 8; | |
| 7000 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | |
| 7001 verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x0F, 0xC1, 0x35, 0x00, | |
| 7002 0xFF, 0x01, 0x00); | |
| 7003 reset(); | |
| 7004 | |
| 7005 __ xadd(IceType_i16, Address::Absolute(0x1FF00), | |
| 7006 GPRRegister::Encoded_Reg_esi, Locked); | |
| 7007 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | |
| 7008 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | |
| 7009 verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x0F, 0xC1, 0x35, | |
| 7010 0x00, 0xFF, 0x01, 0x00); | |
| 7011 reset(); | |
| 7012 } | |
| 7013 | |
| 7014 { | |
| 7015 __ xadd(IceType_i32, Address::Absolute(0x1FF00), | |
| 7016 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 7017 static constexpr uint8_t ByteCountNotLocked32 = 7; | |
| 7018 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | |
| 7019 verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x0F, 0xC1, 0x35, 0x00, 0xFF, | |
| 7020 0x01, 0x00); | |
| 7021 reset(); | |
| 7022 | |
| 7023 __ xadd(IceType_i32, Address::Absolute(0x1FF00), | |
| 7024 GPRRegister::Encoded_Reg_esi, Locked); | |
| 7025 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | |
| 7026 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | |
| 7027 verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x0F, 0xC1, 0x35, 0x00, | |
| 7028 0xFF, 0x01, 0x00); | |
| 7029 reset(); | |
| 7030 } | |
| 7031 } | |
| 7032 | |
| 7033 TEST_F(AssemblerX8632LowLevelTest, EmitSegmentOverride) { | |
| 7034 #define TestImpl(Prefix) \ | |
| 7035 do { \ | |
| 7036 static constexpr uint8_t ByteCount = 1; \ | |
| 7037 __ emitSegmentOverride(Prefix); \ | |
| 7038 ASSERT_EQ(ByteCount, codeBytesSize()) << Prefix; \ | |
| 7039 verifyBytes<ByteCount>(codeBytes(), Prefix); \ | |
| 7040 reset(); \ | |
| 7041 } while (0) | |
| 7042 | |
| 7043 TestImpl(0x26); | |
| 7044 TestImpl(0x2E); | |
| 7045 TestImpl(0x36); | |
| 7046 TestImpl(0x3E); | |
| 7047 TestImpl(0x64); | |
| 7048 TestImpl(0x65); | |
| 7049 TestImpl(0x66); | |
| 7050 TestImpl(0x67); | |
| 7051 | |
| 7052 #undef TestImpl | |
| 7053 } | |
| 7054 | |
| 7055 TEST_F(AssemblerX8632Test, Cmpxchg8b) { | |
| 7056 static constexpr bool NotLocked = false; | |
| 7057 static constexpr bool Locked = true; | |
| 7058 | |
| 7059 #define TestImpl(Value0, Value1, ValueMem, LockedOrNot) \ | |
| 7060 do { \ | |
| 7061 static constexpr char TestString[] = \ | |
| 7062 "(" #Value0 ", " #Value1 ", " #ValueMem ", " #LockedOrNot ")"; \ | |
| 7063 const uint32_t T0 = allocateQword(); \ | |
| 7064 static constexpr uint64_t V0 = ValueMem; \ | |
| 7065 const uint32_t ZeroFlag = allocateDword(); \ | |
| 7066 \ | |
| 7067 __ mov(IceType_i32, GPRRegister::Encoded_Reg_eax, \ | |
| 7068 Immediate(uint64_t(Value0) & 0xFFFFFFFF)); \ | |
| 7069 __ mov(IceType_i32, GPRRegister::Encoded_Reg_edx, \ | |
| 7070 Immediate(uint64_t(Value0) >> 32)); \ | |
| 7071 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ebx, \ | |
| 7072 Immediate(uint64_t(Value1) & 0xFFFFFFFF)); \ | |
| 7073 __ mov(IceType_i32, GPRRegister::Encoded_Reg_ecx, \ | |
| 7074 Immediate(uint64_t(Value1) >> 32)); \ | |
| 7075 __ cmpxchg8b(dwordAddress(T0), LockedOrNot); \ | |
| 7076 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ | |
| 7077 \ | |
| 7078 AssembledTest test = assemble(); \ | |
| 7079 test.setQwordTo(T0, V0); \ | |
| 7080 test.setDwordTo(ZeroFlag, uint32_t(0xFF)); \ | |
| 7081 test.run(); \ | |
| 7082 \ | |
| 7083 if (V0 == (Value0)) { \ | |
| 7084 ASSERT_EQ(uint64_t(Value1), test.contentsOfQword(T0)) << TestString; \ | |
| 7085 ASSERT_EQ(1u, test.contentsOfDword(ZeroFlag)) << TestString; \ | |
| 7086 } else { \ | |
| 7087 ASSERT_EQ(uint64_t(ValueMem) & 0xFFFFFFFF, test.eax()) << TestString; \ | |
| 7088 ASSERT_EQ((uint64_t(ValueMem) >> 32) & 0xFFFFFFFF, test.edx()) \ | |
| 7089 << TestString; \ | |
| 7090 ASSERT_EQ(0u, test.contentsOfDword(ZeroFlag)) << TestString; \ | |
| 7091 } \ | |
| 7092 reset(); \ | |
| 7093 } while (0) | |
| 7094 | |
| 7095 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, NotLocked); | |
| 7096 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, Locked); | |
| 7097 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, NotLocked); | |
| 7098 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); | |
| 7099 | |
| 7100 #undef TestImpl | |
| 7101 } | |
| 7102 | |
| 7103 TEST_F(AssemblerX8632LowLevelTest, Cmpxchg8b) { | |
| 7104 static constexpr bool NotLocked = false; | |
| 7105 static constexpr bool Locked = true; | |
| 7106 | |
| 7107 // Ensures that cmpxchg8b emits a lock prefix accordingly. | |
| 7108 __ cmpxchg8b(Address::Absolute(0x1FF00), NotLocked); | |
| 7109 static constexpr uint8_t ByteCountNotLocked = 7; | |
| 7110 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); | |
| 7111 verifyBytes<ByteCountNotLocked>(codeBytes(), 0x0F, 0xC7, 0x0D, 0x00, 0xFF, | |
| 7112 0x01, 0x00); | |
| 7113 reset(); | |
| 7114 | |
| 7115 __ cmpxchg8b(Address::Absolute(0x1FF00), Locked); | |
| 7116 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; | |
| 7117 ASSERT_EQ(ByteCountLocked, codeBytesSize()); | |
| 7118 verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x0F, 0xC7, 0x0D, 0x00, 0xFF, | |
| 7119 0x01, 0x00); | |
| 7120 reset(); | |
| 7121 } | |
| 7122 | |
| 7123 TEST_F(AssemblerX8632Test, Cmpxchg) { | |
| 7124 static constexpr bool NotLocked = false; | |
| 7125 static constexpr bool Locked = true; | |
| 7126 | |
| 7127 static constexpr uint32_t Mask8 = 0x000000FF; | |
| 7128 static constexpr uint32_t Mask16 = 0x0000FFFF; | |
| 7129 static constexpr uint32_t Mask32 = 0xFFFFFFFF; | |
| 7130 | |
| 7131 #define TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, Size) \ | |
| 7132 do { \ | |
| 7133 static constexpr char TestString[] = \ | |
| 7134 "(" #Value0 ", " #Src ", " #Value1 ", " #ValueMem ", " #LockedOrNot \ | |
| 7135 ", " #Size ")"; \ | |
| 7136 const uint32_t T0 = allocateDword(); \ | |
| 7137 static constexpr uint32_t V0 = (ValueMem)&Mask##Size; \ | |
| 7138 const uint32_t ZeroFlag = allocateDword(); \ | |
| 7139 \ | |
| 7140 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_eax, \ | |
| 7141 Immediate((Value0)&Mask##Size)); \ | |
| 7142 __ mov(IceType_i##Size, GPRRegister::Encoded_Reg_##Src, \ | |
| 7143 Immediate((Value1)&Mask##Size)); \ | |
| 7144 __ cmpxchg(IceType_i##Size, dwordAddress(T0), \ | |
| 7145 GPRRegister::Encoded_Reg_##Src, LockedOrNot); \ | |
| 7146 __ setcc(Cond::Br_e, dwordAddress(ZeroFlag)); \ | |
| 7147 \ | |
| 7148 AssembledTest test = assemble(); \ | |
| 7149 test.setDwordTo(T0, V0); \ | |
| 7150 test.setDwordTo(ZeroFlag, uint32_t(0xFF)); \ | |
| 7151 test.run(); \ | |
| 7152 \ | |
| 7153 if (V0 == (Mask##Size & (Value0))) { \ | |
| 7154 ASSERT_EQ(uint32_t((Value1)&Mask##Size), test.contentsOfDword(T0)) \ | |
| 7155 << TestString; \ | |
| 7156 ASSERT_EQ(1u, test.contentsOfDword(ZeroFlag)) << TestString; \ | |
| 7157 } else { \ | |
| 7158 ASSERT_EQ(uint32_t((ValueMem)&Mask##Size), test.eax()) << TestString; \ | |
| 7159 ASSERT_EQ(0u, test.contentsOfDword(ZeroFlag)) << TestString; \ | |
| 7160 } \ | |
| 7161 reset(); \ | |
| 7162 } while (0) | |
| 7163 | |
| 7164 #define TestImplValue(Value0, Src, Value1, ValueMem, LockedOrNot) \ | |
| 7165 do { \ | |
| 7166 if (GPRRegister::Encoded_Reg_##Src < 4) { \ | |
| 7167 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 8); \ | |
| 7168 } \ | |
| 7169 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 16); \ | |
| 7170 TestImplAddrReg(Value0, Src, Value1, ValueMem, LockedOrNot, 32); \ | |
| 7171 } while (0) | |
| 7172 | |
| 7173 #define TestImpl(Src, LockedOrNot) \ | |
| 7174 do { \ | |
| 7175 TestImplValue(0xFFFFFFFF, Src, 0x1, 0xFFFFFFFF, LockedOrNot); \ | |
| 7176 TestImplValue(0x0FFF0F0F, Src, 0x1, 0xFFFFFFFF, LockedOrNot); \ | |
| 7177 } while (0) | |
| 7178 | |
| 7179 TestImpl(ebx, Locked); | |
| 7180 TestImpl(edx, NotLocked); | |
| 7181 TestImpl(ecx, Locked); | |
| 7182 TestImpl(ecx, NotLocked); | |
| 7183 TestImpl(edx, Locked); | |
| 7184 TestImpl(edx, NotLocked); | |
| 7185 TestImpl(esi, Locked); | |
| 7186 TestImpl(esi, NotLocked); | |
| 7187 TestImpl(edi, Locked); | |
| 7188 TestImpl(edi, NotLocked); | |
| 7189 | |
| 7190 #undef TestImpl | |
| 7191 #undef TestImplValue | |
| 7192 #undef TestImplAddrReg | |
| 7193 } | |
| 7194 | |
| 7195 TEST_F(AssemblerX8632LowLevelTest, Cmpxchg) { | |
| 7196 static constexpr bool NotLocked = false; | |
| 7197 static constexpr bool Locked = true; | |
| 7198 | |
| 7199 // Ensures that cmpxchg emits a lock prefix accordingly. | |
| 7200 { | |
| 7201 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), | |
| 7202 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 7203 static constexpr uint8_t ByteCountNotLocked8 = 7; | |
| 7204 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | |
| 7205 verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x0F, 0xB0, 0x35, 0x00, 0xFF, | |
| 7206 0x01, 0x00); | |
| 7207 reset(); | |
| 7208 | |
| 7209 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), | |
| 7210 GPRRegister::Encoded_Reg_esi, Locked); | |
| 7211 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | |
| 7212 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | |
| 7213 verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x0F, 0xB0, 0x35, 0x00, | |
| 7214 0xFF, 0x01, 0x00); | |
| 7215 reset(); | |
| 7216 } | |
| 7217 | |
| 7218 { | |
| 7219 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), | |
| 7220 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 7221 static constexpr uint8_t ByteCountNotLocked16 = 8; | |
| 7222 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | |
| 7223 verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x0F, 0xB1, 0x35, 0x00, | |
| 7224 0xFF, 0x01, 0x00); | |
| 7225 reset(); | |
| 7226 | |
| 7227 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), | |
| 7228 GPRRegister::Encoded_Reg_esi, Locked); | |
| 7229 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | |
| 7230 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | |
| 7231 verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x0F, 0xB1, 0x35, | |
| 7232 0x00, 0xFF, 0x01, 0x00); | |
| 7233 reset(); | |
| 7234 } | |
| 7235 | |
| 7236 { | |
| 7237 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), | |
| 7238 GPRRegister::Encoded_Reg_esi, NotLocked); | |
| 7239 static constexpr uint8_t ByteCountNotLocked32 = 7; | |
| 7240 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | |
| 7241 verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x0F, 0xB1, 0x35, 0x00, 0xFF, | |
| 7242 0x01, 0x00); | |
| 7243 reset(); | |
| 7244 | |
| 7245 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), | |
| 7246 GPRRegister::Encoded_Reg_esi, Locked); | |
| 7247 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | |
| 7248 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | |
| 7249 verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x0F, 0xB1, 0x35, 0x00, | |
| 7250 0xFF, 0x01, 0x00); | |
| 7251 reset(); | |
| 7252 } | |
| 7253 } | |
| 7254 | |
| 7255 TEST_F(AssemblerX8632Test, Set1ps) { | |
| 7256 #define TestImpl(Xmm, Src, Imm) \ | |
| 7257 do { \ | |
| 7258 __ set1ps(XmmRegister::Encoded_Reg_##Xmm, GPRRegister::Encoded_Reg_##Src, \ | |
| 7259 Immediate(Imm)); \ | |
| 7260 \ | |
| 7261 AssembledTest test = assemble(); \ | |
| 7262 test.run(); \ | |
| 7263 \ | |
| 7264 const Dqword Expected((uint64_t(Imm) << 32) | uint32_t(Imm), \ | |
| 7265 (uint64_t(Imm) << 32) | uint32_t(Imm)); \ | |
| 7266 ASSERT_EQ(Expected, test.Xmm<Dqword>()) \ | |
| 7267 << "(" #Xmm ", " #Src ", " #Imm ")"; \ | |
| 7268 reset(); \ | |
| 7269 } while (0) | |
| 7270 | |
| 7271 TestImpl(xmm0, ebx, 1); | |
| 7272 TestImpl(xmm1, ecx, 2); | |
| 7273 TestImpl(xmm2, edx, 3); | |
| 7274 TestImpl(xmm3, esi, 4); | |
| 7275 TestImpl(xmm4, edi, 5); | |
| 7276 TestImpl(xmm5, eax, 6); | |
| 7277 TestImpl(xmm6, ebx, 7); | |
| 7278 TestImpl(xmm7, ecx, 8); | |
| 7279 | |
| 7280 #undef TestImpl | |
| 7281 } | |
| 7282 | |
|
jvoung (off chromium)
2015/07/23 17:59:36
Uh... haven't read all this. I'm assuming this is
John
2015/07/27 20:35:58
Well, these are just dumb tests -- I went over the
| |
| 715 #undef __ | 7283 #undef __ |
| 716 | 7284 |
| 717 } // end of anonymous namespace | 7285 } // end of anonymous namespace |
| 718 } // end of namespace X8632 | 7286 } // end of namespace X8632 |
| 719 } // end of namespace Ice | 7287 } // end of namespace Ice |
| OLD | NEW |