Black Lives Matter. Support the Equal Justice Initiative.

Text file src/internal/bytealg/compare_mipsx.s

Documentation: internal/bytealg

     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  //go:build mips || mipsle
     6  // +build mips mipsle
     7  
     8  #include "go_asm.h"
     9  #include "textflag.h"
    10  
    11  TEXT ·Compare(SB),NOSPLIT,$0-28
    12  	MOVW	a_base+0(FP), R3
    13  	MOVW	b_base+12(FP), R4
    14  	MOVW	a_len+4(FP), R1
    15  	MOVW	b_len+16(FP), R2
    16  	BEQ	R3, R4, samebytes
    17  	SGTU	R1, R2, R7
    18  	MOVW	R1, R8
    19  	CMOVN	R7, R2, R8	// R8 is min(R1, R2)
    20  
    21  	ADDU	R3, R8	// R3 is current byte in a, R8 is last byte in a to compare
    22  loop:
    23  	BEQ	R3, R8, samebytes
    24  
    25  	MOVBU	(R3), R6
    26  	ADDU	$1, R3
    27  	MOVBU	(R4), R7
    28  	ADDU	$1, R4
    29  	BEQ	R6, R7 , loop
    30  
    31  	SGTU	R6, R7, R8
    32  	MOVW	$-1, R6
    33  	CMOVZ	R8, R6, R8
    34  	JMP	cmp_ret
    35  samebytes:
    36  	SGTU	R1, R2, R6
    37  	SGTU	R2, R1, R7
    38  	SUBU	R7, R6, R8
    39  cmp_ret:
    40  	MOVW	R8, ret+24(FP)
    41  	RET
    42  
    43  TEXT runtime·cmpstring(SB),NOSPLIT,$0-20
    44  	MOVW	a_base+0(FP), R3
    45  	MOVW	a_len+4(FP), R1
    46  	MOVW	b_base+8(FP), R4
    47  	MOVW	b_len+12(FP), R2
    48  	BEQ	R3, R4, samebytes
    49  	SGTU	R1, R2, R7
    50  	MOVW	R1, R8
    51  	CMOVN	R7, R2, R8	// R8 is min(R1, R2)
    52  
    53  	ADDU	R3, R8	// R3 is current byte in a, R8 is last byte in a to compare
    54  loop:
    55  	BEQ	R3, R8, samebytes	// all compared bytes were the same; compare lengths
    56  
    57  	MOVBU	(R3), R6
    58  	ADDU	$1, R3
    59  	MOVBU	(R4), R7
    60  	ADDU	$1, R4
    61  	BEQ	R6, R7 , loop
    62  	// bytes differed
    63  	SGTU	R6, R7, R8
    64  	MOVW	$-1, R6
    65  	CMOVZ	R8, R6, R8
    66  	JMP	cmp_ret
    67  samebytes:
    68  	SGTU	R1, R2, R6
    69  	SGTU	R2, R1, R7
    70  	SUBU	R7, R6, R8
    71  cmp_ret:
    72  	MOVW	R8, ret+16(FP)
    73  	RET
    74  

View as plain text