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