Comments (6)
Hi @jijingg,
I think there is something quite close already via the spinal.lib.WhenBuilder :
import spinal.lib._
val conds = Bits(8 bits)
val result = UInt(8 bits)
val ctx = WhenBuilder()
ctx.when(conds(0)) {
result := 0
}
ctx.when(conds(1)) {
result := 1
}
if(true){
ctx.when(conds(2)) {
result := 2
}
}
ctx.when(conds(3)) {
result := 3
}
for(i <- 5 to 7) ctx.when(conds(i)) {
result := i
}
ctx.otherwise{
result := 255
}
=>
assign when_Utils_l1437 = conds[0];
always @(*) begin
if(when_Utils_l1437) begin
result = 8'h0;
end else begin
if(when_Utils_l1440) begin
result = 8'h01;
end else begin
if(when_Utils_l1440_1) begin
result = 8'h02;
end else begin
if(when_Utils_l1440_2) begin
result = 8'h03;
end else begin
if(when_Utils_l1440_3) begin
result = 8'h05;
end else begin
if(when_Utils_l1440_4) begin
result = 8'h06;
end else begin
if(when_Utils_l1440_5) begin
result = 8'h07;
end else begin
result = 8'hff;
end
end
end
end
end
end
end
end
assign when_Utils_l1440 = conds[1];
assign when_Utils_l1440_1 = conds[2];
assign when_Utils_l1440_2 = conds[3];
assign when_Utils_l1440_3 = conds[5];
assign when_Utils_l1440_4 = conds[6];
assign when_Utils_l1440_5 = conds[7];
More syntax suggars can be added
Would this match the need ?
from spinalhdl.
@Dolu1990 Good, this meets my need for parameterization. It's indeed a feature that's not easy to discover, so it's necessary to add it to the documentation.
from spinalhdl.
Yes i agree, this is quite underground lacking doc.
from spinalhdl.
Yes i agree, this is quite underground lacking doc.
@Dolu1990 don't worry, I will add it to the document later.
i have another question , Is there a way to move the previous expression to the later , some thing like this ,
//#PART1
when(io.addr === 0x0004 && io.wr){
my_reg := io.wdata
}.elsewhen(io.clr){
my_reg := B(0x1234, 32 bit)
}
...
...
...
i know my_reg have many method like `my_reg.removeStatement(`)
did there have mothod to get `my_reg.getStatement()` then move to another place
//#PART2
when(io.set){
my_reg := B(0x1234, 32 bit)
}.elewhen(xxxx){
my_reg.move_part1_logic_to_here
}.otherwise{
my_reg := B(0x0000, 32 bit)
}
Of course, this feature is not recommended for ordinary users to use, but it is still necessary to reserve such interfaces for areas that require hacks.
from spinalhdl.
I will add it to the document later.
Thanks :D
Also feel free to tweek / add syntax sugar on the top
my_reg.move_part1_logic_to_here
So, moving things using my_reg as "anchor" is tricky , because it would not be realy a move, but more a "move statments into a duplicated conditional scope".
I would say that instead, moving the whole when statements would be easier, but there is nothing in place for this yet. But it would just be about patching the linkedlist of statements i think. But there may be some tricky side effects related to statements ordering, i'm not sure.
Otherwise :
def func(){
when(io.addr === 0x0004 && io.wr){
my_reg := io.wdata
}.elsewhen(io.clr){
my_reg := B(0x1234, 32 bit)
}
}
//#PART2
when(io.set){
my_reg := B(0x1234, 32 bit)
}.elewhen(xxxx){
func()
}.otherwise{
my_reg := B(0x0000, 32 bit)
}
from spinalhdl.
I would say that instead, moving the whole when statements would be easier, but there is nothing in place for this yet. But it would just be about patching the linkedlist of statements i think. But there may be some tricky side effects related to statements ordering, i'm not sure.
Indeed, it might not be easy to handle, and it could be more feasible to choose a def
method as a callback. Thanks
from spinalhdl.
Related Issues (20)
- Seed does not work at parallel test of spinal sim HOT 5
- Underscore in literals HOT 5
- Linux: Spaces in path break formal verification HOT 7
- `privateNamespace` changes BlackBox component name HOT 1
- 『Help』Component Interface Name Changes Result in SpinalHDL Generating Excessive Redundant Module.v Files. HOT 5
- Register fields with AccessType ROV don't get names HOT 1
- When’ Requirement: Merging ‘setWhen’ and ‘clearWhen’ in Verilog Output HOT 3
- Assignment error with scala int `0x...` literal HOT 4
- fixTo is broken when range minimum is negative and using rounding with align option HOT 1
- ClockDomain.newSlowedClockDomain uses current clock domain rather than clockdomain on which it is called
- Nesting SlowAreas produces unexpected results HOT 1
- Formal: support for temporal sequences HOT 17
- Formal proofs started to fail with newer versions of sby HOT 11
- Could you please advise if there is any method to generate a port in the format of [lsb:msb]? HOT 6
- Porting to spinalHDL HOT 4
- Rethink on pastValid function.
- trait use help HOT 3
- Porting SpinalHDL to CIRCT? HOT 5
- PackedBundle EndiannessSwap
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spinalhdl.