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