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

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

Issue 1991143002: Convert SIMD wasm ops to runtime function calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup Created 4 years, 5 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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 InitSigTable() {
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
81 } 87 }
82 88
89 // Initialize the signature table.
titzer 2016/07/08 14:16:03 You can just merge this with the above function an
gdeepti 2016/07/11 09:50:34 Done.
90 static void InitSimdSigTable() {
91 byte simd_index;
92 #define SET_SIG_TABLE(name, opcode, sig) \
93 simd_index = opcode & 0xff; \
94 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1;
95 FOREACH_SIMD_OPCODE(SET_SIG_TABLE)
96 #undef SET_SIG_TABLE
97 }
98
83 class SigTable { 99 class SigTable {
84 public: 100 public:
85 SigTable() { 101 SigTable() {
86 // TODO(ahaas): Move {InitSigTable} into the class. 102 // TODO(ahaas): Move {InitSigTable} into the class.
87 InitSigTable(); 103 InitSigTable();
104 InitSimdSigTable();
88 } 105 }
89 FunctionSig* Signature(WasmOpcode opcode) const { 106 FunctionSig* Signature(WasmOpcode opcode) const {
90 return const_cast<FunctionSig*>( 107 return const_cast<FunctionSig*>(
91 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); 108 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]);
92 } 109 }
110 FunctionSig* SimdSignature(WasmOpcode opcode) const {
111 return const_cast<FunctionSig*>(
112 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]);
113 }
93 }; 114 };
94 115
95 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; 116 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER;
96 117
97 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { 118 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
98 return sig_table.Get().Signature(opcode); 119 if (opcode >> 8 == kSimdPrefix) {
120 return sig_table.Get().SimdSignature(opcode);
121 } else {
122 return sig_table.Get().Signature(opcode);
123 }
99 } 124 }
100 125
101 // TODO(titzer): pull WASM_64 up to a common header. 126 // TODO(titzer): pull WASM_64 up to a common header.
102 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 127 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
103 #define WASM_64 1 128 #define WASM_64 1
104 #else 129 #else
105 #define WASM_64 0 130 #define WASM_64 0
106 #endif 131 #endif
107 132
108 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { 133 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
109 switch (reason) { 134 switch (reason) {
110 #define TRAPREASON_TO_MESSAGE(name) \ 135 #define TRAPREASON_TO_MESSAGE(name) \
111 case k##name: \ 136 case k##name: \
112 return MessageTemplate::kWasm##name; 137 return MessageTemplate::kWasm##name;
113 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) 138 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
114 #undef TRAPREASON_TO_MESSAGE 139 #undef TRAPREASON_TO_MESSAGE
115 default: 140 default:
116 return MessageTemplate::kNone; 141 return MessageTemplate::kNone;
117 } 142 }
118 } 143 }
119 144
120 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { 145 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
121 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); 146 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
122 } 147 }
123 } // namespace wasm 148 } // namespace wasm
124 } // namespace internal 149 } // namespace internal
125 } // namespace v8 150 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698