github.com/primecitizens/pcz/std@v0.2.1/core/cmp/bs_mipsx.s (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2018 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 //go:build pcz && (mips || mipsle) 9 10 #include "textflag.h" 11 12 TEXT ·Bytes(SB),NOSPLIT,$0-28 13 MOVW a_base+0(FP), R3 14 MOVW b_base+12(FP), R4 15 MOVW a_len+4(FP), R1 16 MOVW b_len+16(FP), R2 17 BEQ R3, R4, samebytes 18 SGTU R1, R2, R7 19 MOVW R1, R8 20 CMOVN R7, R2, R8 // R8 is min(R1, R2) 21 22 ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 23 loop: 24 BEQ R3, R8, samebytes 25 26 MOVBU (R3), R6 27 ADDU $1, R3 28 MOVBU (R4), R7 29 ADDU $1, R4 30 BEQ R6, R7 , loop 31 32 SGTU R6, R7, R8 33 MOVW $-1, R6 34 CMOVZ R8, R6, R8 35 JMP cmp_ret 36 samebytes: 37 SGTU R1, R2, R6 38 SGTU R2, R1, R7 39 SUBU R7, R6, R8 40 cmp_ret: 41 MOVW R8, ret+24(FP) 42 RET 43 44 TEXT ·String(SB),NOSPLIT,$0-20 45 MOVW a_base+0(FP), R3 46 MOVW a_len+4(FP), R1 47 MOVW b_base+8(FP), R4 48 MOVW b_len+12(FP), R2 49 BEQ R3, R4, samebytes 50 SGTU R1, R2, R7 51 MOVW R1, R8 52 CMOVN R7, R2, R8 // R8 is min(R1, R2) 53 54 ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 55 loop: 56 BEQ R3, R8, samebytes // all compared bytes were the same; compare lengths 57 58 MOVBU (R3), R6 59 ADDU $1, R3 60 MOVBU (R4), R7 61 ADDU $1, R4 62 BEQ R6, R7 , loop 63 // bytes differed 64 SGTU R6, R7, R8 65 MOVW $-1, R6 66 CMOVZ R8, R6, R8 67 JMP cmp_ret 68 samebytes: 69 SGTU R1, R2, R6 70 SGTU R2, R1, R7 71 SUBU R7, R6, R8 72 cmp_ret: 73 MOVW R8, ret+16(FP) 74 RET