we can parse lots of assembler constraints now (but not all yet), and emit immediates...
[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 #   latency   => "latency of this operation (can be float)"
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 # latency: the latency of the operation, default is 1
99 #
100
101 # register types:
102 #   0 - no special type
103 #   1 - caller save (register must be saved by the caller of a function)
104 #   2 - callee save (register must be saved by the called function)
105 #   4 - ignore (do not assign this register)
106 #   8 - emitter can choose an arbitrary register of this class
107 #  16 - the register is a virtual one
108 #  32 - register represents a state
109 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
110 %reg_classes = (
111         gp => [
112                 { name => "eax", type => 1 },
113                 { name => "edx", type => 1 },
114                 { name => "ebx", type => 2 },
115                 { name => "ecx", type => 1 },
116                 { name => "esi", type => 2 },
117                 { name => "edi", type => 2 },
118                 { name => "ebp", type => 2 },
119                 { name => "esp", type => 4 },
120                 { name => "gp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
121                 { name => "gp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
122                 { mode => "mode_Iu" }
123         ],
124         xmm => [
125                 { name => "xmm0", type => 1 },
126                 { name => "xmm1", type => 1 },
127                 { name => "xmm2", type => 1 },
128                 { name => "xmm3", type => 1 },
129                 { name => "xmm4", type => 1 },
130                 { name => "xmm5", type => 1 },
131                 { name => "xmm6", type => 1 },
132                 { name => "xmm7", type => 1 },
133                 { name => "xmm_NOREG", type => 4 | 16 },     # we need a dummy register for NoReg nodes
134                 { name => "xmm_UKNWN", type => 4 | 8 | 16},  # we need a dummy register for Unknown nodes
135                 { mode => "mode_E" }
136         ],
137         vfp => [
138                 { name => "vf0", type => 1 | 16 },
139                 { name => "vf1", type => 1 | 16 },
140                 { name => "vf2", type => 1 | 16 },
141                 { name => "vf3", type => 1 | 16 },
142                 { name => "vf4", type => 1 | 16 },
143                 { name => "vf5", type => 1 | 16 },
144                 { name => "vf6", type => 1 | 16 },
145                 { name => "vf7", type => 1 | 16 },
146                 { name => "vfp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
147                 { name => "vfp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
148                 { mode => "mode_E" }
149         ],
150         st => [
151                 { name => "st0", realname => "st",    type => 4 },
152                 { name => "st1", realname => "st(1)", type => 4 },
153                 { name => "st2", realname => "st(2)", type => 4 },
154                 { name => "st3", realname => "st(3)", type => 4 },
155                 { name => "st4", realname => "st(4)", type => 4 },
156                 { name => "st5", realname => "st(5)", type => 4 },
157                 { name => "st6", realname => "st(6)", type => 4 },
158                 { name => "st7", realname => "st(7)", type => 4 },
159                 { mode => "mode_E" }
160         ],
161         fp_cw => [      # the floating point control word
162                 { name => "fpcw", type => 4 | 32},
163                 { mode => "mode_fpcw" }
164         ],
165         flags => [
166                 { name => "eflags", type => 4 },
167                 { mode => "mode_Iu" }
168         ],
169         fp_sw => [
170                 { name => "fpsw", type => 4 },
171                 { mode => "mode_Hu" }
172         ],
173 ); # %reg_classes
174
175 %flags = (
176         CF  => { reg => "eflags", bit => 0 },
177         PF  => { reg => "eflags", bit => 2 },
178         AF  => { reg => "eflags", bit => 4 },
179         ZF  => { reg => "eflags", bit => 6 },
180         SF  => { reg => "eflags", bit => 7 },
181         TF  => { reg => "eflags", bit => 8 },
182         IF  => { reg => "eflags", bit => 9 },
183         DF  => { reg => "eflags", bit => 10 },
184         OF  => { reg => "eflags", bit => 11 },
185         IOPL0 => { reg => "eflags", bit => 12 },
186         IOPL1 => { reg => "eflags", bit => 13 },
187         NT  => { reg => "eflags", bit => 14 },
188         RF  => { reg => "eflags", bit => 16 },
189         VM  => { reg => "eflags", bit => 17 },
190         AC  => { reg => "eflags", bit => 18 },
191         VIF => { reg => "eflags", bit => 19 },
192         VIP => { reg => "eflags", bit => 20 },
193         ID  => { reg => "eflags", bit => 21 },
194
195         FP_IE => { reg => "fpsw", bit => 0 },
196         FP_DE => { reg => "fpsw", bit => 1 },
197         FP_ZE => { reg => "fpsw", bit => 2 },
198         FP_OE => { reg => "fpsw", bit => 3 },
199         FP_UE => { reg => "fpsw", bit => 4 },
200         FP_PE => { reg => "fpsw", bit => 5 },
201         FP_SF => { reg => "fpsw", bit => 6 },
202         FP_ES => { reg => "fpsw", bit => 7 },
203         FP_C0 => { reg => "fpsw", bit => 8 },
204         FP_C1 => { reg => "fpsw", bit => 9 },
205         FP_C2 => { reg => "fpsw", bit => 10 },
206         FP_TOP0 => { reg => "fpsw", bit => 11 },
207         FP_TOP1 => { reg => "fpsw", bit => 12 },
208         FP_TOP2 => { reg => "fpsw", bit => 13 },
209         FP_C3 => { reg => "fpsw", bit => 14 },
210         FP_B  => { reg => "fpsw", bit => 15 },
211
212         FP_IM => { reg => "fpcw", bit => 0 },
213         FP_DM => { reg => "fpcw", bit => 1 },
214         FP_ZM => { reg => "fpcw", bit => 2 },
215         FP_OM => { reg => "fpcw", bit => 3 },
216         FP_UM => { reg => "fpcw", bit => 4 },
217         FP_PM => { reg => "fpcw", bit => 5 },
218         FP_PC0 => { reg => "fpcw", bit => 8 },
219         FP_PC1 => { reg => "fpcw", bit => 9 },
220         FP_RC0 => { reg => "fpcw", bit => 10 },
221         FP_RC1 => { reg => "fpcw", bit => 11 },
222         FP_X  => { reg => "fpcw", bit => 12 }
223 ); # %flags
224
225 %cpu = (
226         GP     => [ 1, "GP_EAX", "GP_EBX", "GP_ECX", "GP_EDX", "GP_ESI", "GP_EDI", "GP_EBP" ],
227         SSE    => [ 1, "SSE_XMM0", "SSE_XMM1", "SSE_XMM2", "SSE_XMM3", "SSE_XMM4", "SSE_XMM5", "SSE_XMM6", "SSE_XMM7" ],
228         VFP    => [ 1, "VFP_VF0", "VFP_VF1", "VFP_VF2", "VFP_VF3", "VFP_VF4", "VFP_VF5", "VFP_VF6", "VFP_VF7" ],
229         BRANCH => [ 1, "BRANCH1", "BRANCH2" ],
230 ); # %cpu
231
232 %vliw = (
233         bundle_size       => 1,
234         bundels_per_cycle => 1
235 ); # vliw
236
237 %emit_templates = (
238         S0 => "${arch}_emit_source_register(env, node, 0);",
239         S1 => "${arch}_emit_source_register(env, node, 1);",
240         S2 => "${arch}_emit_source_register(env, node, 2);",
241         S3 => "${arch}_emit_source_register(env, node, 3);",
242         S4 => "${arch}_emit_source_register(env, node, 4);",
243         S5 => "${arch}_emit_source_register(env, node, 5);",
244         D0 => "${arch}_emit_dest_register(env, node, 0);",
245         D1 => "${arch}_emit_dest_register(env, node, 1);",
246         D2 => "${arch}_emit_dest_register(env, node, 2);",
247         D3 => "${arch}_emit_dest_register(env, node, 3);",
248         D4 => "${arch}_emit_dest_register(env, node, 4);",
249         D5 => "${arch}_emit_dest_register(env, node, 5);",
250         X0 => "${arch}_emit_x87_name(env, node, 0);",
251         X1 => "${arch}_emit_x87_name(env, node, 1);",
252         X2 => "${arch}_emit_x87_name(env, node, 2);",
253         C  => "${arch}_emit_immediate(env, node);",
254         SE => "${arch}_emit_extend_suffix(env, get_ia32_ls_mode(node));",
255         ME => "if(get_mode_size_bits(get_ia32_ls_mode(node)) != 32)\n
256                    ia32_emit_mode_suffix(env, node);",
257         M  => "${arch}_emit_mode_suffix(env, node);",
258         XM => "${arch}_emit_x87_mode_suffix(env, node);",
259         XXM => "${arch}_emit_xmm_mode_suffix(env, node);",
260         XSD => "${arch}_emit_xmm_mode_suffix_s(env, node);",
261         AM => "${arch}_emit_am(env, node);",
262         unop => "${arch}_emit_unop(env, node);",
263         binop => "${arch}_emit_binop(env, node);",
264         x87_binop => "${arch}_emit_x87_binop(env, node);",
265 );
266
267 #--------------------------------------------------#
268 #                        _                         #
269 #                       (_)                        #
270 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
271 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
272 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
273 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
274 #                                      | |         #
275 #                                      |_|         #
276 #--------------------------------------------------#
277
278 $default_cmp_attr  = "return ia32_compare_attr(attr_a, attr_b);";
279 $default_attr_type = "ia32_attr_t";
280
281 %operands = (
282 );
283
284 $mode_xmm     = "mode_E";
285 $mode_gp      = "mode_Iu";
286 $mode_fpcw    = "mode_fpcw";
287 $status_flags = [ "CF", "PF", "AF", "ZF", "SF", "OF" ];
288 $fpcw_flags   = [ "FP_IM", "FP_DM", "FP_ZM", "FP_OM", "FP_UM", "FP_PM",
289                   "FP_PC0", "FP_PC1", "FP_RC0", "FP_RC1", "FP_X" ];
290
291 %nodes = (
292
293 Immediate => {
294         state     => "pinned",
295         op_flags  => "c",
296         irn_flags => "I",
297         reg_req   => { out => [ "gp_NOREG" ] },
298         mode      => $mode_gp,
299 },
300
301 Asm => {
302         mode      => "mode_T",
303         arity     => "variable",
304         out_arity => "variable",
305 },
306
307 #-----------------------------------------------------------------#
308 #  _       _                                         _            #
309 # (_)     | |                                       | |           #
310 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
311 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
312 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
313 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
314 #                   __/ |                                         #
315 #                  |___/                                          #
316 #-----------------------------------------------------------------#
317
318 # commutative operations
319
320 # NOTE:
321 # All nodes supporting Addressmode have 5 INs:
322 # 1 - base    r1 == NoReg in case of no AM or no base
323 # 2 - index   r2 == NoReg in case of no AM or no index
324 # 3 - op1     r3 == always present
325 # 4 - op2     r4 == NoReg in case of immediate operation
326 # 5 - mem     NoMem in case of no AM otherwise it takes the mem from the Load
327
328 Add => {
329         irn_flags => "R",
330         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
331         ins       => [ "base", "index", "left", "right", "mem" ],
332         emit      => '. add%M %binop',
333         units     => [ "GP" ],
334         mode      => $mode_gp,
335         modified_flags => $status_flags
336 },
337
338 Adc => {
339         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
340         emit      => '. adc%M %binop',
341         units     => [ "GP" ],
342         mode      => $mode_gp,
343         modified_flags => $status_flags
344 },
345
346 Add64Bit => {
347         irn_flags => "R",
348         arity     => 4,
349         reg_req   => { in => [ "gp", "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
350         emit      => '
351 . movl %S0, %D0
352 . movl %S1, %D1
353 . addl %S2, %D0
354 . adcl %S3, %D1
355 ',
356         outs      => [ "low_res", "high_res" ],
357         units     => [ "GP" ],
358         modified_flags => $status_flags
359 },
360
361 l_Add => {
362         op_flags  => "C",
363         irn_flags => "R",
364         cmp_attr  => "return 1;",
365         arity     => 2,
366 },
367
368 l_Adc => {
369         op_flags  => "C",
370         cmp_attr  => "return 1;",
371         arity     => 2,
372 },
373
374 Mul => {
375         # we should not rematrialize this node. It produces 2 results and has
376         # very strict constrains
377         reg_req   => { in => [ "gp", "gp", "eax", "gp", "none" ], out => [ "eax", "edx", "none" ] },
378         emit      => '. mul%M %unop',
379         outs      => [ "EAX", "EDX", "M" ],
380         latency   => 10,
381         units     => [ "GP" ],
382         modified_flags => $status_flags
383 },
384
385 l_Mul => {
386         # we should not rematrialize this node. It produces 2 results and has
387         # very strict constrains
388         op_flags  => "C",
389         cmp_attr  => "return 1;",
390         outs      => [ "EAX", "EDX", "M" ],
391         arity     => 2
392 },
393
394 IMul => {
395         irn_flags => "R",
396         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
397         emit      => '. imul%M %binop',
398         latency   => 5,
399         units     => [ "GP" ],
400         mode      => $mode_gp,
401         modified_flags => $status_flags
402 },
403
404 IMul1OP => {
405         irn_flags => "R",
406         reg_req   => { in => [ "gp", "gp", "eax", "gp", "none" ], out => [ "eax", "edx", "none" ] },
407         emit      => '. imul%M %unop',
408         outs      => [ "EAX", "EDX", "M" ],
409         latency   => 5,
410         units     => [ "GP" ],
411         modified_flags => $status_flags
412 },
413
414 l_IMul => {
415         op_flags  => "C",
416         cmp_attr  => "return 1;",
417         arity     => 2
418 },
419
420 And => {
421         irn_flags => "R",
422         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
423         emit      => '. and%M %binop',
424         units     => [ "GP" ],
425         mode      => $mode_gp,
426         modified_flags => $status_flags
427 },
428
429 Or => {
430         irn_flags => "R",
431         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
432         emit      => '. or%M %binop',
433         units     => [ "GP" ],
434         mode      => $mode_gp,
435         modified_flags => $status_flags
436 },
437
438 Xor => {
439         irn_flags => "R",
440         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
441         emit      => '. xor%M %binop',
442         units     => [ "GP" ],
443         mode      => $mode_gp,
444         modified_flags => $status_flags
445 },
446
447 l_Xor => {
448         op_flags  => "C",
449         cmp_attr  => "return 1;",
450         arity     => 2,
451         modified_flags => $status_flags
452 },
453
454 # not commutative operations
455
456 Sub => {
457         irn_flags => "R",
458         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
459         emit      => '. sub%M %binop',
460         units     => [ "GP" ],
461         mode      => $mode_gp,
462         modified_flags => $status_flags
463 },
464
465 Sbb => {
466         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "in_r3 !in_r4" ] },
467         emit      => '. sbb%M %binop',
468         units     => [ "GP" ],
469         mode      => $mode_gp,
470         modified_flags => $status_flags
471 },
472
473 Sub64Bit => {
474         irn_flags => "R",
475         arity     => 4,
476         reg_req   => { in => [ "gp", "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
477         emit      => '
478 . movl %S0, %D0
479 . movl %S1, %D1
480 . subl %S2, %D0
481 . sbbl %S3, %D1
482 ',
483         outs      => [ "low_res", "high_res" ],
484         units     => [ "GP" ],
485         modified_flags => $status_flags
486 },
487
488 l_Sub => {
489         irn_flags => "R",
490         cmp_attr  => "return 1;",
491         arity     => 2,
492 },
493
494 l_Sbb => {
495         cmp_attr  => "return 1;",
496         arity     => 2,
497 },
498
499 IDiv => {
500         op_flags  => "F|L",
501         state     => "exc_pinned",
502         reg_req   => { in => [ "gp", "gp", "eax", "edx", "gp", "none" ], out => [ "eax", "edx", "none" ] },
503         attr      => "ia32_op_flavour_t dm_flav",
504         init_attr => "attr->data.op_flav = dm_flav;",
505         emit      => ". idiv%M %unop",
506         outs      => [ "div_res", "mod_res", "M" ],
507         latency   => 25,
508         units     => [ "GP" ],
509         modified_flags => $status_flags
510 },
511
512 Div => {
513         op_flags  => "F|L",
514         state     => "exc_pinned",
515         reg_req   => { in => [ "gp", "gp", "eax", "edx", "gp", "none" ], out => [ "eax", "edx", "none" ] },
516         attr      => "ia32_op_flavour_t dm_flav",
517         init_attr => "attr->data.op_flav = dm_flav;",
518         emit      => ". div%M %unop",
519         outs      => [ "div_res", "mod_res", "M" ],
520         latency   => 25,
521         units     => [ "GP" ],
522         modified_flags => $status_flags
523 },
524
525 Shl => {
526         irn_flags => "R",
527         reg_req   => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
528         ins       => [ "base", "index", "left", "right", "mem" ],
529         emit      => '. shl%M %binop',
530         units     => [ "GP" ],
531         mode      => $mode_gp,
532         modified_flags => $status_flags
533 },
534
535 l_Shl => {
536         cmp_attr  => "return 1;",
537         arity     => 2
538 },
539
540 ShlD => {
541         irn_flags => "R",
542         # Out requirements is: different from all in
543         # This is because, out must be different from LowPart and ShiftCount.
544         # We could say "!ecx !in_r4" but it can occur, that all values live through
545         # this Shift and the only value dying is the ShiftCount. Then there would be a
546         # register missing, as result must not be ecx and all other registers are
547         # occupied. What we should write is "!in_r4 !in_r5", but this is not supported
548         # (and probably never will). So we create artificial interferences of the result
549         # with all inputs, so the spiller can always assure a free register.
550         reg_req   => { in => [ "gp", "gp", "gp", "gp", "ecx", "none" ], out => [ "!in" ] },
551         emit      =>
552 '
553 if (get_ia32_immop_type(node) == ia32_ImmNone) {
554         if (get_ia32_op_type(node) == ia32_AddrModeD) {
555                 . shld%M %%cl, %S3, %AM
556         } else {
557                 . shld%M %%cl, %S3, %S2
558         }
559 } else {
560         if (get_ia32_op_type(node) == ia32_AddrModeD) {
561                 . shld%M %C, %S3, %AM
562         } else {
563                 . shld%M %C, %S3, %S2
564         }
565 }
566 ',
567         latency   => 6,
568         units     => [ "GP" ],
569         mode      => $mode_gp,
570         modified_flags => $status_flags
571 },
572
573 l_ShlD => {
574         cmp_attr  => "return 1;",
575         arity     => 3,
576 },
577
578 Shr => {
579         irn_flags => "R",
580         reg_req   => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
581         emit      => '. shr%M %binop',
582         units     => [ "GP" ],
583         mode      => $mode_gp,
584         modified_flags => $status_flags
585 },
586
587 l_Shr => {
588         cmp_attr  => "return 1;",
589         arity     => 2
590 },
591
592 ShrD => {
593         irn_flags => "R",
594         # Out requirements is: different from all in
595         # This is because, out must be different from LowPart and ShiftCount.
596         # We could say "!ecx !in_r4" but it can occur, that all values live through
597         # this Shift and the only value dying is the ShiftCount. Then there would be a
598         # register missing, as result must not be ecx and all other registers are
599         # occupied. What we should write is "!in_r4 !in_r5", but this is not supported
600         # (and probably never will). So we create artificial interferences of the result
601         # with all inputs, so the spiller can always assure a free register.
602         reg_req   => { in => [ "gp", "gp", "gp", "gp", "ecx", "none" ], out => [ "!in" ] },
603         emit      => '
604 if (get_ia32_immop_type(node) == ia32_ImmNone) {
605         if (get_ia32_op_type(node) == ia32_AddrModeD) {
606                 . shrd%M %%cl, %S3, %AM
607         } else {
608                 . shrd%M %%cl, %S3, %S2
609         }
610 } else {
611         if (get_ia32_op_type(node) == ia32_AddrModeD) {
612                 . shrd%M %C, %S3, %AM
613         } else {
614                 . shrd%M %C, %S3, %S2
615         }
616 }
617 ',
618         latency   => 6,
619         units     => [ "GP" ],
620         mode      => $mode_gp,
621         modified_flags => $status_flags
622 },
623
624 l_ShrD => {
625         cmp_attr  => "return 1;",
626         arity     => 3
627 },
628
629 Sar => {
630         irn_flags => "R",
631         reg_req   => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
632         emit      => '. sar%M %binop',
633         units     => [ "GP" ],
634         mode      => $mode_gp,
635         modified_flags => $status_flags
636 },
637
638 l_Sar => {
639         cmp_attr  => "return 1;",
640         arity     => 2
641 },
642
643 Ror => {
644         irn_flags => "R",
645         reg_req   => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
646         emit      => '. ror%M %binop',
647         units     => [ "GP" ],
648         mode      => $mode_gp,
649         modified_flags => $status_flags
650 },
651
652 Rol => {
653         irn_flags => "R",
654         reg_req   => { in => [ "gp", "gp", "gp", "ecx", "none" ], out => [ "in_r3 !in_r4" ] },
655         emit      => '. rol%M %binop',
656         units     => [ "GP" ],
657         mode      => $mode_gp,
658         modified_flags => $status_flags
659 },
660
661 # unary operations
662
663 Neg => {
664         irn_flags => "R",
665         reg_req   => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
666         emit      => '. neg%M %unop',
667         units     => [ "GP" ],
668         mode      => $mode_gp,
669         modified_flags => $status_flags
670 },
671
672 Minus64Bit => {
673         irn_flags => "R",
674         reg_req   => { in => [ "gp", "gp", "gp" ], out => [ "!in", "!in" ] },
675         emit      => '
676 . movl %S0, %D0
677 . movl %S0, %D1
678 . subl %S1, %D0
679 . sbbl %S2, %D1
680 ',
681         outs      => [ "low_res", "high_res" ],
682         units     => [ "GP" ],
683         modified_flags => $status_flags
684 },
685
686
687 l_Neg => {
688         cmp_attr  => "return 1;",
689         arity     => 1,
690 },
691
692 Inc => {
693         irn_flags => "R",
694         reg_req   => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
695         emit      => '. inc%M %unop',
696         units     => [ "GP" ],
697         mode      => $mode_gp,
698         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
699 },
700
701 Dec => {
702         irn_flags => "R",
703         reg_req   => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
704         emit      => '. dec%M %unop',
705         units     => [ "GP" ],
706         mode      => $mode_gp,
707         modified_flags => [ "OF", "SF", "ZF", "AF", "PF" ]
708 },
709
710 Not => {
711         irn_flags => "R",
712         reg_req   => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3" ] },
713         emit      => '. not%M %unop',
714         units     => [ "GP" ],
715         mode      => $mode_gp,
716         modified_flags => []
717 },
718
719 # other operations
720
721 CondJmp => {
722         state     => "pinned",
723         op_flags  => "L|X|Y",
724         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "none", "none"] },
725         outs      => [ "false", "true" ],
726         latency   => 3,
727         units     => [ "BRANCH" ],
728 },
729
730 TestJmp => {
731         state     => "pinned",
732         op_flags  => "L|X|Y",
733         reg_req  => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
734         outs      => [ "false", "true" ],
735         latency   => 3,
736         units     => [ "BRANCH" ],
737 },
738
739 CJmpAM => {
740         state     => "pinned",
741         op_flags  => "L|X|Y",
742         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "none", "none" ] },
743         outs      => [ "false", "true" ],
744         units     => [ "BRANCH" ],
745 },
746
747 CJmp => {
748         state     => "pinned",
749         op_flags  => "L|X|Y",
750         reg_req   => { in => [ "gp", "gp" ] },
751         units     => [ "BRANCH" ],
752 },
753
754 SwitchJmp => {
755         state     => "pinned",
756         op_flags  => "L|X|Y",
757         reg_req   => { in => [ "gp" ], out => [ "none" ] },
758         latency   => 3,
759         units     => [ "BRANCH" ],
760 },
761
762 Const => {
763         op_flags  => "c",
764         irn_flags => "R",
765         reg_req   => { out => [ "gp" ] },
766         units     => [ "GP" ],
767         mode      => $mode_gp,
768 },
769
770 Unknown_GP => {
771         state     => "pinned",
772         op_flags  => "c",
773         irn_flags => "I",
774         reg_req   => { out => [ "gp_UKNWN" ] },
775         units     => [],
776         emit      => "",
777         mode      => $mode_gp
778 },
779
780 Unknown_VFP => {
781         state     => "pinned",
782         op_flags  => "c",
783         irn_flags => "I",
784         reg_req   => { out => [ "vfp_UKNWN" ] },
785         units     => [],
786         emit      => "",
787         mode      => "mode_E"
788 },
789
790 Unknown_XMM => {
791         state     => "pinned",
792         op_flags  => "c",
793         irn_flags => "I",
794         reg_req   => { out => [ "xmm_UKNWN" ] },
795         units     => [],
796         emit      => "",
797         mode      => "mode_E"
798 },
799
800 NoReg_GP => {
801         state     => "pinned",
802         op_flags  => "c",
803         irn_flags => "I",
804         reg_req   => { out => [ "gp_NOREG" ] },
805         units     => [],
806         emit      => "",
807         mode      => $mode_gp
808 },
809
810 NoReg_VFP => {
811         state     => "pinned",
812         op_flags  => "c",
813         irn_flags => "I",
814         reg_req   => { out => [ "vfp_NOREG" ] },
815         units     => [],
816         emit      => "",
817         mode      => "mode_E"
818 },
819
820 NoReg_XMM => {
821         state     => "pinned",
822         op_flags  => "c",
823         irn_flags => "I",
824         reg_req   => { out => [ "xmm_NOREG" ] },
825         units     => [],
826         emit      => "",
827         mode      => "mode_E"
828 },
829
830 ChangeCW => {
831         state     => "pinned",
832         op_flags  => "c",
833         irn_flags => "I",
834         reg_req   => { out => [ "fp_cw" ] },
835         mode      => $mode_fpcw,
836         latency   => 3,
837         units     => [ "GP" ],
838         modified_flags => $fpcw_flags
839 },
840
841 FldCW => {
842         op_flags  => "L|F",
843         state     => "exc_pinned",
844         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "fp_cw" ] },
845         latency   => 5,
846         emit      => ". fldcw %AM",
847         mode      => $mode_fpcw,
848         units     => [ "GP" ],
849         modified_flags => $fpcw_flags
850 },
851
852 FnstCW => {
853         op_flags  => "L|F",
854         state     => "exc_pinned",
855         reg_req   => { in => [ "gp", "gp", "fp_cw", "none" ], out => [ "none" ] },
856         latency   => 5,
857         emit      => ". fnstcw %AM",
858         mode      => "mode_M",
859         units     => [ "GP" ],
860 },
861
862 Cltd => {
863         # we should not rematrialize this node. It produces 2 results and has
864         # very strict constrains
865         reg_req   => { in => [ "gp" ], out => [ "eax in_r1", "edx" ] },
866         emit      => '. cltd',
867         outs      => [ "EAX", "EDX" ],
868         units     => [ "GP" ],
869 },
870
871 # Load / Store
872
873 Load => {
874         op_flags  => "L|F",
875         state     => "exc_pinned",
876         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
877         latency   => 3,
878         emit      => ". mov%SE%ME%.l %AM, %D0",
879         outs      => [ "res", "M" ],
880         units     => [ "GP" ],
881 },
882
883 l_Load => {
884         op_flags  => "L|F",
885         cmp_attr  => "return 1;",
886         outs      => [ "res", "M" ],
887         arity     => 2,
888 },
889
890 l_Store => {
891         op_flags  => "L|F",
892         cmp_attr  => "return 1;",
893         state     => "exc_pinned",
894         arity     => 3,
895         mode      => "mode_M",
896 },
897
898 Store => {
899         op_flags  => "L|F",
900         state     => "exc_pinned",
901         reg_req   => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
902         emit      => '. mov%M %binop',
903         latency   => 3,
904         units     => [ "GP" ],
905         mode      => "mode_M",
906 },
907
908 Store8Bit => {
909         op_flags  => "L|F",
910         state     => "exc_pinned",
911         reg_req   => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => ["none" ] },
912         emit      => '. mov%M %binop',
913         latency   => 3,
914         units     => [ "GP" ],
915         mode      => "mode_M",
916 },
917
918 Lea => {
919         irn_flags => "R",
920         reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
921         emit      => '. leal %AM, %D0',
922         latency   => 2,
923         units     => [ "GP" ],
924         mode      => $mode_gp,
925         modified_flags => [],
926 },
927
928 Push => {
929         reg_req   => { in => [ "gp", "gp", "gp", "esp", "none" ], out => [ "esp", "none" ] },
930         emit      => '. push%M %unop',
931         outs      => [ "stack:I|S", "M" ],
932         latency   => 3,
933         units     => [ "GP" ],
934         modified_flags => [],
935 },
936
937 Pop => {
938         reg_req   => { in => [ "gp", "gp", "esp", "none" ], out => [ "esp", "gp", "none" ] },
939         emit      => '. pop%M %unop',
940         outs      => [ "stack:I|S", "res", "M" ],
941         latency   => 4,
942         units     => [ "GP" ],
943         modified_flags => [],
944 },
945
946 Enter => {
947         reg_req   => { in => [ "esp" ], out => [ "ebp", "esp", "none" ] },
948         emit      => '. enter',
949         outs      => [ "frame:I", "stack:I|S", "M" ],
950         latency   => 15,
951         units     => [ "GP" ],
952 },
953
954 Leave => {
955         reg_req   => { in => [ "esp", "ebp" ], out => [ "ebp", "esp" ] },
956         emit      => '. leave',
957         outs      => [ "frame:I", "stack:I|S" ],
958         latency   => 3,
959         units     => [ "GP" ],
960 },
961
962 AddSP => {
963         irn_flags => "I",
964         reg_req   => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
965         emit      => '. addl %binop',
966         outs      => [ "stack:S", "M" ],
967         units     => [ "GP" ],
968         modified_flags => $status_flags
969 },
970
971 SubSP => {
972         irn_flags => "I",
973         reg_req   => { in => [ "gp", "gp", "esp", "gp", "none" ], out => [ "in_r3", "none" ] },
974         emit      => '. subl %binop',
975         outs      => [ "stack:S", "M" ],
976         units     => [ "GP" ],
977         modified_flags => $status_flags
978 },
979
980 LdTls => {
981         irn_flags => "R",
982         reg_req   => { out => [ "gp" ] },
983         units     => [ "GP" ],
984 },
985
986 # the int instruction
987 int => {
988         reg_req   => { in => [ "none" ], out => [ "none" ] },
989         mode      => "mode_M",
990         attr      => "tarval *tv",
991         init_attr => "\tset_ia32_Immop_tarval(res, tv);",
992         emit      => '. int %C',
993         units     => [ "GP" ],
994         cmp_attr  => "return 1;",
995 },
996
997
998 #-----------------------------------------------------------------------------#
999 #   _____ _____ ______    __ _             _                     _            #
1000 #  / ____/ ____|  ____|  / _| |           | |                   | |           #
1001 # | (___| (___ | |__    | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1002 #  \___ \\___ \|  __|   |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1003 #  ____) |___) | |____  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
1004 # |_____/_____/|______| |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1005 #-----------------------------------------------------------------------------#
1006
1007 # commutative operations
1008
1009 xAdd => {
1010         irn_flags => "R",
1011         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1012         emit      => '. add%XXM %binop',
1013         latency   => 4,
1014         units     => [ "SSE" ],
1015         mode      => "mode_E",
1016 },
1017
1018 xMul => {
1019         irn_flags => "R",
1020         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1021         emit      => '. mul%XXM %binop',
1022         latency   => 4,
1023         units     => [ "SSE" ],
1024         mode      => "mode_E",
1025 },
1026
1027 xMax => {
1028         irn_flags => "R",
1029         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1030         emit      => '. max%XXM %binop',
1031         latency   => 2,
1032         units     => [ "SSE" ],
1033         mode      => "mode_E",
1034 },
1035
1036 xMin => {
1037         irn_flags => "R",
1038         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1039         emit      => '. min%XXM %binop',
1040         latency   => 2,
1041         units     => [ "SSE" ],
1042         mode      => "mode_E",
1043 },
1044
1045 xAnd => {
1046         irn_flags => "R",
1047         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1048         emit      => '. andp%XSD %binop',
1049         latency   => 3,
1050         units     => [ "SSE" ],
1051         mode      => "mode_E",
1052 },
1053
1054 xOr => {
1055         irn_flags => "R",
1056         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1057         emit      => '. orp%XSD %binop',
1058         units     => [ "SSE" ],
1059         mode      => "mode_E",
1060 },
1061
1062 xXor => {
1063         irn_flags => "R",
1064         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1065         emit      => '. xorp%XSD %binop',
1066         latency   => 3,
1067         units     => [ "SSE" ],
1068         mode      => "mode_E",
1069 },
1070
1071 # not commutative operations
1072
1073 xAndNot => {
1074         irn_flags => "R",
1075         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1076         emit      => '. andnp%XSD %binop',
1077         latency   => 3,
1078         units     => [ "SSE" ],
1079         mode      => "mode_E",
1080 },
1081
1082 xSub => {
1083         irn_flags => "R",
1084         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3" ] },
1085         emit      => '. sub%XXM %binop',
1086         latency   => 4,
1087         units     => [ "SSE" ],
1088         mode      => "mode_E",
1089 },
1090
1091 xDiv => {
1092         irn_flags => "R",
1093         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4", "none" ] },
1094         outs      => [ "res", "M" ],
1095         emit      => '. div%XXM %binop',
1096         latency   => 16,
1097         units     => [ "SSE" ],
1098 },
1099
1100 # other operations
1101
1102 xCmp => {
1103         irn_flags => "R",
1104         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "in_r3 !in_r4" ] },
1105         latency   => 3,
1106         units     => [ "SSE" ],
1107         mode      => "mode_E",
1108 },
1109
1110 xCondJmp => {
1111         state     => "pinned",
1112         op_flags  => "L|X|Y",
1113         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "none", "none" ] },
1114         outs      => [ "false", "true" ],
1115         latency   => 5,
1116         units     => [ "SSE" ],
1117 },
1118
1119 xConst => {
1120         op_flags  => "c",
1121         irn_flags => "R",
1122         reg_req   => { out => [ "xmm" ] },
1123         emit      => '. mov%XXM %C, %D0',
1124         latency   => 2,
1125         units     => [ "SSE" ],
1126         mode      => "mode_E",
1127 },
1128
1129 # Load / Store
1130
1131 xLoad => {
1132         op_flags  => "L|F",
1133         state     => "exc_pinned",
1134         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1135         emit      => '. mov%XXM %AM, %D0',
1136         outs      => [ "res", "M" ],
1137         latency   => 2,
1138         units     => [ "SSE" ],
1139 },
1140
1141 xStore => {
1142         op_flags => "L|F",
1143         state    => "exc_pinned",
1144         reg_req  => { in => [ "gp", "gp", "xmm", "none" ] },
1145         emit     => '. mov%XXM %binop',
1146         latency  => 2,
1147         units    => [ "SSE" ],
1148         mode     => "mode_M",
1149 },
1150
1151 xStoreSimple => {
1152         op_flags => "L|F",
1153         state    => "exc_pinned",
1154         reg_req  => { in => [ "gp", "gp", "xmm", "none" ] },
1155         ins      => [ "base", "index", "val", "mem" ],
1156         emit     => '. mov%XXM %S2, %AM',
1157         latency  => 2,
1158         units    => [ "SSE" ],
1159         mode     => "mode_M",
1160 },
1161
1162 CvtSI2SS => {
1163         op_flags => "L|F",
1164         reg_req  => { in => [ "gp", "gp", "gp", "none" ], out => [ "xmm" ] },
1165         emit     => '. cvtsi2ss %D0, %AM',
1166         latency  => 2,
1167         units    => [ "SSE" ],
1168         mode     => $mode_xmm
1169 },
1170
1171 CvtSI2SD => {
1172         op_flags => "L|F",
1173         reg_req  => { in => [ "gp", "gp", "gp", "none" ], out => [ "xmm" ] },
1174         emit     => '. cvtsi2sd %unop',
1175         latency  => 2,
1176         units    => [ "SSE" ],
1177         mode     => $mode_xmm
1178 },
1179
1180
1181 l_X87toSSE => {
1182         op_flags => "L|F",
1183         cmp_attr => "return 1;",
1184         arity    => 3,
1185 },
1186
1187 l_SSEtoX87 => {
1188         op_flags => "L|F",
1189         cmp_attr => "return 1;",
1190         arity    => 3,
1191 },
1192
1193 GetST0 => {
1194         op_flags => "L|F",
1195         irn_flags => "I",
1196         state    => "exc_pinned",
1197         reg_req  => { in => [ "gp", "gp", "none" ] },
1198         emit     => '. fstp%XM %AM',
1199         latency  => 4,
1200         units    => [ "SSE" ],
1201         mode     => "mode_M",
1202 },
1203
1204 SetST0 => {
1205         op_flags => "L|F",
1206         irn_flags => "I",
1207         state    => "exc_pinned",
1208         reg_req  => { in => [ "gp", "gp", "none" ], out => [ "vf0", "none" ] },
1209         ins      => [ "base", "index", "mem" ],
1210         emit     => '. fld%XM %AM',
1211         outs     => [ "res", "M" ],
1212         latency  => 2,
1213         units     => [ "SSE" ],
1214 },
1215
1216 # CopyB
1217
1218 CopyB => {
1219         op_flags => "F|H",
1220         state    => "pinned",
1221         reg_req  => { in => [ "edi", "esi", "ecx", "none" ], out => [ "edi", "esi", "ecx", "none" ] },
1222         outs     => [ "DST", "SRC", "CNT", "M" ],
1223         units    => [ "GP" ],
1224         modified_flags => [ "DF" ]
1225 },
1226
1227 CopyB_i => {
1228         op_flags => "F|H",
1229         state    => "pinned",
1230         reg_req  => { in => [ "edi", "esi", "none" ], out => [  "edi", "esi", "none" ] },
1231         outs     => [ "DST", "SRC", "M" ],
1232         units    => [ "GP" ],
1233         modified_flags => [ "DF" ]
1234 },
1235
1236 # Conversions
1237
1238 Conv_I2I => {
1239         reg_req  => { in => [ "gp", "gp", "gp", "none" ], out => [ "in_r3", "none" ] },
1240         units    => [ "GP" ],
1241         mode     => $mode_gp,
1242         modified_flags => $status_flags
1243 },
1244
1245 Conv_I2I8Bit => {
1246         reg_req  => { in => [ "gp", "gp", "eax ebx ecx edx", "none" ], out => [ "in_r3", "none" ] },
1247         units    => [ "GP" ],
1248         mode     => $mode_gp,
1249         modified_flags => $status_flags
1250 },
1251
1252 Conv_I2FP => {
1253         reg_req  => { in => [ "gp", "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1254         latency  => 10,
1255         units    => [ "SSE" ],
1256         mode     => "mode_E",
1257 },
1258
1259 Conv_FP2I => {
1260         reg_req  => { in => [ "gp", "gp", "xmm", "none" ], out => [ "gp", "none" ] },
1261         latency  => 10,
1262         units    => [ "SSE" ],
1263         mode     => $mode_gp,
1264 },
1265
1266 Conv_FP2FP => {
1267         reg_req  => { in => [ "gp", "gp", "xmm", "none" ], out => [ "xmm", "none" ] },
1268         latency  => 8,
1269         units    => [ "SSE" ],
1270         mode     => "mode_E",
1271 },
1272
1273 CmpCMov => {
1274         irn_flags => "R",
1275         reg_req   => { in => [ "gp", "gp", "gp", "gp" ], out => [ "in_r4" ] },
1276         latency   => 2,
1277         units     => [ "GP" ],
1278         mode      => $mode_gp,
1279 },
1280
1281 PsiCondCMov => {
1282         irn_flags => "R",
1283         reg_req   => { in => [ "gp", "gp", "gp" ], out => [ "in_r3" ] },
1284         latency   => 2,
1285         units     => [ "GP" ],
1286         mode      => $mode_gp,
1287 },
1288
1289 xCmpCMov => {
1290         irn_flags => "R",
1291         reg_req   => { in => [ "xmm", "xmm", "gp", "gp" ], out => [ "in_r4" ] },
1292         latency   => 5,
1293         units     => [ "SSE" ],
1294         mode      => $mode_gp,
1295 },
1296
1297 vfCmpCMov => {
1298         irn_flags => "R",
1299         reg_req   => { in => [ "vfp", "vfp", "gp", "gp" ], out => [ "in_r4" ] },
1300         latency   => 10,
1301         units     => [ "VFP" ],
1302         mode      => $mode_gp,
1303 },
1304
1305 CmpSet => {
1306         irn_flags => "R",
1307         reg_req   => { in => [ "gp", "gp", "gp", "gp", "none" ], out => [ "eax ebx ecx edx" ] },
1308         latency   => 2,
1309         units     => [ "GP" ],
1310         mode      => $mode_gp,
1311 },
1312
1313 PsiCondSet => {
1314         irn_flags => "R",
1315         reg_req   => { in => [ "gp" ], out => [ "eax ebx ecx edx" ] },
1316         latency   => 2,
1317         units     => [ "GP" ],
1318         mode      => $mode_gp,
1319 },
1320
1321 xCmpSet => {
1322         irn_flags => "R",
1323         reg_req   => { in => [ "gp", "gp", "xmm", "xmm", "none" ], out => [ "eax ebx ecx edx" ] },
1324         latency   => 5,
1325         units     => [ "SSE" ],
1326         mode      => $mode_gp,
1327 },
1328
1329 vfCmpSet => {
1330         irn_flags => "R",
1331         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "eax ebx ecx edx" ] },
1332         latency   => 10,
1333         units     => [ "VFP" ],
1334         mode      => $mode_gp,
1335 },
1336
1337 vfCMov => {
1338         irn_flags => "R",
1339         reg_req   => { in => [ "vfp", "vfp", "vfp", "vfp" ], out => [ "vfp" ] },
1340         latency   => 10,
1341         units     => [ "VFP" ],
1342         mode      => "mode_E",
1343 },
1344
1345 #----------------------------------------------------------#
1346 #        _      _               _    __ _             _    #
1347 #       (_)    | |             | |  / _| |           | |   #
1348 # __   ___ _ __| |_ _   _  __ _| | | |_| | ___   __ _| |_  #
1349 # \ \ / / | '__| __| | | |/ _` | | |  _| |/ _ \ / _` | __| #
1350 #  \ V /| | |  | |_| |_| | (_| | | | | | | (_) | (_| | |_  #
1351 #   \_/ |_|_|   \__|\__,_|\__,_|_| |_| |_|\___/ \__,_|\__| #
1352 #                 | |                                      #
1353 #  _ __   ___   __| | ___  ___                             #
1354 # | '_ \ / _ \ / _` |/ _ \/ __|                            #
1355 # | | | | (_) | (_| |  __/\__ \                            #
1356 # |_| |_|\___/ \__,_|\___||___/                            #
1357 #----------------------------------------------------------#
1358
1359 vfadd => {
1360         irn_flags => "R",
1361         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1362         latency   => 4,
1363         units     => [ "VFP" ],
1364         mode      => "mode_E",
1365 },
1366
1367 vfmul => {
1368         irn_flags => "R",
1369         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1370         latency   => 4,
1371         units     => [ "VFP" ],
1372         mode      => "mode_E",
1373 },
1374
1375 l_vfmul => {
1376         op_flags  => "C",
1377         cmp_attr  => "return 1;",
1378         arity     => 2,
1379 },
1380
1381 vfsub => {
1382         irn_flags => "R",
1383         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1384         latency   => 4,
1385         units     => [ "VFP" ],
1386         mode      => "mode_E",
1387 },
1388
1389 l_vfsub => {
1390         cmp_attr  => "return 1;",
1391         arity     => 2,
1392 },
1393
1394 vfdiv => {
1395         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp", "none" ] },
1396         outs      => [ "res", "M" ],
1397         latency   => 20,
1398         units     => [ "VFP" ],
1399 },
1400
1401 l_vfdiv => {
1402         cmp_attr  => "return 1;",
1403         outs      => [ "res", "M" ],
1404         arity     => 2,
1405 },
1406
1407 vfprem => {
1408         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "vfp" ] },
1409         latency   => 20,
1410         units     => [ "VFP" ],
1411         mode      => "mode_E",
1412 },
1413
1414 l_vfprem => {
1415         cmp_attr  => "return 1;",
1416         arity     => 2,
1417 },
1418
1419 vfabs => {
1420         irn_flags => "R",
1421         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1422         latency   => 2,
1423         units     => [ "VFP" ],
1424         mode      => "mode_E",
1425 },
1426
1427 vfchs => {
1428         irn_flags => "R",
1429         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1430         latency   => 2,
1431         units     => [ "VFP" ],
1432         mode      => "mode_E",
1433 },
1434
1435 vfsin => {
1436         irn_flags => "R",
1437         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1438         latency   => 150,
1439         units     => [ "VFP" ],
1440         mode      => "mode_E",
1441 },
1442
1443 vfcos => {
1444         irn_flags => "R",
1445         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1446         latency   => 150,
1447         units     => [ "VFP" ],
1448         mode      => "mode_E",
1449 },
1450
1451 vfsqrt => {
1452         irn_flags => "R",
1453         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1454         latency   => 30,
1455         units     => [ "VFP" ],
1456         mode      => "mode_E",
1457 },
1458
1459 # virtual Load and Store
1460
1461 vfld => {
1462         op_flags  => "L|F",
1463         state     => "exc_pinned",
1464         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1465         outs      => [ "res", "M" ],
1466         latency   => 2,
1467         units     => [ "VFP" ],
1468 },
1469
1470 vfst => {
1471         op_flags  => "L|F",
1472         state     => "exc_pinned",
1473         reg_req   => { in => [ "gp", "gp", "vfp", "none" ] },
1474         latency   => 2,
1475         units     => [ "VFP" ],
1476         mode      => "mode_M",
1477 },
1478
1479 # Conversions
1480
1481 vfild => {
1482         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "vfp", "none" ] },
1483         outs      => [ "res", "M" ],
1484         latency   => 4,
1485         units     => [ "VFP" ],
1486 },
1487
1488 l_vfild => {
1489         cmp_attr  => "return 1;",
1490         outs      => [ "res", "M" ],
1491         arity     => 2,
1492 },
1493
1494 vfist => {
1495         reg_req   => { in => [ "gp", "gp", "vfp", "fpcw", "none" ] },
1496         latency   => 4,
1497         units     => [ "VFP" ],
1498         mode      => "mode_M",
1499 },
1500
1501 l_vfist => {
1502         cmp_attr  => "return 1;",
1503         arity     => 3,
1504         mode      => "mode_M",
1505 },
1506
1507
1508 # constants
1509
1510 vfldz => {
1511         irn_flags => "R",
1512         reg_req   => { out => [ "vfp" ] },
1513         latency   => 4,
1514         units     => [ "VFP" ],
1515         mode      => "mode_E",
1516 },
1517
1518 vfld1 => {
1519         irn_flags => "R",
1520         reg_req   => { out => [ "vfp" ] },
1521         latency   => 4,
1522         units     => [ "VFP" ],
1523         mode      => "mode_E",
1524 },
1525
1526 vfldpi => {
1527         irn_flags => "R",
1528         reg_req   => { out => [ "vfp" ] },
1529         latency   => 4,
1530         units     => [ "VFP" ],
1531         mode      => "mode_E",
1532 },
1533
1534 vfldln2 => {
1535         irn_flags => "R",
1536         reg_req   => { out => [ "vfp" ] },
1537         latency   => 4,
1538         units     => [ "VFP" ],
1539         mode      => "mode_E",
1540 },
1541
1542 vfldlg2 => {
1543         irn_flags => "R",
1544         reg_req   => { out => [ "vfp" ] },
1545         latency   => 4,
1546         units     => [ "VFP" ],
1547         mode      => "mode_E",
1548 },
1549
1550 vfldl2t => {
1551         irn_flags => "R",
1552         reg_req   => { out => [ "vfp" ] },
1553         latency   => 4,
1554         units     => [ "VFP" ],
1555         mode      => "mode_E",
1556 },
1557
1558 vfldl2e => {
1559         irn_flags => "R",
1560         reg_req   => { out => [ "vfp" ] },
1561         latency   => 4,
1562         units     => [ "VFP" ],
1563         mode      => "mode_E",
1564 },
1565
1566 vfConst => {
1567         op_flags  => "c",
1568         irn_flags => "R",
1569 #  init_attr => "  set_ia32_ls_mode(res, mode);",
1570         reg_req   => { out => [ "vfp" ] },
1571         latency   => 3,
1572         units     => [ "VFP" ],
1573         mode      => "mode_E",
1574 },
1575
1576 # other
1577
1578 vfCondJmp => {
1579         state     => "pinned",
1580         op_flags  => "L|X|Y",
1581         reg_req   => { in => [ "gp", "gp", "vfp", "vfp", "none" ], out => [ "none", "none", "eax" ] },
1582         outs      => [ "false", "true", "temp_reg_eax" ],
1583         latency   => 10,
1584         units     => [ "VFP" ],
1585 },
1586
1587 #------------------------------------------------------------------------#
1588 #       ___ _____    __ _             _                     _            #
1589 # __  _( _ )___  |  / _| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
1590 # \ \/ / _ \  / /  | |_| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
1591 #  >  < (_) |/ /   |  _| | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
1592 # /_/\_\___//_/    |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
1593 #------------------------------------------------------------------------#
1594
1595 # Note: gas is strangely buggy: fdivrp and fdivp as well as fsubrp and fsubp
1596 #       are swapped, we work this around in the emitter...
1597
1598 fadd => {
1599         op_flags  => "R",
1600         rd_constructor => "NONE",
1601         reg_req   => { },
1602         emit      => '. fadd%XM %x87_binop',
1603 },
1604
1605 faddp => {
1606         op_flags  => "R",
1607         rd_constructor => "NONE",
1608         reg_req   => { },
1609         emit      => '. faddp %x87_binop',
1610 },
1611
1612 fmul => {
1613         op_flags  => "R",
1614         rd_constructor => "NONE",
1615         reg_req   => { },
1616         emit      => '. fmul%XM %x87_binop',
1617 },
1618
1619 fmulp => {
1620         op_flags  => "R",
1621         rd_constructor => "NONE",
1622         reg_req   => { },
1623         emit      => '. fmulp %x87_binop',,
1624 },
1625
1626 fsub => {
1627         op_flags  => "R",
1628         rd_constructor => "NONE",
1629         reg_req   => { },
1630         emit      => '. fsub%XM %x87_binop',
1631 },
1632
1633 fsubp => {
1634         op_flags  => "R",
1635         rd_constructor => "NONE",
1636         reg_req   => { },
1637 # see note about gas bugs
1638         emit      => '. fsubrp %x87_binop',
1639 },
1640
1641 fsubr => {
1642         op_flags  => "R",
1643         rd_constructor => "NONE",
1644         irn_flags => "R",
1645         reg_req   => { },
1646         emit      => '. fsubr%XM %x87_binop',
1647 },
1648
1649 fsubrp => {
1650         op_flags  => "R",
1651         rd_constructor => "NONE",
1652         irn_flags => "R",
1653         reg_req   => { },
1654 # see note about gas bugs
1655         emit      => '. fsubp %x87_binop',
1656 },
1657
1658 fprem => {
1659         op_flags  => "R",
1660         rd_constructor => "NONE",
1661         reg_req   => { },
1662         emit      => '. fprem1',
1663 },
1664
1665 # this node is just here, to keep the simulator running
1666 # we can omit this when a fprem simulation function exists
1667 fpremp => {
1668         op_flags  => "R",
1669         rd_constructor => "NONE",
1670         reg_req   => { },
1671         emit      => '. fprem1',
1672 },
1673
1674 fdiv => {
1675         op_flags  => "R",
1676         rd_constructor => "NONE",
1677         reg_req   => { },
1678         emit      => '. fdiv%XM %x87_binop',
1679 },
1680
1681 fdivp => {
1682         op_flags  => "R",
1683         rd_constructor => "NONE",
1684         reg_req   => { },
1685 # see note about gas bugs
1686         emit      => '. fdivrp %x87_binop',
1687 },
1688
1689 fdivr => {
1690         op_flags  => "R",
1691         rd_constructor => "NONE",
1692         reg_req   => { },
1693         emit      => '. fdivr%XM %x87_binop',
1694 },
1695
1696 fdivrp => {
1697         op_flags  => "R",
1698         rd_constructor => "NONE",
1699         reg_req   => { },
1700 # see note about gas bugs
1701         emit      => '. fdivp %x87_binop',
1702 },
1703
1704 fabs => {
1705         op_flags  => "R",
1706         rd_constructor => "NONE",
1707         reg_req   => { },
1708         emit      => '. fabs',
1709 },
1710
1711 fchs => {
1712         op_flags  => "R|K",
1713         rd_constructor => "NONE",
1714         reg_req   => { },
1715         emit      => '. fchs',
1716 },
1717
1718 fsin => {
1719         op_flags  => "R",
1720         rd_constructor => "NONE",
1721         reg_req   => { },
1722         emit      => '. fsin',
1723 },
1724
1725 fcos => {
1726         op_flags  => "R",
1727         rd_constructor => "NONE",
1728         reg_req   => { },
1729         emit      => '. fcos',
1730 },
1731
1732 fsqrt => {
1733         op_flags  => "R",
1734         rd_constructor => "NONE",
1735         reg_req   => { },
1736         emit      => '. fsqrt $',
1737 },
1738
1739 # x87 Load and Store
1740
1741 fld => {
1742         rd_constructor => "NONE",
1743         op_flags  => "R|L|F",
1744         state     => "exc_pinned",
1745         reg_req   => { },
1746         emit      => '. fld%XM %AM',
1747 },
1748
1749 fst => {
1750         rd_constructor => "NONE",
1751         op_flags  => "R|L|F",
1752         state     => "exc_pinned",
1753         reg_req   => { },
1754         emit      => '. fst%XM %AM',
1755         mode      => "mode_M",
1756 },
1757
1758 fstp => {
1759         rd_constructor => "NONE",
1760         op_flags  => "R|L|F",
1761         state     => "exc_pinned",
1762         reg_req   => { },
1763         emit      => '. fstp%XM %AM',
1764         mode      => "mode_M",
1765 },
1766
1767 # Conversions
1768
1769 fild => {
1770         op_flags  => "R",
1771         rd_constructor => "NONE",
1772         reg_req   => { },
1773         emit      => '. fild%XM %AM',
1774 },
1775
1776 fist => {
1777         op_flags  => "R",
1778         rd_constructor => "NONE",
1779         reg_req   => { },
1780         emit      => '. fist%XM %AM',
1781         mode      => "mode_M",
1782 },
1783
1784 fistp => {
1785         op_flags  => "R",
1786         rd_constructor => "NONE",
1787         reg_req   => { },
1788         emit      => '. fistp%XM %AM',
1789         mode      => "mode_M",
1790 },
1791
1792 # constants
1793
1794 fldz => {
1795         op_flags  => "R|c|K",
1796         irn_flags  => "R",
1797         reg_req   => { },
1798         emit      => '. fldz',
1799 },
1800
1801 fld1 => {
1802         op_flags  => "R|c|K",
1803         irn_flags  => "R",
1804         reg_req   => { },
1805         emit      => '. fld1',
1806 },
1807
1808 fldpi => {
1809         op_flags  => "R|c|K",
1810         irn_flags  => "R",
1811         reg_req   => { },
1812         emit      => '. fldpi',
1813 },
1814
1815 fldln2 => {
1816         op_flags  => "R|c|K",
1817         irn_flags  => "R",
1818         reg_req   => { },
1819         emit      => '. fldln2',
1820 },
1821
1822 fldlg2 => {
1823         op_flags  => "R|c|K",
1824         irn_flags  => "R",
1825         reg_req   => { },
1826         emit      => '. fldlg2',
1827 },
1828
1829 fldl2t => {
1830         op_flags  => "R|c|K",
1831         irn_flags  => "R",
1832         reg_req   => { },
1833         emit      => '. fldll2t',
1834 },
1835
1836 fldl2e => {
1837         op_flags  => "R|c|K",
1838         irn_flags  => "R",
1839         reg_req   => { },
1840         emit      => '. fldl2e',
1841 },
1842
1843 # fxch, fpush, fpop
1844 # Note that it is NEVER allowed to do CSE on these nodes
1845 # Moreover, note the virtual register requierements!
1846
1847 fxch => {
1848         op_flags  => "R|K",
1849         reg_req   => { },
1850         cmp_attr  => "return 1;",
1851         emit      => '. fxch %X0',
1852 },
1853
1854 fpush => {
1855         op_flags  => "R|K",
1856         reg_req   => {},
1857         cmp_attr  => "return 1;",
1858         emit      => '. fld %X0',
1859 },
1860
1861 fpushCopy => {
1862         op_flags  => "R",
1863         reg_req   => { in => [ "vfp"], out => [ "vfp" ] },
1864         cmp_attr  => "return 1;",
1865         emit      => '. fld %X0',
1866 },
1867
1868 fpop => {
1869         op_flags  => "R|K",
1870         reg_req   => { },
1871         cmp_attr  => "return 1;",
1872         emit      => '. fstp %X0',
1873 },
1874
1875 # compare
1876
1877 fcomJmp => {
1878         op_flags  => "L|X|Y",
1879         reg_req   => { },
1880 },
1881
1882 fcompJmp => {
1883         op_flags  => "L|X|Y",
1884         reg_req   => { },
1885 },
1886
1887 fcomppJmp => {
1888         op_flags  => "L|X|Y",
1889         reg_req   => { },
1890 },
1891
1892 fcomrJmp => {
1893         op_flags  => "L|X|Y",
1894         reg_req   => { },
1895 },
1896
1897 fcomrpJmp => {
1898         op_flags  => "L|X|Y",
1899         reg_req   => { },
1900 },
1901
1902 fcomrppJmp => {
1903         op_flags  => "L|X|Y",
1904         reg_req   => { },
1905 },
1906
1907
1908 # -------------------------------------------------------------------------------- #
1909 #  ____ ____  _____                  _                               _             #
1910 # / ___/ ___|| ____| __   _____  ___| |_ ___  _ __   _ __   ___   __| | ___  ___   #
1911 # \___ \___ \|  _|   \ \ / / _ \/ __| __/ _ \| '__| | '_ \ / _ \ / _` |/ _ \/ __|  #
1912 #  ___) |__) | |___   \ V /  __/ (__| || (_) | |    | | | | (_) | (_| |  __/\__ \  #
1913 # |____/____/|_____|   \_/ \___|\___|\__\___/|_|    |_| |_|\___/ \__,_|\___||___/  #
1914 #                                                                                  #
1915 # -------------------------------------------------------------------------------- #
1916
1917
1918 # Spilling and reloading of SSE registers, hardcoded, not generated #
1919
1920 xxLoad => {
1921         op_flags  => "L|F",
1922         state     => "exc_pinned",
1923         reg_req   => { in => [ "gp", "gp", "none" ], out => [ "xmm", "none" ] },
1924         emit      => '. movdqu %D0, %AM',
1925         outs      => [ "res", "M" ],
1926         units     => [ "SSE" ],
1927 },
1928
1929 xxStore => {
1930         op_flags => "L|F",
1931         state    => "exc_pinned",
1932         reg_req  => { in => [ "gp", "gp", "xmm", "none" ] },
1933         emit     => '. movdqu %binop',
1934         units    => [ "SSE" ],
1935         mode     => "mode_M",
1936 },
1937
1938 ); # end of %nodes
1939
1940 # Include the generated SIMD node specification written by the SIMD optimization
1941 $my_script_name = dirname($myname) . "/../ia32/ia32_simd_spec.pl";
1942 unless ($return = do $my_script_name) {
1943         warn "couldn't parse $my_script_name: $@" if $@;
1944         warn "couldn't do $my_script_name: $!"    unless defined $return;
1945         warn "couldn't run $my_script_name"       unless $return;
1946 }