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

Side by Side Diff: test/cctest/compiler/test-run-machops.cc

Issue 415403005: [turbofan] Support for combining branches with <Operation>WithOverflow. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months 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
« no previous file with comments | « test/cctest/compiler/test-instruction-selector-arm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <functional> 5 #include <functional>
6 #include <limits> 6 #include <limits>
7 7
8 #include "test/cctest/cctest.h" 8 #include "test/cctest/cctest.h"
9 #include "test/cctest/compiler/codegen-tester.h" 9 #include "test/cctest/compiler/codegen-tester.h"
10 #include "test/cctest/compiler/value-helper.h" 10 #include "test/cctest/compiler/value-helper.h"
(...skipping 3885 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 static_cast<int32_t>(static_cast<uint32_t>(x) - static_cast<uint32_t>(y)); 3896 static_cast<int32_t>(static_cast<uint32_t>(x) - static_cast<uint32_t>(y));
3897 *val = v; 3897 *val = v;
3898 return (((v ^ x) & (v ^ ~y)) >> 31) & 1; 3898 return (((v ^ x) & (v ^ ~y)) >> 31) & 1;
3899 } 3899 }
3900 3900
3901 3901
3902 TEST(RunInt32AddWithOverflowP) { 3902 TEST(RunInt32AddWithOverflowP) {
3903 int32_t actual_val = -1; 3903 int32_t actual_val = -1;
3904 RawMachineAssemblerTester<int32_t> m; 3904 RawMachineAssemblerTester<int32_t> m;
3905 Int32BinopTester bt(&m); 3905 Int32BinopTester bt(&m);
3906 Node* val, *ovf; 3906 Node* add = m.Int32AddWithOverflow(bt.param0, bt.param1);
3907 m.Int32AddWithOverflow(bt.param0, bt.param1, &val, &ovf); 3907 Node* val = m.Projection(0, add);
3908 Node* ovf = m.Projection(1, add);
3908 m.StoreToPointer(&actual_val, kMachineWord32, val); 3909 m.StoreToPointer(&actual_val, kMachineWord32, val);
3909 bt.AddReturn(ovf); 3910 bt.AddReturn(ovf);
3910 FOR_INT32_INPUTS(i) { 3911 FOR_INT32_INPUTS(i) {
3911 FOR_INT32_INPUTS(j) { 3912 FOR_INT32_INPUTS(j) {
3912 int32_t expected_val; 3913 int32_t expected_val;
3913 int expected_ovf = sadd_overflow(*i, *j, &expected_val); 3914 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3914 CHECK_EQ(expected_ovf, bt.call(*i, *j)); 3915 CHECK_EQ(expected_ovf, bt.call(*i, *j));
3915 CHECK_EQ(expected_val, actual_val); 3916 CHECK_EQ(expected_val, actual_val);
3916 } 3917 }
3917 } 3918 }
3918 } 3919 }
3919 3920
3920 3921
3921 TEST(RunInt32AddWithOverflowImm) { 3922 TEST(RunInt32AddWithOverflowImm) {
3922 int32_t actual_val = -1, expected_val = 0; 3923 int32_t actual_val = -1, expected_val = 0;
3923 FOR_INT32_INPUTS(i) { 3924 FOR_INT32_INPUTS(i) {
3924 { 3925 {
3925 RawMachineAssemblerTester<int32_t> m(kMachineWord32); 3926 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
3926 Node* val, *ovf; 3927 Node* add = m.Int32AddWithOverflow(m.Int32Constant(*i), m.Parameter(0));
3927 m.Int32AddWithOverflow(m.Int32Constant(*i), m.Parameter(0), &val, &ovf); 3928 Node* val = m.Projection(0, add);
3929 Node* ovf = m.Projection(1, add);
3928 m.StoreToPointer(&actual_val, kMachineWord32, val); 3930 m.StoreToPointer(&actual_val, kMachineWord32, val);
3929 m.Return(ovf); 3931 m.Return(ovf);
3930 FOR_INT32_INPUTS(j) { 3932 FOR_INT32_INPUTS(j) {
3931 int expected_ovf = sadd_overflow(*i, *j, &expected_val); 3933 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3932 CHECK_EQ(expected_ovf, m.Call(*j)); 3934 CHECK_EQ(expected_ovf, m.Call(*j));
3933 CHECK_EQ(expected_val, actual_val); 3935 CHECK_EQ(expected_val, actual_val);
3934 } 3936 }
3935 } 3937 }
3936 { 3938 {
3937 RawMachineAssemblerTester<int32_t> m(kMachineWord32); 3939 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
3938 Node* val, *ovf; 3940 Node* add = m.Int32AddWithOverflow(m.Parameter(0), m.Int32Constant(*i));
3939 m.Int32AddWithOverflow(m.Parameter(0), m.Int32Constant(*i), &val, &ovf); 3941 Node* val = m.Projection(0, add);
3942 Node* ovf = m.Projection(1, add);
3940 m.StoreToPointer(&actual_val, kMachineWord32, val); 3943 m.StoreToPointer(&actual_val, kMachineWord32, val);
3941 m.Return(ovf); 3944 m.Return(ovf);
3942 FOR_INT32_INPUTS(j) { 3945 FOR_INT32_INPUTS(j) {
3943 int expected_ovf = sadd_overflow(*i, *j, &expected_val); 3946 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3944 CHECK_EQ(expected_ovf, m.Call(*j)); 3947 CHECK_EQ(expected_ovf, m.Call(*j));
3945 CHECK_EQ(expected_val, actual_val); 3948 CHECK_EQ(expected_val, actual_val);
3946 } 3949 }
3947 } 3950 }
3948 FOR_INT32_INPUTS(j) { 3951 FOR_INT32_INPUTS(j) {
3949 RawMachineAssemblerTester<int32_t> m; 3952 RawMachineAssemblerTester<int32_t> m;
3950 Node* val, *ovf; 3953 Node* add =
3951 m.Int32AddWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j), &val, 3954 m.Int32AddWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j));
3952 &ovf); 3955 Node* val = m.Projection(0, add);
3956 Node* ovf = m.Projection(1, add);
3953 m.StoreToPointer(&actual_val, kMachineWord32, val); 3957 m.StoreToPointer(&actual_val, kMachineWord32, val);
3954 m.Return(ovf); 3958 m.Return(ovf);
3955 int expected_ovf = sadd_overflow(*i, *j, &expected_val); 3959 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3956 CHECK_EQ(expected_ovf, m.Call()); 3960 CHECK_EQ(expected_ovf, m.Call());
3957 CHECK_EQ(expected_val, actual_val); 3961 CHECK_EQ(expected_val, actual_val);
3958 } 3962 }
3959 } 3963 }
3960 } 3964 }
3961 3965
3962 3966
3963 TEST(RunInt32AddWithOverflowInBranchP) { 3967 TEST(RunInt32AddWithOverflowInBranchP) {
3968 int constant = 911777;
3964 MLabel blocka, blockb; 3969 MLabel blocka, blockb;
3965 RawMachineAssemblerTester<int32_t> m; 3970 RawMachineAssemblerTester<int32_t> m;
3966 Int32BinopTester bt(&m); 3971 Int32BinopTester bt(&m);
3967 Node* val, *ovf; 3972 Node* add = m.Int32AddWithOverflow(bt.param0, bt.param1);
3968 m.Int32AddWithOverflow(bt.param0, bt.param1, &val, &ovf); 3973 Node* ovf = m.Projection(1, add);
3969 m.Branch(ovf, &blocka, &blockb); 3974 m.Branch(ovf, &blocka, &blockb);
3970 m.Bind(&blocka); 3975 m.Bind(&blocka);
3971 bt.AddReturn(m.Word32Not(val)); 3976 bt.AddReturn(m.Int32Constant(constant));
3972 m.Bind(&blockb); 3977 m.Bind(&blockb);
3978 Node* val = m.Projection(0, add);
3973 bt.AddReturn(val); 3979 bt.AddReturn(val);
3974 FOR_UINT32_INPUTS(i) { 3980 FOR_UINT32_INPUTS(i) {
3975 FOR_UINT32_INPUTS(j) { 3981 FOR_UINT32_INPUTS(j) {
3976 int32_t expected; 3982 int32_t expected;
3977 if (sadd_overflow(*i, *j, &expected)) expected = ~expected; 3983 if (sadd_overflow(*i, *j, &expected)) expected = constant;
3978 CHECK_EQ(expected, bt.call(*i, *j)); 3984 CHECK_EQ(expected, bt.call(*i, *j));
3979 } 3985 }
3980 } 3986 }
3981 } 3987 }
3982 3988
3983 3989
3984 TEST(RunInt32SubWithOverflowP) { 3990 TEST(RunInt32SubWithOverflowP) {
3985 int32_t actual_val = -1; 3991 int32_t actual_val = -1;
3986 RawMachineAssemblerTester<int32_t> m; 3992 RawMachineAssemblerTester<int32_t> m;
3987 Int32BinopTester bt(&m); 3993 Int32BinopTester bt(&m);
3988 Node* val, *ovf; 3994 Node* add = m.Int32SubWithOverflow(bt.param0, bt.param1);
3989 m.Int32SubWithOverflow(bt.param0, bt.param1, &val, &ovf); 3995 Node* val = m.Projection(0, add);
3996 Node* ovf = m.Projection(1, add);
3990 m.StoreToPointer(&actual_val, kMachineWord32, val); 3997 m.StoreToPointer(&actual_val, kMachineWord32, val);
3991 bt.AddReturn(ovf); 3998 bt.AddReturn(ovf);
3992 FOR_INT32_INPUTS(i) { 3999 FOR_INT32_INPUTS(i) {
3993 FOR_INT32_INPUTS(j) { 4000 FOR_INT32_INPUTS(j) {
3994 int32_t expected_val; 4001 int32_t expected_val;
3995 int expected_ovf = ssub_overflow(*i, *j, &expected_val); 4002 int expected_ovf = ssub_overflow(*i, *j, &expected_val);
3996 CHECK_EQ(expected_ovf, bt.call(*i, *j)); 4003 CHECK_EQ(expected_ovf, bt.call(*i, *j));
3997 CHECK_EQ(expected_val, actual_val); 4004 CHECK_EQ(expected_val, actual_val);
3998 } 4005 }
3999 } 4006 }
4000 } 4007 }
4001 4008
4002 4009
4003 TEST(RunInt32SubWithOverflowImm) { 4010 TEST(RunInt32SubWithOverflowImm) {
4004 int32_t actual_val = -1, expected_val = 0; 4011 int32_t actual_val = -1, expected_val = 0;
4005 FOR_INT32_INPUTS(i) { 4012 FOR_INT32_INPUTS(i) {
4006 { 4013 {
4007 RawMachineAssemblerTester<int32_t> m(kMachineWord32); 4014 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
4008 Node* val, *ovf; 4015 Node* add = m.Int32SubWithOverflow(m.Int32Constant(*i), m.Parameter(0));
4009 m.Int32SubWithOverflow(m.Int32Constant(*i), m.Parameter(0), &val, &ovf); 4016 Node* val = m.Projection(0, add);
4017 Node* ovf = m.Projection(1, add);
4010 m.StoreToPointer(&actual_val, kMachineWord32, val); 4018 m.StoreToPointer(&actual_val, kMachineWord32, val);
4011 m.Return(ovf); 4019 m.Return(ovf);
4012 FOR_INT32_INPUTS(j) { 4020 FOR_INT32_INPUTS(j) {
4013 int expected_ovf = ssub_overflow(*i, *j, &expected_val); 4021 int expected_ovf = ssub_overflow(*i, *j, &expected_val);
4014 CHECK_EQ(expected_ovf, m.Call(*j)); 4022 CHECK_EQ(expected_ovf, m.Call(*j));
4015 CHECK_EQ(expected_val, actual_val); 4023 CHECK_EQ(expected_val, actual_val);
4016 } 4024 }
4017 } 4025 }
4018 { 4026 {
4019 RawMachineAssemblerTester<int32_t> m(kMachineWord32); 4027 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
4020 Node* val, *ovf; 4028 Node* add = m.Int32SubWithOverflow(m.Parameter(0), m.Int32Constant(*i));
4021 m.Int32SubWithOverflow(m.Parameter(0), m.Int32Constant(*i), &val, &ovf); 4029 Node* val = m.Projection(0, add);
4030 Node* ovf = m.Projection(1, add);
4022 m.StoreToPointer(&actual_val, kMachineWord32, val); 4031 m.StoreToPointer(&actual_val, kMachineWord32, val);
4023 m.Return(ovf); 4032 m.Return(ovf);
4024 FOR_INT32_INPUTS(j) { 4033 FOR_INT32_INPUTS(j) {
4025 int expected_ovf = ssub_overflow(*j, *i, &expected_val); 4034 int expected_ovf = ssub_overflow(*j, *i, &expected_val);
4026 CHECK_EQ(expected_ovf, m.Call(*j)); 4035 CHECK_EQ(expected_ovf, m.Call(*j));
4027 CHECK_EQ(expected_val, actual_val); 4036 CHECK_EQ(expected_val, actual_val);
4028 } 4037 }
4029 } 4038 }
4030 FOR_INT32_INPUTS(j) { 4039 FOR_INT32_INPUTS(j) {
4031 RawMachineAssemblerTester<int32_t> m; 4040 RawMachineAssemblerTester<int32_t> m;
4032 Node* val, *ovf; 4041 Node* add =
4033 m.Int32SubWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j), &val, 4042 m.Int32SubWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j));
4034 &ovf); 4043 Node* val = m.Projection(0, add);
4044 Node* ovf = m.Projection(1, add);
4035 m.StoreToPointer(&actual_val, kMachineWord32, val); 4045 m.StoreToPointer(&actual_val, kMachineWord32, val);
4036 m.Return(ovf); 4046 m.Return(ovf);
4037 int expected_ovf = ssub_overflow(*i, *j, &expected_val); 4047 int expected_ovf = ssub_overflow(*i, *j, &expected_val);
4038 CHECK_EQ(expected_ovf, m.Call()); 4048 CHECK_EQ(expected_ovf, m.Call());
4039 CHECK_EQ(expected_val, actual_val); 4049 CHECK_EQ(expected_val, actual_val);
4040 } 4050 }
4041 } 4051 }
4042 } 4052 }
4043 4053
4044 4054
4045 TEST(RunInt32SubWithOverflowInBranchP) { 4055 TEST(RunInt32SubWithOverflowInBranchP) {
4056 int constant = 911999;
4046 MLabel blocka, blockb; 4057 MLabel blocka, blockb;
4047 RawMachineAssemblerTester<int32_t> m; 4058 RawMachineAssemblerTester<int32_t> m;
4048 Int32BinopTester bt(&m); 4059 Int32BinopTester bt(&m);
4049 Node* val, *ovf; 4060 Node* sub = m.Int32SubWithOverflow(bt.param0, bt.param1);
4050 m.Int32SubWithOverflow(bt.param0, bt.param1, &val, &ovf); 4061 Node* ovf = m.Projection(1, sub);
4051 m.Branch(ovf, &blocka, &blockb); 4062 m.Branch(ovf, &blocka, &blockb);
4052 m.Bind(&blocka); 4063 m.Bind(&blocka);
4053 bt.AddReturn(m.Word32Not(val)); 4064 bt.AddReturn(m.Int32Constant(constant));
4054 m.Bind(&blockb); 4065 m.Bind(&blockb);
4066 Node* val = m.Projection(0, sub);
4055 bt.AddReturn(val); 4067 bt.AddReturn(val);
4056 FOR_UINT32_INPUTS(i) { 4068 FOR_UINT32_INPUTS(i) {
4057 FOR_UINT32_INPUTS(j) { 4069 FOR_UINT32_INPUTS(j) {
4058 int32_t expected; 4070 int32_t expected;
4059 if (ssub_overflow(*i, *j, &expected)) expected = ~expected; 4071 if (ssub_overflow(*i, *j, &expected)) expected = constant;
4060 CHECK_EQ(expected, bt.call(*i, *j)); 4072 CHECK_EQ(expected, bt.call(*i, *j));
4061 } 4073 }
4062 } 4074 }
4063 } 4075 }
4064 4076
4065 #endif // V8_TURBOFAN_TARGET 4077 #endif // V8_TURBOFAN_TARGET
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-instruction-selector-arm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698