summaryrefslogtreecommitdiff
path: root/passes/pmgen/peepopt_muldiv.pmg
blob: 06c275834e5f1282fa2005619c8d4818640faaa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pattern muldiv

state <SigSpec> t x y

match mul
	select mul->type == $mul
	select GetSize(port(mul, \A)) + GetSize(port(mul, \B)) <= GetSize(port(mul, \Y))
endmatch

code t x y
	t = port(mul, \Y);
	x = port(mul, \A);
	y = port(mul, \B);
	branch;
	std::swap(x, y);
endcode

match div
	select div->type.in($div)
	index <SigSpec> port(div, \A) === t
	index <SigSpec> port(div, \B) === x
endmatch

code
	SigSpec div_y = port(div, \Y);
	SigSpec val_y = y;

	if (GetSize(div_y) != GetSize(val_y))
		val_y.extend_u0(GetSize(div_y), param(div, \A_SIGNED).as_bool());

	did_something = true;
	log("muldiv pattern in %s: mul=%s, div=%s\n", log_id(module), log_id(mul), log_id(div));
	module->connect(div_y, val_y);
	autoremove(div);
	reject;
endcode