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",
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
42 # op_flags: flags for the operation, OPTIONAL (default is "N")
44 # state: state of the operation, OPTIONAL (default is "pinned")
46 # arity: arity of the operation, MUST NOT BE OMITTED
48 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
49 # are always the first 3 arguments and are always autmatically
51 # If this key is missing the following arguments will be created:
52 # for i = 1 .. arity: ir_node *op_i
55 # comment: OPTIONAL comment for the node constructor
57 # rd_constructor: for every operation there will be a
58 # new_rd_<arch>_<op-name> function with the arguments from above
59 # which creates the ir_node corresponding to the defined operation
60 # you can either put the complete source code of this function here
62 # This key is OPTIONAL. If omitted, the following constructor will
64 # if (!op_<arch>_<op-name>) assert(0);
68 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
71 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
75 # 1 - write invariant (writes to this register doesn't change it's content)
76 # 2 - caller save (register must be saved by the caller of a function)
77 # 3 - callee save (register must be saved by the called function)
78 # 4 - ignore (do not assign this register)
79 # NOTE: Make sure to list the registers returning the call-result at first and
80 # in the correct order, otherwise it will break the magic!
82 "general_purpose" => [
83 { "name" => "eax", "type" => 2 },
84 { "name" => "edx", "type" => 2 },
85 { "name" => "ebx", "type" => 3 },
86 { "name" => "ecx", "type" => 2 },
87 { "name" => "edi", "type" => 2 },
88 { "name" => "esi", "type" => 3 },
89 { "name" => "ebp", "type" => 3 }
92 { "name" => "xmm0", "type" => 2 },
93 { "name" => "xmm1", "type" => 2 },
94 { "name" => "xmm2", "type" => 2 },
95 { "name" => "xmm3", "type" => 2 },
96 { "name" => "xmm4", "type" => 2 },
97 { "name" => "xmm5", "type" => 2 },
98 { "name" => "xmm6", "type" => 2 },
99 { "name" => "xmm7", "type" => 2 },
103 #--------------------------------------------------#
106 # _ __ _____ __ _ _ __ ___ _ __ ___ #
107 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
108 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
109 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
112 #--------------------------------------------------#
116 #-----------------------------------------------------------------#
119 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
120 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
121 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
122 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
125 #-----------------------------------------------------------------#
127 # commutative operations
133 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
135 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
136 "emit" => '. addl %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
142 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
144 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
145 "emit" => '. addl %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
151 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
152 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "eax in_r1", "edx in_r2" ] },
154 ' if (mode_is_signed(get_irn_mode(n))) {
155 4. imull %S2\t\t\t/* signed Mul(%S1, %S2) -> %D1, (%A1, %A2) */
158 4. mull %S2\t\t\t/* unsigned Mul(%S1, %S2) -> %D1, (%A1, %A2) */
166 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
167 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
169 ' if (mode_is_signed(get_irn_mode(n))) {
170 4. imull %C\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */
173 4. mull %C\t\t\t/* unsigned Mul(%C, %S1) -> %D1, (%A1, const) */
182 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
184 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
185 "emit" => '. andl %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
191 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
193 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
194 "emit" => '. andl %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
201 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
203 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
204 "emit" => '. orl %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
210 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
212 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
213 "emit" => '. orl %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
220 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
222 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
223 "emit" => '. xorl %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
229 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
231 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
232 "emit" => '. xorl %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
239 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
241 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
243 '2. cmpl %S2, %S1\t\t\t/* prepare Max (%S1 should be %D1), (%A1, %A2) */
244 if (mode_is_signed(get_irn_mode(n))) {
245 4. cmovl %S2, %D1\t\t\t/* %S1 is less %S2 */
248 4. cmovb %S2, %D1\t\t\t/* %S1 is below %S2 */
257 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
259 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
261 '2. cmpl %S2, %S1\t\t\t/* prepare Min (%S1 should be %D1), (%A1, %A2) */
262 if (mode_is_signed(get_irn_mode(n))) {
263 2. cmovg %S2, %D1\t\t\t/* %S1 is greater %S2 */
266 2. cmova %S2, %D1\t\t\t/* %S1 is above %S2 */
271 # not commutative operations
276 "comment" => "construct Sub: Sub(a, b) = a - b",
278 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
279 "emit" => '. subl %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
285 "comment" => "construct Sub: Sub(a, const) = a - const",
287 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
288 "emit" => '. subl %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
293 "state" => "exc_pinned",
295 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "general_purpose", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
297 ' if (mode_is_signed(get_irn_mode(n))) {
298 4. idivl %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
301 4. divl %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
309 "comment" => "construct Shl: Shl(a, b) = a << b",
311 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
312 "emit" => '. shll %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
318 "comment" => "construct Shl: Shl(a, const) = a << const",
320 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
321 "emit" => '. shll %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
327 "comment" => "construct Shr: Shr(a, b) = a >> b",
329 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
330 "emit" => '. shrl %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
336 "comment" => "construct Shr: Shr(a, const) = a >> const",
338 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
339 "emit" => '. shrl %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
345 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
347 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
348 "emit" => '. sarl %S2, %D1\t\t\t/* Shrs(%S1, %S2) -> %D1, (%A1, %A2) */'
354 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
356 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
357 "emit" => '. sarl %C, %D1\t\t\t/* Shrs(%S1, %C) -> %D1, (%A1, const) */'
363 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
365 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
366 "emit" => '. rorl %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
372 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
374 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
375 "emit" => '. roll %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
381 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
383 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
384 "emit" => '. roll %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
390 "comment" => "construct Minus: Minus(a) = -a",
392 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
393 "emit" => '. negl %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
399 "comment" => "construct Increment: Inc(a) = a++",
401 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
402 "emit" => '. incl %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
408 "comment" => "construct Decrement: Dec(a) = a--",
410 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
411 "emit" => '. decl %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
417 "comment" => "construct Not: Not(a) = !a",
419 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
420 "emit" => '. notl %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
427 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
428 "comment" => "construct Conv: Conv(a) = (conv)a"
432 "op_flags" => "C|L|X|Y",
434 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
435 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
439 "op_flags" => "L|X|Y",
441 "comment" => "construct conditional jump: CMP A, const && JMPxx LABEL",
442 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
446 "op_flags" => "L|X|Y",
448 "comment" => "construct switch",
449 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
456 "comment" => "represents an integer constant",
457 "reg_req" => { "out" => [ "general_purpose" ] },
458 "emit" => '. movl %C, %D1\t\t\t/* Mov Const into register */',
461 if (attr_a->tp == attr_b->tp) {
462 if (attr_a->tp == asmop_SymConst) {
463 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
466 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
469 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
472 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
486 "comment" => "construct Cltd: sign extend EAX -> EDX:EAX",
487 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
488 "emit" => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
495 "state" => "exc_pinned",
498 "comment" => "construct Load: Load(ptr, mem) = LD ptr -> reg",
499 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
500 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
505 "state" => "exc_pinned",
508 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
509 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "none" ] },
510 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
515 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
516 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
517 "emit" => '. leal %O(%S1, %S2, %C), %D1\t\t/* %D1 = %S1 + %S2 << %C + %O, (%A1, %A2) */'
522 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
523 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
524 "emit" => '. leal %C(%S1), %D1\t\t\t/* %D1 = %S1 + %C, (%A1)*/'
529 "comment" => "constructs a Register Parameter to cover parameters passed in register",
530 "reg_req" => { "in" => [ "none" ], "out" => [ "none" ] },
533 return (attr_a->pn_code != attr_b->pn_code);
539 "comment" => "constructs a Stack Parameter to retrieve a parameter from Stack",
540 "reg_req" => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
543 return (attr_a->pn_code != attr_b->pn_code);
549 "comment" => "constructs a Stack Argument to pass an argument on Stack",
550 "reg_req" => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
553 return (attr_a->pn_code != attr_b->pn_code);
557 #--------------------------------------------------------#
560 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
561 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
562 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
563 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
564 #--------------------------------------------------------#
566 # commutative operations
573 "comment" => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
574 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
575 "emit" => '. add%M %S2, %D1\t\t\t/* SSE Add(%S1, %S2) -> %D1 */'
582 "comment" => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
583 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
584 "emit" =>'. muls%M %S2, %D1\t\t\t/* SSE Mul(%S1, %S2) -> %D1 */'
592 "comment" => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
593 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
594 "emit" =>'. maxs%M %S2, %D1\t\t\t/* SSE Max(%S1, %S2) -> %D1 */'
602 "comment" => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
603 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
604 "emit" =>'. mins%M %S2, %D1\t\t\t/* SSE Min(%S1, %S2) -> %D1 */'
607 # not commutative operations
613 "comment" => "construct SSE Sub: Sub(a, b) = a - b",
614 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
615 "emit" => '. subs%M %S2, %D1\t\t\t/* SSE Sub(%S1, %S2) -> %D1 */'
622 "comment" => "construct SSE Div: Div(a, b) = a / b",
623 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
624 "emit" => '. divs%M %S2, %D1\t\t\t/* SSE Div(%S1, %S2) -> %D1 */'
631 "comment" => "construct SSE Minus: Minus(a) = -a",
632 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "in_r1" ] },
633 "emit" => '. xorp%M c %D1\t\t\t/* SSE Minus(%S1) -> %D1 */'
640 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "general_purpose" ] },
641 "comment" => "construct Conv: Conv(a) = (conv)a"
645 "op_flags" => "C|L|X|Y",
647 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
648 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
655 "comment" => "represents a SSE constant",
656 "reg_req" => { "out" => [ "floating_point" ] },
657 "emit" => '. mov%M %C, %D1\t\t\t/* Mov fConst into register */',
660 if (attr_a->tp == attr_b->tp) {
661 if (attr_a->tp == asmop_SymConst) {
662 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
665 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
668 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
671 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
686 "state" => "exc_pinned",
689 "comment" => "construct SSE Load: Load(ptr, mem) = LD ptr",
690 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
691 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
696 "state" => "exc_pinned",
699 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
700 "reg_req" => { "in" => [ "general_purpose", "floating_point", "none" ] },
701 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
706 "comment" => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
707 "reg_req" => { "in" => [ "none" ], "out" => [ "floating_point" ] },
710 return (attr_a->pn_code != attr_b->pn_code);
716 "comment" => "constructs a Stack Argument to pass an argument on Stack",
717 "reg_req" => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
720 return (attr_a->pn_code != attr_b->pn_code);
728 "state" => "mem_pinned",
729 "arity" => "variable",
731 "comment" => "construct Call: Call(...)",
733 { "type" => "int", "name" => "n" },
734 { "type" => "ir_node **", "name" => "in" }
737 " if (!op_ia32_Call) assert(0);
738 return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);