github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/bytealg/compare_loong64.s (about)

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