diff options
author | Jerry Zhao <jerryz123@berkeley.edu> | 2023-02-14 15:43:33 -0800 |
---|---|---|
committer | Jerry Zhao <jerryz123@berkeley.edu> | 2023-05-22 14:58:36 -0700 |
commit | 2af89e5977874ffdf8cfca67a48ad803d5fe08be (patch) | |
tree | 166c8a843e1147060e59c6be502bbbaed456e9da /benchmarks | |
parent | 9c8677c39e7959d3acd425f0c8032edda51375f0 (diff) | |
download | riscv-tests-2af89e5977874ffdf8cfca67a48ad803d5fe08be.zip riscv-tests-2af89e5977874ffdf8cfca67a48ad803d5fe08be.tar.gz riscv-tests-2af89e5977874ffdf8cfca67a48ad803d5fe08be.tar.bz2 |
Add vec-strcmp
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/Makefile | 1 | ||||
-rw-r--r-- | benchmarks/vec-strcmp/vec-strcmp.S | 32 | ||||
-rw-r--r-- | benchmarks/vec-strcmp/vec-strcmp_main.c | 34 |
3 files changed, 67 insertions, 0 deletions
diff --git a/benchmarks/Makefile b/benchmarks/Makefile index 4875111..ad7397b 100644 --- a/benchmarks/Makefile +++ b/benchmarks/Makefile @@ -35,6 +35,7 @@ bmarks = \ vec-memcpy \ vec-daxpy \ vec-sgemm \ + vec-strcmp \ #-------------------------------------------------------------------- # Build rules diff --git a/benchmarks/vec-strcmp/vec-strcmp.S b/benchmarks/vec-strcmp/vec-strcmp.S new file mode 100644 index 0000000..ff04333 --- /dev/null +++ b/benchmarks/vec-strcmp/vec-strcmp.S @@ -0,0 +1,32 @@ + .text + .balign 4 + .global vec_strcmp + # int vec_strcmp(const char *src1, const char* src2) +vec_strcmp: + ## Using LMUL=2, but same register names work for larger LMULs + li t1, 0 # Initial pointer bump +loop: + vsetvli t0, x0, e8, m2, ta, ma # Max length vectors of bytes + add a0, a0, t1 # Bump src1 pointer + vle8ff.v v8, (a0) # Get src1 bytes + add a1, a1, t1 # Bump src2 pointer + vle8ff.v v16, (a1) # Get src2 bytes + + vmseq.vi v0, v8, 0 # Flag zero bytes in src1 + vmsne.vv v1, v8, v16 # Flag if src1 != src2 + vmor.mm v0, v0, v1 # Combine exit conditions + + vfirst.m a2, v0 # ==0 or != ? + csrr t1, vl # Get number of bytes fetched + + bltz a2, loop # Loop if all same and no zero byte + + add a0, a0, a2 # Get src1 element address + lbu a3, (a0) # Get src1 byte from memory + + add a1, a1, a2 # Get src2 element address + lbu a4, (a1) # Get src2 byte from memory + + sub a0, a3, a4 # Return value. + + ret diff --git a/benchmarks/vec-strcmp/vec-strcmp_main.c b/benchmarks/vec-strcmp/vec-strcmp_main.c new file mode 100644 index 0000000..c17fa5f --- /dev/null +++ b/benchmarks/vec-strcmp/vec-strcmp_main.c @@ -0,0 +1,34 @@ +// See LICENSE for license details. + +//************************************************************************** +// Strcmp benchmark +//-------------------------------------------------------------------------- +// +// This benchmark tests a vectorized strcmp implementation. + +#include <string.h> +#include "util.h" + +//-------------------------------------------------------------------------- +// Input/Reference Data + +const char* test_str = "The quick brown fox jumped over the lazy dog"; +const char* same_str = "The quick brown fox jumped over the lazy dog"; +char* diff_str = "The quick brown fox jumped over the lazy cat"; + +//-------------------------------------------------------------------------- +// Main + +int vec_strcmp(const char *src1, const char* src2); + +int main( int argc, char* argv[] ) +{ + // Do the strcmp + setStats(1); + int r0 = vec_strcmp(test_str, same_str); + int r1 = vec_strcmp(test_str, diff_str); + setStats(0); + + // Check the results + return !(r0 == 0 && r1 != 0); +} |