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 # "arity" => "0|1|2|3|variable|dynamic|all",
17 # "state" => "floats|pinned",
19 # { "type" => "type 1", "name" => "name 1" },
20 # { "type" => "type 2", "name" => "name 2" },
23 # "comment" => "any comment for constructor",
24 # "rd_constructor" => "c source code which constructs an ir_node"
27 # ... # (all nodes you need to describe)
29 # ); # close the %nodes initializer
31 # the op_flags correspond to the firm irop_flags:
34 # C irop_flag_commutative
35 # X irop_flag_cfopcode
36 # I irop_flag_ip_cfopcode
39 # H irop_flag_highlevel
40 # c irop_flag_constlike
43 # op_flags: flags for the operation, OPTIONAL (default is "N")
45 # state: state of the operation, OPTIONAL (default is "pinned")
47 # arity: arity of the operation, MUST NOT BE OMITTED
49 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
50 # are always the first 3 arguments and are always autmatically
52 # If this key is missing the following arguments will be created:
53 # for i = 1 .. arity: ir_node *op_i
56 # comment: OPTIONAL comment for the node constructor
58 # rd_constructor: for every operation there will be a
59 # new_rd_<arch>_<op-name> function with the arguments from above
60 # which creates the ir_node corresponding to the defined operation
61 # you can either put the complete source code of this function here
63 # This key is OPTIONAL. If omitted, the following constructor will
65 # if (!op_<arch>_<op-name>) assert(0);
69 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
72 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
76 # 1 - write invariant (writes to this register doesn't change it's content)
77 # 2 - caller save (register must be saved by the caller of a function)
78 # 3 - callee save (register must be saved by the called function)
79 # 4 - ignore (do not assign this register)
80 # NOTE: Make sure to list the registers returning the call-result before all other
81 # caller save registers and in the correct order, otherwise it will break
84 "general_purpose" => [
85 { "name" => "eax", "type" => 2 },
86 { "name" => "edx", "type" => 2 },
87 { "name" => "ebx", "type" => 3 },
88 { "name" => "ecx", "type" => 2 },
89 { "name" => "esi", "type" => 3 },
90 { "name" => "edi", "type" => 3 },
91 { "name" => "ebp", "type" => 3 },
92 { "name" => "esp", "type" => 4 } # we don't want esp to be assigned
95 { "name" => "xmm0", "type" => 2 },
96 { "name" => "xmm1", "type" => 2 },
97 { "name" => "xmm2", "type" => 2 },
98 { "name" => "xmm3", "type" => 2 },
99 { "name" => "xmm4", "type" => 2 },
100 { "name" => "xmm5", "type" => 2 },
101 { "name" => "xmm6", "type" => 2 },
102 { "name" => "xmm7", "type" => 2 },
106 #--------------------------------------------------#
109 # _ __ _____ __ _ _ __ ___ _ __ ___ #
110 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
111 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
112 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
115 #--------------------------------------------------#
119 #-----------------------------------------------------------------#
122 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
123 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
124 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
125 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
128 #-----------------------------------------------------------------#
130 # commutative operations
136 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
138 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
139 "emit" => '. addl %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
145 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
147 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
148 "emit" => '. addl %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
154 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
155 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "eax in_r1", "edx in_r2" ] },
157 ' if (mode_is_signed(get_irn_mode(n))) {
158 4. imull %S2\t\t\t/* signed Mul(%S1, %S2) -> %D1, (%A1, %A2) */
161 4. mull %S2\t\t\t/* unsigned Mul(%S1, %S2) -> %D1, (%A1, %A2) */
169 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
170 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
172 ' if (mode_is_signed(get_irn_mode(n))) {
173 4. imull %C\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */
176 4. mull %C\t\t\t/* unsigned Mul(%C, %S1) -> %D1, (%A1, const) */
185 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
187 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
188 "emit" => '. andl %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
194 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
196 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
197 "emit" => '. andl %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
204 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
206 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
207 "emit" => '. orl %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
213 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
215 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
216 "emit" => '. orl %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
223 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
225 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
226 "emit" => '. xorl %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
232 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
234 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
235 "emit" => '. xorl %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
242 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
244 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
246 '2. cmpl %S2, %S1\t\t\t/* prepare Max (%S1 should be %D1), (%A1, %A2) */
247 if (mode_is_signed(get_irn_mode(n))) {
248 4. cmovl %S2, %D1\t\t\t/* %S1 is less %S2 */
251 4. cmovb %S2, %D1\t\t\t/* %S1 is below %S2 */
260 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
262 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
264 '2. cmpl %S2, %S1\t\t\t/* prepare Min (%S1 should be %D1), (%A1, %A2) */
265 if (mode_is_signed(get_irn_mode(n))) {
266 2. cmovg %S2, %D1\t\t\t/* %S1 is greater %S2 */
269 2. cmova %S2, %D1\t\t\t/* %S1 is above %S2 */
274 # not commutative operations
279 "comment" => "construct Sub: Sub(a, b) = a - b",
281 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
282 "emit" => '. subl %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
288 "comment" => "construct Sub: Sub(a, const) = a - const",
290 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
291 "emit" => '. subl %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
296 "state" => "exc_pinned",
298 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "general_purpose", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
300 ' if (mode_is_signed(get_irn_mode(n))) {
301 4. idivl %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
304 4. divl %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
312 "comment" => "construct Shl: Shl(a, b) = a << b",
314 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
315 "emit" => '. shll %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
321 "comment" => "construct Shl: Shl(a, const) = a << const",
323 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
324 "emit" => '. shll %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
330 "comment" => "construct Shr: Shr(a, b) = a >> b",
332 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
333 "emit" => '. shrl %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
339 "comment" => "construct Shr: Shr(a, const) = a >> const",
341 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
342 "emit" => '. shrl %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
348 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
350 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
351 "emit" => '. sarl %S2, %D1\t\t\t/* Shrs(%S1, %S2) -> %D1, (%A1, %A2) */'
357 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
359 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
360 "emit" => '. sarl %C, %D1\t\t\t/* Shrs(%S1, %C) -> %D1, (%A1, const) */'
366 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
368 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
369 "emit" => '. rorl %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
375 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
377 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
378 "emit" => '. roll %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
384 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
386 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
387 "emit" => '. roll %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
393 "comment" => "construct Minus: Minus(a) = -a",
395 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
396 "emit" => '. negl %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
402 "comment" => "construct Increment: Inc(a) = a++",
404 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
405 "emit" => '. incl %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
411 "comment" => "construct Decrement: Dec(a) = a--",
413 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
414 "emit" => '. decl %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
420 "comment" => "construct Not: Not(a) = !a",
422 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
423 "emit" => '. notl %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
430 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
431 "comment" => "construct Conv: Conv(a) = (conv)a"
435 "op_flags" => "C|L|X|Y",
437 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
438 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
442 "op_flags" => "L|X|Y",
444 "comment" => "construct conditional jump: CMP A, const && JMPxx LABEL",
445 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
449 "op_flags" => "L|X|Y",
451 "comment" => "construct switch",
452 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
459 "comment" => "represents an integer constant",
460 "reg_req" => { "out" => [ "general_purpose" ] },
461 "emit" => '. movl %C, %D1\t\t\t/* Mov Const into register */',
464 if (attr_a->tp == attr_b->tp) {
465 if (attr_a->tp == asmop_SymConst) {
466 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
469 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
472 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
475 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
489 "comment" => "construct Cltd: sign extend EAX -> EDX:EAX",
490 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
491 "emit" => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
498 "state" => "exc_pinned",
501 "comment" => "construct Load: Load(ptr, mem) = LD ptr -> reg",
502 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
503 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
508 "state" => "exc_pinned",
511 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
512 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "none" ] },
513 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
518 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
519 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
520 "emit" => '. leal %O(%S1, %S2, %C), %D1\t\t/* %D1 = %S1 + %S2 << %C + %O, (%A1, %A2) */'
525 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
526 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
527 "emit" => '. leal %C(%S1), %D1\t\t\t/* %D1 = %S1 + %C, (%A1)*/'
533 "comment" => "constructs a Stack Parameter to retrieve a parameter from Stack",
534 "reg_req" => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
537 return (attr_a->pn_code != attr_b->pn_code);
543 "comment" => "constructs a Stack Argument to pass an argument on Stack",
544 "reg_req" => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
547 return (attr_a->pn_code != attr_b->pn_code);
551 #--------------------------------------------------------#
554 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
555 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
556 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
557 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
558 #--------------------------------------------------------#
560 # commutative operations
567 "comment" => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
568 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
569 "emit" => '. add%M %S2, %D1\t\t\t/* SSE Add(%S1, %S2) -> %D1 */'
576 "comment" => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
577 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
578 "emit" =>'. muls%M %S2, %D1\t\t\t/* SSE Mul(%S1, %S2) -> %D1 */'
586 "comment" => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
587 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
588 "emit" =>'. maxs%M %S2, %D1\t\t\t/* SSE Max(%S1, %S2) -> %D1 */'
596 "comment" => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
597 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
598 "emit" =>'. mins%M %S2, %D1\t\t\t/* SSE Min(%S1, %S2) -> %D1 */'
601 # not commutative operations
607 "comment" => "construct SSE Sub: Sub(a, b) = a - b",
608 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
609 "emit" => '. subs%M %S2, %D1\t\t\t/* SSE Sub(%S1, %S2) -> %D1 */'
616 "comment" => "construct SSE Div: Div(a, b) = a / b",
617 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
618 "emit" => '. divs%M %S2, %D1\t\t\t/* SSE Div(%S1, %S2) -> %D1 */'
625 "comment" => "construct SSE Minus: Minus(a) = -a",
626 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "in_r1" ] },
627 "emit" => '. xorp%M c %D1\t\t\t/* SSE Minus(%S1) -> %D1 */'
634 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "general_purpose" ] },
635 "comment" => "construct Conv: Conv(a) = (conv)a"
639 "op_flags" => "C|L|X|Y",
641 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
642 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
649 "comment" => "represents a SSE constant",
650 "reg_req" => { "out" => [ "floating_point" ] },
651 "emit" => '. mov%M %C, %D1\t\t\t/* Mov fConst into register */',
654 if (attr_a->tp == attr_b->tp) {
655 if (attr_a->tp == asmop_SymConst) {
656 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
659 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
662 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
665 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
680 "state" => "exc_pinned",
683 "comment" => "construct SSE Load: Load(ptr, mem) = LD ptr",
684 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
685 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
690 "state" => "exc_pinned",
693 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
694 "reg_req" => { "in" => [ "general_purpose", "floating_point", "none" ] },
695 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
701 "comment" => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
702 "reg_req" => { "in" => [ "none" ], "out" => [ "floating_point" ] },
705 return (attr_a->pn_code != attr_b->pn_code);
711 "comment" => "constructs a Stack Argument to pass an argument on Stack",
712 "reg_req" => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
715 return (attr_a->pn_code != attr_b->pn_code);
723 "state" => "mem_pinned",
724 "arity" => "variable",
725 "comment" => "construct Call: Call(...)",
727 { "type" => "int", "name" => "n" },
728 { "type" => "ir_node **", "name" => "in" }
731 " if (!op_ia32_Call) assert(0);
732 return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);
741 "arity" => "variable",
742 "comment" => "construct Return: Return(...)",
744 { "type" => "int", "name" => "n" },
745 { "type" => "ir_node **", "name" => "in" }
748 " if (!op_ia32_Return) assert(0);
749 return new_ir_node(db, irg, block, op_ia32_Return, mode_X, n, in);
759 "comment" => "construct Alloca: allocate memory on Stack",
760 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] }
767 "comment" => "construct Alloca: allocate memory on Stack",
768 "reg_req" => { "out" => [ "general_purpose" ] }