Skip to content
79 changes: 49 additions & 30 deletions generator/insn_vdrs1mrs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generator
import (
"fmt"
"strings"
"math"
)

func (i *Insn) genCodeVdRs1mRs2Vm(pos int) []string {
Expand All @@ -17,47 +18,65 @@ func (i *Insn) genCodeVdRs1mRs2Vm(pos int) []string {

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

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

vd := int(c.LMUL1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why there are so many changes in the following code. When SEW != EEW, there is only 1 thing changed, which is the EMUL.

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))
var sew SEW = 8 // sew is data width, c.SEW is offset width
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no offset width in unit-stride and constant-stride instructions.

for ; sew <= SEW(i.Option.XLEN); sew <<= 1 {
if int(sew) > int(float64(i.Option.XLEN)*float64(c.LMUL)) {
continue
}
emul := (float64(c.SEW) / float64(sew)) * float64(c.LMUL) * float64(nfields)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not emul.

if emul > 8 || emul < 1./8 {
continue
}
emul = math.Max(emul, 1) // offset lmul
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used.

builder.WriteString(c.initialize())

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.gWriteRandomData(LMUL(1)))
builder.WriteString(i.gLoadDataIntoRegisterGroup(0, LMUL(1), SEW(32)))

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW))
builder.WriteString(i.gMagicInsn(vd, c.LMUL1))
lmul1 := LMUL(math.Max((float64(c.SEW)/float64(sew))*float64(c.LMUL), 1))
vd := int(lmul1)

for _, stride := range []int{minStride, 0, 1, maxStride} {
stride = stride * int(c.SEW) / 8
builder.WriteString(i.gWriteRandomData(c.LMUL1))
builder.WriteString(i.gWriteIntegerTestData(lmul1*LMUL(nfields), sew, 0))
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(c.LMUL1)), c.LMUL1, c.SEW))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd+(nf*int(lmul1)), lmul1, sew))
builder.WriteString(fmt.Sprintf("li a5, %d\n", i.vlenb()*int(lmul1)))
builder.WriteString("add a0, a0, a5\n")
}
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")

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(fmt.Sprintf("li s0, %d # stride\n", stride))
builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL))
builder.WriteString(fmt.Sprintf("%s v%d, (a0), s0%s\n", i.Name, vd, v0t(c.Mask)))
builder.WriteString(i.gVsetvli(c.Vl, 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())
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))
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(lmul1)), lmul1, sew))
builder.WriteString(i.gMagicInsn(vd+(nf*int(lmul1)), lmul1))
}

for _, stride := range []int{minStride, 0, 1, maxStride} {
stride = stride * int(c.SEW) / 8

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

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

builder.WriteString(i.gResultDataAddr())
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(lmul1)), lmul1, sew))
builder.WriteString(i.gMagicInsn(vd+(nf*int(lmul1)), lmul1))
}
}
}
res = append(res, builder.String())
Expand Down
57 changes: 36 additions & 21 deletions generator/insn_vdrs1mvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generator
import (
"fmt"
"strings"
"math"
)

func (i *Insn) genCodeVdRs1mVm(pos int) []string {
Expand All @@ -17,27 +18,41 @@ func (i *Insn) genCodeVdRs1mVm(pos int) []string {

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

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

vd := int(c.LMUL1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why there are so many changes in the following code. When SEW != EEW, there is only 1 thing changed, which is the EMUL.

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())
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))
var sew SEW = 8 // sew is data width, c.SEW is offset width
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no offset width in unit-stride and constant-stride instructions.

for ; sew <= SEW(i.Option.XLEN); sew <<= 1 {
if int(sew) > int(float64(i.Option.XLEN)*float64(c.LMUL)) {
continue
}
emul := (float64(c.SEW) / float64(sew)) * float64(c.LMUL) * float64(nfields)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not emul.

if emul > 8 || emul < 1./8 {
continue
}
emul = math.Max(emul, 1) // offset lmul
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used.

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.SEW)/float64(sew))*float64(c.LMUL), 1))
vd := int(lmul1)

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

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(i.gVsetvli(c.Vl, 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())
for nf := 0; nf < nfields; nf++ {
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd+(nf*int(lmul1)), lmul1, sew))
builder.WriteString(i.gMagicInsn(vd+(nf*int(lmul1)), lmul1))
}
}

res = append(res, builder.String())
Expand Down