-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathbinary_intcarry_template.py
124 lines (108 loc) · 3.94 KB
/
binary_intcarry_template.py
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
120
121
122
123
124
"""
--------------------------------------------------------------------------------
Copyright 2022 SiFive Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--------------------------------------------------------------------------------
Template for rendering Add-With-Carry and Subtract-With-Borrow instructions
to their corresponding intrinsics.
"""
#pylint: disable=relative-beyond-top-level
from utils import prod
from utils import TypeHelper
from enums import InstInfo
from enums import InstType
def render(G, op_list, type_list, sew_list, lmul_list, decorator_list,
description):
#pylint: disable=invalid-name
# FIXME: Renaming 'G' to 'g' all in once later.
G.emit_function_group_description(description)
G.inst_group_prologue()
for decorator in decorator_list:
decorator.write_text_header(G)
for args in prod(OP=op_list, TYPE=type_list, SEW=sew_list, LMUL=lmul_list):
type_helper = TypeHelper(**args)
v = type_helper.v
s = type_helper.s
m = type_helper.m
assert args["OP"] is not None
args["OP"] = "v" + args["OP"]
inst_info_vvm = InstInfo.get(args, decorator, InstType.VVVM)
inst_info_vxm = InstInfo.get(args, decorator, InstType.VVXM)
if not "m" in args["OP"]:
G.func(
inst_info=inst_info_vvm,
name="{OP}_vvm_{TYPE}{SEW}m{LMUL}".format_map(args) +
decorator.func_suffix,
return_type=v,
**decorator.tu_dest_args(v),
vs2=v,
vs1=v,
v0=m,
vl=type_helper.size_t)
G.func(
inst_info=inst_info_vxm,
name="{OP}_vxm_{TYPE}{SEW}m{LMUL}".format_map(args) +
decorator.func_suffix,
return_type=v,
**decorator.tu_dest_args(v),
vs2=v,
rs1=s,
v0=m,
vl=type_helper.size_t)
for args in prod(OP=op_list, TYPE=type_list, SEW=sew_list, LMUL=lmul_list):
type_helper = TypeHelper(**args)
v = type_helper.v
s = type_helper.s
m = type_helper.m
assert args["OP"] is not None
args["OP"] = "v" + args["OP"]
inst_info_vvm = InstInfo.get(args, None, InstType.VVVM)
inst_info_vxm = InstInfo.get(args, None, InstType.VVXM)
inst_info_vv = InstInfo.get(args, None, InstType.VVV)
inst_info_vx = InstInfo.get(args, None, InstType.VVX)
# madc or msbc
if "m" in args["OP"]:
args["MLEN"] = type_helper.mlen
G.func(
inst_info_vvm,
name="{OP}_vvm_{TYPE}{SEW}m{LMUL}_b{MLEN}".format_map(args) +
decorator.func_suffix,
return_type=m,
vs2=v,
vs1=v,
v0=m,
vl=type_helper.size_t)
G.func(
inst_info_vxm,
name="{OP}_vxm_{TYPE}{SEW}m{LMUL}_b{MLEN}".format_map(args) +
decorator.func_suffix,
return_type=m,
vs2=v,
rs1=s,
v0=m,
vl=type_helper.size_t)
G.func(
inst_info_vv,
name="{OP}_vv_{TYPE}{SEW}m{LMUL}_b{MLEN}".format_map(args) +
decorator.func_suffix,
return_type=m,
vs2=v,
vs1=v,
vl=type_helper.size_t)
G.func(
inst_info_vx,
name="{OP}_vx_{TYPE}{SEW}m{LMUL}_b{MLEN}".format_map(args) +
decorator.func_suffix,
return_type=m,
vs2=v,
rs1=s,
vl=type_helper.size_t)
G.inst_group_epilogue()