github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/bytealg/compare_mips64x.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 //go:build mips64 || mips64le 6 // +build mips64 mips64le 7 8 #include "go_asm.h" 9 #include "textflag.h" 10 11 TEXT ·Compare(SB),NOSPLIT,$0-56 12 MOVV a_base+0(FP), R3 13 MOVV b_base+24(FP), R4 14 MOVV a_len+8(FP), R1 15 MOVV b_len+32(FP), R2 16 MOVV $ret+48(FP), R9 17 JMP cmpbody<>(SB) 18 19 TEXT runtime·cmpstring(SB),NOSPLIT,$0-40 20 MOVV a_base+0(FP), R3 21 MOVV b_base+16(FP), R4 22 MOVV a_len+8(FP), R1 23 MOVV b_len+24(FP), R2 24 MOVV $ret+32(FP), R9 25 JMP cmpbody<>(SB) 26 27 // On entry: 28 // R1 length of a 29 // R2 length of b 30 // R3 points to the start of a 31 // R4 points to the start of b 32 // R9 points to the return value (-1/0/1) 33 TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0 34 BEQ R3, R4, samebytes // same start of a and b 35 36 SGTU R1, R2, R7 37 BNE R0, R7, r2_lt_r1 38 MOVV R1, R10 39 JMP entry 40 r2_lt_r1: 41 MOVV R2, R10 // R10 is min(R1, R2) 42 entry: 43 ADDV R3, R10, R8 // R3 start of a, R8 end of a 44 BEQ R3, R8, samebytes // length is 0 45 46 SRLV $4, R10 // R10 is number of chunks 47 BEQ R0, R10, byte_loop 48 49 // make sure both a and b are aligned. 50 OR R3, R4, R11 51 AND $7, R11 52 BNE R0, R11, byte_loop 53 54 chunk16_loop: 55 BEQ R0, R10, byte_loop 56 MOVV (R3), R6 57 MOVV (R4), R7 58 BNE R6, R7, byte_loop 59 MOVV 8(R3), R13 60 MOVV 8(R4), R14 61 ADDV $16, R3 62 ADDV $16, R4 63 SUBVU $1, R10 64 BEQ R13, R14, chunk16_loop 65 SUBV $8, R3 66 SUBV $8, R4 67 68 byte_loop: 69 BEQ R3, R8, samebytes 70 MOVBU (R3), R6 71 ADDVU $1, R3 72 MOVBU (R4), R7 73 ADDVU $1, R4 74 BEQ R6, R7, byte_loop 75 76 byte_cmp: 77 SGTU R6, R7, R8 // R8 = 1 if (R6 > R7) 78 BNE R0, R8, ret 79 MOVV $-1, R8 80 JMP ret 81 82 samebytes: 83 SGTU R1, R2, R6 84 SGTU R2, R1, R7 85 SUBV R7, R6, R8 86 87 ret: 88 MOVV R8, (R9) 89 RET