- improve set transformation
[libfirm] / ir / be / ia32 / ia32_spec.pl
1 # Creation: 2005/10/19
2 # $Id$
3 # This is the specification for the ia32 assembler Firm-operations
4
5 use File::Basename;
6
7 $new_emit_syntax = 1;
8 my $myname = $0;
9
10 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
11 $arch = "ia32";
12
13 # The node description is done as a perl hash initializer with the
14 # following structure:
15 #
16 # %nodes = (
17 #
18 # <op-name> => {
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",
23 #   args      => [
24 #                    { type => "type 1", name => "name 1" },
25 #                    { type => "type 2", name => "name 2" },
26 #                    ...
27 #                  ],
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 #   attr_type => "name of the attribute struct",
36 # },
37 #
38 # ... # (all nodes you need to describe)
39 #
40 # ); # close the %nodes initializer
41
42 # op_flags: flags for the operation, OPTIONAL (default is "N")
43 # the op_flags correspond to the firm irop_flags:
44 #   N   irop_flag_none
45 #   L   irop_flag_labeled
46 #   C   irop_flag_commutative
47 #   X   irop_flag_cfopcode
48 #   I   irop_flag_ip_cfopcode
49 #   F   irop_flag_fragile
50 #   Y   irop_flag_forking
51 #   H   irop_flag_highlevel
52 #   c   irop_flag_constlike
53 #   K   irop_flag_keep
54 #
55 # irn_flags: special node flags, OPTIONAL (default is 0)
56 # following irn_flags are supported:
57 #   R   rematerializeable
58 #   N   not spillable
59 #   I   ignore for register allocation
60 #   S   modifies stack pointer
61 #
62 # state: state of the operation, OPTIONAL (default is "floats")
63 #
64 # arity: arity of the operation, MUST NOT BE OMITTED
65 #
66 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
67 #        are always the first 3 arguments and are always autmatically
68 #        created)
69 #        If this key is missing the following arguments will be created:
70 #        for i = 1 .. arity: ir_node *op_i
71 #        ir_mode *mode
72 #
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" ]
79 #
80 # comment: OPTIONAL comment for the node constructor
81 #
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
86 #
87 #      This key is OPTIONAL. If omitted, the following constructor will
88 #      be created:
89 #      if (!op_<arch>_<op-name>) assert(0);
90 #      for i = 1 to arity
91 #         set in[i] = op_i
92 #      done
93 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
94 #      return res
95 #
96 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
97 #
98
99 # register types:
100 #   0 - no special type
101 #   1 - caller save (register must be saved by the caller of a function)
102 #   2 - callee save (register must be saved by the called function)
103 #   4 - ignore (do not assign this register)
104 #   8 - emitter can choose an arbitrary register of this class
105 #  16 - the register is a virtual one
106 #  32 - register represents a state
107 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
108 %reg_classes = (
109         gp => [
110                 { name => "edx", type => 1 },
111                 { name => "ecx", type => 1 },
112                 { name => "eax", type => 1 },
113                 { name => "ebx", type => 2 },
114                 { name => "esi", type => 2 },
115                 { name => "edi", type => 2 },
116                 { name => "ebp", type => 2 },
117                 { name => "esp", type => 4 },
118                 { name => "gp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
119                 { name => "gp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
120                 { mode => "mode_Iu" }
121         ],
122         mmx => [
123                 { name => "mm0", type => 4 },
124                 { name => "mm1", type => 4 },
125                 { name => "mm2", type => 4 },
126                 { name => "mm3", type => 4 },
127                 { name => "mm4", type => 4 },
128                 { name => "mm5", type => 4 },
129                 { name => "mm6", type => 4 },
130                 { name => "mm7", type => 4 },
131                 { mode => "mode_E", flags => "manual_ra" }
132         ],
133         xmm => [
134                 { name => "xmm0", type => 1 },
135                 { name => "xmm1", type => 1 },
136                 { name => "xmm2", type => 1 },
137                 { name => "xmm3", type => 1 },
138                 { name => "xmm4", type => 1 },
139                 { name => "xmm5", type => 1 },
140                 { name => "xmm6", type => 1 },
141                 { name => "xmm7", type => 1 },
142                 { name => "xmm_NOREG", type => 4 | 16 },     # we need a dummy register for NoReg nodes
143                 { name => "xmm_UKNWN", type => 4 | 8 | 16},  # we need a dummy register for Unknown nodes
144                 { mode => "mode_E" }
145         ],
146         vfp => [
147                 { name => "vf0", type => 1 | 16 },
148                 { name => "vf1", type => 1 | 16 },
149                 { name => "vf2", type => 1 | 16 },
150                 { name => "vf3", type => 1 | 16 },
151                 { name => "vf4", type => 1 | 16 },
152                 { name => "vf5", type => 1 | 16 },
153                 { name => "vf6", type => 1 | 16 },
154                 { name => "vf7", type => 1 | 16 },
155                 { name => "vfp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
156                 { name => "vfp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
157                 { mode => "mode_E" }
158         ],
159         st => [
160                 { name => "st0", realname => "st",    type => 4 },
161                 { name => "st1", realname => "st(1)", type => 4 },
162                 { name => "st2", realname => "st(2)", type => 4 },
163                 { name => "st3", realname => "st(3)", type => 4 },
164                 { name => "st4", realname => "st(4)", type => 4 },
165                 { name => "st5", realname => "st(5)", type => 4 },
166                 { name => "st6", realname => "st(6)", type => 4 },
167                 { name => "st7", realname => "st(7)", type => 4 },
168                 { mode => "mode_E", flags => "manual_ra" }
169         ],
170         fp_cw => [      # the floating point control word
171                 { name => "fpcw", type => 4|32 },
172                 { mode => "mode_fpcw", flags => "manual_ra|state" }
173         ],
174         flags => [
175                 { name => "eflags", type => 0 },
176                 { mode => "mode_Iu", flags => "manual_ra" }
177         ],
178 ); # %reg_classes
179
180 %cpu = (
181         GP     => [ 1, "GP_EAX", "GP_EBX", "GP_ECX", "GP_EDX", "GP_ESI", "GP_EDI", "GP_EBP" ],
182         SSE    => [ 1, "SSE_XMM0", "SSE_XMM1", "SSE_XMM2", "SSE_XMM3", "SSE_XMM4", "SSE_XMM5", "SSE_XMM6", "SSE_XMM7" ],
183         VFP    => [ 1, "VFP_VF0", "VFP_VF1", "VFP_VF2", "VFP_VF3", "VFP_VF4", "VFP_VF5", "VFP_VF6", "VFP_VF7" ],
184         BRANCH => [ 1, "BRANCH1", "BRANCH2" ],
185 ); # %cpu
186
187 %vliw = (
188         bundle_size       => 1,
189         bundels_per_cycle => 1
190 ); # vliw
191
192 %emit_templates = (
193         S0 => "${arch}_emit_source_register(node, 0);",
194         S1 => "${arch}_emit_source_register(node, 1);",
195         S2 => "${arch}_emit_source_register(node, 2);",
196         S3 => "${arch}_emit_source_register(node, 3);",
197         SB1 => "${arch}_emit_8bit_source_register_or_immediate(node, 1);",
198         SB2 => "${arch}_emit_8bit_source_register_or_immediate(node, 2);",
199         SB3 => "${arch}_emit_8bit_source_register_or_immediate(node, 3);",
200         SI3 => "${arch}_emit_source_register_or_immediate(node, 3);",
201         D0 => "${arch}_emit_dest_register(node, 0);",
202         D1 => "${arch}_emit_dest_register(node, 1);",
203         DB0 => "${arch}_emit_8bit_dest_register(node, 0);",
204         X0 => "${arch}_emit_x87_register(node, 0);",
205         X1 => "${arch}_emit_x87_register(node, 1);",
206         SE => "${arch}_emit_extend_suffix(get_ia32_ls_mode(node));",
207         ME => "if(get_mode_size_bits(get_ia32_ls_mode(node)) != 32)\n
208                    ia32_emit_mode_suffix(node);",
209         M  => "${arch}_emit_mode_suffix(node);",
210         XM => "${arch}_emit_x87_mode_suffix(node);",
211         XXM => "${arch}_emit_xmm_mode_suffix(node);",
212         XSD => "${arch}_emit_xmm_mode_suffix_s(node);",
213         AM => "${arch}_emit_am(node);",
214         unop3 => "${arch}_emit_unop(node, 3);",
215         unop4 => "${arch}_emit_unop(node, 4);",
216         unop5 => "${arch}_emit_unop(node, 5);",
217         DAM0  => "${arch}_emit_am_or_dest_register(node, 0);",
218         binop => "${arch}_emit_binop(node);",
219         x87_binop => "${arch}_emit_x87_binop(node);",
220         CMP0  => "${arch}_emit_cmp_suffix_node(node, 0);",
221         CMP3  => "${arch}_emit_cmp_suffix_node(node, 3);",
222 );
223
224 #--------------------------------------------------#
225 #                        _                         #
226 #                       (_)                        #
227 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
228 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
229 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
230 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
231 #                                      | |         #
232 #                                      |_|         #
233 #--------------------------------------------------#
234
235 $default_op_attr_type = "ia32_op_attr_t";
236 $default_attr_type    = "ia32_attr_t";
237 $default_copy_attr    = "ia32_copy_attr";
238
239 sub ia32_custom_init_attr {
240         my $node = shift;
241         my $name = shift;
242         my $res = "";
243
244         if(defined($node->{modified_flags})) {
245                 $res .= "\tset_ia32_flags(res, get_ia32_flags(res) | arch_irn_flags_modify_flags);\n";
246         }
247         if(defined($node->{am})) {
248                 my $am = $node->{am};
249                 if($am eq "full,binary") {
250                         $res .= "\tset_ia32_am_support(res, ia32_am_Full, ia32_am_binary);";
251                 } elsif($am eq "full,unary") {
252                         $res .= "\tset_ia32_am_support(res, ia32_am_Full, ia32_am_unary);";
253                 } elsif($am eq "source,unary") {
254                         $res .= "\tset_ia32_am_support(res, ia32_am_Source, ia32_am_unary);";
255                 } elsif($am eq "source,binary") {
256                         $res .= "\tset_ia32_am_support(res, ia32_am_Source, ia32_am_binary);";
257                 } elsif($am eq "dest,unary") {
258                         $res .= "\tset_ia32_am_support(res, ia32_am_Dest, ia32_am_unary);";
259                 } elsif($am eq "dest,binary") {
260                         $res .= "\tset_ia32_am_support(res, ia32_am_Dest, ia32_am_binary);";
261                 } elsif($am eq "dest,ternary") {
262                         $res .= "\tset_ia32_am_support(res, ia32_am_Dest, ia32_am_ternary);";
263                 } elsif($am eq "source,ternary") {
264                         $res .= "\tset_ia32_am_support(res, ia32_am_Source, ia32_am_ternary);";
265                 } elsif($am eq "none") {
266                         # nothing to do
267                 } else {
268                         die("Invalid address mode '$am' specified on op $name");
269                 }
270                 if($am ne "none") {
271                         if($node->{state} ne "exc_pinned"
272                                         and $node->{state} ne "pinned") {
273                                 die("AM nodes must have pinned or AM pinned state ($name)");
274                         }
275                 }
276         }
277         return $res;
278 }
279 $custom_init_attr_func = \&ia32_custom_init_attr;
280
281 %init_attr = (
282         ia32_attr_t     => "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);",
283         ia32_x87_attr_t =>
284                 "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
285                 "\tinit_ia32_x87_attributes(res);",
286         ia32_asm_attr_t =>
287                 "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
288                 "\tinit_ia32_x87_attributes(res);".
289                 "\tinit_ia32_asm_attributes(res);",
290         ia32_immediate_attr_t =>
291                 "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
292                 "\tinit_ia32_immediate_attributes(res, symconst, symconst_sign, offset);",
293         ia32_copyb_attr_t =>
294                 "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
295                 "\tinit_ia32_copyb_attributes(res, size);",
296         ia32_condcode_attr_t =>
297                 "\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
298                 "\tinit_ia32_condcode_attributes(res, pnc);",
299 );
300
301 %compare_attr = (
302         ia32_attr_t           => "ia32_compare_nodes_attr",
303         ia32_x87_attr_t       => "ia32_compare_x87_attr",
304         ia32_asm_attr_t       => "ia32_compare_asm_attr",
305         ia32_immediate_attr_t => "ia32_compare_immediate_attr",
306         ia32_copyb_attr_t     => "ia32_compare_copyb_attr",
307         ia32_condcode_attr_t  => "ia32_compare_condcode_attr",
308 );
309
310 %operands = (
311 );
312
313 $mode_xmm     = "mode_E";
314 $mode_gp      = "mode_Iu";
315 $mode_flags   = "mode_Iu";
316 $mode_fpcw    = "mode_fpcw";
317 $status_flags = [ "CF", "PF", "AF", "ZF", "SF", "OF" ];
318 $fpcw_flags   = [ "FP_IM", "FP_DM", "FP_ZM", "FP_OM", "FP_UM", "FP_PM",
319                   "FP_PC0", "FP_PC1", "FP_RC0", "FP_RC1", "FP_X" ];
320
321 %nodes = (
322
323 Immediate => {
324         state     => "pinned",
325         op_flags  => "c",
326         irn_flags => "I",
327         reg_req   => { out => [ "gp_NOREG" ] },
328         attr      => "ir_entity *symconst, int symconst_sign, long offset",
329         attr_type => "ia32_immediate_attr_t",
330         latency   => 0,
331         mode      => $mode_gp,
332 },
333
334 Asm => {
335         mode      => "mode_T",
336         arity     => "variable",
337         out_arity => "variable",
338         attr_type => "ia32_asm_attr_t",
339         attr      => "ident *asm_text, const ia32_asm_reg_t *register_map",
340         init_attr => "attr->asm_text = asm_text;\n".
341                      "\tattr->register_map = register_map;\n",
342         latency   => 10,
343         modified_flags => 1,
344 },
345
346 ProduceVal => {
347         op_flags  => "c",
348         irn_flags => "R",
349         reg_req   => { out => [ "gp" ] },
350         emit      => "",
351         units     => [ ],
352         latency   => 0,
353         mode      => $mode_gp,
354         cmp_attr  => "return 1;",
355 },
356
357 #-----------------------------------------------------------------#
358 #  _       _                                         _            #
359 # (_)     | |                                       | |           #
360 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
361 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
362 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
363 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
364 #                   __/ |                                         #
365 #                  |___/                                          #
366 #-----------------------------------------------------------------#
367
368 # commutative operations
369
370 Add => {
371         irn_flags => "R",
372         state     => "exc_pinned",
373         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ], out => [ "in_r4 in_r5", "none", "flags" ] },
374         ins       => [ "base", "index", "mem", "left", "right" ],
375         emit      => '. add%M %binop',
376         am        => "full,binary",
377         units     => [ "GP" ],
378         latency   => 1,
379         mode      => $mode_gp,
380         modified_flags => $status_flags
381 },
382
383 AddMem => {
384         irn_flags => "R",
385         state     => "exc_pinned",
386         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
387         ins       => [ "base", "index", "mem", "val" ],
388         emit      => ". add%M %SI3, %AM",
389         units     => [ "GP" ],
390         latency   => 1,
391         mode      => "mode_M",
392         modified_flags => $status_flags
393 },
394
395 AddMem8Bit => {
396         irn_flags => "R",
397         state     => "exc_pinned",
398         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
399         ins       => [ "base", "index", "mem", "val" ],
400         emit      => ". add%M %SB3, %AM",
401         units     => [ "GP" ],
402         latency   => 1,
403         mode      => "mode_M",
404         modified_flags => $status_flags
405 },
406
407 Adc => {
408         state     => "exc_pinned",
409         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "flags" ], out => [ "in_r4 in_r5" ] },
410         ins       => [ "base", "index", "mem", "left", "right", "eflags" ],
411         emit      => '. adc%M %binop',
412         am        => "full,binary",
413         units     => [ "GP" ],
414         latency   => 1,
415         mode      => $mode_gp,
416         modified_flags => $status_flags
417 },
418
419 l_Add => {
420         op_flags  => "C",
421         reg_req   => { in => [ "none", "none" ], out => [ "none" ] },
422         ins       => [ "left", "right" ],
423 },
424
425 l_Adc => {
426         reg_req   => { in => [ "none", "none", "none" ], out => [ "none" ] },
427         ins       => [ "left", "right", "eflags" ],
428 },
429
430 Mul => {
431         # we should not rematrialize this node. It produces 2 results and has
432         # very strict constrains
433         state     => "exc_pinned",
434         reg_req   => { in => [ "gp", "gp", "none", "eax", "gp" ], out => [ "eax", "edx", "none" ] },
435         ins       => [ "base", "index", "mem", "val_high", "val_low" ],
436         emit      => '. mul%M %unop4',
437         outs      => [ "EAX", "EDX", "M" ],
438         am        => "source,binary",
439         latency   => 10,
440         units     => [ "GP" ],
441         modified_flags => $status_flags
442 },
443
444 l_Mul => {
445         # we should not rematrialize this node. It produces 2 results and has
446         # very strict constrains
447         op_flags  => "C",
448         cmp_attr  => "return 1;",
449         outs      => [ "EAX", "EDX", "M" ],
450         arity     => 2
451 },
452
453 IMul => {
454         irn_flags => "R",
455         state     => "exc_pinned",
456         # TODO: adjust out requirements for the 3 operand form
457         # (no need for should_be_same then)
458         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
459                            out => [ "in_r4 in_r5", "none", "flags" ] },
460         ins       => [ "base", "index", "mem", "left", "right" ],
461         outs      => [ "res", "M", "flags" ],
462         am        => "source,binary",
463         latency   => 5,
464         units     => [ "GP" ],
465         mode      => $mode_gp,
466         modified_flags => $status_flags
467 },
468
469 IMul1OP => {
470         irn_flags => "R",
471         state     => "exc_pinned",
472         reg_req   => { in => [ "gp", "gp", "none", "eax", "gp" ], out => [ "eax", "edx", "none" ] },
473         ins       => [ "base", "index", "mem", "val_high", "val_low" ],
474         emit      => '. imul%M %unop4',
475         outs      => [ "EAX", "EDX", "M" ],
476         am        => "source,binary",
477         latency   => 5,
478         units     => [ "GP" ],
479         modified_flags => $status_flags
480 },
481
482 l_IMul => {
483         # we should not rematrialize this node. It produces 2 results and has
484         # very strict constrains
485         op_flags  => "C",
486         cmp_attr  => "return 1;",
487         outs      => [ "EAX", "EDX", "M" ],
488         arity     => 2
489 },
490
491 And => {
492         irn_flags => "R",
493         state     => "exc_pinned",
494         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ], out => [ "in_r4 in_r5" ] },
495         ins       => [ "base", "index", "mem", "left", "right" ],
496         op_modes  => "commutative | am | immediate | mode_neutral",
497         am        => "full,binary",
498         emit      => '. and%M %binop',
499         units     => [ "GP" ],
500         latency   => 1,
501         mode      => $mode_gp,
502         modified_flags => $status_flags
503 },
504
505 AndMem => {
506         irn_flags => "R",
507         state     => "exc_pinned",
508         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
509         ins       => [ "base", "index", "mem", "val" ],
510         emit      => '. and%M %SI3, %AM',
511         units     => [ "GP" ],
512         latency   => 1,
513         mode      => "mode_M",
514         modified_flags => $status_flags
515 },
516
517 AndMem8Bit => {
518         irn_flags => "R",
519         state     => "exc_pinned",
520         reg_req   => { in => [ "gp", "gp", "none",  "eax ebx ecx edx" ], out => [ "none" ] },
521         ins       => [ "base", "index", "mem", "val" ],
522         emit      => '. and%M %SB3, %AM',
523         units     => [ "GP" ],
524         latency   => 1,
525         mode      => "mode_M",
526         modified_flags => $status_flags
527 },
528
529 Or => {
530         irn_flags => "R",
531         state     => "exc_pinned",
532         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ], out => [ "in_r4 in_r5" ] },
533         ins       => [ "base", "index", "mem", "left", "right" ],
534         am        => "full,binary",
535         emit      => '. or%M %binop',
536         units     => [ "GP" ],
537         latency   => 1,
538         mode      => $mode_gp,
539         modified_flags => $status_flags
540 },
541
542 OrMem => {
543         irn_flags => "R",
544         state     => "exc_pinned",
545         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
546         ins       => [ "base", "index", "mem", "val" ],
547         emit      => '. or%M %SI3, %AM',
548         units     => [ "GP" ],
549         latency   => 1,
550         mode      => "mode_M",
551         modified_flags => $status_flags
552 },
553
554 OrMem8Bit => {
555         irn_flags => "R",
556         state     => "exc_pinned",
557         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
558         ins       => [ "base", "index", "mem", "val" ],
559         emit      => '. or%M %SB3, %AM',
560         units     => [ "GP" ],
561         latency   => 1,
562         mode      => "mode_M",
563         modified_flags => $status_flags
564 },
565
566 Xor => {
567         irn_flags => "R",
568         state     => "exc_pinned",
569         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ], out => [ "in_r4 in_r5" ] },
570         ins       => [ "base", "index", "mem", "left", "right" ],
571         am        => "full,binary",
572         emit      => '. xor%M %binop',
573         units     => [ "GP" ],
574         latency   => 1,
575         mode      => $mode_gp,
576         modified_flags => $status_flags
577 },
578
579 XorMem => {
580         irn_flags => "R",
581         state     => "exc_pinned",
582         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
583         ins       => [ "base", "index", "mem", "val" ],
584         emit      => '. xor%M %SI3, %AM',
585         units     => [ "GP" ],
586         latency   => 1,
587         mode      => "mode_M",
588         modified_flags => $status_flags
589 },
590
591 XorMem8Bit => {
592         irn_flags => "R",
593         state     => "exc_pinned",
594         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
595         ins       => [ "base", "index", "mem", "val" ],
596         emit      => '. xor%M %SB3, %AM',
597         units     => [ "GP" ],
598         latency   => 1,
599         mode      => "mode_M",
600         modified_flags => $status_flags
601 },
602
603 # not commutative operations
604
605 Sub => {
606         irn_flags => "R",
607         state     => "exc_pinned",
608         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ], out => [ "in_r4", "none", "flags" ] },
609         ins       => [ "base", "index", "mem", "left", "right" ],
610         am        => "full,binary",
611         emit      => '. sub%M %binop',
612         units     => [ "GP" ],
613         latency   => 1,
614         mode      => $mode_gp,
615         modified_flags => $status_flags
616 },
617
618 SubMem => {
619         irn_flags => "R",
620         state     => "exc_pinned",
621         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
622         ins       => [ "base", "index", "mem", "val" ],
623         emit      => '. sub%M %SI3, %AM',
624         units     => [ "GP" ],
625         latency   => 1,
626         mode      => 'mode_M',
627         modified_flags => $status_flags
628 },
629
630 SubMem8Bit => {
631         irn_flags => "R",
632         state     => "exc_pinned",
633         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
634         ins       => [ "base", "index", "mem", "val" ],
635         emit      => '. sub%M %SB3, %AM',
636         units     => [ "GP" ],
637         latency   => 1,
638         mode      => 'mode_M',
639         modified_flags => $status_flags
640 },
641
642 Sbb => {
643         state     => "exc_pinned",
644         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "flags" ], out => [ "in_r4 !in_r5" ] },
645         ins       => [ "base", "index", "mem", "left", "right", "eflags" ],
646         am        => "full,binary",
647         emit      => '. sbb%M %binop',
648         units     => [ "GP" ],
649         latency   => 1,
650         mode      => $mode_gp,
651         modified_flags => $status_flags
652 },
653
654 l_Sub => {
655         reg_req   => { in => [ "none", "none" ], out => [ "none" ] },
656         ins       => [ "left", "right" ],
657 },
658
659 l_Sbb => {
660         reg_req   => { in => [ "none", "none", "none" ], out => [ "none" ] },
661         ins       => [ "left", "right", "eflags" ],
662 },
663
664 IDiv => {
665         op_flags  => "F|L",
666         state     => "exc_pinned",
667         reg_req   => { in => [ "gp", "gp", "none", "eax", "edx", "gp" ], out => [ "eax", "none", "none", "edx" ] },
668         ins       => [ "base", "index", "mem", "left_low", "left_high", "right" ],
669         outs      => [ "div_res", "M", "unused", "mod_res" ],
670         am        => "source,ternary",
671         emit      => ". idiv%M %unop5",
672         latency   => 25,
673         units     => [ "GP" ],
674         modified_flags => $status_flags
675 },
676
677 Div => {
678         op_flags  => "F|L",
679         state     => "exc_pinned",
680         reg_req   => { in => [ "gp", "gp", "none", "eax", "edx", "gp" ], out => [ "eax", "none", "none", "edx" ] },
681         ins       => [ "base", "index", "mem", "left_low", "left_high", "right" ],
682         outs      => [ "div_res", "M", "unused", "mod_res" ],
683         am        => "source,ternary",
684         emit      => ". div%M %unop5",
685         latency   => 25,
686         units     => [ "GP" ],
687         modified_flags => $status_flags
688 },
689
690 Shl => {
691         irn_flags => "R",
692         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
693         ins       => [ "left", "right" ],
694         emit      => '. shl %SB1, %S0',
695         units     => [ "GP" ],
696         latency   => 1,
697         mode      => $mode_gp,
698         modified_flags => $status_flags
699 },
700
701 ShlMem => {
702         irn_flags => "R",
703         state     => "exc_pinned",
704         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
705         ins       => [ "base", "index", "mem", "count" ],
706         emit      => '. shl%M %SB3, %AM',
707         units     => [ "GP" ],
708         latency   => 1,
709         mode      => "mode_M",
710         modified_flags => $status_flags
711 },
712
713 l_ShlDep => {
714         cmp_attr  => "return 1;",
715         ins       => [ "left", "right", "dep" ],
716         # value, cnt, dependency
717         arity     => 3
718 },
719
720 ShlD => {
721         irn_flags => "R",
722         # see ShrD about the strange out constraint
723         reg_req   => { in => [ "gp", "gp", "ecx" ], out => [ "!in" ] },
724         ins       => [ "left_high", "left_low", "right" ],
725         emit      => ". shld%M %SB2, %S1, %S0\n".
726                      ". movl %S0, %D0",
727         latency   => 6,
728         units     => [ "GP" ],
729         mode      => $mode_gp,
730         modified_flags => $status_flags
731 },
732
733 l_ShlD => {
734         cmp_attr  => "return 1;",
735         ins       => [ "high", "low", "count" ],
736         arity     => 3,
737 },
738
739 Shr => {
740         irn_flags => "R",
741         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
742         ins       => [ "val", "count" ],
743         emit      => '. shr %SB1, %S0',
744         units     => [ "GP" ],
745         mode      => $mode_gp,
746         latency   => 1,
747         modified_flags => $status_flags
748 },
749
750 ShrMem => {
751         irn_flags => "R",
752         state     => "exc_pinned",
753         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
754         ins       => [ "base", "index", "mem", "count" ],
755         emit      => '. shr%M %SB3, %AM',
756         units     => [ "GP" ],
757         mode      => "mode_M",
758         latency   => 1,
759         modified_flags => $status_flags
760 },
761
762 l_ShrDep => {
763         cmp_attr  => "return 1;",
764         ins       => [ "left", "right", "dep" ],
765         # value, cnt, dependency
766         arity     => 3
767 },
768
769 ShrD => {
770         # What's going on with the out constraint here? We would like to write
771         # "in_r2" and be done. However in firm we only support should_be_same
772         # constraints at the moment. Which means they could be non-fullfilled in
773         # some cases. Now when all values happen to live through the node, out
774         # is ecx and in_r2 not ecx, then we're screwed. Because in this case we
775         # need a 4th Register.
776         #
777         # The best solution for this is extending the register allocator to support
778         # must_be_same constraints which create a copy when the in_r2 value
779         # lives through (this ensures that we have the 4th register in the cases
780         # when we need it and can always fix the situation).
781         #
782         # For now I'm doing this ultra ugly !in hack which allocates 4 registers
783         # and creates an extra mov
784         irn_flags => "R",
785         reg_req   => { in => [ "gp", "gp", "ecx" ], out => [ "!in" ] },
786         ins       => [ "left_high", "left_low", "right" ],
787         emit      => ". shrd%M %SB2, %S1, %S0\n".
788                      ". movl   %S0, %D0",
789         latency   => 6,
790         units     => [ "GP" ],
791         mode      => $mode_gp,
792         modified_flags => $status_flags
793 },
794
795 l_ShrD => {
796         cmp_attr  => "return 1;",
797         arity     => 3,
798         ins       => [ "high", "low", "count" ],
799 },
800
801 Sar => {
802         irn_flags => "R",
803         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
804         ins       => [ "val", "count" ],
805         emit      => '. sar %SB1, %S0',
806         units     => [ "GP" ],
807         latency   => 1,
808         mode      => $mode_gp,
809         modified_flags => $status_flags
810 },
811
812 SarMem => {
813         irn_flags => "R",
814         state     => "exc_pinned",
815         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
816         ins       => [ "base", "index", "mem", "count" ],
817         emit      => '. sar%M %SB3, %AM',
818         units     => [ "GP" ],
819         latency   => 1,
820         mode      => "mode_M",
821         modified_flags => $status_flags
822 },
823
824 l_SarDep => {
825         cmp_attr  => "return 1;",
826         ins       => [ "left", "right", "dep" ],
827         # value, cnt, dependency
828         arity     => 3
829 },
830
831 Ror => {
832         irn_flags => "R",
833         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
834         ins       => [ "val", "count" ],
835         emit      => '. ror %SB1, %S0',
836         units     => [ "GP" ],
837         latency   => 1,
838         mode      => $mode_gp,
839         modified_flags => $status_flags
840 },
841
842 RorMem => {
843         irn_flags => "R",
844         state     => "exc_pinned",
845         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
846         ins       => [ "base", "index", "mem", "count" ],
847         emit      => '. ror%M %SB3, %AM',
848         units     => [ "GP" ],
849         latency   => 1,
850         mode      => "mode_M",
851         modified_flags => $status_flags
852 },
853
854 Rol => {
855         irn_flags => "R",
856         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
857         ins       => [ "val", "count" ],
858         emit      => '. rol %SB1, %S0',
859         units     => [ "GP" ],
860         latency   => 1,
861         mode      => $mode_gp,
862         modified_flags => $status_flags
863 },
864
865 RolMem => {
866         irn_flags => "R",
867         state     => "exc_pinned",
868         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
869         ins       => [ "base", "index", "mem", "count" ],
870         emit      => '. rol%M %SB3, %AM',
871         units     => [ "GP" ],
872         latency   => 1,
873         mode      => "mode_M",
874         modified_flags => $status_flags
875 },
876
877 # unary operations
878
879 Neg => {
880         irn_flags => "R",
881         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
882         emit      => '. neg %S0',
883         ins       => [ "val" ],
884         units     => [ "GP" ],
885         latency   => 1,
886         mode      => $mode_gp,
887         modified_flags => $status_flags
888 },
889
890 NegMem => {
891         irn_flags => "R",
892         state     => "exc_pinned",
893         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
894         ins       => [ "base", "index", "mem" ],
895         emit      => '. neg%M %AM',
896         units     => [ "GP" ],
897         latency   => 1,
898         mode      => "mode_M",
899         modified_flags => $status_flags
900 },
901
902 Minus64Bit => {
903         irn_flags => "R",
904         reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1", "gp" ] },
905         outs      => [ "low_res", "high_res" ],
906         units     => [ "GP" ],
907         latency   => 3,
908         modified_flags => $status_flags
909 },
910
911
912 Inc => {
913         irn_flags => "R",
914         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
915         emit      => '. inc %S0',
916         units     => [ "GP" ],
917         mode      => $mode_gp,
918         latency   => 1,
919         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
920 },
921
922 IncMem => {
923         irn_flags => "R",
924         state     => "exc_pinned",
925         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
926         ins       => [ "base", "index", "mem" ],
927         emit      => '. inc%M %AM',
928         units     => [ "GP" ],
929         mode      => "mode_M",
930         latency   => 1,
931         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
932 },
933
934 Dec => {
935         irn_flags => "R",
936         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
937         emit      => '. dec %S0',
938         units     => [ "GP" ],
939         mode      => $mode_gp,
940         latency   => 1,
941         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
942 },
943
944 DecMem => {
945         irn_flags => "R",
946         state     => "exc_pinned",
947         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
948         ins       => [ "base", "index", "mem" ],
949         emit      => '. dec%M %AM',
950         units     => [ "GP" ],
951         mode      => "mode_M",
952         latency   => 1,
953         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
954 },
955
956 Not => {
957         irn_flags => "R",
958         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
959         ins       => [ "val" ],
960         emit      => '. not %S0',
961         units     => [ "GP" ],
962         latency   => 1,
963         mode      => $mode_gp,
964 },
965
966 NotMem => {
967         irn_flags => "R",
968         state     => "exc_pinned",
969         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
970         ins       => [ "base", "index", "mem" ],
971         emit      => '. not%M %AM',
972         units     => [ "GP" ],
973         latency   => 1,
974         mode      => "mode_M",
975 },
976
977 # other operations
978
979 Cmp => {
980         irn_flags => "R",
981         state     => "exc_pinned",
982         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ] , out => [ "flags" ] },
983         ins       => [ "base", "index", "mem", "left", "right" ],
984         outs      => [ "eflags" ],
985         am        => "source,binary",
986         emit      => '. cmp%M %binop',
987         attr      => "int ins_permuted, int cmp_unsigned",
988         init_attr => "attr->data.ins_permuted   = ins_permuted;\n".
989                      "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
990         latency   => 1,
991         units     => [ "GP" ],
992         mode      => $mode_flags,
993         modified_flags => $status_flags
994 },
995
996 Cmp8Bit => {
997         irn_flags => "R",
998         state     => "exc_pinned",
999         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx", "eax ebx ecx edx" ] , out => [ "flags" ] },
1000         ins       => [ "base", "index", "mem", "left", "right" ],
1001         outs      => [ "eflags" ],
1002         am        => "source,binary",
1003         emit      => '. cmpb %binop',
1004         attr      => "int ins_permuted, int cmp_unsigned",
1005         init_attr => "attr->data.ins_permuted   = ins_permuted;\n".
1006                      "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
1007         latency   => 1,
1008         units     => [ "GP" ],
1009         mode      => $mode_flags,
1010         modified_flags => $status_flags
1011 },
1012
1013 Test => {
1014         irn_flags => "R",
1015         state     => "exc_pinned",
1016         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ] , out => [ "flags" ] },
1017         ins       => [ "base", "index", "mem", "left", "right" ],
1018         outs      => [ "eflags" ],
1019         am        => "source,binary",
1020         emit      => '. test%M %binop',
1021         attr      => "int ins_permuted, int cmp_unsigned",
1022         init_attr => "attr->data.ins_permuted = ins_permuted;\n".
1023                      "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
1024         latency   => 1,
1025         units     => [ "GP" ],
1026         mode      => $mode_flags,
1027         modified_flags => $status_flags
1028 },
1029
1030 Test8Bit => {
1031         irn_flags => "R",
1032         state     => "exc_pinned",
1033         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx", "eax ebx ecx edx" ] , out => [ "flags" ] },
1034         ins       => [ "base", "index", "mem", "left", "right" ],
1035         outs      => [ "eflags" ],
1036         am        => "source,binary",
1037         emit      => '. testb %binop',
1038         attr      => "int ins_permuted, int cmp_unsigned",
1039         init_attr => "attr->data.ins_permuted = ins_permuted;\n".
1040                      "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
1041         latency   => 1,
1042         units     => [ "GP" ],
1043         mode      => $mode_flags,
1044         modified_flags => $status_flags
1045 },
1046
1047 Set => {
1048         #irn_flags => "R",
1049         reg_req   => { in => [ "eflags" ], out => [ "eax ebx ecx edx" ] },
1050         ins       => [ "eflags" ],
1051         attr_type => "ia32_condcode_attr_t",
1052         attr      => "pn_Cmp pnc, int ins_permuted",
1053         init_attr => "attr->attr.data.ins_permuted = ins_permuted;\n".
1054                       "\tset_ia32_ls_mode(res, mode_Bu);\n",
1055         emit      => '. set%CMP0 %DB0',
1056         latency   => 1,
1057         units     => [ "GP" ],
1058         mode      => $mode_gp,
1059 },
1060
1061 SetMem => {
1062         #irn_flags => "R",
1063         state     => "exc_pinned",
1064         reg_req   => { in => [ "gp", "gp", "none", "eflags" ], out => [ "none" ] },
1065         ins       => [ "base", "index", "mem","eflags" ],
1066         attr_type => "ia32_condcode_attr_t",
1067         attr      => "pn_Cmp pnc, int ins_permuted",
1068         init_attr => "attr->attr.data.ins_permuted = ins_permuted;\n".
1069                       "\tset_ia32_ls_mode(res, mode_Bu);\n",
1070         emit      => '. set%CMP3 %AM',
1071         latency   => 1,
1072         units     => [ "GP" ],
1073         mode      => 'mode_M',
1074 },
1075
1076 CMov => {
1077         #irn_flags => "R",
1078         # (note: leave the false,true order intact to make it compatible with other
1079         #  ia32_binary ops)
1080         state     => "exc_pinned",
1081         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "eflags" ], out => [ "in_r4 in_r5" ] },
1082         ins       => [ "base", "index", "mem", "val_false", "val_true", "eflags" ],
1083         am        => "source,binary",
1084         attr_type => "ia32_condcode_attr_t",
1085         attr      => "int ins_permuted, pn_Cmp pnc",
1086         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1087         latency   => 1,
1088         units     => [ "GP" ],
1089         mode      => $mode_gp,
1090 },
1091
1092 Jcc => {
1093         state     => "pinned",
1094         op_flags  => "L|X|Y",
1095         reg_req   => { in  => [ "eflags" ], out => [ "none", "none" ] },
1096         ins       => [ "eflags" ],
1097         outs      => [ "false", "true" ],
1098         attr_type => "ia32_condcode_attr_t",
1099         attr      => "pn_Cmp pnc",
1100         latency   => 2,
1101         units     => [ "BRANCH" ],
1102 },
1103
1104 SwitchJmp => {
1105         state     => "pinned",
1106         op_flags  => "L|X|Y",
1107         reg_req   => { in => [ "gp" ], out => [ "none" ] },
1108         mode      => "mode_T",
1109         attr_type => "ia32_condcode_attr_t",
1110         attr      => "pn_Cmp pnc",
1111         latency   => 3,
1112         units     => [ "BRANCH" ],
1113         modified_flags => $status_flags,
1114 },
1115
1116 IJmp => {
1117         state     => "pinned",
1118         op_flags  => "X",
1119         reg_req   => { in => [ "gp", "gp", "none", "gp" ] },
1120         ins       => [ "base", "index", "mem", "target" ],
1121         am        => "source,unary",
1122         emit      => '. jmp *%unop3',
1123         latency   => 1,
1124         units     => [ "BRANCH" ],
1125         mode      => "mode_X",
1126 },
1127
1128 Const => {
1129         op_flags  => "c",
1130         irn_flags => "R",
1131         reg_req   => { out => [ "gp" ] },
1132         units     => [ "GP" ],
1133         attr      => "ir_entity *symconst, int symconst_sign, long offset",
1134         attr_type => "ia32_immediate_attr_t",
1135         latency   => 1,
1136         mode      => $mode_gp,
1137 },
1138
1139 Unknown_GP => {
1140         state     => "pinned",
1141         op_flags  => "c",
1142         irn_flags => "I",
1143         reg_req   => { out => [ "gp_UKNWN" ] },
1144         units     => [],
1145         emit      => "",
1146         latency   => 0,
1147         mode      => $mode_gp
1148 },
1149
1150 Unknown_VFP => {
1151         state     => "pinned",
1152         op_flags  => "c",
1153         irn_flags => "I",
1154         reg_req   => { out => [ "vfp_UKNWN" ] },
1155         units     => [],
1156         emit      => "",
1157         mode      => "mode_E",
1158         latency   => 0,
1159         attr_type => "ia32_x87_attr_t",
1160 },
1161
1162 Unknown_XMM => {
1163         state     => "pinned",
1164         op_flags  => "c",
1165         irn_flags => "I",
1166         reg_req   => { out => [ "xmm_UKNWN" ] },
1167         units     => [],
1168         emit      => "",
1169         latency   => 0,
1170         mode      => "mode_E"
1171 },
1172
1173 NoReg_GP => {
1174         state     => "pinned",
1175         op_flags  => "c",
1176         irn_flags => "I",
1177         reg_req   => { out => [ "gp_NOREG" ] },
1178         units     => [],
1179         emit      => "",
1180         latency   => 0,
1181         mode      => $mode_gp
1182 },
1183
1184 NoReg_VFP => {
1185         state     => "pinned",
1186         op_flags  => "c",
1187         irn_flags => "I",
1188         reg_req   => { out => [ "vfp_NOREG" ] },
1189         units     => [],
1190         emit      => "",
1191         mode      => "mode_E",
1192         latency   => 0,
1193         attr_type => "ia32_x87_attr_t",
1194 },
1195
1196 NoReg_XMM => {
1197         state     => "pinned",
1198         op_flags  => "c",
1199         irn_flags => "I",
1200         reg_req   => { out => [ "xmm_NOREG" ] },
1201         units     => [],
1202         emit      => "",
1203         latency   => 0,
1204         mode      => "mode_E"
1205 },
1206
1207 ChangeCW => {
1208         state     => "pinned",
1209         op_flags  => "c",
1210         irn_flags => "I",
1211         reg_req   => { out => [ "fp_cw" ] },
1212         mode      => $mode_fpcw,
1213         latency   => 3,
1214         units     => [ "GP" ],
1215         modified_flags => $fpcw_flags
1216 },
1217
1218 FldCW => {
1219         op_flags  => "L|F",
1220         state     => "pinned",
1221         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "fp_cw" ] },
1222         ins       => [ "base", "index", "mem" ],
1223         latency   => 5,
1224         emit      => ". fldcw %AM",
1225         mode      => $mode_fpcw,
1226         units     => [ "GP" ],
1227         modified_flags => $fpcw_flags
1228 },
1229
1230 FnstCW => {
1231         op_flags  => "L|F",
1232         state     => "pinned",
1233         reg_req   => { in => [ "gp", "gp", "none", "fp_cw" ], out => [ "none" ] },
1234         ins       => [ "base", "index", "mem", "fpcw" ],
1235         latency   => 5,
1236         emit      => ". fnstcw %AM",
1237         mode      => "mode_M",
1238         units     => [ "GP" ],
1239 },
1240
1241 FnstCWNOP => {
1242         op_flags  => "L|F",
1243         state     => "pinned",
1244         reg_req   => { in => [ "fp_cw" ], out => [ "none" ] },
1245         ins       => [ "fpcw" ],
1246         latency   => 0,
1247         emit      => "",
1248         mode      => "mode_M",
1249 },
1250
1251 Cltd => {
1252         # we should not rematrialize this node. It has very strict constraints.
1253         reg_req   => { in => [ "eax", "edx" ], out => [ "edx" ] },
1254         ins       => [ "val", "globbered" ],
1255         emit      => '. cltd',
1256         latency   => 1,
1257         mode      => $mode_gp,
1258         units     => [ "GP" ],
1259 },
1260
1261 # Load / Store
1262 #
1263 # Note that we add additional latency values depending on address mode, so a
1264 # lateny of 0 for load is correct
1265
1266 Load => {
1267         op_flags  => "L|F",
1268         state     => "exc_pinned",
1269         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
1270         ins       => [ "base", "index", "mem" ],
1271         outs      => [ "res", "M" ],
1272         latency   => 0,
1273         emit      => ". mov%SE%ME%.l %AM, %D0",
1274         units     => [ "GP" ],
1275 },
1276
1277 l_Load => {
1278         op_flags  => "L|F",
1279         cmp_attr  => "return 1;",
1280         outs      => [ "res", "M" ],
1281         arity     => 2,
1282 },
1283
1284 l_Store => {
1285         op_flags  => "L|F",
1286         cmp_attr  => "return 1;",
1287         state     => "exc_pinned",
1288         arity     => 3,
1289         mode      => "mode_M",
1290 },
1291
1292 Store => {
1293         op_flags  => "L|F",
1294         state     => "exc_pinned",
1295         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
1296         ins       => [ "base", "index", "mem", "val" ],
1297         emit      => '. mov%M %SI3, %AM',
1298         latency   => 2,
1299         units     => [ "GP" ],
1300         mode      => "mode_M",
1301 },
1302
1303 Store8Bit => {
1304         op_flags  => "L|F",
1305         state     => "exc_pinned",
1306         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => ["none" ] },
1307         ins       => [ "base", "index", "mem", "val" ],
1308         emit      => '. mov%M %SB3, %AM',
1309         latency   => 2,
1310         units     => [ "GP" ],
1311         mode      => "mode_M",
1312 },
1313
1314 Lea => {
1315         irn_flags => "R",
1316         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
1317         ins       => [ "base", "index" ],
1318         emit      => '. leal %AM, %D0',
1319         latency   => 2,
1320         units     => [ "GP" ],
1321         mode      => $mode_gp,
1322 # lea doesn't modify the flags, but setting this seems advantageous since it
1323 # increases chances that the Lea is transformed back to an Add
1324         modified_flags => 1,
1325 },
1326
1327 Push => {
1328         state     => "exc_pinned",
1329         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "esp", "none" ] },
1330         ins       => [ "base", "index", "mem", "val", "stack" ],
1331         emit      => '. push%M %unop4',
1332         outs      => [ "stack:I|S", "M" ],
1333         am        => "source,binary",
1334         latency   => 2,
1335         units     => [ "GP" ],
1336 },
1337
1338 Pop => {
1339         state     => "exc_pinned",
1340         reg_req   => { in => [ "gp", "gp", "none", "esp" ], out => [ "gp", "none", "none", "esp" ] },
1341         emit      => '. pop%M %DAM0',
1342         outs      => [ "res", "M", "unused", "stack:I|S" ],
1343         ins       => [ "base", "index", "mem", "stack" ],
1344         am        => "dest,unary",
1345         latency   => 3, # Pop is more expensive than Push on Athlon
1346         units     => [ "GP" ],
1347 },
1348
1349 Enter => {
1350         reg_req   => { in => [ "esp" ], out => [ "ebp", "esp", "none" ] },
1351         emit      => '. enter',
1352         outs      => [ "frame:I", "stack:I|S", "M" ],
1353         latency   => 15,
1354         units     => [ "GP" ],
1355 },
1356
1357 Leave => {
1358         reg_req   => { in => [ "esp", "ebp" ], out => [ "ebp", "esp" ] },
1359         emit      => '. leave',
1360         outs      => [ "frame:I", "stack:I|S" ],
1361         latency   => 3,
1362         units     => [ "GP" ],
1363 },
1364
1365 AddSP => {
1366         irn_flags => "I",
1367         state     => "pinned",
1368         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "in_r4", "none" ] },
1369         ins       => [ "base", "index", "mem", "stack", "size" ],
1370         am        => "source,binary",
1371         emit      => '. addl %binop',
1372         latency   => 1,
1373         outs      => [ "stack:S", "M" ],
1374         units     => [ "GP" ],
1375         modified_flags => $status_flags
1376 },
1377
1378 SubSP => {
1379 #irn_flags => "I",
1380         state     => "pinned",
1381         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "in_r4", "gp", "none" ] },
1382         ins       => [ "base", "index", "mem", "stack", "size" ],
1383         am        => "source,binary",
1384         emit      => ". subl %binop\n".
1385                      ". movl %%esp, %D1",
1386         latency   => 2,
1387         outs      => [ "stack:I|S", "addr", "M" ],
1388         units     => [ "GP" ],
1389         modified_flags => $status_flags
1390 },
1391
1392 LdTls => {
1393         irn_flags => "R",
1394         reg_req   => { out => [ "gp" ] },
1395         units     => [ "GP" ],
1396         latency   => 1,
1397 },
1398
1399
1400 #-----------------------------------------------------------------------------#
1401 #   _____ _____ ______    __ _             _                     _            #
1402 #  / ____/ ____|  ____|  / _| |           | |                   | |           #
1403 # | (___| (___ | |__    | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1404 #  \___ \\___ \|  __|   |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1405 #  ____) |___) | |____  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
1406 # |_____/_____/|______| |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1407 #-----------------------------------------------------------------------------#
1408
1409 xZero => {
1410         irn_flags => "R",
1411         reg_req   => { out => [ "xmm" ] },
1412         emit      => '. xorp%XSD %D0, %D0',
1413         latency   => 3,
1414         units     => [ "SSE" ],
1415         mode      => "mode_E",
1416 },
1417
1418 # commutative operations
1419
1420 xAdd => {
1421         irn_flags => "R",
1422         state     => "exc_pinned",
1423         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1424         ins       => [ "base", "index", "mem", "left", "right" ],
1425         am        => "source,binary",
1426         emit      => '. add%XXM %binop',
1427         latency   => 4,
1428         units     => [ "SSE" ],
1429         mode      => "mode_E",
1430 },
1431
1432 xMul => {
1433         irn_flags => "R",
1434         state     => "exc_pinned",
1435         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1436         ins       => [ "base", "index", "mem", "left", "right" ],
1437         am        => "source,binary",
1438         emit      => '. mul%XXM %binop',
1439         latency   => 4,
1440         units     => [ "SSE" ],
1441         mode      => "mode_E",
1442 },
1443
1444 xMax => {
1445         irn_flags => "R",
1446         state     => "exc_pinned",
1447         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1448         ins       => [ "base", "index", "mem", "left", "right" ],
1449         am        => "source,binary",
1450         emit      => '. max%XXM %binop',
1451         latency   => 2,
1452         units     => [ "SSE" ],
1453         mode      => "mode_E",
1454 },
1455
1456 xMin => {
1457         irn_flags => "R",
1458         state     => "exc_pinned",
1459         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1460         ins       => [ "base", "index", "mem", "left", "right" ],
1461         am        => "source,binary",
1462         emit      => '. min%XXM %binop',
1463         latency   => 2,
1464         units     => [ "SSE" ],
1465         mode      => "mode_E",
1466 },
1467
1468 xAnd => {
1469         irn_flags => "R",
1470         state     => "exc_pinned",
1471         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1472         ins       => [ "base", "index", "mem", "left", "right" ],
1473         am        => "source,binary",
1474         emit      => '. andp%XSD %binop',
1475         latency   => 3,
1476         units     => [ "SSE" ],
1477         mode      => "mode_E",
1478 },
1479
1480 xOr => {
1481         irn_flags => "R",
1482         state     => "exc_pinned",
1483         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1484         ins       => [ "base", "index", "mem", "left", "right" ],
1485         am        => "source,binary",
1486         emit      => '. orp%XSD %binop',
1487         latency   => 3,
1488         units     => [ "SSE" ],
1489         mode      => "mode_E",
1490 },
1491
1492 xXor => {
1493         irn_flags => "R",
1494         state     => "exc_pinned",
1495         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1496         ins       => [ "base", "index", "mem", "left", "right" ],
1497         am        => "source,binary",
1498         emit      => '. xorp%XSD %binop',
1499         latency   => 3,
1500         units     => [ "SSE" ],
1501         mode      => "mode_E",
1502 },
1503
1504 # not commutative operations
1505
1506 xAndNot => {
1507         irn_flags => "R",
1508         state     => "exc_pinned",
1509         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 !in_r5" ] },
1510         ins       => [ "base", "index", "mem", "left", "right" ],
1511         am        => "source,binary",
1512         emit      => '. andnp%XSD %binop',
1513         latency   => 3,
1514         units     => [ "SSE" ],
1515         mode      => "mode_E",
1516 },
1517
1518 xSub => {
1519         irn_flags => "R",
1520         state     => "exc_pinned",
1521         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4" ] },
1522         ins       => [ "base", "index", "mem", "left", "right" ],
1523         am        => "source,binary",
1524         emit      => '. sub%XXM %binop',
1525         latency   => 4,
1526         units     => [ "SSE" ],
1527         mode      => "mode_E",
1528 },
1529
1530 xDiv => {
1531         irn_flags => "R",
1532         state     => "exc_pinned",
1533         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 !in_r5", "none" ] },
1534         ins       => [ "base", "index", "mem", "left", "right" ],
1535         am        => "source,binary",
1536         outs      => [ "res", "M" ],
1537         emit      => '. div%XXM %binop',
1538         latency   => 16,
1539         units     => [ "SSE" ],
1540 },
1541
1542 # other operations
1543
1544 Ucomi => {
1545         irn_flags => "R",
1546         state     => "exc_pinned",
1547         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "eflags" ] },
1548         ins       => [ "base", "index", "mem", "left", "right" ],
1549         outs      => [ "flags" ],
1550         am        => "source,binary",
1551         attr      => "int ins_permuted",
1552         init_attr => "attr->data.ins_permuted = ins_permuted;",
1553         emit      => ' .ucomi%XXM %binop',
1554         latency   => 3,
1555         units     => [ "SSE" ],
1556         mode      => $mode_flags,
1557         modified_flags => 1,
1558 },
1559
1560 # Load / Store
1561
1562 xLoad => {
1563         op_flags  => "L|F",
1564         state     => "exc_pinned",
1565         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1566         ins       => [ "base", "index", "mem" ],
1567         emit      => '. mov%XXM %AM, %D0',
1568         attr      => "ir_mode *load_mode",
1569         init_attr => "attr->ls_mode = load_mode;",
1570         outs      => [ "res", "M" ],
1571         latency   => 0,
1572         units     => [ "SSE" ],
1573 },
1574
1575 xStore => {
1576         op_flags => "L|F",
1577         state    => "exc_pinned",
1578         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
1579         ins       => [ "base", "index", "mem", "val" ],
1580         emit     => '. mov%XXM %S3, %AM',
1581         latency  => 0,
1582         units    => [ "SSE" ],
1583         mode     => "mode_M",
1584 },
1585
1586 xStoreSimple => {
1587         op_flags => "L|F",
1588         state    => "exc_pinned",
1589         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
1590         ins      => [ "base", "index", "mem", "val" ],
1591         emit     => '. mov%XXM %S3, %AM',
1592         latency  => 0,
1593         units    => [ "SSE" ],
1594         mode     => "mode_M",
1595 },
1596
1597 CvtSI2SS => {
1598         op_flags => "L|F",
1599         state     => "exc_pinned",
1600         reg_req  => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm" ] },
1601         ins      => [ "base", "index", "mem", "val" ],
1602         am       => "source,unary",
1603         emit     => '. cvtsi2ss %unop3, %D0',
1604         latency  => 2,
1605         units    => [ "SSE" ],
1606         mode     => $mode_xmm
1607 },
1608
1609 CvtSI2SD => {
1610         op_flags => "L|F",
1611         state     => "exc_pinned",
1612         reg_req  => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm" ] },
1613         ins      => [ "base", "index", "mem", "val" ],
1614         am       => "source,unary",
1615         emit     => '. cvtsi2sd %unop3, %D0',
1616         latency  => 2,
1617         units    => [ "SSE" ],
1618         mode     => $mode_xmm
1619 },
1620
1621
1622 l_X87toSSE => {
1623         op_flags => "L|F",
1624         cmp_attr => "return 1;",
1625         arity    => 3,
1626 },
1627
1628 l_SSEtoX87 => {
1629         op_flags => "L|F",
1630         cmp_attr => "return 1;",
1631         arity    => 3,
1632 },
1633
1634 # CopyB
1635
1636 CopyB => {
1637         op_flags  => "F|H",
1638         state     => "pinned",
1639         reg_req   => { in => [ "edi", "esi", "ecx", "none" ], out => [ "edi", "esi", "ecx", "none" ] },
1640         outs      => [ "DST", "SRC", "CNT", "M" ],
1641         attr_type => "ia32_copyb_attr_t",
1642         attr      => "unsigned size",
1643         units     => [ "GP" ],
1644         latency  => 3,
1645 # we don't care about this flag, so no need to mark this node
1646 #       modified_flags => [ "DF" ]
1647 },
1648
1649 CopyB_i => {
1650         op_flags  => "F|H",
1651         state     => "pinned",
1652         reg_req   => { in => [ "edi", "esi", "none" ], out => [  "edi", "esi", "none" ] },
1653         outs      => [ "DST", "SRC", "M" ],
1654         attr_type => "ia32_copyb_attr_t",
1655         attr      => "unsigned size",
1656         units     => [ "GP" ],
1657         latency  => 3,
1658 # we don't care about this flag, so no need to mark this node
1659 #       modified_flags => [ "DF" ]
1660 },
1661
1662 # Conversions
1663
1664 Conv_I2I => {
1665         state     => "exc_pinned",
1666         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "gp", "none" ] },
1667         ins       => [ "base", "index", "mem", "val" ],
1668         am        => "source,unary",
1669         units     => [ "GP" ],
1670         latency   => 1,
1671         attr      => "ir_mode *smaller_mode",
1672         init_attr => "attr->ls_mode = smaller_mode;",
1673         mode      => $mode_gp,
1674 },
1675
1676 Conv_I2I8Bit => {
1677         state     => "exc_pinned",
1678         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "gp", "none" ] },
1679         ins       => [ "base", "index", "mem", "val" ],
1680         am        => "source,unary",
1681         units     => [ "GP" ],
1682         latency   => 1,
1683         attr      => "ir_mode *smaller_mode",
1684         init_attr => "attr->ls_mode = smaller_mode;",
1685         mode      => $mode_gp,
1686 },
1687
1688 Conv_I2FP => {
1689         state     => "exc_pinned",
1690         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm", "none" ] },
1691         ins       => [ "base", "index", "mem", "val" ],
1692         am        => "source,unary",
1693         latency   => 10,
1694         units     => [ "SSE" ],
1695         mode      => "mode_E",
1696 },
1697
1698 Conv_FP2I => {
1699         state     => "exc_pinned",
1700         reg_req   => { in => [ "gp", "gp", "none", "xmm" ], out => [ "gp", "none" ] },
1701         ins       => [ "base", "index", "mem", "val" ],
1702         am        => "source,unary",
1703         latency   => 10,
1704         units     => [ "SSE" ],
1705         mode      => $mode_gp,
1706 },
1707
1708 Conv_FP2FP => {
1709         state     => "exc_pinned",
1710         reg_req   => { in => [ "gp", "gp", "none", "xmm" ], out => [ "xmm", "none" ] },
1711         ins       => [ "base", "index", "mem", "val" ],
1712         am        => "source,unary",
1713         latency   => 8,
1714         units     => [ "SSE" ],
1715         mode      => "mode_E",
1716 },
1717
1718 #----------------------------------------------------------#
1719 #        _      _               _    __ _             _    #
1720 #       (_)    | |             | |  / _| |           | |   #
1721 # __   ___ _ __| |_ _   _  __ _| | | |_| | ___   __ _| |_  #
1722 # \ \ / / | '__| __| | | |/ _` | | |  _| |/ _ \ / _` | __| #
1723 #  \ V /| | |  | |_| |_| | (_| | | | | | | (_) | (_| | |_  #
1724 #   \_/ |_|_|   \__|\__,_|\__,_|_| |_| |_|\___/ \__,_|\__| #
1725 #                 | |                                      #
1726 #  _ __   ___   __| | ___  ___                             #
1727 # | '_ \ / _ \ / _` |/ _ \/ __|                            #
1728 # | | | | (_) | (_| |  __/\__ \                            #
1729 # |_| |_|\___/ \__,_|\___||___/                            #
1730 #----------------------------------------------------------#
1731
1732 # rematerialisation disabled for all float nodes for now, because the fpcw
1733 # handler runs before spilling and we might end up with wrong fpcw then
1734
1735 vfadd => {
1736 #       irn_flags => "R",
1737         state     => "exc_pinned",
1738         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1739         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1740         am        => "source,binary",
1741         latency   => 4,
1742         units     => [ "VFP" ],
1743         mode      => "mode_E",
1744         attr_type => "ia32_x87_attr_t",
1745 },
1746
1747 vfmul => {
1748 #       irn_flags => "R",
1749         state     => "exc_pinned",
1750         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1751         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1752         am        => "source,binary",
1753         latency   => 4,
1754         units     => [ "VFP" ],
1755         mode      => "mode_E",
1756         attr_type => "ia32_x87_attr_t",
1757 },
1758
1759 vfsub => {
1760 #       irn_flags => "R",
1761         state     => "exc_pinned",
1762         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1763         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1764         am        => "source,binary",
1765         latency   => 4,
1766         units     => [ "VFP" ],
1767         mode      => "mode_E",
1768         attr_type => "ia32_x87_attr_t",
1769 },
1770
1771 vfdiv => {
1772         state     => "exc_pinned",
1773         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp", "none" ] },
1774         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1775         am        => "source,binary",
1776         outs      => [ "res", "M" ],
1777         latency   => 20,
1778         units     => [ "VFP" ],
1779         attr_type => "ia32_x87_attr_t",
1780 },
1781
1782 vfprem => {
1783         reg_req   => { in => [ "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1784         ins       => [ "left", "right", "fpcw" ],
1785         latency   => 20,
1786         units     => [ "VFP" ],
1787         mode      => "mode_E",
1788         attr_type => "ia32_x87_attr_t",
1789 },
1790
1791 vfabs => {
1792         irn_flags => "R",
1793         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1794         ins       => [ "value" ],
1795         latency   => 2,
1796         units     => [ "VFP" ],
1797         mode      => "mode_E",
1798         attr_type => "ia32_x87_attr_t",
1799 },
1800
1801 vfchs => {
1802         irn_flags => "R",
1803         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1804         ins       => [ "value" ],
1805         latency   => 2,
1806         units     => [ "VFP" ],
1807         mode      => "mode_E",
1808         attr_type => "ia32_x87_attr_t",
1809 },
1810
1811 # virtual Load and Store
1812
1813 vfld => {
1814         irn_flags => "R",
1815         op_flags  => "L|F",
1816         state     => "exc_pinned",
1817         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1818         ins       => [ "base", "index", "mem" ],
1819         outs      => [ "res", "M" ],
1820         attr      => "ir_mode *load_mode",
1821         init_attr => "attr->attr.ls_mode = load_mode;",
1822         latency   => 2,
1823         units     => [ "VFP" ],
1824         attr_type => "ia32_x87_attr_t",
1825 },
1826
1827 vfst => {
1828         irn_flags => "R",
1829         op_flags  => "L|F",
1830         state     => "exc_pinned",
1831         reg_req   => { in => [ "gp", "gp", "none", "vfp" ] },
1832         ins       => [ "base", "index", "mem", "val" ],
1833         attr      => "ir_mode *store_mode",
1834         init_attr => "attr->attr.ls_mode = store_mode;",
1835         latency   => 2,
1836         units     => [ "VFP" ],
1837         mode      => "mode_M",
1838         attr_type => "ia32_x87_attr_t",
1839 },
1840
1841 # Conversions
1842
1843 vfild => {
1844         state     => "exc_pinned",
1845         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1846         outs      => [ "res", "M" ],
1847         ins       => [ "base", "index", "mem" ],
1848         latency   => 4,
1849         units     => [ "VFP" ],
1850         attr_type => "ia32_x87_attr_t",
1851 },
1852
1853 l_vfild => {
1854         cmp_attr  => "return 1;",
1855         outs      => [ "res", "M" ],
1856         arity     => 2,
1857 },
1858
1859 vfist => {
1860         state     => "exc_pinned",
1861         reg_req   => { in => [ "gp", "gp", "none", "vfp", "fpcw" ] },
1862         ins       => [ "base", "index", "mem", "val", "fpcw" ],
1863         latency   => 4,
1864         units     => [ "VFP" ],
1865         mode      => "mode_M",
1866         attr_type => "ia32_x87_attr_t",
1867 },
1868
1869 l_vfist => {
1870         cmp_attr  => "return 1;",
1871         state     => "exc_pinned",
1872         arity     => 3,
1873         mode      => "mode_M",
1874 },
1875
1876
1877 # constants
1878
1879 vfldz => {
1880         irn_flags => "R",
1881         reg_req   => { out => [ "vfp" ] },
1882         latency   => 4,
1883         units     => [ "VFP" ],
1884         mode      => "mode_E",
1885         attr_type => "ia32_x87_attr_t",
1886 },
1887
1888 vfld1 => {
1889         irn_flags => "R",
1890         reg_req   => { out => [ "vfp" ] },
1891         latency   => 4,
1892         units     => [ "VFP" ],
1893         mode      => "mode_E",
1894         attr_type => "ia32_x87_attr_t",
1895 },
1896
1897 vfldpi => {
1898         irn_flags => "R",
1899         reg_req   => { out => [ "vfp" ] },
1900         latency   => 4,
1901         units     => [ "VFP" ],
1902         mode      => "mode_E",
1903         attr_type => "ia32_x87_attr_t",
1904 },
1905
1906 vfldln2 => {
1907         irn_flags => "R",
1908         reg_req   => { out => [ "vfp" ] },
1909         latency   => 4,
1910         units     => [ "VFP" ],
1911         mode      => "mode_E",
1912         attr_type => "ia32_x87_attr_t",
1913 },
1914
1915 vfldlg2 => {
1916         irn_flags => "R",
1917         reg_req   => { out => [ "vfp" ] },
1918         latency   => 4,
1919         units     => [ "VFP" ],
1920         mode      => "mode_E",
1921         attr_type => "ia32_x87_attr_t",
1922 },
1923
1924 vfldl2t => {
1925         irn_flags => "R",
1926         reg_req   => { out => [ "vfp" ] },
1927         latency   => 4,
1928         units     => [ "VFP" ],
1929         mode      => "mode_E",
1930         attr_type => "ia32_x87_attr_t",
1931 },
1932
1933 vfldl2e => {
1934         irn_flags => "R",
1935         reg_req   => { out => [ "vfp" ] },
1936         latency   => 4,
1937         units     => [ "VFP" ],
1938         mode      => "mode_E",
1939         attr_type => "ia32_x87_attr_t",
1940 },
1941
1942 # other
1943
1944 vFucomFnstsw => {
1945 # we can't allow to rematerialize this node so we don't have
1946 #  accidently produce Phi(Fucom, Fucom(ins_permuted))
1947 #       irn_flags => "R",
1948         reg_req   => { in => [ "vfp", "vfp" ], out => [ "eax" ] },
1949         ins       => [ "left", "right" ],
1950         outs      => [ "flags" ],
1951         attr      => "int ins_permuted",
1952         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1953         latency   => 3,
1954         units     => [ "VFP" ],
1955         attr_type => "ia32_x87_attr_t",
1956         mode      => $mode_gp
1957 },
1958
1959 vFucomi => {
1960         irn_flags => "R",
1961         reg_req   => { in => [ "vfp", "vfp" ], out => [ "eflags" ] },
1962         ins       => [ "left", "right" ],
1963         outs      => [ "flags" ],
1964         attr      => "int ins_permuted",
1965         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1966         latency   => 3,
1967         units     => [ "VFP" ],
1968         attr_type => "ia32_x87_attr_t",
1969         mode      => $mode_gp
1970 },
1971
1972 vFtstFnstsw => {
1973 #       irn_flags => "R",
1974         reg_req   => { in => [ "vfp" ], out => [ "eax" ] },
1975         ins       => [ "left" ],
1976         outs      => [ "flags" ],
1977         attr      => "int ins_permuted",
1978         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1979         latency   => 3,
1980         units     => [ "VFP" ],
1981         attr_type => "ia32_x87_attr_t",
1982         mode      => $mode_gp
1983 },
1984
1985 Sahf => {
1986         irn_flags => "R",
1987         reg_req   => { in => [ "eax" ], out => [ "eflags" ] },
1988         ins       => [ "val" ],
1989         outs      => [ "flags" ],
1990         emit      => '. sahf',
1991         latency   => 1,
1992         units     => [ "GP" ],
1993         mode      => $mode_flags,
1994 },
1995
1996 #------------------------------------------------------------------------#
1997 #       ___ _____    __ _             _                     _            #
1998 # __  _( _ )___  |  / _| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1999 # \ \/ / _ \  / /  | |_| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
2000 #  >  < (_) |/ /   |  _| | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
2001 # /_/\_\___//_/    |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
2002 #------------------------------------------------------------------------#
2003
2004 # Note: gas is strangely buggy: fdivrp and fdivp as well as fsubrp and fsubp
2005 #       are swapped, we work this around in the emitter...
2006
2007 fadd => {
2008         state     => "exc_pinned",
2009         rd_constructor => "NONE",
2010         reg_req   => { },
2011         emit      => '. fadd%XM %x87_binop',
2012         latency   => 4,
2013         attr_type => "ia32_x87_attr_t",
2014 },
2015
2016 faddp => {
2017         state     => "exc_pinned",
2018         rd_constructor => "NONE",
2019         reg_req   => { },
2020         emit      => '. faddp%XM %x87_binop',
2021         latency   => 4,
2022         attr_type => "ia32_x87_attr_t",
2023 },
2024
2025 fmul => {
2026         state     => "exc_pinned",
2027         rd_constructor => "NONE",
2028         reg_req   => { },
2029         emit      => '. fmul%XM %x87_binop',
2030         latency   => 4,
2031         attr_type => "ia32_x87_attr_t",
2032 },
2033
2034 fmulp => {
2035         state     => "exc_pinned",
2036         rd_constructor => "NONE",
2037         reg_req   => { },
2038         emit      => '. fmulp%XM %x87_binop',,
2039         latency   => 4,
2040         attr_type => "ia32_x87_attr_t",
2041 },
2042
2043 fsub => {
2044         state     => "exc_pinned",
2045         rd_constructor => "NONE",
2046         reg_req   => { },
2047         emit      => '. fsub%XM %x87_binop',
2048         latency   => 4,
2049         attr_type => "ia32_x87_attr_t",
2050 },
2051
2052 fsubp => {
2053         state     => "exc_pinned",
2054         rd_constructor => "NONE",
2055         reg_req   => { },
2056 # see note about gas bugs
2057         emit      => '. fsubrp%XM %x87_binop',
2058         latency   => 4,
2059         attr_type => "ia32_x87_attr_t",
2060 },
2061
2062 fsubr => {
2063         state     => "exc_pinned",
2064         rd_constructor => "NONE",
2065         irn_flags => "R",
2066         reg_req   => { },
2067         emit      => '. fsubr%XM %x87_binop',
2068         latency   => 4,
2069         attr_type => "ia32_x87_attr_t",
2070 },
2071
2072 fsubrp => {
2073         state     => "exc_pinned",
2074         rd_constructor => "NONE",
2075         irn_flags => "R",
2076         reg_req   => { },
2077 # see note about gas bugs
2078         emit      => '. fsubp%XM %x87_binop',
2079         latency   => 4,
2080         attr_type => "ia32_x87_attr_t",
2081 },
2082
2083 fprem => {
2084         rd_constructor => "NONE",
2085         reg_req   => { },
2086         emit      => '. fprem1',
2087         latency   => 20,
2088         attr_type => "ia32_x87_attr_t",
2089 },
2090
2091 # this node is just here, to keep the simulator running
2092 # we can omit this when a fprem simulation function exists
2093 fpremp => {
2094         rd_constructor => "NONE",
2095         reg_req   => { },
2096         emit      => '. fprem1\n'.
2097                      '. fstp %X0',
2098         latency   => 20,
2099         attr_type => "ia32_x87_attr_t",
2100 },
2101
2102 fdiv => {
2103         state     => "exc_pinned",
2104         rd_constructor => "NONE",
2105         reg_req   => { },
2106         emit      => '. fdiv%XM %x87_binop',
2107         latency   => 20,
2108         attr_type => "ia32_x87_attr_t",
2109 },
2110
2111 fdivp => {
2112         state     => "exc_pinned",
2113         rd_constructor => "NONE",
2114         reg_req   => { },
2115 # see note about gas bugs
2116         emit      => '. fdivrp%XM %x87_binop',
2117         latency   => 20,
2118         attr_type => "ia32_x87_attr_t",
2119 },
2120
2121 fdivr => {
2122         state     => "exc_pinned",
2123         rd_constructor => "NONE",
2124         reg_req   => { },
2125         emit      => '. fdivr%XM %x87_binop',
2126         latency   => 20,
2127         attr_type => "ia32_x87_attr_t",
2128 },
2129
2130 fdivrp => {
2131         state     => "exc_pinned",
2132         rd_constructor => "NONE",
2133         reg_req   => { },
2134 # see note about gas bugs
2135         emit      => '. fdivp%XM %x87_binop',
2136         latency   => 20,
2137         attr_type => "ia32_x87_attr_t",
2138 },
2139
2140 fabs => {
2141         rd_constructor => "NONE",
2142         reg_req   => { },
2143         emit      => '. fabs',
2144         latency   => 4,
2145         attr_type => "ia32_x87_attr_t",
2146 },
2147
2148 fchs => {
2149         op_flags  => "R|K",
2150         rd_constructor => "NONE",
2151         reg_req   => { },
2152         emit      => '. fchs',
2153         latency   => 4,
2154         attr_type => "ia32_x87_attr_t",
2155 },
2156
2157 # x87 Load and Store
2158
2159 fld => {
2160         rd_constructor => "NONE",
2161         op_flags  => "R|L|F",
2162         state     => "exc_pinned",
2163         reg_req   => { },
2164         emit      => '. fld%XM %AM',
2165         attr_type => "ia32_x87_attr_t",
2166         latency   => 2,
2167 },
2168
2169 fst => {
2170         rd_constructor => "NONE",
2171         op_flags  => "R|L|F",
2172         state     => "exc_pinned",
2173         reg_req   => { },
2174         emit      => '. fst%XM %AM',
2175         mode      => "mode_M",
2176         attr_type => "ia32_x87_attr_t",
2177         latency   => 2,
2178 },
2179
2180 fstp => {
2181         rd_constructor => "NONE",
2182         op_flags  => "R|L|F",
2183         state     => "exc_pinned",
2184         reg_req   => { },
2185         emit      => '. fstp%XM %AM',
2186         mode      => "mode_M",
2187         attr_type => "ia32_x87_attr_t",
2188         latency   => 2,
2189 },
2190
2191 # Conversions
2192
2193 fild => {
2194         state     => "exc_pinned",
2195         rd_constructor => "NONE",
2196         reg_req   => { },
2197         emit      => '. fild%M %AM',
2198         attr_type => "ia32_x87_attr_t",
2199         latency   => 2,
2200 },
2201
2202 fist => {
2203         state     => "exc_pinned",
2204         rd_constructor => "NONE",
2205         reg_req   => { },
2206         emit      => '. fist%M %AM',
2207         mode      => "mode_M",
2208         attr_type => "ia32_x87_attr_t",
2209         latency   => 2,
2210 },
2211
2212 fistp => {
2213         state     => "exc_pinned",
2214         rd_constructor => "NONE",
2215         reg_req   => { },
2216         emit      => '. fistp%M %AM',
2217         mode      => "mode_M",
2218         attr_type => "ia32_x87_attr_t",
2219         latency   => 2,
2220 },
2221
2222 # constants
2223
2224 fldz => {
2225         op_flags  => "R|c|K",
2226         irn_flags => "R",
2227         reg_req   => { out => [ "vfp" ] },
2228         emit      => '. fldz',
2229         attr_type => "ia32_x87_attr_t",
2230         latency   => 2,
2231 },
2232
2233 fld1 => {
2234         op_flags  => "R|c|K",
2235         irn_flags => "R",
2236         reg_req   => { out => [ "vfp" ] },
2237         emit      => '. fld1',
2238         attr_type => "ia32_x87_attr_t",
2239         latency   => 2,
2240 },
2241
2242 fldpi => {
2243         op_flags  => "R|c|K",
2244         irn_flags => "R",
2245         reg_req   => { out => [ "vfp" ] },
2246         emit      => '. fldpi',
2247         attr_type => "ia32_x87_attr_t",
2248         latency   => 2,
2249 },
2250
2251 fldln2 => {
2252         op_flags  => "R|c|K",
2253         irn_flags => "R",
2254         reg_req   => { out => [ "vfp" ] },
2255         emit      => '. fldln2',
2256         attr_type => "ia32_x87_attr_t",
2257         latency   => 2,
2258 },
2259
2260 fldlg2 => {
2261         op_flags  => "R|c|K",
2262         irn_flags => "R",
2263         reg_req   => { out => [ "vfp" ] },
2264         emit      => '. fldlg2',
2265         attr_type => "ia32_x87_attr_t",
2266         latency   => 2,
2267 },
2268
2269 fldl2t => {
2270         op_flags  => "R|c|K",
2271         irn_flags => "R",
2272         reg_req   => { out => [ "vfp" ] },
2273         emit      => '. fldll2t',
2274         attr_type => "ia32_x87_attr_t",
2275         latency   => 2,
2276 },
2277
2278 fldl2e => {
2279         op_flags  => "R|c|K",
2280         irn_flags => "R",
2281         reg_req   => { out => [ "vfp" ] },
2282         emit      => '. fldl2e',
2283         attr_type => "ia32_x87_attr_t",
2284         latency   => 2,
2285 },
2286
2287 # fxch, fpush, fpop
2288 # Note that it is NEVER allowed to do CSE on these nodes
2289 # Moreover, note the virtual register requierements!
2290
2291 fxch => {
2292         op_flags  => "R|K",
2293         reg_req   => { },
2294         cmp_attr  => "return 1;",
2295         emit      => '. fxch %X0',
2296         attr_type => "ia32_x87_attr_t",
2297         mode      => "mode_ANY",
2298         latency   => 1,
2299 },
2300
2301 fpush => {
2302         op_flags  => "R|K",
2303         reg_req   => {},
2304         cmp_attr  => "return 1;",
2305         emit      => '. fld %X0',
2306         attr_type => "ia32_x87_attr_t",
2307         mode      => "mode_ANY",
2308         latency   => 1,
2309 },
2310
2311 fpushCopy => {
2312         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
2313         cmp_attr  => "return 1;",
2314         emit      => '. fld %X0',
2315         attr_type => "ia32_x87_attr_t",
2316         latency   => 1,
2317 },
2318
2319 fpop => {
2320         op_flags  => "K",
2321         reg_req   => { },
2322         cmp_attr  => "return 1;",
2323         emit      => '. fstp %X0',
2324         attr_type => "ia32_x87_attr_t",
2325         mode      => "mode_ANY",
2326         latency   => 1,
2327 },
2328
2329 ffreep => {
2330         op_flags  => "K",
2331         reg_req   => { },
2332         cmp_attr  => "return 1;",
2333         emit      => '. ffreep %X0',
2334         attr_type => "ia32_x87_attr_t",
2335         mode      => "mode_ANY",
2336         latency   => 1,
2337 },
2338
2339 emms => {
2340         op_flags  => "K",
2341         reg_req   => { },
2342         cmp_attr  => "return 1;",
2343         emit      => '. emms',
2344         attr_type => "ia32_x87_attr_t",
2345         mode      => "mode_ANY",
2346         latency   => 3,
2347 },
2348
2349 femms => {
2350         op_flags  => "K",
2351         reg_req   => { },
2352         cmp_attr  => "return 1;",
2353         emit      => '. femms',
2354         attr_type => "ia32_x87_attr_t",
2355         mode      => "mode_ANY",
2356         latency   => 3,
2357 },
2358
2359 # compare
2360
2361 FucomFnstsw => {
2362         reg_req   => { },
2363         emit      => ". fucom %X1\n".
2364                      ". fnstsw",
2365         attr_type => "ia32_x87_attr_t",
2366         latency   => 2,
2367 },
2368
2369 FucompFnstsw => {
2370         reg_req   => { },
2371         emit      => ". fucomp %X1\n".
2372                      ". fnstsw",
2373         attr_type => "ia32_x87_attr_t",
2374         latency   => 2,
2375 },
2376
2377 FucomppFnstsw => {
2378         reg_req   => { },
2379         emit      => ". fucompp\n".
2380                      ". fnstsw",
2381         attr_type => "ia32_x87_attr_t",
2382         latency   => 2,
2383 },
2384
2385 Fucomi => {
2386         reg_req   => { },
2387         emit      => '. fucomi %X1',
2388         attr_type => "ia32_x87_attr_t",
2389         latency   => 1,
2390 },
2391
2392 Fucompi => {
2393         reg_req   => { },
2394         emit      => '. fucompi %X1',
2395         attr_type => "ia32_x87_attr_t",
2396         latency   => 1,
2397 },
2398
2399 FtstFnstsw => {
2400         reg_req   => { },
2401         emit      => ". ftst\n".
2402                      ". fnstsw",
2403         attr_type => "ia32_x87_attr_t",
2404         latency   => 2,
2405 },
2406
2407
2408 # -------------------------------------------------------------------------------- #
2409 #  ____ ____  _____                  _                               _             #
2410 # / ___/ ___|| ____| __   _____  ___| |_ ___  _ __   _ __   ___   __| | ___  ___   #
2411 # \___ \___ \|  _|   \ \ / / _ \/ __| __/ _ \| '__| | '_ \ / _ \ / _` |/ _ \/ __|  #
2412 #  ___) |__) | |___   \ V /  __/ (__| || (_) | |    | | | | (_) | (_| |  __/\__ \  #
2413 # |____/____/|_____|   \_/ \___|\___|\__\___/|_|    |_| |_|\___/ \__,_|\___||___/  #
2414 #                                                                                  #
2415 # -------------------------------------------------------------------------------- #
2416
2417
2418 # Spilling and reloading of SSE registers, hardcoded, not generated #
2419
2420 xxLoad => {
2421         op_flags  => "L|F",
2422         state     => "exc_pinned",
2423         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
2424         emit      => '. movdqu %D0, %AM',
2425         outs      => [ "res", "M" ],
2426         units     => [ "SSE" ],
2427         latency   => 1,
2428 },
2429
2430 xxStore => {
2431         op_flags => "L|F",
2432         state    => "exc_pinned",
2433         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
2434         ins      => [ "base", "index", "mem", "val" ],
2435         emit     => '. movdqu %binop',
2436         units    => [ "SSE" ],
2437         latency   => 1,
2438         mode     => "mode_M",
2439 },
2440
2441 ); # end of %nodes
2442
2443 # Include the generated SIMD node specification written by the SIMD optimization
2444 $my_script_name = dirname($myname) . "/../ia32/ia32_simd_spec.pl";
2445 unless ($return = do $my_script_name) {
2446         warn "couldn't parse $my_script_name: $@" if $@;
2447         warn "couldn't do $my_script_name: $!"    unless defined $return;
2448         warn "couldn't run $my_script_name"       unless $return;
2449 }
2450
2451 # Transform some attributes
2452 foreach my $op (keys(%nodes)) {
2453         my $node         = $nodes{$op};
2454         my $op_attr_init = $node->{op_attr_init};
2455
2456         if(defined($op_attr_init)) {
2457                 $op_attr_init .= "\n\t";
2458         } else {
2459                 $op_attr_init = "";
2460         }
2461
2462         if(!defined($node->{latency})) {
2463                 if($op =~ m/^l_/) {
2464                         $node->{latency} = 0;
2465                 } else {
2466                         die("Latency missing for op $op");
2467                 }
2468         }
2469         $op_attr_init .= "attr->latency = ".$node->{latency} . ";";
2470
2471         $node->{op_attr_init} = $op_attr_init;
2472 }
2473
2474 print "ok";