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)
69 # res = optimize_node(res)
70 # IRN_VRFY_IRG(res, irg)
73 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
76 "general_purpose" => [
77 { "name" => "eax", "type" => 0 },
78 { "name" => "ebx", "type" => 0 },
79 { "name" => "ecx", "type" => 0 },
80 { "name" => "edx", "type" => 0 },
81 { "name" => "edi", "type" => 0 },
82 { "name" => "esi", "type" => 0 },
83 { "name" => "ebp", "type" => 0 }
86 { "name" => "xmm0", "type" => 0 },
87 { "name" => "xmm1", "type" => 0 },
88 { "name" => "xmm2", "type" => 0 },
89 { "name" => "xmm3", "type" => 0 },
90 { "name" => "xmm4", "type" => 0 },
91 { "name" => "xmm5", "type" => 0 },
92 { "name" => "xmm6", "type" => 0 },
93 { "name" => "xmm7", "type" => 0 },
96 { "name" => "eflags", "type" => 0 }
100 #--------------------------------------------------#
103 # _ __ _____ __ _ _ __ ___ _ __ ___ #
104 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
105 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
106 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
109 #--------------------------------------------------#
113 # arithmetic operations
115 # commutative operations
121 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
123 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
124 "emit" => '. addl %s2, %d1\t\t\t/* Add(%s1, %s2) -> %d1 */'
130 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
132 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
133 "emit" => '. addl %c, %d1\t\t\t/* Add(%c, %s1) -> %d1 */'
139 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
140 "reg_req" => { "in" => [ "eax", "general_purpose" ], "out" => [ "eax" ] },
142 ' if (mode_is_signed(get_irn_mode(n))) {
143 4. imull %s2\t\t\t/* signed Mul(%s1, %s2) -> %d1 */
146 4. mull %s2\t\t\t/* unsigned Mul(%s1, %s2) -> %d1 */
154 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
155 # "reg_req" => { "in" => [ "eax" ], "out" => [ "eax" ] },
156 "reg_req" => { "in" => [ "!eax" ], "out" => [ "eax" ] },
158 ' if (mode_is_signed(get_irn_mode(n))) {
159 4. imull %c\t\t\t/* signed Mul(%c, %s1) -> %d1 */
162 4. mull %c\t\t\t/* unsigned Mul(%c, %s1) -> %d1 */
170 "comment" => "construct Mulh: Mulh(a, b) = Mulh(b, a) = get_32_highest_bits(a * b)",
171 "reg_req" => { "in" => [ "eax", "general_purpose" ], "out" => [ "edx" ] },
173 ' if (mode_is_signed(get_irn_mode(n))) {
174 4. imull %s2\t\t\t/* signed Mulh(%s1, %s2) -> %d1 */
177 4. mull %s2\t\t\t/* unsigned Mulh(%s1, %s2) -> %d1 */
185 "comment" => "construct Mulh: Mulh(a, const) = Mulh(const, a) = get_32_highest_bits(a * const)",
186 "reg_req" => { "in" => [ "eax" ], "out" => [ "edx" ] },
188 ' if (mode_is_signed(get_irn_mode(n))) {
189 4. imull %c\t\t\t/* signed Mulh(%c, %s1) -> %d1 */
192 4. mull %c\t\t\t/* unsigned Mulh(%c, %s1) -> %d1 */
201 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
203 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
204 "emit" => '. andl %s2, %d1\t\t\t/* And(%s1, %s2) -> %d1 */'
210 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
212 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
213 "emit" => '. andl %c, %d1\t\t\t/* And(%c, %s1) -> %d1 */'
220 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
222 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
223 "emit" => '. orl %s2, %d1\t\t\t/* Or(%s1, %s2) -> %d1 */'
229 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
231 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
232 "emit" => '. orl %c, %d1\t\t\t/* Or(%c, %s1) -> %d1 */'
239 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
241 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
242 "emit" => '. xorl %s2, %d1\t\t\t/* Xor(%s1, %s2) -> %d1 */'
248 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
250 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
251 "emit" => '. xorl %c, %d1\t\t\t/* Xor(%c, %s1) -> %d1 */'
258 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
260 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
262 '2. cmpl %s2, %s1\t\t\t/* prepare Max (%s1 should be %d1) */
263 if (mode_is_signed(get_irn_mode(n))) {
264 4. cmovl %s2, %d1\t\t\t/* %s1 is less %s2 */
267 4. cmovb %s2, %d1\t\t\t/* %s1 is below %s2 */
276 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
278 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
280 '2. cmpl %s2, %s1\t\t\t/* prepare Min (%s1 should be %d1) */
281 if (mode_is_signed(get_irn_mode(n))) {
282 2. cmovg %s2, %d1\t\t\t/* %s1 is greater %s2 */
285 2. cmova %s2, %d1\t\t\t/* %s1 is above %s2 */
290 # not commutative operations
295 "comment" => "construct Sub: Sub(a, b) = a - b",
297 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
298 "emit" => '. subl %s2, %d1\t\t\t/* Sub(%s1, %s2) -> %d1 */'
304 "comment" => "construct Sub: Sub(a, const) = a - const",
306 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
307 "emit" => '. subl %c, %d1\t\t\t/* Sub(%s1, %c) -> %d1 */'
312 "comment" => "construct DivMod: DivMod(a,b) = (a / b, a % b)",
313 "reg_req" => { "in" => [ "eax", "general_purpose", "edx" ], "out" => [ "eax", "edx" ] },
315 ' if (mode_is_signed(get_irn_mode(n))) {
316 4. idivl %s2\t\t\t/* signed Mod(%s1, %s2) -> %d1 */
319 4. divl %s2\t\t\t/* unsigned Mod(%s1, %s2) -> %d1 */
323 { "type" => "ir_node *", "name" => "divisor" },
324 { "type" => "ir_node *", "name" => "dividend" },
325 { "type" => "divmod_flavour_t", "name" => "dm_flav" }, # flavours (flavour_Div, flavour_Mod, flavour_DivMod)
326 { "type" => "ir_mode *", "name" => "mode" },
332 if (!op_ia32_DivMod) assert(0);
335 if (mode_is_signed(mode)) {
337 /* in signed mode , we need to sign extend the divisor */
338 cltd = new_rd_ia32_Cltd(db, current_ir_graph, block, divisor, mode_T);
339 in[0] = new_rd_Proj(db, current_ir_graph, block, cltd, mode, pn_EAX);
340 in[2] = new_rd_Proj(db, current_ir_graph, block, cltd, mode, pn_EDX);
344 in[2] = new_rd_ia32_Const(dbg, current_ir_graph, block, mode);
345 set_Const_type(in[2], asmop_Const);
346 set_Immop_tarval(in[2], get_tarval_null(mode_Iu));
349 res = new_ir_node(db, irg, block, op_ia32_DivMod, mode, 1, in);
350 res = optimize_node(res);
351 irn_vrfy_irg(res, irg);
353 set_DivMod_flavour(dm_flav);
362 "comment" => "construct Shl: Shl(a, b) = a << b",
364 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
365 "emit" => '. shll %s2, %d1\t\t\t/* Shl(%s1, %s2) -> %d1 */'
371 "comment" => "construct Shl: Shl(a, const) = a << const",
373 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
374 "emit" => '. shll %c, %d1\t\t\t/* Shl(%s1, %c) -> %d1 */'
380 "comment" => "construct Shr: Shr(a, b) = a >> b",
382 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
383 "emit" => '. shrl %s2, %d1\t\t\t/* Shr(%s1, %s2) -> %d1 */'
389 "comment" => "construct Shr: Shr(a, const) = a >> const",
391 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
392 "emit" => '. shrl %c, %d1\t\t\t/* Shr(%s1, %c) -> %d1 */'
398 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
400 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
401 "emit" => '. sarl %s2, %d1\t\t\t/* Shrs(%s1, %s2) -> %d1 */'
407 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
409 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
410 "emit" => '. sarl %c, %d1\t\t\t/* Shrs(%s1, %c) -> %d1 */'
416 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
418 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
419 "emit" => '. rorl %s2, %d1\t\t\t/* RotR(%s1, %s2) -> %d1 */'
425 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
427 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
428 "emit" => '. roll %s2, %d1\t\t\t/* RotL(%s1, %s2) -> %d1 */'
434 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
436 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
437 "emit" => '. roll %c, %d1\t\t\t/* RotL(%s1, %c) -> %d1 */'
443 "comment" => "construct Minus: Minus(a) = -a",
445 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
446 "emit" => '. negl %d1\t\t\t/* Neg(%s1) -> %d1 */'
452 "comment" => "construct Increment: Inc(a) = a++",
454 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
455 "emit" => '. incl %d1\t\t\t/* Inc(%s1) -> %d1 */'
461 "comment" => "construct Decrement: Dec(a) = a--",
463 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
464 "emit" => '. decl %d1\t\t\t/* Dec(%s1) -> %d1 */'
470 "comment" => "construct Not: Not(a) = !a",
472 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
473 "emit" => '. notl %d1\t\t\t/* Not(%s1) -> %d1 */'
480 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
481 "comment" => "construct Conv: Conv(a) = (conv)a"
487 "comment" => "construct Cmp: Cmp(a, b) = a CMP b",
488 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "flag_register" ] },
489 "emit" => '. cmpl %s2, %s1\t\t\t/* Cmp(%s1, %s2) -> flags */'
494 "comment" => "construct Cmp: Cmp(a, const) = Cmp(const, a) = a CMP const",
495 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "flag_register" ] },
496 "emit" => '. cmpl %c, %s1\t\t\t/* Cmp(%s1, %c) -> flags */'
501 "comment" => "construct Cond: evaluate Cmp node",
502 "reg_req" => { "in" => [ "flag_register" ] }
508 "comment" => "represents an integer constant",
509 "reg_req" => { "out" => [ "general_purpose" ] }
515 "comment" => "construct Cltd: sign extend EAX -> EDX:EAX",
516 "reg_req" => { "in" => [ "eax" ], "out" => [ "eax", "edx" ] },
517 "emit" => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX */'
525 "comment" => "construct Load: Load(mem-edge, ptr) = LD ptr",
526 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
527 "emit" => '. movl (%s1), %d1\t\t\t/* Load((%s1)) -> %d1 */'
533 "comment" => "construct Store: Store(mem-edge, ptr, val) = ST ptr,val",
534 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
535 "emit" => '. movl %s1, (%d1)\t\t\t/* Store(%s1) -> (%d1) */'
540 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
541 "reg_req" => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
542 "emit" => '. leal %o(%s1, %s2, %c), %d1\t\t\t/* %d1 = %s1 + %s2 << %c + %o */'
547 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
548 "reg_req" => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
549 "emit" => '. leal %c(%s1), %d1\t\t\t/* %d1 = %s1 + %c */'
557 "comment" => "construct Call: Call(...)",
558 "args" => [ { "type" => "ir_node *", "name" => "old_call" } ],
564 if (!op_ia32_Call) assert(0);
566 in[0] = get_Call_mem(old_call);
568 res = new_ir_node(db, irg, block, op_ia32_Call, mode_T, 1, in);
569 res = optimize_node(res);
570 irn_vrfy_irg(res, irg);
572 attr = (asmop_attr *)get_irn_generic_attr(res);
573 attr->data.old_ir = old_call;