github.com/primecitizens/pcz/std@v0.2.1/core/mem/equal_arm.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 && arm
     9  
    10  #include "textflag.h"
    11  
    12  // Equal(a, b unsafe.Pointer, size uintptr) bool
    13  TEXT ·Equal(SB),NOSPLIT|NOFRAME,$0-13
    14  	MOVW a+0(FP), R0
    15  	MOVW b+4(FP), R2
    16  	CMP R0, R2
    17  	B.EQ eq
    18  	MOVW size+8(FP), R1
    19  	CMP $0, R1
    20  	B.EQ eq // short path to handle 0-byte case
    21  	MOVW $ret+12(FP), R7
    22  	B memeqbody<>(SB)
    23  eq:
    24  	MOVW $1, R0
    25  	MOVB R0, ret+12(FP)
    26  	RET
    27  
    28  // memequal_varlen(a, b unsafe.Pointer) bool
    29  TEXT runtime·memequal_varlen(SB),NOSPLIT|NOFRAME,$0-9
    30  	MOVW a+0(FP), R0
    31  	MOVW b+4(FP), R2
    32  	CMP R0, R2
    33  	B.EQ eq
    34  	MOVW 4(R7), R1 // compiler stores size at offset 4 in the closure
    35  	CMP $0, R1
    36  	B.EQ eq // short path to handle 0-byte case
    37  	MOVW $ret+8(FP), R7
    38  	B memeqbody<>(SB)
    39  eq:
    40  	MOVW $1, R0
    41  	MOVB R0, ret+8(FP)
    42  	RET
    43  
    44  // Input:
    45  // R0: data of a
    46  // R1: length
    47  // R2: data of b
    48  // R7: points to return value
    49  //
    50  // On exit:
    51  // R4, R5 and R6 are clobbered
    52  TEXT memeqbody<>(SB),NOSPLIT|NOFRAME,$0-0
    53  	CMP $1, R1
    54  	B.EQ one // 1-byte special case for better performance
    55  
    56  	CMP $4, R1
    57  	ADD R0, R1 // R1 is the end of the range to compare
    58  	B.LT byte_loop // length < 4
    59  	AND $3, R0, R6
    60  	CMP $0, R6
    61  	B.NE byte_loop // unaligned a, use byte-wise compare (TODO: try to align a)
    62  	AND $3, R2, R6
    63  	CMP $0, R6
    64  	B.NE byte_loop // unaligned b, use byte-wise compare
    65  	AND $0xfffffffc, R1, R6
    66  	// length >= 4
    67  chunk4_loop:
    68  	MOVW.P 4(R0), R4
    69  	MOVW.P 4(R2), R5
    70  	CMP R4, R5
    71  	B.NE notequal
    72  	CMP R0, R6
    73  	B.NE chunk4_loop
    74  	CMP R0, R1
    75  	B.EQ equal // reached the end
    76  byte_loop:
    77  	MOVBU.P 1(R0), R4
    78  	MOVBU.P 1(R2), R5
    79  	CMP R4, R5
    80  	B.NE notequal
    81  	CMP R0, R1
    82  	B.NE byte_loop
    83  equal:
    84  	MOVW $1, R0
    85  	MOVB R0, (R7)
    86  	RET
    87  one:
    88  	MOVBU (R0), R4
    89  	MOVBU (R2), R5
    90  	CMP R4, R5
    91  	B.EQ equal
    92  notequal:
    93  	MOVW $0, R0
    94  	MOVB R0, (R7)
    95  	RET