1
0
mirror of https://github.com/golang/go synced 2024-11-19 12:54:45 -07:00

runtime: fix regression in BenchmarkCompareBytes* for ppc64x

Between go1.7 and go1.8, a performance regression was introduced in some of the
BenchmarkCompareBytes benchmarks.

Go1.7 vs Go1.8:
BenchmarkCompareBytesToNil-8               7.44          8.44          +13.44%
BenchmarkCompareBytesIdentical-8           6.96          11.5          +65.23%
BenchmarkCompareBytesBigIdentical-8        6.65          47112         +708351.13%

This change fixes the problem by optimizing the case where the byte slices being
compared are equal:

Go1.9 vs current:
BenchmarkCompareBytesToNil-8               7.35          7.00          -4.76%
BenchmarkCompareBytesIdentical-8           11.4          6.81          -40.26%
BenchmarkCompareBytesBigIdentical-8        48396         9.26          -99.98%

runtime.cmpstring can benefit from the same approach and is also changed.

Change-Id: I3cb25f59d8b940a83a2cf687eea764cfeff90688
Reviewed-on: https://go-review.googlesource.com/59650
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
This commit is contained in:
Carlos Eduardo Seo 2017-08-25 15:00:00 -03:00 committed by Lynn Boger
parent 03876af91c
commit 4641d78a59

View File

@ -1258,28 +1258,65 @@ small_string:
TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40
MOVD s1_base+0(FP), R5
MOVD s1_len+8(FP), R3
MOVD s2_base+16(FP), R6
MOVD s1_len+8(FP), R3
CMP R5,R6,CR7
MOVD s2_len+24(FP), R4
MOVD $ret+32(FP), R7
CMP R3,R4,CR6
BEQ CR7,equal
notequal:
#ifdef GOARCH_ppc64le
BR cmpbodyLE<>(SB)
#else
BR cmpbodyBE<>(SB)
#endif
equal:
BEQ CR6,done
MOVD $1, R8
BGT CR6,greater
NEG R8
greater:
MOVD R8, (R7)
RET
done:
MOVD $0, (R7)
RET
TEXT bytes·Compare(SB),NOSPLIT|NOFRAME,$0-56
MOVD s1+0(FP), R5
MOVD s1+8(FP), R3
MOVD s2+24(FP), R6
MOVD s1+8(FP), R3
CMP R5,R6,CR7
MOVD s2+32(FP), R4
MOVD $ret+48(FP), R7
CMP R3,R4,CR6
BEQ CR7,equal
#ifdef GOARCH_ppc64le
BR cmpbodyLE<>(SB)
#else
BR cmpbodyBE<>(SB)
#endif
equal:
BEQ CR6,done
MOVD $1, R8
BGT CR6,greater
NEG R8
greater:
MOVD R8, (R7)
RET
done:
MOVD $0, (R7)
RET
TEXT runtime·return0(SB), NOSPLIT, $0
MOVW $0, R3
RET