OLD | NEW |
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 SignedSubOverflow32(std::numeric_limits<int32_t>::max(), -1, &val)); | 192 SignedSubOverflow32(std::numeric_limits<int32_t>::max(), -1, &val)); |
193 EXPECT_EQ(std::numeric_limits<int32_t>::min(), val); | 193 EXPECT_EQ(std::numeric_limits<int32_t>::min(), val); |
194 TRACED_FORRANGE(int32_t, i, 1, 50) { | 194 TRACED_FORRANGE(int32_t, i, 1, 50) { |
195 TRACED_FORRANGE(int32_t, j, 1, i) { | 195 TRACED_FORRANGE(int32_t, j, 1, i) { |
196 EXPECT_FALSE(SignedSubOverflow32(i, j, &val)); | 196 EXPECT_FALSE(SignedSubOverflow32(i, j, &val)); |
197 EXPECT_EQ(i - j, val); | 197 EXPECT_EQ(i - j, val); |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
| 202 |
| 203 TEST(Bits, SignedMulHigh32) { |
| 204 EXPECT_EQ(0, SignedMulHigh32(0, 0)); |
| 205 TRACED_FORRANGE(int32_t, i, 1, 50) { |
| 206 TRACED_FORRANGE(int32_t, j, 1, i) { EXPECT_EQ(0, SignedMulHigh32(i, j)); } |
| 207 } |
| 208 EXPECT_EQ(-1073741824, SignedMulHigh32(std::numeric_limits<int32_t>::max(), |
| 209 std::numeric_limits<int32_t>::min())); |
| 210 EXPECT_EQ(-1073741824, SignedMulHigh32(std::numeric_limits<int32_t>::min(), |
| 211 std::numeric_limits<int32_t>::max())); |
| 212 EXPECT_EQ(1, SignedMulHigh32(1024 * 1024 * 1024, 4)); |
| 213 EXPECT_EQ(2, SignedMulHigh32(8 * 1024, 1024 * 1024)); |
| 214 } |
| 215 |
| 216 |
| 217 TEST(Bits, SignedMulHighAndAdd32) { |
| 218 TRACED_FORRANGE(int32_t, i, 1, 50) { |
| 219 EXPECT_EQ(i, SignedMulHighAndAdd32(0, 0, i)); |
| 220 TRACED_FORRANGE(int32_t, j, 1, i) { |
| 221 EXPECT_EQ(i, SignedMulHighAndAdd32(j, j, i)); |
| 222 } |
| 223 EXPECT_EQ(i + 1, SignedMulHighAndAdd32(1024 * 1024 * 1024, 4, i)); |
| 224 } |
| 225 } |
| 226 |
| 227 |
| 228 TEST(Bits, SignedMulHighAndSub32) { |
| 229 TRACED_FORRANGE(int32_t, i, 1, 50) { |
| 230 EXPECT_EQ(i, SignedMulHighAndSub32(0, 0, i)); |
| 231 TRACED_FORRANGE(int32_t, j, 1, i) { |
| 232 EXPECT_EQ(i, SignedMulHighAndSub32(j, j, i)); |
| 233 } |
| 234 EXPECT_EQ(i - 1, SignedMulHighAndSub32(1024 * 1024 * 1024, 4, i)); |
| 235 } |
| 236 } |
| 237 |
202 } // namespace bits | 238 } // namespace bits |
203 } // namespace base | 239 } // namespace base |
204 } // namespace v8 | 240 } // namespace v8 |
OLD | NEW |