| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 for (int j = 0; j < assigned->length(); j++) { | 45 for (int j = 0; j < assigned->length(); j++) { |
| 46 CHECK_EQ(false, assigned->Contains(j)); | 46 CHECK_EQ(false, assigned->Contains(j)); |
| 47 } | 47 } |
| 48 num_locals++; | 48 num_locals++; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(WasmLoopAssignmentAnalyzerTest, One) { | 52 TEST_F(WasmLoopAssignmentAnalyzerTest, One) { |
| 53 num_locals = 5; | 53 num_locals = 5; |
| 54 for (int i = 0; i < 5; i++) { | 54 for (int i = 0; i < 5; i++) { |
| 55 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i))}; | 55 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i))}; |
| 56 BitVector* assigned = Analyze(code, code + arraysize(code)); | 56 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 57 for (int j = 0; j < assigned->length(); j++) { | 57 for (int j = 0; j < assigned->length(); j++) { |
| 58 CHECK_EQ(j == i, assigned->Contains(j)); | 58 CHECK_EQ(j == i, assigned->Contains(j)); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) { | 63 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) { |
| 64 num_locals = 5; | 64 num_locals = 5; |
| 65 for (int i = 0; i < 5; i++) { | 65 for (int i = 0; i < 5; i++) { |
| 66 byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i)), WASM_SET_ZERO(1)}; | 66 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i)), WASM_SET_ZERO(1)}; |
| 67 BitVector* assigned = Analyze(code, code + arraysize(code)); | 67 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 68 for (int j = 0; j < assigned->length(); j++) { | 68 for (int j = 0; j < assigned->length(); j++) { |
| 69 CHECK_EQ(j == i, assigned->Contains(j)); | 69 CHECK_EQ(j == i, assigned->Contains(j)); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST_F(WasmLoopAssignmentAnalyzerTest, Two) { | 74 TEST_F(WasmLoopAssignmentAnalyzerTest, Two) { |
| 75 num_locals = 5; | 75 num_locals = 5; |
| 76 for (int i = 0; i < 5; i++) { | 76 for (int i = 0; i < 5; i++) { |
| 77 for (int j = 0; j < 5; j++) { | 77 for (int j = 0; j < 5; j++) { |
| 78 byte code[] = {WASM_LOOP(2, WASM_SET_ZERO(i), WASM_SET_ZERO(j))}; | 78 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i), WASM_SET_ZERO(j))}; |
| 79 BitVector* assigned = Analyze(code, code + arraysize(code)); | 79 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 80 for (int k = 0; k < assigned->length(); k++) { | 80 for (int k = 0; k < assigned->length(); k++) { |
| 81 bool expected = k == i || k == j; | 81 bool expected = k == i || k == j; |
| 82 CHECK_EQ(expected, assigned->Contains(k)); | 82 CHECK_EQ(expected, assigned->Contains(k)); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) { | 88 TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) { |
| 89 num_locals = 5; | 89 num_locals = 5; |
| 90 for (int i = 0; i < 5; i++) { | 90 for (int i = 0; i < 5; i++) { |
| 91 byte code[] = {WASM_LOOP( | 91 byte code[] = {WASM_LOOP( |
| 92 1, WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))}; | 92 WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))}; |
| 93 BitVector* assigned = Analyze(code, code + arraysize(code)); | 93 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 94 for (int j = 0; j < assigned->length(); j++) { | 94 for (int j = 0; j < assigned->length(); j++) { |
| 95 bool expected = i == j || j == 0 || j == 1; | 95 bool expected = i == j || j == 0 || j == 1; |
| 96 CHECK_EQ(expected, assigned->Contains(j)); | 96 CHECK_EQ(expected, assigned->Contains(j)); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 static byte LEBByte(uint32_t val, byte which) { | 101 static byte LEBByte(uint32_t val, byte which) { |
| 102 byte b = (val >> (which * 7)) & 0x7F; | 102 byte b = (val >> (which * 7)) & 0x7F; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 for (int j = 0; j < assigned->length(); j++) { | 121 for (int j = 0; j < assigned->length(); j++) { |
| 122 bool expected = i == j; | 122 bool expected = i == j; |
| 123 CHECK_EQ(expected, assigned->Contains(j)); | 123 CHECK_EQ(expected, assigned->Contains(j)); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { | 128 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { |
| 129 num_locals = 3; | 129 num_locals = 3; |
| 130 byte code[] = { | 130 byte code[] = { |
| 131 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))), | 131 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))), |
| 132 WASM_SET_ZERO(0)}; | 132 WASM_SET_ZERO(0)}; |
| 133 | 133 |
| 134 BitVector* assigned = Analyze(code, code + arraysize(code)); | 134 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 135 for (int j = 0; j < assigned->length(); j++) { | 135 for (int j = 0; j < assigned->length(); j++) { |
| 136 bool expected = j == 1; | 136 bool expected = j == 1; |
| 137 CHECK_EQ(expected, assigned->Contains(j)); | 137 CHECK_EQ(expected, assigned->Contains(j)); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { | 141 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { |
| 142 num_locals = 5; | 142 num_locals = 5; |
| 143 byte code[] = { | 143 byte code[] = { |
| 144 WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), | 144 WASM_LOOP(WASM_IF( |
| 145 WASM_BRV(0, WASM_SET_LOCAL( | 145 WASM_GET_LOCAL(0), |
| 146 3, WASM_I32_SUB(WASM_GET_LOCAL(0), | 146 WASM_BRV(0, WASM_SET_LOCAL( |
| 147 WASM_I8(1)))))), | 147 3, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))))), |
| 148 WASM_GET_LOCAL(0)}; | 148 WASM_GET_LOCAL(0)}; |
| 149 | 149 |
| 150 BitVector* assigned = Analyze(code, code + arraysize(code)); | 150 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 151 for (int j = 0; j < assigned->length(); j++) { | 151 for (int j = 0; j < assigned->length(); j++) { |
| 152 bool expected = j == 3; | 152 bool expected = j == 3; |
| 153 CHECK_EQ(expected, assigned->Contains(j)); | 153 CHECK_EQ(expected, assigned->Contains(j)); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { | 157 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { |
| 158 num_locals = 6; | 158 num_locals = 6; |
| 159 const byte kIter = 0; | 159 const byte kIter = 0; |
| 160 const byte kSum = 3; | 160 const byte kSum = 3; |
| 161 | 161 |
| 162 byte code[] = {WASM_BLOCK( | 162 byte code[] = {WASM_BLOCK( |
| 163 3, | |
| 164 WASM_WHILE( | 163 WASM_WHILE( |
| 165 WASM_GET_LOCAL(kIter), | 164 WASM_GET_LOCAL(kIter), |
| 166 WASM_BLOCK(2, WASM_SET_LOCAL( | 165 WASM_BLOCK( |
| 167 kSum, WASM_F32_ADD( | 166 WASM_SET_LOCAL( |
| 168 WASM_GET_LOCAL(kSum), | 167 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), |
| 169 WASM_LOAD_MEM(MachineType::Float32(), | 168 WASM_LOAD_MEM(MachineType::Float32(), |
| 170 WASM_GET_LOCAL(kIter)))), | 169 WASM_GET_LOCAL(kIter)))), |
| 171 WASM_SET_LOCAL(kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter), | 170 WASM_SET_LOCAL(kIter, |
| 172 WASM_I8(4))))), | 171 WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))), |
| 173 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), | 172 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), |
| 174 WASM_GET_LOCAL(kIter))}; | 173 WASM_GET_LOCAL(kIter))}; |
| 175 | 174 |
| 176 BitVector* assigned = Analyze(code + 1, code + arraysize(code)); | 175 BitVector* assigned = Analyze(code + 1, code + arraysize(code)); |
| 177 for (int j = 0; j < assigned->length(); j++) { | 176 for (int j = 0; j < assigned->length(); j++) { |
| 178 bool expected = j == kIter || j == kSum; | 177 bool expected = j == kIter || j == kSum; |
| 179 CHECK_EQ(expected, assigned->Contains(j)); | 178 CHECK_EQ(expected, assigned->Contains(j)); |
| 180 } | 179 } |
| 181 } | 180 } |
| 182 | 181 |
| 183 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { | 182 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { |
| 184 byte code[] = {kExprLoop, kExprF32Neg, kExprBrTable, 0x0e, 'h', 'e', | 183 byte code[] = {kExprLoop, kExprF32Neg, kExprBrTable, 0x0e, 'h', 'e', |
| 185 'l', 'l', 'o', ',', ' ', 'w', | 184 'l', 'l', 'o', ',', ' ', 'w', |
| 186 'o', 'r', 'l', 'd', '!'}; | 185 'o', 'r', 'l', 'd', '!'}; |
| 187 BitVector* assigned = Analyze(code, code + arraysize(code)); | 186 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 188 CHECK_NULL(assigned); | 187 CHECK_NULL(assigned); |
| 189 } | 188 } |
| 190 | 189 |
| 191 } // namespace wasm | 190 } // namespace wasm |
| 192 } // namespace internal | 191 } // namespace internal |
| 193 } // namespace v8 | 192 } // namespace v8 |
| OLD | NEW |