From 4dc7375d8992fbe44dffc5a6bdff2361d9290808 Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Wed, 10 Jan 2024 00:36:43 +0800 Subject: [PATCH] Add vxsat support (for #20) --- configs/vnclip.wi.toml | 1 + configs/vnclip.wv.toml | 1 + configs/vnclip.wx.toml | 1 + configs/vnclipu.wi.toml | 1 + configs/vnclipu.wv.toml | 1 + configs/vnclipu.wx.toml | 1 + configs/vsadd.vi.toml | 1 + configs/vsadd.vv.toml | 1 + configs/vsadd.vx.toml | 1 + configs/vsaddu.vi.toml | 1 + configs/vsaddu.vv.toml | 1 + configs/vsaddu.vx.toml | 1 + configs/vsmul.vv.toml | 1 + configs/vsmul.vx.toml | 1 + generator/insn.go | 16 +++++++++++++--- generator/insn_g.go | 13 ++++++++++++- generator/insn_util.go | 2 ++ pspike/pspike.cc | 4 ++++ 18 files changed, 45 insertions(+), 4 deletions(-) diff --git a/configs/vnclip.wi.toml b/configs/vnclip.wi.toml index fa7353f..21abeb5 100644 --- a/configs/vnclip.wi.toml +++ b/configs/vnclip.wi.toml @@ -1,6 +1,7 @@ name = "vnclip.wi" format = "vd,vs2,uimm,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vnclip.wv.toml b/configs/vnclip.wv.toml index e7e5d00..0ced9cd 100644 --- a/configs/vnclip.wv.toml +++ b/configs/vnclip.wv.toml @@ -1,6 +1,7 @@ name = "vnclip.wv" format = "vd,vs2,vs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vnclip.wx.toml b/configs/vnclip.wx.toml index ca73c24..e5a2225 100644 --- a/configs/vnclip.wx.toml +++ b/configs/vnclip.wx.toml @@ -1,6 +1,7 @@ name = "vnclip.wx" format = "vd,vs2,rs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vnclipu.wi.toml b/configs/vnclipu.wi.toml index 546146c..62985b5 100644 --- a/configs/vnclipu.wi.toml +++ b/configs/vnclipu.wi.toml @@ -1,6 +1,7 @@ name = "vnclipu.wi" format = "vd,vs2,uimm,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vnclipu.wv.toml b/configs/vnclipu.wv.toml index e550bbc..91968b1 100644 --- a/configs/vnclipu.wv.toml +++ b/configs/vnclipu.wv.toml @@ -1,6 +1,7 @@ name = "vnclipu.wv" format = "vd,vs2,vs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vnclipu.wx.toml b/configs/vnclipu.wx.toml index 4128f0d..3ad6ea0 100644 --- a/configs/vnclipu.wx.toml +++ b/configs/vnclipu.wx.toml @@ -1,6 +1,7 @@ name = "vnclipu.wx" format = "vd,vs2,rs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vsadd.vi.toml b/configs/vsadd.vi.toml index 8ef30a2..7543204 100644 --- a/configs/vsadd.vi.toml +++ b/configs/vsadd.vi.toml @@ -1,5 +1,6 @@ name = "vsadd.vi" format = "vd,vs2,imm,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsadd.vv.toml b/configs/vsadd.vv.toml index f77ad42..1710c5c 100644 --- a/configs/vsadd.vv.toml +++ b/configs/vsadd.vv.toml @@ -1,5 +1,6 @@ name = "vsadd.vv" format = "vd,vs2,vs1,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsadd.vx.toml b/configs/vsadd.vx.toml index e5079f1..2edd00d 100644 --- a/configs/vsadd.vx.toml +++ b/configs/vsadd.vx.toml @@ -1,5 +1,6 @@ name = "vsadd.vx" format = "vd,vs2,rs1,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsaddu.vi.toml b/configs/vsaddu.vi.toml index 0be15ad..c738eb7 100644 --- a/configs/vsaddu.vi.toml +++ b/configs/vsaddu.vi.toml @@ -1,5 +1,6 @@ name = "vsaddu.vi" format = "vd,vs2,imm,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsaddu.vv.toml b/configs/vsaddu.vv.toml index 01719fb..f9597e0 100644 --- a/configs/vsaddu.vv.toml +++ b/configs/vsaddu.vv.toml @@ -1,5 +1,6 @@ name = "vsaddu.vv" format = "vd,vs2,vs1,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsaddu.vx.toml b/configs/vsaddu.vx.toml index 54bb633..6adeb47 100644 --- a/configs/vsaddu.vx.toml +++ b/configs/vsaddu.vx.toml @@ -1,5 +1,6 @@ name = "vsaddu.vx" format = "vd,vs2,rs1,vm" +vxsat = true [tests] base = [ diff --git a/configs/vsmul.vv.toml b/configs/vsmul.vv.toml index d1ff93e..addac0f 100644 --- a/configs/vsmul.vv.toml +++ b/configs/vsmul.vv.toml @@ -1,6 +1,7 @@ name = "vsmul.vv" format = "vd,vs2,vs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/configs/vsmul.vx.toml b/configs/vsmul.vx.toml index f9c2412..70f5f73 100644 --- a/configs/vsmul.vx.toml +++ b/configs/vsmul.vx.toml @@ -1,6 +1,7 @@ name = "vsmul.vx" format = "vd,vs2,rs1,vm" vxrm = true +vxsat = true [tests] base = [ diff --git a/generator/insn.go b/generator/insn.go index 2e6eedf..83f3687 100644 --- a/generator/insn.go +++ b/generator/insn.go @@ -54,6 +54,7 @@ type Insn struct { Name string `toml:"name"` Format insnFormat `toml:"format"` Vxrm bool `toml:"vxrm"` + Vxsat bool `toml:"vxsat"` Tests tests `toml:"tests"` Option Option `toml:"-"` TestData *TestData @@ -439,18 +440,26 @@ type combination struct { Vl int Mask bool VXRM VXRM + VXSAT VXSAT } func (c *combination) initialize() string { - // write comments, set vxrm - return fmt.Sprintf(` + // write comments, set vxrm, clear vxsat if necessary + str := fmt.Sprintf(` # Generating tests for VL: %d, LMUL: %s, SEW: %s, Mask: %v -# Initialize vxrm CSR. +# Initialize vxrm CSR csrwi vxrm, %d # %s `, c.Vl, c.LMUL.String(), c.SEW.String(), c.Mask, c.VXRM, c.VXRM) + if c.VXSAT { + str = fmt.Sprintf(`%s# Clear vxsat CSR +csrci vxsat, 1 + +`, str) + } + return str } func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool, vxrms []VXRM) []combination { @@ -475,6 +484,7 @@ func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool, vxrms []VXRM Vl: vl, Mask: mask, VXRM: vxrm, + VXSAT: VXSAT(i.Vxsat), }) } } diff --git a/generator/insn_g.go b/generator/insn_g.go index ca22086..080448d 100644 --- a/generator/insn_g.go +++ b/generator/insn_g.go @@ -122,7 +122,18 @@ func (i *Insn) gMoveScalarToVector(scalar string, vector int, sew SEW) string { } func (i *Insn) gMagicInsn(group int) string { - insn := 0b0001011 + (group&0b11111)<<15 + + // opcode + insn := 0b0001011 + + // rs1 for vreg group + insn += (group & 0b11111) << 15 + + // rs2[0] for vxsat CSR + if i.Vxsat { + insn += 1 << 20 + } + return fmt.Sprintf(".word 0x%x\n", insn) } diff --git a/generator/insn_util.go b/generator/insn_util.go index 6eef0d6..dc673a6 100644 --- a/generator/insn_util.go +++ b/generator/insn_util.go @@ -22,6 +22,8 @@ func (v VXRM) String() string { return vxrmNames[v] } +type VXSAT bool + type SEW int var allSEWs = []SEW{8, 16, 32, 64} diff --git a/pspike/pspike.cc b/pspike/pspike.cc index c9bffd2..563d154 100644 --- a/pspike/pspike.cc +++ b/pspike/pspike.cc @@ -20,6 +20,7 @@ static std::vector> make_mems(const std::vecto static reg_t magic_insn(processor_t* p, insn_t insn, reg_t pc) { static int ncase = 2; int group = insn.rs1(); + bool vxsat = insn.rs2() & 0x1; for (int reg = group; reg < 2*group; reg++) { for (int i = 0; i < p->VU.VLEN / p->get_xlen(); i++) { if (p->get_xlen() == 64) { @@ -35,6 +36,9 @@ static reg_t magic_insn(processor_t* p, insn_t insn, reg_t pc) { } } } + if (vxsat) { + printf(" TEST_CASE(%d, t0, 0x%lx, csrr t0, vxsat)\n", ncase++, p->get_csr(0x009)); + } printf("---\n"); return pc + 4; }