diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2014-11-25 13:39:53 -0800 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2014-11-25 14:40:51 -0800 |
commit | 590417bec978bfc3fbf35d303760494395eb65b2 (patch) | |
tree | e264e60f8ad9eba772257c9b2676997cd02b7140 /dummy_rocc/dummy_rocc_test.c | |
parent | c31742961bdab9094c35ef6c1b33186892aa34d1 (diff) | |
download | spike-590417bec978bfc3fbf35d303760494395eb65b2.zip spike-590417bec978bfc3fbf35d303760494395eb65b2.tar.gz spike-590417bec978bfc3fbf35d303760494395eb65b2.tar.bz2 |
Factor out the dummy RoCC accelerator
Diffstat (limited to 'dummy_rocc/dummy_rocc_test.c')
-rw-r--r-- | dummy_rocc/dummy_rocc_test.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/dummy_rocc/dummy_rocc_test.c b/dummy_rocc/dummy_rocc_test.c new file mode 100644 index 0000000..94de8c0 --- /dev/null +++ b/dummy_rocc/dummy_rocc_test.c @@ -0,0 +1,29 @@ +// The following is a RISC-V program to test the functionality of the +// dummy RoCC accelerator. +// Compile with riscv64-unknown-elf-gcc dummy_rocc_test.c +// Run with spike --extension=dummy_rocc pk a.out + +#include <assert.h> +#include <stdio.h> +#include <stdint.h> + +int main() { + uint64_t x = 123, y = 456, z = 0; + // load x into accumulator 2 (funct=0) + asm volatile ("custom0 x0, %0, 2, 0" : : "r"(x)); + // read it back into z (funct=1) to verify it + asm volatile ("custom0 %0, x0, 2, 1" : "=r"(z)); + assert(z == x); + // accumulate 456 into it (funct=3) + asm volatile ("custom0 x0, %0, 2, 3" : : "r"(y)); + // verify it + asm volatile ("custom0 %0, x0, 2, 1" : "=r"(z)); + assert(z == x+y); + // do it all again, but initialize acc2 via memory this time (funct=2) + asm volatile ("custom0 x0, %0, 2, 2" : : "r"(&x)); + asm volatile ("custom0 x0, %0, 2, 3" : : "r"(y)); + asm volatile ("custom0 %0, x0, 2, 1" : "=r"(z)); + assert(z == x+y); + + printf("success!\n"); +} |