Skip to content

Commit

Permalink
Add vxsat support (for #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed Jan 9, 2024
1 parent c793e19 commit 4dc7375
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions configs/vnclip.wi.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclip.wi"
format = "vd,vs2,uimm,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclip.wv.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclip.wv"
format = "vd,vs2,vs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclip.wx.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclip.wx"
format = "vd,vs2,rs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclipu.wi.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclipu.wi"
format = "vd,vs2,uimm,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclipu.wv.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclipu.wv"
format = "vd,vs2,vs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclipu.wx.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vnclipu.wx"
format = "vd,vs2,rs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsadd.vi.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsadd.vi"
format = "vd,vs2,imm,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsadd.vv.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsadd.vv"
format = "vd,vs2,vs1,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsadd.vx.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsadd.vx"
format = "vd,vs2,rs1,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsaddu.vi.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsaddu.vi"
format = "vd,vs2,imm,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsaddu.vv.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsaddu.vv"
format = "vd,vs2,vs1,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsaddu.vx.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vsaddu.vx"
format = "vd,vs2,rs1,vm"
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsmul.vv.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vsmul.vv"
format = "vd,vs2,vs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vsmul.vx.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "vsmul.vx"
format = "vd,vs2,rs1,vm"
vxrm = true
vxsat = true

[tests]
base = [
Expand Down
16 changes: 13 additions & 3 deletions generator/insn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
})
}
}
Expand Down
13 changes: 12 additions & 1 deletion generator/insn_g.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions generator/insn_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions pspike/pspike.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static std::vector<std::pair<reg_t, abstract_mem_t*>> 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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 4dc7375

Please sign in to comment.