# Adding a pass for Multiple Constant Multiplication (mcm)

**URL:** <https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165>\
**Category:** Developers\
**Created:** [September 9, 2026, 8:37am UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165 "2026-09-09T08:37:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hfthra](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hfthra](https://yosyshq.discourse.group/u/hfthra)\
**Post date:** [September 9, 2026, 8:37am UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/1 "2026-09-09T08:37:53Z")

</div>

I am creating a new pass for restructuring multiplication with constants into shifts with addition/subtraction. $mul operations with constants will be implemented as shifts, which results in a smaller mapped area than implementing generic multipliers.

This will be useful in cases such as FIR filters, FFT with constants, MAC operations with constant weights etc.

Will this be a useful addition to yosys?

---

<div class="post-metadata">

**Author:** ![hfthra](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hfthra](https://yosyshq.discourse.group/u/hfthra)\
**Post date:** [September 14, 2026, 12:49pm UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/2 "2026-09-14T12:49:04Z")

</div>

Made a PR for this as a separate pass called mcm under techmap

> <https://github.com/YosysHQ/yosys/pull/6202>
>
> Separate pass(mcm) for multiple constant multiplication operations. Replaces $mu…l cells that have a constant operand into a shared adder graph of shifts, additions and subtractions. 
> 
> It factors out coefficient shifts, greedily constructs a bounded depth A-operation graph for the remaining odd coefficients and reuses intermediate terms across outputs. The pass prunes unused nodes, sizes arithmetic to demanded output widths and a cost estimate to avoid unprofitable rewrites.
> 
> This could be useful in blocks such as filters with constant coefficients (FIR etc.) and MAC with constant weights etc.
> 
> Simple test file is included with the PR.

---

<div class="post-metadata">

**Author:** ![nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@nick](https://yosyshq.discourse.group/u/nick)\
**Post date:** [September 14, 2026, 3:52pm UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/3 "2026-09-14T15:52:07Z")

</div>

What are your specific use cases for an MCM pass?

Generally I think it’s probably helpful to have in the codebase. MCM is an NP-Hard problem and reduces to heuristic search, so I think it would be best if the implementation was as generic as possible over both it’s search algorithm and heuristic scoring measure.

---

<div class="post-metadata">

**Author:** ![hfthra](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hfthra](https://yosyshq.discourse.group/u/hfthra)\
**Post date:** [September 15, 2026, 7:47am UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/4 "2026-09-15T07:47:13Z")

</div>

Thanks for the comment.

I’ve been experimenting with DSP filters which have constant coefficients. And I have an idea to try with some designs that have constant weighted multipliers.

I agree with your idea about making it more generic. I will refactor it.

---

<div class="post-metadata">

**Author:** ![widlarizer](https://avatars.discourse-cdn.com/v4/letter/w/bbce88/32.png) [@widlarizer](https://yosyshq.discourse.group/u/widlarizer)\
**Post date:** [September 15, 2026, 8:07am UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/5 "2026-09-15T08:07:12Z")

</div>

Even in the problem of a single constant multiplication Yosys main doesn’t seem to be doing anything. I expect your pass to help with that too, but also I’d like to be able to clearly verify from the code that it behaves nicely from a runtime perspective on designs without multiple constant multiplications done on a single value. Single constant multiplication optimization _might or might not_ be best to rely on MCM code. Would be interested to hear more about the performance concerns of running your pass unconditionally if it’s heuristics applied to an NP-hard problem

---

<div class="post-metadata">

**Author:** ![nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@nick](https://yosyshq.discourse.group/u/nick)\
**Post date:** [September 15, 2026, 2:03pm UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/6 "2026-09-15T14:03:35Z")

</div>

> Single constant multiplication optimization _might or might not_ be best to rely on MCM code.

Agreed, SCM is only NP-Complete ([https://doi.org/10.1109/TASSP.1984.1164433](https://doi.org/10.1109/TASSP.1984.1164433)) and strictly easier than MCM. I would be interested in seeing the performance of the MCM implementation on an SCM problem vs a SAT solver.

---

<div class="post-metadata">

**Author:** ![hfthra](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hfthra](https://yosyshq.discourse.group/u/hfthra)\
**Post date:** [September 21, 2026, 12:31pm UTC](https://yosyshq.discourse.group/t/adding-a-pass-for-multiple-constant-multiplication-mcm/165/7 "2026-09-21T12:31:10Z")

</div>

Pushed the refactored code. I couldn’t benchmark the performance
