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

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

Issue 2644323002: [wasm] Use the official opcode names everywhere. (Closed)
Patch Set: [wasm] Use the official opcode names everywhere. Created 3 years, 11 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
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | src/wasm/wasm-text.cc » ('j') | 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/runtime/runtime.h" 7 #include "src/runtime/runtime.h"
8 #include "src/signature.h" 8 #include "src/signature.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace wasm { 12 namespace wasm {
13 13
14 typedef Signature<ValueType> FunctionSig; 14 typedef Signature<ValueType> FunctionSig;
15 15
16 #define CASE_OP(name, str) \
17 case kExpr##name: \
18 return str;
19 #define CASE_I32_OP(name, str) CASE_OP(I32##name, "i32." str)
20 #define CASE_I64_OP(name, str) CASE_OP(I64##name, "i64." str)
21 #define CASE_F32_OP(name, str) CASE_OP(F32##name, "f32." str)
22 #define CASE_F64_OP(name, str) CASE_OP(F64##name, "f64." str)
23 #define CASE_S128_OP(name, str) CASE_OP(S128##name, "s128." str)
24 #define CASE_F32x4_OP(name, str) CASE_OP(F32x4##name, "f32x4." str)
25 #define CASE_I32x4_OP(name, str) CASE_OP(I32x4##name, "i32x4." str)
26 #define CASE_I16x8_OP(name, str) CASE_OP(I16x8##name, "i16x8." str)
27 #define CASE_I8x16_OP(name, str) CASE_OP(I8x16##name, "i8x16." str)
28 #define CASE_S32x4_OP(name, str) CASE_OP(S32x4##name, "s32x4." str)
29 #define CASE_INT_OP(name, str) CASE_I32_OP(name, str) CASE_I64_OP(name, str)
30 #define CASE_FLOAT_OP(name, str) CASE_F32_OP(name, str) CASE_F64_OP(name, str)
31 #define CASE_ALL_OP(name, str) CASE_FLOAT_OP(name, str) CASE_INT_OP(name, str)
32 #define CASE_SIMD_OP(name, str) \
33 CASE_F32x4_OP(name, str) CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) \
34 CASE_I8x16_OP(name, str)
35 #define CASE_SIMDI_OP(name, str) \
36 CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) CASE_I8x16_OP(name, str)
37 #define CASE_SIGN_OP(TYPE, name, str) \
38 CASE_##TYPE##_OP(name##S, str "_s") CASE_##TYPE##_OP(name##U, str "_u")
39 #define CASE_ALL_SIGN_OP(name, str) \
40 CASE_FLOAT_OP(name, str) CASE_SIGN_OP(INT, name, str)
41 #define CASE_CONVERT_OP(name, RES, SRC, src_suffix, str) \
42 CASE_##RES##_OP(U##name##SRC, str "_u/" src_suffix) \
43 CASE_##RES##_OP(S##name##SRC, str "_s/" src_suffix)
44 #define CASE_L32_OP(name, str) \
45 CASE_SIGN_OP(I32, name##8, str "8") \
46 CASE_SIGN_OP(I32, name##16, str "16") \
47 CASE_I32_OP(name, str "32")
48
16 const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) { 49 const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
17 switch (opcode) { 50 switch (opcode) {
18 #define DECLARE_NAME_CASE(name, opcode, sig) \ 51 // clang-format off
19 case kExpr##name: \ 52
20 return "Expr" #name; 53 // Standard opcodes
21 FOREACH_OPCODE(DECLARE_NAME_CASE) 54 CASE_INT_OP(Eqz, "eqz")
22 #undef DECLARE_NAME_CASE 55 CASE_ALL_OP(Eq, "eq")
23 default: 56 CASE_ALL_OP(Ne, "ne")
24 break; 57 CASE_ALL_OP(Add, "add")
58 CASE_ALL_OP(Sub, "sub")
59 CASE_ALL_OP(Mul, "mul")
60 CASE_ALL_SIGN_OP(Lt, "lt")
61 CASE_ALL_SIGN_OP(Gt, "gt")
62 CASE_ALL_SIGN_OP(Le, "le")
63 CASE_ALL_SIGN_OP(Ge, "ge")
64 CASE_INT_OP(Clz, "clz")
65 CASE_INT_OP(Ctz, "ctz")
66 CASE_INT_OP(Popcnt, "popcnt")
67 CASE_ALL_SIGN_OP(Div, "div")
68 CASE_SIGN_OP(INT, Rem, "rem")
69 CASE_INT_OP(And, "and")
70 CASE_INT_OP(Ior, "or")
71 CASE_INT_OP(Xor, "xor")
72 CASE_INT_OP(Shl, "shl")
73 CASE_SIGN_OP(INT, Shr, "shr")
74 CASE_INT_OP(Rol, "rol")
75 CASE_INT_OP(Ror, "ror")
76 CASE_FLOAT_OP(Abs, "abs")
77 CASE_FLOAT_OP(Neg, "neg")
78 CASE_FLOAT_OP(Ceil, "ceil")
79 CASE_FLOAT_OP(Floor, "floor")
80 CASE_FLOAT_OP(Trunc, "trunc")
81 CASE_FLOAT_OP(NearestInt, "nearest")
82 CASE_FLOAT_OP(Sqrt, "sqrt")
83 CASE_FLOAT_OP(Min, "min")
84 CASE_FLOAT_OP(Max, "max")
85 CASE_FLOAT_OP(CopySign, "copysign")
86 CASE_I32_OP(ConvertI64, "wrap/i64")
87 CASE_CONVERT_OP(Convert, INT, F32, "f32", "trunc")
88 CASE_CONVERT_OP(Convert, INT, F64, "f64", "trunc")
89 CASE_CONVERT_OP(Convert, I64, I32, "i32", "extend")
90 CASE_CONVERT_OP(Convert, F32, I32, "i32", "convert")
91 CASE_CONVERT_OP(Convert, F32, I64, "i64", "convert")
92 CASE_F32_OP(ConvertF64, "demote/f64")
93 CASE_CONVERT_OP(Convert, F64, I32, "i32", "convert")
94 CASE_CONVERT_OP(Convert, F64, I64, "i64", "convert")
95 CASE_F64_OP(ConvertF32, "promote/f32")
96 CASE_I32_OP(ReinterpretF32, "reinterpret/f32")
97 CASE_I64_OP(ReinterpretF64, "reinterpret/f64")
98 CASE_F32_OP(ReinterpretI32, "reinterpret/i32")
99 CASE_F64_OP(ReinterpretI64, "reinterpret/i64")
100 CASE_OP(Unreachable, "unreachable")
101 CASE_OP(Nop, "nop")
102 CASE_OP(Block, "block")
103 CASE_OP(Loop, "loop")
104 CASE_OP(If, "if")
105 CASE_OP(Else, "else")
106 CASE_OP(End, "end")
107 CASE_OP(Br, "br")
108 CASE_OP(BrIf, "br_if")
109 CASE_OP(BrTable, "br_table")
110 CASE_OP(Return, "return")
111 CASE_OP(CallFunction, "call")
112 CASE_OP(CallIndirect, "call_indirect")
113 CASE_OP(Drop, "drop")
114 CASE_OP(Select, "select")
115 CASE_OP(GetLocal, "get_local")
116 CASE_OP(SetLocal, "set_local")
117 CASE_OP(TeeLocal, "tee_local")
118 CASE_OP(GetGlobal, "get_global")
119 CASE_OP(SetGlobal, "set_global")
120 CASE_ALL_OP(Const, "const")
121 CASE_OP(MemorySize, "current_memory")
122 CASE_OP(GrowMemory, "grow_memory")
123 CASE_ALL_OP(LoadMem, "load")
124 CASE_SIGN_OP(INT, LoadMem8, "load8")
125 CASE_SIGN_OP(INT, LoadMem16, "load16")
126 CASE_SIGN_OP(I64, LoadMem32, "load32")
127 CASE_ALL_OP(StoreMem, "store")
128 CASE_INT_OP(StoreMem8, "store8")
129 CASE_INT_OP(StoreMem16, "store16")
130 CASE_I64_OP(StoreMem32, "store32")
131
132 // Non-standard opcodes.
133 CASE_OP(Try, "try")
134 CASE_OP(Throw, "throw")
135 CASE_OP(Catch, "catch")
136
137 // asm.js-only opcodes.
138 CASE_F64_OP(Acos, "acos")
139 CASE_F64_OP(Asin, "asin")
140 CASE_F64_OP(Atan, "atan")
141 CASE_F64_OP(Cos, "cos")
142 CASE_F64_OP(Sin, "sin")
143 CASE_F64_OP(Tan, "tan")
144 CASE_F64_OP(Exp, "exp")
145 CASE_F64_OP(Log, "log")
146 CASE_F64_OP(Atan2, "atan2")
147 CASE_F64_OP(Pow, "pow")
148 CASE_F64_OP(Mod, "mod")
149 CASE_F32_OP(AsmjsLoadMem, "asmjs_load")
150 CASE_F64_OP(AsmjsLoadMem, "asmjs_load")
151 CASE_L32_OP(AsmjsLoadMem, "asmjs_load")
152 CASE_I32_OP(AsmjsStoreMem, "asmjs_store")
153 CASE_F32_OP(AsmjsStoreMem, "asmjs_store")
154 CASE_F64_OP(AsmjsStoreMem, "asmjs_store")
155 CASE_I32_OP(AsmjsStoreMem8, "asmjs_store8")
156 CASE_I32_OP(AsmjsStoreMem16, "asmjs_store16")
157 CASE_SIGN_OP(I32, AsmjsDiv, "asmjs_div")
158 CASE_SIGN_OP(I32, AsmjsRem, "asmjs_rem")
159 CASE_I32_OP(AsmjsSConvertF32, "asmjs_convert_s/f32")
160 CASE_I32_OP(AsmjsUConvertF32, "asmjs_convert_u/f32")
161 CASE_I32_OP(AsmjsSConvertF64, "asmjs_convert_s/f64")
162 CASE_I32_OP(AsmjsUConvertF64, "asmjs_convert_u/f64")
163
164 // SIMD opcodes.
165 CASE_SIMD_OP(Splat, "splat")
166 CASE_SIMD_OP(Neg, "neg")
167 CASE_SIMD_OP(Eq, "eq")
168 CASE_SIMD_OP(Ne, "ne")
169 CASE_SIMD_OP(Add, "add")
170 CASE_SIMD_OP(Sub, "sub")
171 CASE_SIMD_OP(Mul, "mul")
172 CASE_F32x4_OP(Abs, "abs")
173 CASE_F32x4_OP(Sqrt, "sqrt")
174 CASE_F32x4_OP(Div, "div")
175 CASE_F32x4_OP(RecipApprox, "recip_approx")
176 CASE_F32x4_OP(SqrtApprox, "sqrt_approx")
177 CASE_F32x4_OP(Min, "min")
178 CASE_F32x4_OP(Max, "max")
179 CASE_F32x4_OP(MinNum, "min_num")
180 CASE_F32x4_OP(MaxNum, "max_num")
181 CASE_F32x4_OP(Lt, "lt")
182 CASE_F32x4_OP(Le, "le")
183 CASE_F32x4_OP(Gt, "gt")
184 CASE_F32x4_OP(Ge, "ge")
185 CASE_CONVERT_OP(Convert, F32x4, I32x4, "i32", "convert")
186 CASE_F32x4_OP(ExtractLane, "extract_lane")
187 CASE_F32x4_OP(ReplaceLane, "replace_lane")
188 CASE_SIMDI_OP(ExtractLane, "extract_lane")
189 CASE_SIMDI_OP(ReplaceLane, "replace_lane")
190 CASE_SIGN_OP(SIMDI, Min, "min")
191 CASE_SIGN_OP(SIMDI, Max, "max")
192 CASE_SIGN_OP(SIMDI, Lt, "lt")
193 CASE_SIGN_OP(SIMDI, Le, "le")
194 CASE_SIGN_OP(SIMDI, Gt, "gt")
195 CASE_SIGN_OP(SIMDI, Ge, "ge")
196 CASE_SIGN_OP(SIMDI, Shr, "shr")
197 CASE_SIMDI_OP(Shl, "shl")
198 CASE_SIMDI_OP(Swizzle, "swizzle")
199 CASE_SIMDI_OP(Shuffle, "shuffle")
200 CASE_SIMDI_OP(Select, "select")
201 CASE_S128_OP(Ior, "or")
202 CASE_S128_OP(Xor, "xor")
203 CASE_S128_OP(And, "and")
204 CASE_S128_OP(Not, "not")
205 CASE_S32x4_OP(Select, "select")
206 CASE_S32x4_OP(Swizzle, "swizzle")
207 CASE_S32x4_OP(Shuffle, "shuffle")
208 CASE_CONVERT_OP(Convert, I32x4, F32x4, "f32", "convert")
209 CASE_SIGN_OP(I16x8, AddSaturate, "add_saturate")
210 CASE_SIGN_OP(I8x16, AddSaturate, "add_saturate")
211 CASE_SIGN_OP(I16x8, SubSaturate, "sub_saturate")
212 CASE_SIGN_OP(I8x16, SubSaturate, "sub_saturate")
213
214 // Atomic operations.
215 CASE_L32_OP(AtomicAdd, "atomic_add")
216 CASE_L32_OP(AtomicAnd, "atomic_and")
217 CASE_L32_OP(AtomicCompareExchange, "atomic_cmpxchng")
218 CASE_L32_OP(AtomicExchange, "atomic_xchng")
219 CASE_L32_OP(AtomicOr, "atomic_or")
220 CASE_L32_OP(AtomicSub, "atomic_sub")
221 CASE_L32_OP(AtomicXor, "atomic_xor")
222
223 default : return "unknown";
224 // clang-format on
25 } 225 }
26 return "Unknown";
27 } 226 }
28 227
29 const char* WasmOpcodes::ShortOpcodeName(WasmOpcode opcode) {
30 switch (opcode) {
31 #define DECLARE_NAME_CASE(name, opcode, sig) \
32 case kExpr##name: \
33 return #name;
34 FOREACH_OPCODE(DECLARE_NAME_CASE)
35 #undef DECLARE_NAME_CASE
36 default:
37 break;
38 }
39 return "Unknown";
40 }
41
42 bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) { 228 bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) {
43 switch (opcode) { 229 switch (opcode) {
44 #define CHECK_PREFIX(name, opcode) \ 230 #define CHECK_PREFIX(name, opcode) \
45 case k##name##Prefix: \ 231 case k##name##Prefix: \
46 return true; 232 return true;
47 FOREACH_PREFIX(CHECK_PREFIX) 233 FOREACH_PREFIX(CHECK_PREFIX)
48 #undef CHECK_PREFIX 234 #undef CHECK_PREFIX
49 default: 235 default:
50 return false; 236 return false;
51 } 237 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return MessageTemplate::kNone; 361 return MessageTemplate::kNone;
176 } 362 }
177 } 363 }
178 364
179 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { 365 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
180 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); 366 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
181 } 367 }
182 } // namespace wasm 368 } // namespace wasm
183 } // namespace internal 369 } // namespace internal
184 } // namespace v8 370 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | src/wasm/wasm-text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698