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 17// See LICENSE.Berkeley for license details. 18// See LICENSE.SiFive for license details. 19 20package xiangshan.backend.fu.fpu 21 22import org.chipsalliance.cde.config.Parameters 23import chisel3._ 24import chisel3.util._ 25import utility.{SignExt, ZeroExt} 26import xiangshan.backend.fu.{FuConfig, FuncUnit, PipedFuncUnit} 27import xiangshan.backend.fu.vector.Bundles.VSew 28import xiangshan.IF2VectorType 29 30class IntFPToVec(cfg: FuConfig)(implicit p: Parameters) extends PipedFuncUnit(cfg) { 31 protected val in = io.in.bits 32 protected val out = io.out.bits 33 34 // vsew is the lowest 2 bits of fuOpType 35 private val isImm = IF2VectorType.isImm(in.ctrl.fuOpType(4, 2)) 36 // when needDup is true, the scalar data is duplicated in vector register 37 private val needDup = IF2VectorType.needDup(in.ctrl.fuOpType(4, 2)) 38 // when isFmv is true, the high bits of the scalar data is 1 39 private val isFmv = IF2VectorType.isFmv(in.ctrl.fuOpType(4, 2)) 40 41 // imm use src(1), scalar use src(0) 42 private val scalaData = Mux(isImm, in.data.src(1), in.data.src(0)) 43 // vsew is the lowest 2 bits of fuOpType 44 private val vsew = in.ctrl.fuOpType(1, 0) 45 private val dataWidth = cfg.dataBits 46 47 private val fpData = Mux1H(Seq( 48 (vsew === VSew.e8) -> Cat(Fill(56, 1.U), scalaData( 7, 0)), 49 (vsew === VSew.e16) -> Cat(Fill(48, 1.U), scalaData(15, 0)), 50 (vsew === VSew.e32) -> Cat(Fill(32, 1.U), scalaData(31, 0)), 51 (vsew === VSew.e64) -> scalaData 52 )) 53 54 private val vecE8Data = Wire(Vec(dataWidth / 8, UInt( 8.W))) 55 private val vecE16Data = Wire(Vec(dataWidth / 16, UInt(16.W))) 56 private val vecE32Data = Wire(Vec(dataWidth / 32, UInt(32.W))) 57 private val vecE64Data = Wire(Vec(dataWidth / 64, UInt(64.W))) 58 59 vecE8Data := VecInit(Seq.fill(dataWidth / 8)(scalaData( 7, 0))) 60 vecE16Data := VecInit(Seq.fill(dataWidth / 16)(scalaData(15, 0))) 61 vecE32Data := VecInit(Seq.fill(dataWidth / 32)(scalaData(31, 0))) 62 vecE64Data := VecInit(Seq.fill(dataWidth / 64)(scalaData(63, 0))) 63 64 out.res.data := Mux(needDup, Mux1H(Seq( 65 (vsew === VSew.e8) -> vecE8Data.asUInt, 66 (vsew === VSew.e16) -> vecE16Data.asUInt, 67 (vsew === VSew.e32) -> vecE32Data.asUInt, 68 (vsew === VSew.e64) -> vecE64Data.asUInt, 69 )), Mux(isFmv, fpData, scalaData)) 70} 71