-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds 2 simple E2E tests: - unsigned dwords multiplication - bubble sort algorithm
- Loading branch information
Showing
16 changed files
with
199 additions
and
40 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
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
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
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,9 @@ | ||
#ifndef BESM666_E2ETEST_BOOTSTRAP_H | ||
#define BESM666_E2ETEST_BOOTSTRAP_H | ||
|
||
typedef unsigned long long rv64dw; | ||
|
||
unsigned long long start(); | ||
unsigned long long do_nothing_with_value(unsigned long long); | ||
|
||
#endif /* BESM666_E2ETEST_BOOTSTRAP_H */ |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.option norvc | ||
.section ".text.init" | ||
.global _start | ||
|
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,44 @@ | ||
#include "bootstrap.h" | ||
|
||
rv64dw array[] = { | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
5, 4, 6, 8, 3, 6, 2, 7, 9, 4, 2, 5, 7, 8, 9, 4, 2, 2, 9, | ||
}; | ||
|
||
void bubble_sort(rv64dw* array, rv64dw size) { | ||
rv64dw* last = array + size - 1; | ||
for(rv64dw* i = array; i < last; ++i) { | ||
for(rv64dw* j = i; j < last; ++j) { | ||
rv64dw* cur = j; | ||
rv64dw* next = j + 1; | ||
|
||
if(*cur < *next) { | ||
rv64dw tmp = *cur; | ||
*cur = *next; | ||
*next = tmp; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int validate_sort(rv64dw const* array, rv64dw size) { | ||
for(rv64dw const* i = array; i < array + size - 1; ++i) { | ||
if(*i < *(i + 1)) { | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
rv64dw start() { | ||
bubble_sort(array, sizeof(array) / sizeof(array[0])); | ||
return validate_sort(array, sizeof(array) / sizeof(array[0])); | ||
} |
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,53 @@ | ||
.option norvc | ||
.section .text | ||
.global start | ||
|
||
// multiplies two unsigned dwords | ||
// a1 - first multiplier | ||
// a2 - second multplier | ||
// a0 - result | ||
mul: | ||
// leaf function, can reduce stack frame creation | ||
|
||
add a0, zero, zero | ||
|
||
.mul_loop: | ||
andi t0, a2, 0x1 | ||
beqz t0, .mul_next | ||
add a0, a0, a1 | ||
.mul_next: | ||
srli a2, a2, 0x1 | ||
slli a1, a1, 0x1 | ||
|
||
bnez a2, .mul_loop | ||
|
||
.mul_end: | ||
jalr zero, ra, 0 | ||
|
||
start: | ||
// creating stack frame of 8 bytes size | ||
// to store ra register value onto the stack | ||
addi sp, sp, -8 | ||
// store ra onto the stack | ||
sd ra, 0(sp) | ||
|
||
// load operands of mul function: want to get value of 15 * 8 | ||
li a1, 15 | ||
li a2, 8 | ||
call mul | ||
|
||
li a1, 120 | ||
sub a0, a0, a1 | ||
bnez a0, .fail | ||
|
||
.success: | ||
li a0, 1 | ||
j .finish | ||
|
||
.fail: | ||
li a0, 0 | ||
|
||
.finish: | ||
ld ra, 0(sp) | ||
add sp, sp, 8 | ||
jalr zero, ra, 0 |
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,21 @@ | ||
#include "bootstrap.h" | ||
|
||
rv64dw __umoddi3(rv64dw value, rv64dw div) { | ||
while(value >= div) { | ||
value -= div; | ||
} | ||
return value; | ||
} | ||
|
||
int is_prime(rv64dw value) { | ||
for(rv64dw i = 2; i < value / 2; ++i) { | ||
if(value % i == 0) { | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
rv64dw start() { | ||
return is_prime(1787); | ||
} |
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
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
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
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
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
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
Oops, something went wrong.