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