ia32_spec.pl 73.5 KB
Newer Older
1
2
3
4
# Creation: 2005/10/19
# $Id$
# This is the specification for the ia32 assembler Firm-operations

Andreas Schösser's avatar
Andreas Schösser committed
5
6
use File::Basename;

7
$new_emit_syntax = 1;
Andreas Schösser's avatar
Andreas Schösser committed
8
my $myname = $0;
9

10
11
12
13
14
15
16
17
18
# the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
$arch = "ia32";

# The node description is done as a perl hash initializer with the
# following structure:
#
# %nodes = (
#
# <op-name> => {
19
#   op_flags  => "N|L|C|X|I|F|Y|H|c|K",
20
#   irn_flags => "R|N"
21
22
23
24
25
#   arity     => "0|1|2|3 ... |variable|dynamic|any",
#   state     => "floats|pinned|mem_pinned|exc_pinned",
#   args      => [
#                    { type => "type 1", name => "name 1" },
#                    { type => "type 2", name => "name 2" },
26
27
#                    ...
#                  ],
28
29
30
#   comment   => "any comment for constructor",
#   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
#   cmp_attr  => "c source code for comparing node attributes",
31
32
33
#   outs      => { "out1", "out2" } # optional, creates pn_op_out1, ... consts
#   ins       => { "in1", "in2" }   # optional, creates n_op_in1, ... consts
#   mode      => "mode_Iu"          # optional, predefines the mode
34
#   emit      => "emit code with templates",
Moritz Kroll's avatar
Moritz Kroll committed
35
#   attr      => "additional attribute arguments for constructor",
36
37
38
39
#   init_attr => "emit attribute initialization template",
#   rd_constructor => "c source code which constructs an ir_node",
#   hash_func => "name of the hash function for this operation",
#   latency   => "latency of this operation (can be float)"
Michael Beck's avatar
Michael Beck committed
40
#   attr_type => "name of the attribute struct",
41
#   modified_flags =>  [ "CF", ... ] # optional, list of modified flags
42
43
44
45
46
47
# },
#
# ... # (all nodes you need to describe)
#
# ); # close the %nodes initializer

48
# op_flags: flags for the operation, OPTIONAL (default is "N")
49
50
51
52
53
54
55
56
57
58
# the op_flags correspond to the firm irop_flags:
#   N   irop_flag_none
#   L   irop_flag_labeled
#   C   irop_flag_commutative
#   X   irop_flag_cfopcode
#   I   irop_flag_ip_cfopcode
#   F   irop_flag_fragile
#   Y   irop_flag_forking
#   H   irop_flag_highlevel
#   c   irop_flag_constlike
Michael Beck's avatar
Michael Beck committed
59
#   K   irop_flag_keep
60
61
#   NB  irop_flag_dump_noblock
#   NI  irop_flag_dump_noinput
62
#
63
64
65
66
# irn_flags: special node flags, OPTIONAL (default is 0)
# following irn_flags are supported:
#   R   rematerializeable
#   N   not spillable
Christian Würdig's avatar
Christian Würdig committed
67
#
Christian Würdig's avatar
Christian Würdig committed
68
# state: state of the operation, OPTIONAL (default is "floats")
Christian Würdig's avatar
Christian Würdig committed
69
70
71
72
#
# arity: arity of the operation, MUST NOT BE OMITTED
#
# args:  the OPTIONAL arguments of the node constructor (debug, irg and block
73
74
#        are always the first 3 arguments and are always autmatically
#        created)
Christian Würdig's avatar
Christian Würdig committed
75
#        If this key is missing the following arguments will be created:
76
77
#        for i = 1 .. arity: ir_node *op_i
#        ir_mode *mode
Christian Würdig's avatar
Christian Würdig committed
78
#
Michael Beck's avatar
Michael Beck committed
79
80
# outs:  if a node defines more than one output, the names of the projections
#        nodes having outs having automatically the mode mode_T
81
#        example: [ "frame", "stack", "M" ]
Michael Beck's avatar
Michael Beck committed
82
#
Christian Würdig's avatar
Christian Würdig committed
83
84
# comment: OPTIONAL comment for the node constructor
#
85
86
87
88
89
# rd_constructor: for every operation there will be a
#      new_rd_<arch>_<op-name> function with the arguments from above
#      which creates the ir_node corresponding to the defined operation
#      you can either put the complete source code of this function here
#
Christian Würdig's avatar
Christian Würdig committed
90
91
#      This key is OPTIONAL. If omitted, the following constructor will
#      be created:
92
93
94
95
#      if (!op_<arch>_<op-name>) assert(0);
#      for i = 1 to arity
#         set in[i] = op_i
#      done
Christian Würdig's avatar
Christian Würdig committed
96
#      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
97
98
#      return res
#
Christian Würdig's avatar
Christian Würdig committed
99
# NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
Christian Würdig's avatar
Christian Würdig committed
100
#
101

