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

Side by Side Diff: src/wasm/wasm-opcodes.cc

Issue 2423883003: [wasm] add atomic opcodes (Closed)
Patch Set: [wasm] add atomic opcodes Created 4 years, 1 month 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 | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; 81 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
82 82
83 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name, 83 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name,
84 84
85 static const FunctionSig* kSimdExprSigs[] = { 85 static const FunctionSig* kSimdExprSigs[] = {
86 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)}; 86 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)};
87 87
88 static byte kSimpleExprSigTable[256]; 88 static byte kSimpleExprSigTable[256];
89 static byte kSimpleAsmjsExprSigTable[256]; 89 static byte kSimpleAsmjsExprSigTable[256];
90 static byte kSimdExprSigTable[256]; 90 static byte kSimdExprSigTable[256];
91 static byte kAtomicExprSigTable[256];
91 92
92 // Initialize the signature table. 93 // Initialize the signature table.
93 static void InitSigTables() { 94 static void InitSigTables() {
94 #define SET_SIG_TABLE(name, opcode, sig) \ 95 #define SET_SIG_TABLE(name, opcode, sig) \
95 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; 96 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1;
96 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); 97 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE);
97 #undef SET_SIG_TABLE 98 #undef SET_SIG_TABLE
98 #define SET_ASMJS_SIG_TABLE(name, opcode, sig) \ 99 #define SET_ASMJS_SIG_TABLE(name, opcode, sig) \
99 kSimpleAsmjsExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; 100 kSimpleAsmjsExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1;
100 FOREACH_ASMJS_COMPAT_OPCODE(SET_ASMJS_SIG_TABLE); 101 FOREACH_ASMJS_COMPAT_OPCODE(SET_ASMJS_SIG_TABLE);
101 #undef SET_ASMJS_SIG_TABLE 102 #undef SET_ASMJS_SIG_TABLE
102 byte simd_index; 103 byte simd_index;
103 #define SET_SIG_TABLE(name, opcode, sig) \ 104 #define SET_SIG_TABLE(name, opcode, sig) \
104 simd_index = opcode & 0xff; \ 105 simd_index = opcode & 0xff; \
105 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1; 106 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1;
106 FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE) 107 FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE)
107 #undef SET_SIG_TABLE 108 #undef SET_SIG_TABLE
109 byte atomic_index;
110 #define SET_ATOMIC_SIG_TABLE(name, opcode, sig) \
111 atomic_index = opcode & 0xff; \
112 kAtomicExprSigTable[atomic_index] = static_cast<int>(kSigEnum_##sig) + 1;
113 FOREACH_ATOMIC_OPCODE(SET_ATOMIC_SIG_TABLE)
114 #undef SET_ATOMIC_SIG_TABLE
108 } 115 }
109 116
110 class SigTable { 117 class SigTable {
111 public: 118 public:
112 SigTable() { 119 SigTable() {
113 // TODO(ahaas): Move {InitSigTable} into the class. 120 // TODO(ahaas): Move {InitSigTable} into the class.
114 InitSigTables(); 121 InitSigTables();
115 } 122 }
116 FunctionSig* Signature(WasmOpcode opcode) const { 123 FunctionSig* Signature(WasmOpcode opcode) const {
117 return const_cast<FunctionSig*>( 124 return const_cast<FunctionSig*>(
118 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); 125 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]);
119 } 126 }
120 FunctionSig* AsmjsSignature(WasmOpcode opcode) const { 127 FunctionSig* AsmjsSignature(WasmOpcode opcode) const {
121 return const_cast<FunctionSig*>( 128 return const_cast<FunctionSig*>(
122 kSimpleExprSigs[kSimpleAsmjsExprSigTable[static_cast<byte>(opcode)]]); 129 kSimpleExprSigs[kSimpleAsmjsExprSigTable[static_cast<byte>(opcode)]]);
123 } 130 }
124 FunctionSig* SimdSignature(WasmOpcode opcode) const { 131 FunctionSig* SimdSignature(WasmOpcode opcode) const {
125 return const_cast<FunctionSig*>( 132 return const_cast<FunctionSig*>(
126 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]); 133 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]);
127 } 134 }
135 FunctionSig* AtomicSignature(WasmOpcode opcode) const {
136 return const_cast<FunctionSig*>(
137 kSimpleExprSigs[kAtomicExprSigTable[static_cast<byte>(opcode & 0xff)]]);
138 }
128 }; 139 };
129 140
130 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; 141 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER;
131 142
132 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { 143 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
133 if (opcode >> 8 == kSimdPrefix) { 144 if (opcode >> 8 == kSimdPrefix) {
134 return sig_table.Get().SimdSignature(opcode); 145 return sig_table.Get().SimdSignature(opcode);
135 } else { 146 } else {
136 return sig_table.Get().Signature(opcode); 147 return sig_table.Get().Signature(opcode);
137 } 148 }
138 } 149 }
139 150
140 FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) { 151 FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) {
141 return sig_table.Get().AsmjsSignature(opcode); 152 return sig_table.Get().AsmjsSignature(opcode);
142 } 153 }
143 154
155 FunctionSig* WasmOpcodes::AtomicSignature(WasmOpcode opcode) {
156 return sig_table.Get().AtomicSignature(opcode);
157 }
158
144 // TODO(titzer): pull WASM_64 up to a common header. 159 // TODO(titzer): pull WASM_64 up to a common header.
145 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 160 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
146 #define WASM_64 1 161 #define WASM_64 1
147 #else 162 #else
148 #define WASM_64 0 163 #define WASM_64 0
149 #endif 164 #endif
150 165
151 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { 166 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
152 switch (reason) { 167 switch (reason) {
153 #define TRAPREASON_TO_MESSAGE(name) \ 168 #define TRAPREASON_TO_MESSAGE(name) \
154 case k##name: \ 169 case k##name: \
155 return MessageTemplate::kWasm##name; 170 return MessageTemplate::kWasm##name;
156 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) 171 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
157 #undef TRAPREASON_TO_MESSAGE 172 #undef TRAPREASON_TO_MESSAGE
158 default: 173 default:
159 return MessageTemplate::kNone; 174 return MessageTemplate::kNone;
160 } 175 }
161 } 176 }
162 177
163 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { 178 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
164 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); 179 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
165 } 180 }
166 } // namespace wasm 181 } // namespace wasm
167 } // namespace internal 182 } // namespace internal
168 } // namespace v8 183 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698