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

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2453343002: [asmjs] Do constant folding for I32Asmjs(Div|Rem)S to avoid checks of constant divisors (Closed)
Patch Set: Add tests Created 4 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
« no previous file with comments | « src/wasm/wasm-macro-gen.h ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/utils.h" 10 #include "src/utils.h"
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 for (int32_t val = -7; val < 8; ++val) { 441 for (int32_t val = -7; val < 8; ++val) {
442 if (denom == 0) { 442 if (denom == 0) {
443 CHECK_TRAP(r.Call(val)); 443 CHECK_TRAP(r.Call(val));
444 } else { 444 } else {
445 CHECK_EQ(val / denom, r.Call(val)); 445 CHECK_EQ(val / denom, r.Call(val));
446 } 446 }
447 } 447 }
448 } 448 }
449 } 449 }
450 450
451 WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) {
452 for (int8_t denom = -2; denom < 8; ++denom) {
453 TestingModule module(execution_mode);
454 module.ChangeOriginToAsmjs();
455 WasmRunner<int32_t> r(&module, MachineType::Int32());
456 BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
457 FOR_INT32_INPUTS(i) {
458 if (denom == 0) {
459 CHECK_EQ(0, r.Call(*i));
460 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) {
461 CHECK_EQ(std::numeric_limits<int32_t>::min(), r.Call(*i));
462 } else {
463 CHECK_EQ(*i / denom, r.Call(*i));
464 }
465 }
466 }
467 }
468
469 WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) {
470 for (int8_t denom = -2; denom < 8; ++denom) {
471 TestingModule module(execution_mode);
472 module.ChangeOriginToAsmjs();
473 WasmRunner<int32_t> r(&module, MachineType::Int32());
474 BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I8(denom)));
475 FOR_INT32_INPUTS(i) {
476 if (denom == 0) {
477 CHECK_EQ(0, r.Call(*i));
478 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) {
479 CHECK_EQ(0, r.Call(*i));
480 } else {
481 CHECK_EQ(*i % denom, r.Call(*i));
482 }
483 }
484 }
485 }
486
451 WASM_EXEC_TEST(Int32DivU_byzero_const) { 487 WASM_EXEC_TEST(Int32DivU_byzero_const) {
452 for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) { 488 for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
453 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32()); 489 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32());
454 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); 490 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
455 491
456 for (uint32_t val = 0xfffffff0; val < 8; ++val) { 492 for (uint32_t val = 0xfffffff0; val < 8; ++val) {
457 if (denom == 0) { 493 if (denom == 0) {
458 CHECK_TRAP(r.Call(val)); 494 CHECK_TRAP(r.Call(val));
459 } else { 495 } else {
460 CHECK_EQ(val / denom, r.Call(val)); 496 CHECK_EQ(val / denom, r.Call(val));
(...skipping 2478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2939 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, 2975 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
2940 WASM_ZERO); 2976 WASM_ZERO);
2941 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2977 const int32_t kMin = std::numeric_limits<int32_t>::min();
2942 CHECK_EQ(0, r.Call(133, 100)); 2978 CHECK_EQ(0, r.Call(133, 100));
2943 CHECK_EQ(0, r.Call(kMin, -1)); 2979 CHECK_EQ(0, r.Call(kMin, -1));
2944 CHECK_EQ(0, r.Call(0, 1)); 2980 CHECK_EQ(0, r.Call(0, 1));
2945 CHECK_TRAP(r.Call(100, 0)); 2981 CHECK_TRAP(r.Call(100, 0));
2946 CHECK_TRAP(r.Call(-1001, 0)); 2982 CHECK_TRAP(r.Call(-1001, 0));
2947 CHECK_TRAP(r.Call(kMin, 0)); 2983 CHECK_TRAP(r.Call(kMin, 0));
2948 } 2984 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-macro-gen.h ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698