Skip to content

Commit

Permalink
Decouple LMUL and NFIELDS to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed Dec 16, 2024
1 parent 20200cc commit 52cd473
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 75 deletions.
44 changes: 44 additions & 0 deletions Makefrag
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,24 @@ tests = \
vloxseg2ei32_v-0 \
vloxseg2ei32_v-1 \
vloxseg2ei64_v-0 \
vloxseg2ei64_v-1 \
vloxseg2ei8_v-0 \
vloxseg2ei8_v-1 \
vloxseg3ei16_v-0 \
vloxseg3ei16_v-1 \
vloxseg3ei32_v-0 \
vloxseg3ei32_v-1 \
vloxseg3ei64_v-0 \
vloxseg3ei8_v-0 \
vloxseg3ei8_v-1 \
vloxseg4ei16_v-0 \
vloxseg4ei16_v-1 \
vloxseg4ei32_v-0 \
vloxseg4ei32_v-1 \
vloxseg4ei64_v-0 \
vloxseg4ei64_v-1 \
vloxseg4ei8_v-0 \
vloxseg4ei8_v-1 \
vloxseg5ei16_v-0 \
vloxseg5ei32_v-0 \
vloxseg5ei64_v-0 \
Expand Down Expand Up @@ -553,17 +561,25 @@ tests = \
vlseg8e8_v-0 \
vlseg8e8ff_v-0 \
vlsseg2e16_v-0 \
vlsseg2e16_v-1 \
vlsseg2e32_v-0 \
vlsseg2e32_v-1 \
vlsseg2e64_v-0 \
vlsseg2e64_v-1 \
vlsseg2e8_v-0 \
vlsseg2e8_v-1 \
vlsseg3e16_v-0 \
vlsseg3e32_v-0 \
vlsseg3e64_v-0 \
vlsseg3e8_v-0 \
vlsseg4e16_v-0 \
vlsseg4e16_v-1 \
vlsseg4e32_v-0 \
vlsseg4e32_v-1 \
vlsseg4e64_v-0 \
vlsseg4e64_v-1 \
vlsseg4e8_v-0 \
vlsseg4e8_v-1 \
vlsseg5e16_v-0 \
vlsseg5e32_v-0 \
vlsseg5e64_v-0 \
Expand Down Expand Up @@ -592,16 +608,24 @@ tests = \
vluxseg2ei32_v-0 \
vluxseg2ei32_v-1 \
vluxseg2ei64_v-0 \
vluxseg2ei64_v-1 \
vluxseg2ei8_v-0 \
vluxseg2ei8_v-1 \
vluxseg3ei16_v-0 \
vluxseg3ei16_v-1 \
vluxseg3ei32_v-0 \
vluxseg3ei32_v-1 \
vluxseg3ei64_v-0 \
vluxseg3ei8_v-0 \
vluxseg3ei8_v-1 \
vluxseg4ei16_v-0 \
vluxseg4ei16_v-1 \
vluxseg4ei32_v-0 \
vluxseg4ei32_v-1 \
vluxseg4ei64_v-0 \
vluxseg4ei64_v-1 \
vluxseg4ei8_v-0 \
vluxseg4ei8_v-1 \
vluxseg5ei16_v-0 \
vluxseg5ei32_v-0 \
vluxseg5ei64_v-0 \
Expand Down Expand Up @@ -1173,6 +1197,7 @@ tests = \
vsoxseg2ei16_v-0 \
vsoxseg2ei16_v-1 \
vsoxseg2ei32_v-0 \
vsoxseg2ei32_v-1 \
vsoxseg2ei64_v-0 \
vsoxseg2ei8_v-0 \
vsoxseg2ei8_v-1 \
Expand All @@ -1181,9 +1206,12 @@ tests = \
vsoxseg3ei64_v-0 \
vsoxseg3ei8_v-0 \
vsoxseg4ei16_v-0 \
vsoxseg4ei16_v-1 \
vsoxseg4ei32_v-0 \
vsoxseg4ei32_v-1 \
vsoxseg4ei64_v-0 \
vsoxseg4ei8_v-0 \
vsoxseg4ei8_v-1 \
vsoxseg5ei16_v-0 \
vsoxseg5ei32_v-0 \
vsoxseg5ei64_v-0 \
Expand Down Expand Up @@ -1224,12 +1252,16 @@ tests = \
vsrl_vx-5 \
vsse16_v-0 \
vsse16_v-1 \
vsse16_v-2 \
vsse32_v-0 \
vsse32_v-1 \
vsse32_v-2 \
vsse64_v-0 \
vsse64_v-1 \
vsse64_v-2 \
vsse8_v-0 \
vsse8_v-1 \
vsse8_v-2 \
vsseg2e16_v-0 \
vsseg2e32_v-0 \
vsseg2e64_v-0 \
Expand Down Expand Up @@ -1365,13 +1397,21 @@ tests = \
vssseg2e8_v-0 \
vssseg2e8_v-1 \
vssseg3e16_v-0 \
vssseg3e16_v-1 \
vssseg3e32_v-0 \
vssseg3e32_v-1 \
vssseg3e64_v-0 \
vssseg3e64_v-1 \
vssseg3e8_v-0 \
vssseg3e8_v-1 \
vssseg4e16_v-0 \
vssseg4e16_v-1 \
vssseg4e32_v-0 \
vssseg4e32_v-1 \
vssseg4e64_v-0 \
vssseg4e64_v-1 \
vssseg4e8_v-0 \
vssseg4e8_v-1 \
vssseg5e16_v-0 \
vssseg5e32_v-0 \
vssseg5e64_v-0 \
Expand Down Expand Up @@ -1428,6 +1468,7 @@ tests = \
vsuxseg2ei16_v-0 \
vsuxseg2ei16_v-1 \
vsuxseg2ei32_v-0 \
vsuxseg2ei32_v-1 \
vsuxseg2ei64_v-0 \
vsuxseg2ei8_v-0 \
vsuxseg2ei8_v-1 \
Expand All @@ -1436,9 +1477,12 @@ tests = \
vsuxseg3ei64_v-0 \
vsuxseg3ei8_v-0 \
vsuxseg4ei16_v-0 \
vsuxseg4ei16_v-1 \
vsuxseg4ei32_v-0 \
vsuxseg4ei32_v-1 \
vsuxseg4ei64_v-0 \
vsuxseg4ei8_v-0 \
vsuxseg4ei8_v-1 \
vsuxseg5ei16_v-0 \
vsuxseg5ei32_v-0 \
vsuxseg5ei64_v-0 \
Expand Down
16 changes: 2 additions & 14 deletions generator/insn_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func getEEW(name string) SEW {
return SEW(eew)
}

