github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/bytealg/indexbyte_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 ·IndexByte(SB), NOSPLIT, $0-40
     9  	I64Load b_base+0(FP)
    10  	I32WrapI64
    11  	I32Load8U c+24(FP)
    12  	I64Load b_len+8(FP)
    13  	I32WrapI64
    14  	Call memchr<>(SB)
    15  	I64ExtendSI32
    16  	Set R0
    17  
    18  	Get SP
    19  	I64Const $-1
    20  	Get R0
    21  	I64Load b_base+0(FP)
    22  	I64Sub
    23  	Get R0
    24  	I64Eqz $0
    25  	Select
    26  	I64Store ret+32(FP)
    27  
    28  	RET
    29  
    30  TEXT ·IndexByteString(SB), NOSPLIT, $0-32
    31  	Get SP
    32  	I64Load s_base+0(FP)
    33  	I32WrapI64
    34  	I32Load8U c+16(FP)
    35  	I64Load s_len+8(FP)
    36  	I32WrapI64
    37  	Call memchr<>(SB)
    38  	I64ExtendSI32
    39  	Set R0
    40  
    41  	I64Const $-1
    42  	Get R0
    43  	I64Load s_base+0(FP)
    44  	I64Sub
    45  	Get R0
    46  	I64Eqz $0
    47  	Select
    48  	I64Store ret+24(FP)
    49  
    50  	RET
    51  
    52  // compiled with emscripten
    53  // params: s, c, len
    54  // ret: index
    55  TEXT memchr<>(SB), NOSPLIT, $0
    56  	Get R1
    57  	I32Const $255
    58  	I32And
    59  	Set R4
    60  	Block
    61  	Block
    62  	Get R2
    63  	I32Const $0
    64  	I32Ne
    65  	Tee R3
    66  	Get R0
    67  	I32Const $3
    68  	I32And
    69  	I32Const $0
    70  	I32Ne
    71  	I32And
    72  	If
    73  	Get R1
    74  	I32Const $255
    75  	I32And
    76  	Set R5
    77  	Loop
    78  	Get R0
    79  	I32Load8U $0
    80  	Get R5
    81  	I32Eq
    82  	BrIf $2
    83  	Get R2
    84  	I32Const $-1
    85  	I32Add
    86  	Tee R2
    87  	I32Const $0
    88  	I32Ne
    89  	Tee R3
    90  	Get R0
    91  	I32Const $1
    92  	I32Add
    93  	Tee R0
    94  	I32Const $3
    95  	I32And
    96  	I32Const $0
    97  	I32Ne
    98  	I32And
    99  	BrIf $0
   100  	End
   101  	End
   102  	Get R3
   103  	BrIf $0
   104  	I32Const $0
   105  	Set R1
   106  	Br $1
   107  	End
   108  	Get R0
   109  	I32Load8U $0
   110  	Get R1
   111  	I32Const $255
   112  	I32And
   113  	Tee R3
   114  	I32Eq
   115  	If
   116  	Get R2
   117  	Set R1
   118  	Else
   119  	Get R4
   120  	I32Const $16843009
   121  	I32Mul
   122  	Set R4
   123  	Block
   124  	Block
   125  	Get R2
   126  	I32Const $3
   127  	I32GtU
   128  	If
   129  	Get R2
   130  	Set R1
   131  	Loop
   132  	Get R0
   133  	I32Load $0
   134  	Get R4
   135  	I32Xor
   136  	Tee R2
   137  	I32Const $-2139062144
   138  	I32And
   139  	I32Const $-2139062144
   140  	I32Xor
   141  	Get R2
   142  	I32Const $-16843009
   143  	I32Add
   144  	I32And
   145  	I32Eqz
   146  	If
   147  	Get R0
   148  	I32Const $4
   149  	I32Add
   150  	Set R0
   151  	Get R1
   152  	I32Const $-4
   153  	I32Add
   154  	Tee R1
   155  	I32Const $3
   156  	I32GtU
   157  	BrIf $1
   158  	Br $3
   159  	End
   160  	End
   161  	Else
   162  	Get R2
   163  	Set R1
   164  	Br $1
   165  	End
   166  	Br $1
   167  	End
   168  	Get R1
   169  	I32Eqz
   170  	If
   171  	I32Const $0
   172  	Set R1
   173  	Br $3
   174  	End
   175  	End
   176  	Loop
   177  	Get R0
   178  	I32Load8U $0
   179  	Get R3
   180  	I32Eq
   181  	BrIf $2
   182  	Get R0
   183  	I32Const $1
   184  	I32Add
   185  	Set R0
   186  	Get R1
   187  	I32Const $-1
   188  	I32Add
   189  	Tee R1
   190  	BrIf $0
   191  	I32Const $0
   192  	Set R1
   193  	End
   194  	End
   195  	End
   196  	Get R0
   197  	I32Const $0
   198  	Get R1
   199  	Select
   200  	Return