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.datapath 18 19import chisel3._ 20import chisel3.util._ 21 22class NewPipelineConnectPipe[T <: Data](gen: T) extends Module { 23 val io = IO(new Bundle() { 24 val in = Flipped(DecoupledIO(gen.cloneType)) 25 val out = DecoupledIO(gen.cloneType) 26 val rightOutFire = Input(Bool()) 27 val isFlush = Input(Bool()) 28 }) 29 30 NewPipelineConnect.connect(io.in, io.out, io.rightOutFire, io.isFlush) 31} 32 33object NewPipelineConnect { 34 def connect[T <: Data]( 35 left: DecoupledIO[T], 36 right: DecoupledIO[T], 37 rightOutFire: Bool, 38 isFlush: Bool 39 ): T = { 40 val valid = RegInit(false.B) 41 42 left.ready := right.ready || !valid 43 val data = RegEnable(left.bits, left.fire) 44 45 when (rightOutFire) { valid := false.B } 46 when (left.fire) { valid := true.B } 47 when (isFlush) { valid := false.B } 48 49 right.bits := data 50 right.valid := valid 51 52 data 53 } 54 55 def apply[T <: Data]( 56 left: DecoupledIO[T], 57 right: DecoupledIO[T], 58 rightOutFire: Bool, 59 isFlush: Bool, 60 moduleName: Option[String] = None 61 ): Option[T] = { 62 if (moduleName.isDefined) { 63 val pipeline = Module(new NewPipelineConnectPipe(left.bits)) 64 pipeline.suggestName(moduleName.get) 65 pipeline.io.in <> left 66 pipeline.io.rightOutFire := rightOutFire 67 pipeline.io.isFlush := isFlush 68 pipeline.io.out <> right 69 pipeline.io.out.ready := right.ready 70 None 71 } 72 else { 73 // do not use module here to please DCE 74 Some(connect(left, right, rightOutFire, isFlush)) 75 } 76 } 77}