Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSOC] integrated support for Zvbc and Zvkg instructions #44

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CONFIGS = configs/

SPIKE = spike
PATCHER_SPIKE = build/pspike
MARCH = rv${XLEN}gcv_zvbb
MARCH = rv${XLEN}gcv_zvbb_zvbc_zvkg
MABI = lp64d

ifeq ($(XLEN), 32)
Expand Down
8 changes: 8 additions & 0 deletions Makefrag
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ tests = \
vasubu_vx-9 \
vbrev8_v-0 \
vbrev_v-0 \
vclmul_vv-0 \
vclmul_vx-0 \
vclmul_vx-1 \
vclmulh_vv-0 \
vclmulh_vx-0 \
vclmulh_vx-1 \
vclz_v-0 \
vcompress_vm-0 \
vcpop_m-0 \
Expand Down Expand Up @@ -409,6 +415,8 @@ tests = \
vfwsub_wf-0 \
vfwsub_wf-1 \
vfwsub_wv-0 \
vghsh_vv-0 \
vgmul_vv-0 \
vid_v-0 \
vid_v-1 \
viota_m-0 \
Expand Down
22 changes: 22 additions & 0 deletions configs/vclmul.vv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = "vclmul.vv"
format = "vd,vs2,vs1,vm"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]

sew64 = [
["0xffffffffffff8000", "0x0000000000000000"],
["0xffffffff80000000", "0x0000000000000000"],
["0xffffffff80000000", "0xffffffffffff8000"],
["0x0000000000007fff", "0x0000000000000000"],
["0x000000007fffffff", "0x0000000000007fff"],
["0xffffffff80000000", "0x0000000000007fff"],
["0x000000007fffffff", "0xffffffffffff8000"],
["0xffffffffffffffff", "0x0000000000000001"],
["0xffffffffffffffff", "0x0000000000000000"],
["0xffffffffffffffff", "0xffffffffffffffff"]
]
22 changes: 22 additions & 0 deletions configs/vclmul.vx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = "vclmul.vx"
format = "vd,vs2,rs1,vm"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]
sew64 = [
["0xffffffffffff8000", "0x0000000000000000"],
["0xffffffff80000000", "0x0000000000000000"],
["0xffffffff80000000", "0xffffffffffff8000"],
["0x0000000000007fff", "0x0000000000000000"],
["0x000000007fffffff", "0x0000000000007fff"],
["0xffffffff80000000", "0x0000000000007fff"],
["0x000000007fffffff", "0xffffffffffff8000"],
["0xffffffffffffffff", "0x0000000000000001"],
["0xffffffffffffffff", "0x0000000000000000"],
["0xffffffffffffffff", "0xffffffffffffffff"]
]

21 changes: 21 additions & 0 deletions configs/vclmulh.vv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = "vclmulh.vv"
format = "vd,vs2,vs1,vm"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]
sew64 = [
["0xffffffffffff8000", "0x0000000000000000"],
["0xffffffff80000000", "0x0000000000000000"],
["0xffffffff80000000", "0xffffffffffff8000"],
["0x0000000000007fff", "0x0000000000000000"],
["0x000000007fffffff", "0x0000000000007fff"],
["0xffffffff80000000", "0x0000000000007fff"],
["0x000000007fffffff", "0xffffffffffff8000"],
["0xffffffffffffffff", "0x0000000000000001"],
["0xffffffffffffffff", "0x0000000000000000"],
["0xffffffffffffffff", "0xffffffffffffffff"]
]
21 changes: 21 additions & 0 deletions configs/vclmulh.vx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = "vclmulh.vx"
format = "vd,vs2,rs1,vm"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]
sew64 = [
["0xffffffffffff8000", "0x0000000000000000"],
["0xffffffff80000000", "0x0000000000000000"],
["0xffffffff80000000", "0xffffffffffff8000"],
["0x0000000000007fff", "0x0000000000000000"],
["0x000000007fffffff", "0x0000000000007fff"],
["0xffffffff80000000", "0x0000000000007fff"],
["0x000000007fffffff", "0xffffffffffff8000"],
["0xffffffffffffffff", "0x0000000000000001"],
["0xffffffffffffffff", "0x0000000000000000"],
["0xffffffffffffffff", "0xffffffffffffffff"]
]
19 changes: 19 additions & 0 deletions configs/vghsh.vv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "vghsh.vv"
format = "vd,vs2,vs1"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]