Christian Würdig's avatar
Christian Würdig committed
102
103
# register types:
#   0 - no special type
104
105
#   1 - caller save (register must be saved by the caller of a function)
#   2 - callee save (register must be saved by the called function)
Christian Würdig's avatar
Christian Würdig committed
106
#   4 - ignore (do not assign this register)
107
108
#   8 - emitter can choose an arbitrary register of this class
#  16 - the register is a virtual one
109
#  32 - register represents a state
Christian Würdig's avatar
Christian Würdig committed
110
# NOTE: Last entry of each class is the largest Firm-Mode a register can hold
111
%reg_classes = (
112
113
114
	gp => [
		{ name => "edx", type => 1 },
		{ name => "ecx", type => 1 },
115
116
		{ name => "eax", type => 1 },
		{ name => "ebx", type => 2 },
117
118
119
120
121
122
123
		{ name => "esi", type => 2 },
		{ name => "edi", type => 2 },
		{ name => "ebp", type => 2 },
		{ name => "esp", type => 4 },
		{ name => "gp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
		{ name => "gp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
		{ mode => "mode_Iu" }
124
	],
125
126
127
128
129
130
131
132
133
	mmx => [
		{ name => "mm0", type => 4 },
		{ name => "mm1", type => 4 },
		{ name => "mm2", type => 4 },
		{ name => "mm3", type => 4 },
		{ name => "mm4", type => 4 },
		{ name => "mm5", type => 4 },
		{ name => "mm6", type => 4 },
		{ name => "mm7", type => 4 },
134
		{ mode => "mode_E", flags => "manual_ra" }
135
	],
136
137
138
139
140
141
142
143
144
145
146
	xmm => [
		{ name => "xmm0", type => 1 },
		{ name => "xmm1", type => 1 },
		{ name => "xmm2", type => 1 },
		{ name => "xmm3", type => 1 },
		{ name => "xmm4", type => 1 },
		{ name => "xmm5", type => 1 },
		{ name => "xmm6", type => 1 },
		{ name => "xmm7", type => 1 },
		{ name => "xmm_NOREG", type => 4 | 16 },     # we need a dummy register for NoReg nodes
		{ name => "xmm_UKNWN", type => 4 | 8 | 16},  # we need a dummy register for Unknown nodes
147
		{ mode => "mode_E" }
148
	],
149
	vfp => [
150
151
152
153
154
155
156
157
		{ name => "vf0", type => 1 },
		{ name => "vf1", type => 1 },
		{ name => "vf2", type => 1 },
		{ name => "vf3", type => 1 },
		{ name => "vf4", type => 1 },
		{ name => "vf5", type => 1 },
		{ name => "vf6", type => 1 },
		{ name => "vf7", type => 1 },
158
159
160
		{ name => "vfp_NOREG", type => 4 | 8 | 16 }, # we need a dummy register for NoReg nodes
		{ name => "vfp_UKNWN", type => 4 | 8 | 16 },  # we need a dummy register for Unknown nodes
		{ mode => "mode_E" }
161
	],
162
	st => [
163
164
165
166
167
168
169
170
		{ name => "st0", realname => "st",    type => 4 },
		{ name => "st1", realname => "st(1)", type => 4 },
		{ name => "st2", realname => "st(2)", type => 4 },
		{ name => "st3", realname => "st(3)", type => 4 },
		{ name => "st4", realname => "st(4)", type => 4 },
		{ name => "st5", realname => "st(5)", type => 4 },
		{ name => "st6", realname => "st(6)", type => 4 },
		{ name => "st7", realname => "st(7)", type => 4 },
171
		{ mode => "mode_E", flags => "manual_ra" }
172
	],
173
	fp_cw => [	# the floating point control word
174
175
		{ name => "fpcw", type => 4|32 },
		{ mode => "mode_fpcw", flags => "manual_ra|state" }
176
	],
177
	flags => [
178
179
		{ name => "eflags", type => 0 },
		{ mode => "mode_Iu", flags => "manual_ra" }
180
	],
181
182
); # %reg_classes

183
%cpu = (
184
185
186
187
	GP     => [ 1, "GP_EAX", "GP_EBX", "GP_ECX", "GP_EDX", "GP_ESI", "GP_EDI", "GP_EBP" ],
	SSE    => [ 1, "SSE_XMM0", "SSE_XMM1", "SSE_XMM2", "SSE_XMM3", "SSE_XMM4", "SSE_XMM5", "SSE_XMM6", "SSE_XMM7" ],
	VFP    => [ 1, "VFP_VF0", "VFP_VF1", "VFP_VF2", "VFP_VF3", "VFP_VF4", "VFP_VF5", "VFP_VF6", "VFP_VF7" ],
	BRANCH => [ 1, "BRANCH1", "BRANCH2" ],
188
189
); # %cpu

190
%vliw = (
191
192
	bundle_size       => 1,
	bundels_per_cycle => 1
193
194
); # vliw

195
%emit_templates = (
196
197
198
199
200
201
202
	S0 => "${arch}_emit_source_register(node, 0);",
	S1 => "${arch}_emit_source_register(node, 1);",
	S2 => "${arch}_emit_source_register(node, 2);",
	S3 => "${arch}_emit_source_register(node, 3);",
	SB1 => "${arch}_emit_8bit_source_register_or_immediate(node, 1);",
	SB2 => "${arch}_emit_8bit_source_register_or_immediate(node, 2);",
	SB3 => "${arch}_emit_8bit_source_register_or_immediate(node, 3);",
203
	SI1 => "${arch}_emit_source_register_or_immediate(node, 1);",
204
205
206
207
208
209
210
	SI3 => "${arch}_emit_source_register_or_immediate(node, 3);",
	D0 => "${arch}_emit_dest_register(node, 0);",
	D1 => "${arch}_emit_dest_register(node, 1);",
	DB0 => "${arch}_emit_8bit_dest_register(node, 0);",
	X0 => "${arch}_emit_x87_register(node, 0);",
	X1 => "${arch}_emit_x87_register(node, 1);",
	SE => "${arch}_emit_extend_suffix(get_ia32_ls_mode(node));",
211
	ME => "if(get_mode_size_bits(get_ia32_ls_mode(node)) != 32)\n
212
213
214
215
216
217
	           ia32_emit_mode_suffix(node);",
	M  => "${arch}_emit_mode_suffix(node);",
	XM => "${arch}_emit_x87_mode_suffix(node);",
	XXM => "${arch}_emit_xmm_mode_suffix(node);",
	XSD => "${arch}_emit_xmm_mode_suffix_s(node);",
	AM => "${arch}_emit_am(node);",
Christoph Mallon's avatar
Christoph Mallon committed
218
219
	unop3 => "${arch}_emit_unop(node, n_ia32_unary_op);",
	unop4 => "${arch}_emit_unop(node, n_ia32_binary_right);",
220
	binop => "${arch}_emit_binop(node);",
221
222
	x87_binop => "${arch}_emit_x87_binop(node);",
	CMP0  => "${arch}_emit_cmp_suffix_node(node, 0);",
Matthias Braun's avatar
Matthias Braun committed
223
	CMP3  => "${arch}_emit_cmp_suffix_node(node, 3);",
224
225
);

226
227
228
229
230
231
232
233
234
235
236
#--------------------------------------------------#
#                        _                         #
#                       (_)                        #
#  _ __   _____      __  _ _ __    ___  _ __  ___  #
# | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
# | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
# |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
#                                      | |         #
#                                      |_|         #
#--------------------------------------------------#

237
238
239
$default_op_attr_type = "ia32_op_attr_t";
$default_attr_type    = "ia32_attr_t";
$default_copy_attr    = "ia32_copy_attr";
240

241
242
243
244
sub ia32_custom_init_attr {
	my $node = shift;
	my $name = shift;
	my $res = "";
245

246
	if(defined($node->{modified_flags})) {
247
		$res .= "\tarch_irn_add_flags(res, arch_irn_flags_modify_flags);\n";
248
249
250
	}
	if(defined($node->{am})) {
		my $am = $node->{am};
Christoph Mallon's avatar
Christoph Mallon committed
251
		if($am eq "source,unary") {
252
			$res .= "\tset_ia32_am_support(res, ia32_am_unary);";
253
		} elsif($am eq "source,binary") {
254
			$res .= "\tset_ia32_am_support(res, ia32_am_binary);";
255
256
257
258
259
		} elsif($am eq "none") {
			# nothing to do
		} else {
			die("Invalid address mode '$am' specified on op $name");
		}
260
261
262
263
264
265
		if($am ne "none") {
			if($node->{state} ne "exc_pinned"
					and $node->{state} ne "pinned") {
				die("AM nodes must have pinned or AM pinned state ($name)");
			}
		}
266
267
268
269
270
	}
	return $res;
}
$custom_init_attr_func = \&ia32_custom_init_attr;

271
%init_attr = (
272
	ia32_asm_attr_t =>
273
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
274
		"\tinit_ia32_x87_attributes(res);".
275
		"\tinit_ia32_asm_attributes(res);",
Christoph Mallon's avatar
Christoph Mallon committed
276
277
	ia32_attr_t     =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);",
278
279
280
	ia32_call_attr_t =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
		"\tinit_ia32_call_attributes(res, pop, call_tp);",
Christoph Mallon's avatar
Christoph Mallon committed
281
	ia32_condcode_attr_t =>
282
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
Christoph Mallon's avatar
Christoph Mallon committed
283
		"\tinit_ia32_condcode_attributes(res, pnc);",
Michael Beck's avatar
Michael Beck committed
284
	ia32_copyb_attr_t =>
285
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
Michael Beck's avatar
Michael Beck committed
286
		"\tinit_ia32_copyb_attributes(res, size);",
Christoph Mallon's avatar
Christoph Mallon committed
287
	ia32_immediate_attr_t =>
288
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
Christoph Mallon's avatar
Christoph Mallon committed
289
290
291
292
		"\tinit_ia32_immediate_attributes(res, symconst, symconst_sign, offset);",
	ia32_x87_attr_t =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
		"\tinit_ia32_x87_attributes(res);",
293
294
295
	ia32_climbframe_attr_t =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
		"\tinit_ia32_climbframe_attributes(res, count);",
296
297
298
);

%compare_attr = (
299
	ia32_asm_attr_t       => "ia32_compare_asm_attr",
300
301
302
303
304
305
306
	ia32_attr_t            => "ia32_compare_nodes_attr",
	ia32_call_attr_t       => "ia32_compare_call_attr",
	ia32_condcode_attr_t   => "ia32_compare_condcode_attr",
	ia32_copyb_attr_t      => "ia32_compare_copyb_attr",
	ia32_immediate_attr_t  => "ia32_compare_immediate_attr",
	ia32_x87_attr_t        => "ia32_compare_x87_attr",
	ia32_climbframe_attr_t => "ia32_compare_climbframe_attr",
307
308
);

Michael Beck's avatar
Michael Beck committed
309
310
311
%operands = (
);

312
313
314
315
316
317
318
319
$mode_xmm           = "mode_E";
$mode_gp            = "mode_Iu";
$mode_flags         = "mode_Iu";
$mode_fpcw          = "mode_fpcw";
$status_flags       = [ "CF", "PF", "AF", "ZF", "SF", "OF" ];
$status_flags_wo_cf = [       "PF", "AF", "ZF", "SF", "OF" ];
$fpcw_flags         = [ "FP_IM", "FP_DM", "FP_ZM", "FP_OM", "FP_UM", "FP_PM",
                        "FP_PC0", "FP_PC1", "FP_RC0", "FP_RC1", "FP_X" ];
320

321
322
%nodes = (

323
324
325
Immediate => {
	state     => "pinned",
	op_flags  => "c",
326
	reg_req   => { out => [ "gp_NOREG:I" ] },
327
	attr      => "ir_entity *symconst, int symconst_sign, long offset",
328
	attr_type => "ia32_immediate_attr_t",
329
	hash_func => "ia32_hash_Immediate",
330
	latency   => 0,
331
332
	mode      => $mode_gp,
},
333

334
335
336
337
Asm => {
	mode      => "mode_T",
	arity     => "variable",
	out_arity => "variable",
338
	attr_type => "ia32_asm_attr_t",
339
340
341
342
	attr      => "ident *asm_text, const ia32_asm_reg_t *register_map",
	init_attr => "attr->asm_text = asm_text;\n".
	             "\tattr->register_map = register_map;\n",
	latency   => 10,
343
	modified_flags => $status_flags,
344
345
},

346
347
348
349
350
351
352
353
354
355
356
357
# "allocates" a free register
ProduceVal => {
	op_flags  => "c",
	irn_flags => "R",
	reg_req   => { out => [ "gp" ] },
	emit      => "",
	units     => [ ],
	latency   => 0,
	mode      => $mode_gp,
	cmp_attr  => "return 1;",
},

Christian Würdig's avatar
Christian Würdig committed
358
359
360
361
362
363
364
365
366
367
#-----------------------------------------------------------------#
#  _       _                                         _            #
# (_)     | |                                       | |           #
#  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
# | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
# | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
# |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
#                   __/ |                                         #
#                  |___/                                          #
#-----------------------------------------------------------------#
Christian Würdig's avatar
Christian Würdig committed
368

369
370
# commutative operations

371
Add => {
372
	irn_flags => "R",
373
	state     => "exc_pinned",
374
375
	reg_req   => { in  => [ "gp", "gp", "none", "gp", "gp" ],
	               out => [ "in_r4 in_r5", "flags", "none" ] },
376
	ins       => [ "base", "index", "mem", "left", "right" ],
377
	outs      => [ "res", "flags", "M" ],
378
	emit      => '. add%M %binop',
Christoph Mallon's avatar
Christoph Mallon committed
379
	am        => "source,binary",
380
	units     => [ "GP" ],
381
	latency   => 1,
382
383
	mode      => $mode_gp,
	modified_flags => $status_flags
384
385
},

386
387
AddMem => {
	irn_flags => "R",
388
	state     => "exc_pinned",
389
390
391
	reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => ". add%M %SI3, %AM",
392
	units     => [ "GP" ],
393
	latency   => 1,
394
395
396
397
	mode      => "mode_M",
	modified_flags => $status_flags
},

398
399
AddMem8Bit => {
	irn_flags => "R",
400
	state     => "exc_pinned",
401
402
403
404
	reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => ". add%M %SB3, %AM",
	units     => [ "GP" ],
405
	latency   => 1,
406
407
408
409
	mode      => "mode_M",
	modified_flags => $status_flags
},

410
Adc => {
411
	state     => "exc_pinned",
412
413
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "flags" ],
	               out => [ "in_r4 in_r5", "flags", "none" ] },
414
	ins       => [ "base", "index", "mem", "left", "right", "eflags" ],
415
	outs      => [ "res", "flags", "M" ],
416
	emit      => '. adc%M %binop',
Christoph Mallon's avatar
Christoph Mallon committed
417
	am        => "source,binary",
418
	units     => [ "GP" ],
419
	latency   => 1,
420
421
	mode      => $mode_gp,
	modified_flags => $status_flags
422
423
},

