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