Search code examples
scalachiselrocket-chip

How to understand this line of chisel code


I'm in the process of learning chisel and scala language and try to analyse some lines of rocket-chip code.Could anyone try to explain me this line? https://github.com/chipsalliance/rocket-chip/blob/54237b5602a273378e3b35307bb47eb1e58cb9fb/src/main/scala/rocket/RocketCore.scala#L957

I understand what log2Up function is doing but don't understand why that log2Up(n)-1 and 0,were passed like "arguments" to addr which is val of type UInt!?


Solution

  • I could not find where UInt was defined, but if I had to guess, UInt is a class that has an apply method. This is a special method that allows us to use a parenthesis operator on an instance of the class.

    For example lets say we have a class called Multiply that defines an apply method.

    class Multiply {
      def apply(a: Int, b: Int): Int = a * b
    }
    

    This allows you to call operator () on any instance of that class. For example:

    val mul = new Multiply()
    println(mul(5, 6)) // prints 30