424
425
426
427
428
429
430
431
432
433
434
l_Add => {
	op_flags  => "C",
	reg_req   => { in => [ "none", "none" ], out => [ "none" ] },
	ins       => [ "left", "right" ],
},

l_Adc => {
	reg_req   => { in => [ "none", "none", "none" ], out => [ "none" ] },
	ins       => [ "left", "right", "eflags" ],
},

435
Mul => {
436
	# we should not rematrialize this node. It produces 2 results and has
Christoph Mallon's avatar
Christoph Mallon committed
437
	# very strict constraints
438
	state     => "exc_pinned",
439
	reg_req   => { in => [ "gp", "gp", "none", "eax", "gp" ],
440
	               out => [ "eax", "flags", "edx", "none" ] },
Christoph Mallon's avatar
Christoph Mallon committed
441
	ins       => [ "base", "index", "mem", "left", "right" ],
442
	emit      => '. mul%M %unop4',
443
	outs      => [ "res_low", "flags", "res_high", "M" ],
444
	am        => "source,binary",
445
446
	latency   => 10,
	units     => [ "GP" ],
447
	modified_flags => $status_flags
448
449
},

450
l_Mul => {
451
	# we should not rematrialize this node. It produces 2 results and has
Christoph Mallon's avatar
Christoph Mallon committed
452
	# very strict constraints
453
454
	op_flags  => "C",
	cmp_attr  => "return 1;",
455
	outs      => [ "EAX", "flags", "EDX", "M" ],
456
	arity     => 2
457
458
459
},

