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

Side by Side Diff: test/unittests/wasm/loop-assignment-analysis-unittest.cc

Issue 1970543003: [formatting] Remove all double blank lines in WASM code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « test/unittests/wasm/encoder-unittest.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 14 matching lines...) Expand all
25 public: 25 public:
26 WasmLoopAssignmentAnalyzerTest() : num_locals(0) {} 26 WasmLoopAssignmentAnalyzerTest() : num_locals(0) {}
27 TestSignatures sigs; 27 TestSignatures sigs;
28 uint32_t num_locals; 28 uint32_t num_locals;
29 29
30 BitVector* Analyze(const byte* start, const byte* end) { 30 BitVector* Analyze(const byte* start, const byte* end) {
31 return AnalyzeLoopAssignmentForTesting(zone(), num_locals, start, end); 31 return AnalyzeLoopAssignmentForTesting(zone(), num_locals, start, end);
32 } 32 }
33 }; 33 };
34 34
35
36 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty0) { 35 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty0) {
37 byte code[] = { 0 }; 36 byte code[] = { 0 };
38 BitVector* assigned = Analyze(code, code); 37 BitVector* assigned = Analyze(code, code);
39 CHECK_NULL(assigned); 38 CHECK_NULL(assigned);
40 } 39 }
41 40
42
43 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty1) { 41 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty1) {
44 byte code[] = {kExprLoop, 0}; 42 byte code[] = {kExprLoop, 0};
45 for (int i = 0; i < 5; i++) { 43 for (int i = 0; i < 5; i++) {
46 BitVector* assigned = Analyze(code, code + arraysize(code)); 44 BitVector* assigned = Analyze(code, code + arraysize(code));
47 for (int j = 0; j < assigned->length(); j++) { 45 for (int j = 0; j < assigned->length(); j++) {
48 CHECK_EQ(false, assigned->Contains(j)); 46 CHECK_EQ(false, assigned->Contains(j));
49 } 47 }
50 num_locals++; 48 num_locals++;
51 } 49 }
52 } 50 }
53 51
54
55 TEST_F(WasmLoopAssignmentAnalyzerTest, One) { 52 TEST_F(WasmLoopAssignmentAnalyzerTest, One) {
56 num_locals = 5; 53 num_locals = 5;
57 for (int i = 0; i < 5; i++) { 54 for (int i = 0; i < 5; i++) {
58 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i))}; 55 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i))};
59 BitVector* assigned = Analyze(code, code + arraysize(code)); 56 BitVector* assigned = Analyze(code, code + arraysize(code));
60 for (int j = 0; j < assigned->length(); j++) { 57 for (int j = 0; j < assigned->length(); j++) {
61 CHECK_EQ(j == i, assigned->Contains(j)); 58 CHECK_EQ(j == i, assigned->Contains(j));
62 } 59 }
63 } 60 }
64 } 61 }
65 62
66
67 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) { 63 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) {
68 num_locals = 5; 64 num_locals = 5;
69 for (int i = 0; i < 5; i++) { 65 for (int i = 0; i < 5; i++) {
70 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i)), WASM_SET_ZERO(1)}; 66 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i)), WASM_SET_ZERO(1)};
71 BitVector* assigned = Analyze(code, code + arraysize(code)); 67 BitVector* assigned = Analyze(code, code + arraysize(code));
72 for (int j = 0; j < assigned->length(); j++) { 68 for (int j = 0; j < assigned->length(); j++) {
73 CHECK_EQ(j == i, assigned->Contains(j)); 69 CHECK_EQ(j == i, assigned->Contains(j));
74 } 70 }
75 } 71 }
76 } 72 }
77 73
78
79 TEST_F(WasmLoopAssignmentAnalyzerTest, Two) { 74 TEST_F(WasmLoopAssignmentAnalyzerTest, Two) {
80 num_locals = 5; 75 num_locals = 5;
81 for (int i = 0; i < 5; i++) { 76 for (int i = 0; i < 5; i++) {
82 for (int j = 0; j < 5; j++) { 77 for (int j = 0; j < 5; j++) {
83 byte code[] = {WASM_LOOP(2, WASM_SET_ZERO(i), WASM_SET_ZERO(j))}; 78 byte code[] = {WASM_LOOP(2, WASM_SET_ZERO(i), WASM_SET_ZERO(j))};
84 BitVector* assigned = Analyze(code, code + arraysize(code)); 79 BitVector* assigned = Analyze(code, code + arraysize(code));
85 for (int k = 0; k < assigned->length(); k++) { 80 for (int k = 0; k < assigned->length(); k++) {
86 bool expected = k == i || k == j; 81 bool expected = k == i || k == j;
87 CHECK_EQ(expected, assigned->Contains(k)); 82 CHECK_EQ(expected, assigned->Contains(k));
88 } 83 }
89 } 84 }
90 } 85 }
91 } 86 }
92 87
93
94 TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) { 88 TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) {
95 num_locals = 5; 89 num_locals = 5;
96 for (int i = 0; i < 5; i++) { 90 for (int i = 0; i < 5; i++) {
97 byte code[] = {WASM_LOOP( 91 byte code[] = {WASM_LOOP(
98 1, WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))}; 92 1, WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))};
99 BitVector* assigned = Analyze(code, code + arraysize(code)); 93 BitVector* assigned = Analyze(code, code + arraysize(code));
100 for (int j = 0; j < assigned->length(); j++) { 94 for (int j = 0; j < assigned->length(); j++) {
101 bool expected = i == j || j == 0 || j == 1; 95 bool expected = i == j || j == 0 || j == 1;
102 CHECK_EQ(expected, assigned->Contains(j)); 96 CHECK_EQ(expected, assigned->Contains(j));
103 } 97 }
104 } 98 }
105 } 99 }
106 100
107
108 static byte LEBByte(uint32_t val, byte which) { 101 static byte LEBByte(uint32_t val, byte which) {
109 byte b = (val >> (which * 7)) & 0x7F; 102 byte b = (val >> (which * 7)) & 0x7F;
110 if (val >> ((which + 1) * 7)) b |= 0x80; 103 if (val >> ((which + 1) * 7)) b |= 0x80;
111 return b; 104 return b;
112 } 105 }
113 106
114
115 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { 107 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) {
116 num_locals = 65000; 108 num_locals = 65000;
117 for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) { 109 for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) {
118 byte code[] = {kExprLoop, 110 byte code[] = {kExprLoop,
119 1, 111 1,
120 kExprSetLocal, 112 kExprSetLocal,
121 LEBByte(i, 0), 113 LEBByte(i, 0),
122 LEBByte(i, 1), 114 LEBByte(i, 1),
123 LEBByte(i, 2), 115 LEBByte(i, 2),
124 11, 116 11,
125 12, 117 12,
126 13}; 118 13};
127 119
128 BitVector* assigned = Analyze(code, code + arraysize(code)); 120 BitVector* assigned = Analyze(code, code + arraysize(code));
129 for (int j = 0; j < assigned->length(); j++) { 121 for (int j = 0; j < assigned->length(); j++) {
130 bool expected = i == j; 122 bool expected = i == j;
131 CHECK_EQ(expected, assigned->Contains(j)); 123 CHECK_EQ(expected, assigned->Contains(j));
132 } 124 }
133 } 125 }
134 } 126 }
135 127
136
137 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { 128 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) {
138 num_locals = 3; 129 num_locals = 3;
139 byte code[] = { 130 byte code[] = {
140 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))), 131 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))),
141 WASM_SET_ZERO(0)}; 132 WASM_SET_ZERO(0)};
142 133
143 BitVector* assigned = Analyze(code, code + arraysize(code)); 134 BitVector* assigned = Analyze(code, code + arraysize(code));
144 for (int j = 0; j < assigned->length(); j++) { 135 for (int j = 0; j < assigned->length(); j++) {
145 bool expected = j == 1; 136 bool expected = j == 1;
146 CHECK_EQ(expected, assigned->Contains(j)); 137 CHECK_EQ(expected, assigned->Contains(j));
147 } 138 }
148 } 139 }
149 140
150
151 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { 141 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) {
152 num_locals = 5; 142 num_locals = 5;
153 byte code[] = { 143 byte code[] = {
154 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), 144 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0),
155 WASM_BRV(0, WASM_SET_LOCAL( 145 WASM_BRV(0, WASM_SET_LOCAL(
156 3, WASM_I32_SUB(WASM_GET_LOCAL(0), 146 3, WASM_I32_SUB(WASM_GET_LOCAL(0),
157 WASM_I8(1)))))), 147 WASM_I8(1)))))),
158 WASM_GET_LOCAL(0)}; 148 WASM_GET_LOCAL(0)};
159 149
160 BitVector* assigned = Analyze(code, code + arraysize(code)); 150 BitVector* assigned = Analyze(code, code + arraysize(code));
161 for (int j = 0; j < assigned->length(); j++) { 151 for (int j = 0; j < assigned->length(); j++) {
162 bool expected = j == 3; 152 bool expected = j == 3;
163 CHECK_EQ(expected, assigned->Contains(j)); 153 CHECK_EQ(expected, assigned->Contains(j));
164 } 154 }
165 } 155 }
166 156
167
168 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { 157 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) {
169 num_locals = 6; 158 num_locals = 6;
170 const byte kIter = 0; 159 const byte kIter = 0;
171 const byte kSum = 3; 160 const byte kSum = 3;
172 161
173 byte code[] = {WASM_BLOCK( 162 byte code[] = {WASM_BLOCK(
174 3, 163 3,
175 WASM_WHILE( 164 WASM_WHILE(
176 WASM_GET_LOCAL(kIter), 165 WASM_GET_LOCAL(kIter),
177 WASM_BLOCK(2, WASM_SET_LOCAL( 166 WASM_BLOCK(2, WASM_SET_LOCAL(
178 kSum, WASM_F32_ADD( 167 kSum, WASM_F32_ADD(
179 WASM_GET_LOCAL(kSum), 168 WASM_GET_LOCAL(kSum),
180 WASM_LOAD_MEM(MachineType::Float32(), 169 WASM_LOAD_MEM(MachineType::Float32(),
181 WASM_GET_LOCAL(kIter)))), 170 WASM_GET_LOCAL(kIter)))),
182 WASM_SET_LOCAL(kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter), 171 WASM_SET_LOCAL(kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter),
183 WASM_I8(4))))), 172 WASM_I8(4))))),
184 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), 173 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)),
185 WASM_GET_LOCAL(kIter))}; 174 WASM_GET_LOCAL(kIter))};
186 175
187 BitVector* assigned = Analyze(code + 1, code + arraysize(code)); 176 BitVector* assigned = Analyze(code + 1, code + arraysize(code));
188 for (int j = 0; j < assigned->length(); j++) { 177 for (int j = 0; j < assigned->length(); j++) {
189 bool expected = j == kIter || j == kSum; 178 bool expected = j == kIter || j == kSum;
190 CHECK_EQ(expected, assigned->Contains(j)); 179 CHECK_EQ(expected, assigned->Contains(j));
191 } 180 }
192 } 181 }
193 182
194
195 } // namespace wasm 183 } // namespace wasm
196 } // namespace internal 184 } // namespace internal
197 } // namespace v8 185 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/encoder-unittest.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698