Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] is it better to use full case than the casex statement ?

Status
Not open for further replies.

blooz

Advanced Member level 2
Joined
Dec 29, 2010
Messages
560
Helped
121
Reputation
242
Reaction score
116
Trophy points
1,343
Location
India
Activity points
4,985
I am Designing a Instruction decoder 12 bit to 15 bit ..using case statement total 4096 statements .Earlier I used casex so that only few statements need to written .Will it be good to do with case

earlier the code was like this

casex(op)

35 cases

default case


now code changed to

case(op)
all 4096 cases


///Will there be any priority issues related to this approach
 

you can use default statement for the bit patterns you don't care.
Code:
case(in)
   12'h000: out = <some value1>
   12'h001: out = <some value2>
   12'h002: out = <some value3>
   default   : out = < I don't care in this case so let's put whatever value here>
endcase
 
Last edited:

you can use default statement for the bit patterns you don't care.
Code:
case(in)
   12'h000: out = <some value1>
   12'h001: out = <some value2>
   12'h002: out = <some value3>
   default   : out = < I don't care in this case so let's put whatever value here>
endcase
particular case
is

always @(inst) begin
casex (inst) // synopsys parallel_case
// *** Byte-Oriented File Register Operations
//
// A A ALU W F Z C B T O
// L L O W W W W D R P
// U U P E E E E P I T
// A B O S
// L
12'b0000_0000_0000: decodes = 15'b00_00_0000_0_0_0_0_0_0_0; // NOP
// 12'b0000_001X_XXXX: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF this expression has real 32 cases ....which expands as follows
/*12'b000000100000: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(0)
12'b000000100001: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(1)
12'b000000100010: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(2)
12'b000000100011: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(3)
12'b000000100100: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(4)
12'b000000100101: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(5)
12'b000000100110: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(6)
12'b000000100111: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(7)
12'b000000101000: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(8)
12'b000000101001: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(9)
12'b000000101010: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(10)
12'b000000101011: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(11)
12'b000000101100: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(12)
12'b000000101101: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(13)
12'b000000101110: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(14)
12'b000000101111: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(15)
12'b000000110000: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(16)
12'b000000110001: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(17)
12'b000000110010: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(18)
12'b000000110011: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(19)
12'b000000110100: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(20)
12'b000000110101: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(21)
12'b000000110110: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(22)
12'b000000110111: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(23)
12'b000000111000: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(24)
12'b000000111001: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(25)
12'b000000111010: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(26)
12'b000000111011: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(27)
12'b000000111100: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(28)
12'b000000111101: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(29)
12'b000000111110: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(30)
12'b000000111111: decodes = 15'b00_00_0010_0_1_0_0_0_0_0; // MOVWF(31)

so ....what will be a better strategy ? fully specifying the cases or just go with casex ....I have gone through sunburst design paper cliff cummings and it seems the casex has got some trouble ...synthesis stage
 

so ....what will be a better strategy ? fully specifying the cases or just go with casex ....I have gone through sunburst design paper cliff cummings and it seems the casex has got some trouble ...synthesis stage

Hi blooz,

What I got from that paper is (short version):
- no full_case parallel_case directives, unless you really need it.
- no casex. ever.
- for case statements with don't-cares, use a casez statement, with a ? for the don't-cares.
- always include a default statement, even when all cases have been specified. This goes for both case and casez.

I've been sticking with that plan, and so far everything works out fine during simulation & synthesis. Below is an example of working code with a casez statement that uses ? for the don't-cares.

Code:
module bubble8_to_bin3 (
    input            clk,
    input      [7:0] bubble_count_in,
    output reg [2:0] bin_count_out
    );

initial begin
    bin_count_out = 0;
end

always @(posedge clk) begin
    casez(bubble_count_in)
      // Decode RIGHT running counter
      8'b1?000000: bin_count_out <= 3'b000;
      8'b01?00000: bin_count_out <= 3'b001;
      8'b001?0000: bin_count_out <= 3'b010;
      8'b0001?000: bin_count_out <= 3'b011;
      8'b00001?00: bin_count_out <= 3'b100;
      8'b000001?0: bin_count_out <= 3'b101;
      8'b0000001?: bin_count_out <= 3'b110;
      8'b?0000001: bin_count_out <= 3'b111;
      default    : bin_count_out <= 3'b000;
    endcase // bubble_count_in
end

endmodule // bubble8_to_bin3

So to answer your question... you probably want to use casez with ? for the don't-cares, similar to the above module.
 
  • Like
Reactions: blooz

    blooz

    Points: 2
    Helpful Answer Positive Rating
so the change needed is casex() to casez and replacing 'x' with '?'.

---------- Post added at 13:05 ---------- Previous post was at 12:58 ----------

so the change needed is casex() to casez and replacing 'x' with '?'.
 

so the change needed is casex() to casez and replacing 'x' with '?.

Yes. And making sure that you have a sensible default statement.

Oh yeah, and it also can't hurt to check the synthesis report to see what it actually synthesizes based on your case statement...
 
  • Like
Reactions: blooz

    blooz

    Points: 2
    Helpful Answer Positive Rating
As long as the synthesizer can recognize the casex statement, it is fine to use. Casex will be expended to normal cases in your any way.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top