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 before all other
80 # caller save registers and in the correct order, otherwise it will break
83 "general_purpose" => [
84 { "name" => "eax", "type" => 2 },
85 { "name" => "edx", "type" => 2 },
86 { "name" => "ebx", "type" => 3 },
87 { "name" => "ecx", "type" => 2 },
88 { "name" => "esi", "type" => 3 },
89 { "name" => "edi", "type" => 3 },
90 { "name" => "ebp", "type" => 3 },
91 { "name" => "esp", "type" => 4 } # we don't want esp to be assigned
94 { "name" => "xmm0", "type" => 2 },
95 { "name" => "xmm1", "type" => 2 },
96 { "name" => "xmm2", "type" => 2 },
97 { "name" => "xmm3", "type" => 2 },
98 { "name" => "xmm4", "type" => 2 },
99 { "name" => "xmm5", "type" => 2 },
100 { "name" => "xmm6", "type" => 2 },
101 { "name" => "xmm7", "type" => 2 },
105 #--------------------------------------------------#
108 # _ __ _____ __ _ _ __ ___ _ __ ___ #
109 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
110 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
111 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
114 #--------------------------------------------------#
118 #-----------------------------------------------------------------#
121 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
122 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
123 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
124 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
127 #-----------------------------------------------------------------#
129 # commutative operations
135 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
137 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
138 "emit" => '. addl %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
144 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
146 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
147 "emit" => '. addl %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
153 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
154 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "eax in_r1", "edx in_r2" ] },
156 ' if (mode_is_signed(get_irn_mode(n))) {
157 4. imull %S2\t\t\t/* signed Mul(%S1, %S2) -> %D1, (%A1, %A2) */
160 4. mull %S2\t\t\t/* unsigned Mul(%S1, %S2) -> %D1, (%A1, %A2) */
168 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
169 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
171 ' if (mode_is_signed(get_irn_mode(n))) {
172 4. imull %C\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */
175 4. mull %C\t\t\t/* unsigned Mul(%C, %S1) -> %D1, (%A1, const) */
184 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
186 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
187 "emit" => '. andl %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
193 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
195 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
196 "emit" => '. andl %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
203 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
205 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
206 "emit" => '. orl %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
212 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
214 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
215 "emit" => '. orl %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
222 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
224 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
225 "emit" => '. xorl %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
231 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
233 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
234 "emit" => '. xorl %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
241 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
243 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
245 '2. cmpl %S2, %S1\t\t\t/* prepare Max (%S1 should be %D1), (%A1, %A2) */
246 if (mode_is_signed(get_irn_mode(n))) {
247 4. cmovl %S2, %D1\t\t\t/* %S1 is less %S2 */
250 4. cmovb %S2, %D1\t\t\t/* %S1 is below %S2 */
259 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
261 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
263 '2. cmpl %S2, %S1\t\t\t/* prepare Min (%S1 should be %D1), (%A1, %A2) */
264 if (mode_is_signed(get_irn_mode(n))) {
265 2. cmovg %S2, %D1\t\t\t/* %S1 is greater %S2 */
268 2. cmova %S2, %D1\t\t\t/* %S1 is above %S2 */
273 # not commutative operations
278 "comment" => "construct Sub: Sub(a, b) = a - b",
280 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
281 "emit" => '. subl %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
287 "comment" => "construct Sub: Sub(a, const) = a - const",
289 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
290 "emit" => '. subl %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
295 "state" => "exc_pinned",
297 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "general_purpose", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
299 ' if (mode_is_signed(get_irn_mode(n))) {
300 4. idivl %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
303 4. divl %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
311 "comment" => "construct Shl: Shl(a, b) = a << b",
313 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
314 "emit" => '. shll %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
320 "comment" => "construct Shl: Shl(a, const) = a << const",
322 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
323 "emit" => '. shll %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
329 "comment" => "construct Shr: Shr(a, b) = a >> b",
331 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
332 "emit" => '. shrl %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
338 "comment" => "construct Shr: Shr(a, const) = a >> const",
340 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
341 "emit" => '. shrl %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
347 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
349 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
350 "emit" => '. sarl %S2, %D1\t\t\t/* Shrs(%S1, %S2) -> %D1, (%A1, %A2) */'
356 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
358 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
359 "emit" => '. sarl %C, %D1\t\t\t/* Shrs(%S1, %C) -> %D1, (%A1, const) */'
365 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
367 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
368 "emit" => '. rorl %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
374 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
376 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
377 "emit" => '. roll %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
383 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
385 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
386 "emit" => '. roll %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
392 "comment" => "construct Minus: Minus(a) = -a",
394 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
395 "emit" => '. negl %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
401 "comment" => "construct Increment: Inc(a) = a++",
403 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
404 "emit" => '. incl %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
410 "comment" => "construct Decrement: Dec(a) = a--",
412 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
413 "emit" => '. decl %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
419 "comment" => "construct Not: Not(a) = !a",
421 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
422 "emit" => '. notl %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
429 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
430 "comment" => "construct Conv: Conv(a) = (conv)a"
434 "op_flags" => "C|L|X|Y",
436 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
437 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
441 "op_flags" => "L|X|Y",
443 "comment" => "construct conditional jump: CMP A, const && JMPxx LABEL",
444 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
448 "op_flags" => "L|X|Y",
450 "comment" => "construct switch",
451 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
458 "comment" => "represents an integer constant",
459 "reg_req" => { "out" => [ "general_purpose" ] },
460 "emit" => '. movl %C, %D1\t\t\t/* Mov Const into register */',
463 if (attr_a->tp == attr_b->tp) {
464 if (attr_a->tp == asmop_SymConst) {
465 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
468 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
471 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
474 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
488 "comment" => "construct Cltd: sign extend EAX -> EDX:EAX",
489 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
490 "emit" => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
497 "state" => "exc_pinned",
500 "comment" => "construct Load: Load(ptr, mem) = LD ptr -> reg",
501 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
502 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
507 "state" => "exc_pinned",
510 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
511 "reg_req" => { "in" => [ "general_purpose", "general_purpose", "none" ] },
512 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
517 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
518 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
519 "emit" => '. leal %O(%S1, %S2, %C), %D1\t\t/* %D1 = %S1 + %S2 << %C + %O, (%A1, %A2) */'
524 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
525 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
526 "emit" => '. leal %C(%S1), %D1\t\t\t/* %D1 = %S1 + %C, (%A1)*/'
532 "comment" => "constructs a Stack Parameter to retrieve a parameter from Stack",
533 "reg_req" => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
536 return (attr_a->pn_code != attr_b->pn_code);
542 "comment" => "constructs a Stack Argument to pass an argument on Stack",
543 "reg_req" => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
546 return (attr_a->pn_code != attr_b->pn_code);
550 #--------------------------------------------------------#
553 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
554 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
555 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
556 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
557 #--------------------------------------------------------#
559 # commutative operations
566 "comment" => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
567 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
568 "emit" => '. add%M %S2, %D1\t\t\t/* SSE Add(%S1, %S2) -> %D1 */'
575 "comment" => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
576 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
577 "emit" =>'. muls%M %S2, %D1\t\t\t/* SSE Mul(%S1, %S2) -> %D1 */'
585 "comment" => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
586 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
587 "emit" =>'. maxs%M %S2, %D1\t\t\t/* SSE Max(%S1, %S2) -> %D1 */'
595 "comment" => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
596 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
597 "emit" =>'. mins%M %S2, %D1\t\t\t/* SSE Min(%S1, %S2) -> %D1 */'
600 # not commutative operations
606 "comment" => "construct SSE Sub: Sub(a, b) = a - b",
607 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
608 "emit" => '. subs%M %S2, %D1\t\t\t/* SSE Sub(%S1, %S2) -> %D1 */'
615 "comment" => "construct SSE Div: Div(a, b) = a / b",
616 "reg_req" => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
617 "emit" => '. divs%M %S2, %D1\t\t\t/* SSE Div(%S1, %S2) -> %D1 */'
624 "comment" => "construct SSE Minus: Minus(a) = -a",
625 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "in_r1" ] },
626 "emit" => '. xorp%M c %D1\t\t\t/* SSE Minus(%S1) -> %D1 */'
633 "reg_req" => { "in" => [ "floating_point" ], "out" => [ "general_purpose" ] },
634 "comment" => "construct Conv: Conv(a) = (conv)a"
638 "op_flags" => "C|L|X|Y",
640 "comment" => "construct conditional jump: CMP A, B && JMPxx LABEL",
641 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
648 "comment" => "represents a SSE constant",
649 "reg_req" => { "out" => [ "floating_point" ] },
650 "emit" => '. mov%M %C, %D1\t\t\t/* Mov fConst into register */',
653 if (attr_a->tp == attr_b->tp) {
654 if (attr_a->tp == asmop_SymConst) {
655 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
658 return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
661 if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
664 if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
679 "state" => "exc_pinned",
682 "comment" => "construct SSE Load: Load(ptr, mem) = LD ptr",
683 "reg_req" => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
684 "emit" => '. movl (%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
689 "state" => "exc_pinned",
692 "comment" => "construct Store: Store(ptr, val, mem) = ST ptr,val",
693 "reg_req" => { "in" => [ "general_purpose", "floating_point", "none" ] },
694 "emit" => '. movl %S2, (%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
700 "comment" => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
701 "reg_req" => { "in" => [ "none" ], "out" => [ "floating_point" ] },
704 return (attr_a->pn_code != attr_b->pn_code);
710 "comment" => "constructs a Stack Argument to pass an argument on Stack",
711 "reg_req" => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
714 return (attr_a->pn_code != attr_b->pn_code);
722 "state" => "mem_pinned",
723 "arity" => "variable",
724 "comment" => "construct Call: Call(...)",
726 { "type" => "int", "name" => "n" },
727 { "type" => "ir_node **", "name" => "in" }
730 " if (!op_ia32_Call) assert(0);
731 return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);
740 "arity" => "variable",
741 "comment" => "construct Return: Return(...)",
743 { "type" => "int", "name" => "n" },
744 { "type" => "ir_node **", "name" => "in" }
747 " if (!op_ia32_Return) assert(0);
748 return new_ir_node(db, irg, block, op_ia32_Return, mode_X, n, in);