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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 204 |
205 // Ensures that xadd emits a lock prefix accordingly. | 205 // Ensures that xadd emits a lock prefix accordingly. |
206 { | 206 { |
207 __ xadd(IceType_i8, Address(0x1FF00, AssemblerFixup::NoFixup), | 207 __ xadd(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
208 Encoded_GPR_r14(), NotLocked); | 208 NotLocked); |
209 static constexpr uint8_t ByteCountNotLocked8 = 10; | 209 static constexpr uint8_t ByteCountNotLocked8 = 10; |
210 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | 210 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
211 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x67, 0x44, 0x0F, | 211 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x67, 0x44, 0x0F, |
212 0xC0, 0x34, 0x25, 0x00, 0xFF, | 212 0xC0, 0x34, 0x25, 0x00, 0xFF, |
213 0x01, 0x00)); | 213 0x01, 0x00)); |
214 reset(); | 214 reset(); |
215 | 215 |
216 __ xadd(IceType_i8, Address(0x1FF00, AssemblerFixup::NoFixup), | 216 __ xadd(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); |
217 Encoded_GPR_r14(), Locked); | |
218 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | 217 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
219 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | 218 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
220 ASSERT_TRUE(verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x67, 0x44, | 219 ASSERT_TRUE(verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x67, 0x44, |
221 0x0F, 0xC0, 0x34, 0x25, 0x00, | 220 0x0F, 0xC0, 0x34, 0x25, 0x00, |
222 0xFF, 0x01, 0x00)); | 221 0xFF, 0x01, 0x00)); |
223 reset(); | 222 reset(); |
224 } | 223 } |
225 | 224 |
226 { | 225 { |
227 __ xadd(IceType_i16, Address(0x1FF00, AssemblerFixup::NoFixup), | 226 __ xadd(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
228 Encoded_GPR_r14(), NotLocked); | 227 NotLocked); |
229 static constexpr uint8_t ByteCountNotLocked16 = 11; | 228 static constexpr uint8_t ByteCountNotLocked16 = 11; |
230 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | 229 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
231 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x67, 0x44, | 230 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x67, 0x44, |
232 0x0F, 0xC1, 0x34, 0x25, 0x00, | 231 0x0F, 0xC1, 0x34, 0x25, 0x00, |
233 0xFF, 0x01, 0x00)); | 232 0xFF, 0x01, 0x00)); |
234 reset(); | 233 reset(); |
235 | 234 |
236 __ xadd(IceType_i16, Address(0x1FF00, AssemblerFixup::NoFixup), | 235 __ xadd(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); |
237 Encoded_GPR_r14(), Locked); | |
238 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | 236 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
239 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | 237 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
240 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x67, | 238 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x67, |
241 0x44, 0x0F, 0xC1, 0x34, 0x25, | 239 0x44, 0x0F, 0xC1, 0x34, 0x25, |
242 0x00, 0xFF, 0x01, 0x00)); | 240 0x00, 0xFF, 0x01, 0x00)); |
243 reset(); | 241 reset(); |
244 } | 242 } |
245 | 243 |
246 { | 244 { |
247 __ xadd(IceType_i32, Address(0x1FF00, AssemblerFixup::NoFixup), | 245 __ xadd(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
248 Encoded_GPR_r14(), NotLocked); | 246 NotLocked); |
249 static constexpr uint8_t ByteCountNotLocked32 = 10; | 247 static constexpr uint8_t ByteCountNotLocked32 = 10; |
250 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | 248 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
251 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x67, 0x44, 0x0F, | 249 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x67, 0x44, 0x0F, |
252 0xC1, 0x34, 0x25, 0x00, 0xFF, | 250 0xC1, 0x34, 0x25, 0x00, 0xFF, |
253 0x01, 0x00)); | 251 0x01, 0x00)); |
254 reset(); | 252 reset(); |
255 | 253 |
256 __ xadd(IceType_i32, Address(0x1FF00, AssemblerFixup::NoFixup), | 254 __ xadd(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), Locked); |
257 Encoded_GPR_r14(), Locked); | |
258 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | 255 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
259 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | 256 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
260 ASSERT_TRUE(verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x67, 0x44, | 257 ASSERT_TRUE(verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x67, 0x44, |
261 0x0F, 0xC1, 0x34, 0x25, 0x00, | 258 0x0F, 0xC1, 0x34, 0x25, 0x00, |
262 0xFF, 0x01, 0x00)); | 259 0xFF, 0x01, 0x00)); |
263 reset(); | 260 reset(); |
264 } | 261 } |
265 } | 262 } |
266 | 263 |
267 TEST_F(AssemblerX8664LowLevelTest, EmitSegmentOverride) { | 264 TEST_F(AssemblerX8664LowLevelTest, EmitSegmentOverride) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); | 327 TestImpl(0x98987676543210ull, 0x1, 0x98987676543211ull, Locked); |
331 | 328 |
332 #undef TestImpl | 329 #undef TestImpl |
333 } | 330 } |
334 | 331 |
335 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg8b) { | 332 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg8b) { |
336 static constexpr bool NotLocked = false; | 333 static constexpr bool NotLocked = false; |
337 static constexpr bool Locked = true; | 334 static constexpr bool Locked = true; |
338 | 335 |
339 // Ensures that cmpxchg8b emits a lock prefix accordingly. | 336 // Ensures that cmpxchg8b emits a lock prefix accordingly. |
340 __ cmpxchg8b(Address(0x1FF00, AssemblerFixup::NoFixup), NotLocked); | 337 __ cmpxchg8b(Address::Absolute(0x1FF00), NotLocked); |
341 static constexpr uint8_t ByteCountNotLocked = 9; | 338 static constexpr uint8_t ByteCountNotLocked = 9; |
342 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); | 339 ASSERT_EQ(ByteCountNotLocked, codeBytesSize()); |
343 ASSERT_TRUE(verifyBytes<ByteCountNotLocked>( | 340 ASSERT_TRUE(verifyBytes<ByteCountNotLocked>( |
344 codeBytes(), 0x67, 0x0F, 0xC7, 0x0C, 0x25, 0x00, 0xFF, 0x01, 0x00)); | 341 codeBytes(), 0x67, 0x0F, 0xC7, 0x0C, 0x25, 0x00, 0xFF, 0x01, 0x00)); |
345 reset(); | 342 reset(); |
346 | 343 |
347 __ cmpxchg8b(Address(0x1FF00, AssemblerFixup::NoFixup), Locked); | 344 __ cmpxchg8b(Address::Absolute(0x1FF00), Locked); |
348 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; | 345 static constexpr uint8_t ByteCountLocked = 1 + ByteCountNotLocked; |
349 ASSERT_EQ(ByteCountLocked, codeBytesSize()); | 346 ASSERT_EQ(ByteCountLocked, codeBytesSize()); |
350 ASSERT_TRUE(verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x67, 0x0F, 0xC7, | 347 ASSERT_TRUE(verifyBytes<ByteCountLocked>(codeBytes(), 0xF0, 0x67, 0x0F, 0xC7, |
351 0x0C, 0x25, 0x00, 0xFF, 0x01, 0x00)); | 348 0x0C, 0x25, 0x00, 0xFF, 0x01, 0x00)); |
352 reset(); | 349 reset(); |
353 } | 350 } |
354 | 351 |
355 TEST_F(AssemblerX8664Test, Cmpxchg) { | 352 TEST_F(AssemblerX8664Test, Cmpxchg) { |
356 static constexpr bool NotLocked = false; | 353 static constexpr bool NotLocked = false; |
357 static constexpr bool Locked = true; | 354 static constexpr bool Locked = true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 #undef TestImplValue | 434 #undef TestImplValue |
438 #undef TestImplAddrReg | 435 #undef TestImplAddrReg |
439 } | 436 } |
440 | 437 |
441 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg) { | 438 TEST_F(AssemblerX8664LowLevelTest, Cmpxchg) { |
442 static constexpr bool NotLocked = false; | 439 static constexpr bool NotLocked = false; |
443 static constexpr bool Locked = true; | 440 static constexpr bool Locked = true; |
444 | 441 |
445 // Ensures that cmpxchg emits a lock prefix accordingly. | 442 // Ensures that cmpxchg emits a lock prefix accordingly. |
446 { | 443 { |
447 __ cmpxchg(IceType_i8, Address(0x1FF00, AssemblerFixup::NoFixup), | 444 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
448 Encoded_GPR_r14(), NotLocked); | 445 NotLocked); |
449 static constexpr uint8_t ByteCountNotLocked8 = 10; | 446 static constexpr uint8_t ByteCountNotLocked8 = 10; |
450 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); | 447 ASSERT_EQ(ByteCountNotLocked8, codeBytesSize()); |
451 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x67, 0x44, 0x0F, | 448 ASSERT_TRUE(verifyBytes<ByteCountNotLocked8>(codeBytes(), 0x67, 0x44, 0x0F, |
452 0xB0, 0x34, 0x25, 0x00, 0xFF, | 449 0xB0, 0x34, 0x25, 0x00, 0xFF, |
453 0x01, 0x00)); | 450 0x01, 0x00)); |
454 reset(); | 451 reset(); |
455 | 452 |
456 __ cmpxchg(IceType_i8, Address(0x1FF00, AssemblerFixup::NoFixup), | 453 __ cmpxchg(IceType_i8, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
457 Encoded_GPR_r14(), Locked); | 454 Locked); |
458 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; | 455 static constexpr uint8_t ByteCountLocked8 = 1 + ByteCountNotLocked8; |
459 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); | 456 ASSERT_EQ(ByteCountLocked8, codeBytesSize()); |
460 ASSERT_TRUE(verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x67, 0x44, | 457 ASSERT_TRUE(verifyBytes<ByteCountLocked8>(codeBytes(), 0xF0, 0x67, 0x44, |
461 0x0F, 0xB0, 0x34, 0x25, 0x00, | 458 0x0F, 0xB0, 0x34, 0x25, 0x00, |
462 0xFF, 0x01, 0x00)); | 459 0xFF, 0x01, 0x00)); |
463 reset(); | 460 reset(); |
464 } | 461 } |
465 | 462 |
466 { | 463 { |
467 __ cmpxchg(IceType_i16, Address(0x1FF00, AssemblerFixup::NoFixup), | 464 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
468 Encoded_GPR_r14(), NotLocked); | 465 NotLocked); |
469 static constexpr uint8_t ByteCountNotLocked16 = 11; | 466 static constexpr uint8_t ByteCountNotLocked16 = 11; |
470 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); | 467 ASSERT_EQ(ByteCountNotLocked16, codeBytesSize()); |
471 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x67, 0x44, | 468 ASSERT_TRUE(verifyBytes<ByteCountNotLocked16>(codeBytes(), 0x66, 0x67, 0x44, |
472 0x0F, 0xB1, 0x34, 0x25, 0x00, | 469 0x0F, 0xB1, 0x34, 0x25, 0x00, |
473 0xFF, 0x01, 0x00)); | 470 0xFF, 0x01, 0x00)); |
474 reset(); | 471 reset(); |
475 | 472 |
476 __ cmpxchg(IceType_i16, Address(0x1FF00, AssemblerFixup::NoFixup), | 473 __ cmpxchg(IceType_i16, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
477 Encoded_GPR_r14(), Locked); | 474 Locked); |
478 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; | 475 static constexpr uint8_t ByteCountLocked16 = 1 + ByteCountNotLocked16; |
479 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); | 476 ASSERT_EQ(ByteCountLocked16, codeBytesSize()); |
480 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x67, | 477 ASSERT_TRUE(verifyBytes<ByteCountLocked16>(codeBytes(), 0x66, 0xF0, 0x67, |
481 0x44, 0x0F, 0xB1, 0x34, 0x25, | 478 0x44, 0x0F, 0xB1, 0x34, 0x25, |
482 0x00, 0xFF, 0x01, 0x00)); | 479 0x00, 0xFF, 0x01, 0x00)); |
483 reset(); | 480 reset(); |
484 } | 481 } |
485 | 482 |
486 { | 483 { |
487 __ cmpxchg(IceType_i32, Address(0x1FF00, AssemblerFixup::NoFixup), | 484 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
488 Encoded_GPR_r14(), NotLocked); | 485 NotLocked); |
489 static constexpr uint8_t ByteCountNotLocked32 = 10; | 486 static constexpr uint8_t ByteCountNotLocked32 = 10; |
490 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); | 487 ASSERT_EQ(ByteCountNotLocked32, codeBytesSize()); |
491 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x67, 0x44, 0x0F, | 488 ASSERT_TRUE(verifyBytes<ByteCountNotLocked32>(codeBytes(), 0x67, 0x44, 0x0F, |
492 0xB1, 0x34, 0x25, 0x00, 0xFF, | 489 0xB1, 0x34, 0x25, 0x00, 0xFF, |
493 0x01, 0x00)); | 490 0x01, 0x00)); |
494 reset(); | 491 reset(); |
495 | 492 |
496 __ cmpxchg(IceType_i32, Address(0x1FF00, AssemblerFixup::NoFixup), | 493 __ cmpxchg(IceType_i32, Address::Absolute(0x1FF00), Encoded_GPR_r14(), |
497 Encoded_GPR_r14(), Locked); | 494 Locked); |
498 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; | 495 static constexpr uint8_t ByteCountLocked32 = 1 + ByteCountNotLocked32; |
499 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); | 496 ASSERT_EQ(ByteCountLocked32, codeBytesSize()); |
500 ASSERT_TRUE(verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x67, 0x44, | 497 ASSERT_TRUE(verifyBytes<ByteCountLocked32>(codeBytes(), 0xF0, 0x67, 0x44, |
501 0x0F, 0xB1, 0x34, 0x25, 0x00, | 498 0x0F, 0xB1, 0x34, 0x25, 0x00, |
502 0xFF, 0x01, 0x00)); | 499 0xFF, 0x01, 0x00)); |
503 reset(); | 500 reset(); |
504 } | 501 } |
505 } | 502 } |
506 | 503 |
507 } // end of anonymous namespace | 504 } // end of anonymous namespace |
508 } // end of namespace Test | 505 } // end of namespace Test |
509 } // end of namespace X8664 | 506 } // end of namespace X8664 |
510 } // end of namespace Ice | 507 } // end of namespace Ice |
OLD | NEW |