IMul => {
460
	irn_flags => "R",
461
	state     => "exc_pinned",
Matthias Braun's avatar
Matthias Braun committed
462
463
464
	# TODO: adjust out requirements for the 3 operand form
	# (no need for should_be_same then)
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
465
		           out => [ "in_r4 in_r5", "flags", "none" ] },
466
	ins       => [ "base", "index", "mem", "left", "right" ],
467
	outs      => [ "res", "flags", "M" ],
468
	am        => "source,binary",
469
470
	latency   => 5,
	units     => [ "GP" ],
471
472
	mode      => $mode_gp,
	modified_flags => $status_flags
473
474
475
},

IMul1OP => {
476
	irn_flags => "R",
477
	state     => "exc_pinned",
478
	reg_req   => { in => [ "gp", "gp", "none", "eax", "gp" ],
479
	               out => [ "eax", "flags", "edx", "none" ] },
Christoph Mallon's avatar
Christoph Mallon committed
480
	ins       => [ "base", "index", "mem", "left", "right" ],
481
	emit      => '. imul%M %unop4',
482
	outs      => [ "res_low", "flags", "res_high", "M" ],
483
	am        => "source,binary",
484
485
	latency   => 5,
	units     => [ "GP" ],
486
	modified_flags => $status_flags
487
488
489
},

