如何防止 USE 编译器优化我的数组?
How to prevent ISE compiler from optmizing away my array?
我是 Verilog、ISE、FPGA 的新手。我正在尝试将一个简单的设计实现到 FPGA 中,但整个设计都被优化掉了。它基本上是一个具有一些任意值的二维数组。这是代码:
module top(
output reg out
);
integer i;
integer j;
reg [5:0] array [0:99][0:31];
initial begin
for(i=0;i<100;i=i+1) begin
for(j=0;j<32;j=j+1) begin
array[i][j] = j;
out = array[i][j];
end
end
end
endmodule
它很好地通过了 XST 综合,但在实施过程中未能通过 MAP。给出了两个错误:
ERROR:Map:116 - The design is empty. No processing will be done.
ERROR:Map:52 - Problem encountered processing RPMs.
XST 正在优化整个代码。为什么?我做错了什么?
你的设计被综合掉的原因是你没有在你的模块中描述任何逻辑。
您设计中唯一的块是一个 initial
块,除少数情况外,它通常不用于综合;该构造主要用于模拟中的测试平台(运行 通过 ModelSim 或其他模拟器的 Verilog)。
你想要的是用always
块或者assign
语句来描述XST的逻辑,综合成网表供FPGA仿真。由于您提供的模块没有这两种构造,因此无法生成网表,因此无法合成!
在你的例子中,你想要描述什么逻辑并不完全清楚,因为你的模块的结果总是 out
等于 31。如果你想 out
循环值 0 到 31,您需要添加一些顺序逻辑来实现它。在网上搜索一些关于数字设计的教程,这样你就掌握了基础知识(组合逻辑、门、寄存器等)。然后,考虑您希望设计做什么并将其映射到那些组件。然后,编写描述该设计的 Verilog。
根据评论进行编辑:
您在报告中没有 LUT/FF 使用的原因是因为 FPGA 不需要使用任何资源(或这些资源的 none)来实现您的模块。由于 out
与常量 31 相关联,它的值始终为 1,因此 FPGA 只需将 out
与 Vdd 相关联(注意 out
不是 31,因为它只是一个 1 位寄存器)。其他数组值从不使用或访问,因此 FPGA 将它们合成掉(即,输出不需要知道 array[0][1]
的值,因为 out
是常数,设计中不存在其他端口) .为了保留数组,您只需使用它以某种方式驱动一些输出。这是向您展示的一个基本示例:
module top( input [6:0] i_in, // Used to index the array like i
input [4:0] j_in, // Used to index the array like j
output reg [5:0] out // Note, out is now big enough to store all the bits in array
);
integer i;
integer j;
reg [5:0] array[0:99][0:31];
always @(*) begin
// Set up the array, not necessarily optimal, but it works
for (i = 0; i < 100; i = i + 1) begin
for (j = 0; j < 32; j = j + 1) begin
array[i][j] = j;
end
end
// Assign the output to value in the array at position i_in, j_in
out = array[i_in][j_in];
end
endmodule
如果将输入 i_in
和 j_in
连接到开关或其他东西,将 out
连接到 6 个 LED,您应该能够使用开关索引数组并获得输出在 LED 上确认您的设计。
我是 Verilog、ISE、FPGA 的新手。我正在尝试将一个简单的设计实现到 FPGA 中,但整个设计都被优化掉了。它基本上是一个具有一些任意值的二维数组。这是代码:
module top(
output reg out
);
integer i;
integer j;
reg [5:0] array [0:99][0:31];
initial begin
for(i=0;i<100;i=i+1) begin
for(j=0;j<32;j=j+1) begin
array[i][j] = j;
out = array[i][j];
end
end
end
endmodule
它很好地通过了 XST 综合,但在实施过程中未能通过 MAP。给出了两个错误:
ERROR:Map:116 - The design is empty. No processing will be done.
ERROR:Map:52 - Problem encountered processing RPMs.
XST 正在优化整个代码。为什么?我做错了什么?
你的设计被综合掉的原因是你没有在你的模块中描述任何逻辑。
您设计中唯一的块是一个 initial
块,除少数情况外,它通常不用于综合;该构造主要用于模拟中的测试平台(运行 通过 ModelSim 或其他模拟器的 Verilog)。
你想要的是用always
块或者assign
语句来描述XST的逻辑,综合成网表供FPGA仿真。由于您提供的模块没有这两种构造,因此无法生成网表,因此无法合成!
在你的例子中,你想要描述什么逻辑并不完全清楚,因为你的模块的结果总是 out
等于 31。如果你想 out
循环值 0 到 31,您需要添加一些顺序逻辑来实现它。在网上搜索一些关于数字设计的教程,这样你就掌握了基础知识(组合逻辑、门、寄存器等)。然后,考虑您希望设计做什么并将其映射到那些组件。然后,编写描述该设计的 Verilog。
根据评论进行编辑:
您在报告中没有 LUT/FF 使用的原因是因为 FPGA 不需要使用任何资源(或这些资源的 none)来实现您的模块。由于 out
与常量 31 相关联,它的值始终为 1,因此 FPGA 只需将 out
与 Vdd 相关联(注意 out
不是 31,因为它只是一个 1 位寄存器)。其他数组值从不使用或访问,因此 FPGA 将它们合成掉(即,输出不需要知道 array[0][1]
的值,因为 out
是常数,设计中不存在其他端口) .为了保留数组,您只需使用它以某种方式驱动一些输出。这是向您展示的一个基本示例:
module top( input [6:0] i_in, // Used to index the array like i
input [4:0] j_in, // Used to index the array like j
output reg [5:0] out // Note, out is now big enough to store all the bits in array
);
integer i;
integer j;
reg [5:0] array[0:99][0:31];
always @(*) begin
// Set up the array, not necessarily optimal, but it works
for (i = 0; i < 100; i = i + 1) begin
for (j = 0; j < 32; j = j + 1) begin
array[i][j] = j;
end
end
// Assign the output to value in the array at position i_in, j_in
out = array[i_in][j_in];
end
endmodule
如果将输入 i_in
和 j_in
连接到开关或其他东西,将 out
连接到 6 个 LED,您应该能够使用开关索引数组并获得输出在 LED 上确认您的设计。