github.com/SandwichDev/go-internals@v0.0.0-20210605002614-12311ac6b2c5/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 Tee R5 49 50 I64Eqz 51 If 52 // check length 53 Get R1 54 Get R3 55 I64Sub 56 Set R5 57 End 58 59 I64Const $0 60 I64Const $-1 61 I64Const $1 62 Get R5 63 I64Const $0 64 I64LtS 65 Select 66 Get R5 67 I64Eqz 68 Select 69 Return 70 71 // compiled with emscripten 72 // params: a, b, len 73 // ret: <0/0/>0 74 TEXT memcmp<>(SB), NOSPLIT, $0-0 75 Get R2 76 If $1 77 Loop 78 Get R0 79 I32Load8S $0 80 Tee R3 81 Get R1 82 I32Load8S $0 83 Tee R4 84 I32Eq 85 If 86 Get R0 87 I32Const $1 88 I32Add 89 Set R0 90 Get R1 91 I32Const $1 92 I32Add 93 Set R1 94 I32Const $0 95 Get R2 96 I32Const $-1 97 I32Add 98 Tee R2 99 I32Eqz 100 BrIf $3 101 Drop 102 Br $1 103 End 104 End 105 Get R3 106 I32Const $255 107 I32And 108 Get R4 109 I32Const $255 110 I32And 111 I32Sub 112 Else 113 I32Const $0 114 End 115 Return