l_IMul => {
490
491
	op_flags  => "C",
	cmp_attr  => "return 1;",
492
	outs      => [ "res_low", "res_high", "M" ],
493
	arity     => 2
494
495
496
},

And => {
497
	irn_flags => "R",
498
	state     => "exc_pinned",
499
500
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
		           out => [ "in_r4 in_r5", "flags", "none" ] },
501
	ins       => [ "base", "index", "mem", "left", "right" ],
502
	outs      => [ "res", "flags", "M" ],
503
	op_modes  => "commutative | am | immediate | mode_neutral",
Christoph Mallon's avatar
Christoph Mallon committed
504
	am        => "source,binary",
505
	emit      => '. and%M %binop',
506
	units     => [ "GP" ],
507
	latency   => 1,
508
509
	mode      => $mode_gp,
	modified_flags => $status_flags
510
511
},

512
513
AndMem => {
	irn_flags => "R",
514
	state     => "exc_pinned",
515
516
517
	reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. and%M %SI3, %AM',
518
	units     => [ "GP" ],
519
	latency   => 1,
520
521
522
523
	mode      => "mode_M",
	modified_flags => $status_flags
},

524
525
AndMem8Bit => {
	irn_flags => "R",
526
	state     => "exc_pinned",
527
528
529
530
	reg_req   => { in => [ "gp", "gp", "none",  "eax ebx ecx edx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. and%M %SB3, %AM',
	units     => [ "GP" ],
531
	latency   => 1,
532
533
534
535
	mode      => "mode_M",
	modified_flags => $status_flags
},

536
Or => {
537
	irn_flags => "R",
538
	state     => "exc_pinned",
539
540
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
	               out => [ "in_r4 in_r5", "flags", "none" ] },
541
	ins       => [ "base", "index", "mem", "left", "right" ],
542
	outs      => [ "res", "flags", "M" ],
Christoph Mallon's avatar
Christoph Mallon committed
543
	am        => "source,binary",
Matthias Braun's avatar
Matthias Braun committed
544
	emit      => '. or%M %binop',
545
	units     => [ "GP" ],
546
	latency   => 1,
547
548
	mode      => $mode_gp,
	modified_flags => $status_flags
549
550
},

551
552
OrMem => {
	irn_flags => "R",
553
	state     => "exc_pinned",
554
555
556
	reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. or%M %SI3, %AM',
557
	units     => [ "GP" ],
558
	latency   => 1,
559
560
561
562
	mode      => "mode_M",
	modified_flags => $status_flags
},

563
564
OrMem8Bit => {
	irn_flags => "R",
565
	state     => "exc_pinned",
566
567
568
569
	reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. or%M %SB3, %AM',
	units     => [ "GP" ],
570
	latency   => 1,
571
572
573
574
	mode      => "mode_M",
	modified_flags => $status_flags
},

575
Xor => {
576
	irn_flags => "R",
577
	state     => "exc_pinned",
578
579
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
	               out => [ "in_r4 in_r5", "flags", "none" ] },
580
	ins       => [ "base", "index", "mem", "left", "right" ],
581
	outs      => [ "res", "flags", "M" ],
Christoph Mallon's avatar
Christoph Mallon committed
582
	am        => "source,binary",
583
	emit      => '. xor%M %binop',
584
	units     => [ "GP" ],
585
	latency   => 1,
586
587
	mode      => $mode_gp,
	modified_flags => $status_flags
588
589
},

