From 4641d78a59f37b2a976d98b14ccb1ba5a2d379b0 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Seo Date: Fri, 25 Aug 2017 15:00:00 -0300 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Lynn Boger --- src/runtime/asm_ppc64x.s | 41 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index 0251689b37..68f6dd865e 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -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 -- 2.50.0