2019-04-30 04:25:15 -05:00
|
|
|
pattern muldiv
|
|
|
|
|
|
|
|
state <SigSpec> t x y
|
2020-08-04 09:30:24 -05:00
|
|
|
state <bool> is_signed
|
2019-04-30 04:25:15 -05:00
|
|
|
|
|
|
|
match mul
|
|
|
|
select mul->type == $mul
|
|
|
|
select GetSize(port(mul, \A)) + GetSize(port(mul, \B)) <= GetSize(port(mul, \Y))
|
|
|
|
endmatch
|
|
|
|
|
2020-08-04 09:30:24 -05:00
|
|
|
code t x y is_signed
|
2019-04-30 04:25:15 -05:00
|
|
|
t = port(mul, \Y);
|
|
|
|
x = port(mul, \A);
|
|
|
|
y = port(mul, \B);
|
2020-08-04 09:30:24 -05:00
|
|
|
is_signed = param(mul, \A_SIGNED).as_bool();
|
2019-04-30 04:25:15 -05:00
|
|
|
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
|
2020-08-04 09:30:24 -05:00
|
|
|
filter param(div, \A_SIGNED).as_bool() == is_signed
|
2019-04-30 04:25:15 -05:00
|
|
|
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);
|
2019-08-15 15:47:59 -05:00
|
|
|
accept;
|
2019-04-30 04:25:15 -05:00
|
|
|
endcode
|