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 <functional> | 5 #include <functional> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 #include "test/cctest/compiler/codegen-tester.h" | 10 #include "test/cctest/compiler/codegen-tester.h" |
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 FOR_UINT32_INPUTS(i) { | 2207 FOR_UINT32_INPUTS(i) { |
2208 FOR_UINT32_SHIFTS(shift) { | 2208 FOR_UINT32_SHIFTS(shift) { |
2209 uint32_t expected = *i << shift; | 2209 uint32_t expected = *i << shift; |
2210 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); | 2210 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
2211 } | 2211 } |
2212 } | 2212 } |
2213 } | 2213 } |
2214 } | 2214 } |
2215 | 2215 |
2216 | 2216 |
| 2217 TEST(RunWord32ShlInComparison) { |
| 2218 { |
| 2219 RawMachineAssemblerTester<int32_t> m; |
| 2220 Uint32BinopTester bt(&m); |
| 2221 bt.AddReturn( |
| 2222 m.Word32Equal(m.Word32Shl(bt.param0, bt.param1), m.Int32Constant(0))); |
| 2223 FOR_UINT32_INPUTS(i) { |
| 2224 FOR_UINT32_SHIFTS(shift) { |
| 2225 uint32_t expected = 0 == (*i << shift); |
| 2226 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2227 } |
| 2228 } |
| 2229 } |
| 2230 { |
| 2231 RawMachineAssemblerTester<int32_t> m; |
| 2232 Uint32BinopTester bt(&m); |
| 2233 bt.AddReturn( |
| 2234 m.Word32Equal(m.Int32Constant(0), m.Word32Shl(bt.param0, bt.param1))); |
| 2235 FOR_UINT32_INPUTS(i) { |
| 2236 FOR_UINT32_SHIFTS(shift) { |
| 2237 uint32_t expected = 0 == (*i << shift); |
| 2238 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2239 } |
| 2240 } |
| 2241 } |
| 2242 { |
| 2243 FOR_UINT32_SHIFTS(shift) { |
| 2244 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2245 m.Return( |
| 2246 m.Word32Equal(m.Int32Constant(0), |
| 2247 m.Word32Shl(m.Parameter(0), m.Int32Constant(shift)))); |
| 2248 FOR_UINT32_INPUTS(i) { |
| 2249 uint32_t expected = 0 == (*i << shift); |
| 2250 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2251 } |
| 2252 } |
| 2253 } |
| 2254 { |
| 2255 FOR_UINT32_SHIFTS(shift) { |
| 2256 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2257 m.Return( |
| 2258 m.Word32Equal(m.Word32Shl(m.Parameter(0), m.Int32Constant(shift)), |
| 2259 m.Int32Constant(0))); |
| 2260 FOR_UINT32_INPUTS(i) { |
| 2261 uint32_t expected = 0 == (*i << shift); |
| 2262 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2263 } |
| 2264 } |
| 2265 } |
| 2266 } |
| 2267 |
| 2268 |
2217 TEST(RunWord32ShrP) { | 2269 TEST(RunWord32ShrP) { |
2218 { | 2270 { |
2219 FOR_UINT32_SHIFTS(shift) { | 2271 FOR_UINT32_SHIFTS(shift) { |
2220 RawMachineAssemblerTester<uint32_t> m(kMachUint32); | 2272 RawMachineAssemblerTester<uint32_t> m(kMachUint32); |
2221 m.Return(m.Word32Shr(m.Parameter(0), m.Int32Constant(shift))); | 2273 m.Return(m.Word32Shr(m.Parameter(0), m.Int32Constant(shift))); |
2222 FOR_UINT32_INPUTS(j) { | 2274 FOR_UINT32_INPUTS(j) { |
2223 uint32_t expected = *j >> shift; | 2275 uint32_t expected = *j >> shift; |
2224 CHECK_UINT32_EQ(expected, m.Call(*j)); | 2276 CHECK_UINT32_EQ(expected, m.Call(*j)); |
2225 } | 2277 } |
2226 } | 2278 } |
2227 } | 2279 } |
2228 { | 2280 { |
2229 RawMachineAssemblerTester<int32_t> m; | 2281 RawMachineAssemblerTester<int32_t> m; |
2230 Uint32BinopTester bt(&m); | 2282 Uint32BinopTester bt(&m); |
2231 bt.AddReturn(m.Word32Shr(bt.param0, bt.param1)); | 2283 bt.AddReturn(m.Word32Shr(bt.param0, bt.param1)); |
2232 FOR_UINT32_INPUTS(i) { | 2284 FOR_UINT32_INPUTS(i) { |
2233 FOR_UINT32_SHIFTS(shift) { | 2285 FOR_UINT32_SHIFTS(shift) { |
2234 uint32_t expected = *i >> shift; | 2286 uint32_t expected = *i >> shift; |
2235 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); | 2287 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
2236 } | 2288 } |
2237 } | 2289 } |
2238 CHECK_EQ(0x00010000, bt.call(0x80000000, 15)); | 2290 CHECK_EQ(0x00010000, bt.call(0x80000000, 15)); |
2239 } | 2291 } |
2240 } | 2292 } |
2241 | 2293 |
2242 | 2294 |
| 2295 TEST(RunWord32ShrInComparison) { |
| 2296 { |
| 2297 RawMachineAssemblerTester<int32_t> m; |
| 2298 Uint32BinopTester bt(&m); |
| 2299 bt.AddReturn( |
| 2300 m.Word32Equal(m.Word32Shr(bt.param0, bt.param1), m.Int32Constant(0))); |
| 2301 FOR_UINT32_INPUTS(i) { |
| 2302 FOR_UINT32_SHIFTS(shift) { |
| 2303 uint32_t expected = 0 == (*i >> shift); |
| 2304 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2305 } |
| 2306 } |
| 2307 } |
| 2308 { |
| 2309 RawMachineAssemblerTester<int32_t> m; |
| 2310 Uint32BinopTester bt(&m); |
| 2311 bt.AddReturn( |
| 2312 m.Word32Equal(m.Int32Constant(0), m.Word32Shr(bt.param0, bt.param1))); |
| 2313 FOR_UINT32_INPUTS(i) { |
| 2314 FOR_UINT32_SHIFTS(shift) { |
| 2315 uint32_t expected = 0 == (*i >> shift); |
| 2316 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2317 } |
| 2318 } |
| 2319 } |
| 2320 { |
| 2321 FOR_UINT32_SHIFTS(shift) { |
| 2322 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2323 m.Return( |
| 2324 m.Word32Equal(m.Int32Constant(0), |
| 2325 m.Word32Shr(m.Parameter(0), m.Int32Constant(shift)))); |
| 2326 FOR_UINT32_INPUTS(i) { |
| 2327 uint32_t expected = 0 == (*i >> shift); |
| 2328 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2329 } |
| 2330 } |
| 2331 } |
| 2332 { |
| 2333 FOR_UINT32_SHIFTS(shift) { |
| 2334 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2335 m.Return( |
| 2336 m.Word32Equal(m.Word32Shr(m.Parameter(0), m.Int32Constant(shift)), |
| 2337 m.Int32Constant(0))); |
| 2338 FOR_UINT32_INPUTS(i) { |
| 2339 uint32_t expected = 0 == (*i >> shift); |
| 2340 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2341 } |
| 2342 } |
| 2343 } |
| 2344 } |
| 2345 |
| 2346 |
2243 TEST(RunWord32SarP) { | 2347 TEST(RunWord32SarP) { |
2244 { | 2348 { |
2245 FOR_INT32_SHIFTS(shift) { | 2349 FOR_INT32_SHIFTS(shift) { |
2246 RawMachineAssemblerTester<int32_t> m(kMachInt32); | 2350 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
2247 m.Return(m.Word32Sar(m.Parameter(0), m.Int32Constant(shift))); | 2351 m.Return(m.Word32Sar(m.Parameter(0), m.Int32Constant(shift))); |
2248 FOR_INT32_INPUTS(j) { | 2352 FOR_INT32_INPUTS(j) { |
2249 int32_t expected = *j >> shift; | 2353 int32_t expected = *j >> shift; |
2250 CHECK_EQ(expected, m.Call(*j)); | 2354 CHECK_EQ(expected, m.Call(*j)); |
2251 } | 2355 } |
2252 } | 2356 } |
2253 } | 2357 } |
2254 { | 2358 { |
2255 RawMachineAssemblerTester<int32_t> m; | 2359 RawMachineAssemblerTester<int32_t> m; |
2256 Int32BinopTester bt(&m); | 2360 Int32BinopTester bt(&m); |
2257 bt.AddReturn(m.Word32Sar(bt.param0, bt.param1)); | 2361 bt.AddReturn(m.Word32Sar(bt.param0, bt.param1)); |
2258 FOR_INT32_INPUTS(i) { | 2362 FOR_INT32_INPUTS(i) { |
2259 FOR_INT32_SHIFTS(shift) { | 2363 FOR_INT32_SHIFTS(shift) { |
2260 int32_t expected = *i >> shift; | 2364 int32_t expected = *i >> shift; |
2261 CHECK_EQ(expected, bt.call(*i, shift)); | 2365 CHECK_EQ(expected, bt.call(*i, shift)); |
2262 } | 2366 } |
2263 } | 2367 } |
2264 CHECK_EQ(0xFFFF0000, bt.call(0x80000000, 15)); | 2368 CHECK_EQ(0xFFFF0000, bt.call(0x80000000, 15)); |
2265 } | 2369 } |
2266 } | 2370 } |
2267 | 2371 |
2268 | 2372 |
| 2373 TEST(RunWord32SarInComparison) { |
| 2374 { |
| 2375 RawMachineAssemblerTester<int32_t> m; |
| 2376 Int32BinopTester bt(&m); |
| 2377 bt.AddReturn( |
| 2378 m.Word32Equal(m.Word32Sar(bt.param0, bt.param1), m.Int32Constant(0))); |
| 2379 FOR_INT32_INPUTS(i) { |
| 2380 FOR_INT32_SHIFTS(shift) { |
| 2381 int32_t expected = 0 == (*i >> shift); |
| 2382 CHECK_EQ(expected, bt.call(*i, shift)); |
| 2383 } |
| 2384 } |
| 2385 } |
| 2386 { |
| 2387 RawMachineAssemblerTester<int32_t> m; |
| 2388 Int32BinopTester bt(&m); |
| 2389 bt.AddReturn( |
| 2390 m.Word32Equal(m.Int32Constant(0), m.Word32Sar(bt.param0, bt.param1))); |
| 2391 FOR_INT32_INPUTS(i) { |
| 2392 FOR_INT32_SHIFTS(shift) { |
| 2393 int32_t expected = 0 == (*i >> shift); |
| 2394 CHECK_EQ(expected, bt.call(*i, shift)); |
| 2395 } |
| 2396 } |
| 2397 } |
| 2398 { |
| 2399 FOR_INT32_SHIFTS(shift) { |
| 2400 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
| 2401 m.Return( |
| 2402 m.Word32Equal(m.Int32Constant(0), |
| 2403 m.Word32Sar(m.Parameter(0), m.Int32Constant(shift)))); |
| 2404 FOR_INT32_INPUTS(i) { |
| 2405 int32_t expected = 0 == (*i >> shift); |
| 2406 CHECK_EQ(expected, m.Call(*i)); |
| 2407 } |
| 2408 } |
| 2409 } |
| 2410 { |
| 2411 FOR_INT32_SHIFTS(shift) { |
| 2412 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
| 2413 m.Return( |
| 2414 m.Word32Equal(m.Word32Sar(m.Parameter(0), m.Int32Constant(shift)), |
| 2415 m.Int32Constant(0))); |
| 2416 FOR_INT32_INPUTS(i) { |
| 2417 uint32_t expected = 0 == (*i >> shift); |
| 2418 CHECK_EQ(expected, m.Call(*i)); |
| 2419 } |
| 2420 } |
| 2421 } |
| 2422 } |
| 2423 |
| 2424 |
2269 TEST(RunWord32RorP) { | 2425 TEST(RunWord32RorP) { |
2270 { | 2426 { |
2271 FOR_UINT32_SHIFTS(shift) { | 2427 FOR_UINT32_SHIFTS(shift) { |
2272 RawMachineAssemblerTester<int32_t> m(kMachUint32); | 2428 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
2273 m.Return(m.Word32Ror(m.Parameter(0), m.Int32Constant(shift))); | 2429 m.Return(m.Word32Ror(m.Parameter(0), m.Int32Constant(shift))); |
2274 FOR_UINT32_INPUTS(j) { | 2430 FOR_UINT32_INPUTS(j) { |
2275 int32_t expected = bits::RotateRight32(*j, shift); | 2431 int32_t expected = bits::RotateRight32(*j, shift); |
2276 CHECK_EQ(expected, m.Call(*j)); | 2432 CHECK_EQ(expected, m.Call(*j)); |
2277 } | 2433 } |
2278 } | 2434 } |
2279 } | 2435 } |
2280 { | 2436 { |
2281 RawMachineAssemblerTester<int32_t> m; | 2437 RawMachineAssemblerTester<int32_t> m; |
2282 Uint32BinopTester bt(&m); | 2438 Uint32BinopTester bt(&m); |
2283 bt.AddReturn(m.Word32Ror(bt.param0, bt.param1)); | 2439 bt.AddReturn(m.Word32Ror(bt.param0, bt.param1)); |
2284 FOR_UINT32_INPUTS(i) { | 2440 FOR_UINT32_INPUTS(i) { |
2285 FOR_UINT32_SHIFTS(shift) { | 2441 FOR_UINT32_SHIFTS(shift) { |
2286 uint32_t expected = bits::RotateRight32(*i, shift); | 2442 uint32_t expected = bits::RotateRight32(*i, shift); |
2287 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); | 2443 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
2288 } | 2444 } |
2289 } | 2445 } |
2290 } | 2446 } |
2291 } | 2447 } |
2292 | 2448 |
2293 | 2449 |
| 2450 TEST(RunWord32RorInComparison) { |
| 2451 { |
| 2452 RawMachineAssemblerTester<int32_t> m; |
| 2453 Uint32BinopTester bt(&m); |
| 2454 bt.AddReturn( |
| 2455 m.Word32Equal(m.Word32Ror(bt.param0, bt.param1), m.Int32Constant(0))); |
| 2456 FOR_UINT32_INPUTS(i) { |
| 2457 FOR_UINT32_SHIFTS(shift) { |
| 2458 uint32_t expected = 0 == bits::RotateRight32(*i, shift); |
| 2459 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2460 } |
| 2461 } |
| 2462 } |
| 2463 { |
| 2464 RawMachineAssemblerTester<int32_t> m; |
| 2465 Uint32BinopTester bt(&m); |
| 2466 bt.AddReturn( |
| 2467 m.Word32Equal(m.Int32Constant(0), m.Word32Ror(bt.param0, bt.param1))); |
| 2468 FOR_UINT32_INPUTS(i) { |
| 2469 FOR_UINT32_SHIFTS(shift) { |
| 2470 uint32_t expected = 0 == bits::RotateRight32(*i, shift); |
| 2471 CHECK_UINT32_EQ(expected, bt.call(*i, shift)); |
| 2472 } |
| 2473 } |
| 2474 } |
| 2475 { |
| 2476 FOR_UINT32_SHIFTS(shift) { |
| 2477 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2478 m.Return( |
| 2479 m.Word32Equal(m.Int32Constant(0), |
| 2480 m.Word32Ror(m.Parameter(0), m.Int32Constant(shift)))); |
| 2481 FOR_UINT32_INPUTS(i) { |
| 2482 uint32_t expected = 0 == bits::RotateRight32(*i, shift); |
| 2483 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2484 } |
| 2485 } |
| 2486 } |
| 2487 { |
| 2488 FOR_UINT32_SHIFTS(shift) { |
| 2489 RawMachineAssemblerTester<int32_t> m(kMachUint32); |
| 2490 m.Return( |
| 2491 m.Word32Equal(m.Word32Ror(m.Parameter(0), m.Int32Constant(shift)), |
| 2492 m.Int32Constant(0))); |
| 2493 FOR_UINT32_INPUTS(i) { |
| 2494 uint32_t expected = 0 == bits::RotateRight32(*i, shift); |
| 2495 CHECK_UINT32_EQ(expected, m.Call(*i)); |
| 2496 } |
| 2497 } |
| 2498 } |
| 2499 } |
| 2500 |
| 2501 |
2294 TEST(RunWord32NotP) { | 2502 TEST(RunWord32NotP) { |
2295 RawMachineAssemblerTester<int32_t> m(kMachInt32); | 2503 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
2296 m.Return(m.Word32Not(m.Parameter(0))); | 2504 m.Return(m.Word32Not(m.Parameter(0))); |
2297 FOR_INT32_INPUTS(i) { | 2505 FOR_INT32_INPUTS(i) { |
2298 int expected = ~(*i); | 2506 int expected = ~(*i); |
2299 CHECK_EQ(expected, m.Call(*i)); | 2507 CHECK_EQ(expected, m.Call(*i)); |
2300 } | 2508 } |
2301 } | 2509 } |
2302 | 2510 |
2303 | 2511 |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3988 FOR_INT32_INPUTS(i) { | 4196 FOR_INT32_INPUTS(i) { |
3989 FOR_INT32_INPUTS(j) { | 4197 FOR_INT32_INPUTS(j) { |
3990 int32_t expected; | 4198 int32_t expected; |
3991 if (ssub_overflow(*i, *j, &expected)) expected = constant; | 4199 if (ssub_overflow(*i, *j, &expected)) expected = constant; |
3992 CHECK_EQ(expected, bt.call(*i, *j)); | 4200 CHECK_EQ(expected, bt.call(*i, *j)); |
3993 } | 4201 } |
3994 } | 4202 } |
3995 } | 4203 } |
3996 | 4204 |
3997 #endif // V8_TURBOFAN_TARGET | 4205 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |