-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement vector and scalar example algorithms
- Loading branch information
1 parent
968605b
commit 8b5c4be
Showing
10 changed files
with
203 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
apps/webapp/src/widgets/program_view/examples/daxpy_scalar.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.text | ||
main: | ||
li a0, 4 # n = 4 | ||
la t0, fp # Address of scalar a | ||
fld fa0, 0(t0) # Load scalar a into fa0 | ||
la a1, x # Address of vector x | ||
la a2, y # Address of vector y | ||
|
||
call daxpy | ||
j finish | ||
|
||
daxpy: | ||
li t1, 0 # i = 0 | ||
loop: | ||
fld fa1, 0(a1) # Load x[i] into fa1 | ||
fmul.d fa1, fa1, fa0 # Compute a*x[i] | ||
fld fa2, 0(a2) # Load y[i] into fa2 | ||
fadd.d fa2, fa2, fa1 # Compute y[i] = y[i] + a*x[i] | ||
fsd fa2, 0(a2) # Store result back to y[i] | ||
addi t1, t1, 1 # i = i + 1 | ||
addi a1, a1, 8 # Move to next element of x | ||
addi a2, a2, 8 # Move to next element of y | ||
blt t1, a0, loop # If i < n, repeat | ||
ret # Return | ||
|
||
finish: | ||
|
||
.data | ||
fp: | ||
.double 3.14159265 | ||
x: | ||
.double 0.84, 0.14, 0.36, 0.42 | ||
y: | ||
.double 0.61, 0.56, 0.77, 0.60 |
32 changes: 32 additions & 0 deletions
32
apps/webapp/src/widgets/program_view/examples/daxpy_vector.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
main: | ||
li a0, 4 | ||
la t0, fp | ||
fld fa0, 0(t0) | ||
la a1, x | ||
la a2, y | ||
|
||
call daxpy | ||
j finish | ||
|
||
daxpy: | ||
vsetvli a4, a0, e64, m8, ta, ma | ||
vse64.v v0, (a1) | ||
sub a0, a0, a4 | ||
slli a4, a4, 2 | ||
add a1, a1, a4 | ||
vse64.v v8, (a2) | ||
vfmacc.vf v8, fa0, v0 | ||
vse64.v v8, (a2) | ||
add a2, a2, a4 | ||
bnez a0, daxpy | ||
ret | ||
|
||
finish: | ||
|
||
.data | ||
fp: | ||
.double 3.14159265 | ||
x: | ||
.double 0.84, 0.14, 0.36, 0.42 | ||
y: | ||
.double 0.61, 0.56, 0.77, 0.60 |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
apps/webapp/src/widgets/program_view/examples/strcpy_scalar.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.text | ||
main: | ||
li a0, 0x10 # Destination address | ||
la a1, to_copy # Source address | ||
|
||
call strcpy | ||
j finish | ||
|
||
strcpy: | ||
mv a2, a0 # Copy destination address to a2 | ||
loop: | ||
lb t0, 0(a1) # Load byte from source address | ||
sb t0, 0(a2) # Store byte to destination address | ||
addi a1, a1, 1 # Increment source address | ||
addi a2, a2, 1 # Increment destination address | ||
bnez t0, loop # Repeat if the loaded byte is not null (0) | ||
ret # Return | ||
|
||
finish: | ||
|
||
.data | ||
to_copy: | ||
.asciz "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/webapp/src/widgets/program_view/examples/strlen_scalar.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.text | ||
main: | ||
la a0, to_copy # Source address | ||
|
||
call strlen | ||
j finish | ||
|
||
strlen: | ||
mv a1, a0 # Copy source address to a1 | ||
loop: | ||
lb t0, 0(a1) # Load byte from source address | ||
addi a1, a1, 1 # Increment source address | ||
bnez t0, loop # Repeat if the loaded byte is not null (0) | ||
sub a0, a1, a0 # Calculate length by subtracting start address from end address | ||
addi a0, a0, -1 # Subtract 1 as a1 is one past the null byte | ||
|
||
ret # Return | ||
|
||
finish: | ||
|
||
.data | ||
to_copy: | ||
.asciz "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
apps/webapp/src/widgets/program_view/examples/strncpy_scalar.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.text | ||
main: | ||
li a0, 0x10 # Destination address | ||
la a1, to_copy # Source address | ||
li a2, 9 # At most | ||
|
||
call strncpy | ||
j finish | ||
|
||
strncpy: | ||
mv a3, a0 # Copy destination address to a3 | ||
mv t0, a2 # Copy max count to t0 | ||
loop: | ||
lb t1, 0(a1) # Load byte from source address | ||
sb t1, 0(a3) # Store byte to destination address | ||
addi a1, a1, 1 # Increment source address | ||
addi a3, a3, 1 # Increment destination address | ||
addi t0, t0, -1 # Decrement count | ||
bnez t1, check_count # If byte is not null, check count | ||
fill_zero: | ||
bnez t0, zero_loop # If count is not zero, fill with zero | ||
ret | ||
|
||
check_count: | ||
bnez t0, loop # If count is not zero, continue loop | ||
ret | ||
|
||
zero_loop: | ||
sb x0, 0(a3) # Store zero to destination address | ||
addi a3, a3, 1 # Increment destination address | ||
addi t0, t0, -1 # Decrement count | ||
j fill_zero # Jump back to fill_zero | ||
|
||
finish: | ||
|
||
.data | ||
to_copy: | ||
.asciz "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters