OLD | NEW |
1 //===- subzero/unittest/AssemblerX8664/Locked.cpp -------------------------===// | 1 //===- subzero/unittest/AssemblerX8664/Locked.cpp -------------------------===// |
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 #include "AssemblerX8664/TestUtil.h" | 9 #include "AssemblerX8664/TestUtil.h" |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 TestImpl(r15); | 194 TestImpl(r15); |
195 | 195 |
196 #undef TestImpl | 196 #undef TestImpl |
197 #undef TestImplSize | 197 #undef TestImplSize |
198 #undef TestImplAddrReg | 198 #undef TestImplAddrReg |
199 } | 199 } |
200 | 200 |
201 TEST_F(AssemblerX8664LowLevelTest, Xadd) { | 201 TEST_F(AssemblerX8664LowLevelTest, Xadd) { |
202 static constexpr bool NotLocked = false; | 202 static constexpr bool NotLocked = false; |
203 static constexpr bool Locked = true; | 203 static constexpr bool Locked = true; |
| 204 static constexpr AssemblerFixup *Fixup = nullptr; |
204 | 205 |
205 // Ensures that xadd emits a lock prefix accordingly. | 206 // Ensures that xadd emits a lock prefix accordingly. |
206 { | 207 { |
207 __ xadd(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 208 __ xadd(IceType_i8, Address(0x1FF00, Fixup), Encoded_GPR_r14(), NotLocked); |
208 NotLocked); | |
209 static constexpr uint8_t ByteCountNotLocked8 = 8; | 209 static constexpr uint8_t ByteCountNotLocked8 = 8; |
210 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | 210 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
211 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x44, 0x0F, 0xC0, | 211 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x44, 0x0F, 0xC0, |
212 0x35, 0x00, 0xFF, 0x01, 0x00)); | 212 0x35, 0x00, 0xFF, 0x01, 0x00)); |
213 reset(); | 213 reset(); |
214 | 214 |
215 __ xadd(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); | 215 __ xadd(IceType_i8, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
216 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | 216 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
217 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | 217 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
218 ASSERT_TRUE(verifyBytes<ByteCountLocked8>( | 218 ASSERT_TRUE(verifyBytes<ByteCountLocked8>( |
219 codeBytes(), 0xF0, 0x44, 0x0F, 0xC0, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 219 codeBytes(), 0xF0, 0x44, 0x0F, 0xC0, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
220 reset(); | 220 reset(); |
221 } | 221 } |
222 | 222 |
223 { | 223 { |
224 __ xadd(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 224 __ xadd(IceType_i16, Address(0x1FF00, Fixup), Encoded_GPR_r14(), NotLocked); |
225 NotLocked); | |
226 static constexpr uint8_t ByteCountNotLocked16 = 9; | 225 static constexpr uint8_t ByteCountNotLocked16 = 9; |
227 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | 226 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
228 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>( | 227 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>( |
229 codeBytes(), 0x66, 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 228 codeBytes(), 0x66, 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
230 reset(); | 229 reset(); |
231 | 230 |
232 __ xadd(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); | 231 __ xadd(IceType_i16, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
233 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | 232 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
234 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | 233 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
235 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x44, | 234 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x44, |
236 0x0F, 0xC1, 0x35, 0x00, 0xFF, | 235 0x0F, 0xC1, 0x35, 0x00, 0xFF, |
237 0x01, 0x00)); | 236 0x01, 0x00)); |
238 reset(); | 237 reset(); |
239 } | 238 } |
240 | 239 |
241 { | 240 { |
242 __ xadd(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 241 __ xadd(IceType_i32, Address(0x1FF00, Fixup), Encoded_GPR_r14(), NotLocked); |
243 NotLocked); | |
244 static constexpr uint8_t ByteCountNotLocked32 = 8; | 242 static constexpr uint8_t ByteCountNotLocked32 = 8; |
245 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | 243 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
246 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>( | 244 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>( |
247 codeBytes(), 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 245 codeBytes(), 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
248 reset(); | 246 reset(); |
249 | 247 |
250 __ xadd(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); | 248 __ xadd(IceType_i32, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
251 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | 249 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
252 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | 250 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
253 ASSERT_TRUE(verifyBytes<ByteCountLocked32>( | 251 ASSERT_TRUE(verifyBytes<ByteCountLocked32>( |
254 codeBytes(), 0xF0, 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 252 codeBytes(), 0xF0, 0x44, 0x0F, 0xC1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
255 reset(); | 253 reset(); |
256 } | 254 } |
257 } | 255 } |
258 | 256 |
259 TEST_F(AssemblerX8664LowLevelTest, EmitSegmentOverride) { | 257 TEST_F(AssemblerX8664LowLevelTest, EmitSegmentOverride) { |
260 #define TestImpl(Prefix) \ | 258 #define TestImpl(Prefix) \ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, Locked); | 318 TestImpl(0x98987676543210ull, 0x1, 0x98987676543210ull, Locked); |
321 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, NotLocked); | 319 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, NotLocked); |
322 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); | 320 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); |
323 | 321 |
324 #undef TestImpl | 322 #undef TestImpl |
325 } | 323 } |
326 | 324 |
327 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg8b) { | 325 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg8b) { |
328 static constexpr bool NotLocked = false; | 326 static constexpr bool NotLocked = false; |
329 static constexpr bool Locked = true; | 327 static constexpr bool Locked = true; |
| 328 static constexpr AssemblerFixup *Fixup = nullptr; |
330 | 329 |
331 // Ensures that cmpxchg8b emits a lock prefix accordingly. | 330 // Ensures that cmpxchg8b emits a lock prefix accordingly. |
332 __ cmpxchg8b(Address::Absolute(0x1FF00), NotLocked); | 331 __ cmpxchg8b(Address(0x1FF00, Fixup), NotLocked); |
333 static constexpr uint8_t ByteCountNotLocked = 7; | 332 static constexpr uint8_t ByteCountNotLocked = 7; |
334 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); | 333 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); |
335 ASSERT_TRUE(verifyBytes<ByteCountNotLocked>(codeBytes(), 0x0F, 0xC7, 0x0D, | 334 ASSERT_TRUE(verifyBytes<ByteCountNotLocked>(codeBytes(), 0x0F, 0xC7, 0x0D, |
336 0x00, 0xFF, 0x01, 0x00)); | 335 0x00, 0xFF, 0x01, 0x00)); |
337 reset(); | 336 reset(); |
338 | 337 |
339 __ cmpxchg8b(Address::Absolute(0x1FF00), Locked); | 338 __ cmpxchg8b(Address(0x1FF00, Fixup), Locked); |
340 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; | 339 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; |
341 ASSERT_EQ(ByteCountLocked, codeBytesSize()); | 340 ASSERT_EQ(ByteCountLocked, codeBytesSize()); |
342 ASSERT_TRUE(verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x0F, 0xC7, 0x0D, | 341 ASSERT_TRUE(verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x0F, 0xC7, 0x0D, |
343 0x00, 0xFF, 0x01, 0x00)); | 342 0x00, 0xFF, 0x01, 0x00)); |
344 reset(); | 343 reset(); |
345 } | 344 } |
346 | 345 |
347 TEST_F(AssemblerX8664Test, Cmpxchg) { | 346 TEST_F(AssemblerX8664Test, Cmpxchg) { |
348 static constexpr bool NotLocked = false; | 347 static constexpr bool NotLocked = false; |
349 static constexpr bool Locked = true; | 348 static constexpr bool Locked = true; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 TestImpl(r15, NotLocked); | 425 TestImpl(r15, NotLocked); |
427 | 426 |
428 #undef TestImpl | 427 #undef TestImpl |
429 #undef TestImplValue | 428 #undef TestImplValue |
430 #undef TestImplAddrReg | 429 #undef TestImplAddrReg |
431 } | 430 } |
432 | 431 |
433 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg) { | 432 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg) { |
434 static constexpr bool NotLocked = false; | 433 static constexpr bool NotLocked = false; |
435 static constexpr bool Locked = true; | 434 static constexpr bool Locked = true; |
| 435 static constexpr AssemblerFixup *Fixup = nullptr; |
436 | 436 |
437 // Ensures that cmpxchg emits a lock prefix accordingly. | 437 // Ensures that cmpxchg emits a lock prefix accordingly. |
438 { | 438 { |
439 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 439 __ cmpxchg(IceType_i8, Address(0x1FF00, Fixup), Encoded_GPR_r14(), |
440 NotLocked); | 440 NotLocked); |
441 static constexpr uint8_t ByteCountNotLocked8 = 8; | 441 static constexpr uint8_t ByteCountNotLocked8 = 8; |
442 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | 442 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
443 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x44, 0x0F, 0xB0, | 443 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x44, 0x0F, 0xB0, |
444 0x35, 0x00, 0xFF, 0x01, 0x00)); | 444 0x35, 0x00, 0xFF, 0x01, 0x00)); |
445 reset(); | 445 reset(); |
446 | 446 |
447 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 447 __ cmpxchg(IceType_i8, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
448 Locked); | |
449 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | 448 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
450 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | 449 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
451 ASSERT_TRUE(verifyBytes<ByteCountLocked8>( | 450 ASSERT_TRUE(verifyBytes<ByteCountLocked8>( |
452 codeBytes(), 0xF0, 0x44, 0x0F, 0xB0, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 451 codeBytes(), 0xF0, 0x44, 0x0F, 0xB0, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
453 reset(); | 452 reset(); |
454 } | 453 } |
455 | 454 |
456 { | 455 { |
457 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 456 __ cmpxchg(IceType_i16, Address(0x1FF00, Fixup), Encoded_GPR_r14(), |
458 NotLocked); | 457 NotLocked); |
459 static constexpr uint8_t ByteCountNotLocked16 = 9; | 458 static constexpr uint8_t ByteCountNotLocked16 = 9; |
460 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | 459 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
461 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>( | 460 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>( |
462 codeBytes(), 0x66, 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 461 codeBytes(), 0x66, 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
463 reset(); | 462 reset(); |
464 | 463 |
465 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 464 __ cmpxchg(IceType_i16, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
466 Locked); | |
467 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | 465 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
468 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | 466 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
469 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x44, | 467 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x44, |
470 0x0F, 0xB1, 0x35, 0x00, 0xFF, | 468 0x0F, 0xB1, 0x35, 0x00, 0xFF, |
471 0x01, 0x00)); | 469 0x01, 0x00)); |
472 reset(); | 470 reset(); |
473 } | 471 } |
474 | 472 |
475 { | 473 { |
476 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 474 __ cmpxchg(IceType_i32, Address(0x1FF00, Fixup), Encoded_GPR_r14(), |
477 NotLocked); | 475 NotLocked); |
478 static constexpr uint8_t ByteCountNotLocked32 = 8; | 476 static constexpr uint8_t ByteCountNotLocked32 = 8; |
479 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | 477 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
480 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>( | 478 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>( |
481 codeBytes(), 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 479 codeBytes(), 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
482 reset(); | 480 reset(); |
483 | 481 |
484 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), | 482 __ cmpxchg(IceType_i32, Address(0x1FF00, Fixup), Encoded_GPR_r14(), Locked); |
485 Locked); | |
486 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | 483 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
487 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | 484 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
488 ASSERT_TRUE(verifyBytes<ByteCountLocked32>( | 485 ASSERT_TRUE(verifyBytes<ByteCountLocked32>( |
489 codeBytes(), 0xF0, 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); | 486 codeBytes(), 0xF0, 0x44, 0x0F, 0xB1, 0x35, 0x00, 0xFF, 0x01, 0x00)); |
490 reset(); | 487 reset(); |
491 } | 488 } |
492 } | 489 } |
493 | 490 |
494 } // end of anonymous namespace | 491 } // end of anonymous namespace |
495 } // end of namespace Test | 492 } // end of namespace Test |
496 } // end of namespace X8664 | 493 } // end of namespace X8664 |
497 } // end of namespace Ice | 494 } // end of namespace Ice |
OLD | NEW |