blob: 989ee82c2783ae61108c81d84defe1b7e615c03d [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"
25
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000026# 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",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000035 "lshiftp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000036 "lshiftq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000037 "muli",
38 "negi",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000039 "negp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000040 "negq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000041 "noti",
42 "ori",
43 "rshifti",
44 "urshifti",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000045 "rshiftp",
46 "urshiftp",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000047 "rshiftq",
48 "urshiftq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000049 "subi",
50 "xori",
51 "loadi",
fpizlo@apple.com685a4202012-03-11 00:33:20 +000052 "loadis",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000053 "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>
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000070 "fq2d",
71 "fd2q",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000072 "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",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +000091 "sxi2q",
92 "zxi2q",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000093 "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",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000114 "btis",
115 "btiz",
116 "btinz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000117 "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",
fpizlo@apple.com1d216892012-04-12 00:55:44 +0000140 "cbeq",
141 "cbneq",
142 "cba",
143 "cbaeq",
144 "cbb",
145 "cbbeq",
146 "cbgt",
147 "cbgteq",
148 "cblt",
149 "cblteq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000150 "cieq",
151 "cineq",
152 "cia",
153 "ciaeq",
154 "cib",
155 "cibeq",
156 "cigt",
157 "cigteq",
158 "cilt",
159 "cilteq",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000160 "tis",
161 "tiz",
162 "tinz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000163 "tbs",
164 "tbz",
165 "tbnz",
fpizlo@apple.com1d216892012-04-12 00:55:44 +0000166 "tps",
167 "tpz",
168 "tpnz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000169 "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",
fpizlo@apple.com685a4202012-03-11 00:33:20 +0000182 "mulp",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000183 "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",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000199 "btps",
200 "btpz",
201 "btpnz",
202 "baddpo",
203 "baddps",
204 "baddpz",
205 "baddpnz",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +0000206 "tqs",
207 "tqz",
208 "tqnz",
yuqiang.xian@intel.comf1431ade2012-10-25 05:24:39 +0000209 "bqeq",
210 "bqneq",
211 "bqa",
212 "bqaeq",
213 "bqb",
214 "bqbeq",
215 "bqgt",
216 "bqgteq",
217 "bqlt",
218 "bqlteq",
219 "addq",
220 "mulq",
221 "andq",
222 "orq",
223 "subq",
224 "xorq",
225 "loadq",
226 "cqeq",
227 "cqneq",
228 "cqa",
229 "cqaeq",
230 "cqb",
231 "cqbeq",
232 "cqgt",
233 "cqgteq",
234 "cqlt",
235 "cqlteq",
236 "storeq",
237 "btqs",
238 "btqz",
239 "btqnz",
240 "baddqo",
241 "baddqs",
242 "baddqz",
243 "baddqnz",
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000244 "bo",
245 "bs",
246 "bz",
247 "bnz",
248 "leai",
249 "leap",
msaboff@apple.com4655f792013-11-14 07:39:30 +0000250 "pushCalleeSaves",
fpizlo@apple.com33961712013-11-20 05:49:05 +0000251 "popCalleeSaves",
252 "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 [
263 "clrbp"
264 ]
265
msaboff@apple.com61758882013-11-22 01:11:54 +0000266ARM64_INSTRUCTIONS =
267 [
268 "popLRAndFP", # ARM64 requires registers to be pushed and popped in pairs,
269 "pushLRAndFP" # therefore we do LR (link register) and FP (frame pointer) together.
270 ]
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 [
293 "shllx",
294 "shlrx",
295 "shld",
296 "shad",
297 "bdnan",
298 "loaddReversedAndIncrementAddress",
299 "storedReversedAndDecrementAddress",
300 "ldspr",
commit-queue@webkit.orgea3fae72013-11-14 16:52:48 +0000301 "stspr",
302 "setargs"
commit-queue@webkit.org0486d5d2013-04-15 23:04:15 +0000303 ]
304
commit-queue@webkit.orge13567f2012-09-01 17:36:51 +0000305CXX_INSTRUCTIONS =
306 [
307 "cloopCrash", # no operands
308 "cloopCallJSFunction", # operands: callee
309 "cloopCallNative", # operands: callee
310 "cloopCallSlowPath", # operands: callTarget, currentFrame, currentPC
mark.lam@apple.com9cc5df72012-09-25 00:38:51 +0000311
312 # For debugging only:
313 # Takes no operands but simply emits whatever follows in // comments as
314 # a line of C++ code in the generated LLIntAssembly.h file. This can be
315 # used to insert instrumentation into the interpreter loop to inspect
316 # variables of interest. Do not leave these instructions in production
317 # code.
318 "cloopDo", # no operands
commit-queue@webkit.orge13567f2012-09-01 17:36:51 +0000319 ]
320
msaboff@apple.com95894332014-01-29 19:18:54 +0000321INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + ARM_INSTRUCTIONS + ARM64_INSTRUCTIONS + RISC_INSTRUCTIONS + MIPS_INSTRUCTIONS + SH4_INSTRUCTIONS + CXX_INSTRUCTIONS
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000322
323INSTRUCTION_PATTERN = Regexp.new('\\A((' + INSTRUCTIONS.join(')|(') + '))\\Z')
324
325def isBranch(instruction)
326 instruction =~ /^b/
327end
328
329def hasFallThrough(instruction)
330 instruction != "ret" and instruction != "jmp"
331end
332