|
| 1 | +/********************************************************************** |
| 2 | + Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS). |
| 3 | + |
| 4 | + Redistribution and use in source and binary forms, with or without |
| 5 | + modification, are permitted provided that the following conditions |
| 6 | + are met: |
| 7 | + * Redistributions of source code must retain the above copyright |
| 8 | + notice, this list of conditions and the following disclaimer. |
| 9 | + * Redistributions in binary form must reproduce the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer in |
| 11 | + the documentation and/or other materials provided with the |
| 12 | + distribution. |
| 13 | + * Neither the name of ISCAS Corporation nor the names of its |
| 14 | + contributors may be used to endorse or promote products derived |
| 15 | + from this software without specific prior written permission. |
| 16 | + |
| 17 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +**********************************************************************/ |
| 29 | +#if HAVE_RVV |
| 30 | +.option arch, +v |
| 31 | +.global xor_gen_rvv |
| 32 | +.type xor_gen_rvv, %function |
| 33 | +xor_gen_rvv: |
| 34 | + beqz a1, ret0 # len <= 0, return 0 |
| 35 | + addi t1, a0, -2 # vects - 3 |
| 36 | + blez t1, ret1 # vects < 3, return 1 |
| 37 | + |
| 38 | + slli t0, a0, 3 # t0 = vects * 8 |
| 39 | + add t0, a2, t0 # array + vects * 8 |
| 40 | + ld a4, 0(a2) # src[0] |
| 41 | + ld a3, -8(t0) # dest = array[vects - 1] |
| 42 | + mv t5, a3 # save dest |
| 43 | + mv t6, a1 # save len |
| 44 | + |
| 45 | +init_dest: |
| 46 | + vsetvli t4, t6, e8, m8, ta, ma |
| 47 | + vle8.v v0, (a4) # load src[0] |
| 48 | + vse8.v v0, (a3) # dest |
| 49 | + sub t6, t6, t4 |
| 50 | + add a4, a4, t4 |
| 51 | + add a3, a3, t4 |
| 52 | + bnez t6, init_dest |
| 53 | + |
| 54 | +outer_j: |
| 55 | + mv a3, t5 # restore dest |
| 56 | + mv t6, a1 # restore length |
| 57 | + ld a4, -16(t0) |
| 58 | + |
| 59 | +inner_len: |
| 60 | + vsetvli t4, t6, e8, m8, ta, ma |
| 61 | + vle8.v v0, (a4) # src[j] |
| 62 | + vle8.v v8, (a3) # dest |
| 63 | + vxor.vv v8, v8, v0 # dest ^= src[j] |
| 64 | + vse8.v v8, (a3) |
| 65 | + sub t6, t6, t4 |
| 66 | + add a4, a4, t4 |
| 67 | + add a3, a3, t4 |
| 68 | + bnez t6, inner_len |
| 69 | + |
| 70 | + addi t1, t1, -1 |
| 71 | + addi t0, t0, -8 |
| 72 | + bnez t1, outer_j |
| 73 | + |
| 74 | +ret0: |
| 75 | + li a0, 0 |
| 76 | + ret |
| 77 | + |
| 78 | +ret1: |
| 79 | + li a0, 1 |
| 80 | + ret |
| 81 | + |
| 82 | +#endif |
0 commit comments