|
以下,是我改编的一段代码,其综合后生成的RTL结构相同。但是 ,按照书上的说法,if语句是指定了一个有优先级的编码逻辑,而case语句生成的逻辑是并行的,不具有优先级。那他们的RTL结构应该是有区别的。但是,在下面的代码中显示是一样的。
module sdata_if(clk,reset,x,s,y);
input clk;
input reset;
input [3:0] x;
input [1:0] s;
output y;
reg y;
always @(posedge clk) begin
if(!reset) begin
y <= 0;
end
else begin
if(s == 2'b00)y<=x[0];
else if(s == 2'b01)y<=x[1];
else if(s == 2'b10)y<=x[2];
else y<=x[3];
end
end
endmodule
module sdata_case(clk,reset,x,s,y);
input clk;
input reset;
input [3:0] x;
input [1:0] s;
output y;
reg y;
always @(posedge clk) begin
if(!reset) begin
y<=0;
end
else begin
case(s)
2'b00: y <= x[0];
2'b01: y <= x[1];
2'b10: y <= x[2];
2'b11: y <= x[3];
endcase
end
end
endmodule
这是为什么呢? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|