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