Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: test/unittests/base/bits-unittest.cc

Issue 677483005: [turbofan] Implement the correct semantics for integer division/modulus. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes and tests Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/macros.h" 8 #include "src/base/macros.h"
9 #include "testing/gtest-support.h" 9 #include "testing/gtest-support.h"
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 TEST(Bits, SignedMulHighAndAdd32) { 217 TEST(Bits, SignedMulHighAndAdd32) {
218 TRACED_FORRANGE(int32_t, i, 1, 50) { 218 TRACED_FORRANGE(int32_t, i, 1, 50) {
219 EXPECT_EQ(i, SignedMulHighAndAdd32(0, 0, i)); 219 EXPECT_EQ(i, SignedMulHighAndAdd32(0, 0, i));
220 TRACED_FORRANGE(int32_t, j, 1, i) { 220 TRACED_FORRANGE(int32_t, j, 1, i) {
221 EXPECT_EQ(i, SignedMulHighAndAdd32(j, j, i)); 221 EXPECT_EQ(i, SignedMulHighAndAdd32(j, j, i));
222 } 222 }
223 EXPECT_EQ(i + 1, SignedMulHighAndAdd32(1024 * 1024 * 1024, 4, i)); 223 EXPECT_EQ(i + 1, SignedMulHighAndAdd32(1024 * 1024 * 1024, 4, i));
224 } 224 }
225 } 225 }
226 226
227
228 TEST(Bits, SignedDiv32) {
229 EXPECT_EQ(std::numeric_limits<int32_t>::min(),
230 SignedDiv32(std::numeric_limits<int32_t>::min(), -1));
231 EXPECT_EQ(std::numeric_limits<int32_t>::max(),
232 SignedDiv32(std::numeric_limits<int32_t>::max(), 1));
233 TRACED_FORRANGE(int32_t, i, 0, 50) {
234 EXPECT_EQ(0, SignedDiv32(i, 0));
235 TRACED_FORRANGE(int32_t, j, 1, i) {
236 EXPECT_EQ(1, SignedDiv32(j, j));
237 EXPECT_EQ(i / j, SignedDiv32(i, j));
238 EXPECT_EQ(-i / j, SignedDiv32(i, -j));
239 }
240 }
241 }
242
243
244 TEST(Bits, SignedMod32) {
245 EXPECT_EQ(0, SignedMod32(std::numeric_limits<int32_t>::min(), -1));
246 EXPECT_EQ(0, SignedMod32(std::numeric_limits<int32_t>::max(), 1));
247 TRACED_FORRANGE(int32_t, i, 0, 50) {
248 EXPECT_EQ(0, SignedMod32(i, 0));
249 TRACED_FORRANGE(int32_t, j, 1, i) {
250 EXPECT_EQ(0, SignedMod32(j, j));
251 EXPECT_EQ(i % j, SignedMod32(i, j));
252 EXPECT_EQ(i % j, SignedMod32(i, -j));
253 }
254 }
255 }
256
257
258 TEST(Bits, UnsignedDiv32) {
259 TRACED_FORRANGE(uint32_t, i, 0, 50) {
260 EXPECT_EQ(0u, UnsignedDiv32(i, 0));
261 TRACED_FORRANGE(uint32_t, j, i + 1, 100) {
262 EXPECT_EQ(1u, UnsignedDiv32(j, j));
263 EXPECT_EQ(i / j, UnsignedDiv32(i, j));
264 }
265 }
266 }
267
268
269 TEST(Bits, UnsignedMod32) {
270 TRACED_FORRANGE(uint32_t, i, 0, 50) {
271 EXPECT_EQ(0u, UnsignedMod32(i, 0));
272 TRACED_FORRANGE(uint32_t, j, i + 1, 100) {
273 EXPECT_EQ(0u, UnsignedMod32(j, j));
274 EXPECT_EQ(i % j, UnsignedMod32(i, j));
275 }
276 }
277 }
278
227 } // namespace bits 279 } // namespace bits
228 } // namespace base 280 } // namespace base
229 } // namespace v8 281 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-arm.cc ('k') | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698