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