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