1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package xiangshan.backend.fu 18 19import chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import utils.XSPerfAccumulate 23import xiangshan._ 24import xiangshan.backend.fu.fpu._ 25 26trait HasFuLatency { 27 val latencyVal: Option[Int] 28 val uncertainLatencyVal: Option[Int] 29} 30 31case class CertainLatency(value: Int) extends HasFuLatency { 32 override val latencyVal: Option[Int] = Some(value) 33 override val uncertainLatencyVal: Option[Int] = None 34} 35 36case class UncertainLatency(value: Option[Int]) extends HasFuLatency { 37 override val latencyVal: Option[Int] = None 38 override val uncertainLatencyVal: Option[Int] = value 39} 40 41object UncertainLatency { 42 def apply(): UncertainLatency = UncertainLatency(None) 43 def apply(value: Int): UncertainLatency = UncertainLatency(Some(value)) 44} 45 46class FuOutput(val len: Int)(implicit p: Parameters) extends XSBundle { 47 val data = UInt(len.W) 48 val uop = new MicroOp 49} 50 51class FunctionUnitInput(val len: Int)(implicit p: Parameters) extends XSBundle { 52 val src = Vec(3, UInt(len.W)) 53 val uop = new MicroOp 54} 55 56class FunctionUnitIO(val len: Int)(implicit p: Parameters) extends XSBundle { 57 val in = Flipped(DecoupledIO(new FunctionUnitInput(len))) 58 59 val out = DecoupledIO(new FuOutput(len)) 60 61 val redirectIn = Flipped(ValidIO(new Redirect)) 62} 63 64abstract class FunctionUnit(len: Int = 64)(implicit p: Parameters) extends XSModule { 65 66 val io = IO(new FunctionUnitIO(len)) 67 68 XSPerfAccumulate("in_valid", io.in.valid) 69 XSPerfAccumulate("in_fire", io.in.fire) 70 XSPerfAccumulate("out_valid", io.out.valid) 71 XSPerfAccumulate("out_fire", io.out.fire) 72 73} 74