xref: /XiangShan/src/test/scala/xiangshan/backend/fu/VsetModuleMain.scala (revision 195ef4a53ab54326d879e884c4e1568f424f2668)
1package xiangshan.backend.fu
2
3import chisel3._
4import chiseltest.{ChiselScalatestTester, _}
5import org.scalatest.flatspec.AnyFlatSpec
6import org.scalatest.matchers.must.Matchers
7import top.DefaultConfig
8import xiangshan.backend.fu.vector.Bundles.{VLmul, VSew}
9import xiangshan.{VSETOpType, XSCoreParameters, XSCoreParamsKey, XSTileKey}
10
11class VsetModuleMain extends AnyFlatSpec with ChiselScalatestTester with Matchers {
12
13  val defaultConfig = (new DefaultConfig).alterPartial({
14    case XSCoreParamsKey => XSCoreParameters()
15  })
16
17  def F = false.B
18
19  def T = true.B
20
21  private val ills = Seq(F, T)
22  private val vtas = Seq(F, T)
23  private val vmas = Seq(F, T)
24  private val vsews = Seq(VSew.e8, VSew.e16, VSew.e32, VSew.e64)
25  private val vlmuls = Seq(VLmul.m8, VLmul.m4, VLmul.m2, VLmul.m1, VLmul.mf2, VLmul.mf4, VLmul.mf8)
26  private val avls = Seq(0.U, 1.U, 0x100.U)
27  private val funcs = Seq(VSETOpType.uvsetvcfg_xi,
28                          VSETOpType.uvsetrd_xi,
29                          VSETOpType.uvsetvcfg_vlmax_i,
30                          VSETOpType.uvsetrd_vlmax_i,
31                          VSETOpType.uvsetvcfg_keep_v,
32                          VSETOpType.uvsetvcfg_xx,
33                          VSETOpType.uvsetrd_xx,
34                          VSETOpType.uvsetvcfg_vlmax_x,
35                          VSETOpType.uvsetrd_vlmax_x,
36                          VSETOpType.uvsetvcfg_vv,
37                          VSETOpType.uvsetvcfg_ii,
38                          VSETOpType.uvsetrd_ii)
39  private val oldVls = Seq(0x83.U)
40
41  val inputs = for {
42    ill <- ills
43    vta <- vtas
44    vma <- vmas
45    vsew <- vsews
46    vlmul <- vlmuls
47    func <- funcs
48    avl <- avls
49    oldVl <- oldVls
50  }
51  yield {
52    (ill, vta, vma, vsew, vlmul, func, avl, oldVl)
53  }
54
55
56  println("Test started!")
57
58  behavior of "VsetModule"
59  it should "run" in {
60    test(new VsetTop()(defaultConfig)) { m: VsetTop =>
61      for((ill, vta, vma, vsew, vlmul, func, avl, oldVl) <- inputs) {
62        val (testVl, testVill, testVta, testVma, testVsew, testVlmul) = VsetRef.test(avlPre = avl.litValue.toInt,
63                                                                                     vsew = vsew.litValue.toInt,
64                                                                                     vlmul = vlmul.litValue.toInt,
65                                                                                     vta = vta.litToBoolean,
66                                                                                     vma = vma.litToBoolean,
67                                                                                     villPre = ill.litToBoolean,
68                                                                                     func = func.litValue.toInt,
69                                                                                     oldVL = oldVl.litValue.toInt)
70
71        m.io.in.func.poke(func)
72        m.io.in.avl.poke(avl)
73        m.io.in.vtype.illegal.poke(ill)
74        m.io.in.vtype.vta.poke(vta)
75        m.io.in.vtype.vma.poke(vma)
76        m.io.in.vtype.vsew.poke(vsew)
77        m.io.in.vtype.vlmul.poke(vlmul)
78        m.io.in.oldVl.poke(oldVl)
79
80        val message = " ill: " + ill.litToBoolean +
81                      " vta: " + vta.litToBoolean +
82                      " vma: " + vma.litToBoolean +
83                      " vsew: " + vsew.litValue.toInt +
84                      " vlmul: " + vlmul.litValue.toInt +
85                      " func: " + func.litValue.toInt.toBinaryString +
86                      " avl: " + avl.litValue.toInt
87
88        m.io.out.vconfig.vtype.illegal.expect(testVill.B, message)
89        m.io.out.vconfig.vtype.vta.expect(testVta, message)
90        m.io.out.vconfig.vtype.vma.expect(testVma, message)
91        m.io.out.vconfig.vtype.vsew.expect(testVsew, message)
92        m.io.out.vconfig.vtype.vlmul.expect(testVlmul, message)
93        m.io.out.vconfig.vl.expect(testVl.U, message)
94
95        println(s"illegal: ${m.io.out.vconfig.vtype.illegal.peek().litValue}")
96        println(s"vta: ${m.io.out.vconfig.vtype.vta.peek().litToBoolean} ")
97        println(s"vma: ${m.io.out.vconfig.vtype.vma.peek().litToBoolean} ")
98        println(s"vsew: ${m.io.out.vconfig.vtype.vsew.peek().litValue} ")
99        println(s"vlmul: ${m.io.out.vconfig.vtype.vlmul.peek().litValue} ")
100        println(s"vl: ${m.io.out.vconfig.vl.peek().litValue} ")
101        println("-------------")
102        println(s"fuoptype: ${m.io.debug.fuOpType0.peek().litValue.toInt.toBinaryString} ")
103        println(s"src0: ${m.io.debug.src0(0).peek().litValue.toInt.toBinaryString} ")
104        println(s"src1: ${m.io.debug.src0(1).peek().litValue.toInt.toBinaryString} ")
105        println("-------------")
106        println(s"fuoptype: ${m.io.debug.fuOpType1.peek().litValue.toInt.toBinaryString} ")
107        println(s"src0: ${m.io.debug.src1(0).peek().litValue.toInt.toBinaryString} ")
108        println(s"src1: ${m.io.debug.src1(1).peek().litValue.toInt.toBinaryString} ")
109        println("-------------")
110        println(s"fuoptype: ${m.io.debug.fuOpType2.peek().litValue.toInt.toBinaryString} ")
111        println(s"src0: ${m.io.debug.src2(0).peek().litValue.toInt.toBinaryString} ")
112        println(s"src1: ${m.io.debug.src2(1).peek().litValue.toInt.toBinaryString} ")
113      }
114    }
115  }
116}
117