-1

I am trying to see if Yosys fits my requirements or no. What i want to do is to find an operation in Verilog code (e.g. temp = 16*val1 + 8*val2 ) and replace this with another op like ( temp = val1 << 4 + val2 << 3 ).

Which parts i need to learn & use from Yosys? if anyone knows the set of command to use, can he/she please let me know to boost my learning curve ?

Thanks.

Amin
  • 1
  • 1

1 Answers1

0

For example consider the following verilog input (test.v):

module test(input [7:0] val1, val2, output [7:0] temp);
  assign temp = 16*val1 + 8*val2;
endmodule

The command yosys -p 'prep; opt -full; show' test.v will produce the following circuit diagram:

enter image description here

And the output written to the console contains this:

3.1. Executing OPT_EXPR pass (perform const folding).
Replacing multiply-by-16 cell `$mul$test.v:2$1' in module `\test' with shift-by-4.
Replacing multiply-by-8 cell `$mul$test.v:2$2' in module `\test' with shift-by-3.
Replacing $shl cell `$mul$test.v:2$1' (B=3'100, SHR=-4) in module `test' with fixed wiring: { \val1 [3:0] 4'0000 }
Replacing $shl cell `$mul$test.v:2$2' (B=2'11, SHR=-3) in module `test' with fixed wiring: { \val2 [4:0] 3'000 }

The two lines reading Replacing multiply-by-* cell are the transformation you mentioned. The two lines after that replace the constant shift operations with wiring, using {val1[3:0], 4'b0000} and {val2[4:0], 3'b000} as inputs for the adder.

This is done in the opt_expr pass. See passes/opt/opt_expr.cc for its source code to see how it's done.

CliffordVienna
  • 7,995
  • 1
  • 37
  • 57