-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: Make switch statement optimized for one-hot encoded arguments #145
Comments
I’d suggest to enter the code like the following. It should be functionally equivalent but points out better the intent. (* parallel case *)
case(1) // synopsys parallel_case
((pc_state & `PcState_defautEncoding_Idle) == `PcState_defaultEncoding_Idle): begin Also this would allow the code to be used for other *hot encodings as well, e.g. two-hot. However, the |
@typingArtist SpinalHDL/core/src/main/scala/spinal/core/internals/ComponentEmitterVerilog.scala Line 540 in f238a44
The is isPure is calculated to be true if only literals are used in the SpinalHDL 'is' statements, as Verilog doesn't support case statements with non literal cases. So the generation of switch statement with only literal stuff is there SpinalHDL/core/src/main/scala/spinal/core/internals/ComponentEmitterVerilog.scala Line 565 in f238a44
@typingArtist and @tomverbeure
code into non synposys / parrallel cases capable tools ? is that still legal verilog ? |
I believe that's only true for full_case, but not for parallel_case. My rule of thumb is to never ever use full_case. It's too dangerous. For parallel_case, the simply rule of them is the one listed above: if you know for sure that the input is one-hot, then you're good, even if you don't cover all the options.
Tools that don't implement the Tom |
…L#145 This allows the special case of a binaryOneHot encoding to be encoded with best synthesis results
@typingArtist I suggest 2 fixed:
Tom |
ANDing everything together for isPure is easier to understand Scala. (* parallel case *) replaced by (* parallel_case *), and // synopsys parallel_case replaced by // synthesis parallel_case, for better tool compatibility.
Change coding style of Verilog to case(1) with parallel_case #145
Current code:
This generates the following verilog:
The regular compare operation is optimized for one-hot encoding, but the switch statement compares the full vector.
Ideally, it should generate something like this:
The
(* parallel case *)
is supported by some, but not all, synthesis tools. The same is true for// synopsys parallel_case
. So you need both. It's seriously annoying.parallel_case usage is usually highly discouraged, but one-hot encoded case statements are an exception. From the paper:
The text was updated successfully, but these errors were encountered: