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 17import chisel3._ 18import chisel3.util._ 19import chipsalliance.rocketchip.config.Parameters 20import freechips.rocketchip.tile.XLen 21import xiangshan.ExceptionNO._ 22import xiangshan.backend.issue._ 23import xiangshan.backend.fu._ 24import xiangshan.backend.fu.fpu._ 25import xiangshan.backend.fu.vector._ 26import xiangshan.backend.exu._ 27import xiangshan.backend.{Std, ScheLaneConfig} 28 29package object xiangshan { 30 object SrcType { 31 def imm = "b000".U 32 def pc = "b000".U 33 def xp = "b001".U 34 def fp = "b010".U 35 def vp = "b100".U 36 37 // alias 38 def reg = this.xp 39 def DC = imm // Don't Care 40 def X = BitPat("b000") 41 42 def isPc(srcType: UInt) = srcType===pc 43 def isImm(srcType: UInt) = srcType===imm 44 def isReg(srcType: UInt) = srcType(0) 45 def isFp(srcType: UInt) = srcType(1) 46 def isVp(srcType: UInt) = srcType(2) 47 def isPcOrImm(srcType: UInt) = isPc(srcType) || isImm(srcType) 48 49 def isNull(srcType: UInt) = !(isPcOrImm(srcType) || isReg(srcType) || 50 isFp(srcType) || isVp(srcType)) 51 52 def apply() = UInt(3.W) 53 } 54 55 object SrcState { 56 def busy = "b0".U 57 def rdy = "b1".U 58 // def specRdy = "b10".U // speculative ready, for future use 59 def apply() = UInt(1.W) 60 } 61 62 // Todo: Use OH instead 63 object FuType { 64 def jmp = "b00000".U 65 def i2f = "b00001".U 66 def csr = "b00010".U 67 def alu = "b00110".U 68 def mul = "b00100".U 69 def div = "b00101".U 70 def fence = "b00011".U 71 def bku = "b00111".U 72 73 def fmac = "b01000".U 74 def fmisc = "b01011".U 75 def fDivSqrt = "b01010".U 76 77 def ldu = "b01100".U 78 def stu = "b01101".U 79 def mou = "b01111".U // for amo, lr, sc, fence 80 81 def vipu = "b10000".U 82 def vfpu = "b11000".U 83 def vldu = "b11100".U 84 def vstu = "b11101".U 85 def vppu = "b11001".U // for Permutation Unit 86 def X = BitPat("b00000") // TODO: It may be a potential bug 87 88 def num = 19 89 90 def apply() = UInt(log2Up(num).W) 91 92 // TODO: Optimize FuTpye and its method 93 // FIXME: Vector FuType coding is not ready 94 def isVecExu(fuType: UInt) = fuType(4) 95 def isIntExu(fuType: UInt) = !isVecExu(fuType) && !fuType(3) 96 def isJumpExu(fuType: UInt) = fuType === jmp 97 def isFpExu(fuType: UInt) = !isVecExu(fuType) && (fuType(3, 2) === "b10".U) 98 def isMemExu(fuType: UInt) = !isVecExu(fuType) && (fuType(3, 2) === "b11".U) 99 def isLoadStore(fuType: UInt) = isMemExu(fuType) && !fuType(1) 100 def isStoreExu(fuType: UInt) = isMemExu(fuType) && fuType(0) 101 def isAMO(fuType: UInt) = fuType(1) 102 def isFence(fuType: UInt) = fuType === fence 103 def isSvinvalBegin(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.nofence && !flush 104 def isSvinval(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.sfence && !flush 105 def isSvinvalEnd(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.nofence && flush 106 107 def jmpCanAccept(fuType: UInt) = !fuType(2) 108 def mduCanAccept(fuType: UInt) = fuType(2) && !fuType(1) || fuType(2) && fuType(1) && fuType(0) 109 def aluCanAccept(fuType: UInt) = fuType(2) && fuType(1) && !fuType(0) 110 111 def fmacCanAccept(fuType: UInt) = !fuType(1) 112 def fmiscCanAccept(fuType: UInt) = fuType(1) 113 114 def loadCanAccept(fuType: UInt) = !fuType(0) 115 def storeCanAccept(fuType: UInt) = fuType(0) 116 117 def storeIsAMO(fuType: UInt) = fuType(1) 118 119 val functionNameMap = Map( 120 jmp.litValue() -> "jmp", 121 i2f.litValue() -> "int_to_float", 122 csr.litValue() -> "csr", 123 alu.litValue() -> "alu", 124 mul.litValue() -> "mul", 125 div.litValue() -> "div", 126 fence.litValue() -> "fence", 127 bku.litValue() -> "bku", 128 fmac.litValue() -> "fmac", 129 fmisc.litValue() -> "fmisc", 130 fDivSqrt.litValue() -> "fdiv_fsqrt", 131 ldu.litValue() -> "load", 132 stu.litValue() -> "store", 133 mou.litValue() -> "mou" 134 ) 135 } 136 137 def FuOpTypeWidth = 8 138 object FuOpType { 139 def apply() = UInt(FuOpTypeWidth.W) 140 def X = BitPat("b00000000") 141 } 142 143 // move VipuType and VfpuType into YunSuan/package.scala 144 // object VipuType { 145 // def dummy = 0.U(7.W) 146 // } 147 148 // object VfpuType { 149 // def dummy = 0.U(7.W) 150 // } 151 152 object VlduType { 153 def dummy = 0.U 154 } 155 156 object VstuType { 157 def dummy = 0.U 158 } 159 160 object CommitType { 161 def NORMAL = "b000".U // int/fp 162 def BRANCH = "b001".U // branch 163 def LOAD = "b010".U // load 164 def STORE = "b011".U // store 165 166 def apply() = UInt(3.W) 167 def isFused(commitType: UInt): Bool = commitType(2) 168 def isLoadStore(commitType: UInt): Bool = !isFused(commitType) && commitType(1) 169 def lsInstIsStore(commitType: UInt): Bool = commitType(0) 170 def isStore(commitType: UInt): Bool = isLoadStore(commitType) && lsInstIsStore(commitType) 171 def isBranch(commitType: UInt): Bool = commitType(0) && !commitType(1) && !isFused(commitType) 172 } 173 174 object RedirectLevel { 175 def flushAfter = "b0".U 176 def flush = "b1".U 177 178 def apply() = UInt(1.W) 179 // def isUnconditional(level: UInt) = level(1) 180 def flushItself(level: UInt) = level(0) 181 // def isException(level: UInt) = level(1) && level(0) 182 } 183 184 object ExceptionVec { 185 def apply() = Vec(16, Bool()) 186 } 187 188 object PMAMode { 189 def R = "b1".U << 0 //readable 190 def W = "b1".U << 1 //writeable 191 def X = "b1".U << 2 //executable 192 def I = "b1".U << 3 //cacheable: icache 193 def D = "b1".U << 4 //cacheable: dcache 194 def S = "b1".U << 5 //enable speculative access 195 def A = "b1".U << 6 //enable atomic operation, A imply R & W 196 def C = "b1".U << 7 //if it is cacheable is configable 197 def Reserved = "b0".U 198 199 def apply() = UInt(7.W) 200 201 def read(mode: UInt) = mode(0) 202 def write(mode: UInt) = mode(1) 203 def execute(mode: UInt) = mode(2) 204 def icache(mode: UInt) = mode(3) 205 def dcache(mode: UInt) = mode(4) 206 def speculate(mode: UInt) = mode(5) 207 def atomic(mode: UInt) = mode(6) 208 def configable_cache(mode: UInt) = mode(7) 209 210 def strToMode(s: String) = { 211 var result = 0.U(8.W) 212 if (s.toUpperCase.indexOf("R") >= 0) result = result + R 213 if (s.toUpperCase.indexOf("W") >= 0) result = result + W 214 if (s.toUpperCase.indexOf("X") >= 0) result = result + X 215 if (s.toUpperCase.indexOf("I") >= 0) result = result + I 216 if (s.toUpperCase.indexOf("D") >= 0) result = result + D 217 if (s.toUpperCase.indexOf("S") >= 0) result = result + S 218 if (s.toUpperCase.indexOf("A") >= 0) result = result + A 219 if (s.toUpperCase.indexOf("C") >= 0) result = result + C 220 result 221 } 222 } 223 224 225 object CSROpType { 226 def jmp = "b000".U 227 def wrt = "b001".U 228 def set = "b010".U 229 def clr = "b011".U 230 def wfi = "b100".U 231 def wrti = "b101".U 232 def seti = "b110".U 233 def clri = "b111".U 234 def needAccess(op: UInt): Bool = op(1, 0) =/= 0.U 235 } 236 237 // jump 238 object JumpOpType { 239 def jal = "b00".U 240 def jalr = "b01".U 241 def auipc = "b10".U 242// def call = "b11_011".U 243// def ret = "b11_100".U 244 def jumpOpisJalr(op: UInt) = op(0) 245 def jumpOpisAuipc(op: UInt) = op(1) 246 } 247 248 object FenceOpType { 249 def fence = "b10000".U 250 def sfence = "b10001".U 251 def fencei = "b10010".U 252 def nofence= "b00000".U 253 } 254 255 object ALUOpType { 256 // shift optype 257 def slliuw = "b000_0000".U // slliuw: ZEXT(src1[31:0]) << shamt 258 def sll = "b000_0001".U // sll: src1 << src2 259 260 def bclr = "b000_0010".U // bclr: src1 & ~(1 << src2[5:0]) 261 def bset = "b000_0011".U // bset: src1 | (1 << src2[5:0]) 262 def binv = "b000_0100".U // binv: src1 ^ ~(1 << src2[5:0]) 263 264 def srl = "b000_0101".U // srl: src1 >> src2 265 def bext = "b000_0110".U // bext: (src1 >> src2)[0] 266 def sra = "b000_0111".U // sra: src1 >> src2 (arithmetic) 267 268 def rol = "b000_1001".U // rol: (src1 << src2) | (src1 >> (xlen - src2)) 269 def ror = "b000_1011".U // ror: (src1 >> src2) | (src1 << (xlen - src2)) 270 271 // RV64 32bit optype 272 def addw = "b001_0000".U // addw: SEXT((src1 + src2)[31:0]) 273 def oddaddw = "b001_0001".U // oddaddw: SEXT((src1[0] + src2)[31:0]) 274 def subw = "b001_0010".U // subw: SEXT((src1 - src2)[31:0]) 275 276 def addwbit = "b001_0100".U // addwbit: (src1 + src2)[0] 277 def addwbyte = "b001_0101".U // addwbyte: (src1 + src2)[7:0] 278 def addwzexth = "b001_0110".U // addwzexth: ZEXT((src1 + src2)[15:0]) 279 def addwsexth = "b001_0111".U // addwsexth: SEXT((src1 + src2)[15:0]) 280 281 def sllw = "b001_1000".U // sllw: SEXT((src1 << src2)[31:0]) 282 def srlw = "b001_1001".U // srlw: SEXT((src1[31:0] >> src2)[31:0]) 283 def sraw = "b001_1010".U // sraw: SEXT((src1[31:0] >> src2)[31:0]) 284 def rolw = "b001_1100".U 285 def rorw = "b001_1101".U 286 287 // ADD-op 288 def adduw = "b010_0000".U // adduw: src1[31:0] + src2 289 def add = "b010_0001".U // add: src1 + src2 290 def oddadd = "b010_0010".U // oddadd: src1[0] + src2 291 292 def sr29add = "b010_0100".U // sr29add: src1[63:29] + src2 293 def sr30add = "b010_0101".U // sr30add: src1[63:30] + src2 294 def sr31add = "b010_0110".U // sr31add: src1[63:31] + src2 295 def sr32add = "b010_0111".U // sr32add: src1[63:32] + src2 296 297 def sh1adduw = "b010_1000".U // sh1adduw: {src1[31:0], 1'b0} + src2 298 def sh1add = "b010_1001".U // sh1add: {src1[62:0], 1'b0} + src2 299 def sh2adduw = "b010_1010".U // sh2add_uw: {src1[31:0], 2'b0} + src2 300 def sh2add = "b010_1011".U // sh2add: {src1[61:0], 2'b0} + src2 301 def sh3adduw = "b010_1100".U // sh3add_uw: {src1[31:0], 3'b0} + src2 302 def sh3add = "b010_1101".U // sh3add: {src1[60:0], 3'b0} + src2 303 def sh4add = "b010_1111".U // sh4add: {src1[59:0], 4'b0} + src2 304 305 // SUB-op: src1 - src2 306 def sub = "b011_0000".U 307 def sltu = "b011_0001".U 308 def slt = "b011_0010".U 309 def maxu = "b011_0100".U 310 def minu = "b011_0101".U 311 def max = "b011_0110".U 312 def min = "b011_0111".U 313 314 // branch 315 def beq = "b111_0000".U 316 def bne = "b111_0010".U 317 def blt = "b111_1000".U 318 def bge = "b111_1010".U 319 def bltu = "b111_1100".U 320 def bgeu = "b111_1110".U 321 322 // misc optype 323 def and = "b100_0000".U 324 def andn = "b100_0001".U 325 def or = "b100_0010".U 326 def orn = "b100_0011".U 327 def xor = "b100_0100".U 328 def xnor = "b100_0101".U 329 def orcb = "b100_0110".U 330 331 def sextb = "b100_1000".U 332 def packh = "b100_1001".U 333 def sexth = "b100_1010".U 334 def packw = "b100_1011".U 335 336 def revb = "b101_0000".U 337 def rev8 = "b101_0001".U 338 def pack = "b101_0010".U 339 def orh48 = "b101_0011".U 340 341 def szewl1 = "b101_1000".U 342 def szewl2 = "b101_1001".U 343 def szewl3 = "b101_1010".U 344 def byte2 = "b101_1011".U 345 346 def andlsb = "b110_0000".U 347 def andzexth = "b110_0001".U 348 def orlsb = "b110_0010".U 349 def orzexth = "b110_0011".U 350 def xorlsb = "b110_0100".U 351 def xorzexth = "b110_0101".U 352 def orcblsb = "b110_0110".U 353 def orcbzexth = "b110_0111".U 354 def vsetvli1 = "b1000_0000".U 355 def vsetvli2 = "b1000_0100".U 356 def vsetvl1 = "b1000_0001".U 357 def vsetvl2 = "b1000_0101".U 358 def vsetivli1 = "b1000_0010".U 359 def vsetivli2 = "b1000_0110".U 360 361 def isAddw(func: UInt) = func(6, 4) === "b001".U && !func(3) && !func(1) 362 def isSimpleLogic(func: UInt) = func(6, 4) === "b100".U && !func(0) 363 def logicToLsb(func: UInt) = Cat("b110".U(3.W), func(3, 1), 0.U(1.W)) 364 def logicToZexth(func: UInt) = Cat("b110".U(3.W), func(3, 1), 1.U(1.W)) 365 def isBranch(func: UInt) = func(6, 4) === "b111".U 366 def getBranchType(func: UInt) = func(3, 2) 367 def isBranchInvert(func: UInt) = func(1) 368 def isVset(func: UInt) = func(7, 3) === "b1000_0".U 369 def isVsetvl(func: UInt) = isVset(func) && func(0) 370 def isVsetvli(func: UInt) = isVset(func) && !func(1, 0).orR 371 def vsetExchange(func: UInt) = Cat(func(7, 3), "b1".U, func(1, 0)) 372 373 def apply() = UInt(FuOpTypeWidth.W) 374 } 375 376 object MDUOpType { 377 // mul 378 // bit encoding: | type (2bit) | isWord(1bit) | opcode(2bit) | 379 def mul = "b00000".U 380 def mulh = "b00001".U 381 def mulhsu = "b00010".U 382 def mulhu = "b00011".U 383 def mulw = "b00100".U 384 385 def mulw7 = "b01100".U 386 387 // div 388 // bit encoding: | type (2bit) | isWord(1bit) | isSign(1bit) | opcode(1bit) | 389 def div = "b10000".U 390 def divu = "b10010".U 391 def rem = "b10001".U 392 def remu = "b10011".U 393 394 def divw = "b10100".U 395 def divuw = "b10110".U 396 def remw = "b10101".U 397 def remuw = "b10111".U 398 399 def isMul(op: UInt) = !op(4) 400 def isDiv(op: UInt) = op(4) 401 402 def isDivSign(op: UInt) = isDiv(op) && !op(1) 403 def isW(op: UInt) = op(2) 404 def isH(op: UInt) = (isDiv(op) && op(0)) || (isMul(op) && op(1, 0) =/= 0.U) 405 def getMulOp(op: UInt) = op(1, 0) 406 } 407 408 object LSUOpType { 409 // load pipeline 410 411 // normal load 412 // Note: bit(1, 0) are size, DO NOT CHANGE 413 // bit encoding: | load 0 | is unsigned(1bit) | size(2bit) | 414 def lb = "b0000".U 415 def lh = "b0001".U 416 def lw = "b0010".U 417 def ld = "b0011".U 418 def lbu = "b0100".U 419 def lhu = "b0101".U 420 def lwu = "b0110".U 421 422 // Zicbop software prefetch 423 // bit encoding: | prefetch 1 | 0 | prefetch type (2bit) | 424 def prefetch_i = "b1000".U // TODO 425 def prefetch_r = "b1001".U 426 def prefetch_w = "b1010".U 427 428 def isPrefetch(op: UInt): Bool = op(3) 429 430 // store pipeline 431 // normal store 432 // bit encoding: | store 00 | size(2bit) | 433 def sb = "b0000".U 434 def sh = "b0001".U 435 def sw = "b0010".U 436 def sd = "b0011".U 437 438 // l1 cache op 439 // bit encoding: | cbo_zero 01 | size(2bit) 11 | 440 def cbo_zero = "b0111".U 441 442 // llc op 443 // bit encoding: | prefetch 11 | suboptype(2bit) | 444 def cbo_clean = "b1100".U 445 def cbo_flush = "b1101".U 446 def cbo_inval = "b1110".U 447 448 def isCbo(op: UInt): Bool = op(3, 2) === "b11".U 449 450 // atomics 451 // bit(1, 0) are size 452 // since atomics use a different fu type 453 // so we can safely reuse other load/store's encodings 454 // bit encoding: | optype(4bit) | size (2bit) | 455 def lr_w = "b000010".U 456 def sc_w = "b000110".U 457 def amoswap_w = "b001010".U 458 def amoadd_w = "b001110".U 459 def amoxor_w = "b010010".U 460 def amoand_w = "b010110".U 461 def amoor_w = "b011010".U 462 def amomin_w = "b011110".U 463 def amomax_w = "b100010".U 464 def amominu_w = "b100110".U 465 def amomaxu_w = "b101010".U 466 467 def lr_d = "b000011".U 468 def sc_d = "b000111".U 469 def amoswap_d = "b001011".U 470 def amoadd_d = "b001111".U 471 def amoxor_d = "b010011".U 472 def amoand_d = "b010111".U 473 def amoor_d = "b011011".U 474 def amomin_d = "b011111".U 475 def amomax_d = "b100011".U 476 def amominu_d = "b100111".U 477 def amomaxu_d = "b101011".U 478 479 def size(op: UInt) = op(1,0) 480 } 481 482 object BKUOpType { 483 484 def clmul = "b000000".U 485 def clmulh = "b000001".U 486 def clmulr = "b000010".U 487 def xpermn = "b000100".U 488 def xpermb = "b000101".U 489 490 def clz = "b001000".U 491 def clzw = "b001001".U 492 def ctz = "b001010".U 493 def ctzw = "b001011".U 494 def cpop = "b001100".U 495 def cpopw = "b001101".U 496 497 // 01xxxx is reserve 498 def aes64es = "b100000".U 499 def aes64esm = "b100001".U 500 def aes64ds = "b100010".U 501 def aes64dsm = "b100011".U 502 def aes64im = "b100100".U 503 def aes64ks1i = "b100101".U 504 def aes64ks2 = "b100110".U 505 506 // merge to two instruction sm4ks & sm4ed 507 def sm4ed0 = "b101000".U 508 def sm4ed1 = "b101001".U 509 def sm4ed2 = "b101010".U 510 def sm4ed3 = "b101011".U 511 def sm4ks0 = "b101100".U 512 def sm4ks1 = "b101101".U 513 def sm4ks2 = "b101110".U 514 def sm4ks3 = "b101111".U 515 516 def sha256sum0 = "b110000".U 517 def sha256sum1 = "b110001".U 518 def sha256sig0 = "b110010".U 519 def sha256sig1 = "b110011".U 520 def sha512sum0 = "b110100".U 521 def sha512sum1 = "b110101".U 522 def sha512sig0 = "b110110".U 523 def sha512sig1 = "b110111".U 524 525 def sm3p0 = "b111000".U 526 def sm3p1 = "b111001".U 527 } 528 529 object BTBtype { 530 def B = "b00".U // branch 531 def J = "b01".U // jump 532 def I = "b10".U // indirect 533 def R = "b11".U // return 534 535 def apply() = UInt(2.W) 536 } 537 538 object SelImm { 539 def IMM_X = "b0111".U 540 def IMM_S = "b1110".U 541 def IMM_SB = "b0001".U 542 def IMM_U = "b0010".U 543 def IMM_UJ = "b0011".U 544 def IMM_I = "b0100".U 545 def IMM_Z = "b0101".U 546 def INVALID_INSTR = "b0110".U 547 def IMM_B6 = "b1000".U 548 549 def IMM_OPIVIS = "b1001".U 550 def IMM_OPIVIU = "b1010".U 551 def IMM_VSETVLI = "b1100".U 552 def IMM_VSETIVLI = "b1101".U 553 554 def X = BitPat("b0000") 555 556 def apply() = UInt(4.W) 557 } 558 559 object ExceptionNO { 560 def instrAddrMisaligned = 0 561 def instrAccessFault = 1 562 def illegalInstr = 2 563 def breakPoint = 3 564 def loadAddrMisaligned = 4 565 def loadAccessFault = 5 566 def storeAddrMisaligned = 6 567 def storeAccessFault = 7 568 def ecallU = 8 569 def ecallS = 9 570 def ecallM = 11 571 def instrPageFault = 12 572 def loadPageFault = 13 573 // def singleStep = 14 574 def storePageFault = 15 575 def priorities = Seq( 576 breakPoint, // TODO: different BP has different priority 577 instrPageFault, 578 instrAccessFault, 579 illegalInstr, 580 instrAddrMisaligned, 581 ecallM, ecallS, ecallU, 582 storeAddrMisaligned, 583 loadAddrMisaligned, 584 storePageFault, 585 loadPageFault, 586 storeAccessFault, 587 loadAccessFault 588 ) 589 def all = priorities.distinct.sorted 590 def frontendSet = Seq( 591 instrAddrMisaligned, 592 instrAccessFault, 593 illegalInstr, 594 instrPageFault 595 ) 596 def partialSelect(vec: Vec[Bool], select: Seq[Int]): Vec[Bool] = { 597 val new_vec = Wire(ExceptionVec()) 598 new_vec.foreach(_ := false.B) 599 select.foreach(i => new_vec(i) := vec(i)) 600 new_vec 601 } 602 def selectFrontend(vec: Vec[Bool]): Vec[Bool] = partialSelect(vec, frontendSet) 603 def selectAll(vec: Vec[Bool]): Vec[Bool] = partialSelect(vec, ExceptionNO.all) 604 def selectByFu(vec:Vec[Bool], fuConfig: FuConfig): Vec[Bool] = 605 partialSelect(vec, fuConfig.exceptionOut) 606 def selectByExu(vec:Vec[Bool], exuConfig: ExuConfig): Vec[Bool] = 607 partialSelect(vec, exuConfig.exceptionOut) 608 def selectByExu(vec:Vec[Bool], exuConfigs: Seq[ExuConfig]): Vec[Bool] = 609 partialSelect(vec, exuConfigs.map(_.exceptionOut).reduce(_ ++ _).distinct.sorted) 610 } 611 612 def dividerGen(p: Parameters) = new DividerWrapper(p(XLen))(p) 613 def multiplierGen(p: Parameters) = new ArrayMultiplier(p(XLen) + 1)(p) 614 def aluGen(p: Parameters) = new Alu()(p) 615 def bkuGen(p: Parameters) = new Bku()(p) 616 def jmpGen(p: Parameters) = new Jump()(p) 617 def fenceGen(p: Parameters) = new Fence()(p) 618 def csrGen(p: Parameters) = new CSR()(p) 619 def i2fGen(p: Parameters) = new IntToFP()(p) 620 def fmacGen(p: Parameters) = new FMA()(p) 621 def f2iGen(p: Parameters) = new FPToInt()(p) 622 def f2fGen(p: Parameters) = new FPToFP()(p) 623 def fdivSqrtGen(p: Parameters) = new FDivSqrt()(p) 624 def stdGen(p: Parameters) = new Std()(p) 625 def mouDataGen(p: Parameters) = new Std()(p) 626 def vipuGen(p: Parameters) = new VIPU()(p) 627 def vppuGen(p: Parameters) = new VPPU()(p) 628 def vfpuGen(p: Parameters) = new VFPU()(p) 629 630 def f2iSel(uop: MicroOp): Bool = { 631 uop.ctrl.rfWen 632 } 633 634 def i2fSel(uop: MicroOp): Bool = { 635 uop.ctrl.fpu.fromInt 636 } 637 638 def f2fSel(uop: MicroOp): Bool = { 639 val ctrl = uop.ctrl.fpu 640 ctrl.fpWen && !ctrl.div && !ctrl.sqrt 641 } 642 643 def fdivSqrtSel(uop: MicroOp): Bool = { 644 val ctrl = uop.ctrl.fpu 645 ctrl.div || ctrl.sqrt 646 } 647 648 val aluCfg = FuConfig( 649 name = "alu", 650 fuGen = aluGen, 651 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.alu, 652 fuType = FuType.alu, 653 numIntSrc = 2, 654 numFpSrc = 0, 655 writeIntRf = true, 656 writeFpRf = false, 657 hasRedirect = true, 658 ) 659 660 val jmpCfg = FuConfig( 661 name = "jmp", 662 fuGen = jmpGen, 663 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.jmp, 664 fuType = FuType.jmp, 665 numIntSrc = 1, 666 numFpSrc = 0, 667 writeIntRf = true, 668 writeFpRf = false, 669 hasRedirect = true, 670 ) 671 672 val fenceCfg = FuConfig( 673 name = "fence", 674 fuGen = fenceGen, 675 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.fence, 676 FuType.fence, 2, 0, writeIntRf = false, writeFpRf = false, 677 latency = UncertainLatency(), exceptionOut = Seq(illegalInstr), // TODO: need rewrite latency structure, not just this value, 678 flushPipe = true 679 ) 680 681 val csrCfg = FuConfig( 682 name = "csr", 683 fuGen = csrGen, 684 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.csr, 685 fuType = FuType.csr, 686 numIntSrc = 1, 687 numFpSrc = 0, 688 writeIntRf = true, 689 writeFpRf = false, 690 exceptionOut = Seq(illegalInstr, breakPoint, ecallU, ecallS, ecallM), 691 flushPipe = true 692 ) 693 694 val i2fCfg = FuConfig( 695 name = "i2f", 696 fuGen = i2fGen, 697 fuSel = i2fSel, 698 FuType.i2f, 699 numIntSrc = 1, 700 numFpSrc = 0, 701 writeIntRf = false, 702 writeFpRf = true, 703 writeFflags = true, 704 latency = CertainLatency(2), 705 fastUopOut = true, fastImplemented = true 706 ) 707 708 val divCfg = FuConfig( 709 name = "div", 710 fuGen = dividerGen, 711 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.div, 712 FuType.div, 713 2, 714 0, 715 writeIntRf = true, 716 writeFpRf = false, 717 latency = UncertainLatency(), 718 fastUopOut = true, 719 fastImplemented = true, 720 hasInputBuffer = (true, 4, true) 721 ) 722 723 val mulCfg = FuConfig( 724 name = "mul", 725 fuGen = multiplierGen, 726 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.mul, 727 FuType.mul, 728 2, 729 0, 730 writeIntRf = true, 731 writeFpRf = false, 732 latency = CertainLatency(2), 733 fastUopOut = true, 734 fastImplemented = true 735 ) 736 737 val bkuCfg = FuConfig( 738 name = "bku", 739 fuGen = bkuGen, 740 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.bku, 741 fuType = FuType.bku, 742 numIntSrc = 2, 743 numFpSrc = 0, 744 writeIntRf = true, 745 writeFpRf = false, 746 latency = CertainLatency(1), 747 fastUopOut = true, 748 fastImplemented = true 749 ) 750 751 val fmacCfg = FuConfig( 752 name = "fmac", 753 fuGen = fmacGen, 754 fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.fmac, 755 FuType.fmac, 0, 3, writeIntRf = false, writeFpRf = true, writeFflags = true, 756 latency = UncertainLatency(), fastUopOut = true, fastImplemented = true 757 ) 758 759 val f2iCfg = FuConfig( 760 name = "f2i", 761 fuGen = f2iGen, 762 fuSel = f2iSel, 763 FuType.fmisc, 0, 1, writeIntRf = true, writeFpRf = false, writeFflags = true, latency = CertainLatency(2), 764 fastUopOut = true, fastImplemented = true 765 ) 766 767 val f2fCfg = FuConfig( 768 name = "f2f", 769 fuGen = f2fGen, 770 fuSel = f2fSel, 771 FuType.fmisc, 0, 1, writeIntRf = false, writeFpRf = true, writeFflags = true, latency = CertainLatency(2), 772 fastUopOut = true, fastImplemented = true 773 ) 774 775 val fdivSqrtCfg = FuConfig( 776 name = "fdivSqrt", 777 fuGen = fdivSqrtGen, 778 fuSel = fdivSqrtSel, 779 FuType.fDivSqrt, 0, 2, writeIntRf = false, writeFpRf = true, writeFflags = true, latency = UncertainLatency(), 780 fastUopOut = true, fastImplemented = true, hasInputBuffer = (true, 8, true) 781 ) 782 783 val lduCfg = FuConfig( 784 "ldu", 785 null, // DontCare 786 (uop: MicroOp) => FuType.loadCanAccept(uop.ctrl.fuType), 787 FuType.ldu, 1, 0, writeIntRf = true, writeFpRf = true, 788 latency = UncertainLatency(), 789 exceptionOut = Seq(loadAddrMisaligned, loadAccessFault, loadPageFault), 790 flushPipe = true, 791 replayInst = true, 792 hasLoadError = true 793 ) 794 795 val staCfg = FuConfig( 796 "sta", 797 null, 798 (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType), 799 FuType.stu, 1, 0, writeIntRf = false, writeFpRf = false, 800 latency = UncertainLatency(), 801 exceptionOut = Seq(storeAddrMisaligned, storeAccessFault, storePageFault) 802 ) 803 804 val stdCfg = FuConfig( 805 "std", 806 fuGen = stdGen, fuSel = (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType), FuType.stu, 1, 1, 807 writeIntRf = false, writeFpRf = false, latency = CertainLatency(1) 808 ) 809 810 val mouCfg = FuConfig( 811 "mou", 812 null, 813 (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType), 814 FuType.mou, 1, 0, writeIntRf = false, writeFpRf = false, 815 latency = UncertainLatency(), exceptionOut = lduCfg.exceptionOut ++ staCfg.exceptionOut 816 ) 817 818 val mouDataCfg = FuConfig( 819 "mou", 820 mouDataGen, 821 (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType), 822 FuType.mou, 1, 0, writeIntRf = false, writeFpRf = false, 823 latency = UncertainLatency() 824 ) 825 826 val vipuCfg = FuConfig( 827 name = "vipu", 828 fuGen = vipuGen, 829 fuSel = (uop: MicroOp) => FuType.vipu === uop.ctrl.fuType, 830 fuType = FuType.vipu, 831 numIntSrc = 0, numFpSrc = 0, writeIntRf = false, writeFpRf = false, writeFflags = false, 832 numVecSrc = 2, writeVecRf = true, 833 fastUopOut = false, // TODO: check 834 fastImplemented = true, //TODO: check 835 ) 836 837 val vppuCfg = FuConfig( 838 name = "vppu", 839 fuGen = vppuGen, 840 fuSel = (uop: MicroOp) => FuType.vppu === uop.ctrl.fuType, 841 fuType = FuType.vppu, 842 numIntSrc = 0, numFpSrc = 1, writeIntRf = false, writeFpRf = false, writeFflags = false, 843 numVecSrc = 1, writeVecRf = true, 844 fastUopOut = false, // TODO: check 845 fastImplemented = true, //TODO: check 846 ) 847 848 val vfpuCfg = FuConfig( 849 name = "vfpu", 850 fuGen = vfpuGen, 851 fuSel = (uop: MicroOp) => FuType.vfpu === uop.ctrl.fuType, 852 fuType = FuType.vfpu, 853 numIntSrc = 0, numFpSrc = 1, writeIntRf = false, writeFpRf = false, writeFflags = true, 854 numVecSrc = 2, writeVecRf = true, 855 fastUopOut = false, // TODO: check 856 fastImplemented = true, //TODO: check 857 // latency = CertainLatency(2) 858 ) 859 860 val JumpExeUnitCfg = ExuConfig("JmpExeUnit", "Int", Seq(jmpCfg, i2fCfg), 2, Int.MaxValue) 861 val AluExeUnitCfg = ExuConfig("AluExeUnit", "Int", Seq(aluCfg), 0, Int.MaxValue) 862 val JumpCSRExeUnitCfg = ExuConfig("JmpCSRExeUnit", "Int", Seq(jmpCfg, csrCfg, fenceCfg, i2fCfg), 2, Int.MaxValue) 863 val MulDivExeUnitCfg = ExuConfig("MulDivExeUnit", "Int", Seq(mulCfg, divCfg, bkuCfg), 1, Int.MaxValue) 864 val FmacExeUnitCfg = ExuConfig("FmacExeUnit", "Fp", Seq(fmacCfg, vipuCfg, vppuCfg, vfpuCfg), Int.MaxValue, 0) 865 val FmiscExeUnitCfg = ExuConfig( 866 "FmiscExeUnit", 867 "Fp", 868 Seq(f2iCfg, f2fCfg, fdivSqrtCfg), 869 Int.MaxValue, 1 870 ) 871 val LdExeUnitCfg = ExuConfig("LoadExu", "Mem", Seq(lduCfg), wbIntPriority = 0, wbFpPriority = 0, extendsExu = false) 872 val StaExeUnitCfg = ExuConfig("StaExu", "Mem", Seq(staCfg, mouCfg), wbIntPriority = Int.MaxValue, wbFpPriority = Int.MaxValue, extendsExu = false) 873 val StdExeUnitCfg = ExuConfig("StdExu", "Mem", Seq(stdCfg, mouDataCfg), wbIntPriority = Int.MaxValue, wbFpPriority = Int.MaxValue, extendsExu = false) 874 875 // def jumpRSWrapperGen(p: Parameters) = new JumpRSWrapper()(p) 876 // def mulRSWrapperGen(p: Parameters) = new MulRSWrapper()(p) 877 // def loadRSWrapperGen(p: Parameters) = new LoadRSWrapper()(p) 878 // def stdRSWrapperGen(p: Parameters) = new StdRSWrapper()(p) 879 // def staRSWrapperGen(p: Parameters) = new StaRSWrapper()(p) 880 // def fmaRSWrapperGen(p: Parameters) = new FMARSWrapper()(p) 881 // def fmiscRSWrapperGen(p: Parameters) = new FMiscRSWrapper()(p) 882 883 val aluRSMod = new RSMod( 884 rsWrapperGen = (modGen: RSMod, p: Parameters) => new ALURSWrapper(modGen)(p), 885 rsGen = (a: RSParams, b: Parameters) => new ALURS(a)(b), 886 immExtractorGen = (src: Int, width: Int, p: Parameters) => new AluImmExtractor()(p) 887 ) 888 val fmaRSMod = new RSMod( 889 rsWrapperGen = (modGen: RSMod, p: Parameters) => new FMARSWrapper(modGen)(p), 890 rsGen = (a: RSParams, b: Parameters) => new FMARS(a)(b), 891 ) 892 val fmiscRSMod = new RSMod( 893 rsWrapperGen = (modGen: RSMod, p: Parameters) => new FMiscRSWrapper(modGen)(p), 894 rsGen = (a: RSParams, b: Parameters) => new FMiscRS(a)(b), 895 ) 896 val jumpRSMod = new RSMod( 897 rsWrapperGen = (modGen: RSMod, p: Parameters) => new JumpRSWrapper(modGen)(p), 898 rsGen = (a: RSParams, b: Parameters) => new JumpRS(a)(b), 899 immExtractorGen = (src: Int, width: Int, p: Parameters) => new JumpImmExtractor()(p) 900 ) 901 val loadRSMod = new RSMod( 902 rsWrapperGen = (modGen: RSMod, p: Parameters) => new LoadRSWrapper(modGen)(p), 903 rsGen = (a: RSParams, b: Parameters) => new LoadRS(a)(b), 904 immExtractorGen = (src: Int, width: Int, p: Parameters) => new LoadImmExtractor()(p) 905 ) 906 val mulRSMod = new RSMod( 907 rsWrapperGen = (modGen: RSMod, p: Parameters) => new MulRSWrapper(modGen)(p), 908 rsGen = (a: RSParams, b: Parameters) => new MulRS(a)(b), 909 immExtractorGen = (src: Int, width: Int, p: Parameters) => new MduImmExtractor()(p) 910 ) 911 val staRSMod = new RSMod( 912 rsWrapperGen = (modGen: RSMod, p: Parameters) => new StaRSWrapper(modGen)(p), 913 rsGen = (a: RSParams, b: Parameters) => new StaRS(a)(b), 914 ) 915 val stdRSMod = new RSMod( 916 rsWrapperGen = (modGen: RSMod, p: Parameters) => new StdRSWrapper(modGen)(p), 917 rsGen = (a: RSParams, b: Parameters) => new StdRS(a)(b), 918 ) 919} 920