fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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 | |
commit-queue@webkit.org | 782c20b | 2012-07-14 00:44:47 +0000 | [diff] [blame] | 24 | require "config" |
| 25 | |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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 | |
| 30 | MACRO_INSTRUCTIONS = |
| 31 | [ |
| 32 | "addi", |
| 33 | "andi", |
| 34 | "lshifti", |
fpizlo@apple.com | 685a420 | 2012-03-11 00:33:20 +0000 | [diff] [blame] | 35 | "lshiftp", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 36 | "lshiftq", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 37 | "muli", |
| 38 | "negi", |
fpizlo@apple.com | 685a420 | 2012-03-11 00:33:20 +0000 | [diff] [blame] | 39 | "negp", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 40 | "negq", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 41 | "noti", |
| 42 | "ori", |
| 43 | "rshifti", |
| 44 | "urshifti", |
fpizlo@apple.com | 685a420 | 2012-03-11 00:33:20 +0000 | [diff] [blame] | 45 | "rshiftp", |
| 46 | "urshiftp", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 47 | "rshiftq", |
| 48 | "urshiftq", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 49 | "subi", |
| 50 | "xori", |
| 51 | "loadi", |
fpizlo@apple.com | 685a420 | 2012-03-11 00:33:20 +0000 | [diff] [blame] | 52 | "loadis", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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> |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 70 | "fq2d", |
| 71 | "fd2q", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 91 | "sxi2q", |
| 92 | "zxi2q", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 114 | "btis", |
| 115 | "btiz", |
| 116 | "btinz", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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", |
fpizlo@apple.com | 1d21689 | 2012-04-12 00:55:44 +0000 | [diff] [blame] | 140 | "cbeq", |
| 141 | "cbneq", |
| 142 | "cba", |
| 143 | "cbaeq", |
| 144 | "cbb", |
| 145 | "cbbeq", |
| 146 | "cbgt", |
| 147 | "cbgteq", |
| 148 | "cblt", |
| 149 | "cblteq", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 150 | "cieq", |
| 151 | "cineq", |
| 152 | "cia", |
| 153 | "ciaeq", |
| 154 | "cib", |
| 155 | "cibeq", |
| 156 | "cigt", |
| 157 | "cigteq", |
| 158 | "cilt", |
| 159 | "cilteq", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 160 | "tis", |
| 161 | "tiz", |
| 162 | "tinz", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 163 | "tbs", |
| 164 | "tbz", |
| 165 | "tbnz", |
fpizlo@apple.com | 1d21689 | 2012-04-12 00:55:44 +0000 | [diff] [blame] | 166 | "tps", |
| 167 | "tpz", |
| 168 | "tpnz", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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", |
fpizlo@apple.com | 685a420 | 2012-03-11 00:33:20 +0000 | [diff] [blame] | 182 | "mulp", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 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", |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 199 | "btps", |
| 200 | "btpz", |
| 201 | "btpnz", |
| 202 | "baddpo", |
| 203 | "baddps", |
| 204 | "baddpz", |
| 205 | "baddpnz", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 206 | "tqs", |
| 207 | "tqz", |
| 208 | "tqnz", |
yuqiang.xian@intel.com | f1431ade | 2012-10-25 05:24:39 +0000 | [diff] [blame] | 209 | "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.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 244 | "bo", |
| 245 | "bs", |
| 246 | "bz", |
| 247 | "bnz", |
| 248 | "leai", |
| 249 | "leap", |
msaboff@apple.com | 4655f79 | 2013-11-14 07:39:30 +0000 | [diff] [blame] | 250 | "pushCalleeSaves", |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 251 | "popCalleeSaves", |
| 252 | "memfence" |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 253 | ] |
| 254 | |
| 255 | X86_INSTRUCTIONS = |
| 256 | [ |
| 257 | "cdqi", |
allan.jensen@digia.com | ee0f0dc | 2013-08-15 11:28:55 +0000 | [diff] [blame] | 258 | "idivi" |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 259 | ] |
| 260 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 261 | ARM_INSTRUCTIONS = |
| 262 | [ |
| 263 | "clrbp" |
| 264 | ] |
| 265 | |
msaboff@apple.com | 6175888 | 2013-11-22 01:11:54 +0000 | [diff] [blame] | 266 | ARM64_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.org | 98f0de0 | 2013-10-15 22:16:39 +0000 | [diff] [blame] | 272 | RISC_INSTRUCTIONS = |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 273 | [ |
dbates@webkit.org | 98f0de0 | 2013-10-15 22:16:39 +0000 | [diff] [blame] | 274 | "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.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 279 | ] |
| 280 | |
commit-queue@webkit.org | 99609ea | 2013-01-07 19:40:10 +0000 | [diff] [blame] | 281 | MIPS_INSTRUCTIONS = |
| 282 | [ |
| 283 | "movz", |
| 284 | "movn", |
| 285 | "slt", |
| 286 | "sltu", |
| 287 | "pichdr", |
| 288 | "pichdrra" |
| 289 | ] |
| 290 | |
commit-queue@webkit.org | 0486d5d | 2013-04-15 23:04:15 +0000 | [diff] [blame] | 291 | SH4_INSTRUCTIONS = |
| 292 | [ |
| 293 | "shllx", |
| 294 | "shlrx", |
| 295 | "shld", |
| 296 | "shad", |
| 297 | "bdnan", |
| 298 | "loaddReversedAndIncrementAddress", |
| 299 | "storedReversedAndDecrementAddress", |
| 300 | "ldspr", |
commit-queue@webkit.org | ea3fae7 | 2013-11-14 16:52:48 +0000 | [diff] [blame] | 301 | "stspr", |
| 302 | "setargs" |
commit-queue@webkit.org | 0486d5d | 2013-04-15 23:04:15 +0000 | [diff] [blame] | 303 | ] |
| 304 | |
commit-queue@webkit.org | e13567f | 2012-09-01 17:36:51 +0000 | [diff] [blame] | 305 | CXX_INSTRUCTIONS = |
| 306 | [ |
| 307 | "cloopCrash", # no operands |
| 308 | "cloopCallJSFunction", # operands: callee |
| 309 | "cloopCallNative", # operands: callee |
| 310 | "cloopCallSlowPath", # operands: callTarget, currentFrame, currentPC |
mark.lam@apple.com | 9cc5df7 | 2012-09-25 00:38:51 +0000 | [diff] [blame] | 311 | |
| 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.org | e13567f | 2012-09-01 17:36:51 +0000 | [diff] [blame] | 319 | ] |
| 320 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 321 | INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + ARM_INSTRUCTIONS + ARM64_INSTRUCTIONS + RISC_INSTRUCTIONS + MIPS_INSTRUCTIONS + SH4_INSTRUCTIONS + CXX_INSTRUCTIONS |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 322 | |
| 323 | INSTRUCTION_PATTERN = Regexp.new('\\A((' + INSTRUCTIONS.join(')|(') + '))\\Z') |
| 324 | |
| 325 | def isBranch(instruction) |
| 326 | instruction =~ /^b/ |
| 327 | end |
| 328 | |
| 329 | def hasFallThrough(instruction) |
| 330 | instruction != "ret" and instruction != "jmp" |
| 331 | end |
| 332 | |