1/*
2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "B3Opcode.h"
28
29#if ENABLE(B3_JIT)
30
31#include <wtf/PrintStream.h>
32
33#if ASSERT_DISABLED
34IGNORE_RETURN_TYPE_WARNINGS_BEGIN
35#endif
36
37namespace JSC { namespace B3 {
38
39Optional<Opcode> invertedCompare(Opcode opcode, Type type)
40{
41 switch (opcode) {
42 case Equal:
43 return NotEqual;
44 case NotEqual:
45 return Equal;
46 case LessThan:
47 if (type.isInt())
48 return GreaterEqual;
49 return WTF::nullopt;
50 case GreaterThan:
51 if (type.isInt())
52 return LessEqual;
53 return WTF::nullopt;
54 case LessEqual:
55 if (type.isInt())
56 return GreaterThan;
57 return WTF::nullopt;
58 case GreaterEqual:
59 if (type.isInt())
60 return LessThan;
61 return WTF::nullopt;
62 case Above:
63 return BelowEqual;
64 case Below:
65 return AboveEqual;
66 case AboveEqual:
67 return Below;
68 case BelowEqual:
69 return Above;
70 default:
71 return WTF::nullopt;
72 }
73}
74
75Opcode storeOpcode(Bank bank, Width width)
76{
77 switch (bank) {
78 case GP:
79 switch (width) {
80 case Width8:
81 return Store8;
82 case Width16:
83 return Store16;
84 default:
85 return Store;
86 }
87 case FP:
88 return Store;
89 }
90 ASSERT_NOT_REACHED();
91}
92
93} } // namespace JSC::B3
94
95namespace WTF {
96
97using namespace JSC::B3;
98
99void printInternal(PrintStream& out, Opcode opcode)
100{
101 switch (opcode) {
102 case Nop:
103 out.print("Nop");
104 return;
105 case Identity:
106 out.print("Identity");
107 return;
108 case Opaque:
109 out.print("Opaque");
110 return;
111 case Const32:
112 out.print("Const32");
113 return;
114 case Const64:
115 out.print("Const64");
116 return;
117 case ConstDouble:
118 out.print("ConstDouble");
119 return;
120 case ConstFloat:
121 out.print("ConstFloat");
122 return;
123 case Get:
124 out.print("Get");
125 return;
126 case Set:
127 out.print("Set");
128 return;
129 case SlotBase:
130 out.print("SlotBase");
131 return;
132 case ArgumentReg:
133 out.print("ArgumentReg");
134 return;
135 case FramePointer:
136 out.print("FramePointer");
137 return;
138 case Add:
139 out.print("Add");
140 return;
141 case Sub:
142 out.print("Sub");
143 return;
144 case Mul:
145 out.print("Mul");
146 return;
147 case Div:
148 out.print("Div");
149 return;
150 case UDiv:
151 out.print("UDiv");
152 return;
153 case Mod:
154 out.print("Mod");
155 return;
156 case UMod:
157 out.print("UMod");
158 return;
159 case Neg:
160 out.print("Neg");
161 return;
162 case BitAnd:
163 out.print("BitAnd");
164 return;
165 case BitOr:
166 out.print("BitOr");
167 return;
168 case BitXor:
169 out.print("BitXor");
170 return;
171 case Shl:
172 out.print("Shl");
173 return;
174 case SShr:
175 out.print("SShr");
176 return;
177 case ZShr:
178 out.print("ZShr");
179 return;
180 case RotR:
181 out.print("RotR");
182 return;
183 case RotL:
184 out.print("RotL");
185 return;
186 case Clz:
187 out.print("Clz");
188 return;
189 case Abs:
190 out.print("Abs");
191 return;
192 case Ceil:
193 out.print("Ceil");
194 return;
195 case Floor:
196 out.print("Floor");
197 return;
198 case Sqrt:
199 out.print("Sqrt");
200 return;
201 case BitwiseCast:
202 out.print("BitwiseCast");
203 return;
204 case SExt8:
205 out.print("SExt8");
206 return;
207 case SExt16:
208 out.print("SExt16");
209 return;
210 case SExt32:
211 out.print("SExt32");
212 return;
213 case ZExt32:
214 out.print("ZExt32");
215 return;
216 case Trunc:
217 out.print("Trunc");
218 return;
219 case IToD:
220 out.print("IToD");
221 return;
222 case IToF:
223 out.print("IToF");
224 return;
225 case FloatToDouble:
226 out.print("FloatToDouble");
227 return;
228 case DoubleToFloat:
229 out.print("DoubleToFloat");
230 return;
231 case Equal:
232 out.print("Equal");
233 return;
234 case NotEqual:
235 out.print("NotEqual");
236 return;
237 case LessThan:
238 out.print("LessThan");
239 return;
240 case GreaterThan:
241 out.print("GreaterThan");
242 return;
243 case LessEqual:
244 out.print("LessEqual");
245 return;
246 case GreaterEqual:
247 out.print("GreaterEqual");
248 return;
249 case Above:
250 out.print("Above");
251 return;
252 case Below:
253 out.print("Below");
254 return;
255 case AboveEqual:
256 out.print("AboveEqual");
257 return;
258 case BelowEqual:
259 out.print("BelowEqual");
260 return;
261 case EqualOrUnordered:
262 out.print("EqualOrUnordered");
263 return;
264 case Select:
265 out.print("Select");
266 return;
267 case Load8Z:
268 out.print("Load8Z");
269 return;
270 case Load8S:
271 out.print("Load8S");
272 return;
273 case Load16Z:
274 out.print("Load16Z");
275 return;
276 case Load16S:
277 out.print("Load16S");
278 return;
279 case Load:
280 out.print("Load");
281 return;
282 case Store8:
283 out.print("Store8");
284 return;
285 case Store16:
286 out.print("Store16");
287 return;
288 case Store:
289 out.print("Store");
290 return;
291 case AtomicWeakCAS:
292 out.print("AtomicWeakCAS");
293 return;
294 case AtomicStrongCAS:
295 out.print("AtomicStrongCAS");
296 return;
297 case AtomicXchgAdd:
298 out.print("AtomicXchgAdd");
299 return;
300 case AtomicXchgAnd:
301 out.print("AtomicXchgAnd");
302 return;
303 case AtomicXchgOr:
304 out.print("AtomicXchgOr");
305 return;
306 case AtomicXchgSub:
307 out.print("AtomicXchgSub");
308 return;
309 case AtomicXchgXor:
310 out.print("AtomicXchgXor");
311 return;
312 case AtomicXchg:
313 out.print("AtomicXchg");
314 return;
315 case Depend:
316 out.print("Depend");
317 return;
318 case WasmAddress:
319 out.print("WasmAddress");
320 return;
321 case Fence:
322 out.print("Fence");
323 return;
324 case CCall:
325 out.print("CCall");
326 return;
327 case Patchpoint:
328 out.print("Patchpoint");
329 return;
330 case Extract:
331 out.print("Extract");
332 return;
333 case CheckAdd:
334 out.print("CheckAdd");
335 return;
336 case CheckSub:
337 out.print("CheckSub");
338 return;
339 case CheckMul:
340 out.print("CheckMul");
341 return;
342 case Check:
343 out.print("Check");
344 return;
345 case WasmBoundsCheck:
346 out.print("WasmBoundsCheck");
347 return;
348 case Upsilon:
349 out.print("Upsilon");
350 return;
351 case Phi:
352 out.print("Phi");
353 return;
354 case Jump:
355 out.print("Jump");
356 return;
357 case Branch:
358 out.print("Branch");
359 return;
360 case Switch:
361 out.print("Switch");
362 return;
363 case EntrySwitch:
364 out.print("EntrySwitch");
365 return;
366 case Return:
367 out.print("Return");
368 return;
369 case Oops:
370 out.print("Oops");
371 return;
372 }
373 RELEASE_ASSERT_NOT_REACHED();
374}
375
376} // namespace WTF
377
378#if ASSERT_DISABLED
379IGNORE_RETURN_TYPE_WARNINGS_END
380#endif
381
382#endif // ENABLE(B3_JIT)
383