Skip to content

Commit

Permalink
Merge pull request #7 from dramforever/add-vector-zb
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk authored Nov 3, 2022
2 parents 960dc8d + 9e64ed3 commit 967a8d5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ jobs:

- name: Run invalid-regname example
run: bin/run invalid-regname || true

- name: Run rvv-memcpy example
run: bin/run rvv-memcpy

- name: Run rvk-sha256sig0 example
run: bin/run rvk-sha256sig0
5 changes: 4 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ fi

W=/workspace

ARCH=rv64gcv_zba_zbb_zbc_zbs_zbkx_zk_zks
QEMU_CPU=rv64,v=on,vext_spec=v1.0,zbkx=on,zk=on,zks=on

# Create container
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")
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")

# Copy files from the current directory
# example/solution.s
Expand Down
5 changes: 5 additions & 0 deletions examples/rvk-sha256sig0/solution.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.globl sha256_sigma0

sha256_sigma0:
sha256sig0 a0, a0
ret
28 changes: 28 additions & 0 deletions examples/rvk-sha256sig0/solution_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdlib.h>
#include <time.h>
#include <stddef.h>
#include <stdint.h>
#include <cgreen/cgreen.h>

uint32_t sha256_sigma0(uint32_t input);

uint32_t sha256_sigma0_ref(uint32_t input) {
uint32_t a = (input >> 7) | (input << 25);
uint32_t b = (input >> 18) | (input << 14);
uint32_t c = input >> 3;
return a ^ b ^ c;
}

Describe(sha256_sigma0);
BeforeEach(sha256_sigma0) {}
AfterEach(sha256_sigma0) {}

Ensure(sha256_sigma0, works_for_some_fixed_tests) {
assert_that(sha256_sigma0(0x12345678u), is_equal_to(sha256_sigma0_ref(0x12345678)));
}

TestSuite *solution_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, sha256_sigma0, works_for_some_fixed_tests);
return suite;
}
16 changes: 16 additions & 0 deletions examples/rvv-memcpy/solution.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.globl rvv_memcpy

rvv_memcpy:
mv a4, a0

1:
vsetvli a3, a2, e8, m8, ta, ma
vle8.v v8, (a1)
vse8.v v8, (a0)
add a0, a0, a3
add a1, a1, a3
sub a2, a2, a3
bnez a2, 1b

mv a0, a4
ret
24 changes: 24 additions & 0 deletions examples/rvv-memcpy/solution_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdlib.h>
#include <time.h>
#include <stddef.h>
#include <cgreen/cgreen.h>

void *rvv_memcpy(void *dst, const void *src, size_t len);

Describe(rvv_memcpy);
BeforeEach(rvv_memcpy) {}
AfterEach(rvv_memcpy) {}

Ensure(rvv_memcpy, works_for_some_fixed_tests) {
char buf1[] = "Hello, world!";
char buf2[] = "Alhoa, RISC-V!";
char *res = rvv_memcpy(buf2, buf1, 5);
assert_that(res, is_equal_to(buf2));
assert_that(buf2, is_equal_to_string("Hello, RISC-V!"));
}

TestSuite *solution_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, rvv_memcpy, works_for_some_fixed_tests);
return suite;
}

0 comments on commit 967a8d5

Please sign in to comment.