2267fcf34c0bfed69de6311c5132a942af94b236
[libfirm] / ir / be / sparc / sparc_spec.pl
1 # Creation: 2006/02/13
2 # $Id$
3 # This is a template specification for the Firm-Backend
4
5 $new_emit_syntax = 1;
6
7 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
8
9 $arch = "sparc";
10
11 $mode_gp      = "mode_Iu";
12 $mode_flags   = "mode_Bu";
13 $mode_fp      = "mode_D";
14
15 # The node description is done as a perl hash initializer with the
16 # following structure:
17 #
18 # %nodes = (
19 #
20 # <op-name> => {
21 #   op_flags  => "N|L|C|X|I|F|Y|H|c|K",                 # optional
22 #   irn_flags => "R|N|I"                                # optional
23 #   arity     => "0|1|2|3 ... |variable|dynamic|any",   # optional
24 #   state     => "floats|pinned|mem_pinned|exc_pinned", # optional
25 #   args      => [
26 #                    { type => "type 1", name => "name 1" },
27 #                    { type => "type 2", name => "name 2" },
28 #                    ...
29 #                  ],
30 #   comment   => "any comment for constructor",  # optional
31 #   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
32 #   cmp_attr  => "c source code for comparing node attributes", # optional
33 #   outs      => { "out1", "out2" },# optional, creates pn_op_out1, ... consts
34 #   ins       => { "in1", "in2" },  # optional, creates n_op_in1, ... consts
35 #   mode      => "mode_Iu",         # optional, predefines the mode
36 #   emit      => "emit code with templates",   # optional for virtual nodes
37 #   attr      => "additional attribute arguments for constructor", # optional
38 #   init_attr => "emit attribute initialization template",         # optional
39 #   rd_constructor => "c source code which constructs an ir_node", # optional
40 #   hash_func => "name of the hash function for this operation",   # optional, get the default hash function else
41 #   latency   => "latency of this operation (can be float)"        # optional
42 #   attr_type => "name of the attribute struct",                   # optional
43 # },
44 #
45 # ... # (all nodes you need to describe)
46 #
47 # ); # close the %nodes initializer
48
49 # op_flags: flags for the operation, OPTIONAL (default is "N")
50 # the op_flags correspond to the firm irop_flags:
51 #   N   irop_flag_none
52 #   L   irop_flag_labeled
53 #   C   irop_flag_commutative
54 #   X   irop_flag_cfopcode
55 #   I   irop_flag_ip_cfopcode
56 #   F   irop_flag_fragile
57 #   Y   irop_flag_forking
58 #   H   irop_flag_highlevel
59 #   c   irop_flag_constlike
60 #   K   irop_flag_keep
61 #
62 # irn_flags: special node flags, OPTIONAL (default is 0)
63 # following irn_flags are supported:
64 #   R   rematerializeable
65 #   N   not spillable
66 #   I   ignore for register allocation
67 #
68 # state: state of the operation, OPTIONAL (default is "floats")
69 #
70 # arity: arity of the operation, MUST NOT BE OMITTED
71 #
72 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
73 #        are always the first 3 arguments and are always autmatically
74 #        created)
75 #        If this key is missing the following arguments will be created:
76 #        for i = 1 .. arity: ir_node *op_i
77 #        ir_mode *mode
78 #
79 # outs:  if a node defines more than one output, the names of the projections
80 #        nodes having outs having automatically the mode mode_T
81 #
82 # comment: OPTIONAL comment for the node constructor
83 #
84 # rd_constructor: for every operation there will be a
85 #      new_rd_<arch>_<op-name> function with the arguments from above
86 #      which creates the ir_node corresponding to the defined operation
87 #      you can either put the complete source code of this function here
88 #
89 #      This key is OPTIONAL. If omitted, the following constructor will
90 #      be created:
91 #      if (!op_<arch>_<op-name>) assert(0);
92 #      for i = 1 to arity
93 #         set in[i] = op_i
94 #      done
95 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
96 #      return res
97 #
98 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
99
100 # register types:
101 #   0 - no special type
102 #   1 - caller save (register must be saved by the caller of a function)
103 #   2 - callee save (register must be saved by the called function)
104 #   4 - ignore (do not assign this register)
105 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
106
107 # available SPARC registers: 8 globals, 24 window regs (8 ins, 8 outs, 8 locals)
108 %reg_classes = (
109         gp => [
110                 { name => "g0", realname => "g0", type => 4 }, # hardwired 0, behaves like /dev/null
111                 { name => "g1", realname => "g1", type => 1 }, # temp. value
112                 { name => "g2", realname => "g2", type => 1 },
113                 { name => "g3", realname => "g3", type => 1 },
114                 { name => "g4", realname => "g4", type => 1 },
115                 { name => "g5", realname => "g5", type => 4 }, # reserved by SPARC ABI
116                 { name => "g6", realname => "g6", type => 4 }, # reserved by SPARC ABI
117                 { name => "g7", realname => "g7", type => 4 }, # reserved by SPARC ABI
118
119                 # window's out registers
120                 { name => "o0", realname => "o0", type => 1 }, # param 1 / return value from callee
121                 { name => "o1", realname => "o1", type => 1 }, # param 2
122                 { name => "o2", realname => "o2", type => 1 }, # param 3
123                 { name => "o3", realname => "o3", type => 1 }, # param 4
124                 { name => "o4", realname => "o4", type => 1 }, # param 5
125                 { name => "o5", realname => "o5", type => 1 }, # param 6
126                 { name => "sp", realname => "sp", type => 4 }, # our stackpointer
127                 { name => "o7", realname => "o6", type => 4 }, # temp. value / address of CALL instr.
128
129                 # window's local registers
130                 { name => "l0", realname => "l0", type => 0 },
131                 { name => "l1", realname => "l1", type => 0 },
132                 { name => "l2", realname => "l2", type => 0 },
133                 { name => "l3", realname => "l3", type => 0 },
134                 { name => "l4", realname => "l4", type => 0 },
135                 { name => "l5", realname => "l5", type => 0 },
136                 { name => "l6", realname => "l6", type => 0 },
137                 { name => "l7", realname => "l7", type => 0 },
138
139                 # window's in registers
140                 { name => "i0", realname => "i0", type => 0 }, # incoming param1 / return value to caller
141                 { name => "i1", realname => "i1", type => 0 }, # param 2
142                 { name => "i2", realname => "i2", type => 0 }, # param 3
143                 { name => "i3", realname => "i3", type => 0 }, # param 4
144                 { name => "i4", realname => "i4", type => 0 }, # param 5
145                 { name => "i5", realname => "i5", type => 0 }, # param 6
146                 { name => "fp", realname => "fp", type => 4 }, # our framepointer
147                 { name => "i7", realname => "i7", type => 4 }, # return address - 8
148                 { mode => $mode_gp }
149         ],
150         flags => [
151                 { name => "y", realname => "y", type => 4 },  # the multiply/divide state register
152                 { mode => $mode_flags, flags => "manual_ra" }
153         ],
154 #       cpu => [
155 #               { name => "psr", realname => "psr", type => 4 },  # the processor state register
156 #               { name => "wim", realname => "wim", type => 4 },  # the window invalid mask register
157 #               { name => "tbr", realname => "tbr", type => 4 },  # the trap base register
158 #               { name => "pc", realname => "pc", type => 4 },  # the program counter register
159 #               { name => "npc", realname => "npc", type => 4 },  # the next instruction addr. (PC + 1) register
160 #               { mode => "mode_Iu", flags => "manual_ra" }
161 #       ],
162
163         # fp registers can be accessed any time
164         fp  => [
165                 { name => "f0", type => 1 },
166                 { name => "f1", type => 1 },
167                 { name => "f2", type => 1 },
168                 { name => "f3", type => 1 },
169                 { name => "f4", type => 1 },
170                 { name => "f5", type => 1 },
171                 { name => "f6", type => 1 },
172                 { name => "f7", type => 1 },
173                 { name => "f8", type => 1 },
174                 { name => "f9", type => 1 },
175                 { name => "f10", type => 1 },
176                 { name => "f11", type => 1 },
177                 { name => "f12", type => 1 },
178                 { name => "f13", type => 1 },
179                 { name => "f14", type => 1 },
180                 { name => "f15", type => 1 },
181                 { name => "f16", type => 1 },
182                 { name => "f17", type => 1 },
183                 { name => "f18", type => 1 },
184                 { name => "f19", type => 1 },
185                 { name => "f20", type => 1 },
186                 { name => "f21", type => 1 },
187                 { name => "f22", type => 1 },
188                 { name => "f23", type => 1 },
189                 { name => "f24", type => 1 },
190                 { name => "f25", type => 1 },
191                 { name => "f26", type => 1 },
192                 { name => "f27", type => 1 },
193                 { name => "f28", type => 1 },
194                 { name => "f29", type => 1 },
195                 { name => "f30", type => 1 },
196                 { name => "f31", type => 1 },
197                 { mode => $mode_fp }
198         ]
199 ); # %reg_classes
200
201 %emit_templates = (
202 # emit source reg or imm dep. on node's arity
203     RI => "${arch}_emit_reg_or_imm(node, -1);",
204     R1I => "${arch}_emit_reg_or_imm(node, 0);",
205     R2I => "${arch}_emit_reg_or_imm(node, 1);",
206     R3I => "${arch}_emit_reg_or_imm(node, 2);",
207 # simple reg emitters
208     S1 => "${arch}_emit_source_register(node, 0);",
209     S2 => "${arch}_emit_source_register(node, 1);",
210     S3 => "${arch}_emit_source_register(node, 2);",
211     S4 => "${arch}_emit_source_register(node, 3);",
212     S5 => "${arch}_emit_source_register(node, 4);",
213     S6 => "${arch}_emit_source_register(node, 5);",
214     D1 => "${arch}_emit_dest_register(node, 0);",
215     D2 => "${arch}_emit_dest_register(node, 1);",
216     D3 => "${arch}_emit_dest_register(node, 2);",
217     D4 => "${arch}_emit_dest_register(node, 3);",
218     D5 => "${arch}_emit_dest_register(node, 4);",
219     D6 => "${arch}_emit_dest_register(node, 5);",
220 # more custom emitters
221         C  => "${arch}_emit_immediate(node);",
222         LM  => "${arch}_emit_load_mode(node);",
223         SM  => "${arch}_emit_store_mode(node);",
224         O  => "${arch}_emit_offset(node);",
225 );
226
227 #--------------------------------------------------#
228 #                        _                         #
229 #                       (_)                        #
230 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
231 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
232 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
233 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
234 #                                      | |         #
235 #                                      |_|         #
236 #--------------------------------------------------#
237
238 $default_attr_type = "sparc_attr_t";
239 $default_copy_attr = "sparc_copy_attr";
240
241
242 %init_attr = (
243                 sparc_attr_t                            => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
244                 sparc_load_store_attr_t                 => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
245                                                                                         "\tinit_sparc_load_store_attributes(res, ls_mode, entity, entity_sign, offset, is_frame_entity);",
246                 sparc_symconst_attr_t                   => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
247                                                                 "\tinit_sparc_symconst_attributes(res, entity);",
248                 sparc_cmp_attr_t                        => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n",
249                 sparc_jmp_cond_attr_t                   => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
250                 sparc_jmp_switch_attr_t                 => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
251                 sparc_save_attr_t                       => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
252
253 );
254
255 %compare_attr = (
256                 sparc_attr_t            => "cmp_attr_sparc",
257                 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
258                 sparc_symconst_attr_t   => "cmp_attr_sparc_symconst",
259                 sparc_jmp_cond_attr_t   => "cmp_attr_sparc_jmp_cond",
260                 sparc_jmp_switch_attr_t => "cmp_attr_sparc_jmp_switch",
261                 sparc_cmp_attr_t        => "cmp_attr_sparc_cmp",
262                 sparc_save_attr_t       => "cmp_attr_sparc_save",
263 );
264
265
266 # addressing modes: imm, reg, reg +/- imm, reg + reg
267 # max. imm = 13 bits signed (-4096 ... 4096)
268
269
270 my %cmp_operand_constructors = (
271     imm => {
272         attr       => "int immediate_value, bool ins_permuted, bool is_unsigned",
273         custominit => "sparc_set_attr_imm(res, immediate_value);" .
274                                                 "\tinit_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
275         reg_req    => { in => [ "gp" ], out => [ "flags" ] },
276         ins        => [ "left" ],
277     },
278     reg => {
279         attr       => "bool ins_permuted, bool is_unsigned",
280         custominit => "init_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
281         reg_req    => { in => [ "gp", "gp" ], out => [ "flags" ] },
282         ins        => [ "left", "right" ],
283     },
284 );
285
286 my %unop_operand_constructors = (
287     imm => {
288         attr       => "int immediate_value",
289         custominit => "sparc_set_attr_imm(res, immediate_value);",
290         reg_req    => { in => [], out => [ "gp" ] },
291     },
292     reg => {
293         reg_req    => { in => [ "gp" ], out => [ "gp" ] },
294     },
295 );
296
297 my %binop_operand_constructors = (
298     imm => {
299         attr       => "int immediate_value",
300         custominit => "sparc_set_attr_imm(res, immediate_value);",
301         reg_req    => { in => [ "gp" ], out => [ "gp" ] },
302         ins        => [ "left" ],
303     },
304     reg => {
305         reg_req    => { in => [ "gp", "gp" ], out => [ "gp" ] },
306         ins        => [ "left", "right" ],
307     },
308 );
309
310 %nodes = (
311
312 #-----------------------------------------------------------------#
313 #  _       _                                         _            #
314 # (_)     | |                                       | |           #
315 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
316 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
317 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
318 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
319 #                   __/ |                                         #
320 #                  |___/                                          #
321 #-----------------------------------------------------------------#
322
323 # commutative operations
324
325 Add => {
326   irn_flags => "R",
327   comment   => "construct Add: Add(a, b) = Add(b, a) = a + b",
328   mode          => $mode_gp,
329   emit      => '. add %S1, %R2I, %D1',
330   constructors => \%binop_operand_constructors,
331 },
332
333 Sub => {
334   irn_flags => "R",
335   comment   => "construct Sub: Sub(a, b) = a - b",
336   mode          => $mode_gp,
337   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
338   emit      => '. sub %S1, %R2I, %D1',
339   constructors => \%binop_operand_constructors,
340 },
341
342
343 # Load / Store
344 Load => {
345   op_flags  => "L|F",
346   comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
347   state     => "exc_pinned",
348   ins       => [ "ptr", "mem" ],
349   outs      => [ "res", "M" ],
350   reg_req   => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
351   attr_type => "sparc_load_store_attr_t",
352   attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
353   emit      => '. ld%LM [%S1%O], %D1'
354 },
355
356 LoadHi => {
357   op_flags  => "L|F",
358   comment   => "construct LoadHi: Load(ptr, mem) = sethi hi(ptr) -> reg",
359   state     => "exc_pinned",
360   ins       => [ "ptr", "mem" ],
361   outs      => [ "res", "M" ],
362   reg_req   => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
363   attr_type => "sparc_load_store_attr_t",
364   attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
365   emit      => '. sethi %%hi(%S1), %D1',
366 },
367
368 HiImm => {
369   op_flags  => "R",
370   comment   => "construct LoadHi: Load(imm, mem) = sethi hi(imm) -> reg",
371   state     => "exc_pinned",
372   outs      => [ "res" ],
373   mode      => $mode_gp,
374   reg_req   => { in => [], out => [ "gp" ] },
375   #attr_type => "sparc_load_store_attr_t",
376   attr       => "int immediate_value",
377   custominit => "sparc_set_attr_imm(res, immediate_value);",
378
379 },
380
381 LoImm => {
382   op_flags  => "R",
383   comment   => "construct LoadHi: Load(imm, mem) = sethi hi(imm) -> reg",
384   state     => "exc_pinned",
385   ins       => [ "hireg" ],
386   outs      => [ "res" ],
387   mode      => $mode_gp,
388   reg_req   => { in => [ "gp" ], out => [ "gp" ] },
389   #attr_type => "sparc_load_store_attr_t",
390   attr       => "int immediate_value",
391   custominit => "sparc_set_attr_imm(res, immediate_value);",
392
393 },
394
395 LoadLo => {
396   op_flags  => "L|F",
397   comment   => "construct LoadLo: Or(in, ptr, mem) = or in lo(ptr) -> reg",
398   state     => "exc_pinned",
399   ins       => [ "hireg", "ptr", "mem" ],
400   outs      => [ "res", "M" ],
401   reg_req   => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
402   attr_type => "sparc_load_store_attr_t",
403   attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
404   emit      => '. or %S1, %%lo(%S2), %D1'
405 },
406
407 Store => {
408   op_flags  => "L|F",
409   comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
410   mode          => "mode_M",
411   state     => "exc_pinned",
412   ins       => [ "ptr", "val", "mem" ],
413   outs      => [ "mem" ],
414   reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
415   attr_type => "sparc_load_store_attr_t",
416   attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
417   emit      => '. st%SM %S2, [%S1%O]'
418 },
419
420 Mov => {
421   irn_flags => "R",
422   comment   => "construct Mov: Mov(src, dest) = MV src,dest",
423   arity     => "variable",
424   emit      => '. mov %R1I, %D1',
425   mode      => $mode_gp,
426   constructors => \%unop_operand_constructors,
427 },
428
429 Save => {
430         comment => "function prolog instruction. autom. saves sp & shifts the register window. previous out regs become the new in regs",
431         reg_req   => {
432                         in => [ "sp", "none"],
433                         out => [ "sp:I|S","none" ]
434         },
435         ins       => [ "stack", "mem" ],
436         outs      => [ "stack", "mem" ],
437         attr      => "int initial_stacksize",
438         attr_type => "sparc_save_attr_t",
439         init_attr => "\tinit_sparc_save_attr(res, initial_stacksize);",
440 },
441
442 AddSP => {
443         comment => "alloc stack space",
444         reg_req   => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
445         ins       => [ "stack", "size", "mem" ],
446         outs      => [ "stack", "addr", "M" ],
447         emit      => ". sub %S1, %S2, %D1\n",
448 },
449
450 SubSP => {
451         comment => "free stack space",
452         reg_req   => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
453         ins       => [ "stack", "size", "mem" ],
454         outs      => [ "stack", "M" ],
455         emit      => ". add %S1, %S2, %D1\n",
456 },
457
458 SymConst => {
459         op_flags  => "c",
460         irn_flags => "R",
461         attr      => "ir_entity *entity",
462         reg_req   => { out => [ "gp" ] },
463         attr_type => "sparc_symconst_attr_t",
464         mode      => $mode_gp,
465 },
466
467 FrameAddr => {
468         op_flags  => "c",
469         irn_flags => "R",
470         attr      => "ir_entity *entity",
471         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
472         ins       => [ "base" ],
473         attr_type => "sparc_symconst_attr_t",
474         mode      => $mode_gp,
475 },
476
477 Branch => {
478         op_flags  => "L|X|Y",
479         state     => "pinned",
480         mode      => "mode_T",
481         reg_req   => { in => [ "flags" ], out => [ "none", "none" ] },
482         attr      => "int proj_num",
483         attr_type => "sparc_jmp_cond_attr_t",
484         init_attr => "\tset_sparc_jmp_cond_proj_num(res, proj_num);",
485 },
486
487 Jmp => {
488         state     => "pinned",
489         op_flags  => "X",
490         irn_flags => "J",
491         reg_req   => { out => [ "none" ] },
492         mode      => "mode_X",
493 },
494
495 Cmp => {
496         irn_flags    => "R|F",
497         emit         => '. cmp %S1, %R2I',
498         mode         => $mode_flags,
499         attr_type    => "sparc_cmp_attr_t",
500         constructors => \%cmp_operand_constructors,
501 },
502
503 Tst => {
504         irn_flags    => "R|F",
505         emit         => '. tst %S1',
506         mode         => $mode_flags,
507         attr_type    => "sparc_cmp_attr_t",
508         attr         => "bool ins_permuted, bool is_unsigned",
509         custominit   => "init_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
510         reg_req      => { in => [ "gp" ], out => [ "flags" ] },
511         ins          => [ "left" ],
512 },
513
514 SwitchJmp => {
515         op_flags  => "L|X|Y",
516         state     => "pinned",
517         mode      => "mode_T",
518         attr      => "int n_projs, long def_proj_num",
519         init_attr => "\tset_sparc_jmp_switch_n_projs(res, n_projs);\n".
520                                         "\tset_sparc_jmp_switch_default_proj_num(res, def_proj_num);",
521         reg_req   => { in => [ "gp" ], out => [ "none" ] },
522         attr_type => "sparc_jmp_switch_attr_t",
523 },
524
525 ShiftLL => {
526   irn_flags => "R",
527   comment   => "construct shift logical left",
528   mode          => $mode_gp,
529   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
530   emit      => '. sll %S1, %R2I, %D1',
531   constructors => \%binop_operand_constructors,
532 },
533
534 ShiftLR => {
535   irn_flags => "R",
536   comment   => "construct shift logical right",
537   mode          => $mode_gp,
538   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
539   emit      => '. slr %S1, %R2I, %D1',
540   constructors => \%binop_operand_constructors,
541 },
542
543 ShiftRA => {
544   irn_flags => "R",
545   comment   => "construct shift right arithmetical",
546   mode          => $mode_gp,
547   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
548   emit      => '. sra %S1, %R2I, %D1',
549   constructors => \%binop_operand_constructors,
550 },
551
552 And => {
553   irn_flags => "R",
554   comment   => "construct logical and",
555   mode          => $mode_gp,
556   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
557   emit      => '. and %S1, %R2I, %D1',
558   constructors => \%binop_operand_constructors,
559 },
560
561 Or => {
562   irn_flags => "R",
563   comment   => "construct logical or",
564   mode          => $mode_gp,
565   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
566   emit      => '. or %S1, %R2I, %D1',
567   constructors => \%binop_operand_constructors,
568 },
569
570 Xor => {
571   irn_flags => "R",
572   comment   => "construct logical xor",
573   mode          => $mode_gp,
574   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
575   emit      => '. xor %S1, %R2I, %D1',
576   constructors => \%binop_operand_constructors,
577 },
578
579 UMul => {
580   state     => "exc_pinned",
581   comment   => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
582   reg_req   => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
583   outs      => [ "low", "high" ],
584   constructors => \%binop_operand_constructors,
585   emit      =>'. umul %S1, %R2I, %D1'
586 },
587
588 UDiv => {
589   irn_flags => "R",
590   mode      => $mode_gp,
591   comment   => "construct Div: Div(a, b) = a / b",
592   reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
593   outs      => [ "res" ],
594   constructors => \%binop_operand_constructors,
595   emit      =>'. udiv %S1, %R2I, %D1'
596 },
597
598 Minus => {
599   irn_flags => "R",
600   mode      => $mode_gp,
601   comment   => "construct Minus: Minus(a) = -a",
602   #reg_req   => { in => [ "gp" ], out => [ "in_r1" ] },
603   reg_req   => { in => [ "gp" ], out => [ "gp" ] },
604   emit      => ". sub %%g0, %S1, %D1"
605 },
606
607 Not => {
608   irn_flags   => "R",
609   mode        => $mode_gp,
610   comment     => "construct Not: Not(a) = !a",
611   reg_req     => { in => [ "gp" ], out => [ "gp" ] },
612   emit        => '. xnor %S1, %%g0, %D1'
613 },
614
615 #Mul_i => {
616 #  irn_flags => "R",
617 #  comment   => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
618 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
619 #  emit      => '. mul %S1, %C, %D1'
620 #},
621 #
622 #And => {
623 #  op_flags  => "C",
624 #  irn_flags => "R",
625 #  comment   => "construct And: And(a, b) = And(b, a) = a AND b",
626 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
627 #  emit      => '. and %S1, %S2, %D1'
628 #},
629 #
630 #And_i => {
631 #  irn_flags => "R",
632 #  comment   => "construct And: And(a, const) = And(const, a) = a AND const",
633 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
634 #  emit      => '. and %S1, %C, %D1'
635 #},
636 #
637 #Or => {
638 #  op_flags  => "C",
639 #  irn_flags => "R",
640 #  comment   => "construct Or: Or(a, b) = Or(b, a) = a OR b",
641 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
642 #  emit      => '. or %S1, %S2, %D1'
643 #},
644 #
645 #Or_i => {
646 #  op_flags  => "C",
647 #  irn_flags => "R",
648 #  comment   => "construct Or: Or(a, const) = Or(const, a) = a OR const",
649 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
650 #  emit      => '. or %S1, %C, %D1'
651 #},
652 #
653 #Eor => {
654 #  op_flags  => "C",
655 #  irn_flags => "R",
656 #  comment   => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
657 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
658 #  emit      => '. xor %S1, %S2, %D1'
659 #},
660 #
661 #Eor_i => {
662 #  irn_flags => "R",
663 #  comment   => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
664 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
665 #  emit      => '. xor %S1, %C, %D1'
666 #},
667
668 # not commutative operations
669 #Shl => {
670 #  irn_flags => "R",
671 #  comment   => "construct Shl: Shl(a, b) = a << b",
672 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
673 #  emit      => '. shl %S1, %S2, %D1'
674 #},
675 #
676 #Shl_i => {
677 #  irn_flags => "R",
678 #  comment   => "construct Shl: Shl(a, const) = a << const",
679 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
680 #  emit      => '. shl %S1, %C, %D1'
681 #},
682 #
683 #Shr => {
684 #  irn_flags => "R",
685 #  comment   => "construct Shr: Shr(a, b) = a >> b",
686 #  reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
687 #  emit      => '. shr %S2, %D1'
688 #},
689 #
690 #Shr_i => {
691 #  irn_flags => "R",
692 #  comment   => "construct Shr: Shr(a, const) = a >> const",
693 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
694 #  emit      => '. shr %S1, %C, %D1'
695 #},
696 #
697 #RotR => {
698 #  irn_flags => "R",
699 #  comment   => "construct RotR: RotR(a, b) = a ROTR b",
700 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
701 #  emit      => '. ror %S1, %S2, %D1'
702 #},
703 #
704 #RotL => {
705 #  irn_flags => "R",
706 #  comment   => "construct RotL: RotL(a, b) = a ROTL b",
707 #  reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
708 #  emit      => '. rol %S1, %S2, %D1'
709 #},
710 #
711 #RotL_i => {
712 #  irn_flags => "R",
713 #  comment   => "construct RotL: RotL(a, const) = a ROTL const",
714 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
715 #  emit      => '. rol %S1, %C, %D1'
716 #},
717 #
718 #Minus => {
719 #  irn_flags => "R",
720 #  comment   => "construct Minus: Minus(a) = -a",
721 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
722 #  emit      => '. neg %S1, %D1'
723 #},
724 #
725 #Inc => {
726 #  irn_flags => "R",
727 #  comment   => "construct Increment: Inc(a) = a++",
728 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
729 #  emit      => '. inc %S1, %D1'
730 #},
731 #
732 #Dec => {
733 #  irn_flags => "R",
734 #  comment   => "construct Decrement: Dec(a) = a--",
735 #  reg_req   => { in => [ "gp" ], out => [ "gp" ] },
736 #  emit      => '. dec %S1, %D1'
737 #},
738 #
739 #Not => {
740 #  arity       => 1,
741 #  remat       => 1,
742 #  comment     => "construct Not: Not(a) = !a",
743 #  reg_req     => { in => [ "gp" ], out => [ "gp" ] },
744 #  emit        => '. not %S1, %D1'
745 #},
746
747
748 #--------------------------------------------------------#
749 #    __ _             _                     _            #
750 #   / _| |           | |                   | |           #
751 #  | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
752 #  |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
753 #  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
754 #  |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
755 #--------------------------------------------------------#
756
757 # commutative operations
758
759 #fAdd => {
760 #  op_flags  => "C",
761 #  irn_flags => "R",
762 #  comment   => "construct FP Add: Add(a, b) = Add(b, a) = a + b",
763 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
764 #  emit      => '. fadd %S1, %S2, %D1'
765 #},
766 #
767 #fMul => {
768 #  op_flags  => "C",
769 #  comment   => "construct FP Mul: Mul(a, b) = Mul(b, a) = a * b",
770 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
771 #  emit      =>'. fmul %S1, %S2, %D1'
772 #},
773 #
774 #fMax => {
775 #  op_flags  => "C",
776 #  irn_flags => "R",
777 #  comment   => "construct FP Max: Max(a, b) = Max(b, a) = a > b ? a : b",
778 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
779 #  emit      =>'. fmax %S1, %S2, %D1'
780 #},
781 #
782 #fMin => {
783 #  op_flags  => "C",
784 #  irn_flags => "R",
785 #  comment   => "construct FP Min: Min(a, b) = Min(b, a) = a < b ? a : b",
786 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
787 #  emit      =>'. fmin %S1, %S2, %D1'
788 #},
789 #
790 ## not commutative operations
791 #
792 #fSub => {
793 #  irn_flags => "R",
794 #  comment   => "construct FP Sub: Sub(a, b) = a - b",
795 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
796 #  emit      => '. fsub %S1, %S2, %D1'
797 #},
798 #
799 #fDiv => {
800 #  comment   => "construct FP Div: Div(a, b) = a / b",
801 #  reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
802 #  emit      => '. fdiv %S1, %S2, %D1'
803 #},
804 #
805 #fMinus => {
806 #  irn_flags => "R",
807 #  comment   => "construct FP Minus: Minus(a) = -a",
808 #  reg_req   => { in => [ "fp" ], out => [ "fp" ] },
809 #  emit      => '. fneg %S1, %D1'
810 #},
811 #
812 ## other operations
813 #
814 #fConst => {
815 #  op_flags  => "c",
816 #  irn_flags => "R",
817 #  comment   => "represents a FP constant",
818 #  reg_req   => { out => [ "fp" ] },
819 #  emit      => '. fmov %C, %D1',
820 #  cmp_attr  =>
821 #'
822 #       /* TODO: compare fConst attributes */
823 #       return 1;
824 #'
825 #},
826 #
827 ## Load / Store
828 #
829 #fLoad => {
830 #  op_flags  => "L|F",
831 #  irn_flags => "R",
832 #  state     => "exc_pinned",
833 #  comment   => "construct FP Load: Load(ptr, mem) = LD ptr",
834 #  reg_req   => { in => [ "gp", "none" ], out => [ "fp" ] },
835 #  emit      => '. fmov (%S1), %D1'
836 #},
837 #
838 #fStore => {
839 #  op_flags  => "L|F",
840 #  irn_flags => "R",
841 #  state     => "exc_pinned",
842 #  comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
843 #  reg_req   => { in => [ "gp", "fp", "none" ] },
844 #  emit      => '. fmov %S2, (%S1)'
845 #},
846
847 ); # end of %nodes