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