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

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

Issue 436593002: [turbofan] Add Int32AddWithOverflow machine operator. (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
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 3862 matching lines...) Expand 10 before | Expand all | Expand 10 after
3873 } 3873 }
3874 m.Return(one); 3874 m.Return(one);
3875 m.Call(); 3875 m.Call();
3876 for (int i = 0; i < kInputSize; i++) { 3876 for (int i = 0; i < kInputSize; i++) {
3877 CHECK_EQ(outputs[i], i + 2); 3877 CHECK_EQ(outputs[i], i + 2);
3878 } 3878 }
3879 } 3879 }
3880 3880
3881 #endif // MACHINE_ASSEMBLER_SUPPORTS_CALL_C 3881 #endif // MACHINE_ASSEMBLER_SUPPORTS_CALL_C
3882 3882
3883 #endif 3883
3884 static bool sadd_overflow(int32_t x, int32_t y, int32_t* val) {
3885 int32_t v =
3886 static_cast<int32_t>(static_cast<uint32_t>(x) + static_cast<uint32_t>(y));
3887 *val = v;
3888 return (((v ^ x) & (v ^ y)) >> 31) & 1;
3889 }
3890
3891
3892 TEST(RunInt32AddWithOverflowP) {
3893 int32_t actual_val = -1;
3894 RawMachineAssemblerTester<int32_t> m;
3895 Int32BinopTester bt(&m);
3896 Node* add = m.Int32AddWithOverflow(bt.param0, bt.param1);
3897 Node* val = m.Projection(0, add);
3898 Node* ovf = m.Projection(1, add);
3899 m.StoreToPointer(&actual_val, kMachineWord32, val);
3900 bt.AddReturn(ovf);
3901 FOR_INT32_INPUTS(i) {
3902 FOR_INT32_INPUTS(j) {
3903 int32_t expected_val;
3904 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3905 CHECK_EQ(expected_ovf, bt.call(*i, *j));
3906 CHECK_EQ(expected_val, actual_val);
3907 }
3908 }
3909 }
3910
3911
3912 TEST(RunInt32AddWithOverflowImm) {
3913 int32_t actual_val = -1, expected_val = 0;
3914 FOR_INT32_INPUTS(i) {
3915 {
3916 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
3917 Node* add = m.Int32AddWithOverflow(m.Int32Constant(*i), m.Parameter(0));
3918 Node* val = m.Projection(0, add);
3919 Node* ovf = m.Projection(1, add);
3920 m.StoreToPointer(&actual_val, kMachineWord32, val);
3921 m.Return(ovf);
3922 FOR_INT32_INPUTS(j) {
3923 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3924 CHECK_EQ(expected_ovf, m.Call(*j));
3925 CHECK_EQ(expected_val, actual_val);
3926 }
3927 }
3928 {
3929 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
3930 Node* add = m.Int32AddWithOverflow(m.Parameter(0), m.Int32Constant(*i));
3931 Node* val = m.Projection(0, add);
3932 Node* ovf = m.Projection(1, add);
3933 m.StoreToPointer(&actual_val, kMachineWord32, val);
3934 m.Return(ovf);
3935 FOR_INT32_INPUTS(j) {
3936 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3937 CHECK_EQ(expected_ovf, m.Call(*j));
3938 CHECK_EQ(expected_val, actual_val);
3939 }
3940 }
3941 FOR_INT32_INPUTS(j) {
3942 RawMachineAssemblerTester<int32_t> m;
3943 Node* add =
3944 m.Int32AddWithOverflow(m.Int32Constant(*i), m.Int32Constant(*j));
3945 Node* val = m.Projection(0, add);
3946 Node* ovf = m.Projection(1, add);
3947 m.StoreToPointer(&actual_val, kMachineWord32, val);
3948 m.Return(ovf);
3949 int expected_ovf = sadd_overflow(*i, *j, &expected_val);
3950 CHECK_EQ(expected_ovf, m.Call());
3951 CHECK_EQ(expected_val, actual_val);
3952 }
3953 }
3954 }
3955
3956
3957 TEST(RunInt32AddWithOverflowInBranchP) {
3958 MLabel blocka, blockb;
3959 RawMachineAssemblerTester<int32_t> m;
3960 Int32BinopTester bt(&m);
3961 Node* add = m.Int32AddWithOverflow(bt.param0, bt.param1);
3962 Node* val = m.Projection(0, add);
3963 Node* ovf = m.Projection(1, add);
3964 m.Branch(ovf, &blocka, &blockb);
3965 m.Bind(&blocka);
3966 bt.AddReturn(m.Word32Not(val));
3967 m.Bind(&blockb);
3968 bt.AddReturn(val);
3969 FOR_UINT32_INPUTS(i) {
3970 FOR_UINT32_INPUTS(j) {
3971 int32_t expected;
3972 if (sadd_overflow(*i, *j, &expected)) expected = ~expected;
3973 CHECK_EQ(expected, bt.call(*i, *j));
3974 }
3975 }
3976 }
3977
3978 #endif // V8_TURBOFAN_TARGET
OLDNEW
« src/compiler/machine-node-factory.h ('K') | « 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