Skip to content

Example of utilisation

denishoornaert edited this page Sep 5, 2019 · 1 revision

Example of utilisation

Hereunder, one can find an example demonstrating the use of the current state of the project. Briefly, the example is an implementation of a simple Float Processing Unit (FPU) where the input io.operator specifies whether io.result will output the outcome of the multiplication or the addition of io.operand1 and io.operand2.

A more complete example of a FPU (used for testing purposes) is currently available here.

import float._

class FPU extends Module {
    val io = IO(new Bundle {
        val operator  = Input(UInt(1.W)) // 0: mul & 1: add
        val operand1 = Input(UInt(32.W))
        val operand2 = Input(UInt(32.W))
        val result   = Output(UInt(32.W))
    })

    val op1 = (io.operand1).asTypeOf(new Float)
    val op2 = (io.operand2).asTypeOf(new Float)

    val res = Wire(new Float)
    when(io.operator.asBool) {
        res := op1+op2
    }
    .otherwise{
        res := op1*op2
    }
    io.result := res.asUInt

}