Skip to content

Commit

Permalink
Refine indexed load/store for #12
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed Sep 27, 2023
1 parent 0aaf2c7 commit 86e80cd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 54 deletions.
10 changes: 5 additions & 5 deletions generator/insn_g.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (i *Insn) gWriteRandomData(lmul LMUL) string {
return builder.String()
}

func (i *Insn) gWriteIndexData(lmul1 LMUL, n int, sew SEW) string {
func (i *Insn) gWriteIndexData(lmul1 LMUL, n int, width SEW, sew SEW) string {
if n <= 0 {
n = 1
}
Expand All @@ -34,13 +34,13 @@ func (i *Insn) gWriteIndexData(lmul1 LMUL, n int, sew SEW) string {
for a := 0; a < nBytes/(int(sew)/8); a++ {
switch sew {
case 8:
_ = binary.Write(buf, binary.LittleEndian, uint8(s[a%n]))
_ = binary.Write(buf, binary.LittleEndian, uint8(s[a%n]*int(width)/8))
case 16:
_ = binary.Write(buf, binary.LittleEndian, uint16(s[a%n]*2))
_ = binary.Write(buf, binary.LittleEndian, uint16(s[a%n]*int(width)/8))
case 32:
_ = binary.Write(buf, binary.LittleEndian, uint32(s[a%n]*4))
_ = binary.Write(buf, binary.LittleEndian, uint32(s[a%n]*int(width)/8))
case 64:
_ = binary.Write(buf, binary.LittleEndian, uint64(s[a%n]*8))
_ = binary.Write(buf, binary.LittleEndian, uint64(s[a%n]*int(width)/8))
}
}
off := i.TestData.Append(buf.Bytes())
Expand Down
62 changes: 37 additions & 25 deletions generator/insn_vdrs1mvs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,43 @@ func (i *Insn) genCodeVdRs1mVs2Vm() []string {
res := make([]string, 0, len(combinations))

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

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(c.LMUL1) * nfields
builder.WriteString(i.gWriteIndexData(lmul1, c.Vl, c.SEW))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, lmul1, c.SEW))
builder.WriteString(i.gWriteRandomData(lmul1))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, lmul1, c.SEW))
builder.WriteString(i.gWriteIntegerTestData(lmul1, 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), 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, c.SEW))
builder.WriteString(i.gMagicInsn(vd))

res = append(res, builder.String())
// sew is data width, c.SEW is offset width
var sew SEW = 8
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)
if emul > 8 || emul < 1./8 {
continue
}
emul = math.Max(emul, 1)
builder := strings.Builder{}
builder.WriteString(c.comment())

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)))

builder.WriteString(i.gWriteIndexData(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("# -------------- 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))
res = append(res, builder.String())
}
}

return res
Expand Down
60 changes: 36 additions & 24 deletions generator/insn_vs3rs1mvs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,42 @@ func (i *Insn) genCodeVs3Rs1mVs2Vm() []string {
res := make([]string, 0, len(combinations))

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

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))
vs3 := int(lmul1)
vs1 := 2 * int(c.LMUL1) * nfields
builder.WriteString(i.gWriteIntegerTestData(lmul1, c.SEW, 0))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs3, lmul1, c.SEW))
builder.WriteString(i.gWriteIndexData(lmul1, c.Vl, c.SEW))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs1, lmul1, c.SEW))

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

builder.WriteString(i.gLoadDataIntoRegisterGroup(vs3, lmul1, c.SEW))
builder.WriteString(i.gMagicInsn(vs3))

res = append(res, builder.String())
// sew is data width, c.SEW is offset width
var sew SEW = 8
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)
if emul > 8 || emul < 1./8 {
continue
}
emul = math.Max(emul, 1)
builder := strings.Builder{}
builder.WriteString(c.comment())

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))
vs3 := int(lmul1)
vs1 := 2 * int(math.Max(emul, float64(int(c.LMUL1)*nfields)))
builder.WriteString(i.gWriteIntegerTestData(lmul1, sew, 0))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs3, lmul1, sew))
builder.WriteString(i.gWriteIndexData(LMUL(emul), c.Vl, sew, c.SEW))
builder.WriteString(i.gLoadDataIntoRegisterGroup(vs1, LMUL(emul), c.SEW))

builder.WriteString(i.gResultDataAddr())
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, vs3, vs1, v0t(c.Mask)))
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gLoadDataIntoRegisterGroup(vs3, lmul1, sew))
builder.WriteString(i.gMagicInsn(vs3))

res = append(res, builder.String())
}
}
return res
}

0 comments on commit 86e80cd

Please sign in to comment.