github.com/FISCO-BCOS/crypto@v0.0.0-20200202032121-bd8ab0b5d4f1/internal/bytealg/compare_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  TEXT ·Compare(SB), NOSPLIT, $0-56
     9  	Get SP
    10  	I64Load a_base+0(FP)
    11  	I64Load a_len+8(FP)
    12  	I64Load b_base+24(FP)
    13  	I64Load b_len+32(FP)
    14  	Call cmpbody<>(SB)
    15  	I64Store ret+48(FP)
    16  	RET
    17  
    18  TEXT runtime·cmpstring(SB), NOSPLIT, $0-40
    19  	Get SP
    20  	I64Load a_base+0(FP)
    21  	I64Load a_len+8(FP)
    22  	I64Load b_base+16(FP)
    23  	I64Load b_len+24(FP)
    24  	Call cmpbody<>(SB)
    25  	I64Store ret+32(FP)
    26  	RET
    27  
    28  // params: a, alen, b, blen
    29  // ret: -1/0/1
    30  TEXT cmpbody<>(SB), NOSPLIT, $0-0
    31  	// len = min(alen, blen)
    32  	Get R1
    33  	Get R3
    34  	Get R1
    35  	Get R3
    36  	I64LtU
    37  	Select
    38  	Set R4
    39  
    40  	Get R0
    41  	I32WrapI64
    42  	Get R2
    43  	I32WrapI64
    44  	Get R4
    45  	I32WrapI64
    46  	Call memcmp<>(SB)
    47  	I64ExtendI32S
    48  	Set R5
    49  
    50  	Get R5
    51  	I64Eqz
    52  	If
    53  		// check length
    54  		Get R1
    55  		Get R3
    56  		I64Sub
    57  		Set R5
    58  	End
    59  
    60  	I64Const $0
    61  	I64Const $-1
    62  	I64Const $1
    63  	Get R5
    64  	I64Const $0
    65  	I64LtS
    66  	Select
    67  	Get R5
    68  	I64Eqz
    69  	Select
    70  	Return
    71  
    72  // compiled with emscripten
    73  // params: a, b, len
    74  // ret: <0/0/>0
    75  TEXT memcmp<>(SB), NOSPLIT, $0-0
    76  	Get R2
    77  	If $1
    78  	Loop
    79  	Get R0
    80  	I32Load8S $0
    81  	Tee R3
    82  	Get R1
    83  	I32Load8S $0
    84  	Tee R4
    85  	I32Eq
    86  	If
    87  	Get R0
    88  	I32Const $1
    89  	I32Add
    90  	Set R0
    91  	Get R1
    92  	I32Const $1
    93  	I32Add
    94  	Set R1
    95  	I32Const $0
    96  	Get R2
    97  	I32Const $-1
    98  	I32Add
    99  	Tee R2
   100  	I32Eqz
   101  	BrIf $3
   102  	Drop
   103  	Br $1
   104  	End
   105  	End
   106  	Get R3
   107  	I32Const $255
   108  	I32And
   109  	Get R4
   110  	I32Const $255
   111  	I32And
   112  	I32Sub
   113  	Else
   114  	I32Const $0
   115  	End
   116  	Return