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