github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/bytealg/compare_arm.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  #include "go_asm.h"
     6  #include "textflag.h"
     7  
     8  TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-28
     9  	MOVW	a_base+0(FP), R2
    10  	MOVW	a_len+4(FP), R0
    11  	MOVW	b_base+12(FP), R3
    12  	MOVW	b_len+16(FP), R1
    13  	ADD	$28, R13, R7
    14  	B	cmpbody<>(SB)
    15  
    16  TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-20
    17  	MOVW	a_base+0(FP), R2
    18  	MOVW	a_len+4(FP), R0
    19  	MOVW	b_base+8(FP), R3
    20  	MOVW	b_len+12(FP), R1
    21  	ADD	$20, R13, R7
    22  	B	cmpbody<>(SB)
    23  
    24  // On entry:
    25  // R0 is the length of a
    26  // R1 is the length of b
    27  // R2 points to the start of a
    28  // R3 points to the start of b
    29  // R7 points to return value (-1/0/1 will be written here)
    30  //
    31  // On exit:
    32  // R4, R5, and R6 are clobbered
    33  TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0
    34  	CMP	R2, R3
    35  	BEQ	samebytes
    36  	CMP 	R0, R1
    37  	MOVW 	R0, R6
    38  	MOVW.LT	R1, R6	// R6 is min(R0, R1)
    39  
    40  	ADD	R2, R6	// R2 is current byte in a, R6 is last byte in a to compare
    41  loop:
    42  	CMP	R2, R6
    43  	BEQ	samebytes // all compared bytes were the same; compare lengths
    44  	MOVBU.P	1(R2), R4
    45  	MOVBU.P	1(R3), R5
    46  	CMP	R4, R5
    47  	BEQ	loop
    48  	// bytes differed
    49  	MOVW.LT	$1, R0
    50  	MOVW.GT	$-1, R0
    51  	MOVW	R0, (R7)
    52  	RET
    53  samebytes:
    54  	CMP	R0, R1
    55  	MOVW.LT	$1, R0
    56  	MOVW.GT	$-1, R0
    57  	MOVW.EQ	$0, R0
    58  	MOVW	R0, (R7)
    59  	RET