0

I am trying to generate Gate Level Verilog initially from a function described in C/C++ language. My C function is a simple and gate:

_Bool and2gate(_Bool a, _Bool b)
{
   return a && b;
}

Using Bambu-Panda tool

http://panda.dei.polimi.it/

I managed to generate a Verilog description of this function:

    `ifdef __ICARUS__
  `define _SIM_HAVE_CLOG2
`endif
`ifdef VERILATOR
  `define _SIM_HAVE_CLOG2
`endif
`ifdef MODEL_TECH
  `define _SIM_HAVE_CLOG2
`endif
`ifdef VCS
  `define _SIM_HAVE_CLOG2
`endif
`ifdef NCVERILOG
  `define _SIM_HAVE_CLOG2
`endif
`ifdef XILINX_SIMULATOR
  `define _SIM_HAVE_CLOG2
`endif
`ifdef XILINX_ISIM
  `define _SIM_HAVE_CLOG2
`endif


`timescale 1ns / 1ps
module ui_bit_and_expr_FU(in1, in2, out1);
  parameter BITSIZE_in1=1, BITSIZE_in2=1, BITSIZE_out1=1;
  // IN
  input [BITSIZE_in1-1:0] in1;
  input [BITSIZE_in2-1:0] in2;
  // OUT
  output [BITSIZE_out1-1:0] out1;
  assign out1 = in1 & in2;
endmodule

// Datapath RTL descrition for and2gate

`timescale 1ns / 1ps
module datapath_and2gate(clock, reset, in_port_a, in_port_b, return_port);
  // IN
  input clock;
  input reset;
  input in_port_a;
  input in_port_b;
  // OUT
  output return_port;
  // Component and signal declarations
  wire [0:0] out_ui_bit_and_expr_FU_1_1_1_3_i0_fu_and2gate_21644_21668;

  ui_bit_and_expr_FU #(.BITSIZE_in1(1), .BITSIZE_in2(1), .BITSIZE_out1(1)) fu_and2gate_21644_21668 (.out1(out_ui_bit_and_expr_FU_1_1_1_3_i0_fu_and2gate_21644_21668), .in1(in_port_a), .in2(in_port_b));
  // io-signal post fix
  assign return_port = out_ui_bit_and_expr_FU_1_1_1_3_i0_fu_and2gate_21644_21668;

endmodule

// FSM based controller descrition for and2gate

`timescale 1ns / 1ps
module controller_and2gate(done_port, clock, reset, start_port);
  // IN
  input clock;
  input reset;
  input start_port;
  // OUT
  output done_port;
  parameter [0:0] S_0 = 1'd0;
  reg [0:0] _present_state, _next_state;
  reg done_port;

  always @(posedge clock)
    if (reset == 1'b0) _present_state <= S_0;
    else _present_state <= _next_state;

  always @(*)
  begin
    _next_state = S_0;
    done_port = 1'b0;
    case (_present_state)
      S_0 :
        if(start_port != 1'b1 )
        begin
          _next_state = S_0;
        end
        else
        begin
          _next_state = S_0;
          done_port = 1'b1;
        end
      default :
        begin
          done_port = 1'b0;
        end
    endcase
  end
endmodule

// Top component for and2gate

`timescale 1ns / 1ps
module and2gate(clock, reset, start_port, done_port, a, b, return_port);
  // IN
  input clock;
  input reset;
  input start_port;
  input a;
  input b;
  // OUT
  output done_port;
  output return_port;
  // Component and signal declarations

  controller_and2gate Controller_i (.done_port(done_port), .clock(clock),        
.reset(reset), .start_port(start_port));
  datapath_and2gate Datapath_i (.return_port(return_port), .clock(clock),     
.reset(reset), .in_port_a(a), .in_port_b(b));

endmodule

// Minimal interface for top component: and2gate

`timescale 1ns / 1ps
module and2gate_minimal_interface(clock, reset, start_port, a, b, done_port, return_port);
  // IN
  input clock;
  input reset;
  input start_port;
  input a;
  input b;
  // OUT
  output done_port;
  output return_port;
  // Component and signal declarations

  and2gate and2gate_i0 (.done_port(done_port), .return_port(return_port), .clock(clock), .reset(reset), .start_port(start_port), .a(a), .b(b));

endmodule

However, this in not a gate level verilog as I understand. What I would like to do is to create a SINGLE module netlist Verilog (Gate Level Verilog with a single module).

I understand that Yosys tool allows to create such Verilog. However, I could not reach the desired output. I would like an output in the following fomat format:

module top (input clk, // clock
            input rst, // reset
            input g_init, //for sequential circuits, initial value for                        
            registers from garbler. Only read in first clock cycle
input e_init, //same for evaluator
input g_input, // garbler's input
input e_input,//evaluator's input
output o // output
);

I'll appreciate very much an explanation on how to generate this kind of Gate Level code from the higher level verilog above, either using Yosys or some other synthesis and sim tool.

I will also appreciate any suggestions on how to generate Verilog from C code and which tools are recommended for such a task?

AlexP
  • 1
  • 3

1 Answers1

0

I have copied the verilog code you posted to a file (and2gate.v) and ran the following yosys command line:

yosys -p 'synth -flatten -top and2gate; clean -purge; write_verilog -noattr and2gate_syn.v' and2gate.v

This produces the following output file (and2gate_syn.v):

/* Generated by Yosys 0.6+337 (git sha1 81bdf0a, clang 3.8.0-2ubuntu4 -fPIC -Os) */

module and2gate(clock, reset, start_port, done_port, a, b, return_port);
  input a;
  input b;
  input clock;
  output done_port;
  input reset;
  output return_port;
  input start_port;
  assign return_port = b & a;
  assign done_port = start_port;
endmodule

See the output of yosys commands such as help synth and help write_verilog for descriptions of the individual commands used in that script.

Gate Level Verilog with a single module

Usually the term "gate level" is used for a design that has been mapped to a standard cell library. However, you have not provided a standard cell library to map to. I think the above solution is as close as one can get to a gate level design without actually mapping to a cell library.

CliffordVienna
  • 7,995
  • 1
  • 37
  • 57
  • CliffordVienna, Thank you for your answer. I tried. 'synth -flatten...' doesn't work for me - Err: unsupported option. I used 'synth_xilinx -flatten ...' instead. Is there any difference? – AlexP Nov 03 '16 at 12:37
  • @AlexP synth does generic synthesis, synth_xilinx does synthesis for Xilinx 7-Series FPGA. Support for "synth -flatten" has been added in April this year. Update to latest git head. – CliffordVienna Nov 03 '16 at 12:43