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