aboutsummaryrefslogtreecommitdiff
path: root/riscv
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2013-08-13 00:54:21 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2013-08-13 00:54:21 -0700
commitbe3414250dcdb258408b9a75187d4b0c99eb46b5 (patch)
treefbf116440fb863f64a8c8e3d10ff3c7b697ef8bb /riscv
parentbbb0f2179c858c77918ef37dbfcd7bb5f3fd0417 (diff)
downloadriscv-isa-sim-be3414250dcdb258408b9a75187d4b0c99eb46b5.zip
riscv-isa-sim-be3414250dcdb258408b9a75187d4b0c99eb46b5.tar.gz
riscv-isa-sim-be3414250dcdb258408b9a75187d4b0c99eb46b5.tar.bz2
Add test program for dummy rocc
Should move this elsewhere
Diffstat (limited to 'riscv')
-rw-r--r--riscv/dummy-rocc-test.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/riscv/dummy-rocc-test.c b/riscv/dummy-rocc-test.c
new file mode 100644
index 0000000..ba362a4
--- /dev/null
+++ b/riscv/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 riscv-gcc dummy.c
+// Run with spike --extension=dummy 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");
+}