3 # This is the specification for the ia32 assembler Firm-operations
10 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
13 # The node description is done as a perl hash initializer with the
14 # following structure:
19 # op_flags => "N|L|C|X|I|F|Y|H|c|K",
20 # irn_flags => "R|N|I|S"
21 # arity => "0|1|2|3 ... |variable|dynamic|any",
22 # state => "floats|pinned|mem_pinned|exc_pinned",
24 # { type => "type 1", name => "name 1" },
25 # { type => "type 2", name => "name 2" },
28 # comment => "any comment for constructor",
29 # reg_req => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
30 # cmp_attr => "c source code for comparing node attributes",
31 # emit => "emit code with templates",
32 # attr => "attitional attribute arguments for constructor"
33 # init_attr => "emit attribute initialization template"
34 # rd_constructor => "c source code which constructs an ir_node"
35 # latency => "latency of this operation (can be float)"
38 # ... # (all nodes you need to describe)
40 # ); # close the %nodes initializer
42 # op_flags: flags for the operation, OPTIONAL (default is "N")
43 # the op_flags correspond to the firm irop_flags:
46 # C irop_flag_commutative
47 # X irop_flag_cfopcode
48 # I irop_flag_ip_cfopcode
51 # H irop_flag_highlevel
52 # c irop_flag_constlike
55 # irn_flags: special node flags, OPTIONAL (default is 0)
56 # following irn_flags are supported:
59 # I ignore for register allocation
60 # S modifies stack pointer
62 # state: state of the operation, OPTIONAL (default is "floats")
64 # arity: arity of the operation, MUST NOT BE OMITTED
66 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
67 # are always the first 3 arguments and are always autmatically
69 # If this key is missing the following arguments will be created:
70 # for i = 1 .. arity: ir_node *op_i
73 # outs: if a node defines more than one output, the names of the projections
74 # nodes having outs having automatically the mode mode_T
75 # One can also annotate some flags for each out, additional to irn_flags.
76 # They are separated from name with a colon ':', and concatenated by pipe '|'
77 # Only I and S are available at the moment (same meaning as in irn_flags).
78 # example: [ "frame:I", "stack:I|S", "M" ]
80 # comment: OPTIONAL comment for the node constructor
82 # rd_constructor: for every operation there will be a
83 # new_rd_<arch>_<op-name> function with the arguments from above
84 # which creates the ir_node corresponding to the defined operation
85 # you can either put the complete source code of this function here
87 # This key is OPTIONAL. If omitted, the following constructor will
89 # if (!op_<arch>_<op-name>) assert(0);
93 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
96 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
98 # latency: the latency of the operation, default is 1
102 # 0 - no special type
103 # 1 - caller save (register must be saved by the caller of a function)
104 # 2 - callee save (register must be saved by the called function)
105 # 4 - ignore (do not assign this register)
106 # 8 - emitter can choose an arbitrary register of this class
107 # 16 - the register is a virtual one
108 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
111 { name => "eax", type => 1 },
112 { name => "edx", type => 1 },
113 { name => "ebx", type => 2 },
114 { name => "ecx", type => 1 },
115 { name => "esi", type => 2 },
116 { name => "edi", type => 2 },
117 { name => "ebp", type => 2 },
118 { name => "esp", type => 4 },
119 { name => "gp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
120 { name => "gp_UKNWN", type => 4 | 8 | 16 }, # we need a dummy register for Unknown nodes
121 { mode => "mode_Iu" }
124 { name => "xmm0", type => 1 },
125 { name => "xmm1", type => 1 },
126 { name => "xmm2", type => 1 },
127 { name => "xmm3", type => 1 },
128 { name => "xmm4", type => 1 },
129 { name => "xmm5", type => 1 },
130 { name => "xmm6", type => 1 },
131 { name => "xmm7", type => 1 },
132 { name => "xmm_NOREG", type => 4 | 16 }, # we need a dummy register for NoReg nodes
133 { name => "xmm_UKNWN", type => 4 | 8 | 16}, # we need a dummy register for Unknown nodes
137 { name => "vf0", type => 1 | 16 },
138 { name => "vf1", type => 1 | 16 },
139 { name => "vf2", type => 1 | 16 },
140 { name => "vf3", type => 1 | 16 },
141 { name => "vf4", type => 1 | 16 },
142 { name => "vf5", type => 1 | 16 },
143 { name => "vf6", type => 1 | 16 },
144 { name => "vf7", type => 1 | 16 },
145 { name => "vfp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
146 { name => "vfp_UKNWN", type => 4 | 8 | 16 }, # we need a dummy register for Unknown nodes
150 { name => "st0", type => 1 },
151 { name => "st1", type => 1 },
152 { name => "st2", type => 1 },
153 { name => "st3", type => 1 },
154 { name => "st4", type => 1 },
155 { name => "st5", type => 1 },
156 { name => "st6", type => 1 },
157 { name => "st7", type => 1 },
160 fp_cw => [ # the floating point control word
161 { name => "fpcw", type => 0 },
162 { mode => "mode_Hu" },
168 GP => [ 1, "GP_EAX", "GP_EBX", "GP_ECX", "GP_EDX", "GP_ESI", "GP_EDI", "GP_EBP" ],
169 SSE => [ 1, "SSE_XMM0", "SSE_XMM1", "SSE_XMM2", "SSE_XMM3", "SSE_XMM4", "SSE_XMM5", "SSE_XMM6", "SSE_XMM7" ],
170 VFP => [ 1, "VFP_VF0", "VFP_VF1", "VFP_VF2", "VFP_VF3", "VFP_VF4", "VFP_VF5", "VFP_VF6", "VFP_VF7" ],
171 BRANCH => [ 1, "BRANCH1", "BRANCH2" ],
176 bundels_per_cycle => 1
180 S1 => "${arch}_emit_source_register(env, node, 0);",
181 S2 => "${arch}_emit_source_register(env, node, 1);",
182 S3 => "${arch}_emit_source_register(env, node, 2);",
183 S4 => "${arch}_emit_source_register(env, node, 3);",
184 S5 => "${arch}_emit_source_register(env, node, 4);",
185 S6 => "${arch}_emit_source_register(env, node, 5);",
186 D1 => "${arch}_emit_dest_register(env, node, 0);",
187 D2 => "${arch}_emit_dest_register(env, node, 1);",
188 D3 => "${arch}_emit_dest_register(env, node, 2);",
189 D4 => "${arch}_emit_dest_register(env, node, 3);",
190 D5 => "${arch}_emit_dest_register(env, node, 4);",
191 D6 => "${arch}_emit_dest_register(env, node, 5);",
192 A1 => "${arch}_emit_in_node_name(env, node, 0);",
193 A2 => "${arch}_emit_in_node_name(env, node, 1);",
194 A3 => "${arch}_emit_in_node_name(env, node, 2);",
195 A4 => "${arch}_emit_in_node_name(env, node, 3);",
196 A5 => "${arch}_emit_in_node_name(env, node, 4);",
197 A6 => "${arch}_emit_in_node_name(env, node, 5);",
198 X1 => "${arch}_emit_x87_name(env, node, 0);",
199 X2 => "${arch}_emit_x87_name(env, node, 1);",
200 X3 => "${arch}_emit_x87_name(env, node, 2);",
201 C => "${arch}_emit_immediate(env, node);",
202 SE => "${arch}_emit_extend_suffix(env, get_ia32_ls_mode(node));",
203 ME => "if(get_mode_size_bits(get_ia32_ls_mode(node)) != 32)\n
204 ia32_emit_mode_suffix(env, get_ia32_ls_mode(node));",
205 M => "${arch}_emit_mode_suffix(env, get_ia32_ls_mode(node));",
206 XM => "${arch}_emit_x87_mode_suffix(env, node);",
207 XXM => "${arch}_emit_xmm_mode_suffix(env, node);",
208 XSD => "${arch}_emit_xmm_mode_suffix_s(env, node);",
209 AM => "${arch}_emit_am(env, node);",
210 unop => "${arch}_emit_unop(env, node);",
211 binop => "${arch}_emit_binop(env, node);",
212 x87_binop => "${arch}_emit_x87_binop(env, node);",
215 #--------------------------------------------------#
218 # _ __ _____ __ _ _ __ ___ _ __ ___ #
219 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
220 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
221 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
224 #--------------------------------------------------#
226 $default_cmp_attr = "return ia32_compare_attr(attr_a, attr_b);";
233 #-----------------------------------------------------------------#
236 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
237 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
238 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
239 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
242 #-----------------------------------------------------------------#
244 # commutative operations
247 # All nodes supporting Addressmode have 5 INs:
248 # 1 - base r1 == NoReg in case of no AM or no base
249 # 2 - index r2 == NoReg in case of no AM or no index
250 # 3 - op1 r3 == always present
251 # 4 - op2 r4 == NoReg in case of immediate operation
252 # 5 - mem NoMem in case of no AM otherwise it takes the mem from the Load
256 comment => "construct Add: Add(a, b) = Add(b, a) = a + b",
257 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
258 emit => '. addl %binop',
264 comment => "construct Add with Carry: Adc(a, b) = Add(b, a) = a + b + carry",
265 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
266 emit => '. adcl %binop',
273 comment => "construct 64Bit Add: Add(a_l, a_h, b_l, b_h) = a_l + b_l; a_h + b_h + carry",
275 reg_req => { in => [ "gp", "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
282 outs => [ "low_res", "high_res" ],
289 cmp_attr => "return 1;",
290 comment => "construct lowered Add: Add(a, b) = Add(b, a) = a + b",
296 cmp_attr => "return 1;",
297 comment => "construct lowered Add with Carry: Adc(a, b) = Adc(b, a) = a + b + carry",
302 # we should not rematrialize this node. It produces 2 results and has
303 # very strict constrains
304 comment => "construct MulS: MulS(a, b) = MulS(b, a) = a * b",
305 reg_req => { in => [ "gp", "gp", "eax", "gp", "none" ], out => [ "eax", "edx", "none" ] },
306 emit => '. mull %unop',
307 outs => [ "EAX", "EDX", "M" ],
313 # we should not rematrialize this node. It produces 2 results and has
314 # very strict constrains
316 cmp_attr => "return 1;",
317 comment => "construct lowered MulS: Mul(a, b) = Mul(b, a) = a * b",
318 outs => [ "EAX", "EDX", "M" ],
324 comment => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
325 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
326 emit => '. imull %binop',
334 comment => "construct Mul (1 operand format): Mul(a, b) = Mul(b, a) = a * b",
335 reg_req => { in => [ "gp", "gp", "eax", "gp", "none" ], out => [ "eax", "edx", "none" ] },
336 emit => '. imull %unop',
337 outs => [ "EAX", "EDX", "M" ],
344 cmp_attr => "return 1;",
345 comment => "construct lowered IMul: IMul(a, b) = IMul(b, a) = a * b",
351 comment => "construct And: And(a, b) = And(b, a) = a AND b",
352 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
353 emit => '. andl %binop',
360 comment => "construct Or: Or(a, b) = Or(b, a) = a OR b",
361 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
362 emit => '. orl %binop',
369 comment => "construct Xor: Xor(a, b) = Xor(b, a) = a EOR b",
370 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
371 emit => '. xorl %binop',
378 cmp_attr => "return 1;",
379 comment => "construct lowered Xor: Xor(a, b) = Xor(b, a) = a XOR b",
383 # not commutative operations
387 comment => "construct Sub: Sub(a, b) = a - b",
388 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
389 emit => '. subl %binop',
395 comment => "construct Sub with Carry: SubC(a, b) = a - b - carry",
396 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3 !in_r4" ] },
397 emit => '. sbbl %binop',
404 comment => "construct 64Bit Sub: Sub(a_l, a_h, b_l, b_h) = a_l - b_l; a_h - b_h - borrow",
406 reg_req => { in => [ "gp", "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
413 outs => [ "low_res", "high_res" ],
419 cmp_attr => "return 1;",
420 comment => "construct lowered Sub: Sub(a, b) = a - b",
425 cmp_attr => "return 1;",
426 comment => "construct lowered Sub with Carry: SubC(a, b) = a - b - carry",
432 state => "exc_pinned",
433 reg_req => { in => [ "gp", "gp", "eax", "edx", "gp", "none" ], out => [ "eax", "edx", "none" ] },
434 attr => "ia32_op_flavour_t dm_flav",
435 init_attr => "attr->data.op_flav = dm_flav;",
436 emit => ". idivl %unop",
437 outs => [ "div_res", "mod_res", "M" ],
444 state => "exc_pinned",
445 reg_req => { in => [ "gp", "gp", "eax", "edx", "gp", "none" ], out => [ "eax", "edx", "none" ] },
446 attr => "ia32_op_flavour_t dm_flav",
447 init_attr => "attr->data.op_flav = dm_flav;",
448 emit => ". divl %unop",
449 outs => [ "div_res", "mod_res", "M" ],
456 comment => "construct Shl: Shl(a, b) = a << b",
457 reg_req => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
458 emit => '. shll %binop',
464 cmp_attr => "return 1;",
465 comment => "construct lowered Shl: Shl(a, b) = a << b",
471 comment => "construct ShlD: ShlD(a, b, c) = a, b << count (shift left count bits from b into a)",
472 # Out requirements is: different from all in
473 # This is because, out must be different from LowPart and ShiftCount.
474 # We could say "!ecx !in_r4" but it can occur, that all values live through
475 # this Shift and the only value dying is the ShiftCount. Then there would be a
476 # register missing, as result must not be ecx and all other registers are
477 # occupied. What we should write is "!in_r4 !in_r5", but this is not supported
478 # (and probably never will). So we create artificial interferences of the result
479 # with all inputs, so the spiller can always assure a free register.
480 reg_req => { in => [ "gp", "gp", "gp", "gp", "ecx", "none" ], out => [ "!in" ] },
483 if (get_ia32_immop_type(node) == ia32_ImmNone) {
484 if (get_ia32_op_type(node) == ia32_AddrModeD) {
485 . shldl %%cl, %S4, %AM
487 . shldl %%cl, %S4, %S3
490 if (get_ia32_op_type(node) == ia32_AddrModeD) {
491 . shldl $%C, %S4, %AM
493 . shldl $%C, %S4, %S3
503 cmp_attr => "return 1;",
504 comment => "construct lowered ShlD: ShlD(a, b, c) = a, b << count (shift left count bits from b into a)",
510 comment => "construct Shr: Shr(a, b) = a >> b",
511 reg_req => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
512 emit => '. shrl %binop',
518 cmp_attr => "return 1;",
519 comment => "construct lowered Shr: Shr(a, b) = a << b",
525 comment => "construct ShrD: ShrD(a, b, c) = a, b >> count (shift rigth count bits from a into b)",
526 # Out requirements is: different from all in
527 # This is because, out must be different from LowPart and ShiftCount.
528 # We could say "!ecx !in_r4" but it can occur, that all values live through
529 # this Shift and the only value dying is the ShiftCount. Then there would be a
530 # register missing, as result must not be ecx and all other registers are
531 # occupied. What we should write is "!in_r4 !in_r5", but this is not supported
532 # (and probably never will). So we create artificial interferences of the result
533 # with all inputs, so the spiller can always assure a free register.
534 reg_req => { in => [ "gp", "gp", "gp", "gp", "ecx", "none" ], out => [ "!in" ] },
536 if (get_ia32_immop_type(node) == ia32_ImmNone) {
537 if (get_ia32_op_type(node) == ia32_AddrModeD) {
538 . shrdl %%cl, %S4, %AM
540 . shrdl %%cl, %S4, %S3
543 if (get_ia32_op_type(node) == ia32_AddrModeD) {
544 . shrdl $%C, %S4, %AM
546 . shrdl $%C, %S4, %S3
556 cmp_attr => "return 1;",
557 comment => "construct lowered ShrD: ShrD(a, b, c) = a, b >> count (shift rigth count bits from a into b)",
563 comment => "construct Shrs: Shrs(a, b) = a >> b",
564 reg_req => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
565 emit => '. sarl %binop',
571 cmp_attr => "return 1;",
572 comment => "construct lowered Sar: Sar(a, b) = a << b",
578 comment => "construct Ror: Ror(a, b) = a ROR b",
579 reg_req => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
580 emit => '. rorl %binop',
587 comment => "construct Rol: Rol(a, b) = a ROL b",
588 reg_req => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
589 emit => '. roll %binop',
598 comment => "construct Minus: Minus(a) = -a",
599 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
600 emit => '. negl %unop',
607 comment => "construct 64Bit Minus: Minus(a_l, a_h, 0) = 0 - a_l; 0 - a_h - borrow",
609 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
616 outs => [ "low_res", "high_res" ],
622 cmp_attr => "return 1;",
623 comment => "construct lowered Minus: Minus(a) = -a",
629 comment => "construct Increment: Inc(a) = a++",
630 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
631 emit => '. incl %unop',
638 comment => "construct Decrement: Dec(a) = a--",
639 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
640 emit => '. decl %unop',
647 comment => "construct Not: Not(a) = !a",
648 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
649 emit => '. notl %unop',
659 comment => "construct conditional jump: CMP A, B && JMPxx LABEL",
660 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ] },
661 outs => [ "false", "true" ],
663 units => [ "BRANCH" ],
669 comment => "construct conditional jump: TEST A, B && JMPxx LABEL",
670 reg_req => { in => [ "gp", "gp" ] },
671 outs => [ "false", "true" ],
673 units => [ "BRANCH" ],
679 comment => "construct conditional jump without CMP (replaces CondJmp): JMPxx LABEL",
680 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "none", "none" ] },
681 outs => [ "false", "true" ],
682 units => [ "BRANCH" ],
688 comment => "construct conditional jump without CMP (replaces TestJmp): JMPxx LABEL",
689 reg_req => { in => [ "gp", "gp" ] },
690 units => [ "BRANCH" ],
696 comment => "construct switch",
697 reg_req => { in => [ "gp" ], out => [ "none" ] },
699 units => [ "BRANCH" ],
705 comment => "represents an integer constant",
706 reg_req => { out => [ "gp" ] },
714 comment => "unknown value",
715 reg_req => { out => [ "gp_UKNWN" ] },
724 comment => "unknown value",
725 reg_req => { out => [ "vfp_UKNWN" ] },
734 comment => "unknown value",
735 reg_req => { out => [ "xmm_UKNWN" ] },
744 comment => "unknown GP value",
745 reg_req => { out => [ "gp_NOREG" ] },
754 comment => "unknown VFP value",
755 reg_req => { out => [ "vfp_NOREG" ] },
764 comment => "unknown XMM value",
765 reg_req => { out => [ "xmm_NOREG" ] },
773 comment => "change floating point control word",
774 reg_req => { out => [ "fp_cw" ] },
782 state => "exc_pinned",
783 comment => "load floating point control word FldCW(ptr, mem) = LD ptr -> reg",
784 reg_req => { in => [ "gp", "gp", "none" ], out => [ "fp_cw" ] },
786 emit => ". fldcw %AM",
793 state => "exc_pinned",
794 comment => "store floating point control word: FstCW(ptr, mem) = ST ptr -> reg",
795 reg_req => { in => [ "gp", "gp", "fp_cw", "none" ] },
797 emit => ". fstcw %AM",
803 # we should not rematrialize this node. It produces 2 results and has
804 # very strict constrains
805 comment => "construct CDQ: sign extend EAX -> EDX:EAX",
806 reg_req => { in => [ "gp" ], out => [ "eax in_r1", "edx" ] },
808 outs => [ "EAX", "EDX" ],
816 state => "exc_pinned",
817 comment => "construct Load: Load(ptr, mem) = LD ptr -> reg",
818 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
820 emit => ". mov%SE%ME%.l %AM, %D1",
821 outs => [ "res", "M" ],
827 cmp_attr => "return 1;",
828 comment => "construct lowered Load: Load(ptr, mem) = LD ptr -> reg",
829 outs => [ "res", "M" ],
835 cmp_attr => "return 1;",
836 state => "exc_pinned",
837 comment => "construct lowered Store: Store(ptr, val, mem) = ST ptr,val",
844 state => "exc_pinned",
845 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
846 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
847 emit => '. mov%M %binop',
855 state => "exc_pinned",
856 comment => "construct 8Bit Store: Store(ptr, val, mem) = ST ptr,val",
857 reg_req => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => ["none" ] },
858 emit => '. mov%M %binop',
866 comment => "construct Lea: Lea(a,b) = lea [a+b*const+offs] | res = a + b * const + offs with const = 0,1,2,4,8",
867 reg_req => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
868 emit => '. leal %AM, %D1',
875 comment => "push on the stack",
876 reg_req => { in => [ "gp", "gp", "gp", "esp", "none" ], out => [ "esp", "none" ] },
877 emit => '. pushl %unop',
878 outs => [ "stack:I|S", "M" ],
884 comment => "pop a gp register from the stack",
885 reg_req => { in => [ "gp", "gp", "esp", "none" ], out => [ "esp", "gp", "none" ] },
886 emit => '. popl %unop',
887 outs => [ "stack:I|S", "res", "M" ],
893 comment => "create stack frame",
894 reg_req => { in => [ "esp" ], out => [ "ebp", "esp" ] },
896 outs => [ "frame:I", "stack:I|S", "M" ],
902 comment => "destroy stack frame",
903 reg_req => { in => [ "esp", "ebp" ], out => [ "ebp", "esp" ] },
905 outs => [ "frame:I", "stack:I|S" ],
912 comment => "allocate space on stack",
913 reg_req => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
914 emit => '. addl %binop',
915 outs => [ "stack:S", "M" ],
921 comment => "free space on stack",
922 reg_req => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
923 emit => '. subl %binop',
924 outs => [ "stack:S", "M" ],
930 comment => "get the TLS base address",
931 reg_req => { out => [ "gp" ] },
937 #-----------------------------------------------------------------------------#
938 # _____ _____ ______ __ _ _ _ #
939 # / ____/ ____| ____| / _| | | | | | #
940 # | (___| (___ | |__ | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
941 # \___ \\___ \| __| | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
942 # ____) |___) | |____ | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
943 # |_____/_____/|______| |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
944 #-----------------------------------------------------------------------------#
946 # commutative operations
950 comment => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
951 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
952 emit => '. add%XXM %binop',
960 comment => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
961 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
962 emit => '. mul%XXM %binop',
970 comment => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
971 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
972 emit => '. max%XXM %binop',
980 comment => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
981 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
982 emit => '. min%XXM %binop',
990 comment => "construct SSE And: And(a, b) = a AND b",
991 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
992 emit => '. andp%XSD %binop',
1000 comment => "construct SSE Or: Or(a, b) = a OR b",
1001 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1002 emit => '. orp%XSD %binop',
1009 comment => "construct SSE Xor: Xor(a, b) = a XOR b",
1010 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1011 emit => '. xorp%XSD %binop',
1017 # not commutative operations
1021 comment => "construct SSE AndNot: AndNot(a, b) = a AND NOT b",
1022 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1023 emit => '. andnp%XSD %binop',
1031 comment => "construct SSE Sub: Sub(a, b) = a - b",
1032 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1033 emit => '. sub%XXM %binop',
1041 comment => "construct SSE Div: Div(a, b) = a / b",
1042 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1043 outs => [ "res", "M" ],
1044 emit => '. div%XXM %binop',
1053 comment => "construct SSE Compare: Cmp(a, b) == a = a cmp b",
1054 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1062 op_flags => "L|X|Y",
1063 comment => "construct conditional jump: UCOMIS A, B && JMPxx LABEL",
1064 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "none", "none" ] },
1065 outs => [ "false", "true" ],
1073 comment => "represents a SSE constant",
1074 reg_req => { out => [ "xmm" ] },
1075 emit => '. mov%XXM $%C, %D1',
1085 state => "exc_pinned",
1086 comment => "construct SSE Load: Load(ptr, mem) = LD ptr",
1087 reg_req => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1088 emit => '. mov%XXM %AM, %D1',
1089 outs => [ "res", "M" ],
1096 state => "exc_pinned",
1097 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
1098 reg_req => { in => [ "gp", "gp", "xmm", "none" ] },
1099 emit => '. mov%XXM %binop',
1107 state => "exc_pinned",
1108 comment => "construct Store without index: Store(ptr, val, mem) = ST ptr,val",
1109 reg_req => { in => [ "gp", "xmm", "none" ] },
1110 emit => '. mov%XXM %S2, %AM',
1118 comment => "construct: transfer a value from x87 FPU into a SSE register",
1119 cmp_attr => "return 1;",
1125 comment => "construct: transfer a value from SSE register to x87 FPU",
1126 cmp_attr => "return 1;",
1133 state => "exc_pinned",
1134 comment => "store ST0 onto stack",
1135 reg_req => { in => [ "gp", "gp", "none" ] },
1136 emit => '. fstp%XM %AM',
1145 state => "exc_pinned",
1146 comment => "load ST0 from stack",
1147 reg_req => { in => [ "gp", "none" ], out => [ "vf0", "none" ] },
1148 emit => '. fld%M %AM',
1149 outs => [ "res", "M" ],
1159 comment => "implements a memcopy: CopyB(dst, src, size, mem) == memcpy(dst, src, size)",
1160 reg_req => { in => [ "edi", "esi", "ecx", "none" ], out => [ "edi", "esi", "ecx", "none" ] },
1161 outs => [ "DST", "SRC", "CNT", "M" ],
1168 comment => "implements a memcopy: CopyB(dst, src, mem) == memcpy(dst, src, attr(size))",
1169 reg_req => { in => [ "edi", "esi", "none" ], out => [ "edi", "esi", "none" ] },
1170 outs => [ "DST", "SRC", "M" ],
1177 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3", "none" ] },
1178 comment => "construct Conv Int -> Int",
1184 reg_req => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => [ "in_r3", "none" ] },
1185 comment => "construct Conv Int -> Int",
1191 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1192 comment => "construct Conv Int -> Floating Point",
1199 reg_req => { in => [ "gp", "gp", "xmm", "none" ], out => [ "gp", "none" ] },
1200 comment => "construct Conv Floating Point -> Int",
1207 reg_req => { in => [ "gp", "gp", "xmm", "none" ], out => [ "xmm", "none" ] },
1208 comment => "construct Conv Floating Point -> Floating Point",
1216 comment => "construct Conditional Move: CMov(sel, a, b) == sel ? a : b",
1217 reg_req => { in => [ "gp", "gp", "gp", "gp" ], out => [ "in_r4" ] },
1225 comment => "check if Psi condition tree evaluates to true and move result accordingly",
1226 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "in_r3" ] },
1234 comment => "construct Conditional Move: SSE Compare + int CMov ",
1235 reg_req => { in => [ "xmm", "xmm", "gp", "gp" ], out => [ "in_r4" ] },
1243 comment => "construct Conditional Move: x87 Compare + int CMov",
1244 reg_req => { in => [ "vfp", "vfp", "gp", "gp" ], out => [ "in_r4" ] },
1252 comment => "construct Set: Set(sel) == sel ? 1 : 0",
1253 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "eax ebx ecx edx" ] },
1261 comment => "check if Psi condition tree evaluates to true and set result accordingly",
1262 reg_req => { in => [ "gp" ], out => [ "eax ebx ecx edx" ] },
1270 comment => "construct Set: SSE Compare + int Set",
1271 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "eax ebx ecx edx" ] },
1279 comment => "construct Set: x87 Compare + int Set",
1280 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "eax ebx ecx edx" ] },
1288 comment => "construct x87 Conditional Move: vfCMov(sel, a, b) = sel ? a : b",
1289 reg_req => { in => [ "vfp", "vfp", "vfp", "vfp" ], out => [ "vfp" ] },
1295 #----------------------------------------------------------#
1297 # (_) | | | | / _| | | | #
1298 # __ ___ _ __| |_ _ _ __ _| | | |_| | ___ __ _| |_ #
1299 # \ \ / / | '__| __| | | |/ _` | | | _| |/ _ \ / _` | __| #
1300 # \ V /| | | | |_| |_| | (_| | | | | | | (_) | (_| | |_ #
1301 # \_/ |_|_| \__|\__,_|\__,_|_| |_| |_|\___/ \__,_|\__| #
1303 # _ __ ___ __| | ___ ___ #
1304 # | '_ \ / _ \ / _` |/ _ \/ __| #
1305 # | | | | (_) | (_| | __/\__ \ #
1306 # |_| |_|\___/ \__,_|\___||___/ #
1307 #----------------------------------------------------------#
1311 comment => "virtual fp Add: Add(a, b) = Add(b, a) = a + b",
1312 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1320 comment => "virtual fp Mul: Mul(a, b) = Mul(b, a) = a * b",
1321 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1329 cmp_attr => "return 1;",
1330 comment => "lowered virtual fp Mul: Mul(a, b) = Mul(b, a) = a * b",
1336 comment => "virtual fp Sub: Sub(a, b) = a - b",
1337 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1344 cmp_attr => "return 1;",
1345 comment => "lowered virtual fp Sub: Sub(a, b) = a - b",
1350 comment => "virtual fp Div: Div(a, b) = a / b",
1351 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1352 outs => [ "res", "M" ],
1358 cmp_attr => "return 1;",
1359 comment => "lowered virtual fp Div: Div(a, b) = a / b",
1360 outs => [ "res", "M" ],
1365 comment => "virtual fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1366 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1373 cmp_attr => "return 1;",
1374 comment => "lowered virtual fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1380 comment => "virtual fp Abs: Abs(a) = |a|",
1381 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1389 comment => "virtual fp Chs: Chs(a) = -a",
1390 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1398 comment => "virtual fp Sin: Sin(a) = sin(a)",
1399 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1407 comment => "virtual fp Cos: Cos(a) = cos(a)",
1408 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1416 comment => "virtual fp Sqrt: Sqrt(a) = a ^ 0.5",
1417 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1423 # virtual Load and Store
1427 state => "exc_pinned",
1428 comment => "virtual fp Load: Load(ptr, mem) = LD ptr -> reg",
1429 reg_req => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1430 outs => [ "res", "M" ],
1437 state => "exc_pinned",
1438 comment => "virtual fp Store: Store(ptr, val, mem) = ST ptr,val",
1439 reg_req => { in => [ "gp", "gp", "vfp", "none" ] },
1448 comment => "virtual fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1449 reg_req => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1450 outs => [ "res", "M" ],
1456 cmp_attr => "return 1;",
1457 comment => "lowered virtual fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1458 outs => [ "res", "M" ],
1463 comment => "virtual fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1464 reg_req => { in => [ "gp", "gp", "vfp", "none" ] },
1471 cmp_attr => "return 1;",
1472 comment => "lowered virtual fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1482 comment => "virtual fp Load 0.0: Ld 0.0 -> reg",
1483 reg_req => { out => [ "vfp" ] },
1491 comment => "virtual fp Load 1.0: Ld 1.0 -> reg",
1492 reg_req => { out => [ "vfp" ] },
1500 comment => "virtual fp Load pi: Ld pi -> reg",
1501 reg_req => { out => [ "vfp" ] },
1509 comment => "virtual fp Load ln 2: Ld ln 2 -> reg",
1510 reg_req => { out => [ "vfp" ] },
1518 comment => "virtual fp Load lg 2: Ld lg 2 -> reg",
1519 reg_req => { out => [ "vfp" ] },
1527 comment => "virtual fp Load ld 10: Ld ld 10 -> reg",
1528 reg_req => { out => [ "vfp" ] },
1536 comment => "virtual fp Load ld e: Ld ld e -> reg",
1537 reg_req => { out => [ "vfp" ] },
1546 # init_attr => " set_ia32_ls_mode(res, mode);",
1547 comment => "represents a virtual floating point constant",
1548 reg_req => { out => [ "vfp" ] },
1558 op_flags => "L|X|Y",
1559 comment => "represents a virtual floating point compare",
1560 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "none", "none", "eax" ] },
1561 outs => [ "false", "true", "temp_reg_eax" ],
1566 #------------------------------------------------------------------------#
1567 # ___ _____ __ _ _ _ #
1568 # __ _( _ )___ | / _| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
1569 # \ \/ / _ \ / / | |_| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1570 # > < (_) |/ / | _| | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
1571 # /_/\_\___//_/ |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1572 #------------------------------------------------------------------------#
1574 # Note: gas is strangely buggy: fdivrp and fdivp as well as fsubrp and fsubp
1575 # are swapped, we work this around in the emitter...
1579 rd_constructor => "NONE",
1580 comment => "x87 Add: Add(a, b) = Add(b, a) = a + b",
1582 emit => '. fadd%XM %x87_binop',
1587 rd_constructor => "NONE",
1588 comment => "x87 Add: Add(a, b) = Add(b, a) = a + b",
1590 emit => '. faddp %x87_binop',
1595 rd_constructor => "NONE",
1596 comment => "x87 fp Mul: Mul(a, b) = Mul(b, a) = a + b",
1598 emit => '. fmul%XM %x87_binop',
1603 rd_constructor => "NONE",
1604 comment => "x87 fp Mul: Mul(a, b) = Mul(b, a) = a + b",
1606 emit => '. fmulp %x87_binop',,
1611 rd_constructor => "NONE",
1612 comment => "x87 fp Sub: Sub(a, b) = a - b",
1614 emit => '. fsub%XM %x87_binop',
1619 rd_constructor => "NONE",
1620 comment => "x87 fp Sub: Sub(a, b) = a - b",
1622 # see note about gas bugs
1623 emit => '. fsubrp %x87_binop',
1628 rd_constructor => "NONE",
1630 comment => "x87 fp SubR: SubR(a, b) = b - a",
1632 emit => '. fsubr%XM %x87_binop',
1637 rd_constructor => "NONE",
1639 comment => "x87 fp SubR: SubR(a, b) = b - a",
1641 # see note about gas bugs
1642 emit => '. fsubp %x87_binop',
1647 rd_constructor => "NONE",
1648 comment => "x87 fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1653 # this node is just here, to keep the simulator running
1654 # we can omit this when a fprem simulation function exists
1657 rd_constructor => "NONE",
1658 comment => "x87 fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1665 rd_constructor => "NONE",
1666 comment => "x87 fp Div: Div(a, b) = a / b",
1668 emit => '. fdiv%XM %x87_binop',
1673 rd_constructor => "NONE",
1674 comment => "x87 fp Div: Div(a, b) = a / b",
1676 # see note about gas bugs
1677 emit => '. fdivrp %x87_binop',
1682 rd_constructor => "NONE",
1683 comment => "x87 fp DivR: DivR(a, b) = b / a",
1685 emit => '. fdivr%XM %x87_binop',
1690 rd_constructor => "NONE",
1691 comment => "x87 fp DivR: DivR(a, b) = b / a",
1693 # see note about gas bugs
1694 emit => '. fdivp %x87_binop',
1699 rd_constructor => "NONE",
1700 comment => "x87 fp Abs: Abs(a) = |a|",
1707 rd_constructor => "NONE",
1708 comment => "x87 fp Chs: Chs(a) = -a",
1715 rd_constructor => "NONE",
1716 comment => "x87 fp Sin: Sin(a) = sin(a)",
1723 rd_constructor => "NONE",
1724 comment => "x87 fp Cos: Cos(a) = cos(a)",
1731 rd_constructor => "NONE",
1732 comment => "x87 fp Sqrt: Sqrt(a) = a ^ 0.5",
1734 emit => '. fsqrt $',
1737 # x87 Load and Store
1740 rd_constructor => "NONE",
1741 op_flags => "R|L|F",
1742 state => "exc_pinned",
1743 comment => "x87 fp Load: Load(ptr, mem) = LD ptr -> reg",
1745 emit => '. fld%XM %AM',
1749 rd_constructor => "NONE",
1750 op_flags => "R|L|F",
1751 state => "exc_pinned",
1752 comment => "x87 fp Store: Store(ptr, val, mem) = ST ptr,val",
1754 emit => '. fst%XM %AM',
1759 rd_constructor => "NONE",
1760 op_flags => "R|L|F",
1761 state => "exc_pinned",
1762 comment => "x87 fp Store: Store(ptr, val, mem) = ST ptr,val",
1764 emit => '. fstp%XM %AM',
1772 rd_constructor => "NONE",
1773 comment => "x87 fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1775 emit => '. fild%XM %AM',
1780 rd_constructor => "NONE",
1781 comment => "x87 fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1783 emit => '. fist%M %AM',
1789 rd_constructor => "NONE",
1790 comment => "x87 fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1792 emit => '. fistp%M %AM',
1801 comment => "x87 fp Load 0.0: Ld 0.0 -> reg",
1809 comment => "x87 fp Load 1.0: Ld 1.0 -> reg",
1817 comment => "x87 fp Load pi: Ld pi -> reg",
1825 comment => "x87 fp Load ln 2: Ld ln 2 -> reg",
1833 comment => "x87 fp Load lg 2: Ld lg 2 -> reg",
1841 comment => "x87 fp Load ld 10: Ld ld 10 -> reg",
1843 emit => '. fldll2t',
1849 comment => "x87 fp Load ld e: Ld ld e -> reg",
1855 # Note that it is NEVER allowed to do CSE on these nodes
1856 # Moreover, note the virtual register requierements!
1860 comment => "x87 stack exchange",
1862 cmp_attr => "return 1;",
1863 emit => '. fxch %X1',
1868 comment => "x87 stack push",
1870 cmp_attr => "return 1;",
1871 emit => '. fld %X1',
1876 comment => "x87 stack push",
1877 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1878 cmp_attr => "return 1;",
1879 emit => '. fld %X1',
1884 comment => "x87 stack pop",
1886 cmp_attr => "return 1;",
1887 emit => '. fstp %X1',
1893 op_flags => "L|X|Y",
1894 comment => "floating point compare",
1899 op_flags => "L|X|Y",
1900 comment => "floating point compare and pop",
1905 op_flags => "L|X|Y",
1906 comment => "floating point compare and pop twice",
1911 op_flags => "L|X|Y",
1912 comment => "floating point compare reverse",
1917 op_flags => "L|X|Y",
1918 comment => "floating point compare reverse and pop",
1923 op_flags => "L|X|Y",
1924 comment => "floating point compare reverse and pop twice",
1929 # -------------------------------------------------------------------------------- #
1930 # ____ ____ _____ _ _ #
1931 # / ___/ ___|| ____| __ _____ ___| |_ ___ _ __ _ __ ___ __| | ___ ___ #
1932 # \___ \___ \| _| \ \ / / _ \/ __| __/ _ \| '__| | '_ \ / _ \ / _` |/ _ \/ __| #
1933 # ___) |__) | |___ \ V / __/ (__| || (_) | | | | | | (_) | (_| | __/\__ \ #
1934 # |____/____/|_____| \_/ \___|\___|\__\___/|_| |_| |_|\___/ \__,_|\___||___/ #
1936 # -------------------------------------------------------------------------------- #
1939 # Spilling and reloading of SSE registers, hardcoded, not generated #
1943 state => "exc_pinned",
1944 comment => "construct SSE Load: Load(ptr, mem) = LD ptr",
1945 reg_req => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1946 emit => '. movdqu %D1, %AM',
1947 outs => [ "res", "M" ],
1953 state => "exc_pinned",
1954 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
1955 reg_req => { in => [ "gp", "gp", "xmm", "none" ] },
1956 emit => '. movdqu %binop',
1963 # Include the generated SIMD node specification written by the SIMD optimization
1964 $my_script_name = dirname($myname) . "/../ia32/ia32_simd_spec.pl";
1965 unless ($return = do $my_script_name) {
1966 warn "couldn't parse $my_script_name: $@" if $@;
1967 warn "couldn't do $my_script_name: $!" unless defined $return;
1968 warn "couldn't run $my_script_name" unless $return;