sew32 = [
[0xfffffff8, 0x00000000],
[0xffffff80, 0xfffffff8],
[0x00007fff, 0x00000000],
[0x00007fff, 0x000007ff],
[0x00007fff, 0x00000001],
[0xffffffff, 0x00000000],
[0xffffffff, 0xffffffff]
]
19 changes: 19 additions & 0 deletions configs/vgmul.vv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "vgmul.vv"
format = "vd,vs2"

[tests]
base = [
[0x0, 0x0],
[0x1, 0x2],
[0x3, 0xf]
]

sew32 = [
[0xfffffff8, 0x00000000],
[0xffffff80, 0xfffffff8],
[0x00007fff, 0x00000000],
[0x00007fff, 0x000007ff],
[0x00007fff, 0x00000001],
[0xffffffff, 0x00000000],
[0xffffffff, 0xffffffff]
]
6 changes: 5 additions & 1 deletion generator/insn_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (l LMUL) String() string {

type VLEN int

func (v VLEN) Zvkg_validVLEN() bool{
return 128 <= v && v <= 4096 && v&(v-1) == 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no limit on the VLEN, as long as VLEN * LMUL >= 128, it's okay.

}

func (v VLEN) Valid() bool {
return 64 <= v && v <= 4096 && v&(v-1) == 0
}
Expand Down Expand Up @@ -179,4 +183,4 @@ func getVRegs(lmul1 LMUL, v0 bool, seed string) (int, int, int) {
})

return availableOptions[0], availableOptions[1], availableOptions[2]
}
}
26 changes: 18 additions & 8 deletions generator/insn_vdvs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@ import (
)

