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 # 32 - register represents a state
109 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
112 { name => "eax", type => 1 },
113 { name => "edx", type => 1 },
114 { name => "ebx", type => 2 },
115 { name => "ecx", type => 1 },
116 { name => "esi", type => 2 },
117 { name => "edi", type => 2 },
118 { name => "ebp", type => 2 },
119 { name => "esp", type => 4 },
120 { name => "gp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
121 { name => "gp_UKNWN", type => 4 | 8 | 16 }, # we need a dummy register for Unknown nodes
122 { mode => "mode_Iu" }
125 { name => "xmm0", type => 1 },
126 { name => "xmm1", type => 1 },
127 { name => "xmm2", type => 1 },
128 { name => "xmm3", type => 1 },
129 { name => "xmm4", type => 1 },
130 { name => "xmm5", type => 1 },
131 { name => "xmm6", type => 1 },
132 { name => "xmm7", type => 1 },
133 { name => "xmm_NOREG", type => 4 | 16 }, # we need a dummy register for NoReg nodes
134 { name => "xmm_UKNWN", type => 4 | 8 | 16}, # we need a dummy register for Unknown nodes
138 { name => "vf0", type => 1 | 16 },
139 { name => "vf1", type => 1 | 16 },
140 { name => "vf2", type => 1 | 16 },
141 { name => "vf3", type => 1 | 16 },
142 { name => "vf4", type => 1 | 16 },
143 { name => "vf5", type => 1 | 16 },
144 { name => "vf6", type => 1 | 16 },
145 { name => "vf7", type => 1 | 16 },
146 { name => "vfp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
147 { name => "vfp_UKNWN", type => 4 | 8 | 16 }, # we need a dummy register for Unknown nodes
151 { name => "st0", type => 4 },
152 { name => "st1", type => 4 },
153 { name => "st2", type => 4 },
154 { name => "st3", type => 4 },
155 { name => "st4", type => 4 },
156 { name => "st5", type => 4 },
157 { name => "st6", type => 4 },
158 { name => "st7", type => 4 },
161 fp_cw => [ # the floating point control word
162 { name => "fpcw", type => 4 | 32},
163 { 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" ] },
715 comment => "unknown value",
716 reg_req => { out => [ "gp_UKNWN" ] },
726 comment => "unknown value",
727 reg_req => { out => [ "vfp_UKNWN" ] },
737 comment => "unknown value",
738 reg_req => { out => [ "xmm_UKNWN" ] },
748 comment => "noreg GP value",
749 reg_req => { out => [ "gp_NOREG" ] },
759 comment => "noreg VFP value",
760 reg_req => { out => [ "vfp_NOREG" ] },
770 comment => "noreg XMM value",
771 reg_req => { out => [ "xmm_NOREG" ] },
781 comment => "change floating point control word",
782 reg_req => { out => [ "fp_cw" ] },
790 state => "exc_pinned",
791 comment => "load floating point control word FldCW(ptr, mem) = LD ptr -> reg",
792 reg_req => { in => [ "gp", "gp", "none" ], out => [ "fp_cw" ] },
794 emit => ". fldcw %AM",
801 state => "exc_pinned",
802 comment => "store floating point control word: FstCW(ptr, mem) = ST ptr -> reg",
803 reg_req => { in => [ "gp", "gp", "fp_cw", "none" ], out => [ "none" ] },
805 emit => ". fnstcw %AM",
811 # we should not rematrialize this node. It produces 2 results and has
812 # very strict constrains
813 comment => "construct CDQ: sign extend EAX -> EDX:EAX",
814 reg_req => { in => [ "gp" ], out => [ "eax in_r1", "edx" ] },
816 outs => [ "EAX", "EDX" ],
824 state => "exc_pinned",
825 comment => "construct Load: Load(ptr, mem) = LD ptr -> reg",
826 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
828 emit => ". mov%SE%ME%.l %AM, %D1",
829 outs => [ "res", "M" ],
835 cmp_attr => "return 1;",
836 comment => "construct lowered Load: Load(ptr, mem) = LD ptr -> reg",
837 outs => [ "res", "M" ],
843 cmp_attr => "return 1;",
844 state => "exc_pinned",
845 comment => "construct lowered Store: Store(ptr, val, mem) = ST ptr,val",
852 state => "exc_pinned",
853 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
854 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
855 emit => '. mov%M %binop',
863 state => "exc_pinned",
864 comment => "construct 8Bit Store: Store(ptr, val, mem) = ST ptr,val",
865 reg_req => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => ["none" ] },
866 emit => '. mov%M %binop',
874 comment => "construct Lea: Lea(a,b) = lea [a+b*const+offs] | res = a + b * const + offs with const = 0,1,2,4,8",
875 reg_req => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
876 emit => '. leal %AM, %D1',
883 comment => "push on the stack",
884 reg_req => { in => [ "gp", "gp", "gp", "esp", "none" ], out => [ "esp", "none" ] },
885 emit => '. pushl %unop',
886 outs => [ "stack:I|S", "M" ],
892 comment => "pop a gp register from the stack",
893 reg_req => { in => [ "gp", "gp", "esp", "none" ], out => [ "esp", "gp", "none" ] },
894 emit => '. popl %unop',
895 outs => [ "stack:I|S", "res", "M" ],
901 comment => "create stack frame",
902 reg_req => { in => [ "esp" ], out => [ "ebp", "esp" ] },
904 outs => [ "frame:I", "stack:I|S", "M" ],
910 comment => "destroy stack frame",
911 reg_req => { in => [ "esp", "ebp" ], out => [ "ebp", "esp" ] },
913 outs => [ "frame:I", "stack:I|S" ],
920 comment => "allocate space on stack",
921 reg_req => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
922 emit => '. addl %binop',
923 outs => [ "stack:S", "M" ],
929 comment => "free space on stack",
930 reg_req => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
931 emit => '. subl %binop',
932 outs => [ "stack:S", "M" ],
938 comment => "get the TLS base address",
939 reg_req => { out => [ "gp" ] },
945 #-----------------------------------------------------------------------------#
946 # _____ _____ ______ __ _ _ _ #
947 # / ____/ ____| ____| / _| | | | | | #
948 # | (___| (___ | |__ | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
949 # \___ \\___ \| __| | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
950 # ____) |___) | |____ | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
951 # |_____/_____/|______| |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
952 #-----------------------------------------------------------------------------#
954 # commutative operations
958 comment => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
959 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
960 emit => '. add%XXM %binop',
968 comment => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
969 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
970 emit => '. mul%XXM %binop',
978 comment => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
979 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
980 emit => '. max%XXM %binop',
988 comment => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
989 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
990 emit => '. min%XXM %binop',
998 comment => "construct SSE And: And(a, b) = a AND b",
999 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1000 emit => '. andp%XSD %binop',
1008 comment => "construct SSE Or: Or(a, b) = a OR b",
1009 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1010 emit => '. orp%XSD %binop',
1017 comment => "construct SSE Xor: Xor(a, b) = a XOR b",
1018 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1019 emit => '. xorp%XSD %binop',
1025 # not commutative operations
1029 comment => "construct SSE AndNot: AndNot(a, b) = a AND NOT b",
1030 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1031 emit => '. andnp%XSD %binop',
1039 comment => "construct SSE Sub: Sub(a, b) = a - b",
1040 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1041 emit => '. sub%XXM %binop',
1049 comment => "construct SSE Div: Div(a, b) = a / b",
1050 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1051 outs => [ "res", "M" ],
1052 emit => '. div%XXM %binop',
1061 comment => "construct SSE Compare: Cmp(a, b) == a = a cmp b",
1062 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1070 op_flags => "L|X|Y",
1071 comment => "construct conditional jump: UCOMIS A, B && JMPxx LABEL",
1072 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "none", "none" ] },
1073 outs => [ "false", "true" ],
1081 comment => "represents a SSE constant",
1082 reg_req => { out => [ "xmm" ] },
1083 emit => '. mov%XXM $%C, %D1',
1093 state => "exc_pinned",
1094 comment => "construct SSE Load: Load(ptr, mem) = LD ptr",
1095 reg_req => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1096 emit => '. mov%XXM %AM, %D1',
1097 outs => [ "res", "M" ],
1104 state => "exc_pinned",
1105 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
1106 reg_req => { in => [ "gp", "gp", "xmm", "none" ] },
1107 emit => '. mov%XXM %binop',
1115 state => "exc_pinned",
1116 comment => "construct Store without index: Store(ptr, val, mem) = ST ptr,val",
1117 reg_req => { in => [ "gp", "xmm", "none" ] },
1118 emit => '. mov%XXM %S2, %AM',
1126 comment => "construct: transfer a value from x87 FPU into a SSE register",
1127 cmp_attr => "return 1;",
1133 comment => "construct: transfer a value from SSE register to x87 FPU",
1134 cmp_attr => "return 1;",
1141 state => "exc_pinned",
1142 comment => "store ST0 onto stack",
1143 reg_req => { in => [ "gp", "gp", "none" ] },
1144 emit => '. fstp%XM %AM',
1153 state => "exc_pinned",
1154 comment => "load ST0 from stack",
1155 reg_req => { in => [ "gp", "none" ], out => [ "vf0", "none" ] },
1156 emit => '. fld%M %AM',
1157 outs => [ "res", "M" ],
1167 comment => "implements a memcopy: CopyB(dst, src, size, mem) == memcpy(dst, src, size)",
1168 reg_req => { in => [ "edi", "esi", "ecx", "none" ], out => [ "edi", "esi", "ecx", "none" ] },
1169 outs => [ "DST", "SRC", "CNT", "M" ],
1176 comment => "implements a memcopy: CopyB(dst, src, mem) == memcpy(dst, src, attr(size))",
1177 reg_req => { in => [ "edi", "esi", "none" ], out => [ "edi", "esi", "none" ] },
1178 outs => [ "DST", "SRC", "M" ],
1185 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3", "none" ] },
1186 comment => "construct Conv Int -> Int",
1192 reg_req => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => [ "in_r3", "none" ] },
1193 comment => "construct Conv Int -> Int",
1199 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1200 comment => "construct Conv Int -> Floating Point",
1207 reg_req => { in => [ "gp", "gp", "xmm", "none" ], out => [ "gp", "none" ] },
1208 comment => "construct Conv Floating Point -> Int",
1215 reg_req => { in => [ "gp", "gp", "xmm", "none" ], out => [ "xmm", "none" ] },
1216 comment => "construct Conv Floating Point -> Floating Point",
1224 comment => "construct Conditional Move: CMov(sel, a, b) == sel ? a : b",
1225 reg_req => { in => [ "gp", "gp", "gp", "gp" ], out => [ "in_r4" ] },
1233 comment => "check if Psi condition tree evaluates to true and move result accordingly",
1234 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "in_r3" ] },
1242 comment => "construct Conditional Move: SSE Compare + int CMov ",
1243 reg_req => { in => [ "xmm", "xmm", "gp", "gp" ], out => [ "in_r4" ] },
1251 comment => "construct Conditional Move: x87 Compare + int CMov",
1252 reg_req => { in => [ "vfp", "vfp", "gp", "gp" ], out => [ "in_r4" ] },
1260 comment => "construct Set: Set(sel) == sel ? 1 : 0",
1261 reg_req => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "eax ebx ecx edx" ] },
1269 comment => "check if Psi condition tree evaluates to true and set result accordingly",
1270 reg_req => { in => [ "gp" ], out => [ "eax ebx ecx edx" ] },
1278 comment => "construct Set: SSE Compare + int Set",
1279 reg_req => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "eax ebx ecx edx" ] },
1287 comment => "construct Set: x87 Compare + int Set",
1288 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "eax ebx ecx edx" ] },
1296 comment => "construct x87 Conditional Move: vfCMov(sel, a, b) = sel ? a : b",
1297 reg_req => { in => [ "vfp", "vfp", "vfp", "vfp" ], out => [ "vfp" ] },
1303 #----------------------------------------------------------#
1305 # (_) | | | | / _| | | | #
1306 # __ ___ _ __| |_ _ _ __ _| | | |_| | ___ __ _| |_ #
1307 # \ \ / / | '__| __| | | |/ _` | | | _| |/ _ \ / _` | __| #
1308 # \ V /| | | | |_| |_| | (_| | | | | | | (_) | (_| | |_ #
1309 # \_/ |_|_| \__|\__,_|\__,_|_| |_| |_|\___/ \__,_|\__| #
1311 # _ __ ___ __| | ___ ___ #
1312 # | '_ \ / _ \ / _` |/ _ \/ __| #
1313 # | | | | (_) | (_| | __/\__ \ #
1314 # |_| |_|\___/ \__,_|\___||___/ #
1315 #----------------------------------------------------------#
1319 comment => "virtual fp Add: Add(a, b) = Add(b, a) = a + b",
1320 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1328 comment => "virtual fp Mul: Mul(a, b) = Mul(b, a) = a * b",
1329 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1337 cmp_attr => "return 1;",
1338 comment => "lowered virtual fp Mul: Mul(a, b) = Mul(b, a) = a * b",
1344 comment => "virtual fp Sub: Sub(a, b) = a - b",
1345 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1352 cmp_attr => "return 1;",
1353 comment => "lowered virtual fp Sub: Sub(a, b) = a - b",
1358 comment => "virtual fp Div: Div(a, b) = a / b",
1359 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1360 outs => [ "res", "M" ],
1366 cmp_attr => "return 1;",
1367 comment => "lowered virtual fp Div: Div(a, b) = a / b",
1368 outs => [ "res", "M" ],
1373 comment => "virtual fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1374 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1381 cmp_attr => "return 1;",
1382 comment => "lowered virtual fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1388 comment => "virtual fp Abs: Abs(a) = |a|",
1389 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1397 comment => "virtual fp Chs: Chs(a) = -a",
1398 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1406 comment => "virtual fp Sin: Sin(a) = sin(a)",
1407 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1415 comment => "virtual fp Cos: Cos(a) = cos(a)",
1416 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1424 comment => "virtual fp Sqrt: Sqrt(a) = a ^ 0.5",
1425 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1431 # virtual Load and Store
1435 state => "exc_pinned",
1436 comment => "virtual fp Load: Load(ptr, mem) = LD ptr -> reg",
1437 reg_req => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1438 outs => [ "res", "M" ],
1445 state => "exc_pinned",
1446 comment => "virtual fp Store: Store(ptr, val, mem) = ST ptr,val",
1447 reg_req => { in => [ "gp", "gp", "vfp", "none" ] },
1456 comment => "virtual fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1457 reg_req => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1458 outs => [ "res", "M" ],
1464 cmp_attr => "return 1;",
1465 comment => "lowered virtual fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1466 outs => [ "res", "M" ],
1471 comment => "virtual fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1472 reg_req => { in => [ "gp", "gp", "vfp", "fpcw", "none" ] },
1479 cmp_attr => "return 1;",
1480 comment => "lowered virtual fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1490 comment => "virtual fp Load 0.0: Ld 0.0 -> reg",
1491 reg_req => { out => [ "vfp" ] },
1499 comment => "virtual fp Load 1.0: Ld 1.0 -> reg",
1500 reg_req => { out => [ "vfp" ] },
1508 comment => "virtual fp Load pi: Ld pi -> reg",
1509 reg_req => { out => [ "vfp" ] },
1517 comment => "virtual fp Load ln 2: Ld ln 2 -> reg",
1518 reg_req => { out => [ "vfp" ] },
1526 comment => "virtual fp Load lg 2: Ld lg 2 -> reg",
1527 reg_req => { out => [ "vfp" ] },
1535 comment => "virtual fp Load ld 10: Ld ld 10 -> reg",
1536 reg_req => { out => [ "vfp" ] },
1544 comment => "virtual fp Load ld e: Ld ld e -> reg",
1545 reg_req => { out => [ "vfp" ] },
1554 # init_attr => " set_ia32_ls_mode(res, mode);",
1555 comment => "represents a virtual floating point constant",
1556 reg_req => { out => [ "vfp" ] },
1566 op_flags => "L|X|Y",
1567 comment => "represents a virtual floating point compare",
1568 reg_req => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "none", "none", "eax" ] },
1569 outs => [ "false", "true", "temp_reg_eax" ],
1574 #------------------------------------------------------------------------#
1575 # ___ _____ __ _ _ _ #
1576 # __ _( _ )___ | / _| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
1577 # \ \/ / _ \ / / | |_| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1578 # > < (_) |/ / | _| | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
1579 # /_/\_\___//_/ |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1580 #------------------------------------------------------------------------#
1582 # Note: gas is strangely buggy: fdivrp and fdivp as well as fsubrp and fsubp
1583 # are swapped, we work this around in the emitter...
1587 rd_constructor => "NONE",
1588 comment => "x87 Add: Add(a, b) = Add(b, a) = a + b",
1590 emit => '. fadd%XM %x87_binop',
1595 rd_constructor => "NONE",
1596 comment => "x87 Add: Add(a, b) = Add(b, a) = a + b",
1598 emit => '. faddp %x87_binop',
1603 rd_constructor => "NONE",
1604 comment => "x87 fp Mul: Mul(a, b) = Mul(b, a) = a + b",
1606 emit => '. fmul%XM %x87_binop',
1611 rd_constructor => "NONE",
1612 comment => "x87 fp Mul: Mul(a, b) = Mul(b, a) = a + b",
1614 emit => '. fmulp %x87_binop',,
1619 rd_constructor => "NONE",
1620 comment => "x87 fp Sub: Sub(a, b) = a - b",
1622 emit => '. fsub%XM %x87_binop',
1627 rd_constructor => "NONE",
1628 comment => "x87 fp Sub: Sub(a, b) = a - b",
1630 # see note about gas bugs
1631 emit => '. fsubrp %x87_binop',
1636 rd_constructor => "NONE",
1638 comment => "x87 fp SubR: SubR(a, b) = b - a",
1640 emit => '. fsubr%XM %x87_binop',
1645 rd_constructor => "NONE",
1647 comment => "x87 fp SubR: SubR(a, b) = b - a",
1649 # see note about gas bugs
1650 emit => '. fsubp %x87_binop',
1655 rd_constructor => "NONE",
1656 comment => "x87 fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1661 # this node is just here, to keep the simulator running
1662 # we can omit this when a fprem simulation function exists
1665 rd_constructor => "NONE",
1666 comment => "x87 fp Rem: Rem(a, b) = a - Q * b (Q is integer)",
1673 rd_constructor => "NONE",
1674 comment => "x87 fp Div: Div(a, b) = a / b",
1676 emit => '. fdiv%XM %x87_binop',
1681 rd_constructor => "NONE",
1682 comment => "x87 fp Div: Div(a, b) = a / b",
1684 # see note about gas bugs
1685 emit => '. fdivrp %x87_binop',
1690 rd_constructor => "NONE",
1691 comment => "x87 fp DivR: DivR(a, b) = b / a",
1693 emit => '. fdivr%XM %x87_binop',
1698 rd_constructor => "NONE",
1699 comment => "x87 fp DivR: DivR(a, b) = b / a",
1701 # see note about gas bugs
1702 emit => '. fdivp %x87_binop',
1707 rd_constructor => "NONE",
1708 comment => "x87 fp Abs: Abs(a) = |a|",
1715 rd_constructor => "NONE",
1716 comment => "x87 fp Chs: Chs(a) = -a",
1723 rd_constructor => "NONE",
1724 comment => "x87 fp Sin: Sin(a) = sin(a)",
1731 rd_constructor => "NONE",
1732 comment => "x87 fp Cos: Cos(a) = cos(a)",
1739 rd_constructor => "NONE",
1740 comment => "x87 fp Sqrt: Sqrt(a) = a ^ 0.5",
1742 emit => '. fsqrt $',
1745 # x87 Load and Store
1748 rd_constructor => "NONE",
1749 op_flags => "R|L|F",
1750 state => "exc_pinned",
1751 comment => "x87 fp Load: Load(ptr, mem) = LD ptr -> reg",
1753 emit => '. fld%XM %AM',
1757 rd_constructor => "NONE",
1758 op_flags => "R|L|F",
1759 state => "exc_pinned",
1760 comment => "x87 fp Store: Store(ptr, val, mem) = ST ptr,val",
1762 emit => '. fst%XM %AM',
1767 rd_constructor => "NONE",
1768 op_flags => "R|L|F",
1769 state => "exc_pinned",
1770 comment => "x87 fp Store: Store(ptr, val, mem) = ST ptr,val",
1772 emit => '. fstp%XM %AM',
1780 rd_constructor => "NONE",
1781 comment => "x87 fp integer Load: Load(ptr, mem) = iLD ptr -> reg",
1783 emit => '. fild%XM %AM',
1788 rd_constructor => "NONE",
1789 comment => "x87 fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1791 emit => '. fist%M %AM',
1797 rd_constructor => "NONE",
1798 comment => "x87 fp integer Store: Store(ptr, val, mem) = iST ptr,val",
1800 emit => '. fistp%M %AM',
1809 comment => "x87 fp Load 0.0: Ld 0.0 -> reg",
1817 comment => "x87 fp Load 1.0: Ld 1.0 -> reg",
1825 comment => "x87 fp Load pi: Ld pi -> reg",
1833 comment => "x87 fp Load ln 2: Ld ln 2 -> reg",
1841 comment => "x87 fp Load lg 2: Ld lg 2 -> reg",
1849 comment => "x87 fp Load ld 10: Ld ld 10 -> reg",
1851 emit => '. fldll2t',
1857 comment => "x87 fp Load ld e: Ld ld e -> reg",
1863 # Note that it is NEVER allowed to do CSE on these nodes
1864 # Moreover, note the virtual register requierements!
1868 comment => "x87 stack exchange",
1870 cmp_attr => "return 1;",
1871 emit => '. fxch %X1',
1876 comment => "x87 stack push",
1878 cmp_attr => "return 1;",
1879 emit => '. fld %X1',
1884 comment => "x87 stack push",
1885 reg_req => { in => [ "vfp"], out => [ "vfp" ] },
1886 cmp_attr => "return 1;",
1887 emit => '. fld %X1',
1892 comment => "x87 stack pop",
1894 cmp_attr => "return 1;",
1895 emit => '. fstp %X1',
1901 op_flags => "L|X|Y",
1902 comment => "floating point compare",
1907 op_flags => "L|X|Y",
1908 comment => "floating point compare and pop",
1913 op_flags => "L|X|Y",
1914 comment => "floating point compare and pop twice",
1919 op_flags => "L|X|Y",
1920 comment => "floating point compare reverse",
1925 op_flags => "L|X|Y",
1926 comment => "floating point compare reverse and pop",
1931 op_flags => "L|X|Y",
1932 comment => "floating point compare reverse and pop twice",
1937 # -------------------------------------------------------------------------------- #
1938 # ____ ____ _____ _ _ #
1939 # / ___/ ___|| ____| __ _____ ___| |_ ___ _ __ _ __ ___ __| | ___ ___ #
1940 # \___ \___ \| _| \ \ / / _ \/ __| __/ _ \| '__| | '_ \ / _ \ / _` |/ _ \/ __| #
1941 # ___) |__) | |___ \ V / __/ (__| || (_) | | | | | | (_) | (_| | __/\__ \ #
1942 # |____/____/|_____| \_/ \___|\___|\__\___/|_| |_| |_|\___/ \__,_|\___||___/ #
1944 # -------------------------------------------------------------------------------- #
1947 # Spilling and reloading of SSE registers, hardcoded, not generated #
1951 state => "exc_pinned",
1952 comment => "construct SSE Load: Load(ptr, mem) = LD ptr",
1953 reg_req => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1954 emit => '. movdqu %D1, %AM',
1955 outs => [ "res", "M" ],
1961 state => "exc_pinned",
1962 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
1963 reg_req => { in => [ "gp", "gp", "xmm", "none" ] },
1964 emit => '. movdqu %binop',
1971 # Include the generated SIMD node specification written by the SIMD optimization
1972 $my_script_name = dirname($myname) . "/../ia32/ia32_simd_spec.pl";
1973 unless ($return = do $my_script_name) {
1974 warn "couldn't parse $my_script_name: $@" if $@;
1975 warn "couldn't do $my_script_name: $!" unless defined $return;
1976 warn "couldn't run $my_script_name" unless $return;