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