5224895e7fe18b4fb1a772c6b69aff04f2b36dbc
[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         reg_req   => { in => [ "gp", "gp", "ecx" ], out => [ "in_r1 !in_r2 !in_r3" ] },
723         ins       => [ "left_high", "left_low", "right" ],
724         emit      => ". shld%M %SB2, %S1, %D0",
725         latency   => 6,
726         units     => [ "GP" ],
727         mode      => $mode_gp,
728         modified_flags => $status_flags
729 },
730
731 l_ShlD => {
732         cmp_attr  => "return 1;",
733         ins       => [ "high", "low", "count" ],
734         arity     => 3,
735 },
736
737 Shr => {
738         irn_flags => "R",
739         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
740         ins       => [ "val", "count" ],
741         emit      => '. shr %SB1, %S0',
742         units     => [ "GP" ],
743         mode      => $mode_gp,
744         latency   => 1,
745         modified_flags => $status_flags
746 },
747
748 ShrMem => {
749         irn_flags => "R",
750         state     => "exc_pinned",
751         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
752         ins       => [ "base", "index", "mem", "count" ],
753         emit      => '. shr%M %SB3, %AM',
754         units     => [ "GP" ],
755         mode      => "mode_M",
756         latency   => 1,
757         modified_flags => $status_flags
758 },
759
760 l_ShrDep => {
761         cmp_attr  => "return 1;",
762         ins       => [ "left", "right", "dep" ],
763         # value, cnt, dependency
764         arity     => 3
765 },
766
767 ShrD => {
768         irn_flags => "R",
769         reg_req   => { in => [ "gp", "gp", "ecx" ], out => [ "in_r1 !in_r2 !in_r3" ] },
770         ins       => [ "left_high", "left_low", "right" ],
771         emit      => ". shrd%M %SB2, %S1, %D0",
772         latency   => 6,
773         units     => [ "GP" ],
774         mode      => $mode_gp,
775         modified_flags => $status_flags
776 },
777
778 l_ShrD => {
779         cmp_attr  => "return 1;",
780         arity     => 3,
781         ins       => [ "high", "low", "count" ],
782 },
783
784 Sar => {
785         irn_flags => "R",
786         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
787         ins       => [ "val", "count" ],
788         emit      => '. sar %SB1, %S0',
789         units     => [ "GP" ],
790         latency   => 1,
791         mode      => $mode_gp,
792         modified_flags => $status_flags
793 },
794
795 SarMem => {
796         irn_flags => "R",
797         state     => "exc_pinned",
798         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
799         ins       => [ "base", "index", "mem", "count" ],
800         emit      => '. sar%M %SB3, %AM',
801         units     => [ "GP" ],
802         latency   => 1,
803         mode      => "mode_M",
804         modified_flags => $status_flags
805 },
806
807 l_SarDep => {
808         cmp_attr  => "return 1;",
809         ins       => [ "left", "right", "dep" ],
810         # value, cnt, dependency
811         arity     => 3
812 },
813
814 Ror => {
815         irn_flags => "R",
816         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
817         ins       => [ "val", "count" ],
818         emit      => '. ror %SB1, %S0',
819         units     => [ "GP" ],
820         latency   => 1,
821         mode      => $mode_gp,
822         modified_flags => $status_flags
823 },
824
825 RorMem => {
826         irn_flags => "R",
827         state     => "exc_pinned",
828         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
829         ins       => [ "base", "index", "mem", "count" ],
830         emit      => '. ror%M %SB3, %AM',
831         units     => [ "GP" ],
832         latency   => 1,
833         mode      => "mode_M",
834         modified_flags => $status_flags
835 },
836
837 Rol => {
838         irn_flags => "R",
839         reg_req   => { in => [ "gp", "ecx" ], out => [ "in_r1 !in_r2" ] },
840         ins       => [ "val", "count" ],
841         emit      => '. rol %SB1, %S0',
842         units     => [ "GP" ],
843         latency   => 1,
844         mode      => $mode_gp,
845         modified_flags => $status_flags
846 },
847
848 RolMem => {
849         irn_flags => "R",
850         state     => "exc_pinned",
851         reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
852         ins       => [ "base", "index", "mem", "count" ],
853         emit      => '. rol%M %SB3, %AM',
854         units     => [ "GP" ],
855         latency   => 1,
856         mode      => "mode_M",
857         modified_flags => $status_flags
858 },
859
860 # unary operations
861
862 Neg => {
863         irn_flags => "R",
864         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
865         emit      => '. neg %S0',
866         ins       => [ "val" ],
867         units     => [ "GP" ],
868         latency   => 1,
869         mode      => $mode_gp,
870         modified_flags => $status_flags
871 },
872
873 NegMem => {
874         irn_flags => "R",
875         state     => "exc_pinned",
876         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
877         ins       => [ "base", "index", "mem" ],
878         emit      => '. neg%M %AM',
879         units     => [ "GP" ],
880         latency   => 1,
881         mode      => "mode_M",
882         modified_flags => $status_flags
883 },
884
885 Minus64Bit => {
886         irn_flags => "R",
887         reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1", "gp" ] },
888         outs      => [ "low_res", "high_res" ],
889         units     => [ "GP" ],
890         latency   => 3,
891         modified_flags => $status_flags
892 },
893
894
895 Inc => {
896         irn_flags => "R",
897         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
898         emit      => '. inc %S0',
899         units     => [ "GP" ],
900         mode      => $mode_gp,
901         latency   => 1,
902         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
903 },
904
905 IncMem => {
906         irn_flags => "R",
907         state     => "exc_pinned",
908         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
909         ins       => [ "base", "index", "mem" ],
910         emit      => '. inc%M %AM',
911         units     => [ "GP" ],
912         mode      => "mode_M",
913         latency   => 1,
914         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
915 },
916
917 Dec => {
918         irn_flags => "R",
919         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
920         emit      => '. dec %S0',
921         units     => [ "GP" ],
922         mode      => $mode_gp,
923         latency   => 1,
924         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
925 },
926
927 DecMem => {
928         irn_flags => "R",
929         state     => "exc_pinned",
930         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
931         ins       => [ "base", "index", "mem" ],
932         emit      => '. dec%M %AM',
933         units     => [ "GP" ],
934         mode      => "mode_M",
935         latency   => 1,
936         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
937 },
938
939 Not => {
940         irn_flags => "R",
941         reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
942         ins       => [ "val" ],
943         emit      => '. not %S0',
944         units     => [ "GP" ],
945         latency   => 1,
946         mode      => $mode_gp,
947 },
948
949 NotMem => {
950         irn_flags => "R",
951         state     => "exc_pinned",
952         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
953         ins       => [ "base", "index", "mem" ],
954         emit      => '. not%M %AM',
955         units     => [ "GP" ],
956         latency   => 1,
957         mode      => "mode_M",
958 },
959
960 # other operations
961
962 Cmp => {
963         irn_flags => "R",
964         state     => "exc_pinned",
965         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ] , out => [ "flags" ] },
966         ins       => [ "base", "index", "mem", "left", "right" ],
967         outs      => [ "eflags" ],
968         am        => "source,binary",
969         emit      => '. cmp%M %binop',
970         attr      => "int ins_permuted, int cmp_unsigned",
971         init_attr => "attr->data.ins_permuted   = ins_permuted;\n".
972                      "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
973         latency   => 1,
974         units     => [ "GP" ],
975         mode      => $mode_flags,
976         modified_flags => $status_flags
977 },
978
979 Cmp8Bit => {
980         irn_flags => "R",
981         state     => "exc_pinned",
982         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx", "eax ebx ecx edx" ] , out => [ "flags" ] },
983         ins       => [ "base", "index", "mem", "left", "right" ],
984         outs      => [ "eflags" ],
985         am        => "source,binary",
986         emit      => '. cmpb %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 Test => {
997         irn_flags => "R",
998         state     => "exc_pinned",
999         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ] , out => [ "flags" ] },
1000         ins       => [ "base", "index", "mem", "left", "right" ],
1001         outs      => [ "eflags" ],
1002         am        => "source,binary",
1003         emit      => '. test%M %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 Test8Bit => {
1014         irn_flags => "R",
1015         state     => "exc_pinned",
1016         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx", "eax ebx ecx edx" ] , out => [ "flags" ] },
1017         ins       => [ "base", "index", "mem", "left", "right" ],
1018         outs      => [ "eflags" ],
1019         am        => "source,binary",
1020         emit      => '. testb %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 Set => {
1031         #irn_flags => "R",
1032         reg_req   => { in => [ "eflags" ], out => [ "eax ebx ecx edx" ] },
1033         ins       => [ "eflags" ],
1034         attr_type => "ia32_condcode_attr_t",
1035         attr      => "pn_Cmp pnc, int ins_permuted",
1036         init_attr => "attr->attr.data.ins_permuted = ins_permuted;\n".
1037                       "\tset_ia32_ls_mode(res, mode_Bu);\n",
1038         emit      => '. set%CMP0 %DB0',
1039         latency   => 1,
1040         units     => [ "GP" ],
1041         mode      => $mode_gp,
1042 },
1043
1044 SetMem => {
1045         #irn_flags => "R",
1046         state     => "exc_pinned",
1047         reg_req   => { in => [ "gp", "gp", "none", "eflags" ], out => [ "none" ] },
1048         ins       => [ "base", "index", "mem","eflags" ],
1049         attr_type => "ia32_condcode_attr_t",
1050         attr      => "pn_Cmp pnc, int ins_permuted",
1051         init_attr => "attr->attr.data.ins_permuted = ins_permuted;\n".
1052                       "\tset_ia32_ls_mode(res, mode_Bu);\n",
1053         emit      => '. set%CMP3 %AM',
1054         latency   => 1,
1055         units     => [ "GP" ],
1056         mode      => 'mode_M',
1057 },
1058
1059 CMov => {
1060         #irn_flags => "R",
1061         # (note: leave the false,true order intact to make it compatible with other
1062         #  ia32_binary ops)
1063         state     => "exc_pinned",
1064         reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "eflags" ], out => [ "in_r4 in_r5" ] },
1065         ins       => [ "base", "index", "mem", "val_false", "val_true", "eflags" ],
1066         am        => "source,binary",
1067         attr_type => "ia32_condcode_attr_t",
1068         attr      => "int ins_permuted, pn_Cmp pnc",
1069         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1070         latency   => 1,
1071         units     => [ "GP" ],
1072         mode      => $mode_gp,
1073 },
1074
1075 Jcc => {
1076         state     => "pinned",
1077         op_flags  => "L|X|Y",
1078         reg_req   => { in  => [ "eflags" ], out => [ "none", "none" ] },
1079         ins       => [ "eflags" ],
1080         outs      => [ "false", "true" ],
1081         attr_type => "ia32_condcode_attr_t",
1082         attr      => "pn_Cmp pnc",
1083         latency   => 2,
1084         units     => [ "BRANCH" ],
1085 },
1086
1087 SwitchJmp => {
1088         state     => "pinned",
1089         op_flags  => "L|X|Y",
1090         reg_req   => { in => [ "gp" ], out => [ "none" ] },
1091         mode      => "mode_T",
1092         attr_type => "ia32_condcode_attr_t",
1093         attr      => "pn_Cmp pnc",
1094         latency   => 3,
1095         units     => [ "BRANCH" ],
1096         modified_flags => $status_flags,
1097 },
1098
1099 IJmp => {
1100         state     => "pinned",
1101         op_flags  => "X",
1102         reg_req   => { in => [ "gp", "gp", "none", "gp" ] },
1103         ins       => [ "base", "index", "mem", "target" ],
1104         am        => "source,unary",
1105         emit      => '. jmp *%unop3',
1106         latency   => 1,
1107         units     => [ "BRANCH" ],
1108         mode      => "mode_X",
1109 },
1110
1111 Const => {
1112         op_flags  => "c",
1113         irn_flags => "R",
1114         reg_req   => { out => [ "gp" ] },
1115         units     => [ "GP" ],
1116         attr      => "ir_entity *symconst, int symconst_sign, long offset",
1117         attr_type => "ia32_immediate_attr_t",
1118         latency   => 1,
1119         mode      => $mode_gp,
1120 },
1121
1122 Unknown_GP => {
1123         state     => "pinned",
1124         op_flags  => "c",
1125         irn_flags => "I",
1126         reg_req   => { out => [ "gp_UKNWN" ] },
1127         units     => [],
1128         emit      => "",
1129         latency   => 0,
1130         mode      => $mode_gp
1131 },
1132
1133 Unknown_VFP => {
1134         state     => "pinned",
1135         op_flags  => "c",
1136         irn_flags => "I",
1137         reg_req   => { out => [ "vfp_UKNWN" ] },
1138         units     => [],
1139         emit      => "",
1140         mode      => "mode_E",
1141         latency   => 0,
1142         attr_type => "ia32_x87_attr_t",
1143 },
1144
1145 Unknown_XMM => {
1146         state     => "pinned",
1147         op_flags  => "c",
1148         irn_flags => "I",
1149         reg_req   => { out => [ "xmm_UKNWN" ] },
1150         units     => [],
1151         emit      => "",
1152         latency   => 0,
1153         mode      => "mode_E"
1154 },
1155
1156 NoReg_GP => {
1157         state     => "pinned",
1158         op_flags  => "c",
1159         irn_flags => "I",
1160         reg_req   => { out => [ "gp_NOREG" ] },
1161         units     => [],
1162         emit      => "",
1163         latency   => 0,
1164         mode      => $mode_gp
1165 },
1166
1167 NoReg_VFP => {
1168         state     => "pinned",
1169         op_flags  => "c",
1170         irn_flags => "I",
1171         reg_req   => { out => [ "vfp_NOREG" ] },
1172         units     => [],
1173         emit      => "",
1174         mode      => "mode_E",
1175         latency   => 0,
1176         attr_type => "ia32_x87_attr_t",
1177 },
1178
1179 NoReg_XMM => {
1180         state     => "pinned",
1181         op_flags  => "c",
1182         irn_flags => "I",
1183         reg_req   => { out => [ "xmm_NOREG" ] },
1184         units     => [],
1185         emit      => "",
1186         latency   => 0,
1187         mode      => "mode_E"
1188 },
1189
1190 ChangeCW => {
1191         state     => "pinned",
1192         op_flags  => "c",
1193         irn_flags => "I",
1194         reg_req   => { out => [ "fp_cw" ] },
1195         mode      => $mode_fpcw,
1196         latency   => 3,
1197         units     => [ "GP" ],
1198         modified_flags => $fpcw_flags
1199 },
1200
1201 FldCW => {
1202         op_flags  => "L|F",
1203         state     => "pinned",
1204         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "fp_cw" ] },
1205         ins       => [ "base", "index", "mem" ],
1206         latency   => 5,
1207         emit      => ". fldcw %AM",
1208         mode      => $mode_fpcw,
1209         units     => [ "GP" ],
1210         modified_flags => $fpcw_flags
1211 },
1212
1213 FnstCW => {
1214         op_flags  => "L|F",
1215         state     => "pinned",
1216         reg_req   => { in => [ "gp", "gp", "none", "fp_cw" ], out => [ "none" ] },
1217         ins       => [ "base", "index", "mem", "fpcw" ],
1218         latency   => 5,
1219         emit      => ". fnstcw %AM",
1220         mode      => "mode_M",
1221         units     => [ "GP" ],
1222 },
1223
1224 FnstCWNOP => {
1225         op_flags  => "L|F",
1226         state     => "pinned",
1227         reg_req   => { in => [ "fp_cw" ], out => [ "none" ] },
1228         ins       => [ "fpcw" ],
1229         latency   => 0,
1230         emit      => "",
1231         mode      => "mode_M",
1232 },
1233
1234 Cltd => {
1235         # we should not rematrialize this node. It has very strict constraints.
1236         reg_req   => { in => [ "eax", "edx" ], out => [ "edx" ] },
1237         ins       => [ "val", "globbered" ],
1238         emit      => '. cltd',
1239         latency   => 1,
1240         mode      => $mode_gp,
1241         units     => [ "GP" ],
1242 },
1243
1244 # Load / Store
1245 #
1246 # Note that we add additional latency values depending on address mode, so a
1247 # lateny of 0 for load is correct
1248
1249 Load => {
1250         op_flags  => "L|F",
1251         state     => "exc_pinned",
1252         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
1253         ins       => [ "base", "index", "mem" ],
1254         outs      => [ "res", "M" ],
1255         latency   => 0,
1256         emit      => ". mov%SE%ME%.l %AM, %D0",
1257         units     => [ "GP" ],
1258 },
1259
1260 l_Load => {
1261         op_flags  => "L|F",
1262         cmp_attr  => "return 1;",
1263         outs      => [ "res", "M" ],
1264         arity     => 2,
1265 },
1266
1267 l_Store => {
1268         op_flags  => "L|F",
1269         cmp_attr  => "return 1;",
1270         state     => "exc_pinned",
1271         arity     => 3,
1272         mode      => "mode_M",
1273 },
1274
1275 Store => {
1276         op_flags  => "L|F",
1277         state     => "exc_pinned",
1278         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
1279         ins       => [ "base", "index", "mem", "val" ],
1280         emit      => '. mov%M %SI3, %AM',
1281         latency   => 2,
1282         units     => [ "GP" ],
1283         mode      => "mode_M",
1284 },
1285
1286 Store8Bit => {
1287         op_flags  => "L|F",
1288         state     => "exc_pinned",
1289         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => ["none" ] },
1290         ins       => [ "base", "index", "mem", "val" ],
1291         emit      => '. mov%M %SB3, %AM',
1292         latency   => 2,
1293         units     => [ "GP" ],
1294         mode      => "mode_M",
1295 },
1296
1297 Lea => {
1298         irn_flags => "R",
1299         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
1300         ins       => [ "base", "index" ],
1301         emit      => '. leal %AM, %D0',
1302         latency   => 2,
1303         units     => [ "GP" ],
1304         mode      => $mode_gp,
1305 # lea doesn't modify the flags, but setting this seems advantageous since it
1306 # increases chances that the Lea is transformed back to an Add
1307         modified_flags => 1,
1308 },
1309
1310 Push => {
1311         state     => "exc_pinned",
1312         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "esp", "none" ] },
1313         ins       => [ "base", "index", "mem", "val", "stack" ],
1314         emit      => '. push%M %unop4',
1315         outs      => [ "stack:I|S", "M" ],
1316         am        => "source,binary",
1317         latency   => 2,
1318         units     => [ "GP" ],
1319 },
1320
1321 Pop => {
1322         state     => "exc_pinned",
1323         reg_req   => { in => [ "gp", "gp", "none", "esp" ], out => [ "gp", "none", "none", "esp" ] },
1324         emit      => '. pop%M %DAM0',
1325         outs      => [ "res", "M", "unused", "stack:I|S" ],
1326         ins       => [ "base", "index", "mem", "stack" ],
1327         am        => "dest,unary",
1328         latency   => 3, # Pop is more expensive than Push on Athlon
1329         units     => [ "GP" ],
1330 },
1331
1332 Enter => {
1333         reg_req   => { in => [ "esp" ], out => [ "ebp", "esp", "none" ] },
1334         emit      => '. enter',
1335         outs      => [ "frame:I", "stack:I|S", "M" ],
1336         latency   => 15,
1337         units     => [ "GP" ],
1338 },
1339
1340 Leave => {
1341         reg_req   => { in => [ "esp", "ebp" ], out => [ "ebp", "esp" ] },
1342         emit      => '. leave',
1343         outs      => [ "frame:I", "stack:I|S" ],
1344         latency   => 3,
1345         units     => [ "GP" ],
1346 },
1347
1348 AddSP => {
1349         irn_flags => "I",
1350         state     => "pinned",
1351         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "in_r4", "none" ] },
1352         ins       => [ "base", "index", "mem", "stack", "size" ],
1353         am        => "source,binary",
1354         emit      => '. addl %binop',
1355         latency   => 1,
1356         outs      => [ "stack:S", "M" ],
1357         units     => [ "GP" ],
1358         modified_flags => $status_flags
1359 },
1360
1361 SubSP => {
1362 #irn_flags => "I",
1363         state     => "pinned",
1364         reg_req   => { in => [ "gp", "gp", "none", "esp", "gp" ], out => [ "in_r4", "gp", "none" ] },
1365         ins       => [ "base", "index", "mem", "stack", "size" ],
1366         am        => "source,binary",
1367         emit      => ". subl %binop\n".
1368                      ". movl %%esp, %D1",
1369         latency   => 2,
1370         outs      => [ "stack:I|S", "addr", "M" ],
1371         units     => [ "GP" ],
1372         modified_flags => $status_flags
1373 },
1374
1375 LdTls => {
1376         irn_flags => "R",
1377         reg_req   => { out => [ "gp" ] },
1378         units     => [ "GP" ],
1379         latency   => 1,
1380 },
1381
1382
1383 #-----------------------------------------------------------------------------#
1384 #   _____ _____ ______    __ _             _                     _            #
1385 #  / ____/ ____|  ____|  / _| |           | |                   | |           #
1386 # | (___| (___ | |__    | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1387 #  \___ \\___ \|  __|   |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1388 #  ____) |___) | |____  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
1389 # |_____/_____/|______| |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1390 #-----------------------------------------------------------------------------#
1391
1392 xZero => {
1393         irn_flags => "R",
1394         reg_req   => { out => [ "xmm" ] },
1395         emit      => '. xorp%XSD %D0, %D0',
1396         latency   => 3,
1397         units     => [ "SSE" ],
1398         mode      => "mode_E",
1399 },
1400
1401 # commutative operations
1402
1403 xAdd => {
1404         irn_flags => "R",
1405         state     => "exc_pinned",
1406         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1407         ins       => [ "base", "index", "mem", "left", "right" ],
1408         am        => "source,binary",
1409         emit      => '. add%XXM %binop',
1410         latency   => 4,
1411         units     => [ "SSE" ],
1412         mode      => "mode_E",
1413 },
1414
1415 xMul => {
1416         irn_flags => "R",
1417         state     => "exc_pinned",
1418         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1419         ins       => [ "base", "index", "mem", "left", "right" ],
1420         am        => "source,binary",
1421         emit      => '. mul%XXM %binop',
1422         latency   => 4,
1423         units     => [ "SSE" ],
1424         mode      => "mode_E",
1425 },
1426
1427 xMax => {
1428         irn_flags => "R",
1429         state     => "exc_pinned",
1430         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1431         ins       => [ "base", "index", "mem", "left", "right" ],
1432         am        => "source,binary",
1433         emit      => '. max%XXM %binop',
1434         latency   => 2,
1435         units     => [ "SSE" ],
1436         mode      => "mode_E",
1437 },
1438
1439 xMin => {
1440         irn_flags => "R",
1441         state     => "exc_pinned",
1442         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1443         ins       => [ "base", "index", "mem", "left", "right" ],
1444         am        => "source,binary",
1445         emit      => '. min%XXM %binop',
1446         latency   => 2,
1447         units     => [ "SSE" ],
1448         mode      => "mode_E",
1449 },
1450
1451 xAnd => {
1452         irn_flags => "R",
1453         state     => "exc_pinned",
1454         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1455         ins       => [ "base", "index", "mem", "left", "right" ],
1456         am        => "source,binary",
1457         emit      => '. andp%XSD %binop',
1458         latency   => 3,
1459         units     => [ "SSE" ],
1460         mode      => "mode_E",
1461 },
1462
1463 xOr => {
1464         irn_flags => "R",
1465         state     => "exc_pinned",
1466         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1467         ins       => [ "base", "index", "mem", "left", "right" ],
1468         am        => "source,binary",
1469         emit      => '. orp%XSD %binop',
1470         latency   => 3,
1471         units     => [ "SSE" ],
1472         mode      => "mode_E",
1473 },
1474
1475 xXor => {
1476         irn_flags => "R",
1477         state     => "exc_pinned",
1478         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 in_r5" ] },
1479         ins       => [ "base", "index", "mem", "left", "right" ],
1480         am        => "source,binary",
1481         emit      => '. xorp%XSD %binop',
1482         latency   => 3,
1483         units     => [ "SSE" ],
1484         mode      => "mode_E",
1485 },
1486
1487 # not commutative operations
1488
1489 xAndNot => {
1490         irn_flags => "R",
1491         state     => "exc_pinned",
1492         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 !in_r5" ] },
1493         ins       => [ "base", "index", "mem", "left", "right" ],
1494         am        => "source,binary",
1495         emit      => '. andnp%XSD %binop',
1496         latency   => 3,
1497         units     => [ "SSE" ],
1498         mode      => "mode_E",
1499 },
1500
1501 xSub => {
1502         irn_flags => "R",
1503         state     => "exc_pinned",
1504         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4" ] },
1505         ins       => [ "base", "index", "mem", "left", "right" ],
1506         am        => "source,binary",
1507         emit      => '. sub%XXM %binop',
1508         latency   => 4,
1509         units     => [ "SSE" ],
1510         mode      => "mode_E",
1511 },
1512
1513 xDiv => {
1514         irn_flags => "R",
1515         state     => "exc_pinned",
1516         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "in_r4 !in_r5", "none" ] },
1517         ins       => [ "base", "index", "mem", "left", "right" ],
1518         am        => "source,binary",
1519         outs      => [ "res", "M" ],
1520         emit      => '. div%XXM %binop',
1521         latency   => 16,
1522         units     => [ "SSE" ],
1523 },
1524
1525 # other operations
1526
1527 Ucomi => {
1528         irn_flags => "R",
1529         state     => "exc_pinned",
1530         reg_req   => { in => [ "gp", "gp", "none", "xmm", "xmm" ], out => [ "eflags" ] },
1531         ins       => [ "base", "index", "mem", "left", "right" ],
1532         outs      => [ "flags" ],
1533         am        => "source,binary",
1534         attr      => "int ins_permuted",
1535         init_attr => "attr->data.ins_permuted = ins_permuted;",
1536         emit      => ' .ucomi%XXM %binop',
1537         latency   => 3,
1538         units     => [ "SSE" ],
1539         mode      => $mode_flags,
1540         modified_flags => 1,
1541 },
1542
1543 # Load / Store
1544
1545 xLoad => {
1546         op_flags  => "L|F",
1547         state     => "exc_pinned",
1548         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1549         ins       => [ "base", "index", "mem" ],
1550         emit      => '. mov%XXM %AM, %D0',
1551         attr      => "ir_mode *load_mode",
1552         init_attr => "attr->ls_mode = load_mode;",
1553         outs      => [ "res", "M" ],
1554         latency   => 0,
1555         units     => [ "SSE" ],
1556 },
1557
1558 xStore => {
1559         op_flags => "L|F",
1560         state    => "exc_pinned",
1561         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
1562         ins       => [ "base", "index", "mem", "val" ],
1563         emit     => '. mov%XXM %S3, %AM',
1564         latency  => 0,
1565         units    => [ "SSE" ],
1566         mode     => "mode_M",
1567 },
1568
1569 xStoreSimple => {
1570         op_flags => "L|F",
1571         state    => "exc_pinned",
1572         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
1573         ins      => [ "base", "index", "mem", "val" ],
1574         emit     => '. mov%XXM %S3, %AM',
1575         latency  => 0,
1576         units    => [ "SSE" ],
1577         mode     => "mode_M",
1578 },
1579
1580 CvtSI2SS => {
1581         op_flags => "L|F",
1582         state     => "exc_pinned",
1583         reg_req  => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm" ] },
1584         ins      => [ "base", "index", "mem", "val" ],
1585         am       => "source,unary",
1586         emit     => '. cvtsi2ss %unop3, %D0',
1587         latency  => 2,
1588         units    => [ "SSE" ],
1589         mode     => $mode_xmm
1590 },
1591
1592 CvtSI2SD => {
1593         op_flags => "L|F",
1594         state     => "exc_pinned",
1595         reg_req  => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm" ] },
1596         ins      => [ "base", "index", "mem", "val" ],
1597         am       => "source,unary",
1598         emit     => '. cvtsi2sd %unop3, %D0',
1599         latency  => 2,
1600         units    => [ "SSE" ],
1601         mode     => $mode_xmm
1602 },
1603
1604
1605 l_X87toSSE => {
1606         op_flags => "L|F",
1607         cmp_attr => "return 1;",
1608         arity    => 3,
1609 },
1610
1611 l_SSEtoX87 => {
1612         op_flags => "L|F",
1613         cmp_attr => "return 1;",
1614         arity    => 3,
1615 },
1616
1617 # CopyB
1618
1619 CopyB => {
1620         op_flags  => "F|H",
1621         state     => "pinned",
1622         reg_req   => { in => [ "edi", "esi", "ecx", "none" ], out => [ "edi", "esi", "ecx", "none" ] },
1623         outs      => [ "DST", "SRC", "CNT", "M" ],
1624         attr_type => "ia32_copyb_attr_t",
1625         attr      => "unsigned size",
1626         units     => [ "GP" ],
1627         latency  => 3,
1628 # we don't care about this flag, so no need to mark this node
1629 #       modified_flags => [ "DF" ]
1630 },
1631
1632 CopyB_i => {
1633         op_flags  => "F|H",
1634         state     => "pinned",
1635         reg_req   => { in => [ "edi", "esi", "none" ], out => [  "edi", "esi", "none" ] },
1636         outs      => [ "DST", "SRC", "M" ],
1637         attr_type => "ia32_copyb_attr_t",
1638         attr      => "unsigned size",
1639         units     => [ "GP" ],
1640         latency  => 3,
1641 # we don't care about this flag, so no need to mark this node
1642 #       modified_flags => [ "DF" ]
1643 },
1644
1645 # Conversions
1646
1647 Conv_I2I => {
1648         state     => "exc_pinned",
1649         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "gp", "none" ] },
1650         ins       => [ "base", "index", "mem", "val" ],
1651         am        => "source,unary",
1652         units     => [ "GP" ],
1653         latency   => 1,
1654         attr      => "ir_mode *smaller_mode",
1655         init_attr => "attr->ls_mode = smaller_mode;",
1656         mode      => $mode_gp,
1657 },
1658
1659 Conv_I2I8Bit => {
1660         state     => "exc_pinned",
1661         reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "gp", "none" ] },
1662         ins       => [ "base", "index", "mem", "val" ],
1663         am        => "source,unary",
1664         units     => [ "GP" ],
1665         latency   => 1,
1666         attr      => "ir_mode *smaller_mode",
1667         init_attr => "attr->ls_mode = smaller_mode;",
1668         mode      => $mode_gp,
1669 },
1670
1671 Conv_I2FP => {
1672         state     => "exc_pinned",
1673         reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "xmm", "none" ] },
1674         ins       => [ "base", "index", "mem", "val" ],
1675         am        => "source,unary",
1676         latency   => 10,
1677         units     => [ "SSE" ],
1678         mode      => "mode_E",
1679 },
1680
1681 Conv_FP2I => {
1682         state     => "exc_pinned",
1683         reg_req   => { in => [ "gp", "gp", "none", "xmm" ], out => [ "gp", "none" ] },
1684         ins       => [ "base", "index", "mem", "val" ],
1685         am        => "source,unary",
1686         latency   => 10,
1687         units     => [ "SSE" ],
1688         mode      => $mode_gp,
1689 },
1690
1691 Conv_FP2FP => {
1692         state     => "exc_pinned",
1693         reg_req   => { in => [ "gp", "gp", "none", "xmm" ], out => [ "xmm", "none" ] },
1694         ins       => [ "base", "index", "mem", "val" ],
1695         am        => "source,unary",
1696         latency   => 8,
1697         units     => [ "SSE" ],
1698         mode      => "mode_E",
1699 },
1700
1701 #----------------------------------------------------------#
1702 #        _      _               _    __ _             _    #
1703 #       (_)    | |             | |  / _| |           | |   #
1704 # __   ___ _ __| |_ _   _  __ _| | | |_| | ___   __ _| |_  #
1705 # \ \ / / | '__| __| | | |/ _` | | |  _| |/ _ \ / _` | __| #
1706 #  \ V /| | |  | |_| |_| | (_| | | | | | | (_) | (_| | |_  #
1707 #   \_/ |_|_|   \__|\__,_|\__,_|_| |_| |_|\___/ \__,_|\__| #
1708 #                 | |                                      #
1709 #  _ __   ___   __| | ___  ___                             #
1710 # | '_ \ / _ \ / _` |/ _ \/ __|                            #
1711 # | | | | (_) | (_| |  __/\__ \                            #
1712 # |_| |_|\___/ \__,_|\___||___/                            #
1713 #----------------------------------------------------------#
1714
1715 # rematerialisation disabled for all float nodes for now, because the fpcw
1716 # handler runs before spilling and we might end up with wrong fpcw then
1717
1718 vfadd => {
1719 #       irn_flags => "R",
1720         state     => "exc_pinned",
1721         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1722         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1723         am        => "source,binary",
1724         latency   => 4,
1725         units     => [ "VFP" ],
1726         mode      => "mode_E",
1727         attr_type => "ia32_x87_attr_t",
1728 },
1729
1730 vfmul => {
1731 #       irn_flags => "R",
1732         state     => "exc_pinned",
1733         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1734         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1735         am        => "source,binary",
1736         latency   => 4,
1737         units     => [ "VFP" ],
1738         mode      => "mode_E",
1739         attr_type => "ia32_x87_attr_t",
1740 },
1741
1742 vfsub => {
1743 #       irn_flags => "R",
1744         state     => "exc_pinned",
1745         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1746         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1747         am        => "source,binary",
1748         latency   => 4,
1749         units     => [ "VFP" ],
1750         mode      => "mode_E",
1751         attr_type => "ia32_x87_attr_t",
1752 },
1753
1754 vfdiv => {
1755         state     => "exc_pinned",
1756         reg_req   => { in => [ "gp", "gp", "none", "vfp", "vfp", "fpcw" ], out => [ "vfp", "none" ] },
1757         ins       => [ "base", "index", "mem", "left", "right", "fpcw" ],
1758         am        => "source,binary",
1759         outs      => [ "res", "M" ],
1760         latency   => 20,
1761         units     => [ "VFP" ],
1762         attr_type => "ia32_x87_attr_t",
1763 },
1764
1765 vfprem => {
1766         reg_req   => { in => [ "vfp", "vfp", "fpcw" ], out => [ "vfp" ] },
1767         ins       => [ "left", "right", "fpcw" ],
1768         latency   => 20,
1769         units     => [ "VFP" ],
1770         mode      => "mode_E",
1771         attr_type => "ia32_x87_attr_t",
1772 },
1773
1774 vfabs => {
1775         irn_flags => "R",
1776         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1777         ins       => [ "value" ],
1778         latency   => 2,
1779         units     => [ "VFP" ],
1780         mode      => "mode_E",
1781         attr_type => "ia32_x87_attr_t",
1782 },
1783
1784 vfchs => {
1785         irn_flags => "R",
1786         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1787         ins       => [ "value" ],
1788         latency   => 2,
1789         units     => [ "VFP" ],
1790         mode      => "mode_E",
1791         attr_type => "ia32_x87_attr_t",
1792 },
1793
1794 # virtual Load and Store
1795
1796 vfld => {
1797         irn_flags => "R",
1798         op_flags  => "L|F",
1799         state     => "exc_pinned",
1800         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1801         ins       => [ "base", "index", "mem" ],
1802         outs      => [ "res", "M" ],
1803         attr      => "ir_mode *load_mode",
1804         init_attr => "attr->attr.ls_mode = load_mode;",
1805         latency   => 2,
1806         units     => [ "VFP" ],
1807         attr_type => "ia32_x87_attr_t",
1808 },
1809
1810 vfst => {
1811         irn_flags => "R",
1812         op_flags  => "L|F",
1813         state     => "exc_pinned",
1814         reg_req   => { in => [ "gp", "gp", "none", "vfp" ] },
1815         ins       => [ "base", "index", "mem", "val" ],
1816         attr      => "ir_mode *store_mode",
1817         init_attr => "attr->attr.ls_mode = store_mode;",
1818         latency   => 2,
1819         units     => [ "VFP" ],
1820         mode      => "mode_M",
1821         attr_type => "ia32_x87_attr_t",
1822 },
1823
1824 # Conversions
1825
1826 vfild => {
1827         state     => "exc_pinned",
1828         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1829         outs      => [ "res", "M" ],
1830         ins       => [ "base", "index", "mem" ],
1831         latency   => 4,
1832         units     => [ "VFP" ],
1833         attr_type => "ia32_x87_attr_t",
1834 },
1835
1836 l_vfild => {
1837         cmp_attr  => "return 1;",
1838         outs      => [ "res", "M" ],
1839         arity     => 2,
1840 },
1841
1842 vfist => {
1843         state     => "exc_pinned",
1844         reg_req   => { in => [ "gp", "gp", "none", "vfp", "fpcw" ] },
1845         ins       => [ "base", "index", "mem", "val", "fpcw" ],
1846         latency   => 4,
1847         units     => [ "VFP" ],
1848         mode      => "mode_M",
1849         attr_type => "ia32_x87_attr_t",
1850 },
1851
1852 l_vfist => {
1853         cmp_attr  => "return 1;",
1854         state     => "exc_pinned",
1855         arity     => 3,
1856         mode      => "mode_M",
1857 },
1858
1859
1860 # constants
1861
1862 vfldz => {
1863         irn_flags => "R",
1864         reg_req   => { out => [ "vfp" ] },
1865         latency   => 4,
1866         units     => [ "VFP" ],
1867         mode      => "mode_E",
1868         attr_type => "ia32_x87_attr_t",
1869 },
1870
1871 vfld1 => {
1872         irn_flags => "R",
1873         reg_req   => { out => [ "vfp" ] },
1874         latency   => 4,
1875         units     => [ "VFP" ],
1876         mode      => "mode_E",
1877         attr_type => "ia32_x87_attr_t",
1878 },
1879
1880 vfldpi => {
1881         irn_flags => "R",
1882         reg_req   => { out => [ "vfp" ] },
1883         latency   => 4,
1884         units     => [ "VFP" ],
1885         mode      => "mode_E",
1886         attr_type => "ia32_x87_attr_t",
1887 },
1888
1889 vfldln2 => {
1890         irn_flags => "R",
1891         reg_req   => { out => [ "vfp" ] },
1892         latency   => 4,
1893         units     => [ "VFP" ],
1894         mode      => "mode_E",
1895         attr_type => "ia32_x87_attr_t",
1896 },
1897
1898 vfldlg2 => {
1899         irn_flags => "R",
1900         reg_req   => { out => [ "vfp" ] },
1901         latency   => 4,
1902         units     => [ "VFP" ],
1903         mode      => "mode_E",
1904         attr_type => "ia32_x87_attr_t",
1905 },
1906
1907 vfldl2t => {
1908         irn_flags => "R",
1909         reg_req   => { out => [ "vfp" ] },
1910         latency   => 4,
1911         units     => [ "VFP" ],
1912         mode      => "mode_E",
1913         attr_type => "ia32_x87_attr_t",
1914 },
1915
1916 vfldl2e => {
1917         irn_flags => "R",
1918         reg_req   => { out => [ "vfp" ] },
1919         latency   => 4,
1920         units     => [ "VFP" ],
1921         mode      => "mode_E",
1922         attr_type => "ia32_x87_attr_t",
1923 },
1924
1925 # other
1926
1927 vFucomFnstsw => {
1928 # we can't allow to rematerialize this node so we don't have
1929 #  accidently produce Phi(Fucom, Fucom(ins_permuted))
1930 #       irn_flags => "R",
1931         reg_req   => { in => [ "vfp", "vfp" ], out => [ "eax" ] },
1932         ins       => [ "left", "right" ],
1933         outs      => [ "flags" ],
1934         attr      => "int ins_permuted",
1935         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1936         latency   => 3,
1937         units     => [ "VFP" ],
1938         attr_type => "ia32_x87_attr_t",
1939         mode      => $mode_gp
1940 },
1941
1942 vFucomi => {
1943         irn_flags => "R",
1944         reg_req   => { in => [ "vfp", "vfp" ], out => [ "eflags" ] },
1945         ins       => [ "left", "right" ],
1946         outs      => [ "flags" ],
1947         attr      => "int ins_permuted",
1948         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1949         latency   => 3,
1950         units     => [ "VFP" ],
1951         attr_type => "ia32_x87_attr_t",
1952         mode      => $mode_gp
1953 },
1954
1955 vFtstFnstsw => {
1956 #       irn_flags => "R",
1957         reg_req   => { in => [ "vfp" ], out => [ "eax" ] },
1958         ins       => [ "left" ],
1959         outs      => [ "flags" ],
1960         attr      => "int ins_permuted",
1961         init_attr => "attr->attr.data.ins_permuted = ins_permuted;",
1962         latency   => 3,
1963         units     => [ "VFP" ],
1964         attr_type => "ia32_x87_attr_t",
1965         mode      => $mode_gp
1966 },
1967
1968 Sahf => {
1969         irn_flags => "R",
1970         reg_req   => { in => [ "eax" ], out => [ "eflags" ] },
1971         ins       => [ "val" ],
1972         outs      => [ "flags" ],
1973         emit      => '. sahf',
1974         latency   => 1,
1975         units     => [ "GP" ],
1976         mode      => $mode_flags,
1977 },
1978
1979 #------------------------------------------------------------------------#
1980 #       ___ _____    __ _             _                     _            #
1981 # __  _( _ )___  |  / _| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1982 # \ \/ / _ \  / /  | |_| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1983 #  >  < (_) |/ /   |  _| | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
1984 # /_/\_\___//_/    |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1985 #------------------------------------------------------------------------#
1986
1987 # Note: gas is strangely buggy: fdivrp and fdivp as well as fsubrp and fsubp
1988 #       are swapped, we work this around in the emitter...
1989
1990 fadd => {
1991         state     => "exc_pinned",
1992         rd_constructor => "NONE",
1993         reg_req   => { },
1994         emit      => '. fadd%XM %x87_binop',
1995         latency   => 4,
1996         attr_type => "ia32_x87_attr_t",
1997 },
1998
1999 faddp => {
2000         state     => "exc_pinned",
2001         rd_constructor => "NONE",
2002         reg_req   => { },
2003         emit      => '. faddp%XM %x87_binop',
2004         latency   => 4,
2005         attr_type => "ia32_x87_attr_t",
2006 },
2007
2008 fmul => {
2009         state     => "exc_pinned",
2010         rd_constructor => "NONE",
2011         reg_req   => { },
2012         emit      => '. fmul%XM %x87_binop',
2013         latency   => 4,
2014         attr_type => "ia32_x87_attr_t",
2015 },
2016
2017 fmulp => {
2018         state     => "exc_pinned",
2019         rd_constructor => "NONE",
2020         reg_req   => { },
2021         emit      => '. fmulp%XM %x87_binop',,
2022         latency   => 4,
2023         attr_type => "ia32_x87_attr_t",
2024 },
2025
2026 fsub => {
2027         state     => "exc_pinned",
2028         rd_constructor => "NONE",
2029         reg_req   => { },
2030         emit      => '. fsub%XM %x87_binop',
2031         latency   => 4,
2032         attr_type => "ia32_x87_attr_t",
2033 },
2034
2035 fsubp => {
2036         state     => "exc_pinned",
2037         rd_constructor => "NONE",
2038         reg_req   => { },
2039 # see note about gas bugs
2040         emit      => '. fsubrp%XM %x87_binop',
2041         latency   => 4,
2042         attr_type => "ia32_x87_attr_t",
2043 },
2044
2045 fsubr => {
2046         state     => "exc_pinned",
2047         rd_constructor => "NONE",
2048         irn_flags => "R",
2049         reg_req   => { },
2050         emit      => '. fsubr%XM %x87_binop',
2051         latency   => 4,
2052         attr_type => "ia32_x87_attr_t",
2053 },
2054
2055 fsubrp => {
2056         state     => "exc_pinned",
2057         rd_constructor => "NONE",
2058         irn_flags => "R",
2059         reg_req   => { },
2060 # see note about gas bugs
2061         emit      => '. fsubp%XM %x87_binop',
2062         latency   => 4,
2063         attr_type => "ia32_x87_attr_t",
2064 },
2065
2066 fprem => {
2067         rd_constructor => "NONE",
2068         reg_req   => { },
2069         emit      => '. fprem1',
2070         latency   => 20,
2071         attr_type => "ia32_x87_attr_t",
2072 },
2073
2074 # this node is just here, to keep the simulator running
2075 # we can omit this when a fprem simulation function exists
2076 fpremp => {
2077         rd_constructor => "NONE",
2078         reg_req   => { },
2079         emit      => '. fprem1\n'.
2080                      '. fstp %X0',
2081         latency   => 20,
2082         attr_type => "ia32_x87_attr_t",
2083 },
2084
2085 fdiv => {
2086         state     => "exc_pinned",
2087         rd_constructor => "NONE",
2088         reg_req   => { },
2089         emit      => '. fdiv%XM %x87_binop',
2090         latency   => 20,
2091         attr_type => "ia32_x87_attr_t",
2092 },
2093
2094 fdivp => {
2095         state     => "exc_pinned",
2096         rd_constructor => "NONE",
2097         reg_req   => { },
2098 # see note about gas bugs
2099         emit      => '. fdivrp%XM %x87_binop',
2100         latency   => 20,
2101         attr_type => "ia32_x87_attr_t",
2102 },
2103
2104 fdivr => {
2105         state     => "exc_pinned",
2106         rd_constructor => "NONE",
2107         reg_req   => { },
2108         emit      => '. fdivr%XM %x87_binop',
2109         latency   => 20,
2110         attr_type => "ia32_x87_attr_t",
2111 },
2112
2113 fdivrp => {
2114         state     => "exc_pinned",
2115         rd_constructor => "NONE",
2116         reg_req   => { },
2117 # see note about gas bugs
2118         emit      => '. fdivp%XM %x87_binop',
2119         latency   => 20,
2120         attr_type => "ia32_x87_attr_t",
2121 },
2122
2123 fabs => {
2124         rd_constructor => "NONE",
2125         reg_req   => { },
2126         emit      => '. fabs',
2127         latency   => 4,
2128         attr_type => "ia32_x87_attr_t",
2129 },
2130
2131 fchs => {
2132         op_flags  => "R|K",
2133         rd_constructor => "NONE",
2134         reg_req   => { },
2135         emit      => '. fchs',
2136         latency   => 4,
2137         attr_type => "ia32_x87_attr_t",
2138 },
2139
2140 # x87 Load and Store
2141
2142 fld => {
2143         rd_constructor => "NONE",
2144         op_flags  => "R|L|F",
2145         state     => "exc_pinned",
2146         reg_req   => { },
2147         emit      => '. fld%XM %AM',
2148         attr_type => "ia32_x87_attr_t",
2149         latency   => 2,
2150 },
2151
2152 fst => {
2153         rd_constructor => "NONE",
2154         op_flags  => "R|L|F",
2155         state     => "exc_pinned",
2156         reg_req   => { },
2157         emit      => '. fst%XM %AM',
2158         mode      => "mode_M",
2159         attr_type => "ia32_x87_attr_t",
2160         latency   => 2,
2161 },
2162
2163 fstp => {
2164         rd_constructor => "NONE",
2165         op_flags  => "R|L|F",
2166         state     => "exc_pinned",
2167         reg_req   => { },
2168         emit      => '. fstp%XM %AM',
2169         mode      => "mode_M",
2170         attr_type => "ia32_x87_attr_t",
2171         latency   => 2,
2172 },
2173
2174 # Conversions
2175
2176 fild => {
2177         state     => "exc_pinned",
2178         rd_constructor => "NONE",
2179         reg_req   => { },
2180         emit      => '. fild%M %AM',
2181         attr_type => "ia32_x87_attr_t",
2182         latency   => 2,
2183 },
2184
2185 fist => {
2186         state     => "exc_pinned",
2187         rd_constructor => "NONE",
2188         reg_req   => { },
2189         emit      => '. fist%M %AM',
2190         mode      => "mode_M",
2191         attr_type => "ia32_x87_attr_t",
2192         latency   => 2,
2193 },
2194
2195 fistp => {
2196         state     => "exc_pinned",
2197         rd_constructor => "NONE",
2198         reg_req   => { },
2199         emit      => '. fistp%M %AM',
2200         mode      => "mode_M",
2201         attr_type => "ia32_x87_attr_t",
2202         latency   => 2,
2203 },
2204
2205 # constants
2206
2207 fldz => {
2208         op_flags  => "R|c|K",
2209         irn_flags => "R",
2210         reg_req   => { out => [ "vfp" ] },
2211         emit      => '. fldz',
2212         attr_type => "ia32_x87_attr_t",
2213         latency   => 2,
2214 },
2215
2216 fld1 => {
2217         op_flags  => "R|c|K",
2218         irn_flags => "R",
2219         reg_req   => { out => [ "vfp" ] },
2220         emit      => '. fld1',
2221         attr_type => "ia32_x87_attr_t",
2222         latency   => 2,
2223 },
2224
2225 fldpi => {
2226         op_flags  => "R|c|K",
2227         irn_flags => "R",
2228         reg_req   => { out => [ "vfp" ] },
2229         emit      => '. fldpi',
2230         attr_type => "ia32_x87_attr_t",
2231         latency   => 2,
2232 },
2233
2234 fldln2 => {
2235         op_flags  => "R|c|K",
2236         irn_flags => "R",
2237         reg_req   => { out => [ "vfp" ] },
2238         emit      => '. fldln2',
2239         attr_type => "ia32_x87_attr_t",
2240         latency   => 2,
2241 },
2242
2243 fldlg2 => {
2244         op_flags  => "R|c|K",
2245         irn_flags => "R",
2246         reg_req   => { out => [ "vfp" ] },
2247         emit      => '. fldlg2',
2248         attr_type => "ia32_x87_attr_t",
2249         latency   => 2,
2250 },
2251
2252 fldl2t => {
2253         op_flags  => "R|c|K",
2254         irn_flags => "R",
2255         reg_req   => { out => [ "vfp" ] },
2256         emit      => '. fldll2t',
2257         attr_type => "ia32_x87_attr_t",
2258         latency   => 2,
2259 },
2260
2261 fldl2e => {
2262         op_flags  => "R|c|K",
2263         irn_flags => "R",
2264         reg_req   => { out => [ "vfp" ] },
2265         emit      => '. fldl2e',
2266         attr_type => "ia32_x87_attr_t",
2267         latency   => 2,
2268 },
2269
2270 # fxch, fpush, fpop
2271 # Note that it is NEVER allowed to do CSE on these nodes
2272 # Moreover, note the virtual register requierements!
2273
2274 fxch => {
2275         op_flags  => "R|K",
2276         reg_req   => { },
2277         cmp_attr  => "return 1;",
2278         emit      => '. fxch %X0',
2279         attr_type => "ia32_x87_attr_t",
2280         mode      => "mode_ANY",
2281         latency   => 1,
2282 },
2283
2284 fpush => {
2285         op_flags  => "R|K",
2286         reg_req   => {},
2287         cmp_attr  => "return 1;",
2288         emit      => '. fld %X0',
2289         attr_type => "ia32_x87_attr_t",
2290         mode      => "mode_ANY",
2291         latency   => 1,
2292 },
2293
2294 fpushCopy => {
2295         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
2296         cmp_attr  => "return 1;",
2297         emit      => '. fld %X0',
2298         attr_type => "ia32_x87_attr_t",
2299         latency   => 1,
2300 },
2301
2302 fpop => {
2303         op_flags  => "K",
2304         reg_req   => { },
2305         cmp_attr  => "return 1;",
2306         emit      => '. fstp %X0',
2307         attr_type => "ia32_x87_attr_t",
2308         mode      => "mode_ANY",
2309         latency   => 1,
2310 },
2311
2312 ffreep => {
2313         op_flags  => "K",
2314         reg_req   => { },
2315         cmp_attr  => "return 1;",
2316         emit      => '. ffreep %X0',
2317         attr_type => "ia32_x87_attr_t",
2318         mode      => "mode_ANY",
2319         latency   => 1,
2320 },
2321
2322 emms => {
2323         op_flags  => "K",
2324         reg_req   => { },
2325         cmp_attr  => "return 1;",
2326         emit      => '. emms',
2327         attr_type => "ia32_x87_attr_t",
2328         mode      => "mode_ANY",
2329         latency   => 3,
2330 },
2331
2332 femms => {
2333         op_flags  => "K",
2334         reg_req   => { },
2335         cmp_attr  => "return 1;",
2336         emit      => '. femms',
2337         attr_type => "ia32_x87_attr_t",
2338         mode      => "mode_ANY",
2339         latency   => 3,
2340 },
2341
2342 # compare
2343
2344 FucomFnstsw => {
2345         reg_req   => { },
2346         emit      => ". fucom %X1\n".
2347                      ". fnstsw",
2348         attr_type => "ia32_x87_attr_t",
2349         latency   => 2,
2350 },
2351
2352 FucompFnstsw => {
2353         reg_req   => { },
2354         emit      => ". fucomp %X1\n".
2355                      ". fnstsw",
2356         attr_type => "ia32_x87_attr_t",
2357         latency   => 2,
2358 },
2359
2360 FucomppFnstsw => {
2361         reg_req   => { },
2362         emit      => ". fucompp\n".
2363                      ". fnstsw",
2364         attr_type => "ia32_x87_attr_t",
2365         latency   => 2,
2366 },
2367
2368 Fucomi => {
2369         reg_req   => { },
2370         emit      => '. fucomi %X1',
2371         attr_type => "ia32_x87_attr_t",
2372         latency   => 1,
2373 },
2374
2375 Fucompi => {
2376         reg_req   => { },
2377         emit      => '. fucompi %X1',
2378         attr_type => "ia32_x87_attr_t",
2379         latency   => 1,
2380 },
2381
2382 FtstFnstsw => {
2383         reg_req   => { },
2384         emit      => ". ftst\n".
2385                      ". fnstsw",
2386         attr_type => "ia32_x87_attr_t",
2387         latency   => 2,
2388 },
2389
2390
2391 # -------------------------------------------------------------------------------- #
2392 #  ____ ____  _____                  _                               _             #
2393 # / ___/ ___|| ____| __   _____  ___| |_ ___  _ __   _ __   ___   __| | ___  ___   #
2394 # \___ \___ \|  _|   \ \ / / _ \/ __| __/ _ \| '__| | '_ \ / _ \ / _` |/ _ \/ __|  #
2395 #  ___) |__) | |___   \ V /  __/ (__| || (_) | |    | | | | (_) | (_| |  __/\__ \  #
2396 # |____/____/|_____|   \_/ \___|\___|\__\___/|_|    |_| |_|\___/ \__,_|\___||___/  #
2397 #                                                                                  #
2398 # -------------------------------------------------------------------------------- #
2399
2400
2401 # Spilling and reloading of SSE registers, hardcoded, not generated #
2402
2403 xxLoad => {
2404         op_flags  => "L|F",
2405         state     => "exc_pinned",
2406         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
2407         emit      => '. movdqu %D0, %AM',
2408         outs      => [ "res", "M" ],
2409         units     => [ "SSE" ],
2410         latency   => 1,
2411 },
2412
2413 xxStore => {
2414         op_flags => "L|F",
2415         state    => "exc_pinned",
2416         reg_req  => { in => [ "gp", "gp", "none", "xmm" ] },
2417         ins      => [ "base", "index", "mem", "val" ],
2418         emit     => '. movdqu %binop',
2419         units    => [ "SSE" ],
2420         latency   => 1,
2421         mode     => "mode_M",
2422 },
2423
2424 ); # end of %nodes
2425
2426 # Include the generated SIMD node specification written by the SIMD optimization
2427 $my_script_name = dirname($myname) . "/../ia32/ia32_simd_spec.pl";
2428 unless ($return = do $my_script_name) {
2429         warn "couldn't parse $my_script_name: $@" if $@;
2430         warn "couldn't do $my_script_name: $!"    unless defined $return;
2431         warn "couldn't run $my_script_name"       unless $return;
2432 }
2433
2434 # Transform some attributes
2435 foreach my $op (keys(%nodes)) {
2436         my $node         = $nodes{$op};
2437         my $op_attr_init = $node->{op_attr_init};
2438
2439         if(defined($op_attr_init)) {
2440                 $op_attr_init .= "\n\t";
2441         } else {
2442                 $op_attr_init = "";
2443         }
2444
2445         if(!defined($node->{latency})) {
2446                 if($op =~ m/^l_/) {
2447                         $node->{latency} = 0;
2448                 } else {
2449                         die("Latency missing for op $op");
2450                 }
2451         }
2452         $op_attr_init .= "attr->latency = ".$node->{latency} . ";";
2453
2454         $node->{op_attr_init} = $op_attr_init;
2455 }
2456
2457 print "ok";