Skip to content

How can I invert the output D bitwise in Verilog without modifying the original source file, and then output a new Verilog file #5147

Closed Answered by KrystalDelusion
yujning asked this question in Q&A
Discussion options

You must be logged in to vote

Provided the output you want to invert is connected to a wire (and not being directly driven as the output of a cell), you can do something like
in.v

module top(input [3:0] a, b, output [3:0] d);
	wire [3:0] d_temp;
	some_mod some_inst(.x(a), .y(b), .z(d));
	assign d = d_temp;
endmodule

yosys -p 'read_verilog in.v; insbuf -buf $_NOT_ A Y w:d; write_verilog -noattr out.v'
and get
out.v

/* Generated by Yosys 0.51+125 (git sha1 98d4355b8, ccache clang++ 18.1.8 -fPIC -O3) */

module top(a, b, d);
  input [3:0] a;
  wire [3:0] a;
  input [3:0] b;
  wire [3:0] b;
  output [3:0] d;
  wire [3:0] d;
  wire [3:0] d_temp;
  assign d[0] = ~d_temp[0];
  assign d[1] = ~d_temp[1];
  assign d[2] = ~d_tem…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yujning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants