github.com/primecitizens/pcz/std@v0.2.1/core/mem/equal_mips64x.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2018 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  #define REGCTXT R22
    13  
    14  // Equal(a, b unsafe.Pointer, size uintptr) bool
    15  TEXT ·Equal(SB),NOSPLIT|NOFRAME,$0-25
    16  	MOVV a+0(FP), R1
    17  	MOVV b+8(FP), R2
    18  	BEQ R1, R2, eq
    19  	MOVV size+16(FP), R3
    20  	ADDV R1, R3, R4
    21  
    22  	// chunk size is 16
    23  	SGTU $16, R3, R8
    24  	BEQ R0, R8, chunk_entry
    25  
    26  byte_loop:
    27  	BNE R1, R4, byte_test
    28  	MOVV $1, R1
    29  	MOVB R1, ret+24(FP)
    30  	RET
    31  byte_test:
    32  	MOVBU (R1), R6
    33  	ADDV $1, R1
    34  	MOVBU (R2), R7
    35  	ADDV $1, R2
    36  	BEQ R6, R7, byte_loop
    37  	JMP not_eq
    38  
    39  chunk_entry:
    40  	// make sure both a and b are aligned
    41  	OR R1, R2, R9
    42  	AND $0x7, R9
    43  	BNE R0, R9, byte_loop
    44  	JMP chunk_loop_1
    45  
    46  chunk_loop:
    47  	// chunk size is 16
    48  	SGTU $16, R3, R8
    49  	BNE R0, R8, chunk_tail_8
    50  chunk_loop_1:
    51  	MOVV (R1), R6
    52  	MOVV (R2), R7
    53  	BNE R6, R7, not_eq
    54  	MOVV 8(R1), R12
    55  	MOVV 8(R2), R13
    56  	ADDV $16, R1
    57  	ADDV $16, R2
    58  	SUBV $16, R3
    59  	BEQ R12, R13, chunk_loop
    60  	JMP not_eq
    61  
    62  chunk_tail_8:
    63  	AND $8, R3, R14
    64  	BEQ R0, R14, chunk_tail_4
    65  	MOVV (R1), R6
    66  	MOVV (R2), R7
    67  	BNE R6, R7, not_eq
    68  	ADDV $8, R1
    69  	ADDV $8, R2
    70  
    71  chunk_tail_4:
    72  	AND $4, R3, R14
    73  	BEQ R0, R14, chunk_tail_2
    74  	MOVWU (R1), R6
    75  	MOVWU (R2), R7
    76  	BNE R6, R7, not_eq
    77  	ADDV $4, R1
    78  	ADDV $4, R2
    79  
    80  chunk_tail_2:
    81  	AND $2, R3, R14
    82  	BEQ R0, R14, chunk_tail_1
    83  	MOVHU (R1), R6
    84  	MOVHU (R2), R7
    85  	BNE R6, R7, not_eq
    86  	ADDV $2, R1
    87  	ADDV $2, R2
    88  
    89  chunk_tail_1:
    90  	AND $1, R3, R14
    91  	BEQ R0, R14, eq
    92  	MOVBU (R1), R6
    93  	MOVBU (R2), R7
    94  	BEQ R6, R7, eq
    95  
    96  not_eq:
    97  	MOVB R0, ret+24(FP)
    98  	RET
    99  eq:
   100  	MOVV $1, R1
   101  	MOVB R1, ret+24(FP)
   102  	RET
   103  
   104  // memequal_varlen(a, b unsafe.Pointer) bool
   105  TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
   106  	MOVV a+0(FP), R1
   107  	MOVV b+8(FP), R2
   108  	BEQ R1, R2, eq
   109  	MOVV 8(REGCTXT), R3    // compiler stores size at offset 8 in the closure
   110  	MOVV R1, 8(R29)
   111  	MOVV R2, 16(R29)
   112  	MOVV R3, 24(R29)
   113  	JAL ·Equal(SB)
   114  	MOVBU 32(R29), R1
   115  	MOVB R1, ret+16(FP)
   116  	RET
   117  eq:
   118  	MOVV $1, R1
   119  	MOVB R1, ret+16(FP)
   120  	RET