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
74 "general_purpose" => [
75 { "name" => "eax", "type" => 0 },
76 { "name" => "ebx", "type" => 0 },
77 { "name" => "ecx", "type" => 0 },
78 { "name" => "edx", "type" => 0 },
79 { "name" => "edi", "type" => 0 },
80 { "name" => "esi", "type" => 0 },
81 { "name" => "ebp", "type" => 0 }
84 { "name" => "xmm0", "type" => 0 },
85 { "name" => "xmm1", "type" => 0 },
86 { "name" => "xmm2", "type" => 0 },
87 { "name" => "xmm3", "type" => 0 },
88 { "name" => "xmm4", "type" => 0 },
89 { "name" => "xmm5", "type" => 0 },
90 { "name" => "xmm6", "type" => 0 },
91 { "name" => "xmm7", "type" => 0 },
95 #--------------------------------------------------#
98 # _ __ _____ __ _ _ __ ___ _ __ ___ #
99 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
100 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
101 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
104 #--------------------------------------------------#
108 #-----------------------------------------------------------------#
111 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
112 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
113 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
114 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
117 #-----------------------------------------------------------------#
119 # commutative operations
125 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
127 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
128 "emit" => '. addl %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
134 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
136 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
137 "emit" => '. addl %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
143 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
144 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "eax in_r1", "edx in_r2" ] },
146 ' if (mode_is_signed(get_irn_mode(n))) {
147 4. imull %S2\t\t\t/* signed Mul(%S1, %S2) -> %D1, (%A1, %A2) */
150 4. mull %S2\t\t\t/* unsigned Mul(%S1, %S2) -> %D1, (%A1, %A2) */
158 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
159 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
161 ' if (mode_is_signed(get_irn_mode(n))) {
162 4. imull %C\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */
165 4. mull %C\t\t\t/* unsigned Mul(%C, %S1) -> %D1, (%A1, const) */
174 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
176 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
177 "emit" => '. andl %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
183 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
185 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
186 "emit" => '. andl %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
193 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
195 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
196 "emit" => '. orl %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
202 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
204 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
205 "emit" => '. orl %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
212 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
214 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
215 "emit" => '. xorl %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
221 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
223 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
224 "emit" => '. xorl %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
231 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
233 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
235 '2. cmpl %S2, %S1\t\t\t/* prepare Max (%S1 should be %D1), (%A1, %A2) */
236 if (mode_is_signed(get_irn_mode(n))) {
237 4. cmovl %S2, %D1\t\t\t/* %S1 is less %S2 */
240 4. cmovb %S2, %D1\t\t\t/* %S1 is below %S2 */
249 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
251 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
253 '2. cmpl %S2, %S1\t\t\t/* prepare Min (%S1 should be %D1), (%A1, %A2) */
254 if (mode_is_signed(get_irn_mode(n))) {
255 2. cmovg %S2, %D1\t\t\t/* %S1 is greater %S2 */
258 2. cmova %S2, %D1\t\t\t/* %S1 is above %S2 */
263 # not commutative operations
268 "comment" => "construct Sub: Sub(a, b) = a - b",
270 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
271 "emit" => '. subl %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
277 "comment" => "construct Sub: Sub(a, const) = a - const",
279 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
280 "emit" => '. subl %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
285 "state" => "exc_pinned",
287 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "general_purpose", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
289 ' if (mode_is_signed(get_irn_mode(n))) {
290 4. idivl %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
293 4. divl %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
301 "comment" => "construct Shl: Shl(a, b) = a << b",
303 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
304 "emit" => '. shll %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
310 "comment" => "construct Shl: Shl(a, const) = a << const",
312 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
313 "emit" => '. shll %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
319 "comment" => "construct Shr: Shr(a, b) = a >> b",
321 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
322 "emit" => '. shrl %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
328 "comment" => "construct Shr: Shr(a, const) = a >> const",
330 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
331 "emit" => '. shrl %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
337 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
339 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
340 "emit" => '. sarl %S2, %D1\t\t\t/* Shrs(%S1, %S2) -> %D1, (%A1, %A2) */'
346 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
348 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
349 "emit" => '. sarl %C, %D1\t\t\t/* Shrs(%S1, %C) -> %D1, (%A1, const) */'
355 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
357 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
358 "emit" => '. rorl %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
364 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
366 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
367 "emit" => '. roll %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
373 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
375 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
376 "emit" => '. roll %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
382 "comment" => "construct Minus: Minus(a) = -a",
384 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
385 "emit" => '. negl %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
391 "comment" => "construct Increment: Inc(a) = a++",
393 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
394 "emit" => '. incl %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
400 "comment" => "construct Decrement: Dec(a) = a--",
402 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
403 "emit" => '. decl %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
409 "comment" => "construct Not: Not(a) = !a",
411 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
412 "emit" => '. notl %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
419 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
420 "comment" => "construct Conv: Conv(a) = (conv)a"
424 "op_flags" => "C|L|X|Y",
426 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
427 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
431 "op_flags" => "L|X|Y",
433 "comment" => "construct conditional jump: CMP A, const && JMPxx LABEL",
434 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
438 "op_flags" => "L|X|Y",
440 "comment" => "construct switch",
441 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
448 "comment" => "represents an integer constant",
449 "reg_req" => { "out" => [ "general_purpose" ] },
450 "emit" => '. movl %C, %D1\t\t\t/* Mov Const into register */',
453 if (attr_a->tp == attr_b->tp) {
454 if (attr_a->tp == asmop_SymConst) {
455 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
458 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
461 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
464 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
478 "comment" => "construct Cltd: sign extend EAX -> EDX:EAX",
479 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
480 "emit" => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
487 "state" => "exc_pinned",
490 "comment" => "construct Load: Load(ptr, mem) = LD ptr -> reg",
491 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
492 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
497 "state" => "exc_pinned",
500 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
501 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "none" ] },
502 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
507 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
508 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
509 "emit" => '. leal %O(%S1, %S2, %C), %D1\t\t/* %D1 = %S1 + %S2 << %C + %O, (%A1, %A2) */'
514 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
515 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
516 "emit" => '. leal %C(%S1), %D1\t\t\t/* %D1 = %S1 + %C, (%A1)*/'
521 "comment" => "constructs a Register Parameter to cover parameters passed in register",
522 "reg_req" => { "in" => [ "none" ], "out" => [ "none" ] },
525 return (attr_a->pn_code != attr_b->pn_code);
531 "comment" => "constructs a Stack Parameter to retrieve a parameter from Stack",
532 "reg_req" => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
535 return (attr_a->pn_code != attr_b->pn_code);
541 "comment" => "constructs a Stack Argument to pass an argument on Stack",
542 "reg_req" => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
545 return (attr_a->pn_code != attr_b->pn_code);
549 #--------------------------------------------------------#
552 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
553 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
554 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
555 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
556 #--------------------------------------------------------#
558 # commutative operations
565 "comment" => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
566 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
567 "emit" => '. add%M %S2, %D1\t\t\t/* SSE Add(%S1, %S2) -> %D1 */'
574 "comment" => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
575 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
576 "emit" =>'. muls%M %S2, %D1\t\t\t/* SSE Mul(%S1, %S2) -> %D1 */'
584 "comment" => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
585 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
586 "emit" =>'. maxs%M %S2, %D1\t\t\t/* SSE Max(%S1, %S2) -> %D1 */'
594 "comment" => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
595 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
596 "emit" =>'. mins%M %S2, %D1\t\t\t/* SSE Min(%S1, %S2) -> %D1 */'
599 # not commutative operations
605 "comment" => "construct SSE Sub: Sub(a, b) = a - b",
606 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
607 "emit" => '. subs%M %S2, %D1\t\t\t/* SSE Sub(%S1, %S2) -> %D1 */'
614 "comment" => "construct SSE Div: Div(a, b) = a / b",
615 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
616 "emit" => '. divs%M %S2, %D1\t\t\t/* SSE Div(%S1, %S2) -> %D1 */'
623 "comment" => "construct SSE Minus: Minus(a) = -a",
624 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "in_r1" ] },
625 "emit" => '. xorp%M c %D1\t\t\t/* SSE Minus(%S1) -> %D1 */'
632 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "general_purpose" ] },
633 "comment" => "construct Conv: Conv(a) = (conv)a"
637 "op_flags" => "C|L|X|Y",
639 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
640 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
647 "comment" => "represents a SSE constant",
648 "reg_req" => { "out" => [ "floating_point" ] },
649 "emit" => '. mov%M %C, %D1\t\t\t/* Mov fConst into register */',
652 if (attr_a->tp == attr_b->tp) {
653 if (attr_a->tp == asmop_SymConst) {
654 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
657 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
660 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
663 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
678 "state" => "exc_pinned",
681 "comment" => "construct SSE Load: Load(ptr, mem) = LD ptr",
682 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
683 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
688 "state" => "exc_pinned",
691 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
692 "reg_req" => { "in" => [ "general_purpose", "floating_point", "none" ] },
693 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
698 "comment" => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
699 "reg_req" => { "in" => [ "none" ], "out" => [ "floating_point" ] },
702 return (attr_a->pn_code != attr_b->pn_code);
708 "comment" => "constructs a Stack Argument to pass an argument on Stack",
709 "reg_req" => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
712 return (attr_a->pn_code != attr_b->pn_code);
720 "state" => "mem_pinned",
721 "arity" => "variable",
723 "comment" => "construct Call: Call(...)",
725 { "type" => "int", "name" => "n" },
726 { "type" => "ir_node **", "name" => "in" }
729 " if (!op_ia32_Call) assert(0);
730 return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);