Skip to content
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

Add section for idioms #131

Open
numero-744 opened this issue Oct 24, 2022 · 7 comments
Open

Add section for idioms #131

numero-744 opened this issue Oct 24, 2022 · 7 comments
Assignees

Comments

@numero-744
Copy link
Collaborator

Spinal enables representing the code in a way which is not possible in RTL.

This section would show idioms which are useful in Spinal. For each idiom, it would explain it, how to use it, when and why it is good to use it, and maybe how it works.

Example of idiom:

val doSomethingFlag = False
def doSomething(): Unit = doSomethingFlag := True

I find it useful in fsm.State.whenActive to express the output logic.

  val fsm = new StateMachine {
    val IDLE, Rnd0, RndI, RndN, DONE = new State
    setEntry(IDLE)

    // Transition logic
    IDLE.whenIsActive { when(io.start) { goto(Rnd0) } }
    Rnd0.whenIsActive { goto(RndI) }
    RndI.whenIsActive { when(round.isLast) { goto(RndN) } }
    RndN.whenIsActive { goto(DONE) }
    DONE.whenIsActive { when(!io.start) { goto(IDLE) } }

    // Output logic, using only this idiom
    IDLE.whenIsActive { round.resetCount }
    Rnd0.whenIsActive { run; useInputs }
    RndI.whenIsActive { run }
    RndN.whenIsActive { run; withoutMixColumns }
    DONE.whenIsActive { enableOutput }
  }
@Dolu1990
Copy link
Member

Yes, such section would be usefull, showing all kind of funny / creative thing

@Readon
Copy link
Collaborator

Readon commented Oct 24, 2022

Nice Work!
This will be a shining pool of sparks for SpinalHDL.

@Dolu1990
Copy link
Member

Maybe we can do a call to discuss about patterns ?

@numero-744
Copy link
Collaborator Author

I was thinking that each pattern would be introduced by a PR into the which we could discuss but a call might be good too.

@Dolu1990
Copy link
Member

sure.

@numero-744
Copy link
Collaborator Author

numero-744 commented Nov 15, 2022

Note for when I will have created this section:

Function-like components: a companion object with an apply.

  object MyComponent {
    def apply(i: MyEnum.C): Bits = {
      val myComponent = new MyComponent
      myComponent.io.i := i
      myComponent.io.o
    }
  }

@numero-744
Copy link
Collaborator Author

numero-744 commented Nov 17, 2022

Once idioms are defined we can provide snippets (for instance providing them in the template) for IDEs. For instance:

	"Doing flag": {
		"scope": "scala",
		"prefix": "doing",
		"body": ["val ${2:${1}ing} = False", "def $1(): Unit = $2 := True", ""]
	}

We can also provide such snippets for Component etc. Providing this kind of ready-to-use tools can improve the Scala UX XD

With this example snippet in VSCodium with 8 keystrokes:

do<Tab>run<Tab><Tab>

I get:

val runing = False
def run(): Unit = runing := True

(It can require more than the 2 keystrokes do to reach the doing snippet depending on the coding context)

This was referenced Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants