forked from chipsalliance/riscv-vector-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.go
78 lines (64 loc) · 1.95 KB
/
single.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"github.com/ksco/riscv-vector-tests/generator"
"github.com/ksco/riscv-vector-tests/testfloat3"
)
func fatalIf(err error) {
if err == nil {
return
}
fmt.Printf("fatal: %s\n", err.Error())
os.Exit(1)
}
var vlenF = flag.Int("VLEN", 256, "")
var xlenF = flag.Int("XLEN", 64, "")
var float16F = flag.Bool("float16", true, "")
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()
if outputFileF == nil || *outputFileF == "" {
fatalIf(errors.New("-outputfile is required"))
}
if configFileF == nil || *configFileF == "" {
fatalIf(errors.New("-configfile is required"))
}
if !(*testfloat3LevelF == 1 || *testfloat3LevelF == 2) {
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),
Repeat: *repeatF,
Float16: *float16F,
}
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)
r := regexp.MustCompile(".word 0x.+")
writeTo(*outputFileF, r.ReplaceAllString(insn.Generate(-1)[0], ""))
}
func writeTo(path string, contents string) {
err := os.MkdirAll(filepath.Dir(path), 0777)
fatalIf(err)
err = os.WriteFile(path, []byte(contents), 0644)
fatalIf(err)
}