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/wasm/wasm-opcodes.h" | 5 #include "src/wasm/wasm-opcodes.h" |
6 #include "src/messages.h" | 6 #include "src/messages.h" |
7 #include "src/signature.h" | 7 #include "src/signature.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 static const FunctionSig kSig_##name( \ | 61 static const FunctionSig kSig_##name( \ |
62 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); | 62 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); |
63 | 63 |
64 FOREACH_SIGNATURE(DECLARE_SIG) | 64 FOREACH_SIGNATURE(DECLARE_SIG) |
65 | 65 |
66 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, | 66 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, |
67 | 67 |
68 static const FunctionSig* kSimpleExprSigs[] = { | 68 static const FunctionSig* kSimpleExprSigs[] = { |
69 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; | 69 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; |
70 | 70 |
| 71 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name, |
| 72 |
| 73 static const FunctionSig* kSimdExprSigs[] = { |
| 74 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)}; |
| 75 |
71 static byte kSimpleExprSigTable[256]; | 76 static byte kSimpleExprSigTable[256]; |
| 77 static byte kSimdExprSigTable[256]; |
72 | 78 |
73 // Initialize the signature table. | 79 // Initialize the signature table. |
74 static void InitSigTable() { | 80 static void InitSigTables() { |
75 #define SET_SIG_TABLE(name, opcode, sig) \ | 81 #define SET_SIG_TABLE(name, opcode, sig) \ |
76 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; | 82 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
77 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); | 83 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); |
78 FOREACH_SIMPLE_MEM_OPCODE(SET_SIG_TABLE); | 84 FOREACH_SIMPLE_MEM_OPCODE(SET_SIG_TABLE); |
79 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); | 85 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); |
80 #undef SET_SIG_TABLE | 86 #undef SET_SIG_TABLE |
| 87 byte simd_index; |
| 88 #define SET_SIG_TABLE(name, opcode, sig) \ |
| 89 simd_index = opcode & 0xff; \ |
| 90 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1; |
| 91 FOREACH_SIMD_OPCODE(SET_SIG_TABLE) |
| 92 #undef SET_SIG_TABLE |
81 } | 93 } |
82 | 94 |
83 class SigTable { | 95 class SigTable { |
84 public: | 96 public: |
85 SigTable() { | 97 SigTable() { |
86 // TODO(ahaas): Move {InitSigTable} into the class. | 98 // TODO(ahaas): Move {InitSigTable} into the class. |
87 InitSigTable(); | 99 InitSigTables(); |
88 } | 100 } |
89 FunctionSig* Signature(WasmOpcode opcode) const { | 101 FunctionSig* Signature(WasmOpcode opcode) const { |
90 return const_cast<FunctionSig*>( | 102 return const_cast<FunctionSig*>( |
91 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); | 103 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); |
92 } | 104 } |
| 105 FunctionSig* SimdSignature(WasmOpcode opcode) const { |
| 106 return const_cast<FunctionSig*>( |
| 107 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]); |
| 108 } |
93 }; | 109 }; |
94 | 110 |
95 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; | 111 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; |
96 | 112 |
97 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { | 113 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { |
98 return sig_table.Get().Signature(opcode); | 114 if (opcode >> 8 == kSimdPrefix) { |
| 115 return sig_table.Get().SimdSignature(opcode); |
| 116 } else { |
| 117 return sig_table.Get().Signature(opcode); |
| 118 } |
99 } | 119 } |
100 | 120 |
101 // TODO(titzer): pull WASM_64 up to a common header. | 121 // TODO(titzer): pull WASM_64 up to a common header. |
102 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 122 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
103 #define WASM_64 1 | 123 #define WASM_64 1 |
104 #else | 124 #else |
105 #define WASM_64 0 | 125 #define WASM_64 0 |
106 #endif | 126 #endif |
107 | 127 |
108 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { | 128 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { |
109 switch (reason) { | 129 switch (reason) { |
110 #define TRAPREASON_TO_MESSAGE(name) \ | 130 #define TRAPREASON_TO_MESSAGE(name) \ |
111 case k##name: \ | 131 case k##name: \ |
112 return MessageTemplate::kWasm##name; | 132 return MessageTemplate::kWasm##name; |
113 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | 133 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
114 #undef TRAPREASON_TO_MESSAGE | 134 #undef TRAPREASON_TO_MESSAGE |
115 default: | 135 default: |
116 return MessageTemplate::kNone; | 136 return MessageTemplate::kNone; |
117 } | 137 } |
118 } | 138 } |
119 | 139 |
120 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { | 140 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { |
121 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); | 141 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
122 } | 142 } |
123 } // namespace wasm | 143 } // namespace wasm |
124 } // namespace internal | 144 } // namespace internal |
125 } // namespace v8 | 145 } // namespace v8 |
OLD | NEW |