func getNfieldsRoundedUp(name string) int {
func getNfields(name string) int {
s := regexp.MustCompile(`v.+?seg(\d)e.+?\.v`)
subs := s.FindStringSubmatch(name)
if len(subs) < 2 {
Expand All @@ -127,19 +127,7 @@ func getNfieldsRoundedUp(name string) int {
if err != nil {
return 1
}
switch nfields {
case 1:
return 1
case 2:
return 2
case 3, 4:
return 4
case 5, 6, 7, 8:
return 8
default:
log.Fatalln("unreachable")
return 1
}
return nfields
}

func iff[T any](condition bool, t T, f T) T {
Expand Down
33 changes: 18 additions & 15 deletions generator/insn_vdrs1mrs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package generator

import (
"fmt"
"math"
"strings"
)

func (i *Insn) genCodeVdRs1mRs2Vm(pos int) []string {
nfields := getNfieldsRoundedUp(i.Name)
nfields := getNfields(i.Name)
combinations := i.combinations(
nfieldsLMULs(nfields),
[]SEW{getEEW(i.Name)},
Expand All @@ -23,27 +22,29 @@ func (i *Insn) genCodeVdRs1mRs2Vm(pos int) []string {
builder.WriteString(i.gWriteRandomData(LMUL(1)))
builder.WriteString(i.gLoadDataIntoRegisterGroup(0, LMUL(1), SEW(32)))

lmul1 := LMUL(math.Max(float64(c.LMUL1)*float64(nfields), 1))
vd, _, _ := getVRegs(lmul1, false, i.Name)
builder.WriteString(i.gWriteRandomData(lmul1))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, lmul1, c.SEW))
builder.WriteString(i.gWriteIntegerTestData(lmul1, c.SEW, 0))
vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
}
builder.WriteString(i.gWriteIntegerTestData(c.LMUL1*LMUL(nfields), c.SEW, 0))

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL))
builder.WriteString(fmt.Sprintf("%s v%d, (a0), zero%s\n", i.Name, vd, v0t(c.Mask)))
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, lmul1, c.SEW))
builder.WriteString(i.gMagicInsn(vd, lmul1))
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW))
builder.WriteString(i.gMagicInsn(vd, c.LMUL1))

for _, stride := range []int{minStride, 0, 1, maxStride} {
stride = stride * int(c.SEW) / 8
builder.WriteString(i.gWriteRandomData(lmul1))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, lmul1, c.SEW))
builder.WriteString(i.gWriteIntegerTestData(lmul1*strides, c.SEW, 0))

