3 # This is the specification for the ia32 assembler Firm-operations
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
9 # The node description is done as a perl hash initializer with the
10 # following structure:
15 # "op_flags" => "N|L|C|X|I|F|Y|H|c|K",
16 # "irn_flags" => "R|N|I"
17 # "arity" => "0|1|2|3 ... |variable|dynamic|any",
18 # "state" => "floats|pinned|mem_pinned|exc_pinned",
20 # { "type" => "type 1", "name" => "name 1" },
21 # { "type" => "type 2", "name" => "name 2" },
24 # "comment" => "any comment for constructor",
25 # "reg_req" => { "in" => [ "reg_class|register" ], "out" => [ "reg_class|register|in_rX" ] },
26 # "cmp_attr" => "c source code for comparing node attributes",
27 # "emit" => "emit code with templates",
28 # "rd_constructor" => "c source code which constructs an ir_node"
31 # ... # (all nodes you need to describe)
33 # ); # close the %nodes initializer
35 # op_flags: flags for the operation, OPTIONAL (default is "N")
36 # the op_flags correspond to the firm irop_flags:
39 # C irop_flag_commutative
40 # X irop_flag_cfopcode
41 # I irop_flag_ip_cfopcode
44 # H irop_flag_highlevel
45 # c irop_flag_constlike
48 # irn_flags: special node flags, OPTIONAL (default is 0)
49 # following irn_flags are supported:
52 # I ignore for register allocation
54 # state: state of the operation, OPTIONAL (default is "floats")
56 # arity: arity of the operation, MUST NOT BE OMITTED
58 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
59 # are always the first 3 arguments and are always autmatically
61 # If this key is missing the following arguments will be created:
62 # for i = 1 .. arity: ir_node *op_i
65 # comment: OPTIONAL comment for the node constructor
67 # rd_constructor: for every operation there will be a
68 # new_rd_<arch>_<op-name> function with the arguments from above
69 # which creates the ir_node corresponding to the defined operation
70 # you can either put the complete source code of this function here
72 # This key is OPTIONAL. If omitted, the following constructor will
74 # if (!op_<arch>_<op-name>) assert(0);
78 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
81 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
85 # 1 - caller save (register must be saved by the caller of a function)
86 # 2 - callee save (register must be saved by the called function)
87 # 4 - ignore (do not assign this register)
88 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
91 { "name" => "eax", "type" => 1 },
92 { "name" => "edx", "type" => 1 },
93 { "name" => "ebx", "type" => 2 },
94 { "name" => "ecx", "type" => 1 },
95 { "name" => "esi", "type" => 2 },
96 { "name" => "edi", "type" => 2 },
97 { "name" => "ebp", "type" => 2 },
98 { "name" => "esp", "type" => 4 },
99 { "name" => "xxx", "type" => 6 }, # we need a dummy register for NoReg and Unknown nodes
100 { "mode" => "mode_P" }
103 { "name" => "xmm0", "type" => 1 },
104 { "name" => "xmm1", "type" => 1 },
105 { "name" => "xmm2", "type" => 1 },
106 { "name" => "xmm3", "type" => 1 },
107 { "name" => "xmm4", "type" => 1 },
108 { "name" => "xmm5", "type" => 1 },
109 { "name" => "xmm6", "type" => 1 },
110 { "name" => "xmm7", "type" => 1 },
111 { "name" => "xxxx", "type" => 6 }, # we need a dummy register for NoReg and Unknown nodes
112 { "mode" => "mode_D" }
116 #--------------------------------------------------#
119 # _ __ _____ __ _ _ __ ___ _ __ ___ #
120 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
121 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
122 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
125 #--------------------------------------------------#
129 #-----------------------------------------------------------------#
132 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
133 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
134 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
135 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
138 #-----------------------------------------------------------------#
140 # commutative operations
143 # All nodes supporting Addressmode have 5 INs:
144 # 1 - base r1 == NoReg in case of no AM or no base
145 # 2 - index r2 == NoReg in case of no AM or no index
146 # 3 - op1 r3 == always present
147 # 4 - op2 r4 == NoReg in case of immediate operation
148 # 5 - mem NoMem in case of no AM otherwise it takes the mem from the Load
152 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
153 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
154 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
155 "emit" => '. add %ia32_emit_binop\t\t\t/* Add(%A1, %A2) -> %D1 */'
160 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
161 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
162 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
163 "emit" => '. imul %ia32_emit_binop\t\t\t/* Mul(%A1, %A2) -> %D1 */'
166 # Mulh is an exception from the 4 INs with AM because the target is always EAX:EDX
168 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
169 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
170 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "eax in_r3", "edx in_r4" ] },
171 "emit" => '. imul %ia32_emit_unop\t\t\t/* Mulh(%A1, %A2) -> %D1 */ '
176 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
177 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
178 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
179 "emit" => '. and %ia32_emit_binop\t\t\t/* And(%A1, %A2) -> %D1 */'
184 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
185 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
186 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
187 "emit" => '. or %ia32_emit_binop\t\t\t/* Or(%A1, %A2) -> %D1 */'
192 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
193 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
194 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
195 "emit" => '. xor %ia32_emit_binop\t\t\t/* Xor(%A1, %A2) -> %D1 */'
200 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
201 "reg_req" => { "in" => [ "gp", "gp" ], "out" => [ "in_r1" ] },
203 '2. cmp %S1, %S2\t\t\t/* prepare Max (%S1 - %S2), (%A1, %A2) */
204 if (mode_is_signed(get_irn_mode(n))) {
205 4. cmovl %D1, %S2\t\t\t/* %S1 is less %S2 */
208 4. cmovb %D1, %S2\t\t\t/* %S1 is below %S2 */
215 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
216 "reg_req" => { "in" => [ "gp", "gp" ], "out" => [ "in_r1" ] },
218 '2. cmp %S1, %S2\t\t\t/* prepare Min (%S1 - %S2), (%A1, %A2) */
219 if (mode_is_signed(get_irn_mode(n))) {
220 2. cmovg %D1, %S2\t\t\t/* %S1 is greater %S2 */
223 2. cmova %D1, %S2, %D1\t\t\t/* %S1 is above %S2 */
230 "comment" => "construct Mux: Mux(sel, a, b) == sel ? a : b",
231 "reg_req" => { "in" => [ "gp", "gp", "gp" ], "out" => [ "in_r2 !in_r3" ] },
233 '. cmp %S1, 0\t\t\t/* compare Sel for CMov (%A2, %A3) */
234 . cmovne %D1, %S3\t\t\t/* sel == true -> return %S3 */
238 # not commutative operations
242 "comment" => "construct Sub: Sub(a, b) = a - b",
243 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
244 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "in_r3 !in_r4" ] },
245 "emit" => '. sub %ia32_emit_binop\t\t\t/* Sub(%A1, %A2) -> %D1 */'
250 "state" => "exc_pinned",
251 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
253 ' if (mode_is_signed(get_irn_mode(n))) {
254 4. idiv %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
257 4. div %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
264 "comment" => "construct Shl: Shl(a, b) = a << b",
265 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
266 "reg_req" => { "in" => [ "gp", "gp", "gp", "ecx", "none" ], "out" => [ "in_r3 !in_r4" ] },
267 "emit" => '. shl %ia32_emit_binop\t\t\t/* Shl(%A1, %A2) -> %D1 */'
272 "comment" => "construct Shr: Shr(a, b) = a >> b",
273 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
274 "reg_req" => { "in" => [ "gp", "gp", "gp", "ecx", "none" ], "out" => [ "in_r3 !in_r4" ] },
275 "emit" => '. shr %ia32_emit_binop\t\t\t/* Shr(%A1, %A2) -> %D1 */'
280 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
281 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
282 "reg_req" => { "in" => [ "gp", "gp", "gp", "ecx", "none" ], "out" => [ "in_r3 !in_r4" ] },
283 "emit" => '. sar %ia32_emit_binop\t\t\t/* Shrs(%A1, %A2) -> %D1 */'
288 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
289 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
290 "reg_req" => { "in" => [ "gp", "gp", "gp", "ecx", "none" ], "out" => [ "in_r3 !in_r4" ] },
291 "emit" => '. ror %ia32_emit_binop\t\t\t/* RotR(%A1, %A2) -> %D1 */'
296 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
297 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
298 "reg_req" => { "in" => [ "gp", "gp", "gp", "ecx", "none" ], "out" => [ "in_r3 !in_r4" ] },
299 "emit" => '. rol %ia32_emit_binop\t\t\t/* RotL(%A1, %A2) -> %D1 */'
306 "comment" => "construct Minus: Minus(a) = -a",
307 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
308 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "in_r3" ] },
309 "emit" => '. neg %ia32_emit_unop\t\t\t/* Neg(%A1) -> %D1, (%A1) */'
314 "comment" => "construct Increment: Inc(a) = a++",
315 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
316 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "in_r3" ] },
317 "emit" => '. inc %ia32_emit_unop\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
322 "comment" => "construct Decrement: Dec(a) = a--",
323 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
324 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "in_r3" ] },
325 "emit" => '. dec %ia32_emit_unop\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
330 "comment" => "construct Not: Not(a) = !a",
331 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
332 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "in_r3" ] },
333 "emit" => '. not %ia32_emit_unop\t\t\t/* Not(%S1) -> %D1, (%A1) */'
339 "op_flags" => "L|X|Y",
340 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
341 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
342 "reg_req" => { "in" => [ "gp", "gp", "gp", "gp", "none" ], "out" => [ "none", "none" ] },
346 "op_flags" => "L|X|Y",
347 "comment" => "construct switch",
348 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
349 "reg_req" => { "in" => [ "gp" ], "out" => [ "none" ] },
355 "comment" => "represents an integer constant",
356 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
357 "reg_req" => { "out" => [ "gp" ] },
359 ' if (get_ia32_Immop_tarval(n) == get_tarval_null(get_irn_mode(n))) {
360 4. sub %D1, %D1\t\t\t/* optimized mov 0 to register */
363 4. mov %D1, %C\t\t\t/* Mov Const into register */
370 "comment" => "construct CDQ: sign extend EAX -> EDX:EAX",
371 "reg_req" => { "in" => [ "gp" ], "out" => [ "eax in_r1", "edx" ] },
372 "emit" => '. cdq\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
380 "state" => "exc_pinned",
381 "comment" => "construct Load: Load(ptr, mem) = LD ptr -> reg",
382 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
383 "reg_req" => { "in" => [ "gp", "gp", "none" ], "out" => [ "gp" ] },
384 "emit" => '. mov %D1, %ia32_emit_am\t\t\t/* Load((%A1)) -> %D1 */'
389 "state" => "exc_pinned",
390 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
391 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
392 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ] },
393 "emit" => '. mov %ia32_emit_binop\t\t\t/* Store(%A3) -> (%A1) */'
398 "comment" => "construct Lea: Lea(a,b) = lea [a+b*const+offs] | res = a + b * const + offs with const = 0,1,2,4,8",
399 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
400 "reg_req" => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
401 "emit" => '. lea %D1, %ia32_emit_am\t\t/* %D1 = %S1 + %S2 << scale + %O, (%A1, %A2) */'
404 #--------------------------------------------------------#
407 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
408 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
409 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
410 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
411 #--------------------------------------------------------#
413 # commutative operations
417 "comment" => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
418 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
419 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
420 "emit" => '. adds%M %ia32_emit_binop\t\t\t/* SSE Add(%A1, %A2) -> %D1 */'
425 "comment" => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
426 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
427 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
428 "emit" => '. muls%M %ia32_emit_binop\t\t\t/* SSE Mul(%A1, %A2) -> %D1 */'
433 "comment" => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
434 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
435 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
436 "emit" => '. maxs%M %ia32_emit_binop\t\t\t/* SSE Max(%A1, %A2) -> %D1 */'
441 "comment" => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
442 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
443 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
444 "emit" => '. mins%M %ia32_emit_binop\t\t\t/* SSE Min(%A1, %A2) -> %D1 */'
449 "comment" => "construct SSE And: And(a, b) = a AND b",
450 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
451 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
452 "emit" => '. andp%M %ia32_emit_binop\t\t\t/* SSE And(%A3, %A4) -> %D1 */'
457 "comment" => "construct SSE Or: Or(a, b) = a OR b",
458 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
459 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
460 "emit" => '. orp%M %ia32_emit_binop\t\t\t/* SSE Or(%A3, %A4) -> %D1 */'
465 "comment" => "construct SSE Eor: Eor(a, b) = a XOR b",
466 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
467 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
468 "emit" => '. xorp%M %ia32_emit_binop\t\t\t/* SSE Xor(%A3, %A4) -> %D1 */'
471 # not commutative operations
475 "comment" => "construct SSE Sub: Sub(a, b) = a - b",
476 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
477 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
478 "emit" => '. subs%M %ia32_emit_binop\t\t\t/* SSE Sub(%A1, %A2) -> %D1 */'
483 "comment" => "construct SSE Div: Div(a, b) = a / b",
484 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
485 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "in_r3 !in_r4" ] },
486 "emit" => '. divs%M %ia32_emit_binop\t\t\t/* SSE Div(%A1, %A2) -> %D1 */'
492 "op_flags" => "L|X|Y",
493 "comment" => "construct conditional jump: UCOMIS A, B && JMPxx LABEL",
494 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
495 "reg_req" => { "in" => [ "gp", "gp", "fp", "fp", "none" ], "out" => [ "none", "none" ] },
501 "comment" => "represents a SSE constant",
502 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
503 "reg_req" => { "out" => [ "fp" ] },
504 "emit" => '. mov%M %D1, %C\t\t\t/* Load fConst into register */',
512 "state" => "exc_pinned",
513 "comment" => "construct SSE Load: Load(ptr, mem) = LD ptr",
514 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
515 "reg_req" => { "in" => [ "gp", "gp", "none" ], "out" => [ "fp" ] },
516 "emit" => '. movs%M %D1, %ia32_emit_am\t\t\t/* Load((%A1)) -> %D1 */'
521 "state" => "exc_pinned",
522 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
523 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
524 "reg_req" => { "in" => [ "gp", "gp", "fp", "none" ] },
525 "emit" => '. movs%M %ia32_emit_am, %S3\t\t\t/* Store(%S3) -> (%A1) */'
533 "comment" => "implements a memcopy: CopyB(dst, src, size, mem) == memcpy(dst, src, size)",
534 "reg_req" => { "in" => [ "edi", "esi", "ecx", "none" ], "out" => [ "none" ] },
540 "comment" => "implements a memcopy: CopyB(dst, src, mem) == memcpy(dst, src, attr(size))",
541 "cmp_attr" => " return ia32_compare_immop_attr(attr_a, attr_b);\n",
542 "reg_req" => { "in" => [ "edi", "esi", "none" ], "out" => [ "none" ] },
548 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "in_r3", "none" ] },
549 "comment" => "construct Conv Int -> Int"
553 "reg_req" => { "in" => [ "gp", "gp", "gp", "none" ], "out" => [ "fp", "none" ] },
554 "comment" => "construct Conv Int -> Floating Point"
558 "reg_req" => { "in" => [ "gp", "gp", "fp", "none" ], "out" => [ "gp", "none" ] },
559 "comment" => "construct Conv Floating Point -> Int"
563 "reg_req" => { "in" => [ "gp", "gp", "fp", "none" ], "out" => [ "in_r3", "none" ] },
564 "comment" => "construct Conv Floating Point -> Floating Point"