-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbril_vector_utilities.py
120 lines (72 loc) · 2.57 KB
/
bril_vector_utilities.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
from bril_vector_constants import *
from bril_core_constants import *
def is_vec(instr):
assert type(instr) == dict
return OP in instr and instr[OP] in VEC_OPS
def build_vecbinop(dest, left, right, binop):
assert type(dest) == str
assert type(left) == str
assert type(right) == str
assert binop in VEC_BINOPS
return {DEST: dest, TYPE: VECTOR, OP: binop, ARGS: [left, right]}
def build_vecadd(dest, left, right):
return build_vecbinop(dest, left, right, VECADD)
def build_vecsub(dest, left, right):
return build_vecbinop(dest, left, right, VECSUB)
def build_vecmul(dest, left, right):
return build_vecbinop(dest, left, right, VECMUL)
def build_vecdiv(dest, left, right):
return build_vecbinop(dest, left, right, VECDIV)
def build_vecunop(dest, arg, unop):
assert type(dest) == str
assert type(arg) == str
assert unop in VEC_UNOPS
return {DEST: dest, TYPE: VECTOR, OP: unop, ARGS: [arg]}
def build_vecneg(dest, arg):
return build_vecunop(dest, arg, VECNEG)
def build_vecmac(dest, m1, m2, a):
assert type(dest) == str
assert type(m1) == str
assert type(m2) == str
assert type(a) == str
return {DEST: dest, TYPE: VECTOR, OP: VECMAC, ARGS: [m1, m2, a]}
def build_veczero(dest):
assert type(dest) == str
return {DEST: dest, TYPE: VECTOR, OP: VECZERO, ARGS: []}
def build_vecload(vector, index, data):
assert type(vector) == str
assert type(index) == str
assert type(data) == str
return {OP: VECLOAD, ARGS: [vector, index, data]}
def build_vecstore(dest, vector, index):
assert type(vector) == str
assert type(index) == str
assert type(dest) == str
return {DEST: dest, TYPE: VECTOR, OP: VECSTORE, ARGS: [vector, index]}
def build_vecmove(dest, vector):
assert type(vector) == str
assert type(dest) == str
return {DEST: dest, TYPE: VECTOR, OP: VECMOVE, ARGS: [vector]}
def is_vec_op(instr, op):
assert type(instr) == dict
return OP in instr and instr[OP] == op
def is_vecadd(instr):
return is_vec_op(instr, VECADD)
def is_vecsub(instr):
return is_vec_op(instr, VECSUB)
def is_vecmul(instr):
return is_vec_op(instr, VECMUL)
def is_vecdiv(instr):
return is_vec_op(instr, VECDIV)
def is_vecneg(instr):
return is_vec_op(instr, VECNEG)
def is_vecmac(instr):
return is_vec_op(instr, VECMAC)
def is_vecload(instr):
return is_vec_op(instr, VECLOAD)
def is_vecstore(instr):
return is_vec_op(instr, VECSTORE)
def is_veczero(instr):
return is_vec_op(instr, VECZERO)
def is_vecmove(instr):
return is_vec_op(instr, VECMOVE)