diff --git a/Makefile b/Makefile index f615010..07e942c 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ SPLIT = 10000 INTEGER = 0 PATTERN = '.*' TESTFLOAT3LEVEL = 2 +REPEAT = 1 SPIKE_INSTALL = $(RISCV) OUTPUT = out/v$(VLEN)x$(XLEN)$(MODE) OUTPUT_STAGE1 = $(OUTPUT)/tests/stage1/ @@ -73,7 +74,7 @@ unittest: generate-stage1: clean-out build @mkdir -p ${OUTPUT_STAGE1} - build/generator -VLEN ${VLEN} -XLEN ${XLEN} -split=${SPLIT} -integer=${INTEGER} -pattern='${PATTERN}' -testfloat3level='${TESTFLOAT3LEVEL}' -stage1output ${OUTPUT_STAGE1} -configs ${CONFIGS} + build/generator -VLEN ${VLEN} -XLEN ${XLEN} -split=${SPLIT} -integer=${INTEGER} -pattern='${PATTERN}' -testfloat3level='${TESTFLOAT3LEVEL}' -repeat='${REPEAT}' -stage1output ${OUTPUT_STAGE1} -configs ${CONFIGS} include Makefrag diff --git a/Makefrag b/Makefrag index 2f68b5b..a05b65d 100644 --- a/Makefrag +++ b/Makefrag @@ -251,13 +251,11 @@ tests = \ vfmacc.vf-2 \ vfmacc.vf-3 \ vfmacc.vv-0 \ - vfmacc.vv-1 \ vfmadd.vf-0 \ vfmadd.vf-1 \ vfmadd.vf-2 \ vfmadd.vf-3 \ vfmadd.vv-0 \ - vfmadd.vv-1 \ vfmax.vf-0 \ vfmax.vf-1 \ vfmax.vf-2 \ @@ -275,13 +273,11 @@ tests = \ vfmsac.vf-2 \ vfmsac.vf-3 \ vfmsac.vv-0 \ - vfmsac.vv-1 \ vfmsub.vf-0 \ vfmsub.vf-1 \ vfmsub.vf-2 \ vfmsub.vf-3 \ vfmsub.vv-0 \ - vfmsub.vv-1 \ vfmul.vf-0 \ vfmul.vf-1 \ vfmul.vf-2 \ @@ -303,25 +299,21 @@ tests = \ vfnmacc.vf-2 \ vfnmacc.vf-3 \ vfnmacc.vv-0 \ - vfnmacc.vv-1 \ vfnmadd.vf-0 \ vfnmadd.vf-1 \ vfnmadd.vf-2 \ vfnmadd.vf-3 \ vfnmadd.vv-0 \ - vfnmadd.vv-1 \ vfnmsac.vf-0 \ vfnmsac.vf-1 \ vfnmsac.vf-2 \ vfnmsac.vf-3 \ vfnmsac.vv-0 \ - vfnmsac.vv-1 \ vfnmsub.vf-0 \ vfnmsub.vf-1 \ vfnmsub.vf-2 \ vfnmsub.vf-3 \ vfnmsub.vv-0 \ - vfnmsub.vv-1 \ vfrdiv.vf-0 \ vfrdiv.vf-1 \ vfrdiv.vf-2 \ diff --git a/README.md b/README.md index 98e1aac..ff61336 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ Options: - `INTEGER`, default is 0, set to 1 if you don't want float tests (i.e. for Zve32x or Zve64x) - `PATTERN`, default is `.*`, set to a valid regex to generate the tests of your interests (e.g. `PATTERN='^v[ls].+\.v$'` to generate load/store tests) - `TESTFLOAT3LEVEL`, default is 2, must be one of 1 or 2, testing level for testfloat3 generated cases. -- `TEST_MODE` , default is `self`, set to `cosim` if you want to generate faster tests without self-verification (to be used with co-simulators). +- `TEST_MODE`, default is `self`, set to `cosim` if you want to generate faster tests without self-verification (to be used with co-simulators). +- `REPEAT`, default is `1`, set to greater value to repeat the same V instruction n times for a better coverage (only valid for float instructions). For example, to generate `isa=rv32gcv varch=vlen:128,elen:32 mode=machine` tests, use `make -e VLEN=128 XLEN=32 MODE=machine -j$(nproc)`. diff --git a/generator/insn.go b/generator/insn.go index 58ee5c3..5fcf9dc 100644 --- a/generator/insn.go +++ b/generator/insn.go @@ -16,8 +16,9 @@ import ( type insnFormat string type Option struct { - VLEN VLEN - XLEN XLEN + VLEN VLEN + XLEN XLEN + Repeat int } const minStride = -1 // Must be negative @@ -52,14 +53,14 @@ func (t *TestData) String() string { } type Insn struct { - Name string `toml:"name"` - Format insnFormat `toml:"format"` - NoTestfloat3 bool `toml:"notestfloat3"` - Vxrm bool `toml:"vxrm"` - Vxsat bool `toml:"vxsat"` - Tests tests `toml:"tests"` - Option Option `toml:"-"` - TestData *TestData + Name string `toml:"name"` + Format insnFormat `toml:"format"` + NoTestfloat3 bool `toml:"notestfloat3"` + Vxrm bool `toml:"vxrm"` + Vxsat bool `toml:"vxsat"` + Tests tests `toml:"tests"` + Option Option `toml:"-"` + TestData *TestData } const ( diff --git a/generator/insn_fdvs2.go b/generator/insn_fdvs2.go index 7d5b1cb..c17d98b 100644 --- a/generator/insn_fdvs2.go +++ b/generator/insn_fdvs2.go @@ -15,22 +15,24 @@ func (i *Insn) genCodeFdVs2(pos int) []string { vd := int(c.LMUL1) vs2 := int(c.LMUL1) * 2 - builder.WriteString(i.gWriteRandomData(LMUL(1))) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, c.LMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, c.LMUL1, c.SEW, 0, 1)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteRandomData(LMUL(1))) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, c.LMUL1, SEW(8))) + builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 0, 1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) - builder.WriteString("# -------------- TEST BEGIN --------------\n") - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(fmt.Sprintf("%s f0, v%d\n", i.Name, vs2)) - builder.WriteString("# -------------- TEST END --------------\n") + builder.WriteString("# -------------- TEST BEGIN --------------\n") + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString(fmt.Sprintf("%s f0, v%d\n", i.Name, vs2)) + builder.WriteString("# -------------- TEST END --------------\n") - builder.WriteString(i.gMoveScalarToVector("f0", vd, c.SEW)) + builder.WriteString(i.gMoveScalarToVector("f0", vd, c.SEW)) - builder.WriteString(i.gResultDataAddr()) - builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW)) - builder.WriteString(i.gMagicInsn(vd)) + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW)) + builder.WriteString(i.gMagicInsn(vd)) + } res = append(res, builder.String()) } diff --git a/generator/insn_g.go b/generator/insn_g.go index 095c3bf..bb2a0cd 100644 --- a/generator/insn_g.go +++ b/generator/insn_g.go @@ -57,11 +57,15 @@ func (i *Insn) gWriteIndexData(dataLmul1 LMUL, offsetLmul1 LMUL, n int, dataSew } func (i *Insn) gWriteIntegerTestData(lmul LMUL, sew SEW, idx int) string { - return i.gWriteTestData(false, false, lmul, sew, idx, 0) + return i.gWriteTestData(false, false, false, lmul, sew, idx, 0) } -func (i *Insn) gWriteTestData(float bool, testfloat bool, lmul LMUL, sew SEW, idx int, numops int) string { - if float && testfloat { +func (i *Insn) gWriteTestData(float bool, testfloat bool, cont bool, lmul LMUL, sew SEW, idx int, numops int) string { + if !float && cont { + panic("unreachable") + } + + if float && testfloat && !cont { testfloat3.InitF32(numops) testfloat3.InitF64(numops) } @@ -77,24 +81,27 @@ func (i *Insn) gWriteTestData(float bool, testfloat bool, lmul LMUL, sew SEW, id builder := strings.Builder{} buf := &bytes.Buffer{} for a := 0; a < (nBytes / (int(sew) / 8)); a++ { - b := a % len(cases) switch sew { case 8: + b := a % len(cases) _ = binary.Write(buf, binary.LittleEndian, convNum[uint8](cases[b][idx])) case 16: + b := a % len(cases) _ = binary.Write(buf, binary.LittleEndian, convNum[uint16](cases[b][idx])) case 32: // Manual test cases exhausted, use testfloat3 to generate new ones. - if float && testfloat && a >= len(cases) { + if (float && testfloat && a >= len(cases)) || cont { _ = binary.Write(buf, binary.LittleEndian, math.Float32bits(nextf32())) } else { + b := a % len(cases) _ = binary.Write(buf, binary.LittleEndian, convNum[uint32](cases[b][idx])) } case 64: // Manual test cases exhausted, use testfloat3 to generate new ones. - if float && testfloat && a >= len(cases) { + if (float && testfloat && a >= len(cases)) || cont { _ = binary.Write(buf, binary.LittleEndian, math.Float64bits(nextf64())) } else { + b := a % len(cases) _ = binary.Write(buf, binary.LittleEndian, convNum[uint64](cases[b][idx])) } } diff --git a/generator/insn_vdfs1vs2vm.go b/generator/insn_vdfs1vs2vm.go index 1fd8ca0..7714e3e 100644 --- a/generator/insn_vdfs1vs2vm.go +++ b/generator/insn_vdfs1vs2vm.go @@ -35,31 +35,34 @@ func (i *Insn) genCodeVdFs1Vs2Vm(pos int) []string { vd := int(vdEMUL1) vs2 := vd * 2 - builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, vdEMUL1, vdEEW, 0, 3)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, vdEEW)) - builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, c.LMUL1, c.SEW, 2, 3)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, r != 0, vdEMUL1, vdEEW, 0, 2)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, vdEEW)) - cases := i.testCases(true, c.SEW) - for a := 0; a < len(cases); a++ { - builder.WriteString("# -------------- TEST BEGIN --------------\n") - switch c.SEW { - case 32: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][1]))) - builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) - case 64: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][1]))) - builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) - } - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(fmt.Sprintf("%s v%d, f0, v%d%s\n", - i.Name, vd, vs2, v0t(c.Mask))) - builder.WriteString("# -------------- TEST END --------------\n") + builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 1, 2)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + + cases := i.testCases(true, c.SEW) + for a := 0; a < len(cases); a++ { + builder.WriteString("# -------------- TEST BEGIN --------------\n") + switch c.SEW { + case 32: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][1]))) + builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) + case 64: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][1]))) + builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) + } + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString(fmt.Sprintf("%s v%d, f0, 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, vdEMUL1, vdEEW)) - builder.WriteString(i.gMagicInsn(vd)) + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) + builder.WriteString(i.gMagicInsn(vd)) + } } res = append(res, builder.String()) diff --git a/generator/insn_vdvs1.go b/generator/insn_vdvs1.go index 54b4eca..75ec794 100644 --- a/generator/insn_vdvs1.go +++ b/generator/insn_vdvs1.go @@ -18,7 +18,7 @@ func (i *Insn) genCodeVdVs1(pos int) []string { builder.WriteString(i.gWriteRandomData(c.LMUL1)) builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, c.LMUL1, c.SEW)) - builder.WriteString(i.gWriteTestData(false, false, c.LMUL1, c.SEW, 0, 1)) + builder.WriteString(i.gWriteTestData(false, false, false, c.LMUL1, c.SEW, 0, 1)) builder.WriteString(i.gLoadDataIntoRegisterGroup(vs1, c.LMUL1, c.SEW)) builder.WriteString("# -------------- TEST BEGIN --------------\n") diff --git a/generator/insn_vdvs1vs2vm.go b/generator/insn_vdvs1vs2vm.go index 0274f2c..d41b989 100644 --- a/generator/insn_vdvs1vs2vm.go +++ b/generator/insn_vdvs1vs2vm.go @@ -43,28 +43,28 @@ func (i *Insn) genCodeVdVs1Vs2Vm(pos int) []string { vd * 2, vd*2 + int(vs1EMUL1), } - builder.WriteString(i.gWriteRandomData(vdEMUL1)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, vdEMUL1, vdEEW, 0, 3)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, vdEEW)) + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, r != 0, vdEMUL1, vdEEW, 0, 3)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, vdEEW)) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, vs1EMUL1, vs1EEW, 1, 3)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[1], vs1EMUL1, vs1EEW)) + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, r != 0, vs1EMUL1, vs1EEW, 1, 3)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[1], vs1EMUL1, vs1EEW)) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, c.LMUL1, c.SEW, 2, 3)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[0], c.LMUL1, c.SEW)) + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 2, 3)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[0], c.LMUL1, c.SEW)) - builder.WriteString("# -------------- TEST BEGIN --------------\n") - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString("# -------------- TEST BEGIN --------------\n") + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(fmt.Sprintf("%s v%d, v%d, v%d%s\n", - i.Name, vd, vss[1], vss[0], v0t(c.Mask))) - builder.WriteString("# -------------- TEST END --------------\n") + builder.WriteString(fmt.Sprintf("%s v%d, v%d, v%d%s\n", + i.Name, vd, vss[1], vss[0], v0t(c.Mask))) + builder.WriteString("# -------------- TEST END --------------\n") - builder.WriteString(i.gResultDataAddr()) - builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) - builder.WriteString(i.gMagicInsn(vd)) + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) + builder.WriteString(i.gMagicInsn(vd)) + } res = append(res, builder.String()) } diff --git a/generator/insn_vdvs2fs1v0.go b/generator/insn_vdvs2fs1v0.go index ad586af..dee2885 100644 --- a/generator/insn_vdvs2fs1v0.go +++ b/generator/insn_vdvs2fs1v0.go @@ -18,31 +18,35 @@ func (i *Insn) genCodeVdVs2Fs1V0(pos int) []string { vd := int(c.LMUL1) vs2 := 2 * int(c.LMUL1) - builder.WriteString(i.gWriteRandomData(c.LMUL1)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, c.LMUL1, SEW(8))) - - builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, c.LMUL1, c.SEW, 1, 2)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) - cases := i.testCases(true, c.SEW) - for a := 0; a < len(cases); a++ { - builder.WriteString("# -------------- TEST BEGIN --------------\n") - switch c.SEW { - case 32: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][0]))) - builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) - case 64: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][0]))) - builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) + + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteRandomData(c.LMUL1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, c.LMUL1, SEW(8))) + + builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 0, 1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + cases := i.testCases(true, c.SEW) + for a := 0; a < len(cases); a++ { + builder.WriteString("# -------------- TEST BEGIN --------------\n") + switch c.SEW { + case 32: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][0]))) + builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) + case 64: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][0]))) + builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) + } + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString(fmt.Sprintf("%s v%d, v%d, f0, v0\n", + i.Name, vd, vs2)) + builder.WriteString("# -------------- TEST END --------------\n") + + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW)) + builder.WriteString(i.gMagicInsn(vd)) } - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(fmt.Sprintf("%s v%d, v%d, f0, v0\n", - i.Name, vd, vs2)) - builder.WriteString("# -------------- TEST END --------------\n") - - builder.WriteString(i.gResultDataAddr()) - builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL1, c.SEW)) - builder.WriteString(i.gMagicInsn(vd)) } + res = append(res, builder.String()) } diff --git a/generator/insn_vdvs2fs1vm.go b/generator/insn_vdvs2fs1vm.go index aa1dbb4..91076ba 100644 --- a/generator/insn_vdvs2fs1vm.go +++ b/generator/insn_vdvs2fs1vm.go @@ -36,31 +36,34 @@ func (i *Insn) genCodeVdVs2Fs1Vm(pos int) []string { vd := int(vdEMUL1) vs2 := vd * 2 - builder.WriteString(i.gWriteRandomData(vdEMUL1)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, c.LMUL1, c.SEW, 1, 2)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteRandomData(vdEMUL1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - cases := i.testCases(true, c.SEW) - for a := 0; a < len(cases); a++ { - builder.WriteString("# -------------- TEST BEGIN --------------\n") - switch c.SEW { - case 32: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][0]))) - builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) - case 64: - builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][0]))) - builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) - } - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(fmt.Sprintf("%s v%d, v%d, f0%s\n", - i.Name, vd, vs2, v0t(c.Mask))) - builder.WriteString("# -------------- TEST END --------------\n") + builder.WriteString(i.gWriteTestData(true, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 0, 1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, c.LMUL1, c.SEW)) + + cases := i.testCases(true, c.SEW) + for a := 0; a < len(cases); a++ { + builder.WriteString("# -------------- TEST BEGIN --------------\n") + switch c.SEW { + case 32: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint32](cases[a][0]))) + builder.WriteString(fmt.Sprintf("fmv.w.x f0, s0\n")) + case 64: + builder.WriteString(fmt.Sprintf("li s0, 0x%x\n", convNum[uint64](cases[a][0]))) + builder.WriteString(fmt.Sprintf("fmv.d.x f0, s0\n")) + } + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString(fmt.Sprintf("%s v%d, v%d, f0%s\n", + i.Name, vd, vs2, v0t(c.Mask))) + builder.WriteString("# -------------- TEST END --------------\n") - builder.WriteString(i.gResultDataAddr()) - builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) - builder.WriteString(i.gMagicInsn(vd)) + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) + builder.WriteString(i.gMagicInsn(vd)) + } } res = append(res, builder.String()) diff --git a/generator/insn_vdvs2vm.go b/generator/insn_vdvs2vm.go index 55340c0..c56a7e9 100644 --- a/generator/insn_vdvs2vm.go +++ b/generator/insn_vdvs2vm.go @@ -40,7 +40,7 @@ func (i *Insn) genCodeVdVs2Vm(pos int) []string { builder.WriteString(i.gWriteRandomData(vdEMUL1)) builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, vs2EMUL1, vs2EEW, 0, 1)) + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, false, vs2EMUL1, vs2EEW, 0, 1)) builder.WriteString(i.gLoadDataIntoRegisterGroup(vs2, vs2EMUL1, vs2EEW)) builder.WriteString("# -------------- TEST BEGIN --------------\n") diff --git a/generator/insn_vdvs2vs1vm.go b/generator/insn_vdvs2vs1vm.go index 3b636f5..4694304 100644 --- a/generator/insn_vdvs2vs1vm.go +++ b/generator/insn_vdvs2vs1vm.go @@ -48,25 +48,28 @@ func (i *Insn) genCodeVdVs2Vs1Vm(pos int) []string { vd * 2, vd*2 + int(vs2EMUL1), } - builder.WriteString(i.gWriteRandomData(vdEMUL1)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, c.LMUL1, c.SEW, 0, 2)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[0], c.LMUL1, c.SEW)) + for r := 0; r < i.Option.Repeat; r += 1 { + builder.WriteString(i.gWriteRandomData(vdEMUL1)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vd, vdEMUL1, SEW(8))) - builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, vs2EMUL1, vs2EEW, 1, 2)) - builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[1], vs2EMUL1, vs2EEW)) + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, r != 0, c.LMUL1, c.SEW, 0, 2)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[0], c.LMUL1, c.SEW)) - builder.WriteString("# -------------- TEST BEGIN --------------\n") - builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) + builder.WriteString(i.gWriteTestData(float, !i.NoTestfloat3, r != 0, vs2EMUL1, vs2EEW, 1, 2)) + builder.WriteString(i.gLoadDataIntoRegisterGroup(vss[1], vs2EMUL1, vs2EEW)) - builder.WriteString(fmt.Sprintf("%s v%d, v%d, v%d%s\n", - i.Name, vd, vss[1], vss[0], v0t(c.Mask))) - builder.WriteString("# -------------- TEST END --------------\n") + builder.WriteString("# -------------- TEST BEGIN --------------\n") + builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL)) - builder.WriteString(i.gResultDataAddr()) - builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) - builder.WriteString(i.gMagicInsn(vd)) + builder.WriteString(fmt.Sprintf("%s v%d, v%d, v%d%s\n", + i.Name, vd, vss[1], vss[0], v0t(c.Mask))) + builder.WriteString("# -------------- TEST END --------------\n") + + builder.WriteString(i.gResultDataAddr()) + builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, vdEMUL1, vdEEW)) + builder.WriteString(i.gMagicInsn(vd)) + } res = append(res, builder.String()) } diff --git a/main.go b/main.go index c558231..ad840dc 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ var patternF = flag.String("pattern", ".*", "regex to filter out tests.") var stage1OutputDirF = flag.String("stage1output", "", "stage1 output directory.") var configsDirF = flag.String("configs", "configs/", "config files directory.") var testfloat3LevelF = flag.Int("testfloat3level", 2, "testfloat3 testing level (1 or 2).") +var repeatF = flag.Int("repeat", 1, "repeat same V instruction n times for a better coverage (only valid for float instructions).") func main() { flag.Parse() @@ -47,13 +48,12 @@ func main() { fatalIf(errors.New("-testfloat3level must be 1 or 2")) } - testfloat3.SetLevel(*testfloat3LevelF) - - option := generator.Option{ - VLEN: generator.VLEN(*vlenF), - XLEN: generator.XLEN(*xlenF), + if *repeatF <= 0 { + fatalIf(errors.New("-repeat must greater than 0")) } + testfloat3.SetLevel(*testfloat3LevelF) + files, err := os.ReadDir(*configsDirF) fatalIf(err) @@ -63,7 +63,7 @@ func main() { lk := sync.Mutex{} wg := sync.WaitGroup{} for _, file := range files { - if *integerF && strings.HasPrefix(file.Name(), "vf") { + if *integerF && (strings.HasPrefix(file.Name(), "vf") || strings.HasPrefix(file.Name(), "vmf")) && !strings.HasPrefix(file.Name(), "vfirst") { continue } @@ -87,6 +87,14 @@ func main() { contents, err := os.ReadFile(fp) fatalIf(err) + option := generator.Option{ + VLEN: generator.VLEN(*vlenF), + XLEN: generator.XLEN(*xlenF), + Repeat: *repeatF, + } + if (!strings.HasPrefix(file.Name(), "vf") && !strings.HasPrefix(file.Name(), "vmf")) || strings.HasPrefix(file.Name(), "vfirst") { + option.Repeat = 1 + } insn, err := generator.ReadInsnFromToml(contents, option) fatalIf(err) diff --git a/single/single.go b/single/single.go index 16a94df..65ff270 100644 --- a/single/single.go +++ b/single/single.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "github.com/ksco/riscv-vector-tests/generator" "github.com/ksco/riscv-vector-tests/testfloat3" @@ -25,6 +26,7 @@ var xlenF = flag.Int("XLEN", 64, "") var outputFileF = flag.String("outputfile", "", "output file name.") var configFileF = flag.String("configfile", "", "config file path.") var testfloat3LevelF = flag.Int("testfloat3level", 2, "testfloat3 testing level (1 or 2).") +var repeatF = flag.Int("repeat", 1, "repeat same V instruction n times for a better coverage (only valid for float instructions).") func main() { flag.Parse() @@ -40,17 +42,25 @@ func main() { fatalIf(errors.New("-testfloat3level must be 1 or 2")) } + if *repeatF <= 0 { + fatalIf(errors.New("-repeat must greater than 0")) + } + testfloat3.SetLevel(*testfloat3LevelF) option := generator.Option{ - VLEN: generator.VLEN(*vlenF), - XLEN: generator.XLEN(*xlenF), + VLEN: generator.VLEN(*vlenF), + XLEN: generator.XLEN(*xlenF), + Repeat: *repeatF, } fp := *configFileF contents, err := os.ReadFile(fp) fatalIf(err) + if (!strings.HasPrefix(filepath.Base(fp), "vf") && !strings.HasPrefix(filepath.Base(fp), "vmf")) || strings.HasPrefix(filepath.Base(fp), "vfirst") { + option.Repeat = 1 + } insn, err := generator.ReadInsnFromToml(contents, option) fatalIf(err)