github.com/primecitizens/pcz/std@v0.2.1/core/mem/equal_wasm.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 && wasm
     9  
    10  #include "textflag.h"
    11  
    12  // Equal(p, q unsafe.Pointer, size uintptr) bool
    13  TEXT ·Equal(SB), NOSPLIT, $0-25
    14  	Get SP
    15  	I64Load a+0(FP)
    16  	I64Load b+8(FP)
    17  	I64Load size+16(FP)
    18  	Call memeqbody<>(SB)
    19  	I64Store8 ret+24(FP)
    20  	RET
    21  
    22  // memequal_varlen(a, b unsafe.Pointer) bool
    23  TEXT runtime·memequal_varlen(SB), NOSPLIT, $0-17
    24  	Get SP
    25  	I64Load a+0(FP)
    26  	I64Load b+8(FP)
    27  	I64Load 8(CTXT) // compiler stores size at offset 8 in the closure
    28  	Call memeqbody<>(SB)
    29  	I64Store8 ret+16(FP)
    30  	RET
    31  
    32  // params: a, b, len
    33  // ret: 0/1
    34  TEXT memeqbody<>(SB), NOSPLIT, $0-0
    35  	Get R0
    36  	Get R1
    37  	I64Eq
    38  	If
    39  		I64Const $1
    40  		Return
    41  	End
    42  
    43  loop:
    44  	Loop
    45  		Get R2
    46  		I64Eqz
    47  		If
    48  			I64Const $1
    49  			Return
    50  		End
    51  
    52  		Get R0
    53  		I32WrapI64
    54  		I64Load8U $0
    55  		Get R1
    56  		I32WrapI64
    57  		I64Load8U $0
    58  		I64Ne
    59  		If
    60  			I64Const $0
    61  			Return
    62  		End
    63  
    64  		Get R0
    65  		I64Const $1
    66  		I64Add
    67  		Set R0
    68  
    69  		Get R1
    70  		I64Const $1
    71  		I64Add
    72  		Set R1
    73  
    74  		Get R2
    75  		I64Const $1
    76  		I64Sub
    77  		Set R2
    78  
    79  		Br loop
    80  	End
    81  	UNDEF