Text file src/internal/bytealg/compare_mips64x.s

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

View as plain text