e1f6a8c36f1fe9f2ccfef8c1f9f13c645904f385
[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_s1" ] },
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_s1" ] },
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" => [ "eax", "general_purpose" ], "out" => [ "eax" ] },
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" => [ "eax" ], "out" => [ "eax" ] },
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 "Mulh" => {
171   "op_flags"    => "C",
172   "arity"       => 2,
173   "comment"     => "construct Mulh: Mulh(a, b) = Mulh(b, a) = get_32_highest_bits(a * b)",
174   "reg_req"     => { "in" => [ "eax", "general_purpose" ], "out" => [ "edx" ] },
175   "emit"        =>
176 '  if (mode_is_signed(get_irn_mode(n))) {
177 4. imull %s2\t\t\t/* signed Mulh(%s1, %s2) -> %d1, (%a1, %a2) */
178   }
179   else {
180 4. mull %s2\t\t\t/* unsigned Mulh(%s1, %s2) -> %d1, (%a1, %a2) */
181   }
182 '
183 },
184
185 "Mulh_i" => {
186   "state"       => "pinned",
187   "arity"       => 1,
188   "comment"     => "construct Mulh: Mulh(a, const) = Mulh(const, a) = get_32_highest_bits(a * const)",
189   "reg_req"     => { "in" => [ "eax" ], "out" => [ "edx" ] },
190   "emit"        =>
191 '  if (mode_is_signed(get_irn_mode(n))) {
192 4. imull %c\t\t\t/* signed Mulh(%c, %s1) -> %d1, (%a1, const) */
193   }
194   else {
195 4. mull %c\t\t\t/* unsigned Mulh(%c, %s1) -> %d1, (%a1, const) */
196   }
197 '
198 },
199
200 "And" => {
201   "op_flags"    => "C",
202   "arity"       => 2,
203   "remat"       => 1,
204   "comment"     => "construct And: And(a, b) = And(b, a) = a AND b",
205   "check_inout" => 1,
206   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
207   "emit"        => '. andl %s2, %d1\t\t\t/* And(%s1, %s2) -> %d1, (%a1, %a2) */'
208 },
209
210 "And_i" => {
211   "arity"       => 1,
212   "remat"       => 1,
213   "comment"     => "construct And: And(a, const) = And(const, a) = a AND const",
214   "check_inout" => 1,
215   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
216   "emit"        => '. andl %c, %d1\t\t\t/* And(%c, %s1) -> %d1, (%a1, const) */'
217 },
218
219 "Or" => {
220   "op_flags"    => "C",
221   "arity"       => 2,
222   "remat"       => 1,
223   "comment"     => "construct Or: Or(a, b) = Or(b, a) = a OR b",
224   "check_inout" => 1,
225   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
226   "emit"        => '. orl %s2, %d1\t\t\t/* Or(%s1, %s2) -> %d1, (%a1, %a2) */'
227 },
228
229 "Or_i" => {
230   "arity"       => 1,
231   "remat"       => 1,
232   "comment"     => "construct Or: Or(a, const) = Or(const, a) = a OR const",
233   "check_inout" => 1,
234   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
235   "emit"        => '. orl %c, %d1\t\t\t/* Or(%c, %s1) -> %d1, (%a1, const) */'
236 },
237
238 "Eor" => {
239   "op_flags"    => "C",
240   "arity"       => 2,
241   "remat"       => 1,
242   "comment"     => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
243   "check_inout" => 1,
244   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
245   "emit"        => '. xorl %s2, %d1\t\t\t/* Xor(%s1, %s2) -> %d1, (%a1, %a2) */'
246 },
247
248 "Eor_i" => {
249   "arity"       => 1,
250   "remat"       => 1,
251   "comment"     => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
252   "check_inout" => 1,
253   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
254   "emit"        => '. xorl %c, %d1\t\t\t/* Xor(%c, %s1) -> %d1, (%a1, const) */'
255 },
256
257 "Max" => {
258   "op_flags"    => "C",
259   "arity"       => 2,
260   "remat"       => 1,
261   "comment"     => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b",
262   "check_inout" => 1,
263   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
264   "emit"        =>
265 '2. cmpl %s2, %s1\t\t\t/* prepare Max (%s1 should be %d1), (%a1, %a2) */
266   if (mode_is_signed(get_irn_mode(n))) {
267 4.  cmovl %s2, %d1\t\t\t/* %s1 is less %s2 */
268   }
269   else {
270 4.  cmovb %s2, %d1\t\t\t/* %s1 is below %s2 */
271   }
272 '
273 },
274
275 "Min" => {
276   "op_flags"    => "C",
277   "arity"       => 2,
278   "remat"       => 1,
279   "comment"     => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b",
280   "check_inout" => 1,
281   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
282   "emit"        =>
283 '2. cmpl %s2, %s1\t\t\t/* prepare Min (%s1 should be %d1), (%a1, %a2) */
284   if (mode_is_signed(get_irn_mode(n))) {
285 2.  cmovg %s2, %d1\t\t\t/* %s1 is greater %s2 */
286   }
287   else {
288 2.  cmova %s2, %d1\t\t\t/* %s1 is above %s2 */
289   }
290 '
291 },
292
293 # not commutative operations
294
295 "Sub" => {
296   "arity"       => 2,
297   "remat"       => 1,
298   "comment"     => "construct Sub: Sub(a, b) = a - b",
299   "check_inout" => 1,
300   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
301   "emit"        => '. subl %s2, %d1\t\t\t/* Sub(%s1, %s2) -> %d1, (%a1, %a2) */'
302 },
303
304 "Sub_i" => {
305   "arity"       => 1,
306   "remat"       => 1,
307   "comment"     => "construct Sub: Sub(a, const) = a - const",
308   "check_inout" => 1,
309   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
310   "emit"        => '. subl %c, %d1\t\t\t/* Sub(%s1, %c) -> %d1, (%a1, const) */'
311 },
312
313 "DivMod" => {
314   "op_flags"    => "F|L",
315   "state"       => "exc_pinned",
316   "arity"       => 4,
317   "comment"     => "construct DivMod: DivMod(a,b) = (a / b, a % b)",
318   "emit"        =>
319 '  if (mode_is_signed(get_irn_mode(n))) {
320 4.  idivl %s2\t\t\t/* signed Mod(%s1, %s2) -> %d1, (%a2, %a3, %4) */
321   }
322   else {
323 4.  divl %s2\t\t\t/* unsigned Mod(%s1, %s2) -> %d1, (%a2, %a3, %a4) */
324   }
325 ',
326   "args"     => [
327                   { "type" => "ir_node *",        "name" => "dividend" },
328                   { "type" => "ir_node *",        "name" => "divisor" },
329                   { "type" => "ir_node *",        "name" => "mem" },
330                   { "type" => "divmod_flavour_t", "name" => "dm_flav" },   # flavours (flavour_Div, flavour_Mod, flavour_DivMod)
331                   { "type" => "ir_mode *",        "name" => "mode" },
332                 ],
333   "rd_constructor" =>
334 "  ir_node *res;
335   ir_node *in[4];
336   asmop_attr *attr;
337
338   if (!op_ia32_DivMod) assert(0);
339
340   in[1] = divisor;
341   in[3] = mem;
342
343   if (mode_is_signed(mode)) {
344     ir_node *cltd;
345     /* in signed mode , we need to sign extend the dividend */
346     cltd  = new_rd_ia32_Cltd(db, current_ir_graph, block, divisor, mode_T);
347     in[0] = new_rd_Proj(db, current_ir_graph, block, cltd, mode_Is, pn_EAX);
348     in[2] = new_rd_Proj(db, current_ir_graph, block, cltd, mode_Is, pn_EDX);
349   }
350   else {
351     in[0] = dividend;
352     in[2] = new_rd_ia32_Const(db, current_ir_graph, block, mode_Iu);
353     set_ia32_Const_type(in[2], asmop_Const);
354     set_ia32_Immop_tarval(in[2], get_tarval_null(mode_Iu));
355   }
356
357   res = new_ir_node(db, irg, block, op_ia32_DivMod, mode, 4, in);
358
359   set_ia32_DivMod_flavour(res, dm_flav);
360   set_ia32_n_res(res, 2);
361
362   attr = get_ia32_attr(res);
363
364   attr->in_req    = calloc(4, sizeof(arch_register_req_t *));
365   attr->in_req[0] = &ia32_default_req_ia32_general_purpose_eax;
366   attr->in_req[1] = &ia32_default_req_ia32_general_purpose;
367   attr->in_req[2] = &ia32_default_req_ia32_general_purpose_edx;
368   attr->in_req[3] = &ia32_default_req_none;
369
370   attr->out_req    = calloc(2, sizeof(arch_register_req_t *));
371   attr->out_req[0] = &ia32_default_req_ia32_general_purpose_eax;
372   attr->out_req[1] = &ia32_default_req_ia32_general_purpose_edx;
373
374   attr->slots = calloc(2, sizeof(arch_register_t *));
375
376   return res;
377 "
378 },
379
380 "Shl" => {
381   "arity"       => 2,
382   "remat"       => 1,
383   "comment"     => "construct Shl: Shl(a, b) = a << b",
384   "check_inout" => 1,
385   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
386   "emit"        => '. shll %s2, %d1\t\t\t/* Shl(%s1, %s2) -> %d1, (%a1, %a2) */'
387 },
388
389 "Shl_i" => {
390   "arity"       => 1,
391   "remat"       => 1,
392   "comment"     => "construct Shl: Shl(a, const) = a << const",
393   "check_inout" => 1,
394   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
395   "emit"        => '. shll %c, %d1\t\t\t/* Shl(%s1, %c) -> %d1, (%a1, const) */'
396 },
397
398 "Shr" => {
399   "arity"       => 2,
400   "remat"       => 1,
401   "comment"     => "construct Shr: Shr(a, b) = a >> b",
402   "check_inout" => 1,
403   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
404   "emit"        => '. shrl %s2, %d1\t\t\t/* Shr(%s1, %s2) -> %d1, (%a1, %a2) */'
405 },
406
407 "Shr_i" => {
408   "arity"       => 1,
409   "remat"       => 1,
410   "comment"     => "construct Shr: Shr(a, const) = a >> const",
411   "check_inout" => 1,
412   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
413   "emit"        => '. shrl %c, %d1\t\t\t/* Shr(%s1, %c) -> %d1, (%a1, const) */'
414 },
415
416 "Shrs" => {
417   "arity"       => 2,
418   "remat"       => 1,
419   "comment"     => "construct Shrs: Shrs(a, b) = a >> b",
420   "check_inout" => 1,
421   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
422   "emit"        => '. sarl %s2, %d1\t\t\t/* Shrs(%s1, %s2) -> %d1, (%a1, %a2) */'
423 },
424
425 "Shrs_i" => {
426   "arity"       => 1,
427   "remat"       => 1,
428   "comment"     => "construct Shrs: Shrs(a, const) = a >> const",
429   "check_inout" => 1,
430   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
431   "emit"        => '. sarl %c, %d1\t\t\t/* Shrs(%s1, %c) -> %d1, (%a1, const) */'
432 },
433
434 "RotR" => {
435   "arity"       => 2,
436   "remat"       => 1,
437   "comment"     => "construct RotR: RotR(a, b) = a ROTR b",
438   "check_inout" => 1,
439   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
440   "emit"        => '. rorl %s2, %d1\t\t\t/* RotR(%s1, %s2) -> %d1, (%a1, %a2) */'
441 },
442
443 "RotL" => {
444   "arity"       => 2,
445   "remat"       => 1,
446   "comment"     => "construct RotL: RotL(a, b) = a ROTL b",
447   "check_inout" => 1,
448   "reg_req"     => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_s1" ] },
449   "emit"        => '. roll %s2, %d1\t\t\t/* RotL(%s1, %s2) -> %d1, (%a1, %a2) */'
450 },
451
452 "RotL_i" => {
453   "arity"       => 1,
454   "remat"       => 1,
455   "comment"     => "construct RotL: RotL(a, const) = a ROTL const",
456   "check_inout" => 1,
457   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
458   "emit"        => '. roll %c, %d1\t\t\t/* RotL(%s1, %c) -> %d1, (%a1, const) */'
459 },
460
461 "Minus" => {
462   "arity"       => 1,
463   "remat"       => 1,
464   "comment"     => "construct Minus: Minus(a) = -a",
465   "check_inout" => 1,
466   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
467   "emit"        => '. negl %d1\t\t\t/* Neg(%s1) -> %d1, (%a1) */'
468 },
469
470 "Inc" => {
471   "arity"       => 1,
472   "remat"       => 1,
473   "comment"     => "construct Increment: Inc(a) = a++",
474   "check_inout" => 1,
475   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
476   "emit"        => '. incl %d1\t\t\t/* Inc(%s1) -> %d1, (%a1) */'
477 },
478
479 "Dec" => {
480   "arity"       => 1,
481   "remat"       => 1,
482   "comment"     => "construct Decrement: Dec(a) = a--",
483   "check_inout" => 1,
484   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
485   "emit"        => '. decl %d1\t\t\t/* Dec(%s1) -> %d1, (%a1) */'
486 },
487
488 "Not" => {
489   "arity"       => 1,
490   "remat"       => 1,
491   "comment"     => "construct Not: Not(a) = !a",
492   "check_inout" => 1,
493   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
494   "emit"        => '. notl %d1\t\t\t/* Not(%s1) -> %d1, (%a1) */'
495 },
496
497 # other operations
498
499 "Conv" => {
500   "arity"    => 1,
501   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
502   "comment"  => "construct Conv: Conv(a) = (conv)a"
503 },
504
505 "CondJmp" => {
506   "op_flags" => "C|L|X|Y",
507   "arity"    => 2,
508   "comment"  => "construct conditional jump: CMP A, B && JMPxx LABEL",
509   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
510 },
511
512 "CondJmp_i" => {
513   "op_flags" => "L|X|Y",
514   "arity"    => 1,
515   "comment"  => "construct conditional jump: CMP A, const && JMPxx LABEL",
516   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "none", "none" ] },
517 },
518
519 "SwitchJmp" => {
520   "op_flags" => "L|X|Y",
521   "arity"    => 1,
522   "comment"  => "construct switch",
523   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "none" ] },
524 },
525
526 "Const" => {
527   "op_flags" => "c",
528   "arity"    => "0",
529   "remat"    => 1,
530   "comment"  => "represents an integer constant",
531   "reg_req"  => { "out" => [ "general_purpose" ] },
532   "emit"     => '. movl %c, %d1\t\t\t/* Mov Const into register */',
533   "cmp_attr" =>
534 '
535   if (attr_a->tp == attr_b->tp) {
536     if (attr_a->tp == asmop_SymConst) {
537       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
538         return 1;
539       else
540         return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
541     }
542     else {
543       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
544         return 1;
545
546       if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
547         return 0;
548       else
549         return 1;
550     }
551   }
552   else
553     return 1;
554 '
555 },
556
557 "Cltd" => {
558   "arity"       => 1,
559   "remat"       => 1,
560   "comment"     => "construct Cltd: sign extend EAX -> EDX:EAX",
561   "reg_req"     => { "in" => [ "eax" ], "out" => [ "eax", "edx" ] },
562   "emit"        => '. cltd\t\t\t/* sign extend EAX -> EDX:EAX, (%a1) */'
563 },
564
565 # Load / Store
566
567 "Load" => {
568   "op_flags" => "L|F",
569   "state"    => "exc_pinned",
570   "arity"    => 2,
571   "remat"    => 1,
572   "comment"  => "construct Load: Load(ptr, mem) = LD ptr -> reg",
573   "reg_req"  => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
574   "emit"     => '. movl (%s1), %d1\t\t\t/* Load((%s1)) -> %d1, (%a1) */'
575 },
576
577 "Store" => {
578   "op_flags" => "L|F",
579   "state"    => "exc_pinned",
580   "arity"    => 3,
581   "remat"    => 1,
582   "comment"  => "construct Store: Store(ptr, val, mem) = ST ptr,val",
583   "reg_req"  => { "in" => [ "general_purpose", "general_purpose", "none" ] },
584   "emit"     => '. movl %s2, (%s1)\t\t\t/* Store(%s2) -> (%s1), (%a1, %a2) */'
585 },
586
587 "Lea" => {
588   "arity"    => 2,
589   "comment"  => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8",
590   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
591   "emit"     => '. leal %o(%s1, %s2, %c), %d1\t\t/* %d1 = %s1 + %s2 << %c + %o, (%a1, %a2) */'
592 },
593
594 "Lea_i" => {
595   "arity"    => 1,
596   "comment"  => "construct Lea: Lea(a) = lea offs(a) | res = a + offs",
597   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
598   "emit"     => '. leal %c(%s1), %d1\t\t\t/* %d1 = %s1 + %c, (%a1)*/'
599 },
600
601 "RegParam" => {
602   "arity"    => 1,
603   "comment"  => "constructs a Register Parameter to cover parameters passed in register",
604   "reg_req"  => { "in" => [ "none" ], "out" => [ "none" ] },
605   "cmp_attr" =>
606 '
607   return (attr_a->pn_code != attr_b->pn_code);
608 '
609 },
610
611 "StackParam" => {
612   "arity"    => 1,
613   "comment"  => "constructs a Stack Parameter to retrieve a parameter from Stack",
614   "reg_req"  => { "in" => [ "none" ], "out" => [ "general_purpose" ] },
615   "cmp_attr" =>
616 '
617   return (attr_a->pn_code != attr_b->pn_code);
618 '
619 },
620
621 "StackArg" => {
622   "arity"    => 2,
623   "comment"  => "constructs a Stack Argument to pass an argument on Stack",
624   "reg_req"  => { "in" => [ "none", "general_purpose" ], "out" => [ "none" ] },
625   "cmp_attr" =>
626 '
627   return (attr_a->pn_code != attr_b->pn_code);
628 '
629 },
630
631 #--------------------------------------------------------#
632 #    __ _             _                     _            #
633 #   / _| |           | |                   | |           #
634 #  | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
635 #  |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
636 #  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
637 #  |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
638 #--------------------------------------------------------#
639
640 # commutative operations
641
642 "fAdd" => {
643   "op_flags"    => "C",
644   "arity"       => 2,
645   "remat"       => 1,
646   "check_inout" => 1,
647   "comment"     => "construct SSE Add: Add(a, b) = Add(b, a) = a + b",
648   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
649   "emit"        => '. add%m %s2, %d1\t\t\t/* SSE Add(%s1, %s2) -> %d1 */'
650 },
651
652 "fMul" => {
653   "op_flags"    => "C",
654   "arity"       => 2,
655   "check_inout" => 1,
656   "comment"     => "construct SSE Mul: Mul(a, b) = Mul(b, a) = a * b",
657   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
658   "emit"        =>'. muls%m %s2, %d1\t\t\t/* SSE Mul(%s1, %s2) -> %d1 */'
659 },
660
661 "fMax" => {
662   "op_flags"    => "C",
663   "arity"       => 2,
664   "remat"       => 1,
665   "check_inout" => 1,
666   "comment"     => "construct SSE Max: Max(a, b) = Max(b, a) = a > b ? a : b",
667   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
668   "emit"        =>'. maxs%m %s2, %d1\t\t\t/* SSE Max(%s1, %s2) -> %d1 */'
669 },
670
671 "fMin" => {
672   "op_flags"    => "C",
673   "arity"       => 2,
674   "remat"       => 1,
675   "check_inout" => 1,
676   "comment"     => "construct SSE Min: Min(a, b) = Min(b, a) = a < b ? a : b",
677   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
678   "emit"        =>'. mins%m %s2, %d1\t\t\t/* SSE Min(%s1, %s2) -> %d1 */'
679 },
680
681 # not commutative operations
682
683 "fSub" => {
684   "arity"       => 2,
685   "remat"       => 1,
686   "check_inout" => 1,
687   "comment"     => "construct SSE Sub: Sub(a, b) = a - b",
688   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
689   "emit"        => '. subs%m %s2, %d1\t\t\t/* SSE Sub(%s1, %s2) -> %d1 */'
690 },
691
692 "fDiv" => {
693   "arity"       => 2,
694   "remat"       => 1,
695   "check_inout" => 1,
696   "comment"     => "construct SSE Div: Div(a, b) = a / b",
697   "reg_req"     => { "in" => [ "floating_point", "floating_point" ], "out" => [ "in_s1" ] },
698   "emit"        => '. divs%m %s2, %d1\t\t\t/* SSE Div(%s1, %s2) -> %d1 */'
699 },
700
701 "fMinus" => {
702   "arity"       => 1,
703   "remat"       => 1,
704   "check_inout" => 1,
705   "comment"     => "construct SSE Minus: Minus(a) = -a",
706   "reg_req"     => { "in" => [ "floating_point" ], "out" => [ "in_s1" ] },
707   "emit"        => '. xorp%m c %d1\t\t\t/* SSE Minus(%s1) -> %d1 */'
708 },
709
710 # other operations
711
712 "fConv" => {
713   "arity"    => 1,
714   "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "in_s1" ] },
715   "comment"  => "construct Conv: Conv(a) = (conv)a"
716 },
717
718 "fCondJmp" => {
719   "op_flags" => "C|L|X|Y",
720   "arity"    => 2,
721   "comment"  => "construct conditional jump: CMP A, B && JMPxx LABEL",
722   "reg_req"  => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "none", "none" ] },
723 },
724
725 "fConst" => {
726   "op_flags" => "c",
727   "arity"    => "0",
728   "remat"    => 1,
729   "comment"  => "represents a SSE constant",
730   "reg_req"  => { "out" => [ "floating_point" ] },
731   "emit"     => '. mov%m %c, %d1\t\t\t/* Mov fConst into register */',
732   "cmp_attr" =>
733 '
734   if (attr_a->tp == attr_b->tp) {
735     if (attr_a->tp == asmop_SymConst) {
736       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
737         return 1;
738       else
739         return strcmp(get_sc_name(attr_a->old_ir), get_sc_name(attr_b->old_ir));
740     }
741     else {
742       if (attr_a->old_ir == NULL || attr_b->old_ir == NULL)
743         return 1;
744
745       if (tarval_cmp(attr_a->tv, attr_b->tv) == pn_Cmp_Eq)
746         return 0;
747       else
748         return 1;
749     }
750   }
751   else
752     return 1;
753 '
754 },
755
756 # Load / Store
757
758 "fLoad" => {
759   "op_flags" => "L|F",
760   "state"    => "exc_pinned",
761   "arity"    => 2,
762   "remat"    => 1,
763   "comment"  => "construct SSE Load: Load(ptr, mem) = LD ptr",
764   "reg_req"  => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
765   "emit"     => '. movl (%s1), %d1\t\t\t/* Load((%s1)) -> %d1 */'
766 },
767
768 "fStore" => {
769   "op_flags" => "L|F",
770   "state"    => "exc_pinned",
771   "arity"    => 3,
772   "remat"    => 1,
773   "comment"  => "construct Store: Store(ptr, val, mem) = ST ptr,val",
774   "reg_req"  => { "in" => [ "general_purpose", "floating_point", "none" ] },
775   "emit"     => '. movl %s2, (%s1)\t\t\t/* Store(%s2) -> (%s1), (%a1, %a2) */'
776 },
777
778 "fStackParam" => {
779   "arity"    => 1,
780   "comment"  => "constructs a Stack Parameter to retrieve a SSE parameter from Stack",
781   "reg_req"  => { "in" => [ "none" ], "out" => [ "floating_point" ] },
782   "cmp_attr" =>
783 '
784   return (attr_a->pn_code != attr_b->pn_code);
785 '
786 },
787
788 "fStackArg" => {
789   "arity"    => 2,
790   "comment"  => "constructs a Stack Argument to pass an argument on Stack",
791   "reg_req"  => { "in" => [ "none", "floating_point" ], "out" => [ "none" ] },
792   "cmp_attr" =>
793 '
794   return (attr_a->pn_code != attr_b->pn_code);
795 '
796 },
797
798 # Call
799
800 "Call" => {
801   "op_flags" => "L|F",
802   "state"    => "mem_pinned",
803   "arity"    => "variable",
804   "spill"    => 0,
805   "comment"  => "construct Call: Call(...)",
806   "args"     => [
807                   { "type" => "int",        "name" => "n" },
808                   { "type" => "ir_node **", "name" => "in" }
809                 ],
810   "rd_constructor" =>
811 "  if (!op_ia32_Call) assert(0);
812   return new_ir_node(db, irg, block, op_ia32_Call, mode_T, n, in);
813 "
814 }
815
816 ); # end of %nodes