added Min, Max, Div, DivMod and Mulh nodes
[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 #      res = optimize_node(res)
70 #      IRN_VRFY_IRG(res, irg)
71 #      return res
72 #
73 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
74
75 #--------------------------------------------------#
76 #                        _                         #
77 #                       (_)                        #
78 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
79 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
80 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
81 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
82 #                                      | |         #
83 #                                      |_|         #
84 #--------------------------------------------------#
85
86 %nodes = (
87
88 # arithmetic operations
89
90 # commutative operations
91
92 "Add" => {
93   "op_flags" => "C",
94   "arity"    => 2,
95   "comment"  => "construct Add: Add(a, b) = Add(b, a) = a + b"
96 },
97
98 "Add_i" => {
99   "arity"    => 1,
100   "comment"  => "construct Add: Add(a, const) = Add(const, a) = a + const",
101 },
102
103 "Mul" => {
104   "op_flags" => "C",
105   "arity"    => 2,
106   "comment"  => "construct Mul: Mul(a, b) = Mul(b, a) = a * b"
107 },
108
109 "Mul_i" => {
110   "state"    => "pinned",
111   "arity"    => 1,
112   "comment"  => "construct Mul: Mul(a, const) = Mul(const, a) = a * const"
113 },
114
115 "Mulh" => {
116   "op_flags" => "C",
117   "arity"    => 2,
118   "comment"  => "construct Mulh: Mulh(a, b) = Mulh(b, a) = get_32_highest_bits(a * b)"
119 },
120
121 "Mulh_i" => {
122   "state"    => "pinned",
123   "arity"    => 1,
124   "comment"  => "construct Mulh: Mulh(a, const) = Mulh(const, a) = get_32_highest_bits(a * const)"
125 },
126
127 "And" => {
128   "op_flags" => "C",
129   "arity"    => 2,
130   "comment"  => "construct And: And(a, b) = And(b, a) = a AND b"
131 },
132
133 "And_i" => {
134   "arity"    => 1,
135   "comment"  => "construct And: And(a, const) = And(const, a) = a AND const"
136 },
137
138 "Or" => {
139   "op_flags" => "C",
140   "arity"    => 2,
141   "comment"  => "construct Or: Or(a, b) = Or(b, a) = a OR b"
142 },
143
144 "Or_i" => {
145   "arity"    => 1,
146   "comment"  => "construct Or: Or(a, const) = Or(const, a) = a OR const"
147 },
148
149 "Eor" => {
150   "op_flags" => "C",
151   "arity"    => 2,
152   "comment"  => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b"
153 },
154
155 "Eor_i" => {
156   "arity"    => 1,
157   "comment"  => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const"
158 },
159
160 "Max" => {
161   "op_flags" => "C",
162   "arity"    => 2,
163   "comment"  => "construct Max: Max(a, b) = Max(b, a) = a > b ? a : b"
164 },
165
166 "Max_i" => {
167   "arity"    => 1,
168   "comment"  => "construct Max: Max(a, const) = Max(const, a) = a > const ? a : const"
169 },
170
171 "Min" => {
172   "op_flags" => "C",
173   "arity"    => 2,
174   "comment"  => "construct Min: Min(a, b) = Min(b, a) = a < b ? a : b"
175 },
176
177 "Min_i" => {
178   "arity"    => 1,
179   "comment"  => "construct Min: Min(a, const) = Min(const, a) = a < const ? a : const"
180 },
181
182 # not commutative operations
183
184 "Sub" => {
185   "arity"    => 2,
186   "comment"  => "construct Sub: Sub(a, b) = a - b"
187 },
188
189 "Sub_i" => {
190   "arity"    => 1,
191   "comment"  => "construct Sub: Sub(a, const) = a - const"
192 },
193
194 "Mod" => {
195   "arity"    => 2,
196   "comment"  => "construct Mod: Mod(a, b) = a % b"
197 },
198
199 "Mod_i" => {
200   "arity"    => 1,
201   "comment"  => "construct Mod: Mod(a, const) = a % const"
202 },
203
204 "DivMod" => {
205   "arity"    => 2,
206   "comment"  => "construct DivMod: DivMod(a,b) = (a / b, a % b)"
207 },
208
209 "DivMod_i" => {
210   "arity"    => 1,
211   "comment"  => "construct DivMod: DivMod(a, const) = (a / const, a % const)"
212 },
213
214 "Div" => {
215   "arity"    => 2,
216   "comment"  => "construct Div: Div(a, b) = a / b"
217 },
218
219 "Div_i" => {
220   "arity"    => 1,
221   "comment"  => "construct Div: Div(a, const) = a / const"
222 },
223
224 "Shl" => {
225   "arity"    => 2,
226   "comment"  => "construct Shl: Shl(a, b) = a << b"
227 },
228
229 "Shl_i" => {
230   "arity"    => 1,
231   "comment"  => "construct Shl: Shl(a, const) = a << const"
232 },
233
234 "Shr" => {
235   "arity"    => 2,
236   "comment"  => "construct Shr: Shr(a, b) = a >> b"
237 },
238
239 "Shr_i" => {
240   "arity"    => 1,
241   "comment"  => "construct Shr: Shr(a, const) = a >> const"
242 },
243
244 "Shrs" => {
245   "arity"    => 2,
246   "comment"  => "construct Shrs: Shrs(a, b) = a >> b"
247 },
248
249 "Shrs_i" => {
250   "arity"    => 1,
251   "comment"  => "construct Shrs: Shrs(a, const) = a >> const"
252 },
253
254 "Rot" => {
255   "arity"    => 2,
256   "comment"  => "construct Rot: Rot(a, b) = a ROT b"
257 },
258
259 "Rot_i" => {
260   "arity"    => 1,
261   "comment"  => "construct Rot: Rot(a, const) = a ROT const"
262 },
263
264 "Minus" => {
265   "arity"    => 1,
266   "comment"  => "construct Minus: Minus(a) = -a"
267 },
268
269 "Inc" => {
270   "arity"    => 1,
271   "comment"  => "construct Increment: Inc(a) = a++"
272 },
273
274 "Dec" => {
275   "arity"    => 1,
276   "comment"  => "construct Decrement: Dec(a) = a--"
277 },
278
279 "Abs" => {
280   "arity"    => 1,
281   "comment"  => "construct Abs: Abs(a) = |a|"
282 },
283
284 "Not" => {
285   "arity"    => 1,
286   "comment"  => "construct Not: Not(a) = !a"
287 },
288
289 # other operations
290
291 "Conv" => {
292   "arity"    => 1,
293   "comment"  => "construct Conv: Conv(a) = (conv)a"
294 },
295
296 "Cmp" => {
297   "op_flags" => "C",
298   "arity"    => 2,
299   "comment"  => "construct Cmp: Cmp(a, b) = a CMP b"
300 },
301
302 "Cmp_i" => {
303   "arity"    => 1,
304   "comment"  => "construct Cmp: Cmp(a, const) = Cmp(const, a) = a CMP const"
305 },
306
307 # Load / Store
308
309 "Load" => {
310   "arity"    => 2,
311   "comment"  => "construct Load: Load(mem-edge, ptr) = LD ptr"
312 },
313
314 "Store" => {
315   "arity"    => 3,
316   "comment"  => "construct Store: Store(mem-edge, ptr, val) = ST ptr,val"
317 },
318
319 "Lea" => {
320   "arity"    => 2,
321   "comment"  => "construct Lea: Lea(a,b) = lea offs(a,b,const) | res = a + b * const + offs with const = 0,1,2,4,8"
322 },
323
324 "Lea_i" => {
325   "arity"    => 1,
326   "comment"  => "construct Lea: Lea(a) = lea offs(a) | res = a + offs"
327 },
328
329 # Call
330
331 "Call" => {
332   "arity"    => 1,
333   "comment"  => "construct Call: Call(...)",
334   "args"     => [ { "type" => "ir_node *", "name" => "old_call" } ],
335   "rd_constructor" =>
336 "  ir_node *res;
337   ir_node *in[1];
338   asmop_attr *attr;
339
340   if (!op_ia32_Call) assert(0);
341
342   in[0] = get_Call_mem(old_call);
343
344   res = new_ir_node(db, irg, block, op_ia32_Call, mode_T, 1, in);
345   res = optimize_node(res);
346   irn_vrfy_irg(res, irg);
347
348   attr = (asmop_attr *)get_irn_generic_attr(res);
349   attr->data.old_ir = old_call;
350
351   return res;
352 "
353 }
354
355 ); # end of %nodes