github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/internal/bytealg/compare_arm.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|NOFRAME,$0-28 9 MOVW a_base+0(FP), R2 10 MOVW a_len+4(FP), R0 11 MOVW b_base+12(FP), R3 12 MOVW b_len+16(FP), R1 13 ADD $28, R13, R7 14 B cmpbody<>(SB) 15 16 TEXT bytes·Compare(SB),NOSPLIT|NOFRAME,$0-28 17 FUNCDATA $0, ·Compare·args_stackmap(SB) 18 MOVW a_base+0(FP), R2 19 MOVW a_len+4(FP), R0 20 MOVW b_base+12(FP), R3 21 MOVW b_len+16(FP), R1 22 ADD $28, R13, R7 23 B cmpbody<>(SB) 24 25 TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-20 26 MOVW a_base+0(FP), R2 27 MOVW a_len+4(FP), R0 28 MOVW b_base+8(FP), R3 29 MOVW b_len+12(FP), R1 30 ADD $20, R13, R7 31 B cmpbody<>(SB) 32 33 // On entry: 34 // R0 is the length of a 35 // R1 is the length of b 36 // R2 points to the start of a 37 // R3 points to the start of b 38 // R7 points to return value (-1/0/1 will be written here) 39 // 40 // On exit: 41 // R4, R5, and R6 are clobbered 42 TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0 43 CMP R2, R3 44 BEQ samebytes 45 CMP R0, R1 46 MOVW R0, R6 47 MOVW.LT R1, R6 // R6 is min(R0, R1) 48 49 ADD R2, R6 // R2 is current byte in a, R6 is last byte in a to compare 50 loop: 51 CMP R2, R6 52 BEQ samebytes // all compared bytes were the same; compare lengths 53 MOVBU.P 1(R2), R4 54 MOVBU.P 1(R3), R5 55 CMP R4, R5 56 BEQ loop 57 // bytes differed 58 MOVW.LT $1, R0 59 MOVW.GT $-1, R0 60 MOVW R0, (R7) 61 RET 62 samebytes: 63 CMP R0, R1 64 MOVW.LT $1, R0 65 MOVW.GT $-1, R0 66 MOVW.EQ $0, R0 67 MOVW R0, (R7) 68 RET