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