|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 steeven_lee 于 2017-3-11 18:41 编辑
写了几段代码做比较,vivado RTL电路图看 a?b:c 和if结果一样复杂一些,case语句生成的电路最简单。但是,然而,综合后的电路图居然都一样,都是LUT查表就没了,真值表都一样。那么,差别呢?差别哪去了?
另外,比较了一下:
如果用always @(posedge clk) 会用到FDRE,多浪费一点资源。
用always输出z必须是reg, 而a?b:c判断就不需要,生成的电路却一样,这点怎么解释?
- module MyTest(
- input clk,
- input [3:0] keys,
- output [3:0] leds
- );
-
- (* dont_touch="true" *) IfTest if_test(clk, keys[0],keys[3:2],leds[0]);
- // (* dont_touch="true" *) CaseTest case_test(clk, keys[0],keys[3:2],leds[1]);
- (* dont_touch="true" *) IfTest1 if_test1(clk, keys[1:00],keys[3:0],leds[2]);
- // (* dont_touch="true" *) CaseTest1 case_test1(clk, keys[1:0],keys[3:0],leds[3]);
- (* dont_touch="true" *) WireTest wire_test(clk, keys[1:00],keys[3:0],leds[1]);
- (* dont_touch="true" *) WireTest1 wire_test1(clk, keys[1:00],keys[3:0],leds[3]);
- endmodule
- module IfTest(input clk, input x, input [1:0] y, output reg z);
- //always @(posedge clk) begin
- always @(*) begin
- if (x == 0)
- z <= y[0];
- else
- z <= y[1];
- end
- endmodule
- module CaseTest(input clk, input x, input [1:0] y, output reg z);
- //always @(posedge clk) begin
- always @(*) begin
- case (x)
- 0: z <= y[0];
- 1: z <= y[1];
- endcase
- end
- endmodule
- module IfTest1(input clk, input [1:0] x, input [3:0] y, output reg z);
- //always @(posedge clk) begin
- always @(*) begin
- if (x == 0)
- z <= y[0];
- else if (x==1)
- z <= y[1];
- else if (x==2)
- z <= y[2];
- else
- z <= y[3];
- end
- endmodule
- module CaseTest1(input clk, input [1:0] x, input [3:0] y, output reg z);
- //always @(posedge clk) begin
- always @(*) begin
- case (x)
- 0: z <= y[0];
- 1: z <= y[1];
- 2: z <= y[2];
- 3: z <= y[3];
- endcase
- end
- endmodule
- module WireTest(input clk, input [1:0] x, input [3:0] y, output z);
- assign z = x==0? y[0]: y[1];
- endmodule
- module WireTest1(input clk, input [1:0] x, input [3:0] y, output z);
- assign z = x==0? y[0]: (x==1? y[1]: (x==2? y[2]: y[3]));
- endmodule
复制代码
因为 a?b:c电路和if完全一致,图省掉。
综合后的电路图,没用时钟:
综合后的电路图,使用时钟:
综合前电路图,没用时钟。看着很复杂,综合后居然一样:
综合前电路图,用时钟:
|
|