| ??? 10/17/07 21:30 Read: times Msg Score: +1 +1 Informative |
#145864 - ***** Interesting result! ****** Responding to: ???'s previous message |
I just ran a test with the Xilinx XST synthesizer. Given the following code: module casetest (
input [7:0] indata,
output reg [1:0] outdata);
always @(indata) begin
casex (indata)
8'b0xxxxxx1 : outdata = 2'b01;
8'b1xxxxxx0 : outdata = 2'b10;
8'b1xxxxxx1 : outdata = 2'b11;
default : outdata = 2'bxx;
endcase // case (indata)
end // always @ (indata)
endmodule // casetestLooking at the RTL schematic, XST reduced all of this to two simple sum-of-products equations:outdata[0] = ( indata[0] & !indata[7]) + (indata[0] & indata[7]) outdata[1] = (!indata[0] & indata[7]) + (indata[0] & indata[7])Not exactly a direct assignment of in[7] to out[1] and in[0] to out[0], but quite simple. But look at the "technology" schematic: a direct assignment, as Russ and others had hoped for! In either case, if one changes the default assignment to outdata = 2'b00, the result is the same. Now, an even more interesting result. In the above patterns, change all of the x bit positions to 0. The result is the same: the simple bit-7 to bit-1 and bit-0 to bit-0 assignment, exactly what Russ was hoping for. Change those bit positions from x to 1 instead of 0, and again you get the same optimal result. Next test: leave those 1s or 0s in the don't-care positions, and change from casex to case. Result? Again, the optimal answer, the simple one-to-one assignment. Hmmm! Now if one looks at Russ' original example: always @(in) begin
case (in)
8'b00110001 : out = 2'b01;
8'b10101100 : out = 2'b10;
8'b11110101 : out = 2'b11;
default : out = 2'bxx;
endcase // case (in)
end // always @ (in)This results in more-complex logic involving four LUTs. Why? Because the case patterns do not differ only in the two bits. I've highlighted the differences that break the simple one-to-one result.
Anyways: I found this to be extremely enlightening and I certainly learned something. I still won't code this way but it's good to know that the synthesis tool sometimes will really do what you want it to do. -a |



