Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "src/signature.h" | 5 #include "src/signature.h" |
| 6 | 6 |
| 7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
| 8 #include "src/flags.h" | 8 #include "src/flags.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ | 379 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ |
| 380 case kExpr##name: \ | 380 case kExpr##name: \ |
| 381 return kArity_##sig; | 381 return kArity_##sig; |
| 382 | 382 |
| 383 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 383 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 384 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 384 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 385 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) | 385 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 386 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) | 386 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) |
| 387 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 387 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 388 FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE) | 388 FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE) |
| 389 FOREACH_SIMD_OPCODE(DECLARE_OPCODE_CASE) | 389 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) |
| 390 #undef DECLARE_OPCODE_CASE | 390 #undef DECLARE_OPCODE_CASE |
| 391 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: | |
| 392 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) | |
| 393 #undef DECLARE_OPCODE_CASE | |
| 394 return 1; | |
| 391 default: | 395 default: |
| 392 UNREACHABLE(); | 396 UNREACHABLE(); |
| 393 return 0; | 397 return 0; |
| 394 } | 398 } |
| 395 } | 399 } |
| 396 | 400 |
| 397 unsigned OpcodeLength(const byte* pc) { | 401 unsigned OpcodeLength(const byte* pc) { |
| 398 switch (static_cast<WasmOpcode>(*pc)) { | 402 switch (static_cast<WasmOpcode>(*pc)) { |
| 399 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: | 403 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
| 400 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 404 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 case kExprI8Const: | 453 case kExprI8Const: |
| 450 return 2; | 454 return 2; |
| 451 case kExprF32Const: | 455 case kExprF32Const: |
| 452 return 5; | 456 return 5; |
| 453 case kExprF64Const: | 457 case kExprF64Const: |
| 454 return 9; | 458 return 9; |
| 455 case kExprReturn: { | 459 case kExprReturn: { |
| 456 ReturnArityOperand operand(this, pc); | 460 ReturnArityOperand operand(this, pc); |
| 457 return 1 + operand.length; | 461 return 1 + operand.length; |
| 458 } | 462 } |
| 459 | 463 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
| 464 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 2; } | |
| 465 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 3; } | |
| 466 #undef DECLARE_OPCODE_CASE | |
| 460 default: | 467 default: |
| 461 return 1; | 468 return 1; |
| 462 } | 469 } |
| 463 } | 470 } |
| 464 }; | 471 }; |
| 465 | 472 |
| 466 static const int32_t kFirstFinallyToken = 1; | 473 static const int32_t kFirstFinallyToken = 1; |
| 467 static const int32_t kFallthroughToken = 0; | 474 static const int32_t kFallthroughToken = 0; |
| 468 static const int32_t kNullFinallyToken = -1; | 475 static const int32_t kNullFinallyToken = -1; |
| 469 | 476 |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 Push(GetReturnType(operand.sig), call); | 1271 Push(GetReturnType(operand.sig), call); |
| 1265 } | 1272 } |
| 1266 len = 1 + operand.length; | 1273 len = 1 + operand.length; |
| 1267 break; | 1274 break; |
| 1268 } | 1275 } |
| 1269 case kSimdPrefix: { | 1276 case kSimdPrefix: { |
| 1270 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); | 1277 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); |
| 1271 len++; | 1278 len++; |
| 1272 byte simd_index = *(pc_ + 1); | 1279 byte simd_index = *(pc_ + 1); |
| 1273 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); | 1280 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); |
| 1274 DecodeSimdOpcode(opcode); | 1281 len += DecodeSimdOpcode(opcode); |
| 1275 break; | 1282 break; |
| 1276 } | 1283 } |
| 1277 default: | 1284 default: |
| 1278 error("Invalid opcode"); | 1285 error("Invalid opcode"); |
| 1279 return; | 1286 return; |
| 1280 } | 1287 } |
| 1281 } // end complex bytecode | 1288 } // end complex bytecode |
| 1282 | 1289 |
| 1283 #if DEBUG | 1290 #if DEBUG |
| 1284 if (FLAG_trace_wasm_decoder) { | 1291 if (FLAG_trace_wasm_decoder) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1389 int DecodeStoreMem(LocalType type, MachineType mem_type) { | 1396 int DecodeStoreMem(LocalType type, MachineType mem_type) { |
| 1390 MemoryAccessOperand operand(this, pc_); | 1397 MemoryAccessOperand operand(this, pc_); |
| 1391 Value val = Pop(1, type); | 1398 Value val = Pop(1, type); |
| 1392 Value index = Pop(0, kAstI32); | 1399 Value index = Pop(0, kAstI32); |
| 1393 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, | 1400 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, |
| 1394 val.node, position()); | 1401 val.node, position()); |
| 1395 Push(type, val.node); | 1402 Push(type, val.node); |
| 1396 return 1 + operand.length; | 1403 return 1 + operand.length; |
| 1397 } | 1404 } |
| 1398 | 1405 |
| 1399 void DecodeSimdOpcode(WasmOpcode opcode) { | 1406 unsigned DecodeSimdOpcode(WasmOpcode opcode) { |
| 1400 FunctionSig* sig = WasmOpcodes::Signature(opcode); | 1407 unsigned len = 0; |
| 1401 compiler::NodeVector inputs(sig->parameter_count(), zone_); | 1408 switch (opcode) { |
| 1402 for (size_t i = sig->parameter_count(); i > 0; i--) { | 1409 case kExprI32x4ExtractLane: { |
| 1403 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); | 1410 uint8_t lane = this->checked_read_u8(pc_, 2, "lane number"); |
| 1404 inputs[i - 1] = val.node; | 1411 if (lane >= 0 && lane <= 3) { |
| 1412 error(pc_, pc_ + 2, "invalid extract lane value "); | |
| 1413 } | |
| 1414 TFNode* input = Pop(0, LocalType::kSimd128).node; | |
| 1415 TFNode* node = BUILD(SimdExtractLane, opcode, lane, input); | |
| 1416 Push(LocalType::kWord32, node); | |
| 1417 len++; | |
| 1418 break; | |
| 1419 } | |
| 1420 default: { | |
| 1421 FunctionSig* sig = WasmOpcodes::Signature(opcode); | |
| 1422 if (sig == nullptr) { | |
| 1423 error(pc_, pc_, "invalid simd opcode"); | |
|
titzer
2016/09/05 12:49:50
You'll have to break here, or you'll crash on the
aseemgarg
2016/09/06 02:49:15
Done.
| |
| 1424 } | |
| 1425 compiler::NodeVector inputs(sig->parameter_count(), zone_); | |
| 1426 for (size_t i = sig->parameter_count(); i > 0; i--) { | |
| 1427 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); | |
| 1428 inputs[i - 1] = val.node; | |
| 1429 } | |
| 1430 TFNode* node = BUILD(SimdOp, opcode, inputs); | |
| 1431 Push(GetReturnType(sig), node); | |
| 1432 } | |
| 1405 } | 1433 } |
| 1406 TFNode* node = BUILD(SimdOp, opcode, inputs); | 1434 return len; |
| 1407 Push(GetReturnType(sig), node); | |
| 1408 } | 1435 } |
| 1409 | 1436 |
| 1410 void DispatchToTargets(Control* next_block, const Value& val) { | 1437 void DispatchToTargets(Control* next_block, const Value& val) { |
| 1411 const ZoneVector<IncomingBranch>& incoming_branches = | 1438 const ZoneVector<IncomingBranch>& incoming_branches = |
| 1412 next_block->try_info->incoming_branches; | 1439 next_block->try_info->incoming_branches; |
| 1413 // Counts how many successors are not current control block. | 1440 // Counts how many successors are not current control block. |
| 1414 uint32_t targets = 0; | 1441 uint32_t targets = 0; |
| 1415 for (const auto& path_token : incoming_branches) { | 1442 for (const auto& path_token : incoming_branches) { |
| 1416 if (path_token.target != next_block) ++targets; | 1443 if (path_token.target != next_block) ++targets; |
| 1417 } | 1444 } |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2064 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 2091 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
| 2065 const byte* start, const byte* end) { | 2092 const byte* start, const byte* end) { |
| 2066 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 2093 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
| 2067 WasmFullDecoder decoder(zone, nullptr, body); | 2094 WasmFullDecoder decoder(zone, nullptr, body); |
| 2068 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 2095 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
| 2069 } | 2096 } |
| 2070 | 2097 |
| 2071 } // namespace wasm | 2098 } // namespace wasm |
| 2072 } // namespace internal | 2099 } // namespace internal |
| 2073 } // namespace v8 | 2100 } // namespace v8 |
| OLD | NEW |