added some test programs
[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 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
6
7 $arch = "ia32";
8
9 # The node description is done as a perl hash initializer with the
10 # following structure:
11 #
12 # %nodes = (
13 #
14 # <op-name> => {
15 #   "op_flags" => "N|L|C|X|I|F|Y|H|c|K",
16 #   "arity"    => "0|1|2|3|variable|dynamic|all",
17 #   "state"    => "floats|pinned",
18 #   "args"     => [
19 #                   { "type" => "type 1", "name" => "name 1" },
20 #                   { "type" => "type 2", "name" => "name 2" },
21 #                   ...
22 #                 ],
23 #   "comment"  => "any comment for constructor",
24 #   "rd_constructor" => "c source code which constructs an ir_node"
25 # },
26 #
27 # ... # (all nodes you need to describe)
28 #
29 # ); # close the %nodes initializer
30
31 # the op_flags correspond to the firm irop_flags:
32 #   N   irop_flag_none
33 #   L   irop_flag_labeled
34 #   C   irop_flag_commutative
35 #   X   irop_flag_cfopcode
36 #   I   irop_flag_ip_cfopcode
37 #   F   irop_flag_fragile
38 #   Y   irop_flag_forking
39 #   H   irop_flag_highlevel
40 #   c   irop_flag_constlike
41 #   K   irop_flag_keep
42 #
43 # op_flags: flags for the operation, OPTIONAL (default is "N")
44 #
45 # state: state of the operation, OPTIONAL (default is "pinned")
46 #
47 # arity: arity of the operation, MUST NOT BE OMITTED
48 #
49 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
50 #        are always the first 3 arguments and are always autmatically
51 #        created)
52 #        If this key is missing the following arguments will be created:
53 #        for i = 1 .. arity: ir_node *op_i
54 #        ir_mode *mode
55 #
56 # comment: OPTIONAL comment for the node constructor
57 #
58 # rd_constructor: for every operation there will be a
59 #      new_rd_<arch>_<op-name> function with the arguments from above
60 #      which creates the ir_node corresponding to the defined operation
61 #      you can either put the complete source code of this function here
62 #
63 #      This key is OPTIONAL. If omitted, the following constructor will
64 #      be created:
65 #      if (!op_<arch>_<op-name>) assert(0);
66 #      for i = 1 to arity
67 #         set in[i] = op_i
68 #      done
69 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
70 #      return res
71 #
72 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
73
74 # register types:
75 #   0 - no special type
76 #   1 - write invariant (writes to this register doesn't change it's content)
77 #   2 - caller save (register must be saved by the caller of a function)
78 #   3 - callee save (register must be saved by the called function)
79 #   4 - ignore (do not assign this register)
80 # NOTE: Make sure to list the registers returning the call-result before all other
81 #       caller save registers and in the correct order, otherwise it will break
82 #       the magic!
83 %reg_classes = (
84   "general_purpose" => [
85                          { "name" => "eax", "type" => 2 },
86                          { "name" => "edx", "type" => 2 },
87                          { "name" => "ebx", "type" => 3 },
88                          { "name" => "ecx", "type" => 2 },
89                          { "name" => "esi", "type" => 3 },
90                          { "name" => "edi", "type" => 3 },
91                          { "name" => "ebp", "type" => 3 },
92                          { "name" => "esp", "type" => 4 }  # we don't want esp to be assigned
93                        ],
94   "floating_point"  => [
95                          { "name" => "xmm0", "type" => 2 },
96                          { "name" => "xmm1", "type" => 2 },
97                          { "name" => "xmm2", "type" => 2 },
98                          { "name" => "xmm3", "type" => 2 },
99                          { "name" => "xmm4", "type" => 2 },
100                          { "name" => "xmm5", "type" => 2 },
101                          { "name" => "xmm6", "type" => 2 },
102                          { "name" => "xmm7", "type" => 2 },
103                        ]
104 ); # %reg_classes
105
106 #--------------------------------------------------#
107 #                        _                         #
108 #                       (_)                        #
109 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
110 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
111 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
112 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
113 #                                      | |         #
114 #                                      |_|         #
115 #--------------------------------------------------#
116
117 %nodes = (
118
119 #-----------------------------------------------------------------#
120 #  _       _                                         _            #
121 # (_)     | |                                       | |           #
122 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
123 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
124 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
125 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
126 #                   __/ |                                         #
127 #                  |___/                                          #
128 #-----------------------------------------------------------------#
129
130 # commutative operations
131
132 "Add" => {
133   "op_flags"    => "C",
134   "arity"       => 2,
135   "remat"       => 1,
136   "comment"     => "construct Add: Add(a, b) = Add(b, a) = a + b",
137   "check_inout" => 1,
138   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
139   "emit"        => '. addl %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
140 },
141
142 "Add_i" => {
143   "arity"       => 1,
144   "remat"       => 1,
145   "comment"     => "construct Add: Add(a, const) = Add(const, a) = a + const",
146   "check_inout" => 1,
147   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
148   "emit"        => '. addl %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
149 },
150
151 "Mul" => {
152   "op_flags"    => "C",
153   "arity"       => 2,
154   "comment"     => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
155   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "eax in_r1", "edx in_r2" ] },
156   "emit"        =>
157 '  if (mode_is_signed(get_irn_mode(n))) {
158 4. imull %S2\t\t\t/* signed Mul(%S1, %S2) -> %D1, (%A1, %A2) */
159   }
160   else {
161 4. mull %S2\t\t\t/* unsigned Mul(%S1, %S2) -> %D1, (%A1, %A2) */
162   }
163 '
164 },
165
166 "Mul_i" => {
167   "state"       => "pinned",
168   "arity"       => 1,
169   "comment"     => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
170   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
171   "emit"        =>
172 '  if (mode_is_signed(get_irn_mode(n))) {
173 4. imull %C\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */
174   }
175   else {
176 4. mull %C\t\t\t/* unsigned Mul(%C, %S1) -> %D1, (%A1, const) */
177   }
178 '
179 },
180
181 "And" => {
182   "op_flags"    => "C",
183   "arity"       => 2,
184   "remat"       => 1,
185   "comment"     => "construct And: And(a, b) = And(b, a) = a AND b",
186   "check_inout" => 1,
187   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
188   "emit"        => '. andl %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
189 },
190
191 "And_i" => {
192   "arity"       => 1,
193   "remat"       => 1,
194   "comment"     => "construct And: And(a, const) = And(const, a) = a AND const",
195   "check_inout" => 1,
196   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
197   "emit"        => '. andl %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
198 },
199
200 "Or" => {
201   "op_flags"    => "C",
202   "arity"       => 2,
203   "remat"       => 1,
204   "comment"     => "construct Or: Or(a, b) = Or(b, a) = a OR b",
205   "check_inout" => 1,
206   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
207   "emit"        => '. orl %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
208 },
209
210 "Or_i" => {
211   "arity"       => 1,
212   "remat"       => 1,
213   "comment"     => "construct Or: Or(a, const) = Or(const, a) = a OR const",
214   "check_inout" => 1,
215   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
216   "emit"        => '. orl %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
217 },
218
219 "Eor" => {
220   "op_flags"    => "C",
221   "arity"       => 2,
222   "remat"       => 1,
223   "comment"     => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
224   "check_inout" => 1,
225   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
226   "emit"        => '. xorl %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
227 },
228
229 "Eor_i" => {
230   "arity"       => 1,
231   "remat"       => 1,
232   "comment"     => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
233   "check_inout" => 1,
234   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
235   "emit"        => '. xorl %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
236 },
237
238 "Max" => {
239   "op_flags"    => "C",
240   "arity"       => 2,
241   "remat"       => 1,
242   "comment"     => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
243   "check_inout" => 1,
244   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
245   "emit"        =>
246 '2. cmpl %S2, %S1\t\t\t/* prepare Max (%S1 should be %D1), (%A1, %A2) */
247   if (mode_is_signed(get_irn_mode(n))) {
248 4.  cmovl %S2, %D1\t\t\t/* %S1 is less %S2 */
249   }
250   else {
251 4.  cmovb %S2, %D1\t\t\t/* %S1 is below %S2 */
252   }
253 '
254 },
255
256 "Min" => {
257   "op_flags"    => "C",
258   "arity"       => 2,
259   "remat"       => 1,
260   "comment"     => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
261   "check_inout" => 1,
262   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
263   "emit"        =>
264 '2. cmpl %S2, %S1\t\t\t/* prepare Min (%S1 should be %D1), (%A1, %A2) */
265   if (mode_is_signed(get_irn_mode(n))) {
266 2.  cmovg %S2, %D1\t\t\t/* %S1 is greater %S2 */
267   }
268   else {
269 2.  cmova %S2, %D1\t\t\t/* %S1 is above %S2 */
270   }
271 '
272 },
273
274 # not commutative operations
275
276 "Sub" => {
277   "arity"       => 2,
278   "remat"       => 1,
279   "comment"     => "construct Sub: Sub(a, b) = a - b",
280   "check_inout" => 1,
281   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
282   "emit"        => '. subl %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
283 },
284
285 "Sub_i" => {
286   "arity"       => 1,
287   "remat"       => 1,
288   "comment"     => "construct Sub: Sub(a, const) = a - const",
289   "check_inout" => 1,
290   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
291   "emit"        => '. subl %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
292 },
293
294 "DivMod" => {
295   "op_flags"    => "F|L",
296   "state"       => "exc_pinned",
297   "arity"       => 4,
298   "reg_req"     => { "in" => [ "general_purpose", "general_purpose", "general_purpose", "none" ], "out" => [ "eax in_r1", "edx in_r3" ] },
299   "emit"        =>
300 '  if (mode_is_signed(get_irn_mode(n))) {
301 4.  idivl %S2\t\t\t/* signed DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
302   }
303   else {
304 4.  divl %S2\t\t\t/* unsigned DivMod(%S1, %S2) -> %D1, (%A1, %A2, %A3) */
305   }
306 '
307 },
308
309 "Shl" => {
310   "arity"       => 2,
311   "remat"       => 1,
312   "comment"     => "construct Shl: Shl(a, b) = a << b",
313   "check_inout" => 1,
314   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
315   "emit"        => '. shll %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
316 },
317
318 "Shl_i" => {
319   "arity"       => 1,
320   "remat"       => 1,
321   "comment"     => "construct Shl: Shl(a, const) = a << const",
322   "check_inout" => 1,
323   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
324   "emit"        => '. shll %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
325 },
326
327 "Shr" => {
328   "arity"       => 2,
329   "remat"       => 1,
330   "comment"     => "construct Shr: Shr(a, b) = a >> b",
331   "check_inout" => 1,
332   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
333   "emit"        => '. shrl %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
334 },
335
336 "Shr_i" => {
337   "arity"       => 1,
338   "remat"       => 1,
339   "comment"     => "construct Shr: Shr(a, const) = a >> const",
340   "check_inout" => 1,
341   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
342   "emit"        => '. shrl %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
343 },
344
345 "Shrs" => {
346   "arity"       => 2,
347   "remat"       => 1,
348   "comment"     => "construct Shrs: Shrs(a, b) = a >> b",
349   "check_inout" => 1,
350   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
351   "emit"        => '. sarl %S2, %D1\t\t\t/* Shrs(%S1, %S2) -> %D1, (%A1, %A2) */'
352 },
353
354 "Shrs_i" => {
355   "arity"       => 1,
356   "remat"       => 1,
357   "comment"     => "construct Shrs: Shrs(a, const) = a >> const",
358   "check_inout" => 1,
359   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
360   "emit"        => '. sarl %C, %D1\t\t\t/* Shrs(%S1, %C) -> %D1, (%A1, const) */'
361 },
362
363 "RotR" => {
364   "arity"       => 2,
365   "remat"       => 1,
366   "comment"     => "construct RotR: RotR(a, b) = a ROTR b",
367   "check_inout" => 1,
368   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
369   "emit"        => '. rorl %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
370 },
371
372 "RotL" => {
373   "arity"       => 2,
374   "remat"       => 1,
375   "comment"     => "construct RotL: RotL(a, b) = a ROTL b",
376   "check_inout" => 1,
377   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
378   "emit"        => '. roll %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
379 },
380
381 "RotL_i" => {
382   "arity"       => 1,
383   "remat"       => 1,
384   "comment"     => "construct RotL: RotL(a, const) = a ROTL const",
385   "check_inout" => 1,
386   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
387   "emit"        => '. roll %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
388 },
389
390 "Minus" => {
391   "arity"       => 1,
392   "remat"       => 1,
393   "comment"     => "construct Minus: Minus(a) = -a",
394   "check_inout" => 1,
395   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
396   "emit"        => '. negl %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
397 },
398
399 "Inc" => {
400   "arity"       => 1,
401   "remat"       => 1,
402   "comment"     => "construct Increment: Inc(a) = a++",
403   "check_inout" => 1,
404   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
405   "emit"        => '. incl %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
406 },
407
408 "Dec" => {
409   "arity"       => 1,
410   "remat"       => 1,
411   "comment"     => "construct Decrement: Dec(a) = a--",
412   "check_inout" => 1,
413   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
414   "emit"        => '. decl %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
415 },
416
417 "Not" => {
418   "arity"       => 1,
419   "remat"       => 1,
420   "comment"     => "construct Not: Not(a) = !a",
421   "check_inout" => 1,
422   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
423   "emit"        => '. notl %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
424 },
425
426 # other operations
427
428 "Conv" => {
429   "arity"    => 1,
430   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "in_r1" ] },
431   "comment"  => "construct Conv: Conv(a) = (conv)a"
432 },
433
434 "CondJmp" => {
435   "op_flags" => "C|L|X|Y",
436   "arity"    => 2,
437   "comment"  => "construct conditional jump: CMP A, B && JMPxx LABEL",
438   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
439 },
440
441 "CondJmp_i" => {
442   "op_flags" => "L|X|Y",
443   "arity"    => 1,
444   "comment"  => "construct conditional jump: CMP A, const && JMPxx LABEL",
445   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
446 },
447
448 "SwitchJmp" => {
449   "op_flags" => "L|X|Y",
450   "arity"    => 1,
451   "comment"  => "construct switch",
452   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
453 },
454
455 "Const" => {
456   "op_flags" => "c",
457   "arity"    => "0",
458   "remat"    => 1,
459   "comment"  => "represents an integer constant",
460   "reg_req"  => { "out" => [ "general_purpose" ] },
461   "emit"     => '. movl %C, %D1\t\t\t/* Mov Const into register */',
462   "cmp_attr" =>
463 '
464   if (attr_a->tp == attr_b->tp) {
465     if (attr_a->tp == asmop_SymConst) {
466       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
467         return 1;
468       else
469         return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
470     }
471     else {
472       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
473         return 1;
474
475       if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
476         return 0;
477       else
478         return 1;
479     }
480   }
481   else
482     return 1;
483 '
484 },
485
486 "Cltd" => {
487   "arity"       => 1,
488   "remat"       => 1,
489   "comment"     => "construct Cltd: sign extend EAX -> EDX:EAX",
490   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "eax in_r1", "edx" ] },
491   "emit"        => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%A1) */'
492 },
493
494 # Load / Store
495
496 "Load" => {
497   "op_flags" => "L|F",
498   "state"    => "exc_pinned",
499   "arity"    => 2,
500   "remat"    => 1,
501   "comment"  => "construct Load: Load(ptr, mem) = LD ptr -> reg",
502   "reg_req"  => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
503   "emit"     => '. movl %O(%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
504 },
505
506 "Store" => {
507   "op_flags" => "L|F",
508   "state"    => "exc_pinned",
509   "arity"    => 3,
510   "remat"    => 1,
511   "comment"  => "construct Store: Store(ptr, val, mem) = ST ptr,val",
512   "reg_req"  => { "in" => [ "general_purpose", "general_purpose", "none" ] },
513   "emit"     => '. movl %S2, %O(%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
514 },
515
516 "Lea" => {
517   "arity"    => 2,
518   "comment"  => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
519   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
520   "emit"     => '. leal %O(%S1, %S2, %C), %D1\t\t/* %D1 = %S1 + %S2 << %C + %O, (%A1, %A2) */'
521 },
522
523 "Lea_i" => {
524   "arity"    => 1,
525   "comment"  => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
526   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
527   "emit"     => '. leal %C(%S1), %D1\t\t\t/* %D1 = %S1 + %C, (%A1)*/'
528 },
529
530 "StackParam" => {
531   "arity"    => 1,
532   "remat"    => 1,
533   "comment"  => "constructs a Stack Parameter to retrieve a parameter from Stack",
534   "reg_req"  => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
535   "cmp_attr" =>
536 '
537   return (attr_a->pn_code != attr_b->pn_code);
538 '
539 },
540
541 "StackArg" => {
542   "arity"    => 2,
543   "comment"  => "constructs a Stack Argument to pass an argument on Stack",
544   "reg_req"  => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
545   "cmp_attr" =>
546 '
547   return (attr_a->pn_code != attr_b->pn_code);
548 '
549 },
550
551 #--------------------------------------------------------#
552 #    __ _             _                     _            #
553 #   / _| |           | |                   | |           #
554 #  | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
555 #  |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
556 #  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
557 #  |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
558 #--------------------------------------------------------#
559
560 # commutative operations
561
562 "fAdd" => {
563   "op_flags"    => "C",
564   "arity"       => 2,
565   "remat"       => 1,
566   "check_inout" => 1,
567   "comment"     => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
568   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
569   "emit"        => '. add%M %S2, %D1\t\t\t/* SSE Add(%S1, %S2) -> %D1 */'
570 },
571
572 "fMul" => {
573   "op_flags"    => "C",
574   "arity"       => 2,
575   "check_inout" => 1,
576   "comment"     => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
577   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
578   "emit"        =>'. muls%M %S2, %D1\t\t\t/* SSE Mul(%S1, %S2) -> %D1 */'
579 },
580
581 "fMax" => {
582   "op_flags"    => "C",
583   "arity"       => 2,
584   "remat"       => 1,
585   "check_inout" => 1,
586   "comment"     => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
587   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
588   "emit"        =>'. maxs%M %S2, %D1\t\t\t/* SSE Max(%S1, %S2) -> %D1 */'
589 },
590
591 "fMin" => {
592   "op_flags"    => "C",
593   "arity"       => 2,
594   "remat"       => 1,
595   "check_inout" => 1,
596   "comment"     => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
597   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
598   "emit"        =>'. mins%M %S2, %D1\t\t\t/* SSE Min(%S1, %S2) -> %D1 */'
599 },
600
601 # not commutative operations
602
603 "fSub" => {
604   "arity"       => 2,
605   "remat"       => 1,
606   "check_inout" => 1,
607   "comment"     => "construct SSE Sub: Sub(a, b) = a - b",
608   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
609   "emit"        => '. subs%M %S2, %D1\t\t\t/* SSE Sub(%S1, %S2) -> %D1 */'
610 },
611
612 "fDiv" => {
613   "arity"       => 2,
614   "remat"       => 1,
615   "check_inout" => 1,
616   "comment"     => "construct SSE Div: Div(a, b) = a / b",
617   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_r1" ] },
618   "emit"        => '. divs%M %S2, %D1\t\t\t/* SSE Div(%S1, %S2) -> %D1 */'
619 },
620
621 "fMinus" => {
622   "arity"       => 1,
623   "remat"       => 1,
624   "check_inout" => 1,
625   "comment"     => "construct SSE Minus: Minus(a) = -a",
626   "reg_req"     => { "in" => [ "floating_point" ], "out" => [ "in_r1" ] },
627   "emit"        => '. xorp%M c %D1\t\t\t/* SSE Minus(%S1) -> %D1 */'
628 },
629
630 # other operations
631
632 "fConv" => {
633   "arity"    => 1,
634   "reg_req"  => { "in" => [ "floating_point" ], "out" => [ "general_purpose" ] },
635   "comment"  => "construct Conv: Conv(a) = (conv)a"
636 },
637
638 "fCondJmp" => {
639   "op_flags" => "C|L|X|Y",
640   "arity"    => 2,
641   "comment"  => "construct conditional jump: CMP A, B && JMPxx LABEL",
642   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
643 },
644
645 "fConst" => {
646   "op_flags" => "c",
647   "arity"    => "0",
648   "remat"    => 1,
649   "comment"  => "represents a SSE constant",
650   "reg_req"  => { "out" => [ "floating_point" ] },
651   "emit"     => '. mov%M %C, %D1\t\t\t/* Mov fConst into register */',
652   "cmp_attr" =>
653 '
654   if (attr_a->tp == attr_b->tp) {
655     if (attr_a->tp == asmop_SymConst) {
656       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
657         return 1;
658       else
659         return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
660     }
661     else {
662       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
663         return 1;
664
665       if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
666         return 0;
667       else
668         return 1;
669     }
670   }
671   else
672     return 1;
673 '
674 },
675
676 # Load / Store
677
678 "fLoad" => {
679   "op_flags" => "L|F",
680   "state"    => "exc_pinned",
681   "arity"    => 2,
682   "remat"    => 1,
683   "comment"  => "construct SSE Load: Load(ptr, mem) = LD ptr",
684   "reg_req"  => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
685   "emit"     => '. movl O(%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
686 },
687
688 "fStore" => {
689   "op_flags" => "L|F",
690   "state"    => "exc_pinned",
691   "arity"    => 3,
692   "remat"    => 1,
693   "comment"  => "construct Store: Store(ptr, val, mem) = ST ptr,val",
694   "reg_req"  => { "in" => [ "general_purpose", "floating_point", "none" ] },
695   "emit"     => '. movl %S2, O(%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
696 },
697
698 "fStackParam" => {
699   "arity"    => 1,
700   "remat"    => 1,
701   "comment"  => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
702   "reg_req"  => { "in" => [ "none" ], "out" => [ "floating_point" ] },
703   "cmp_attr" =>
704 '
705   return (attr_a->pn_code != attr_b->pn_code);
706 '
707 },
708
709 "fStackArg" => {
710   "arity"    => 2,
711   "comment"  => "constructs a Stack Argument to pass an argument on Stack",
712   "reg_req"  => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
713   "cmp_attr" =>
714 '
715   return (attr_a->pn_code != attr_b->pn_code);
716 '
717 },
718
719 # Call
720
721 "Call" => {
722   "op_flags" => "L|F",
723   "state"    => "mem_pinned",
724   "arity"    => "variable",
725   "comment"  => "construct Call: Call(...)",
726   "args"     => [
727                   { "type" => "int",        "name" => "n" },
728                   { "type" => "ir_node **", "name" => "in" }
729                 ],
730   "rd_constructor" =>
731 "  if (!op_ia32_Call) assert(0);
732   return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);
733 "
734 },
735
736 # Return
737
738 "Return" => {
739   "op_flags" => "L|X",
740   "state"    => "pinned",
741   "arity"    => "variable",
742   "comment"  => "construct Return: Return(...)",
743   "args"     => [
744                   { "type" => "int",        "name" => "n" },
745                   { "type" => "ir_node **", "name" => "in" }
746                 ],
747   "rd_constructor" =>
748 "  if (!op_ia32_Return) assert(0);
749   return new_ir_node(db, irg, block, op_ia32_Return, mode_X, n, in);
750 "
751 },
752
753 # M/Alloc
754
755 "Alloca" => {
756   "op_flags" => "L|F",
757   "state"    => "pinned",
758   "arity"    => "2",
759   "comment"  => "construct Alloca: allocate memory on Stack",
760   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] }
761 },
762
763 "Alloca_i" => {
764   "op_flags" => "L|F",
765   "state"    => "pinned",
766   "arity"    => "1",
767   "comment"  => "construct Alloca: allocate memory on Stack",
768   "reg_req"  => { "out" => [ "general_purpose" ] }
769 }
770
771 ); # end of %nodes