OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 value = k_test_val; | 151 value = k_test_val; |
152 new_value = NoBarrier_AtomicExchange(&value, 5); | 152 new_value = NoBarrier_AtomicExchange(&value, 5); |
153 CHECK_EQU(5, value); | 153 CHECK_EQU(5, value); |
154 CHECK_EQU(k_test_val, new_value); | 154 CHECK_EQU(k_test_val, new_value); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 template <class AtomicType> | 158 template <class AtomicType> |
159 static void TestAtomicIncrementBounds() { | 159 static void TestAtomicIncrementBounds() { |
160 // Test at 32-bit boundary for 64-bit atomic type. | 160 // Test at rollover boundary between int_max and int_min. |
161 AtomicType test_val = static_cast<AtomicType>(1) | 161 AtomicType test_val = |
162 << (NUM_BITS(AtomicType) / 2); | 162 static_cast<AtomicType>(1) << (NUM_BITS(AtomicType) - 1); |
163 AtomicType value = test_val - 1; | 163 AtomicType value = -1 ^ test_val; |
164 AtomicType new_value = NoBarrier_AtomicIncrement(&value, 1); | 164 AtomicType new_value = NoBarrier_AtomicIncrement(&value, 1); |
165 CHECK_EQU(test_val, value); | 165 CHECK_EQU(test_val, value); |
166 CHECK_EQU(value, new_value); | 166 CHECK_EQU(value, new_value); |
167 | 167 |
| 168 NoBarrier_AtomicIncrement(&value, -1); |
| 169 CHECK_EQU(-1 ^ test_val, value); |
| 170 |
| 171 // Test at 32-bit boundary for 64-bit atomic type. |
| 172 test_val = static_cast<AtomicType>(1) << (NUM_BITS(AtomicType) / 2); |
| 173 value = test_val - 1; |
| 174 new_value = NoBarrier_AtomicIncrement(&value, 1); |
| 175 CHECK_EQU(test_val, value); |
| 176 CHECK_EQU(value, new_value); |
| 177 |
168 NoBarrier_AtomicIncrement(&value, -1); | 178 NoBarrier_AtomicIncrement(&value, -1); |
169 CHECK_EQU(test_val - 1, value); | 179 CHECK_EQU(test_val - 1, value); |
170 } | 180 } |
171 | 181 |
172 | 182 |
173 // Return an AtomicType with the value 0xa5a5a5.. | 183 // Return an AtomicType with the value 0xa5a5a5.. |
174 template <class AtomicType> | 184 template <class AtomicType> |
175 static AtomicType TestFillValue() { | 185 static AtomicType TestFillValue() { |
176 AtomicType val = 0; | 186 AtomicType val = 0; |
177 memset(&val, 0xa5, sizeof(AtomicType)); | 187 memset(&val, 0xa5, sizeof(AtomicType)); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 TestStore<Atomic32>(); | 300 TestStore<Atomic32>(); |
291 TestStore<AtomicWord>(); | 301 TestStore<AtomicWord>(); |
292 } | 302 } |
293 | 303 |
294 | 304 |
295 TEST(Load) { | 305 TEST(Load) { |
296 TestLoadAtomic8(); | 306 TestLoadAtomic8(); |
297 TestLoad<Atomic32>(); | 307 TestLoad<Atomic32>(); |
298 TestLoad<AtomicWord>(); | 308 TestLoad<AtomicWord>(); |
299 } | 309 } |
OLD | NEW |