JumpExeUnit.scala 3.1 KB
Newer Older
L
LinJiawei 已提交
1 2 3 4 5
package xiangshan.backend.exu


import chisel3._
import chisel3.util._
Y
Yinan Xu 已提交
6
import xiangshan._
7
import xiangshan.backend.exu.Exu.jumpExeUnitCfg
L
LinJiawei 已提交
8 9 10 11
import xiangshan.backend.fu.fpu.FPUOpType.FU_I2F
import xiangshan.backend.fu.{CSR, Fence, FenceToSbuffer, FunctionUnit, Jump}
import xiangshan.backend.fu.fpu.{Fflags, IntToFloatSingleCycle, boxF32ToF64}

12
class JumpExeUnit extends Exu(jumpExeUnitCfg)
L
LinJiawei 已提交
13
{
Y
Yinan Xu 已提交
14 15 16
  val csrio = IO(new Bundle {
    val fflags = Input(new Fflags)
    val dirty_fs = Input(Bool())
Y
Yinan Xu 已提交
17
    val frm = Output(UInt(3.W))
Y
Yinan Xu 已提交
18 19 20 21 22 23 24 25 26
    val exception = Flipped(ValidIO(new MicroOp))
    val isInterrupt = Input(Bool())
    val trapTarget = Output(UInt(VAddrBits.W))
    val interrupt = Output(Bool())
    val memExceptionVAddr = Input(UInt(VAddrBits.W))
    val externalInterrupt = new ExternalInterruptIO
    val tlb = Output(new TlbCsrBundle)
  })
  val fenceio = IO(new Bundle {
Y
Yinan Xu 已提交
27 28 29
    val sfence = Output(new SfenceBundle)
    val fencei = Output(Bool())
    val sbuffer = new FenceToSbuffer
Y
Yinan Xu 已提交
30
  })
31

L
LinJiawei 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
  val jmp = supportedFunctionUnits.collectFirst{
    case j: Jump => j
  }.get
  val csr = supportedFunctionUnits.collectFirst{
    case c: CSR => c
  }.get
  val fence = supportedFunctionUnits.collectFirst{
    case f: Fence => f
  }.get
  val i2f = supportedFunctionUnits.collectFirst {
    case i: IntToFloatSingleCycle => i
  }.get

Y
Yinan Xu 已提交
45
  csr.csrio.perf <> DontCare
Y
Yinan Xu 已提交
46
  csr.csrio.fpu.fflags <> csrio.fflags
Y
Yinan Xu 已提交
47
  csr.csrio.fpu.isIllegal := false.B
Y
Yinan Xu 已提交
48 49
  csr.csrio.fpu.dirty_fs <> csrio.dirty_fs
  csr.csrio.fpu.frm <> csrio.frm
Y
Yinan Xu 已提交
50 51 52 53 54 55 56 57 58 59 60
  csr.csrio.exception <> csrio.exception
  csr.csrio.isInterrupt <> csrio.isInterrupt
  csr.csrio.trapTarget <> csrio.trapTarget
  csr.csrio.interrupt <> csrio.interrupt
  csr.csrio.memExceptionVAddr <> csrio.memExceptionVAddr
  csr.csrio.externalInterrupt <> csrio.externalInterrupt
  csr.csrio.tlb <> csrio.tlb

  fenceio.sfence <> fence.sfence
  fenceio.fencei <> fence.fencei
  fenceio.sbuffer <> fence.toSbuffer
61
  fence.io.out.ready := true.B
L
LinJiawei 已提交
62

Y
Yinan Xu 已提交
63
  val uop = io.fromInt.bits.uop
L
LinJiawei 已提交
64
  val instr_rm = uop.cf.instr(14, 12)
Y
Yinan Xu 已提交
65
  i2f.rm := Mux(instr_rm =/= 7.U, instr_rm, csr.csrio.fpu.frm)
L
LinJiawei 已提交
66 67 68 69 70

  val isDouble = !uop.ctrl.isRVF

  when(i2f.io.in.valid){
    when(uop.ctrl.fuOpType.head(4)===s"b$FU_I2F".U){
71 72
      io.toFp.bits.data := Mux(isDouble, i2f.io.out.bits.data, boxF32ToF64(i2f.io.out.bits.data))
      io.toFp.bits.fflags := i2f.fflags
L
LinJiawei 已提交
73 74
    }.otherwise({
      // a mov.(s/d).x instruction
75 76
      io.toFp.bits.data := Mux(isDouble, io.fromInt.bits.src1, boxF32ToF64(io.fromInt.bits.src1))
      io.toFp.bits.fflags := 0.U.asTypeOf(new Fflags)
L
LinJiawei 已提交
77 78 79 80
    })
  }

  when(csr.io.out.valid){
Y
Yinan Xu 已提交
81
    io.toInt.bits.redirectValid := csr.csrio.redirectOut.valid
82 83 84 85 86 87
    io.toInt.bits.redirect.brTag := uop.brTag
    io.toInt.bits.redirect.isException := false.B
    io.toInt.bits.redirect.isMisPred := false.B
    io.toInt.bits.redirect.isFlushPipe := false.B
    io.toInt.bits.redirect.isReplay := false.B
    io.toInt.bits.redirect.roqIdx := uop.roqIdx
Y
Yinan Xu 已提交
88
    io.toInt.bits.redirect.target := csr.csrio.redirectOut.bits
89
    io.toInt.bits.redirect.pc := uop.cf.pc
L
LinJiawei 已提交
90
  }.elsewhen(jmp.io.out.valid){
91 92 93
    io.toInt.bits.redirectValid := jmp.redirectOutValid
    io.toInt.bits.redirect := jmp.redirectOut
    io.toInt.bits.brUpdate := jmp.brUpdate
L
LinJiawei 已提交
94 95
  }
}