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