more floating point immediate support
[libfirm] / ir / be / arm / arm_spec.pl
1 # Creation: 2006/02/13
2 # $Id$
3 # This is a template specification for the Firm-Backend
4
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
6
7 $arch = "arm";
8 $new_emit_syntax = 1;
9
10 # the number of additional opcodes you want to register
11 #$additional_opcodes = 0;
12
13 # The node description is done as a perl hash initializer with the
14 # following structure:
15 #
16 # %nodes = (
17 #
18 # <op-name> => {
19 #   op_flags  => "N|L|C|X|I|F|Y|H|c|K",
20 #   irn_flags => "R|N|I|S"
21 #   arity     => "0|1|2|3 ... |variable|dynamic|any",
22 #   state     => "floats|pinned|mem_pinned|exc_pinned",
23 #   args      => [
24 #                    { type => "type 1", name => "name 1" },
25 #                    { type => "type 2", name => "name 2" },
26 #                    ...
27 #                  ],
28 #   comment   => "any comment for constructor",
29 #   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
30 #   cmp_attr  => "c source code for comparing node attributes",
31 #   emit      => "emit code with templates",
32 #   attr      => "attitional attribute arguments for constructor"
33 #   init_attr => "emit attribute initialization template"
34 #   rd_constructor => "c source code which constructs an ir_node"
35 #   latency   => "latency of this operation (can be float)"
36 #   attr_type => "name of the attribute struct",
37 # },
38 #
39 # ... # (all nodes you need to describe)
40 #
41 # ); # close the %nodes initializer
42
43 # op_flags: flags for the operation, OPTIONAL (default is "N")
44 # the op_flags correspond to the firm irop_flags:
45 #   N   irop_flag_none
46 #   L   irop_flag_labeled
47 #   C   irop_flag_commutative
48 #   X   irop_flag_cfopcode
49 #   I   irop_flag_ip_cfopcode
50 #   F   irop_flag_fragile
51 #   Y   irop_flag_forking
52 #   H   irop_flag_highlevel
53 #   c   irop_flag_constlike
54 #   K   irop_flag_keep
55 #
56 # irn_flags: special node flags, OPTIONAL (default is 0)
57 # following irn_flags are supported:
58 #   R   rematerializeable
59 #   N   not spillable
60 #   I   ignore for register allocation
61 #   S   modifies stack pointer
62 #
63 # state: state of the operation, OPTIONAL (default is "floats")
64 #
65 # arity: arity of the operation, MUST NOT BE OMITTED
66 #
67 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
68 #        are always the first 3 arguments and are always autmatically
69 #        created)
70 #        If this key is missing the following arguments will be created:
71 #        for i = 1 .. arity: ir_node *op_i
72 #        ir_mode *mode
73 #
74 # outs:  if a node defines more than one output, the names of the projections
75 #        nodes having outs having automatically the mode mode_T
76 #        One can also annotate some flags for each out, additional to irn_flags.
77 #        They are separated from name with a colon ':', and concatenated by pipe '|'
78 #        Only I and S are available at the moment (same meaning as in irn_flags).
79 #        example: [ "frame:I", "stack:I|S", "M" ]
80 #
81 # comment: OPTIONAL comment for the node constructor
82 #
83 # rd_constructor: for every operation there will be a
84 #      new_rd_<arch>_<op-name> function with the arguments from above
85 #      which creates the ir_node corresponding to the defined operation
86 #      you can either put the complete source code of this function here
87 #
88 #      This key is OPTIONAL. If omitted, the following constructor will
89 #      be created:
90 #      if (!op_<arch>_<op-name>) assert(0);
91 #      for i = 1 to arity
92 #         set in[i] = op_i
93 #      done
94 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
95 #      return res
96 #
97 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
98 #
99 # latency: the latency of the operation, default is 1
100 #
101
102 #
103 # Modes
104 #
105 $mode_gp      = "mode_Iu";
106 $mode_fpa     = "mode_E";
107
108 # register types:
109 #   0 - no special type
110 #   1 - caller save (register must be saved by the caller of a function)
111 #   2 - callee save (register must be saved by the called function)
112 #   4 - ignore (do not assign this register)
113 #   8 - emitter can choose an arbitrary register of this class
114 #  16 - the register is a virtual one
115 #  32 - register represents a state
116 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
117 %reg_classes = (
118         gp => [
119                 { "name" => "r0", "type" => 1 },
120                 { "name" => "r1", "type" => 1 },
121                 { "name" => "r2", "type" => 1 },
122                 { "name" => "r3", "type" => 1 },
123                 { "name" => "r4", "type" => 2 },
124                 { "name" => "r5", "type" => 2 },
125                 { "name" => "r6", "type" => 2 },
126                 { "name" => "r7", "type" => 2 },
127                 { "name" => "r8", "type" => 2 },
128                 { "name" => "r9", "type" => 2 },
129                 { "name" => "r10", "type" => 2 },
130                 { "name" => "r11", "type" => 2 },
131                 { "name" => "r12", "type" => 6 }, # reserved for linker
132                 { "name" => "sp", "type" => 6 }, # this is our stack pointer
133                 { "name" => "lr", "type" => 3 }, # this is our return address
134                 { "name" => "pc", "type" => 6 }, # this is our program counter
135                 { name => "gp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
136                 { "mode" => $mode_gp }
137         ],
138         fpa  => [
139                 { "name" => "f0", "type" => 1 },
140                 { "name" => "f1", "type" => 1 },
141                 { "name" => "f2", "type" => 1 },
142                 { "name" => "f3", "type" => 1 },
143                 { "name" => "f4", "type" => 1 },
144                 { "name" => "f5", "type" => 1 },
145                 { "name" => "f6", "type" => 1 },
146                 { "name" => "f7", "type" => 1 },
147                 { name => "fpa_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
148                 { "mode" => $mode_fpa }
149         ]
150 ); # %reg_classes
151
152 %emit_templates = (
153         M  => "${arch}_emit_mode(env, node);",
154         X  => "${arch}_emit_shift(env, node);",
155         S0 => "${arch}_emit_source_register(env, node, 0);",
156         S1 => "${arch}_emit_source_register(env, node, 1);",
157         S2 => "${arch}_emit_source_register(env, node, 2);",
158         S3 => "${arch}_emit_source_register(env, node, 3);",
159         S4 => "${arch}_emit_source_register(env, node, 4);",
160         D0 => "${arch}_emit_dest_register(env, node, 0);",
161         D1 => "${arch}_emit_dest_register(env, node, 1);",
162         D2 => "${arch}_emit_dest_register(env, node, 2);",
163         C  => "${arch}_emit_immediate(env, node);",
164         O  => "${arch}_emit_offset(env, mode);",
165 );
166
167 #--------------------------------------------------#
168 #                        _                         #
169 #                       (_)                        #
170 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
171 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
172 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
173 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
174 #                                      | |         #
175 #                                      |_|         #
176 #--------------------------------------------------#
177
178 $default_attr_type = "arm_attr_t";
179 $default_copy_attr = "arm_copy_attr";
180
181 %init_attr = (
182         arm_attr_t           => "\tinit_arm_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res, latency);",
183         arm_SymConst_attr_t  => "\tinit_arm_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res, latency);",
184         arm_CondJmp_attr_t   => "\tinit_arm_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res, latency);",
185         arm_SwitchJmp_attr_t => "\tinit_arm_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res, latency);",
186 );
187
188 %compare_attr = (
189         arm_attr_t           => "cmp_attr_arm",
190         arm_SymConst_attr_t  => "cmp_attr_arm_SymConst",
191         arm_CondJmp_attr_t   => "cmp_attr_arm_CondJmp",
192         arm_SwitchJmp_attr_t => "cmp_attr_arm_SwitchJmp",
193 );
194
195 #%operands = (
196 #
197 #Immediate => {
198 #       comment   => "blup di dup",
199 #       irn_flags => "R",
200 #       emit      => ". [%S0]-10",
201 #       reg_req   => { },
202 #       attr      => "tarval *tv",
203 #       init_attr => "(void) attri;",
204 #       # op_flags => O
205 #       # cmp => "return 1;"
206 #},
207 #
208 #ShfOp_I => {
209 #       irn_flags => "R",
210 #       emit      => ". ...",
211 #       reg_req   => { in => [ "gp" ] },
212 #       attr      => "tarval *tv",
213 #       init_attr => "(void) tv;",
214 #},
215 #
216 #ShfOp => {
217 #       irn_flags => "R",
218 #       emit      => ". ...",
219 #       reg_req   => { in => [ "gp", "gp" ] },
220 #},
221 #
222 #);
223
224 %nodes = (
225
226 Unknown_GP => {
227         state     => "pinned",
228         op_flags  => "c",
229         irn_flags => "I",
230         reg_req   => { out => [ "gp_UKNWN" ] },
231         emit      => "",
232         mode      => $mode_gp,
233 },
234
235 Unknown_FPA => {
236         state     => "pinned",
237         op_flags  => "c",
238         irn_flags => "I",
239         reg_req   => { out => [ "fpa_UKNWN" ] },
240         emit      => "",
241         mode      => $mode_fpa,
242 },
243
244 #-----------------------------------------------------------------#
245 #  _       _                                         _            #
246 # (_)     | |                                       | |           #
247 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
248 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
249 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
250 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
251 #                   __/ |                                         #
252 #                  |___/                                          #
253 #-----------------------------------------------------------------#
254
255 # commutative operations
256
257 Add => {
258         op_flags  => "C",
259         irn_flags => "R",
260         comment   => "construct Add: Add(a, b) = Add(b, a) = a + b",
261         attr      => "arm_shift_modifier mod, tarval *shf",
262         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
263         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
264         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
265         emit      => '. add %D0, %S0, %S1%X'
266 },
267
268 Add_i => {
269         irn_flags => "R",
270         comment   => "construct Add: Add(a, const) = Add(const, a) = a + const",
271         attr      => "tarval *tv",
272         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
273         cmp_attr  => 'return attr_a->value != attr_b->value;',
274         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
275         emit      => '. add %D0, %S0, %C'
276 },
277
278 Mul => {
279         #op_flags  => "C",
280         irn_flags => "R",
281         comment   => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
282         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "!in_r1" ] },
283         emit      =>'. mul %D0, %S0, %S1'
284 },
285
286 Smull => {
287         #op_flags  => "C",
288         irn_flags => "R",
289         comment   => "construct signed 64bit Mul: Mul(a, b) = Mul(b, a) = a * b",
290         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp", "gp" ] },
291         emit      =>'. smull %D0, %D1, %S0, %S1',
292         outs      => [ "low", "high" ],
293 },
294
295 Umull => {
296         #op_flags  => "C",
297         irn_flags => "R",
298         comment   => "construct unsigned 64bit Mul: Mul(a, b) = Mul(b, a) = a * b",
299         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp", "gp" ] },
300         emit      =>'. umull %D0, %D1, %S0, %S1',
301         outs      => [ "low", "high" ],
302 },
303
304 Mla => {
305         #op_flags  => "C",
306         irn_flags => "R",
307         comment   => "construct Mla: Mla(a, b, c) = a * b + c",
308         reg_req   => { "in" => [ "gp", "gp", "gp" ], "out" => [ "!in_r1" ] },
309         emit      =>'. mla %D0, %S0, %S1, %S2'
310 },
311
312 And => {
313         op_flags  => "C",
314         irn_flags => "R",
315         comment   => "construct And: And(a, b) = And(b, a) = a AND b",
316         attr      => "arm_shift_modifier mod, tarval *shf",
317         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
318         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
319         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
320         emit      => '. and %D0, %S0, %S1%X'
321 },
322
323 And_i => {
324         irn_flags => "R",
325         comment   => "construct And: And(a, const) = And(const, a) = a AND const",
326         attr      => "tarval *tv",
327         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
328         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
329         emit      => '. and %D0, %S0, %C',
330         cmp_attr  => 'return attr_a->value != attr_b->value;'
331 },
332
333 Or => {
334         op_flags  => "C",
335         irn_flags => "R",
336         comment   => "construct Or: Or(a, b) = Or(b, a) = a OR b",
337         attr      => "arm_shift_modifier mod, tarval *shf",
338         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
339         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
340         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
341         emit      => '. orr %D0, %S0, %S1%X'
342 },
343
344 Or_i => {
345         irn_flags => "R",
346         comment   => "construct Or: Or(a, const) = Or(const, a) = a OR const",
347         attr      => "tarval *tv",
348         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
349         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
350         cmp_attr  => 'return attr_a->value != attr_b->value;',
351         emit      => '. orr %D0, %S0, %C'
352 },
353
354 Eor => {
355         op_flags  => "C",
356         irn_flags => "R",
357         comment   => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
358         attr      => "arm_shift_modifier mod, tarval *shf",
359         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
360         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
361         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
362         emit      => '. eor %D0, %S0, %S1%X'
363 },
364
365 Eor_i => {
366         irn_flags => "R",
367         comment   => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
368         attr      => "tarval *tv",
369         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
370         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
371         cmp_attr  => 'return attr_a->value != attr_b->value;',
372         emit      => '. eor %D0, %S0, %C'
373 },
374
375 # not commutative operations
376
377 Bic => {
378         irn_flags => "R",
379         comment   => "construct Bic: Bic(a, b) = a AND ~b",
380         attr      => "arm_shift_modifier mod, tarval *shf",
381         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
382         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
383         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
384         emit      => '. bic %D0, %S0, %S1%X'
385 },
386
387 Bic_i => {
388         irn_flags => "R",
389         comment   => "construct Bic: Bic(a, const) = a AND ~const",
390         attr      => "tarval *tv",
391         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
392         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
393         emit      => '. bic %D0, %S0, %C',
394         cmp_attr  => 'return attr_a->value != attr_b->value;'
395 },
396
397 Sub => {
398         irn_flags => "R",
399         comment   => "construct Sub: Sub(a, b) = a - b",
400         attr      => "arm_shift_modifier mod, tarval *shf",
401         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
402         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
403         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
404         emit      => '. sub %D0, %S0, %S1%X'
405 },
406
407 Sub_i => {
408         irn_flags => "R",
409         comment   => "construct Sub: Sub(a, const) = a - const",
410         attr      => "tarval *tv",
411         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
412         cmp_attr  => 'return attr_a->value != attr_b->value;',
413         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
414         emit      => '. sub %D0, %S0, %C',
415 },
416
417 Rsb => {
418         irn_flags => "R",
419         comment   => "construct Rsb: Rsb(a, b) = b - a",
420         attr      => "arm_shift_modifier mod, tarval *shf",
421         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
422         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
423         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
424         emit      => '. rsb %D0, %S0, %S1%X'
425 },
426
427 Rsb_i => {
428         irn_flags => "R",
429         comment   => "construct Rsb: Rsb(a, const) = const - a",
430         attr      => "tarval *tv",
431         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
432         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
433         emit      => '. rsb %D0, %S0, %C',
434         cmp_attr  => 'return attr_a->value != attr_b->value;'
435 },
436
437 Shl => {
438         irn_flags => "R",
439         comment   => "construct Shl: Shl(a, b) = a << b",
440         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
441         emit      => '. mov %D0, %S0, lsl %S1'
442 },
443
444 Shr => {
445         irn_flags => "R",
446         comment   => "construct Shr: Shr(a, b) = a >> b",
447         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "in_r1" ] },
448         emit      => '. mov %D0, %S0, lsr %S1'
449 },
450
451 Shrs => {
452         irn_flags => "R",
453         comment   => "construct Shrs: Shrs(a, b) = a >> b",
454         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "in_r1" ] },
455         emit      => '. mov %D0, %S0, asr %S1'
456 },
457
458 #RotR => {
459 #       irn_flags => "R",
460 #       comment   => "construct RotR: RotR(a, b) = a ROTR b",
461 #       reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
462 #       emit      => '. mov %D0, %S0, ror %S1 /* RotR(%S0, %S1) -> %D0, (%A1, %A2) */'
463 ##      emit      => '. ror %S0, %S1, %D0'
464 #},
465
466 #RotL => {
467 #  irn_flags => "R",
468 #  comment   => "construct RotL: RotL(a, b) = a ROTL b",
469 #  reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "gp" ] },
470 #  emit      => '. rol %S0, %S1, %D0'
471 #},
472
473 #RotL_i => {
474 #       irn_flags => "R",
475 #       comment   => "construct RotL: RotL(a, const) = a ROTL const",
476 #       reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
477 #       emit      => '. rol %S0, %C, %D0'
478 #},
479
480 Mov => {
481         irn_flags => "R",
482         comment   => "construct Mov: a = b",
483         attr      => "arm_shift_modifier mod, tarval *shf",
484         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
485         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
486         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
487         emit      => '. mov %D0, %S0%X'
488 },
489
490 Mov_i => {
491         irn_flags => "R",
492         comment   => "represents an integer constant",
493         attr      => "tarval *tv",
494         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
495         reg_req   => { "out" => [ "gp" ] },
496         emit      => '. mov %D0, %C',
497         cmp_attr  => 'return attr_a->value != attr_b->value;'
498 },
499
500 Mvn => {
501         irn_flags => "R",
502         comment   => "construct Not: Not(a) = !a",
503         attr      => "arm_shift_modifier mod, tarval *shf",
504         init_attr => 'ARM_SET_SHF_MOD(attr, mod); attr->value = shf;',
505         cmp_attr  => 'return (attr_a->instr_fl != attr_b->instr_fl) || (attr_a->value != attr_b->value);',
506         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
507         emit      => '. mvn %D0, %S0%X'
508 },
509
510 Mvn_i => {
511         irn_flags => "R",
512         comment   => "represents a negated integer constant",
513         attr      => "tarval *tv",
514         init_attr => 'ARM_SET_SHF_MOD(attr, ARM_SHF_IMM); attr->value = tv;',
515         cmp_attr  => 'return attr_a->value != attr_b->value;',
516         reg_req   => { "out" => [ "gp" ] },
517         emit      => '. mvn %D0, %C',
518 },
519
520 Abs => {
521         irn_flags => "R",
522         comment   => "construct Abs: Abs(a) = |a|",
523         reg_req   => { "in" => [ "gp" ], "out" => [ "gp" ] },
524         emit      =>
525 '. movs %S0, %S0, #0
526 . rsbmi %D0, %S0, #0'
527 },
528
529 # other operations
530
531 #
532 # this node produces ALWAYS an empty (tempary) gp reg and cannot be CSE'd
533 #
534 EmptyReg => {
535         op_flags  => "c",
536         irn_flags => "R",
537         comment   => "allocate an empty register for calculations",
538         reg_req   => { "out" => [ "gp" ] },
539         emit      => '. /* %D0 now available for calculations */',
540         cmp_attr  => 'return 1;'
541 },
542
543 Copy => {
544         comment  => "implements a register copy",
545         reg_req  => { "in" => [ "gp" ], "out" => [ "gp" ] },
546 },
547
548 CopyB => {
549         op_flags  => "F|H",
550         state     => "pinned",
551         comment   => "implements a memcopy: CopyB(dst, src, size, mem) == memcpy(dst, src, size)",
552         attr      => "tarval *tv",
553         init_attr => 'attr->value = tv;',
554         reg_req   => { "in" => [ "!sp", "!sp", "gp", "gp", "gp", "none" ], "out" => [ "none" ] },
555         outs      => [ "M" ],
556 },
557
558 SymConst => {
559         op_flags  => "c",
560         irn_flags => "R",
561         comment   => "represents a symbolic constant",
562         attr      => "ident *id",
563         init_attr => "\tset_arm_symconst_id(res, id);",
564         reg_req   => { "out" => [ "gp" ] },
565         attr_type   => "arm_SymConst_attr_t",
566 },
567
568 CmpBra => {
569         op_flags  => "L|X|Y",
570         state     => "pinned",
571         comment   => "construct conditional branch: CMP A, B && JMPxx LABEL",
572         mode      => "mode_T",
573         attr      => "int proj_num",
574         init_attr => "\tset_arm_CondJmp_proj_num(res, proj_num);",
575         reg_req   => { "in" => [ "gp", "gp" ], "out" => [ "none", "none"] },
576         attr_type => "arm_CondJmp_attr_t",
577 },
578
579 SwitchJmp => {
580         op_flags  => "L|X|Y",
581         state     => "pinned",
582         comment   => "construct switch",
583         mode      => "mode_T",
584         attr      => "int n_projs, long def_proj_num",
585         init_attr => "\tset_arm_SwitchJmp_n_projs(res, n_projs);\n".
586                      "\tset_arm_SwitchJmp_default_proj_num(res, def_proj_num);",
587         reg_req   => { "in" => [ "gp" ], "out" => [ "none" ] },
588         attr_type => "arm_SwitchJmp_attr_t",
589 },
590
591 # Load / Store
592
593 Load => {
594         op_flags  => "L|F",
595         irn_flags => "R",
596         state     => "exc_pinned",
597         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
598         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "gp", "none" ] },
599         emit      => '. ldr %D0, [%S0, #0]',
600         outs      => [ "res", "M" ],
601 },
602
603 Loadb => {
604         op_flags  => "L|F",
605         irn_flags => "R",
606         state     => "exc_pinned",
607         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
608         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "gp", "none" ] },
609         emit      => '. ldrb %D0, [%S0, #0]',
610         outs      => [ "res", "M" ],
611 },
612
613 Loadbs => {
614         op_flags  => "L|F",
615         irn_flags => "R",
616         state     => "exc_pinned",
617         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
618         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "gp", "none" ] },
619         emit      => '. ldrsb %D0, [%S0, #0]',
620         outs      => [ "res", "M" ],
621 },
622
623 Loadh => {
624         op_flags  => "L|F",
625         irn_flags => "R",
626         state     => "exc_pinned",
627         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
628         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "gp", "none" ] },
629         emit      => '. ldrh %D0, [%S0, #0]',
630         outs      => [ "res", "M" ],
631 },
632
633 Loadhs => {
634         op_flags  => "L|F",
635         irn_flags => "R",
636         state     => "exc_pinned",
637         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
638         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "gp", "none" ] },
639         emit      => '. ldrsh %D0, [%S0, #0]',
640         outs      => [ "res", "M" ],
641 },
642
643 Storeb => {
644         op_flags  => "L|F",
645         irn_flags => "R",
646         state     => "exc_pinned",
647         comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
648         reg_req   => { "in" => [ "gp", "gp", "none" ], "out" => [ "none" ] },
649         emit      => '. strb %S1, [%S0, #0]',
650         mode      => "mode_M",
651 },
652
653 Storeh => {
654         op_flags  => "L|F",
655         irn_flags => "R",
656         state     => "exc_pinned",
657         comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
658         reg_req   => { "in" => [ "gp", "gp", "none" ], out => [ "none" ] },
659         emit      => '. strh %S1, [%S0, #0]',
660         mode      => "mode_M",
661 },
662
663 Store => {
664         op_flags  => "L|F",
665         irn_flags => "R",
666         state     => "exc_pinned",
667         comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
668         reg_req   => { "in" => [ "gp", "gp", "none" ], out => [ "none" ] },
669         emit      => '. str %S1, [%S0, #0]',
670         mode      => "mode_M",
671 },
672
673 StoreStackM4Inc => {
674         op_flags  => "L|F",
675         irn_flags => "R",
676         state     => "exc_pinned",
677         comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
678         reg_req   => { "in" => [ "sp", "gp", "gp", "gp", "gp", "none" ], "out" => [ "gp", "none" ] },
679         emit      => '. stmfd %S0!, {%S1, %S2, %S3, %S4}',
680         outs      => [ "ptr", "M" ],
681 },
682
683 LoadStackM3 => {
684         op_flags  => "L|F",
685         irn_flags => "R",
686         state     => "exc_pinned",
687         comment   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
688         reg_req   => { "in" => [ "sp", "none" ], "out" => [ "gp", "gp", "gp", "none" ] },
689         emit      => '. ldmfd %S0, {%D0, %D1, %D2}',
690         outs      => [ "res0", "res1", "res2", "M" ],
691 },
692
693
694 #---------------------------------------------------#
695 #    __                               _             #
696 #   / _|                             | |            #
697 #  | |_ _ __   __ _   _ __   ___   __| | ___  ___   #
698 #  |  _| '_ \ / _` | | '_ \ / _ \ / _` |/ _ \/ __|  #
699 #  | | | |_) | (_| | | | | | (_) | (_| |  __/\__ \  #
700 #  |_| | .__/ \__,_| |_| |_|\___/ \__,_|\___||___/  #
701 #      | |                                          #
702 #      |_|                                          #
703 #---------------------------------------------------#
704
705 # commutative operations
706
707 fpaAdf => {
708         op_flags  => "C",
709         irn_flags => "R",
710         comment   => "construct FPA Add: Add(a, b) = Add(b, a) = a + b",
711         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
712         emit      => '. adf%M %D0, %S0, %S1',
713 },
714
715 fpaAdf_i => {
716         op_flags  => "C",
717         irn_flags => "R",
718         comment   => "construct FPA Add: Add(a, b) = Add(b, a) = a + b",
719         attr      => "tarval *tv",
720         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
721         cmp_attr  => 'return attr_a->value != attr_b->value;',
722         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
723         emit      => '. adf%M %D0, %S0, %C',
724 },
725
726 fpaMuf => {
727         op_flags  => "C",
728         irn_flags => "R",
729         comment   => "construct FPA Mul: Mul(a, b) = Mul(b, a) = a * b",
730         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
731         emit      =>'. muf%M %D0, %S0, %S1',
732 },
733
734 fpaMuf_i => {
735         op_flags  => "C",
736         irn_flags => "R",
737         comment   => "construct FPA Mul: Mul(a, b) = Mul(b, a) = a * b",
738         attr      => "tarval *tv",
739         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
740         cmp_attr  => 'return attr_a->value != attr_b->value;',
741         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
742         emit      => '. muf%M %D0, %S0, %C',
743 },
744
745 fpaFml => {
746         op_flags  => "C",
747         irn_flags => "R",
748         comment   => "construct FPA Fast Mul: Mul(a, b) = Mul(b, a) = a * b",
749         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
750         emit      =>'. fml%M %D0, %S0, %S1',
751 },
752
753 fpaMax => {
754         op_flags  => "C",
755         irn_flags => "R",
756         comment   => "construct FPA Max: Max(a, b) = Max(b, a) = a > b ? a : b",
757         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
758         emit      =>'. fmax %S0, %S1, %D0',
759 },
760
761 fpaMin => {
762         op_flags  => "C",
763         irn_flags => "R",
764         comment   => "construct FPA Min: Min(a, b) = Min(b, a) = a < b ? a : b",
765         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
766         emit      =>'. fmin %S0, %S1, %D0',
767 },
768
769 # not commutative operations
770
771 fpaSuf => {
772         irn_flags => "R",
773         comment   => "construct FPA Sub: Sub(a, b) = a - b",
774         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
775         emit      => '. suf%M %D0, %S0, %S1'
776 },
777
778 fpaSuf_i => {
779         irn_flags => "R",
780         comment   => "construct FPA Sub: Sub(a, b) = a - b",
781         attr      => "tarval *tv",
782         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
783         cmp_attr  => 'return attr_a->value != attr_b->value;',
784         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
785         emit      => '. suf%M %D0, %S0, %C'
786 },
787
788 fpaRsf => {
789         irn_flags => "R",
790         comment   => "construct FPA reverse Sub: Sub(a, b) = b - a",
791         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa" ] },
792         emit      => '. rsf%M %D0, %S0, %S1'
793 },
794
795 fpaRsf_i => {
796         irn_flags => "R",
797         comment   => "construct FPA reverse Sub: Sub(a, b) = b - a",
798         attr      => "tarval *tv",
799         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
800         cmp_attr  => 'return attr_a->value != attr_b->value;',
801         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
802         emit      => '. rsf%M %D0, %S0, %C'
803 },
804
805 fpaDvf => {
806         comment   => "construct FPA Div: Div(a, b) = a / b",
807         attr      => "ir_mode *op_mode",
808         init_attr => "attr->op_mode = op_mode;",
809         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa", "none" ] },
810         emit      =>'. dvf%M %D0, %S0, %S1',
811         outs      => [ "res", "M" ],
812 },
813
814 fpaDvf_i => {
815         comment   => "construct FPA Div: Div(a, b) = a / b",
816         attr      => "ir_mode *op_mode, tarval *tv",
817         init_attr => 'attr->op_mode = op_mode; ARM_SET_FPA_IMM(attr); attr->value = tv;',
818         cmp_attr  => 'return attr_a->value != attr_b->value;',
819         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa", "none" ] },
820         emit      =>'. dvf%M %D0, %S0, %C',
821         outs      => [ "res", "M" ],
822 },
823
824 fpaRdf => {
825         comment   => "construct FPA reverse Div: Div(a, b) = b / a",
826         attr      => "ir_mode *op_mode",
827         init_attr => "attr->op_mode = op_mode;",
828         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa", "none" ] },
829         emit      =>'. rdf%M %D0, %S0, %S1',
830         outs      => [ "res", "M" ],
831 },
832
833 fpaRdf_i => {
834         comment   => "construct FPA reverse Div: Div(a, b) = b / a",
835         attr      => "ir_mode *op_mode, tarval *tv",
836         init_attr => 'attr->op_mode = op_mode; ARM_SET_FPA_IMM(attr); attr->value = tv;',
837         cmp_attr  => 'return attr_a->value != attr_b->value;',
838         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa", "none" ] },
839         emit      =>'. rdf%M %D0, %S0, %S1',
840         outs      => [ "res", "M" ],
841 },
842
843 fpaFdv => {
844         comment   => "construct FPA Fast Div: Div(a, b) = a / b",
845         attr      => "ir_mode *op_mode",
846         init_attr => "attr->op_mode = op_mode;",
847         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa", "none" ] },
848         emit      =>'. fdv%M %D0, %S0, %S1',
849         outs      => [ "res", "M" ],
850 },
851
852 fpaFdv_i => {
853         comment   => "construct FPA Fast Div: Div(a, b) = a / b",
854         attr      => "ir_mode *op_mode, tarval *tv",
855         init_attr => 'attr->op_mode = op_mode; ARM_SET_FPA_IMM(attr); attr->value = tv;',
856         cmp_attr  => 'return attr_a->value != attr_b->value;',
857         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa", "none" ] },
858         emit      =>'. fdv%M %D0, %S0, %C',
859         outs      => [ "res", "M" ],
860 },
861
862 fpaFrd => {
863         comment   => "construct FPA Fast reverse Div: Div(a, b) = b / a",
864         attr      => "ir_mode *op_mode",
865         init_attr => "attr->op_mode = op_mode;",
866         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "fpa", "none" ] },
867         emit      =>'. frd%M %D0, %S0, %S1',
868         outs      => [ "res", "M" ],
869 },
870
871 fpaFrd_i => {
872         comment   => "construct FPA Fast reverse Div: Div(a, b) = b / a",
873         attr      => "ir_mode *op_mode, tarval *tv",
874         init_attr => 'attr->op_mode = op_mode; ARM_SET_FPA_IMM(attr); attr->value = tv;',
875         cmp_attr  => 'return attr_a->value != attr_b->value;',
876         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa", "none" ] },
877         emit      =>'. frd%M %D0, %S0, %C',
878         outs      => [ "res", "M" ],
879 },
880
881 fpaMvf => {
882         irn_flags => "R",
883         comment   => "construct FPA Move: b = a",
884         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
885         emit      => '. mvf%M %S0, %D0',
886 },
887
888 fpaMvf_i => {
889         irn_flags => "R",
890         comment   => "represents a float constant",
891         attr      => "tarval *tv",
892         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
893         reg_req   => { "out" => [ "fpa" ] },
894         mode      => "get_tarval_mode(tv)",
895         emit      => '. mvf %D0, %C',
896         cmp_attr  => 'return attr_a->value != attr_b->value;'
897 },
898
899 fpaMnf => {
900         irn_flags => "R",
901         comment   => "construct FPA Move Negated: b = -a",
902         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
903         emit      => '. mnf%M %S0, %D0',
904 },
905
906 fpaMnf_i => {
907         irn_flags => "R",
908         comment   => "represents a float constant",
909         attr      => "tarval *tv",
910         init_attr => 'ARM_SET_FPA_IMM(attr); attr->value = tv;',
911         reg_req   => { "out" => [ "fpa" ] },
912         mode      => "get_tarval_mode(tv)",
913         emit      => '. mnf %D0, %C',
914         cmp_attr  => 'return attr_a->value != attr_b->value;'
915 },
916
917 fpaAbs => {
918         irn_flags => "R",
919         comment   => "construct FPA Absolute value: fAbsd(a) = |a|",
920         reg_req   => { "in" => [ "fpa" ], "out" => [ "fpa" ] },
921         emit      => '. abs%M %D0, %S0',
922 },
923
924 # other operations
925
926 fpaFlt => {
927         irn_flags => "R",
928         comment   => "construct a FPA integer->float conversion",
929         reg_req   => { "in" => ["gp"], "out" => [ "fpa" ] },
930         emit      => '. flt%M %D0, %S0',
931 },
932
933 fpaFix => {
934         irn_flags => "R",
935         comment   => "construct a FPA float->integer conversion",
936         reg_req   => { "in" => ["fpa"], "out" => [ "gp" ] },
937         emit      => '. fix %D0, %S0',
938 },
939
940 fpaCmfBra => {
941         op_flags  => "L|X|Y",
942         state     => "pinned",
943         comment   => "construct floating point Compare and Branch: CMF A, B && JMPxx LABEL",
944         mode      => "mode_T",
945         attr      => "int proj_num",
946         init_attr => "\tset_arm_CondJmp_proj_num(res, proj_num);",
947         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "none", "none"] },
948         attr_type => "arm_CondJmp_attr_t",
949 },
950
951 fpaCnfBra => {
952         op_flags  => "L|X|Y",
953         state     => "pinned",
954         comment   => "construct floating point Compare negative and Branch: CMF A, -B && JMPxx LABEL",
955         mode      => "mode_T",
956         attr      => "int proj_num",
957         init_attr => "\tset_arm_CondJmp_proj_num(res, proj_num);",
958         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "none", "none"] },
959         attr_type => "arm_CondJmp_attr_t",
960 },
961
962 fpaCmfeBra => {
963         op_flags  => "L|X|Y",
964         state     => "pinned",
965         comment   => "construct floating point Compare and Branch: CMF A, -B && JMPxx LABEL",
966         mode      => "mode_T",
967         attr      => "int proj_num",
968         init_attr => "\tset_arm_CondJmp_proj_num(res, proj_num);",
969         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "none", "none"] },
970         attr_type => "arm_CondJmp_attr_t",
971 },
972
973 fpaCnfeBra => {
974         op_flags  => "L|X|Y",
975         state     => "pinned",
976         comment   => "construct floating point Compare and Branch: CMF A, -B && JMPxx LABEL",
977         mode      => "mode_T",
978         attr      => "int proj_num",
979         init_attr => "\tset_arm_CondJmp_proj_num(res, proj_num);",
980         reg_req   => { "in" => [ "fpa", "fpa" ], "out" => [ "none", "none"] },
981         attr_type => "arm_CondJmp_attr_t",
982 },
983
984 # Load / Store
985
986 fpaLdf => {
987         op_flags  => "L|F",
988         irn_flags => "R",
989         state     => "exc_pinned",
990         comment   => "construct FPA Load: Load(ptr, mem) = LD ptr",
991         attr      => "ir_mode *op_mode",
992         init_attr => "attr->op_mode = op_mode;",
993         reg_req   => { "in" => [ "gp", "none" ], "out" => [ "fpa", "none" ] },
994         emit      => '. ldf%M %D0, [%S0]',
995         outs      => [ "res", "M" ],
996 },
997
998 fpaStf => {
999         op_flags  => "L|F",
1000         irn_flags => "R",
1001         state     => "exc_pinned",
1002         comment   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
1003         attr      => "ir_mode *op_mode",
1004         init_attr => "attr->op_mode = op_mode;",
1005         reg_req   => { "in" => [ "gp", "fpa", "none" ], "out" => [ "none" ] },
1006         emit      => '. stf%M %S1, [%S0]',
1007         mode      => "mode_M",
1008 },
1009
1010 fpaDbl2GP => {
1011         op_flags  => "L|F",
1012         irn_flags => "R",
1013         comment   => "construct fp double to 2 gp register transfer",
1014         reg_req   => { "in" => [ "fpa", "none" ], "out" => [ "gp", "gp", "none" ] },
1015         outs      => [ "low", "high", "M" ],
1016 },
1017
1018 AddSP => {
1019         irn_flags => "I",
1020         comment   => "construct Add to stack pointer",
1021         reg_req   => { in => [ "sp", "gp", "none" ], out => [ "in_r1", "none" ] },
1022         emit      => '. add %D0, %S0, %S1',
1023         outs      => [ "stack:S", "M" ],
1024 },
1025
1026 SubSP => {
1027         irn_flags => "I",
1028         comment   => "construct Sub from stack pointer",
1029         reg_req   => { in => [ "sp", "gp", "none" ], out => [ "in_r1", "none" ] },
1030         emit      => '. sub %D0, %S0, %S1',
1031         outs      => [ "stack:S", "M" ],
1032 },
1033
1034 LdTls => {
1035         irn_flags => "R",
1036         comment   => "load the TLS address",
1037         reg_req   => { out => [ "gp" ] },
1038 },
1039
1040
1041 #
1042 # floating point constants
1043 #
1044 fpaConst => {
1045         op_flags  => "c",
1046         irn_flags => "R",
1047         comment   => "construct a floating point constant",
1048         attr      => "tarval *tv",
1049         init_attr => "attr->value = tv;",
1050         mode      => "get_tarval_mode(tv)",
1051         reg_req   => { "out" => [ "fpa" ] },
1052 }
1053
1054 #---------------------------------------------------#
1055 #          __                         _             #
1056 #         / _|                       | |            #
1057 #  __   _| |_ _ __    _ __   ___   __| | ___  ___   #
1058 #  \ \ / /  _| '_ \  | '_ \ / _ \ / _` |/ _ \/ __|  #
1059 #   \ V /| | | |_) | | | | | (_) | (_| |  __/\__ \  #
1060 #    \_/ |_| | .__/  |_| |_|\___/ \__,_|\___||___/  #
1061 #            | |                                    #
1062 #            |_|                                    #
1063 #---------------------------------------------------#
1064
1065 ); # end of %nodes