github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/bytealg/equal_riscv64.s (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "go_asm.h" 6 #include "textflag.h" 7 8 #define CTXT S10 9 10 // func memequal(a, b unsafe.Pointer, size uintptr) bool 11 TEXT runtime·memequal<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-25 12 // X10 = a_base 13 // X11 = b_base 14 // X12 = size 15 JMP memequal<>(SB) 16 17 // func memequal_varlen(a, b unsafe.Pointer) bool 18 TEXT runtime·memequal_varlen<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-17 19 MOV 8(CTXT), X12 // compiler stores size at offset 8 in the closure 20 // X10 = a_base 21 // X11 = b_base 22 JMP memequal<>(SB) 23 24 // On entry X10 and X11 contain pointers, X12 contains length. 25 // For non-regabi X13 contains address for return value. 26 // For regabi return value in X10. 27 TEXT memequal<>(SB),NOSPLIT|NOFRAME,$0 28 BEQ X10, X11, eq 29 30 MOV $32, X23 31 BLT X12, X23, loop4_check 32 33 // Check alignment - if alignment differs we have to do one byte at a time. 34 AND $7, X10, X9 35 AND $7, X11, X19 36 BNE X9, X19, loop4_check 37 BEQZ X9, loop32_check 38 39 // Check one byte at a time until we reach 8 byte alignment. 40 SUB X9, X12, X12 41 align: 42 ADD $-1, X9 43 MOVBU 0(X10), X19 44 MOVBU 0(X11), X20 45 BNE X19, X20, not_eq 46 ADD $1, X10 47 ADD $1, X11 48 BNEZ X9, align 49 50 loop32_check: 51 MOV $32, X9 52 BLT X12, X9, loop16_check 53 loop32: 54 MOV 0(X10), X19 55 MOV 0(X11), X20 56 MOV 8(X10), X21 57 MOV 8(X11), X22 58 BNE X19, X20, not_eq 59 BNE X21, X22, not_eq 60 MOV 16(X10), X14 61 MOV 16(X11), X15 62 MOV 24(X10), X16 63 MOV 24(X11), X17 64 BNE X14, X15, not_eq 65 BNE X16, X17, not_eq 66 ADD $32, X10 67 ADD $32, X11 68 ADD $-32, X12 69 BGE X12, X9, loop32 70 BEQZ X12, eq 71 72 loop16_check: 73 MOV $16, X23 74 BLT X12, X23, loop4_check 75 loop16: 76 MOV 0(X10), X19 77 MOV 0(X11), X20 78 MOV 8(X10), X21 79 MOV 8(X11), X22 80 BNE X19, X20, not_eq 81 BNE X21, X22, not_eq 82 ADD $16, X10 83 ADD $16, X11 84 ADD $-16, X12 85 BGE X12, X23, loop16 86 BEQZ X12, eq 87 88 loop4_check: 89 MOV $4, X23 90 BLT X12, X23, loop1 91 loop4: 92 MOVBU 0(X10), X19 93 MOVBU 0(X11), X20 94 MOVBU 1(X10), X21 95 MOVBU 1(X11), X22 96 BNE X19, X20, not_eq 97 BNE X21, X22, not_eq 98 MOVBU 2(X10), X14 99 MOVBU 2(X11), X15 100 MOVBU 3(X10), X16 101 MOVBU 3(X11), X17 102 BNE X14, X15, not_eq 103 BNE X16, X17, not_eq 104 ADD $4, X10 105 ADD $4, X11 106 ADD $-4, X12 107 BGE X12, X23, loop4 108 109 loop1: 110 BEQZ X12, eq 111 MOVBU 0(X10), X19 112 MOVBU 0(X11), X20 113 BNE X19, X20, not_eq 114 ADD $1, X10 115 ADD $1, X11 116 ADD $-1, X12 117 JMP loop1 118 119 not_eq: 120 MOVB ZERO, X10 121 RET 122 eq: 123 MOV $1, X10 124 RET