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

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

Issue 1504713014: Initial import of v8-native WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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') | src/wasm/wasm-result.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/wasm/wasm-opcodes.h"
6 #include "src/signature.h"
7
8 namespace v8 {
9 namespace internal {
10 namespace wasm {
11
12 typedef Signature<LocalType> FunctionSig;
13
14 const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
15 switch (opcode) {
16 #define DECLARE_NAME_CASE(name, opcode, sig) \
17 case kExpr##name: \
18 return "Expr" #name;
19 FOREACH_OPCODE(DECLARE_NAME_CASE)
20 #undef DECLARE_NAME_CASE
21 default:
22 break;
23 }
24 return "Unknown";
25 }
26
27
28 #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name,
29
30
31 enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) };
32
33
34 // TODO(titzer): not static-initializer safe. Wrap in LazyInstance.
35 #define DECLARE_SIG(name, ...) \
36 static LocalType kTypes_##name[] = {__VA_ARGS__}; \
37 static const FunctionSig kSig_##name( \
38 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name);
39
40 FOREACH_SIGNATURE(DECLARE_SIG)
41
42 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name,
43
44 static const FunctionSig* kSimpleExprSigs[] = {
45 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
46
47 static byte kSimpleExprSigTable[256];
48
49
50 // Initialize the signature table.
51 static void InitSigTable() {
52 #define SET_SIG_TABLE(name, opcode, sig) \
53 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1;
54 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE);
55 #undef SET_SIG_TABLE
56 }
57
58
59 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
60 // TODO(titzer): use LazyInstance to make this thread safe.
61 if (kSimpleExprSigTable[kExprI32Add] == 0) InitSigTable();
62 return const_cast<FunctionSig*>(
63 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]);
64 }
65
66
67 // TODO(titzer): pull WASM_64 up to a common header.
68 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
69 #define WASM_64 1
70 #else
71 #define WASM_64 0
72 #endif
73
74
75 bool WasmOpcodes::IsSupported(WasmOpcode opcode) {
76 switch (opcode) {
77 #if !WASM_64
78 // Opcodes not supported on 32-bit platforms.
79 case kExprI64Add:
80 case kExprI64Sub:
81 case kExprI64Mul:
82 case kExprI64DivS:
83 case kExprI64DivU:
84 case kExprI64RemS:
85 case kExprI64RemU:
86 case kExprI64And:
87 case kExprI64Ior:
88 case kExprI64Xor:
89 case kExprI64Shl:
90 case kExprI64ShrU:
91 case kExprI64ShrS:
92 case kExprI64Eq:
93 case kExprI64Ne:
94 case kExprI64LtS:
95 case kExprI64LeS:
96 case kExprI64LtU:
97 case kExprI64LeU:
98 case kExprI64GtS:
99 case kExprI64GeS:
100 case kExprI64GtU:
101 case kExprI64GeU:
102
103 case kExprI32ConvertI64:
104 case kExprI64SConvertI32:
105 case kExprI64UConvertI32:
106
107 case kExprF64ReinterpretI64:
108 case kExprI64ReinterpretF64:
109
110 case kExprI64Clz:
111 case kExprI64Ctz:
112 case kExprI64Popcnt:
113
114 case kExprF32SConvertI64:
115 case kExprF32UConvertI64:
116 case kExprF64SConvertI64:
117 case kExprF64UConvertI64:
118
119 #endif
120
121 case kExprI64SConvertF32:
122 case kExprI64SConvertF64:
123 case kExprI64UConvertF32:
124 case kExprI64UConvertF64:
125 return false;
126 default:
127 return true;
128 }
129 }
130 } // namespace wasm
131 } // namespace internal
132 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | src/wasm/wasm-result.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698