builder.WriteString(i.gWriteRandomData(c.LMUL1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
}
builder.WriteString(i.gWriteIntegerTestData(c.LMUL1*LMUL(nfields*stride), c.SEW, 0))
builder.WriteString(fmt.Sprintf("li a5, %d\n", -minStride*i.vlenb()*int(c.LMUL1)))
builder.WriteString("add a0, a0, a5\n")

Expand All @@ -54,8 +55,10 @@ func (i *Insn) genCodeVdRs1mRs2Vm(pos int) []string {
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, lmul1, c.SEW))
builder.WriteString(i.gMagicInsn(vd, lmul1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
builder.WriteString(i.gMagicInsn(vd+(nf*int(c.LMUL1)), c.LMUL1))
}
}
res = append(res, builder.String())
}
Expand Down
20 changes: 11 additions & 9 deletions generator/insn_vdrs1mvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package generator

import (
"fmt"
"math"
"strings"
)

func (i *Insn) genCodeVdRs1mVm(pos int) []string {
nfields := getNfieldsRoundedUp(i.Name)
nfields := getNfields(i.Name)
combinations := i.combinations(
nfieldsLMULs(nfields),
[]SEW{getEEW(i.Name)},
Expand All @@ -23,20 +22,23 @@ func (i *Insn) genCodeVdRs1mVm(pos int) []string {
builder.WriteString(i.gWriteRandomData(LMUL(1)))
builder.WriteString(i.gLoadDataIntoRegisterGroup(0, LMUL(1), SEW(32)))

lmul1 := LMUL(math.Max(float64(c.LMUL1)*float64(nfields), 1))
vd, _, _ := getVRegs(lmul1, false, i.Name)
builder.WriteString(i.gWriteRandomData(lmul1))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, lmul1, c.SEW))
builder.WriteString(i.gWriteIntegerTestData(lmul1, c.SEW, 0))
vd := int(c.LMUL1)
builder.WriteString(i.gWriteRandomData(c.LMUL1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
}
builder.WriteString(i.gWriteIntegerTestData(c.LMUL1*LMUL(nfields), c.SEW, 0))

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL))
builder.WriteString(fmt.Sprintf("%s v%d, (a0)%s\n", i.Name, vd, v0t(c.Mask)))
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, lmul1, c.SEW))
builder.WriteString(i.gMagicInsn(vd, lmul1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
builder.WriteString(i.gMagicInsn(vd+(nf*int(c.LMUL1)), c.LMUL1))
}

res = append(res, builder.String())
}
Expand Down
32 changes: 21 additions & 11 deletions generator/insn_vdrs1mvs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (i *Insn) genCodeVdRs1mVs2Vm(pos int) []string {
nfields := getNfieldsRoundedUp(i.Name)
nfields := getNfields(i.Name)
combinations := i.combinations(
nfieldsLMULs(nfields),
[]SEW{getEEW(i.Name)},
Expand All @@ -27,30 +27,40 @@ func (i *Insn) genCodeVdRs1mVs2Vm(pos int) []string {
if emul > 8 || emul < 1./8 {
continue
}
emul = math.Max(emul, 1)
emul = math.Max(emul, 1) // offset lmul
builder.WriteString(c.initialize())

builder.WriteString(i.gWriteRandomData(LMUL(1)))
builder.WriteString(i.gLoadDataIntoRegisterGroup(0, LMUL(1), SEW(32)))

lmul1 := LMUL(math.Max(float64(c.LMUL)*float64(nfields), 1))
vd := int(lmul1)
vs2 := 2 * int(math.Max(emul, float64(int(c.LMUL1)*nfields)))
vd := int(c.LMUL1)

builder.WriteString(i.gWriteIndexData(lmul1, LMUL(emul), c.Vl, sew, c.SEW))
vs2 := 0
for k := vd+int(c.LMUL1)*nfields; true; k += 1 {
if k % int(emul) == 0 {
vs2 = k
break
}
}

builder.WriteString(i.gWriteIndexData(c.LMUL1, LMUL(emul), c.Vl, sew, c.SEW))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, LMUL(emul), c.SEW))
builder.WriteString(i.gWriteRandomData(lmul1))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, lmul1, sew))
builder.WriteString(i.gWriteIntegerTestData(lmul1, sew, 0))
builder.WriteString(i.gWriteRandomData(c.LMUL1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(c.LMUL1)), c.LMUL1, sew))
}
builder.WriteString(i.gWriteIntegerTestData(c.LMUL1*LMUL(nfields), sew, 0))

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(i.gVsetvli(c.Vl, sew, c.LMUL))
builder.WriteString(fmt.Sprintf("%s v%d, (a0), v%d%s\n", i.Name, vd, vs2, v0t(c.Mask)))
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, lmul1, sew))
builder.WriteString(i.gMagicInsn(vd, lmul1))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(c.LMUL1)), c.LMUL1, sew))
builder.WriteString(i.gMagicInsn(vd+(nf*int(c.LMUL1)), c.LMUL1))
}
}
res = append(res, builder.String())
}
Expand Down
Loading

0 comments on commit 52cd473

Please sign in to comment.