590
591
592
593
594
595
596
597
598
599
600
601
Xor0 => {
	op_flags  => "c",
	irn_flags => "R",
	reg_req   => { out => [ "gp", "flags" ] },
	outs      => [ "res", "flags" ],
	emit      => ". xor%M %D0, %D0",
	units     => [ "GP" ],
	latency   => 1,
	mode      => $mode_gp,
	modified_flags => $status_flags
},

602
603
XorMem => {
	irn_flags => "R",
604
	state     => "exc_pinned",
605
606
607
	reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. xor%M %SI3, %AM',
608
	units     => [ "GP" ],
609
	latency   => 1,
610
611
612
613
	mode      => "mode_M",
	modified_flags => $status_flags
},

614
615
XorMem8Bit => {
	irn_flags => "R",
616
	state     => "exc_pinned",
617
618
619
620
	reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "val" ],
	emit      => '. xor%M %SB3, %AM',
	units     => [ "GP" ],
621
	latency   => 1,
622
623
624
625
	mode      => "mode_M",
	modified_flags => $status_flags
},

626
627
# not commutative operations

628
Sub => {
629
	irn_flags => "R",
630
	state     => "exc_pinned",
631
632
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp" ],
	               out => [ "in_r4", "flags", "none" ] },
633
	ins       => [ "base", "index", "mem", "minuend", "subtrahend" ],
