]> git.saurik.com Git - apple/javascriptcore.git/blame - offlineasm/instructions.rb
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / offlineasm / instructions.rb
CommitLineData
6fe7ccc8
A
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
93a37866
A
24require "config"
25
6fe7ccc8
A
26# Interesting invariant, which we take advantage of: branching instructions
27# always begin with "b", and no non-branching instructions begin with "b".
28# Terminal instructions are "jmp" and "ret".
29
30MACRO_INSTRUCTIONS =
31 [
32 "addi",
33 "andi",
34 "lshifti",
35 "lshiftp",
93a37866 36 "lshiftq",
6fe7ccc8
A
37 "muli",
38 "negi",
39 "negp",
93a37866 40 "negq",
6fe7ccc8
A
41 "noti",
42 "ori",
43 "rshifti",
44 "urshifti",
45 "rshiftp",
46 "urshiftp",
93a37866
A
47 "rshiftq",
48 "urshiftq",
6fe7ccc8
A
49 "subi",
50 "xori",
51 "loadi",
52 "loadis",
53 "loadb",
54 "loadbs",
55 "loadh",
56 "loadhs",
57 "storei",
58 "storeb",
59 "loadd",
60 "moved",
61 "stored",
62 "addd",
63 "divd",
64 "subd",
65 "muld",
66 "sqrtd",
67 "ci2d",
68 "fii2d", # usage: fii2d <gpr with least significant bits>, <gpr with most significant bits>, <fpr>
69 "fd2ii", # usage: fd2ii <fpr>, <gpr with least significant bits>, <gpr with most significant bits>
93a37866
A
70 "fq2d",
71 "fd2q",
6fe7ccc8
A
72 "bdeq",
73 "bdneq",
74 "bdgt",
75 "bdgteq",
76 "bdlt",
77 "bdlteq",
78 "bdequn",
79 "bdnequn",
80 "bdgtun",
81 "bdgtequn",
82 "bdltun",
83 "bdltequn",
84 "btd2i",
85 "td2i",
86 "bcd2i",
87 "movdz",
88 "pop",
89 "push",
90 "move",
93a37866
A
91 "sxi2q",
92 "zxi2q",
6fe7ccc8
A
93 "nop",
94 "bieq",
95 "bineq",
96 "bia",
97 "biaeq",
98 "bib",
99 "bibeq",
100 "bigt",
101 "bigteq",
102 "bilt",
103 "bilteq",
104 "bbeq",
105 "bbneq",
106 "bba",
107 "bbaeq",
108 "bbb",
109 "bbbeq",
110 "bbgt",
111 "bbgteq",
112 "bblt",
113 "bblteq",
6fe7ccc8
A
114 "btis",
115 "btiz",
116 "btinz",
6fe7ccc8
A
117 "btbs",
118 "btbz",
119 "btbnz",
120 "jmp",
121 "baddio",
122 "baddis",
123 "baddiz",
124 "baddinz",
125 "bsubio",
126 "bsubis",
127 "bsubiz",
128 "bsubinz",
129 "bmulio",
130 "bmulis",
131 "bmuliz",
132 "bmulinz",
133 "borio",
134 "boris",
135 "boriz",
136 "borinz",
137 "break",
138 "call",
139 "ret",
140 "cbeq",
141 "cbneq",
142 "cba",
143 "cbaeq",
144 "cbb",
145 "cbbeq",
146 "cbgt",
147 "cbgteq",
148 "cblt",
149 "cblteq",
150 "cieq",
151 "cineq",
152 "cia",
153 "ciaeq",
154 "cib",
155 "cibeq",
156 "cigt",
157 "cigteq",
158 "cilt",
159 "cilteq",
6fe7ccc8
A
160 "tis",
161 "tiz",
162 "tinz",
6fe7ccc8
A
163 "tbs",
164 "tbz",
165 "tbnz",
6fe7ccc8
A
166 "tps",
167 "tpz",
168 "tpnz",
169 "peek",
170 "poke",
171 "bpeq",
172 "bpneq",
173 "bpa",
174 "bpaeq",
175 "bpb",
176 "bpbeq",
177 "bpgt",
178 "bpgteq",
179 "bplt",
180 "bplteq",
181 "addp",
182 "mulp",
183 "andp",
184 "orp",
185 "subp",
186 "xorp",
187 "loadp",
188 "cpeq",
189 "cpneq",
190 "cpa",
191 "cpaeq",
192 "cpb",
193 "cpbeq",
194 "cpgt",
195 "cpgteq",
196 "cplt",
197 "cplteq",
198 "storep",
6fe7ccc8
A
199 "btps",
200 "btpz",
201 "btpnz",
202 "baddpo",
203 "baddps",
204 "baddpz",
205 "baddpnz",
93a37866
A
206 "tqs",
207 "tqz",
208 "tqnz",
209 "peekq",
210 "pokeq",
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",
6fe7ccc8
A
246 "bo",
247 "bs",
248 "bz",
249 "bnz",
250 "leai",
251 "leap",
252 ]
253
254X86_INSTRUCTIONS =
255 [
256 "cdqi",
93a37866
A
257 "idivi",
258 "resetX87Stack"
259 ]
260
261RISC_INSTRUCTIONS =
262 [
263 "smulli", # Multiply two 32-bit words and produce a 64-bit word
264 "addis", # Add integers and set a flag.
265 "subis", # Same, but for subtraction.
266 "oris", # Same, but for bitwise or.
267 "addps" # addis but for pointers.
6fe7ccc8
A
268 ]
269
93a37866 270MIPS_INSTRUCTIONS =
6fe7ccc8 271 [
93a37866
A
272 "movz",
273 "movn",
274 "slt",
275 "sltu",
276 "pichdr",
277 "pichdrra"
278 ]
279
280SH4_INSTRUCTIONS =
281 [
282 "shllx",
283 "shlrx",
284 "shld",
285 "shad",
286 "bdnan",
287 "loaddReversedAndIncrementAddress",
288 "storedReversedAndDecrementAddress",
289 "ldspr",
290 "stspr",
291 "callf",
292 "jmpf"
293 ]
294
295CXX_INSTRUCTIONS =
296 [
297 "cloopCrash", # no operands
298 "cloopCallJSFunction", # operands: callee
299 "cloopCallNative", # operands: callee
300 "cloopCallSlowPath", # operands: callTarget, currentFrame, currentPC
301
302 # For debugging only:
303 # Takes no operands but simply emits whatever follows in // comments as
304 # a line of C++ code in the generated LLIntAssembly.h file. This can be
305 # used to insert instrumentation into the interpreter loop to inspect
306 # variables of interest. Do not leave these instructions in production
307 # code.
308 "cloopDo", # no operands
6fe7ccc8
A
309 ]
310
93a37866 311INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + RISC_INSTRUCTIONS + MIPS_INSTRUCTIONS + SH4_INSTRUCTIONS + CXX_INSTRUCTIONS
6fe7ccc8
A
312
313INSTRUCTION_PATTERN = Regexp.new('\\A((' + INSTRUCTIONS.join(')|(') + '))\\Z')
314
315def isBranch(instruction)
316 instruction =~ /^b/
317end
318
319def hasFallThrough(instruction)
320 instruction != "ret" and instruction != "jmp"
321end
322