-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator_py_function.py
299 lines (235 loc) · 4.52 KB
/
operator_py_function.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def add_op(a, b, c=None, m=None):
# vadd vwadd
if m == 0:
return c
else:
return a + b
def sub_op(a, b, c=None, m=None):
# vsub
if m == 0:
return c
else:
return a - b
def mul_op(a, b, c=None, m=None):
# vmul
if m == 0:
return c
else:
return a * b
def div_op(a, b, c=None, m=None):
# vdiv
if m == 0:
return c
else:
if a == 0:
return -1
else:
return b // a
def max_op(a, b, c=None, m=None):
# vmax
if m == 0:
return c
else:
if a > b:
return a
else:
return b
def min_op(a, b, c=None, m=None):
# vmin
if m == 0:
return c
else:
if a > b:
return a
else:
return b
def reminder(a, b, c=None, m=None):
if m == 0:
return c
else:
if a == 0:
return b
else:
return b % a
def add_with_carry_op(a, b, m):
return a + b + m
def sub_with_borrow_op(a, b, c=None, m=None):
if m == 1:
return a - b - m
else:
return a - b
def and_op(a, b, c=None, m=None):
if m == 0:
return c
else:
return a and b
def merge_op(a, b, m):
# always should be masked
if m == 0:
return a
else:
return b
def multiply_add_overwrite_addend_op(a, b, c=None, m=None):
# vmacc
if m == 0:
return c
else:
return a * b + c
def multiply_add_overwrite_multiplicand_op(c, a, b, m=None):
# vmadd
if m == 0:
return c
else:
return b * c + a
def multiply_sbc_overwrite_multiplicand_op(c, a, b, m=None):
# vmsbc
# Produce borrow out in mask register format
if m == 0:
if a >= b:
c = 0
return c
else:
c = 1
return c
else:
if a >= (b - 1):
c = 0
return c
else:
c = 1
return c
def equal_to_op(a, b, n, m=None):
# vmseq
# n present the vd.mask
if m == 0:
return n
else:
if a == b:
return 1
else:
return 0
def not_equal_to_op(a, b, n, m=None):
# vmsne
# n present the vd.mask
if m == 0:
return n
else:
if a == b:
return 0
else:
return 1
def move_op(a):
# vmv
return a
def neg_op(a):
# vneg
return -a
def not_op(a, c=None, m=None):
# vnot
if m == 0:
return c
else:
return a ^ -1
def add_with_carry_return_mask_op(a, b, m):
# vmadc
return a + b + m
def sub_with_borrow_return_mask_op(a, b, m):
# vmsbc
return a - b - m
def nmsac_op(a, b, c, m=None):
# vnmsac
# Integer multiply-sub, overwrite minuend
if m == 0:
return c
else:
c = -(a * b) + c
return c
def nmsub_op(a, b, c, m=None):
# vnmsub
# vd[i] = -(vs1[i] * vd[i]) + vs2[i]
if m == 0:
return c
else:
c = -(b * c) + a
return c
def or_op(a, b, c, m=None):
# vor
if m == 0:
return c
else:
c = a | b
return c
def shift_right_op(a, b, c, m=None):
# vsra, vsrl
if m == 0:
return c
else:
c = a >> b
return c
def shift_left_op(a, b, c, m=None):
# vsll
if m == 0:
return c
else:
c = a << b
return c
def greater_equal_op(a, b, c, m=None):
# vmsge
if m == 0:
return c
else:
if a >= b:
c = 1
return c
else:
c = 0
return c
def less_equal_op(a, b, c, m=None):
# vmsle
if m == 0:
return c
else:
if a <= b:
c = 1
return c
else:
c = 0
return c
def less_than_op(a, b, c, m=None):
# vmslt
if m == 0:
return c
else:
if a < b:
c = 1
return c
else:
c = 0
return c
def greater_than_op(a, b, c, m=None):
# vmsge
if m == 0:
return c
else:
if a > b:
c = 1
return c
else:
c = 0
return c
def reverse_sub_op(a, b, c=None, m=None):
# vrsub
if m == 0:
return c
else:
return b - a
def xor_op(a, b, c=None, m=None):
if m == 0:
return c
else:
if a == b:
c = 0
return c
else:
c = 1
return c