Skip to content

Commit

Permalink
Add vxrm to the combination (for #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed Dec 20, 2023
1 parent 5f56f7a commit 5991f7f
Show file tree
Hide file tree
Showing 60 changed files with 331 additions and 84 deletions.
181 changes: 181 additions & 0 deletions Makefrag

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions configs/vaadd.vv.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vaadd.vv"
format = "vd,vs2,vs1,vm"
vxrm = true

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

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

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

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

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

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

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

[tests]
base = [
Expand Down
1 change: 1 addition & 0 deletions configs/vnclip.wi.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "vnclip.wi"
format = "vd,vs2,uimm,vm"
vxrm = 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,5 +1,6 @@
name = "vnclip.wv"
format = "vd,vs2,vs1,vm"
vxrm = 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,5 +1,6 @@
name = "vnclip.wx"
format = "vd,vs2,rs1,vm"
vxrm = 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,5 +1,6 @@
name = "vnclipu.wi"
format = "vd,vs2,uimm,vm"
vxrm = 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,5 +1,6 @@
name = "vnclipu.wv"
format = "vd,vs2,vs1,vm"
vxrm = 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,5 +1,6 @@
name = "vnclipu.wx"
format = "vd,vs2,rs1,vm"
vxrm = 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,5 +1,6 @@
name = "vsmul.vv"
format = "vd,vs2,vs1,vm"
vxrm = 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,5 +1,6 @@
name = "vsmul.vx"
format = "vd,vs2,rs1,vm"
vxrm = true

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

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

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

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

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

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

[tests]
base = [
Expand Down
45 changes: 30 additions & 15 deletions generator/insn.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (t *TestData) String() string {
type Insn struct {
Name string `toml:"name"`
Format insnFormat `toml:"format"`
Vxrm bool `toml:"vxrm"`
Tests tests `toml:"tests"`
Option Option `toml:"-"`
TestData *TestData
Expand Down Expand Up @@ -437,18 +438,22 @@ type combination struct {
LMUL1 LMUL
Vl int
Mask bool
VXRM VXRM
}

func (c *combination) comment() string {
return fmt.Sprintf(
"\n\n# Generating tests for VL: %d, LMUL: %s, SEW: %s, Mask: %v\n\n",
c.Vl,
c.LMUL.String(),
c.SEW.String(),
c.Mask)
func (c *combination) initialize() string {
// write comments, set vxrm
return fmt.Sprintf(`
# Generating tests for VL: %d, LMUL: %s, SEW: %s, Mask: %v
# Initialize vxrm CSR.
csrwi vxrm, %d # %s
`,
c.Vl, c.LMUL.String(), c.SEW.String(), c.Mask, c.VXRM, c.VXRM)
}

func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool) []combination {
func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool, vxrms []VXRM) []combination {
res := make([]combination, 0)
for _, lmul := range lmuls {
for _, sew := range sews {
Expand All @@ -462,13 +467,16 @@ func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool) []combinatio
for _, mask := range masks {
vlmax1 := int((float64(i.Option.VLEN) / float64(sew)) * float64(lmul1))
for _, vl := range []int{0, vlmax1 / 2, vlmax1, vlmax1 + 1} {
res = append(res, combination{
SEW: sew,
LMUL: lmul,
LMUL1: lmul1,
Vl: vl,
Mask: mask,
})
for _, vxrm := range vxrms {
res = append(res, combination{
SEW: sew,
LMUL: lmul,
LMUL1: lmul1,
Vl: vl,
Mask: mask,
VXRM: vxrm,
})
}
}
}
}
Expand All @@ -477,6 +485,13 @@ func (i *Insn) combinations(lmuls []LMUL, sews []SEW, masks []bool) []combinatio
return res
}

func (i *Insn) vxrms() []VXRM {
if i.Vxrm {
return allVXRMs
}
return noVXRMs
}

type vsetvlicombinations struct {
SEW SEW
LMUL LMUL
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_fdvs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

func (i *Insn) genCodeFdVs2(pos int) []string {
combinations := i.combinations([]LMUL{1}, floatSEWs, []bool{false})
combinations := i.combinations([]LMUL{1}, floatSEWs, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
vs2 := int(c.LMUL1) * 2
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_rdvs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

func (i *Insn) genCodeRdVs2(pos int) []string {
combinations := i.combinations([]LMUL{1}, allSEWs, []bool{false})
combinations := i.combinations([]LMUL{1}, allSEWs, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
vs2 := int(c.LMUL1) * 2
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_rdvs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

func (i *Insn) genCodeRdVs2Vm(pos int) []string {
combinations := i.combinations([]LMUL{1}, []SEW{8}, []bool{false, true})
combinations := i.combinations([]LMUL{1}, []SEW{8}, []bool{false, true}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
vs2 := int(c.LMUL1) * 2
Expand Down
20 changes: 15 additions & 5 deletions generator/insn_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ import (
"log"
"regexp"
"strconv"
"strings"
)

type VXRM int

var allVXRMs = []VXRM{0, 1, 2, 3}
var noVXRMs = []VXRM{0}
var vxrmNames = map[VXRM]string{
allVXRMs[0]: "rnu (round-to-nearest-up)",
allVXRMs[1]: "rne (round-to-nearest-even)",
allVXRMs[2]: "rdn (round-down (truncate))",
allVXRMs[3]: "rod round-to-odd (OR bits into LSB, aka \"jam\")",
}

func (v VXRM) String() string {
return vxrmNames[v]
}

type SEW int

var allSEWs = []SEW{8, 16, 32, 64}
Expand Down Expand Up @@ -82,10 +96,6 @@ func v0t(mask bool) string {
return ""
}

func trimBoth(name, prefix, suffix string) string {
return strings.TrimSuffix(strings.TrimPrefix(name, prefix), suffix)
}

func getEEW(name string) SEW {
s := regexp.MustCompile(`v.+?(\d+)f*\.v`)
eew, err := strconv.Atoi(s.FindStringSubmatch(name)[1])
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_vdfs1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

func (i *Insn) genCodeVdFs1(pos int) []string {
lmuls := iff(strings.HasSuffix(i.Name, ".s.f"), []LMUL{1}, allLMULs)
combinations := i.combinations(lmuls, floatSEWs, []bool{false})
combinations := i.combinations(lmuls, floatSEWs, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
Expand Down
3 changes: 2 additions & 1 deletion generator/insn_vdfs1vs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ func (i *Insn) genCodeVdFs1Vs2Vm(pos int) []string {
iff(vdWidening, wideningMULs, allLMULs),
sews,
[]bool{false, true},
i.vxrms(),
)
res := make([]string, 0, len(combinations))

for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

builder.WriteString(i.gWriteRandomData(LMUL(1)))
builder.WriteString(i.gLoadDataIntoRegisterGroup(0, LMUL(1), SEW(32)))
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_vdimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

func (i *Insn) genCodeVdImm(pos int) []string {
combinations := i.combinations(allLMULs, allSEWs, []bool{false})
combinations := i.combinations(allLMULs, allSEWs, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_vdrs1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

func (i *Insn) genCodeVdRs1(pos int) []string {
lmuls := iff(strings.HasSuffix(i.Name, ".s.x"), []LMUL{1}, allLMULs)
combinations := i.combinations(lmuls, allSEWs, []bool{false})
combinations := i.combinations(lmuls, allSEWs, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
Expand Down
4 changes: 2 additions & 2 deletions generator/insn_vdrs1m.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func (i *Insn) genCodeVdRs1m(pos int) []string {
lmuls = []LMUL{LMUL(nfields)}
sews = []SEW{SEW(eew)}
}
combinations := i.combinations(lmuls, sews, []bool{false})
combinations := i.combinations(lmuls, sews, []bool{false}, i.vxrms())

res := make([]string, 0, len(combinations))

for _, c := range combinations[pos:] {
builder := strings.Builder{}
builder.WriteString(c.comment())
builder.WriteString(c.initialize())

vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
Expand Down
Loading

0 comments on commit 5991f7f

Please sign in to comment.