634
	outs      => [ "res", "flags", "M" ],
Christoph Mallon's avatar
Christoph Mallon committed
635
	am        => "source,binary",
636
	emit      => '. sub%M %binop',
637
	units     => [ "GP" ],
638
	latency   => 1,
639
640
	mode      => $mode_gp,
	modified_flags => $status_flags
641
642
},

643
644
SubMem => {
	irn_flags => "R",
645
	state     => "exc_pinned",
646
	reg_req   => { in => [ "gp", "gp", "none", "gp" ], out => [ "none" ] },
647
	ins       => [ "base", "index", "mem", "subtrahend" ],
648
	emit      => '. sub%M %SI3, %AM',
649
	units     => [ "GP" ],
650
	latency   => 1,
651
652
653
654
	mode      => 'mode_M',
	modified_flags => $status_flags
},

655
656
SubMem8Bit => {
	irn_flags => "R",
657
	state     => "exc_pinned",
658
	reg_req   => { in => [ "gp", "gp", "none", "eax ebx ecx edx" ], out => [ "none" ] },
659
	ins       => [ "base", "index", "mem", "subtrahend" ],
660
661
	emit      => '. sub%M %SB3, %AM',
	units     => [ "GP" ],
662
	latency   => 1,
663
664
665
666
	mode      => 'mode_M',
	modified_flags => $status_flags
},

667
Sbb => {
668
	state     => "exc_pinned",
669
670
	reg_req   => { in => [ "gp", "gp", "none", "gp", "gp", "flags" ],
	               out => [ "in_r4 !in_r5", "flags", "none" ] },
671
	ins       => [ "base", "index", "mem", "minuend", "subtrahend", "eflags" ],
672
	outs      => [ "res", "flags", "M" ],
Christoph Mallon's avatar
Christoph Mallon committed
673
	am        => "source,binary",
674
	emit      => '. sbb%M %binop',
675
	units     => [ "GP" ],
676
	latency   => 1,
677
678
	mode      => $mode_gp,
	modified_flags => $status_flags
679
680
},

681
682
683
684
685
686
687
688
689
690
691
Sbb0 => {
	irn_flags => "R",
	reg_req   => { in => [ "flags" ], out => [ "gp", "flags" ] },
	outs      => [ "res", "flags" ],
	emit      => ". sbb%M %D0, %D0",
	units     => [ "GP" ],
	latency   => 1,
	mode      => $mode_gp,
	modified_flags => $status_flags
},

692
693
l_Sub => {
	reg_req   => { in => [ "none", "none" ], out => [ "none" ] },
694
	ins       => [ "minuend", "subtrahend" ],
695
696
697
698
},

l_Sbb => {
	reg_req   => { in => [ "none", "none", "none" ], out => [ "none" ] },
699
	ins       => [ "minuend", "subtrahend", "eflags" ],
700
701
},

702
IDiv => {
703
704
	op_flags  => "F|L",
	state     => "exc_pinned",
705
	reg_req   => { in => [ "gp", "gp", "none", "gp", "eax", "edx" ],
706
	               out => [ "eax", "flags", "none", "edx", "none" ] },
707
	ins       => [ "base", "index", "mem", "divisor", "dividend_low", "dividend_high" ],
708
	outs      => [ "div_res", "flags", "M", "mod_res", "X_exc" ],
709
	am        => "source,unary",
710
	emit      => ". idiv%M %unop3",
711
712
	latency   => 25,
	units     => [ "GP" ],
713
	modified_flags => $status_flags
714
715
},

