ia32_spec.pl 76.7 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
	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);",
Michael Beck's avatar
Michael Beck committed
200
	SB0 => "${arch}_emit_8bit_source_register_or_immediate(node, 0);",
201
202
203
	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);",
Michael Beck's avatar
Michael Beck committed
204
	SH0 => "${arch}_emit_8bit_high_source_register(node, 0);",
205
206
	SS0 => "${arch}_emit_16bit_source_register_or_immediate(node, 0);",
	SI0 => "${arch}_emit_source_register_or_immediate(node, 0);",
207
	SI1 => "${arch}_emit_source_register_or_immediate(node, 1);",
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);",
211
	DS0 => "${arch}_emit_dest_register_size(node, 0);",
212
213
214
	DB0 => "${arch}_emit_8bit_dest_register(node, 0);",
	X0 => "${arch}_emit_x87_register(node, 0);",
	X1 => "${arch}_emit_x87_register(node, 1);",
215
	EX => "${arch}_emit_extend_suffix(node);",
216
217
218
219
220
	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
221
222
	unop3 => "${arch}_emit_unop(node, n_ia32_unary_op);",
	unop4 => "${arch}_emit_unop(node, n_ia32_binary_right);",
223
	binop => "${arch}_emit_binop(node);",
224
225
	x87_binop => "${arch}_emit_x87_binop(node);",
	CMP0  => "${arch}_emit_cmp_suffix_node(node, 0);",
Matthias Braun's avatar
Matthias Braun committed
226
	CMP3  => "${arch}_emit_cmp_suffix_node(node, 3);",
227
228
);

229
230
231
232
233
234
235
236
237
238
239
#--------------------------------------------------#
#                        _                         #
#                       (_)                        #
#  _ __   _____      __  _ _ __    ___  _ __  ___  #
# | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
# | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
# |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
#                                      | |         #
#                                      |_|         #
#--------------------------------------------------#

240
241
242
$default_op_attr_type = "ia32_op_attr_t";
$default_attr_type    = "ia32_attr_t";
$default_copy_attr    = "ia32_copy_attr";
243

244
245
246
247
sub ia32_custom_init_attr {
	my $node = shift;
	my $name = shift;
	my $res = "";
248

249
	if(defined($node->{modified_flags})) {
250
		$res .= "\tarch_irn_add_flags(res, arch_irn_flags_modify_flags);\n";
251
252
253
	}
	if(defined($node->{am})) {
		my $am = $node->{am};
Christoph Mallon's avatar
Christoph Mallon committed
254
		if($am eq "source,unary") {
255
			$res .= "\tset_ia32_am_support(res, ia32_am_unary);";
256
		} elsif($am eq "source,binary") {
257
			$res .= "\tset_ia32_am_support(res, ia32_am_binary);";
258
259
260
261
262
		} elsif($am eq "none") {
			# nothing to do
		} else {
			die("Invalid address mode '$am' specified on op $name");
		}
263
264
265
266
267
268
		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)");
			}
		}
269
270
271
272
273
	}
	return $res;
}
$custom_init_attr_func = \&ia32_custom_init_attr;

274
%init_attr = (
275
	ia32_asm_attr_t =>
276
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
277
		"\tinit_ia32_x87_attributes(res);".
278
		"\tinit_ia32_asm_attributes(res);",
Christoph Mallon's avatar
Christoph Mallon committed
279
280
	ia32_attr_t     =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);",
281
282
283
	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
284
	ia32_condcode_attr_t =>
285
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
Christoph Mallon's avatar
Christoph Mallon committed
286
		"\tinit_ia32_condcode_attributes(res, pnc);",
Michael Beck's avatar
Michael Beck committed
287
	ia32_copyb_attr_t =>
288
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
Michael Beck's avatar
Michael Beck committed
289
		"\tinit_ia32_copyb_attributes(res, size);",
Christoph Mallon's avatar
Christoph Mallon committed
290
	ia32_immediate_attr_t =>
291
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
292
		"\tinit_ia32_immediate_attributes(res, symconst, symconst_sign, no_pic_adjust, offset);",
Christoph Mallon's avatar
Christoph Mallon committed
293
294
295
	ia32_x87_attr_t =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
		"\tinit_ia32_x87_attributes(res);",
296
297
298
	ia32_climbframe_attr_t =>
		"\tinit_ia32_attributes(res, flags, in_reqs, out_reqs, exec_units, n_res);\n".
		"\tinit_ia32_climbframe_attributes(res, count);",
299
300
301
);

%compare_attr = (
302
	ia32_asm_attr_t       => "ia32_compare_asm_attr",
303
304
305
306
307
308
309
	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",
310
311
);

Michael Beck's avatar
Michael Beck committed
312
313
314
%operands = (
);

315
316
317
318
319
320
321
322
$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" ];
323

324
325
%nodes = (

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

337
338
339
340
Asm => {
	mode      => "mode_T",
	arity     => "variable",
	out_arity => "variable",
341
	attr_type => "ia32_asm_attr_t",
342
343
344
345
	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,
346
	modified_flags => $status_flags,
347
348
},

349
350
351
352
353
354
355
356
357
358
359
360
# "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
361
362
363
364
365
366
367
368
369
370
#-----------------------------------------------------------------#
#  _       _                                         _            #
# (_)     | |                                       | |           #
#  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
# | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
# | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
# |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
#                   __/ |                                         #
#                  |___/                                          #
#-----------------------------------------------------------------#
Christian Würdig's avatar
Christian Würdig committed
371

372
373
# commutative operations

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

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

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

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

427
428
429
430
431
432
433
434
435
436
437
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" ],
},

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

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

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

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

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

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

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

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

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

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

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

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

593
594
595
596
597
598
599
600
601
602
603
604
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
},

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

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

629
630
# not commutative operations

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

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

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

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

684
685
686
687
688
689
690
691
692
693
694
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
},

695
696
l_Sub => {
	reg_req   => { in => [ "none", "none" ], out => [ "none" ] },
697
	ins       => [ "minuend", "subtrahend" ],
698
699
700
701
},

l_Sbb => {
	reg_req   => { in => [ "none", "none", "none" ], out => [ "none" ] },
702
	ins       => [ "minuend", "subtrahend", "eflags" ],
703
704
},

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

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

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

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

758
l_ShlDep => {
759
760
761
	cmp_attr => "return 1;",
	ins      => [ "val", "count", "dep" ],
	arity    => 3
762
763
},

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

777
l_ShlD => {
778
	cmp_attr  => "return 1;",
779
	ins       => [ "val_high", "val_low", "count" ],
780
	arity     => 3,
781
782
},

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

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

808
l_ShrDep => {
809
	cmp_attr  => "return 1;",
810
	ins       => [ "val", "count", "dep" ],
811
	arity     => 3
812
813
},

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

827
l_ShrD => {
828
	cmp_attr  => "return 1;",
829
	arity     => 3,
830
	ins       => [ "val_high", "val_low", "count" ],
831
832
},

833
Sar => {
834
	irn_flags => "R",
835
836
	reg_req   => { in => [ "gp", "ecx" ],
	               out => [ "in_r1 !in_r2", "flags" ] },
837
	ins       => [ "val", "count" ],
838
	outs      => [ "res", "flags" ],
839
	emit      => '. sar%M %SB1, %S0',