func (i *Insn) genCodeVdVs2(pos int) []string {
s := regexp.MustCompile(`vmv(\d)r.v`)
nr, err := strconv.Atoi(s.FindStringSubmatch(i.Name)[1])
if err != nil {
log.Fatal("unreachable")
zvkg_insn := strings.HasPrefix(i.Name, "vg")
sew32_only := iff(zvkg_insn, []SEW{32}, allSEWs)

var nr int
var err error

if match := regexp.MustCompile(`vmv(\d+)r.v`).FindStringSubmatch(i.Name); len(match) > 1 {
nr, err = strconv.Atoi(match[1])
if err != nil {
log.Fatalf("Error parsing register number: %v", err)
}
}

combinations := i.combinations([]LMUL{LMUL(nr)}, allSEWs, []bool{false}, i.vxrms())

combinations := i.combinations(iff(zvkg_insn, []LMUL{1, 2, 4, 8}, []LMUL{LMUL(nr)}), iff(zvkg_insn, sew32_only, allSEWs), []bool{false}, i.vxrms())
res := make([]string, 0, len(combinations))

for _, c := range combinations[pos:] {
if zvkg_insn && c.Vl % 4 != 0 {
c.Vl = (c.Vl + 3) / 4 * 4
}

builder := strings.Builder{}
builder.WriteString(c.initialize())

Expand All @@ -32,16 +44,14 @@ func (i *Insn) genCodeVdVs2(pos int) []string {

builder.WriteString("# -------------- TEST BEGIN --------------\n")
builder.WriteString(i.gVsetvli(c.Vl, c.SEW, c.LMUL))
builder.WriteString(fmt.Sprintf("%s v%d, v%d\n",
i.Name, vd, vs2))
builder.WriteString(fmt.Sprintf("%s v%d, v%d\n", i.Name, vd, vs2))
builder.WriteString("# -------------- TEST END --------------\n")

builder.WriteString(i.gResultDataAddr())
builder.WriteString(i.gStoreRegisterGroupIntoResultData(vd, c.LMUL, c.SEW))
builder.WriteString(i.gMagicInsn(vd, c.LMUL))

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

}

return res
Expand Down
4 changes: 3 additions & 1 deletion generator/insn_vdvs2rs1vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
func (i *Insn) genCodeVdVs2Rs1Vm(pos int) []string {
vdWidening := strings.HasPrefix(i.Name, "vw")
vs2Widening := strings.HasSuffix(i.Name, ".wx")
sew64Only := strings.HasPrefix(i.Name, "vclmul")
vdSize := iff(vdWidening, 2, 1)
vs2Size := iff(vs2Widening, 2, 1)

sews := iff(vdWidening || vs2Widening, allSEWs[:len(allSEWs)-1], allSEWs)
sews = iff(sew64Only, []SEW{64}, sews)
combinations := i.combinations(
iff(vdWidening || vs2Widening, wideningMULs, allLMULs),
iff(vdWidening || vs2Widening, wideningMULs, iff(sew64Only, []LMUL{1, 2, 4, 8}, allLMULs)),
sews,
[]bool{false, true},
i.vxrms(),
Expand Down
12 changes: 11 additions & 1 deletion generator/insn_vdvs2vs1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import (
)

func (i *Insn) genCodeVdVs2Vs1(pos int) []string {
combinations := i.combinations(allLMULs, allSEWs, []bool{false}, i.vxrms())
zvkg_insn := strings.HasPrefix(i.Name, "vg")
sew32_only := iff(zvkg_insn, []SEW{32}, allSEWs)
combinations := i.combinations(
iff(zvkg_insn, []LMUL{1, 2, 4, 8}, allLMULs),
iff(zvkg_insn, sew32_only, allSEWs),
[]bool{false},
i.vxrms(),
)
res := make([]string, 0, len(combinations))
for _, c := range combinations[pos:] {
if zvkg_insn && c.Vl % 4 != 0 {
c.Vl = (c.Vl + 3) / 4 * 4
}
builder := strings.Builder{}
builder.WriteString(c.initialize())

Expand Down
4 changes: 3 additions & 1 deletion generator/insn_vdvs2vs1vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (

func (i *Insn) genCodeVdVs2Vs1Vm(pos int) []string {
float := strings.HasPrefix(i.Name, "vf") || strings.HasPrefix(i.Name, "vmf")
sew64Only := strings.HasPrefix(i.Name, "vclmul")
vdWidening := strings.HasPrefix(i.Name, "vw") || strings.HasPrefix(i.Name, "vfw")
vs2Widening := strings.HasSuffix(i.Name, ".wv")
vdSize := iff(vdWidening, 2, 1)
vs2Size := iff(vs2Widening, 2, 1)

sews := iff(float, floatSEWs, allSEWs)
sews = iff(vdWidening || vs2Widening, sews[:len(sews)-1], sews)
sews = iff(sew64Only, []SEW{64}, sews)
combinations := i.combinations(
iff(vdWidening || vs2Widening, wideningMULs, allLMULs),
iff(vdWidening || vs2Widening, wideningMULs, iff(sew64Only, []LMUL{1, 2, 4, 8}, allLMULs)),
sews,
[]bool{false, true},
i.vxrms(),
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ func main() {
}
insn, err := generator.ReadInsnFromToml(contents, option)
fatalIf(err)

if strings.HasPrefix(insn.Name, "vg") && !option.VLEN.Zvkg_validVLEN() {
lk.Lock()
fmt.Printf("\033[0;1;31mskipping:\033[0m %s, VLEN is not greater than or equal to 128\n", name)
lk.Unlock()
wg.Done()
return
}

if insn.Name != strings.Replace(file.Name(), ".toml", "", -1) {
fatalIf(errors.New("filename and instruction name unmatched"))
}
Expand Down Expand Up @@ -130,4 +139,4 @@ func writeTo(path string, name string, contents string) {
fatalIf(err)
err = os.WriteFile(filepath.Join(path, name), []byte(contents), 0644)
fatalIf(err)
}
}
Loading