-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith_unroll_scheduled_factor_2.s
40 lines (28 loc) · 1.04 KB
/
with_unroll_scheduled_factor_2.s
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
# RISC-V Assembly code with loop unrolling for 5-stage pipeline
.data
array: .word 1, 2, 3, 4, 5, 6, 7, 8
size: .word 8
sum: .word 0
.text
# Load address of array into x1
la x1, array
# Load size of array into x4
lw x4, size
# Initialize sum to 0
li x3, 0
# Loop Unrolling
loop:
# Load array element and add to sum (unrolled iteration 1)
# Load next array element and add to sum (unrolled iteration 2)
lw x2, 0(x1) # Load array element
lw x12, 4(x1) # Load array element
add x3, x3, x2 # Add to sum
add x3, x3, x12 # Add to sum
addi x1, x1, 8 # Move to next element
#addi x1, x1, 4 # Move to next element
# Decrement counter by 2
addi x4, x4, -2 # Decrement counter
bne x4,x0,loop # loop condition
# Store the final sum in memory
sw x3,0(x1) #sum
nop