/
dynamical_flopoco.go
119 lines (104 loc) · 3.16 KB
/
dynamical_flopoco.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package procbuilder
import (
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"github.com/BondMachineHQ/BondMachine/pkg/bmconfig"
"github.com/BondMachineHQ/BondMachine/pkg/bmline"
)
type DynFloPoCo struct{}
func (d DynFloPoCo) GetName() string {
return "dyn_flopoco"
}
func (d DynFloPoCo) MatchName(name string) bool {
re := regexp.MustCompile("multflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
if re.MatchString(name) {
return true
}
re = regexp.MustCompile("addflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
if re.MatchString(name) {
return true
}
re = regexp.MustCompile("divflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
return re.MatchString(name)
}
func (d DynFloPoCo) CreateInstruction(name string) (Opcode, error) {
var regSize int
var runCommand []string
var resultReport string
var vHDL string
entities := make([]string, 0)
var topEntity string
var pipeline int
// Create a temporary directory for the FloPoCo files
dir, err := os.MkdirTemp("", "flopoco")
if err != nil {
return nil, err
}
defer os.RemoveAll(dir)
re := regexp.MustCompile("multflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
if re.MatchString(name) {
es := re.ReplaceAllString(name, "${e}")
fs := re.ReplaceAllString(name, "${f}")
e, _ := strconv.Atoi(es)
f, _ := strconv.Atoi(fs)
runCommand = []string{"flopoco", "FPMult", "we=" + es, "wf=" + fs}
regSize = e + f + 3
}
re = regexp.MustCompile("addflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
if re.MatchString(name) {
es := re.ReplaceAllString(name, "${e}")
fs := re.ReplaceAllString(name, "${f}")
e, _ := strconv.Atoi(es)
f, _ := strconv.Atoi(fs)
runCommand = []string{"flopoco", "FPAdd", "we=" + es, "wf=" + fs}
regSize = e + f + 3
}
re = regexp.MustCompile("divflpe(?P<e>[0-9]+)f(?P<f>[0-9]+)")
if re.MatchString(name) {
es := re.ReplaceAllString(name, "${e}")
fs := re.ReplaceAllString(name, "${f}")
e, _ := strconv.Atoi(es)
f, _ := strconv.Atoi(fs)
runCommand = []string{"flopoco", "FPDiv", "we=" + es, "wf=" + fs}
regSize = e + f + 3
}
cmd := exec.Command(runCommand[0], runCommand[1:]...)
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
return nil, err
} else {
resultReport = string(out)
// Parse every line of the report
for _, line := range strings.Split(resultReport, "\n") {
re = regexp.MustCompile(`.*Entity (?P<entity>\w+).*`)
if re.MatchString(line) {
newEnt := re.ReplaceAllString(line, "${entity}")
entities = append(entities, newEnt)
}
re = regexp.MustCompile(`.*Pipeline depth = (?P<depth>[0-9]+).*`)
if re.MatchString(line) {
depth := re.ReplaceAllString(line, "${depth}")
pipeline, _ = strconv.Atoi(depth)
}
}
topEntity = entities[len(entities)-1]
// Read the VHDL file
f, err := os.ReadFile(dir + "/flopoco.vhdl")
if err != nil {
return nil, err
}
vHDL = string(f)
}
return FloPoCo{floPoCoName: name, regSize: regSize, vHDL: vHDL, topEntity: topEntity, entities: entities, pipeline: pipeline}, nil
}
func (d DynFloPoCo) HLAssemblerGeneratorMatch(bmc *bmconfig.BmConfig) []string {
result := make([]string, 0)
return result
}
func (d DynFloPoCo) HLAssemblerGeneratorList(bmc *bmconfig.BmConfig, bl *bmline.BasmLine) []string {
result := make([]string, 0)
return result
}