github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/not-internal/bytealg/compare_mipsx.s (about) 1 // Copyright 2018 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 // +build mips mipsle 6 7 #include "go_asm.h" 8 #include "textflag.h" 9 10 TEXT ·Compare(SB),NOSPLIT,$0-28 11 MOVW a_base+0(FP), R3 12 MOVW b_base+12(FP), R4 13 MOVW a_len+4(FP), R1 14 MOVW b_len+16(FP), R2 15 BEQ R3, R4, samebytes 16 SGTU R1, R2, R7 17 MOVW R1, R8 18 CMOVN R7, R2, R8 // R8 is min(R1, R2) 19 20 ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 21 loop: 22 BEQ R3, R8, samebytes 23 24 MOVBU (R3), R6 25 ADDU $1, R3 26 MOVBU (R4), R7 27 ADDU $1, R4 28 BEQ R6, R7 , loop 29 30 SGTU R6, R7, R8 31 MOVW $-1, R6 32 CMOVZ R8, R6, R8 33 JMP cmp_ret 34 samebytes: 35 SGTU R1, R2, R6 36 SGTU R2, R1, R7 37 SUBU R7, R6, R8 38 cmp_ret: 39 MOVW R8, ret+24(FP) 40 RET 41 42 TEXT runtime·cmpstring(SB),NOSPLIT,$0-20 43 MOVW a_base+0(FP), R3 44 MOVW a_len+4(FP), R1 45 MOVW b_base+8(FP), R4 46 MOVW b_len+12(FP), R2 47 BEQ R3, R4, samebytes 48 SGTU R1, R2, R7 49 MOVW R1, R8 50 CMOVN R7, R2, R8 // R8 is min(R1, R2) 51 52 ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 53 loop: 54 BEQ R3, R8, samebytes // all compared bytes were the same; compare lengths 55 56 MOVBU (R3), R6 57 ADDU $1, R3 58 MOVBU (R4), R7 59 ADDU $1, R4 60 BEQ R6, R7 , loop 61 // bytes differed 62 SGTU R6, R7, R8 63 MOVW $-1, R6 64 CMOVZ R8, R6, R8 65 JMP cmp_ret 66 samebytes: 67 SGTU R1, R2, R6 68 SGTU R2, R1, R7 69 SUBU R7, R6, R8 70 cmp_ret: 71 MOVW R8, ret+16(FP) 72 RET