1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=0 ft=c:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is SpiderMonkey nanojit.
19 * The Initial Developer of the Original Code is
20 * the Mozilla Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2008
22 * the Initial Developer. All Rights Reserved.
25 * Jeff Walden <jwalden+code@mit.edu>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 * This file is best viewed with 128 columns:
43 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
45 * Definitions of LIR opcodes. If you need to allocate an opcode, look
46 * for one defined using OP_UN() and claim it.
48 * Includers must define an OPxyz macro of the following form:
50 * #define OPxyz(op, number, repKind, retType) ...
52 * Selected arguments can then be used within the macro expansions.
53 * - op Opcode name, token-pasted after "LIR_" to form an LOpcode.
54 * - number Opcode number, used as the LOpcode enum value.
55 * - repKind Indicates how the instruction is represented in memory; XYZ
56 * corresponds to LInsXYZ and LRK_XYZ.
57 * - retType Type (LTy) of the value returned by the instruction.
58 * - isCse 0 if the opcode can never be CSE'd safely, 1 if it always
59 * can, -1 if things are more complicated -- in which case
60 * isCseOpcode() shouldn't be called on this opcode.
62 * Opcodes use type-indicators suffixes that are loosly based on C type names:
63 * - 'c': "char", ie. 8-bit integer
64 * - 's': "short", ie. 16-bit integer
65 * - 'i': "int", ie. 32-bit integer
66 * - 'q': "quad", ie. 64-bit integer
67 * - 'u': "unsigned", is used as a prefix on integer type-indicators when necessary
68 * - 'f': "float", ie. 32-bit floating point value
69 * - 'd': "double", ie. 64-bit floating point value
70 * - 'p': "pointer", ie. a int on 32-bit machines, a quad on 64-bit machines
72 * 'p' opcodes are all aliases of int and quad opcodes, they're given in LIR.h
73 * and chosen according to the platform pointer size.
75 * Certain opcodes aren't supported on all platforms, so OPxyz must be one of
78 * OP___: for opcodes supported on all platforms.
79 * OP_UN: for opcodes not yet used on any platform.
80 * OP_32: for opcodes supported only on 32-bit platforms.
81 * OP_64: for opcodes supported only on 64-bit platforms.
82 * OP_SF: for opcodes supported only on SoftFloat platforms.
83 * OP_86: for opcodes supported only on i386/X64.
86 #define OP_UN(n) OP___(__##n, n, None, V, -1)
89 # define OP_32(a, b, c, d, e) OP_UN(b)
93 # define OP_64(a, b, c, d, e) OP_UN(b)
96 #if NJ_SOFTFLOAT_SUPPORTED
99 # define OP_SF(a, b, c, d, e) OP_UN(b)
102 #if defined NANOJIT_IA32 || defined NANOJIT_X64
105 # define OP_86(a, b, c, d, e) OP_UN(b)
108 //---------------------------------------------------------------------------
109 // Miscellaneous operations
110 //---------------------------------------------------------------------------
111 OP___(start, 0, Op0, V, 0) // start of a fragment
113 // A register fence causes no code to be generated, but it affects register
114 // allocation so that no registers are live when it is reached.
115 OP___(regfence, 1, Op0, V, 0)
117 OP___(skip, 2, Sk, V, 0) // links code chunks
119 OP_32(parami, 3, P, I, 0) // load an int parameter (register or stack location)
120 OP_64(paramq, 4, P, Q, 0) // load a quad parameter (register or stack location)
122 OP___(allocp, 5, I, P, 0) // allocate stack space (result is an address)
124 OP___(reti, 6, Op1, V, 0) // return an int
125 OP_64(retq, 7, Op1, V, 0) // return a quad
126 OP___(retd, 8, Op1, V, 0) // return a double
128 OP___(livei, 9, Op1, V, 0) // extend live range of an int
129 OP_64(liveq, 10, Op1, V, 0) // extend live range of a quad
130 OP___(lived, 11, Op1, V, 0) // extend live range of a double
132 OP___(file, 12, Op1, V, 0) // source filename for debug symbols
133 OP___(line, 13, Op1, V, 0) // source line number for debug symbols
135 OP___(comment, 14, Op1, V, 0) // a comment shown, on its own line, in LIR dumps
139 //---------------------------------------------------------------------------
141 //---------------------------------------------------------------------------
142 OP___(ldc2i, 17, Ld, I, -1) // load char and sign-extend to an int
143 OP___(lds2i, 18, Ld, I, -1) // load short and sign-extend to an int
144 OP___(lduc2ui, 19, Ld, I, -1) // load unsigned char and zero-extend to an unsigned int
145 OP___(ldus2ui, 20, Ld, I, -1) // load unsigned short and zero-extend to an unsigned int
146 OP___(ldi, 21, Ld, I, -1) // load int
147 OP_64(ldq, 22, Ld, Q, -1) // load quad
148 OP___(ldd, 23, Ld, D, -1) // load double
149 OP___(ldf2d, 24, Ld, D, -1) // load float and extend to a double
151 OP___(sti2c, 25, St, V, 0) // store int truncated to char
152 OP___(sti2s, 26, St, V, 0) // store int truncated to short
153 OP___(sti, 27, St, V, 0) // store int
154 OP_64(stq, 28, St, V, 0) // store quad
155 OP___(std, 29, St, V, 0) // store double
156 OP___(std2f, 30, St, V, 0) // store double as a float (losing precision)
161 //---------------------------------------------------------------------------
163 //---------------------------------------------------------------------------
164 OP___(callv, 33, C, V, -1) // call subroutine that returns void
165 OP___(calli, 34, C, I, -1) // call subroutine that returns an int
166 OP_64(callq, 35, C, Q, -1) // call subroutine that returns a quad
167 OP___(calld, 36, C, D, -1) // call subroutine that returns a double
169 //---------------------------------------------------------------------------
170 // Branches and labels
171 //---------------------------------------------------------------------------
172 // 'jt' and 'jf' must be adjacent so that (op ^ 1) gives the opposite one.
173 // Static assertions in LIR.h check this requirement.
174 OP___(j, 37, Op2, V, 0) // jump always
175 OP___(jt, 38, Op2, V, 0) // jump if true
176 OP___(jf, 39, Op2, V, 0) // jump if false
177 OP___(jtbl, 40, Jtbl, V, 0) // jump to address in table
179 OP___(label, 41, Op0, V, 0) // a jump target (no machine code is emitted for this)
183 //---------------------------------------------------------------------------
185 //---------------------------------------------------------------------------
186 // 'xt' and 'xf' must be adjacent so that (op ^ 1) gives the opposite one.
187 // Static assertions in LIR.h check this requirement.
188 OP___(x, 43, Op2, V, 0) // exit always
189 OP___(xt, 44, Op2, V, 1) // exit if true
190 OP___(xf, 45, Op2, V, 1) // exit if false
191 OP___(xtbl, 46, Op2, V, 0) // exit via indirect jump
192 // A LIR_xbarrier cause no code to be generated, but it acts like a never-taken
193 // guard in that it inhibits certain optimisations, such as dead stack store
195 OP___(xbarrier, 47, Op2, V, 0)
199 //---------------------------------------------------------------------------
201 //---------------------------------------------------------------------------
202 OP___(immi, 49, I, I, 1) // int immediate
203 OP_64(immq, 50, QorD, Q, 1) // quad immediate
204 OP___(immd, 51, QorD, D, 1) // double immediate
208 //---------------------------------------------------------------------------
210 //---------------------------------------------------------------------------
212 // All comparisons return an int: 0 on failure and 1 on success.
214 // Within each type group, order must be preserved so that, except for eq*, (op
215 // ^ 1) gives the opposite one (eg. lt ^ 1 == gt). eq* must have odd numbers
216 // for this to work. They must also remain contiguous so that opcode range
217 // checking works correctly. Static assertions in LIR.h check these
219 OP___(eqi, 53, Op2, I, 1) // int equality
220 OP___(lti, 54, Op2, I, 1) // signed int less-than
221 OP___(gti, 55, Op2, I, 1) // signed int greater-than
222 OP___(lei, 56, Op2, I, 1) // signed int less-than-or-equal
223 OP___(gei, 57, Op2, I, 1) // signed int greater-than-or-equal
224 OP___(ltui, 58, Op2, I, 1) // unsigned int less-than
225 OP___(gtui, 59, Op2, I, 1) // unsigned int greater-than
226 OP___(leui, 60, Op2, I, 1) // unsigned int less-than-or-equal
227 OP___(geui, 61, Op2, I, 1) // unsigned int greater-than-or-equal
231 OP_64(eqq, 63, Op2, I, 1) // quad equality
232 OP_64(ltq, 64, Op2, I, 1) // signed quad less-than
233 OP_64(gtq, 65, Op2, I, 1) // signed quad greater-than
234 OP_64(leq, 66, Op2, I, 1) // signed quad less-than-or-equal
235 OP_64(geq, 67, Op2, I, 1) // signed quad greater-than-or-equal
236 OP_64(ltuq, 68, Op2, I, 1) // unsigned quad less-than
237 OP_64(gtuq, 69, Op2, I, 1) // unsigned quad greater-than
238 OP_64(leuq, 70, Op2, I, 1) // unsigned quad less-than-or-equal
239 OP_64(geuq, 71, Op2, I, 1) // unsigned quad greater-than-or-equal
243 OP___(eqd, 73, Op2, I, 1) // double equality
244 OP___(ltd, 74, Op2, I, 1) // double less-than
245 OP___(gtd, 75, Op2, I, 1) // double greater-than
246 OP___(led, 76, Op2, I, 1) // double less-than-or-equal
247 OP___(ged, 77, Op2, I, 1) // double greater-than-or-equal
249 //---------------------------------------------------------------------------
251 //---------------------------------------------------------------------------
252 OP___(negi, 78, Op1, I, 1) // negate int
253 OP___(addi, 79, Op2, I, 1) // add int
254 OP___(subi, 80, Op2, I, 1) // subtract int
255 OP___(muli, 81, Op2, I, 1) // multiply int
256 OP_86(divi, 82, Op2, I, 1) // divide int
257 // LIR_modi is a hack. It's only used on i386/X64. The operand is the result
258 // of a LIR_divi because on i386/X64 div and mod results are computed by the
260 OP_86(modi, 83, Op1, I, 1) // modulo int
262 OP___(noti, 84, Op1, I, 1) // bitwise-NOT int
263 OP___(andi, 85, Op2, I, 1) // bitwise-AND int
264 OP___(ori, 86, Op2, I, 1) // bitwise-OR int
265 OP___(xori, 87, Op2, I, 1) // bitwise-XOR int
267 // For all three integer shift operations, only the bottom five bits of the
268 // second operand are used, and they are treated as unsigned. This matches
270 OP___(lshi, 88, Op2, I, 1) // left shift int
271 OP___(rshi, 89, Op2, I, 1) // right shift int (>>)
272 OP___(rshui, 90, Op2, I, 1) // right shift unsigned int (>>>)
274 OP_64(addq, 91, Op2, Q, 1) // add quad
275 OP_64(subq, 92, Op2, Q, 1) // subtract quad
277 OP_64(andq, 93, Op2, Q, 1) // bitwise-AND quad
278 OP_64(orq, 94, Op2, Q, 1) // bitwise-OR quad
279 OP_64(xorq, 95, Op2, Q, 1) // bitwise-XOR quad
281 // For all three quad shift operations, only the bottom six bits of the
282 // second operand are used, and they are treated as unsigned. This matches
284 OP_64(lshq, 96, Op2, Q, 1) // left shift quad; 2nd operand is an int
285 OP_64(rshq, 97, Op2, Q, 1) // right shift quad; 2nd operand is an int
286 OP_64(rshuq, 98, Op2, Q, 1) // right shift unsigned quad; 2nd operand is an int
288 OP___(negd, 99, Op1, D, 1) // negate double
289 OP___(addd, 100, Op2, D, 1) // add double
290 OP___(subd, 101, Op2, D, 1) // subtract double
291 OP___(muld, 102, Op2, D, 1) // multiply double
292 OP___(divd, 103, Op2, D, 1) // divide double
293 // LIR_modd is just a place-holder opcode, ie. the back-ends cannot generate
294 // code for it. It's used in TraceMonkey briefly but is always demoted to a
295 // LIR_modl or converted to a function call before Nanojit has to do anything
297 OP___(modd, 104, Op2, D, 1) // modulo double
299 OP___(cmovi, 105, Op3, I, 1) // conditional move int
300 OP_64(cmovq, 106, Op3, Q, 1) // conditional move quad
301 OP___(cmovd, 107, Op3, D, 1) // conditional move double
303 //---------------------------------------------------------------------------
305 //---------------------------------------------------------------------------
306 OP_64(i2q, 108, Op1, Q, 1) // sign-extend int to quad
307 OP_64(ui2uq, 109, Op1, Q, 1) // zero-extend unsigned int to unsigned quad
308 OP_64(q2i, 110, Op1, I, 1) // truncate quad to int (removes the high 32 bits)
310 OP___(i2d, 111, Op1, D, 1) // convert int to double
311 OP___(ui2d, 112, Op1, D, 1) // convert unsigned int to double
312 OP___(d2i, 113, Op1, I, 1) // convert double to int (no exceptions raised, platform rounding rules)
314 OP_64(dasq, 114, Op1, Q, 1) // interpret the bits of a double as a quad
315 OP_64(qasd, 115, Op1, D, 1) // interpret the bits of a quad as a double
317 //---------------------------------------------------------------------------
318 // Overflow arithmetic
319 //---------------------------------------------------------------------------
320 // These all exit if overflow occurred. The result is valid on either path.
321 OP___(addxovi, 116, Op3, I, 1) // add int and exit on overflow
322 OP___(subxovi, 117, Op3, I, 1) // subtract int and exit on overflow
323 OP___(mulxovi, 118, Op3, I, 1) // multiply int and exit on overflow
325 // These all branch if overflow occurred. The result is valid on either path.
326 OP___(addjovi, 119, Op3, I, 1) // add int and branch on overflow
327 OP___(subjovi, 120, Op3, I, 1) // subtract int and branch on overflow
328 OP___(muljovi, 121, Op3, I, 1) // multiply int and branch on overflow
330 OP_64(addjovq, 122, Op3, Q, 1) // add quad and branch on overflow
331 OP_64(subjovq, 123, Op3, Q, 1) // subtract quad and branch on overflow
333 //---------------------------------------------------------------------------
335 //---------------------------------------------------------------------------
336 OP_SF(dlo2i, 124, Op1, I, 1) // get the low 32 bits of a double as an int
337 OP_SF(dhi2i, 125, Op1, I, 1) // get the high 32 bits of a double as an int
338 OP_SF(ii2d, 126, Op2, D, 1) // join two ints (1st arg is low bits, 2nd is high)
340 // LIR_hcalli is a hack that's only used on 32-bit platforms that use
341 // SoftFloat. Its operand is always a LIR_calli, but one that specifies a
342 // function that returns a double. It indicates that the double result is
343 // returned via two 32-bit integer registers. The result is always used as the
344 // second operand of a LIR_ii2d.
345 OP_SF(hcalli, 127, Op1, I, 1)