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 17 18 19 20 21 22 23 24 25 26 27 28 29
  val csrio = IO(new Bundle {
    val fflags = Input(new Fflags)
    val dirty_fs = Input(Bool())
    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 {
    val sfence = IO(Output(new SfenceBundle))
    val fencei = IO(Output(Bool()))
    val sbuffer = IO(new FenceToSbuffer)
  })
30

L
LinJiawei 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43
  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 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  csr.csrio.perf <> DontCare
  csr.csrio.fpu.fflags := csrio.fflags
  csr.csrio.fpu.isIllegal := false.B
  csr.csrio.fpu.dirty_fs := csrio.dirty_fs
  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
59
  fence.io.out.ready := true.B
L
LinJiawei 已提交
60

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

  val isDouble = !uop.ctrl.isRVF

  when(i2f.io.in.valid){
    when(uop.ctrl.fuOpType.head(4)===s"b$FU_I2F".U){
69 70
      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 已提交
71 72
    }.otherwise({
      // a mov.(s/d).x instruction
73 74
      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 已提交
75 76 77 78
    })
  }

  when(csr.io.out.valid){
Y
Yinan Xu 已提交
79
    io.toInt.bits.redirectValid := csr.csrio.redirectOut.valid
80 81 82 83 84 85
    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 已提交
86
    io.toInt.bits.redirect.target := csr.csrio.redirectOut.bits
87
    io.toInt.bits.redirect.pc := uop.cf.pc
L
LinJiawei 已提交
88
  }.elsewhen(jmp.io.out.valid){
89 90 91
    io.toInt.bits.redirectValid := jmp.redirectOutValid
    io.toInt.bits.redirect := jmp.redirectOut
    io.toInt.bits.brUpdate := jmp.brUpdate
L
LinJiawei 已提交
92 93
  }
}