Skip to content

Commit 967a8d5

Browse files
authored
Merge pull request #7 from dramforever/add-vector-zb
2 parents 960dc8d + 9e64ed3 commit 967a8d5

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ jobs:
4747

4848
- name: Run invalid-regname example
4949
run: bin/run invalid-regname || true
50+
51+
- name: Run rvv-memcpy example
52+
run: bin/run rvv-memcpy
53+
54+
- name: Run rvk-sha256sig0 example
55+
run: bin/run rvk-sha256sig0

bin/run

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ fi
1111

1212
W=/workspace
1313

14+
ARCH=rv64gcv_zba_zbb_zbc_zbs_zbkx_zk_zks
15+
QEMU_CPU=rv64,v=on,vext_spec=v1.0,zbkx=on,zk=on,zks=on
16+
1417
# Create container
15-
C=$($CONTAINER_ENGINE container create --rm -w $W $IMAGE_TAG sh -c "gcc -O2 solution.s solution_tests.c -lcgreen codewars_reporter.c tests.c -o tests && ./tests")
18+
C=$($CONTAINER_ENGINE container create --rm --env QEMU_CPU=$QEMU_CPU -w $W $IMAGE_TAG sh -c "gcc -O2 solution.s -march=$ARCH solution_tests.c -lcgreen codewars_reporter.c tests.c -o tests && ./tests")
1619

1720
# Copy files from the current directory
1821
# example/solution.s

examples/rvk-sha256sig0/solution.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.globl sha256_sigma0
2+
3+
sha256_sigma0:
4+
sha256sig0 a0, a0
5+
ret
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdlib.h>
2+
#include <time.h>
3+
#include <stddef.h>
4+
#include <stdint.h>
5+
#include <cgreen/cgreen.h>
6+
7+
uint32_t sha256_sigma0(uint32_t input);
8+
9+
uint32_t sha256_sigma0_ref(uint32_t input) {
10+
uint32_t a = (input >> 7) | (input << 25);
11+
uint32_t b = (input >> 18) | (input << 14);
12+
uint32_t c = input >> 3;
13+
return a ^ b ^ c;
14+
}
15+
16+
Describe(sha256_sigma0);
17+
BeforeEach(sha256_sigma0) {}
18+
AfterEach(sha256_sigma0) {}
19+
20+
Ensure(sha256_sigma0, works_for_some_fixed_tests) {
21+
assert_that(sha256_sigma0(0x12345678u), is_equal_to(sha256_sigma0_ref(0x12345678)));
22+
}
23+
24+
TestSuite *solution_tests() {
25+
TestSuite *suite = create_test_suite();
26+
add_test_with_context(suite, sha256_sigma0, works_for_some_fixed_tests);
27+
return suite;
28+
}

examples/rvv-memcpy/solution.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.globl rvv_memcpy
2+
3+
rvv_memcpy:
4+
mv a4, a0
5+
6+
1:
7+
vsetvli a3, a2, e8, m8, ta, ma
8+
vle8.v v8, (a1)
9+
vse8.v v8, (a0)
10+
add a0, a0, a3
11+
add a1, a1, a3
12+
sub a2, a2, a3
13+
bnez a2, 1b
14+
15+
mv a0, a4
16+
ret

examples/rvv-memcpy/solution_tests.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdlib.h>
2+
#include <time.h>
3+
#include <stddef.h>
4+
#include <cgreen/cgreen.h>
5+
6+
void *rvv_memcpy(void *dst, const void *src, size_t len);
7+
8+
Describe(rvv_memcpy);
9+
BeforeEach(rvv_memcpy) {}
10+
AfterEach(rvv_memcpy) {}
11+
12+
Ensure(rvv_memcpy, works_for_some_fixed_tests) {
13+
char buf1[] = "Hello, world!";
14+
char buf2[] = "Alhoa, RISC-V!";
15+
char *res = rvv_memcpy(buf2, buf1, 5);
16+
assert_that(res, is_equal_to(buf2));
17+
assert_that(buf2, is_equal_to_string("Hello, RISC-V!"));
18+
}
19+
20+
TestSuite *solution_tests() {
21+
TestSuite *suite = create_test_suite();
22+
add_test_with_context(suite, rvv_memcpy, works_for_some_fixed_tests);
23+
return suite;
24+
}

0 commit comments

Comments
 (0)