Skip to content

Commit

Permalink
Add REPEAT option
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco committed Feb 22, 2024
1 parent b8d38fe commit f8346b6
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 145 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions Makefrag
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.

Expand Down
21 changes: 11 additions & 10 deletions generator/insn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
26 changes: 14 additions & 12 deletions generator/insn_fdvs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
19 changes: 13 additions & 6 deletions generator/insn_g.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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]))
}
}
Expand Down
47 changes: 25 additions & 22 deletions generator/insn_vdfs1vs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion generator/insn_vdvs1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 16 additions & 16 deletions generator/insn_vdvs1vs2vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
50 changes: 27 additions & 23 deletions generator/insn_vdvs2fs1v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
Loading

0 comments on commit f8346b6

Please sign in to comment.