github.com/primecitizens/pcz/std@v0.2.1/core/cmp/bs_mips64x.s (about)

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