diff --git a/generator/insn_g.go b/generator/insn_g.go index 86aaf72..cf06d61 100644 --- a/generator/insn_g.go +++ b/generator/insn_g.go @@ -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 } @@ -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()) diff --git a/generator/insn_vdrs1mvs2vm.go b/generator/insn_vdrs1mvs2vm.go index 126741e..5c78887 100644 --- a/generator/insn_vdrs1mvs2vm.go +++ b/generator/insn_vdrs1mvs2vm.go @@ -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 diff --git a/generator/insn_vs3rs1mvs2vm.go b/generator/insn_vs3rs1mvs2vm.go index f3445a2..e62408f 100644 --- a/generator/insn_vs3rs1mvs2vm.go +++ b/generator/insn_vs3rs1mvs2vm.go @@ -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 }