716
Div => {
717
718
	op_flags  => "F|L",
	state     => "exc_pinned",
719
	reg_req   => { in => [ "gp", "gp", "none", "gp", "eax", "edx" ],
720
	               out => [ "eax", "flags", "none", "edx", "none" ] },
721
	ins       => [ "base", "index", "mem", "divisor", "dividend_low", "dividend_high" ],
722
	outs      => [ "div_res", "flags", "M", "mod_res", "X_exc" ],
723
	am        => "source,unary",
724
	emit      => ". div%M %unop3",
725
726
	latency   => 25,
	units     => [ "GP" ],
727
	modified_flags => $status_flags
728
729
},

730
Shl => {
731
	irn_flags => "R",
732
733
734
735
	reg_req   => { in => [ "gp", "ecx" ],
	               out => [ "in_r1 !in_r2", "flags" ] },
	ins       => [ "val", "count" ],
	outs      => [ "res", "flags" ],
736
	emit      => '. shl%M %SB1, %S0',
737
	units     => [ "GP" ],
738
	latency   => 1,
739
740
	mode      => $mode_gp,
	modified_flags => $status_flags
741
742
},

743
744
ShlMem => {
	irn_flags => "R",
745
	state     => "exc_pinned",
746
747
748
	reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "count" ],
	emit      => '. shl%M %SB3, %AM',
749
	units     => [ "GP" ],
750
	latency   => 1,
751
752
753
754
	mode      => "mode_M",
	modified_flags => $status_flags
},

755
l_ShlDep => {
756
757
758
	cmp_attr => "return 1;",
	ins      => [ "val", "count", "dep" ],
	arity    => 3
759
760
},

761
ShlD => {
762
	irn_flags => "R",
763
764
765
766
	reg_req   => { in => [ "gp", "gp", "ecx" ],
	               out => [ "in_r1 !in_r2 !in_r3", "flags" ] },
	ins       => [ "val_high", "val_low", "count" ],
	outs      => [ "res", "flags" ],
767
	emit      => ". shld%M %SB2, %S1, %D0",
768
769
	latency   => 6,
	units     => [ "GP" ],
770
771
	mode      => $mode_gp,
	modified_flags => $status_flags
772
773
},

774
l_ShlD => {
775
	cmp_attr  => "return 1;",
776
	ins       => [ "val_high", "val_low", "count" ],
777
	arity     => 3,
778
779
},

780
Shr => {
781
	irn_flags => "R",
782
783
	reg_req   => { in => [ "gp", "ecx" ],
	               out => [ "in_r1 !in_r2", "flags" ] },
784
	ins       => [ "val", "count" ],
785
	outs      => [ "res", "flags" ],
786
	emit      => '. shr%M %SB1, %S0',
787
	units     => [ "GP" ],
788
	mode      => $mode_gp,
789
	latency   => 1,
790
	modified_flags => $status_flags
791
792
},

793
794
ShrMem => {
	irn_flags => "R",
795
	state     => "exc_pinned",
796
797
798
	reg_req   => { in => [ "gp", "gp", "none", "ecx" ], out => [ "none" ] },
	ins       => [ "base", "index", "mem", "count" ],
	emit      => '. shr%M %SB3, %AM',
799
800
	units     => [ "GP" ],
	mode      => "mode_M",
801
	latency   => 1,
802
803
804
	modified_flags => $status_flags
},

805
l_ShrDep => {
806
	cmp_attr  => "return 1;",
807
	ins       => [ "val", "count", "dep" ],
808
	arity     => 3
809
810
},

811
ShrD => {
812
	irn_flags => "R",
813
814
815
816
	reg_req   => { in => [ "gp", "gp", "ecx" ],
	               out => [ "in_r1 !in_r2 !in_r3", "flags" ] },
	ins       => [ "val_high", "val_low", "count" ],
	outs      => [ "res", "flags" ],
817
	emit      => ". shrd%M %SB2, %S1, %D0",
818
819
	latency   => 6,
	units     => [ "GP" ],
820
821
	mode      => $mode_gp,
	modified_flags => $status_flags
822
823
},

824
l_ShrD => {
825
	cmp_attr  => "return 1;",
826
	arity     => 3,
827
	ins       => [ "val_high", "val_low", "count" ],
828
829
},

830
Sar => {
831
	irn_flags => "R",
832
833
	reg_req   => { in => [ "gp", "ecx" ],
	               out => [ "in_r1 !in_r2", "flags" ] },
834
	ins       => [ "val", "count" ],
835
	outs      => [ "res", "flags" ],
836
	emit      => '. sar%M %SB1, %S0',
837
	units     => [ "GP" ],
838
	latency   => 1,
839
840
	mode      => $mode_gp,
	modified_flags => $status_flags
841
842
},

843
844
SarMem => {
	irn_flags => "