|
| 1 | + .text |
| 2 | + .balign 4 |
| 3 | + .global vec_strcmp |
| 4 | + # int vec_strcmp(const char *src1, const char* src2) |
| 5 | +vec_strcmp: |
| 6 | + ## Using LMUL=2, but same register names work for larger LMULs |
| 7 | + li t1, 0 # Initial pointer bump |
| 8 | +loop: |
| 9 | + vsetvli t0, x0, e8, m2, ta, ma # Max length vectors of bytes |
| 10 | + add a0, a0, t1 # Bump src1 pointer |
| 11 | + vle8ff.v v8, (a0) # Get src1 bytes |
| 12 | + add a1, a1, t1 # Bump src2 pointer |
| 13 | + vle8ff.v v16, (a1) # Get src2 bytes |
| 14 | + |
| 15 | + vmseq.vi v0, v8, 0 # Flag zero bytes in src1 |
| 16 | + vmsne.vv v1, v8, v16 # Flag if src1 != src2 |
| 17 | + vmor.mm v0, v0, v1 # Combine exit conditions |
| 18 | + |
| 19 | + vfirst.m a2, v0 # ==0 or != ? |
| 20 | + csrr t1, vl # Get number of bytes fetched |
| 21 | + |
| 22 | + bltz a2, loop # Loop if all same and no zero byte |
| 23 | + |
| 24 | + add a0, a0, a2 # Get src1 element address |
| 25 | + lbu a3, (a0) # Get src1 byte from memory |
| 26 | + |
| 27 | + add a1, a1, a2 # Get src2 element address |
| 28 | + lbu a4, (a1) # Get src2 byte from memory |
| 29 | + |
| 30 | + sub a0, a3, a4 # Return value. |
| 31 | + |
| 32 | + ret |
0 commit comments