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
75 #--------------------------------------------------#
78 # _ __ _____ __ _ _ __ ___ _ __ ___ #
79 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
80 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
81 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
84 #--------------------------------------------------#
88 # arithmetic operations
90 # commutative operations
95 "comment" => "construct Add: Add(a, b) = Add(b, a) = a + b",
96 "emit" => '. addl %s2, %d1\t\t\t/* Add(%s1, %s2) -> %d1 */'
101 "comment" => "construct Add: Add(a, const) = Add(const, a) = a + const",
102 "emit" => '. addl %c, %d1\t\t\t/* Add(%c, %s1) -> %d1 */'
108 "comment" => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
110 ' if (mode_is_signed(get_irn_mode(n))) {
111 4. imull %s2\t\t\t/* signed Mul(%s1, %s2) -> %d1 */
114 4. mull %s2\t\t\t/* unsigned Mul(%s1, %s2) -> %d1 */
122 "comment" => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
124 ' if (mode_is_signed(get_irn_mode(n))) {
125 4. imull %c\t\t\t/* signed Mul(%c, %s1) -> %d1 */
128 4. mull %c\t\t\t/* unsigned Mul(%c, %s1) -> %d1 */
136 "comment" => "construct Mulh: Mulh(a, b) = Mulh(b, a) = get_32_highest_bits(a * b)",
138 ' if (mode_is_signed(get_irn_mode(n))) {
139 4. imull %s2\t\t\t/* signed Mulh(%s1, %s2) -> %d1 */
142 4. mull %s2\t\t\t/* unsigned Mulh(%s1, %s2) -> %d1 */
150 "comment" => "construct Mulh: Mulh(a, const) = Mulh(const, a) = get_32_highest_bits(a * const)",
152 ' if (mode_is_signed(get_irn_mode(n))) {
153 4. imull %c\t\t\t/* signed Mulh(%c, %s1) -> %d1 */
156 4. mull %c\t\t\t/* unsigned Mulh(%c, %s1) -> %d1 */
164 "comment" => "construct And: And(a, b) = And(b, a) = a AND b",
165 "emit" => '. andl %s2, %d1\t\t\t/* And(%s1, %s2) -> %d1 */'
170 "comment" => "construct And: And(a, const) = And(const, a) = a AND const",
171 "emit" => '. andl %c, %d1\t\t\t/* And(%c, %s1) -> %d1 */'
177 "comment" => "construct Or: Or(a, b) = Or(b, a) = a OR b",
178 "emit" => '. orl %s2, %d1\t\t\t/* Or(%s1, %s2) -> %d1 */'
183 "comment" => "construct Or: Or(a, const) = Or(const, a) = a OR const",
184 "emit" => '. orl %c, %d1\t\t\t/* Or(%c, %s1) -> %d1 */'
190 "comment" => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
191 "emit" => '. xorl %s2, %d1\t\t\t/* Xor(%s1, %s2) -> %d1 */'
196 "comment" => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
197 "emit" => '. xorl %c, %d1\t\t\t/* Xor(%c, %s1) -> %d1 */'
203 "comment" => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
205 '2. cmpl %s2, %s1\t\t\t/* prepare Max */
206 if (mode_is_signed(get_irn_mode(n))) {
207 2. cmovg %s1, %d1\t\t\t/* Max(%s1, %s2) -> %d1 */
210 2. cmova %s1, %d1\t\t\t/* Max(%s1, %s2) -> %d1 */
218 "comment" => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
220 '2. cmpl %s2, %s1\t\t\t/* prepare Min (%s1 - %s2) */
221 if (mode_is_signed(get_irn_mode(n))) {
222 2. cmovl %s1, %d1\t\t\t/* Min(%s1, %s2) -> %d1 */
225 2. cmovb %s1, %d1\t\t\t/* Min(%s1, %s2) -> %d1 */
230 # not commutative operations
234 "comment" => "construct Sub: Sub(a, b) = a - b",
235 "emit" => '. subl %s2, %s1\t\t\t/* Sub(%s1, %s2) -> %d1 */'
240 "comment" => "construct Sub: Sub(a, const) = a - const",
241 "emit" => '. subl %c, %s1\t\t\t/* Sub(%s1, %c) -> %d1 */'
246 "comment" => "construct Mod: Mod(a, b) = a % b",
248 ' if (mode_is_signed(get_irn_mode(n))) {
249 4. cltd\t\t\t/* sign extend EAX -> EDX:EAX */\n
250 4. idivl %s2\t\t\t/* signed Mod(%s1, %s2) -> %d1 */
253 4. xorl edx, edx\t\t\t/* EDX = 0 */
254 4. divl %s2\t\t\t/* unsigned Mod(%s1, %s2) -> %d1 */
261 "comment" => "construct DivMod: DivMod(a,b) = (a / b, a % b)",
263 ' if (mode_is_signed(get_irn_mode(n))) {
264 4. cltd\t\t\t/* sign extend EAX -> EDX:EAX */\n
265 4. idivl %s2\t\t\t/* signed DivMod(%s1, %s2) -> (%d1:%d2) (Div, Mod) */
268 4. xorl edx, edx\t\t\t/* EDX = 0 */
269 4. divl %s2\t\t\t/* unsigned DivMod(%s1, %s2) -> (%d1:%d2) (Div, Mod) */
276 "comment" => "construct Div: Div(a, b) = a / b",
278 ' if (mode_is_signed(get_irn_mode(n))) {
279 4. cltd\t\t\t/* sign extend EAX -> EDX:EAX */\n
280 4. idivl %s2\t\t\t/* signed Div(%s1, %s2) -> %d1 */
283 4. xorl edx, edx\t\t\t/* EDX = 0 */
284 4. divl %s2\t\t\t/* unsigned Div(%s1, %s2) -> %d1 */
291 "comment" => "construct Shl: Shl(a, b) = a << b",
292 "emit" => '. shll %s2, %d1\t\t\t/* Shl(%s1, %s2) -> %d1 */'
297 "comment" => "construct Shl: Shl(a, const) = a << const",
298 "emit" => '. shll %c, %d1\t\t\t/* Shl(%s1, %c) -> %d1 */'
303 "comment" => "construct Shr: Shr(a, b) = a >> b",
304 "emit" => '. shrl %s2, %d1\t\t\t/* Shr(%s1, %s2) -> %d1 */'
309 "comment" => "construct Shr: Shr(a, const) = a >> const",
310 "emit" => '. shrl %c, %d1\t\t\t/* Shr(%s1, %c) -> %d1 */'
315 "comment" => "construct Shrs: Shrs(a, b) = a >> b",
316 "emit" => '. sarl %s2, %d1\t\t\t/* Shrs(%s1, %s2) -> %d1 */'
321 "comment" => "construct Shrs: Shrs(a, const) = a >> const",
322 "emit" => '. sarl %c, %d1\t\t\t/* Shrs(%s1, %c) -> %d1 */'
327 "comment" => "construct RotR: RotR(a, b) = a ROTR b",
328 "emit" => '. rorl %s2, %d1\t\t\t/* RotR(%s1, %s2) -> %d1 */'
333 "comment" => "construct RotR: RotR(a, const) = a ROTR const",
334 "emit" => '. rorl %c, %d1\t\t\t/* RotR(%s1, %c) -> %d1 */'
339 "comment" => "construct RotL: RotL(a, b) = a ROTL b",
340 "emit" => '. roll %s2, %d1\t\t\t/* RotL(%s1, %s2) -> %d1 */'
345 "comment" => "construct RotL: RotL(a, const) = a ROTL const",
346 "emit" => '. roll %c, %d1\t\t\t/* RotL(%s1, %c) -> %d1 */'
351 "comment" => "construct Minus: Minus(a) = -a",
352 "emit" => '. negl %d1\t\t\t/* Neg(%s1) -> %d1 */'
357 "comment" => "construct Increment: Inc(a) = a++",
358 "emit" => '. incl %d1\t\t\t/* Inc(%s1) -> %d1 */'
363 "comment" => "construct Decrement: Dec(a) = a--",
364 "emit" => '. decl %d1\t\t\t/* Dec(%s1) -> %d1 */'
369 "comment" => "construct Abs: Abs(a) = |a|",
371 '2. cdq\t\t\t/* Abs: EAX->EDX:EAX */
372 2. xorl %%edx, %%eax\t\t\t/* Abs: one-completent */
373 2. subl %%edx, %%eax\t\t\t/* Abs: two-complement */
379 "comment" => "construct Not: Not(a) = !a",
380 "emit" => '. notl %d1\t\t\t/* Not(%s1) -> %d1 */'
387 "comment" => "construct Conv: Conv(a) = (conv)a"
393 "comment" => "construct Cmp: Cmp(a, b) = a CMP b",
394 "emit" => '. cmpl %s2, %s1\t\t\t/* Cmp(%s1, %s2) -> flags */'
399 "comment" => "construct Cmp: Cmp(a, const) = Cmp(const, a) = a CMP const",
400 "emit" => '. cmpl %c, %s1\t\t\t/* Cmp(%s1, %c) -> flags */'
407 "comment" => "construct Load: Load(mem-edge, ptr) = LD ptr",
408 "emit" => '. movl (%s1), %d1\t\t\t/* Load((%s1)) -> %d1 */'
413 "comment" => "construct Store: Store(mem-edge, ptr, val) = ST ptr,val",
414 "emit" => '. movl %s1, (%d1)\t\t\t/* Store(%s1) -> (%d1) */'
419 "comment" => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
420 "emit" => '. leal %o(%s1, %s2, %c), %d1\t\t\t/* %d1 = %s1 + %s2 << %c + %o */'
425 "comment" => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
426 "emit" => '. leal %c(%s1), %d1\t\t\t/* %d1 = %s1 + %c */'
433 "comment" => "construct Call: Call(...)",
434 "args" => [ { "type" => "ir_node *", "name" => "old_call" } ],
440 if (!op_ia32_Call) assert(0);
442 in[0] = get_Call_mem(old_call);
444 res = new_ir_node(db, irg, block, op_ia32_Call, mode_T, 1, in);
445 res = optimize_node(res);
446 irn_vrfy_irg(res, irg);
448 attr = (asmop_attr *)get_irn_generic_attr(res);
449 attr->data.old_ir = old_call;