[Weekly Review] 2020/03/16-22

Published: by Creative Commons Licence (Last updated: )

2020/03/16-22

This week, I learned some materials related to SiFive TileLink and its chisel codes. Also, tried to test the PE Cluster of FYP. From Friday, I also discussed Fuzzer.scala with Sequencer, though we were puzzled by the function GenMask.

This week, I hope I could attach the ClusterGroup onto TileLink.

Scala Syntax

High-Order Function

Use the function as the input parameter or the output.

def singleThreadPokePeek(adrOrData: Int, peekCon: (Int, Int) => Boolean): Unit = {...}
def formerCon(row: Int, col: Int): Boolean = {
   val condition = (row + col) < inActRouterNum
   condition
}
singleThreadPokePeek(1, formerCon)

Just use => to show it's a function.

Regular Expression Patterns

import scala.util.matching.Regex

val numberPattern: Regex = "[0-9]".r

numberPattern.findFirstMatchIn("awesomepassword") match {
  case Some(_) => println("Password OK")
  case None => println("Password must contain a number")
}

val pattern = "^[a-z0-9._%\\-+]+@(?:[a-z0-9\\-]+\\.)+[a-z]{2,4}$"

val emailRegex = pattern.r // or new Regex(pattern)

emailRegex.pattern.matcher("tt@163.com").matches // true

If you just want to match a piece of string, then you can use find().

Chisel Syntax

One Bug of Chisel fork.withRegion

When I wrote a test for a multi-read-write-IO, I need to use fork.withRegion to combine them together. However, sometimes, they will not work, such as the following situation:

  it should "resolve fork-in-fork" in {
    test(new PassthroughModule(UInt(8.W))) { c =>
      fork {
          fork {
              c.in.poke(42.U)
              c.clock.step()
          } .fork {
              c.clock.step()
              c.in.poke(70.U)
              c.clock.step()
          }
      }.fork.withRegion(Monitor) {
          fork.withRegion(Monitor) {
              c.in.expect(42.U)
              c.clock.step()
          } .fork.withRegion(Monitor) {
              c.clock.step()
              c.in.expect(70.U)
              c.clock.step()
          }
      }.joinAndStep(c.clock)
    }
  }

Base Address and Offset

An address that serves as a reference point for other addresses. For example, a base address could indicate the beginning of a program. The address of every instruction in the program could then be specified by adding an offset to the base address. For example, the address of the fifth instruction would be the base address plus 5.