Skip to content

Commit 25eea7c

Browse files
committed
Replace mul in classify.s
Replace four `mul` instructions in classify.s with cumulative addition/subtraction logic, inspired by the earlier `dot` operation implementation.
1 parent 61b1015 commit 25eea7c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/classify.s

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ classify:
167167
lw t0, 0(s3)
168168
lw t1, 0(s8)
169169
# mul a0, t0, t1 # FIXME: Replace 'mul' with your own implementation
170+
171+
li t5, 0
172+
accumulate:
173+
add t5,t5,t0
174+
addi t1, t1, -1
175+
bne t1, zero, accumulate
176+
mv a0, t5
177+
170178
slli a0, a0, 2
171179
jal malloc
172180
beq a0, x0, error_malloc
@@ -206,6 +214,13 @@ classify:
206214
# mul a1, t0, t1 # length of h array and set it as second argument
207215
# FIXME: Replace 'mul' with your own implementation
208216

217+
li t5, 0
218+
accumulate_1:
219+
add t5,t5,t0
220+
addi t1, t1, -1
221+
bne t1, zero, accumulate_1
222+
mv a1, t5
223+
209224
jal relu
210225

211226
lw a0, 0(sp)
@@ -227,6 +242,14 @@ classify:
227242
lw t0, 0(s3)
228243
lw t1, 0(s6)
229244
# mul a0, t0, t1 # FIXME: Replace 'mul' with your own implementation
245+
246+
li t5, 0
247+
accumulate_2:
248+
add t5,t5,t0
249+
addi t1, t1, -1
250+
bne t1, zero, accumulate_2
251+
mv a0, t5
252+
230253
slli a0, a0, 2
231254
jal malloc
232255
beq a0, x0, error_malloc
@@ -286,9 +309,16 @@ classify:
286309
mv a0, s10 # load o array into first arg
287310
lw t0, 0(s3)
288311
lw t1, 0(s6)
289-
mul a1, t0, t1 # load length of array into second arg
312+
#mul a1, t0, t1 # load length of array into second arg
290313
# FIXME: Replace 'mul' with your own implementation
291314

315+
li t5, 0
316+
accumulate_3:
317+
add t5,t5,t0
318+
addi t1, t1, -1
319+
bne t1, zero, accumulate_3
320+
mv a1, t5
321+
292322
jal argmax
293323

294324
mv t0, a0 # move return value of argmax into t0

0 commit comments

Comments
 (0)