Как создать Verilog уровня ворот из Verilog более высокого уровня с помощью yosys

Сначала я пытаюсь сгенерировать Verilog уровня шлюза из функции, описанной на языке C / C ++. Моя функция C - простая и гейт:

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

Использование инструмента Bambu-Panda

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

Мне удалось создать Verilog-описание этой функции:

    `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
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
);
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
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
);
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
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
);
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

Однако, насколько я понимаю, это не верилог уровня ворот. Что я хотел бы сделать, так это создать ОДИН модуль netlist Verilog (Verilog уровня шлюза с одним модулем).

Я так понимаю, что инструмент Yosys позволяет создать такой Verilog. Однако я не смог достичь желаемого результата. Я хотел бы получить результат в следующем формате fomat:

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
);

Я буду очень признателен за объяснение того, как сгенерировать этот вид кода уровня шлюза из вышеупомянутого verilog более высокого уровня, используя Yosys или какой-либо другой инструмент синтеза и симуляции.

Я также буду признателен за любые предложения о том, как сгенерировать Verilog из кода C и какие инструменты рекомендуются для такой задачи?


person AlexP    schedule 01.11.2016    source источник


Ответы (1)


Я скопировал опубликованный вами код verilog в файл (and2gate.v) и запустил следующую командную строку yosys:

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

Это дает следующий выходной файл (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

См. Вывод команд yosys, таких как help synth и help write_verilog, для описания отдельных команд, используемых в этом сценарии.

Gate Level Verilog с одним модулем

Обычно термин «уровень ворот» используется для проекта, который был сопоставлен со стандартной библиотекой ячеек. Однако вы не предоставили стандартную библиотеку ячеек для сопоставления. Я думаю, что приведенное выше решение максимально близко к дизайну уровня ворот без фактического сопоставления с библиотекой ячеек.

person CliffordVienna    schedule 01.11.2016
comment
CliffordVienna, Спасибо за ответ. Я пытался. 'synth -flatten ...' у меня не работает - Err: неподдерживаемая опция. Вместо этого я использовал "synth_xilinx -flatten ...". Есть ли разница? - person AlexP; 03.11.2016
comment
@AlexP synth выполняет общий синтез, synth_xilinx выполняет синтез для Xilinx 7-Series FPGA. Поддержка synth -flatten была добавлена ​​в апреле этого года. Обновите git head до последней версии. - person CliffordVienna; 03.11.2016