blob: 9196e3cdb544f0a1a0e05ba6783800f5ca50ec09 [file] [log] [blame]
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +00001# 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
commit-queue@webkit.org782c20b2012-07-14 00:44:47 +000024require "config"
mhahnenberg@apple.com6bf37482014-02-04 02:08:23 +000025require "set"
commit-queue@webkit.org782c20b2012-07-14 00:44:47 +000026
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000027# 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
31MACRO_INSTRUCTIONS =
32 [
msaboff@apple.com2935ca82014-08-12 03:20:04 +000033 "emit",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000034 "addi",
35 "andi",
36 "lshifti",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000037 "lshiftp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000038 "lshiftq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000039 "muli",
40 "negi",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000041 "negp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000042 "negq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000043 "noti",
44 "ori",
45 "rshifti",
46 "urshifti",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000047 "rshiftp",
48 "urshiftp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000049 "rshiftq",
50 "urshiftq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000051 "subi",
52 "xori",
53 "loadi",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000054 "loadis",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000055 "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>
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000072 "fq2d",
73 "fd2q",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000074 "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",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000093 "sxi2q",
94 "zxi2q",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000095 "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",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000116 "btis",
117 "btiz",
118 "btinz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000119 "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",
fpizlo@apple.com1d216892012-04-12 00:55:44 +0000142 "cbeq",
143 "cbneq",
144 "cba",
145 "cbaeq",
146 "cbb",
147 "cbbeq",
148 "cbgt",
149 "cbgteq",
150 "cblt",
151 "cblteq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000152 "cieq",
153 "cineq",
154 "cia",
155 "ciaeq",
156 "cib",
157 "cibeq",
158 "cigt",
159 "cigteq",
160 "cilt",
161 "cilteq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000162 "tis",
163 "tiz",
164 "tinz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000165 "tbs",
166 "tbz",
167 "tbnz",
fpizlo@apple.com1d216892012-04-12 00:55:44 +0000168 "tps",
169 "tpz",
170 "tpnz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000171 "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",
fpizlo@apple.com685a4202012-03-11 00:33:20 +0000184 "mulp",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000185 "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",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000201 "btps",
202 "btpz",
203 "btpnz",
204 "baddpo",
205 "baddps",
206 "baddpz",
207 "baddpnz",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +0000208 "tqs",
209 "tqz",
210 "tqnz",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +0000211 "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",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000246 "bo",
247 "bs",
248 "bz",
249 "bnz",
250 "leai",
251 "leap",
fpizlo@apple.com33961712013-11-20 05:49:05 +0000252 "memfence"
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000253 ]
254
255X86_INSTRUCTIONS =
256 [
257 "cdqi",
allan.jensen@digia.comee0f0dc2013-08-15 11:28:55 +0000258 "idivi"
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000259 ]
260
msaboff@apple.com95894332014-01-29 19:18:54 +0000261ARM_INSTRUCTIONS =
262 [
ossy@webkit.org2f9d50a2014-04-20 13:58:25 +0000263 "clrbp",
264 "mvlbl"
msaboff@apple.com95894332014-01-29 19:18:54 +0000265 ]
266
msaboff@apple.com61758882013-11-22 01:11:54 +0000267ARM64_INSTRUCTIONS =
268 [
msaboff@apple.com2935ca82014-08-12 03:20:04 +0000269 "pcrtoaddr" # Address from PC relative offset - adr instruction
msaboff@apple.com61758882013-11-22 01:11:54 +0000270 ]
271
dbates@webkit.org98f0de02013-10-15 22:16:39 +0000272RISC_INSTRUCTIONS =
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000273 [
dbates@webkit.org98f0de02013-10-15 22:16:39 +0000274 "smulli", # Multiply two 32-bit words and produce a 64-bit word
275 "addis", # Add integers and set a flag.
276 "subis", # Same, but for subtraction.
277 "oris", # Same, but for bitwise or.
278 "addps" # addis but for pointers.
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000279 ]
280
commit-queue@webkit.org99609ea2013-01-07 19:40:10 +0000281MIPS_INSTRUCTIONS =
282 [
283 "movz",
284 "movn",
285 "slt",
286 "sltu",
287 "pichdr",
288 "pichdrra"
289 ]
290
commit-queue@webkit.org0486d5d2013-04-15 23:04:15 +0000291SH4_INSTRUCTIONS =
292 [
julien.brianceau@gmail.comb05cfba2014-04-11 15:55:29 +0000293 "flushcp",
294 "alignformova",
295 "mova",
commit-queue@webkit.org0486d5d2013-04-15 23:04:15 +0000296 "shllx",
297 "shlrx",
298 "shld",
299 "shad",
300 "bdnan",
301 "loaddReversedAndIncrementAddress",
302 "storedReversedAndDecrementAddress",
303 "ldspr",
commit-queue@webkit.orgea3fae72013-11-14 16:52:48 +0000304 "stspr",
305 "setargs"
commit-queue@webkit.org0486d5d2013-04-15 23:04:15 +0000306 ]
307
commit-queue@webkit.orge13567f2012-09-01 17:36:51 +0000308CXX_INSTRUCTIONS =
309 [
mhahnenberg@apple.com2e704ae2014-02-04 00:54:16 +0000310 "cloopCrash", # no operands
311 "cloopCallJSFunction", # operands: callee
312 "cloopCallNative", # operands: callee
313 "cloopCallSlowPath", # operands: callTarget, currentFrame, currentPC
314 "cloopCallSlowPathVoid", # operands: callTarget, currentFrame, currentPC
mark.lam@apple.com9cc5df72012-09-25 00:38:51 +0000315
316 # For debugging only:
317 # Takes no operands but simply emits whatever follows in // comments as
318 # a line of C++ code in the generated LLIntAssembly.h file. This can be
319 # used to insert instrumentation into the interpreter loop to inspect
320 # variables of interest. Do not leave these instructions in production
321 # code.
322 "cloopDo", # no operands
commit-queue@webkit.orge13567f2012-09-01 17:36:51 +0000323 ]
324
msaboff@apple.com95894332014-01-29 19:18:54 +0000325INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + ARM_INSTRUCTIONS + ARM64_INSTRUCTIONS + RISC_INSTRUCTIONS + MIPS_INSTRUCTIONS + SH4_INSTRUCTIONS + CXX_INSTRUCTIONS
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000326
mhahnenberg@apple.com6bf37482014-02-04 02:08:23 +0000327INSTRUCTION_SET = INSTRUCTIONS.to_set
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000328
329def isBranch(instruction)
330 instruction =~ /^b/
331end
332
333def hasFallThrough(instruction)
334 instruction != "ret" and instruction != "jmp"
335end
336