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.

Optimizing case statement with large input

Status
Not open for further replies.

stanford

Full Member level 2
Joined
Feb 16, 2014
Messages
132
Helped
4
Reputation
8
Reaction score
6
Trophy points
1,298
Activity points
2,223
Code:
case (input[9:0])
  0: ...
  1: ...
  2: ...
  ...
  1023: ..
  default: ...
endcase

Let's say that there is a 10 bit input and have 1024 possible case statements. If I were to write the case statements in such a way, input == 0 will have the highest priority, and so on.

1. If this the timing is critical for this and priority is not important, would using "unique case" tell the tool that priority is not required so that it can optimize the path further?
2. How does the hardware look like if there is no priority and have many possible drivers?

Thanks!!
 

Hi,

I assume you are talking about HDL.

Then you need to see that all the cases are processed at the same time = in parallel (in opposite to microcontroller code)
And you need to understand that only one "case" can be true.

Thus I see no "priority" at all.

Klaus
 

Hi,

I assume you are talking about HDL.

Then you need to see that all the cases are processed at the same time = in parallel (in opposite to microcontroller code)
And you need to understand that only one "case" can be true.

Thus I see no "priority" at all.

Klaus

Even then, if the cases are processed in parallel, the output needs to be driven based on some 'priority' when implemented with a tree of muxes right, so wouldn't it imply that there is priority?

For casez, there could be multiple cases that evaluate to true, so by default priority is given from top to bottom.
 

I think you are confusing priority with logic gate order.

In a fully decoded case statement, each input bit matters and has no priority over others. According to the logic gate order, bits have however different propagation delay which may matter. Gate order will be respectively optimized in timing driven synthesis.

Of course, it mostly matters for optimization what's inside the case statement.

Presently I don't see where the thread is targeting to.
 

I think you are confusing priority with logic gate order.

In a fully decoded case statement, each input bit matters and has no priority over others. According to the logic gate order, bits have however different propagation delay which may matter. Gate order will be respectively optimized in timing driven synthesis.

Of course, it mostly matters for optimization what's inside the case statement.

Presently I don't see where the thread is targeting to.

Maybe i dont understand how case statements get synthesized.

How is this realized in hardware?
Code:
case (input[1:0])
  0: ...
  1: ...
  2: ...
  3: ...
  default: ...
endcase

How will these two look different in hardware?
Code:
if (input[1:0] == 0)
  ...
else if (input[1:0] == 1)
  ...
else if (input[1:0] == 2)
  ...
else if (input[1:0] == 3)
  ...
else
  ...
endcase
 

Hi,

For casez, there could be multiple cases that evaluate to true, so by default priority is given from top to bottom
I don't understand with your example how multiple can be true the same time.
In my eyes it can be 1 or it can be 2 but it can't be 1 and 2 at the same time..
or any other numbers...

Klaus
 

Nothing has to be synthesized unless you fill up the case construct with actual statements.

Finally a logic expression for each output bit assigned in the case construct is established which will be optimized according to resource usage and timing requirements.
 

case statements in verilog are syntax sugar for the chained if-else statements. synthesis vendors either infer that one and only one case can be reached, or a pragma (fullcase/parallelcase) is used. SystemVerilog adds unique case to add simulation checks if multiple statements are reached.

when the synthesis tool can't assume multiple states can't be reached, it has to implement the logic like the chained if-else including any priority structure that this implies.
 

Maybe i dont understand how case statements get synthesized.

How is this realized in hardware?
Code:
case (input[1:0])
  0: ...
  1: ...
  2: ...
  3: ...
  default: ...
endcase

How will these two look different in hardware?
Code:
if (input[1:0] == 0)
  ...
else if (input[1:0] == 1)
  ...
else if (input[1:0] == 2)
  ...
else if (input[1:0] == 3)
  ...
else
  ...
endcase

These two examples will produce identical hardware. By default consider it a mux but as FvM points out the synthesizer will optimize further based on what's in the case/if statements.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top