]> git.saurik.com Git - apple/javascriptcore.git/blob - offlineasm/instructions.rb
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / offlineasm / instructions.rb
1 # Copyright (C) 2011 Apple Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
5 # are met:
6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
13 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
14 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
16 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
22 # THE POSSIBILITY OF SUCH DAMAGE.
23
24 require "config"
25 require "set"
26
27 # Interesting invariant, which we take advantage of: branching instructions
28 # always begin with "b", and no non-branching instructions begin with "b".
29 # Terminal instructions are "jmp" and "ret".
30
31 MACRO_INSTRUCTIONS =
32 [
33 "emit",
34 "addi",
35 "andi",
36 "lshifti",
37 "lshiftp",
38 "lshiftq",
39 "muli",
40 "negi",
41 "negp",
42 "negq",
43 "noti",
44 "ori",
45 "rshifti",
46 "urshifti",
47 "rshiftp",
48 "urshiftp",
49 "rshiftq",
50 "urshiftq",
51 "subi",
52 "xori",
53 "loadi",
54 "loadis",
55 "loadb",
56 "loadbs",
57 "loadh",
58 "loadhs",
59 "storei",
60 "storeb",
61 "loadd",
62 "moved",
63 "stored",
64 "addd",
65 "divd",
66 "subd",
67 "muld",
68 "sqrtd",
69 "ci2d",
70 "fii2d", # usage: fii2d <gpr with least significant bits>, <gpr with most significant bits>, <fpr>
71 "fd2ii", # usage: fd2ii <fpr>, <gpr with least significant bits>, <gpr with most significant bits>
72 "fq2d",
73 "fd2q",
74 "bdeq",
75 "bdneq",
76 "bdgt",
77 "bdgteq",
78 "bdlt",
79 "bdlteq",
80 "bdequn",
81 "bdnequn",
82 "bdgtun",
83 "bdgtequn",
84 "bdltun",
85 "bdltequn",
86 "btd2i",
87 "td2i",
88 "bcd2i",
89 "movdz",
90 "pop",
91 "push",
92 "move",
93 "sxi2q",
94 "zxi2q",
95 "nop",
96 "bieq",
97 "bineq",
98 "bia",
99 "biaeq",
100 "bib",
101 "bibeq",
102 "bigt",
103 "bigteq",
104 "bilt",
105 "bilteq",
106 "bbeq",
107 "bbneq",
108 "bba",
109 "bbaeq",
110 "bbb",
111 "bbbeq",
112 "bbgt",
113 "bbgteq",
114 "bblt",
115 "bblteq",
116 "btis",
117 "btiz",
118 "btinz",
119 "btbs",
120 "btbz",
121 "btbnz",
122 "jmp",
123 "baddio",
124 "baddis",
125 "baddiz",
126 "baddinz",
127 "bsubio",
128 "bsubis",
129 "bsubiz",
130 "bsubinz",
131 "bmulio",
132 "bmulis",
133 "bmuliz",
134 "bmulinz",
135 "borio",
136 "boris",
137 "boriz",
138 "borinz",
139 "break",
140 "call",
141 "ret",
142 "cbeq",
143 "cbneq",
144 "cba",
145 "cbaeq",
146 "cbb",
147 "cbbeq",
148 "cbgt",
149 "cbgteq",
150 "cblt",
151 "cblteq",
152 "cieq",
153 "cineq",
154 "cia",
155 "ciaeq",
156 "cib",
157 "cibeq",
158 "cigt",
159 "cigteq",
160 "cilt",
161 "cilteq",
162 "tis",
163 "tiz",
164 "tinz",
165 "tbs",
166 "tbz",
167 "tbnz",
168 "tps",
169 "tpz",
170 "tpnz",
171 "peek",
172 "poke",
173 "bpeq",
174 "bpneq",
175 "bpa",
176 "bpaeq",
177 "bpb",
178 "bpbeq",
179 "bpgt",
180 "bpgteq",
181 "bplt",
182 "bplteq",
183 "addp",
184 "mulp",
185 "andp",
186 "orp",
187 "subp",
188 "xorp",
189 "loadp",
190 "cpeq",
191 "cpneq",
192 "cpa",
193 "cpaeq",
194 "cpb",
195 "cpbeq",
196 "cpgt",
197 "cpgteq",
198 "cplt",
199 "cplteq",
200 "storep",
201 "btps",
202 "btpz",
203 "btpnz",
204 "baddpo",
205 "baddps",
206 "baddpz",
207 "baddpnz",
208 "tqs",
209 "tqz",
210 "tqnz",
211 "bqeq",
212 "bqneq",
213 "bqa",
214 "bqaeq",
215 "bqb",
216 "bqbeq",
217 "bqgt",
218 "bqgteq",
219 "bqlt",
220 "bqlteq",
221 "addq",
222 "mulq",
223 "andq",
224 "orq",
225 "subq",
226 "xorq",
227 "loadq",
228 "cqeq",
229 "cqneq",
230 "cqa",
231 "cqaeq",
232 "cqb",
233 "cqbeq",
234 "cqgt",
235 "cqgteq",
236 "cqlt",
237 "cqlteq",
238 "storeq",
239 "btqs",
240 "btqz",
241 "btqnz",
242 "baddqo",
243 "baddqs",
244 "baddqz",
245 "baddqnz",
246 "bo",
247 "bs",
248 "bz",
249 "bnz",
250 "leai",
251 "leap",
252 "memfence"
253 ]
254
255 X86_INSTRUCTIONS =
256 [
257 "cdqi",
258 "idivi"
259 ]
260
261 ARM_INSTRUCTIONS =
262 [
263 "clrbp",
264 "mvlbl"
265 ]
266
267 ARM64_INSTRUCTIONS =
268 [
269 "pcrtoaddr", # Address from PC relative offset - adr instruction
270 "nopFixCortexA53Err835769" # nop on Cortex-A53 (nothing otherwise)
271 ]
272
273 RISC_INSTRUCTIONS =
274 [
275 "smulli", # Multiply two 32-bit words and produce a 64-bit word
276 "addis", # Add integers and set a flag.
277 "subis", # Same, but for subtraction.
278 "oris", # Same, but for bitwise or.
279 "addps" # addis but for pointers.
280 ]
281
282 MIPS_INSTRUCTIONS =
283 [
284 "la",
285 "movz",
286 "movn",
287 "slt",
288 "sltu",
289 "pichdr"
290 ]
291
292 SH4_INSTRUCTIONS =
293 [
294 "flushcp",
295 "alignformova",
296 "mova",
297 "shllx",
298 "shlrx",
299 "shld",
300 "shad",
301 "bdnan",
302 "loaddReversedAndIncrementAddress",
303 "storedReversedAndDecrementAddress",
304 "ldspr",
305 "stspr",
306 "setargs"
307 ]
308
309 CXX_INSTRUCTIONS =
310 [
311 "cloopCrash", # no operands
312 "cloopCallJSFunction", # operands: callee
313 "cloopCallNative", # operands: callee
314 "cloopCallSlowPath", # operands: callTarget, currentFrame, currentPC
315 "cloopCallSlowPathVoid", # operands: callTarget, currentFrame, currentPC
316
317 # For debugging only:
318 # Takes no operands but simply emits whatever follows in // comments as
319 # a line of C++ code in the generated LLIntAssembly.h file. This can be
320 # used to insert instrumentation into the interpreter loop to inspect
321 # variables of interest. Do not leave these instructions in production
322 # code.
323 "cloopDo", # no operands
324 ]
325
326 INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + ARM_INSTRUCTIONS + ARM64_INSTRUCTIONS + RISC_INSTRUCTIONS + MIPS_INSTRUCTIONS + SH4_INSTRUCTIONS + CXX_INSTRUCTIONS
327
328 INSTRUCTION_SET = INSTRUCTIONS.to_set
329
330 def isBranch(instruction)
331 instruction =~ /^b/
332 end
333
334 def hasFallThrough(instruction)
335 instruction != "ret" and instruction != "jmp"
336 end
337