]> Cypherpunks repositories - gostls13.git/commitdiff
internal/bytealg: add assembly implementation of Count/CountString for mips64x
authorJulian Zhu <jz531210@gmail.com>
Thu, 20 Feb 2025 13:55:28 +0000 (21:55 +0800)
committerGopher Robot <gobot@golang.org>
Sat, 22 Feb 2025 02:57:24 +0000 (18:57 -0800)
Add a simple assembly implementation of Count/CountString for mips64x.

name            old sec/op    new sec/op     vs base
CountSingle/10-4   31.16n ±  0%    41.69n ±  0%  +33.79% (p=0.000 n=11)
CountSingle/32-4   69.58n ±  0%    59.61n ±  0%  -14.33% (p=0.000 n=11)
CountSingle/4K-4   7.428µ ±  0%    5.153µ ±  0%  -30.63% (p=0.000 n=11)
CountSingle/4M-4   7.634m ±  0%    5.300m ±  0%  -30.58% (p=0.000 n=11)
CountSingle/64M-4   134.4m ±  0%    100.8m ±  3%  -24.99% (p=0.000 n=11)

name             old B/s      new B/s       vs base
CountSingle/10-4   306.1Mi ±  0%    228.8Mi ±  0%  -25.25% (p=0.000 n=11)
CountSingle/32-4   438.6Mi ±  0%    512.0Mi ±  0%  +16.74% (p=0.000 n=11)
CountSingle/4K-4   525.9Mi ±  0%    758.0Mi ±  0%  +44.15% (p=0.000 n=11)
CountSingle/4M-4   523.9Mi ±  0%    754.7Mi ±  0%  +44.05% (p=0.000 n=11)
CountSingle/64M-4  476.3Mi ±  0%    635.0Mi ±  0%  +33.31% (p=0.000 n=11)

Change-Id: Id5ddbea0d080e2903156ef8dc86c030a8179115b
Reviewed-on: https://go-review.googlesource.com/c/go/+/650995
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>

src/internal/bytealg/count_generic.go
src/internal/bytealg/count_mips64x.s [new file with mode: 0644]
src/internal/bytealg/count_native.go

index 932a7c584c1ae60517465e615feafd815c2e3e83..54bb100cbf94e687dd9941c28e247b8429154dc3 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !amd64 && !arm && !arm64 && !ppc64le && !ppc64 && !riscv64 && !s390x
+//go:build !amd64 && !arm && !arm64 && !mips64le && !mips64 && !ppc64le && !ppc64 && !riscv64 && !s390x
 
 package bytealg
 
diff --git a/src/internal/bytealg/count_mips64x.s b/src/internal/bytealg/count_mips64x.s
new file mode 100644 (file)
index 0000000..247d0b3
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build mips64 || mips64le
+
+#include "go_asm.h"
+#include "textflag.h"
+
+TEXT ·Count(SB),NOSPLIT,$0-40
+       // R1 = b_base
+       // R2 = b_len
+       // R3 = byte to count
+       MOVV    b_base+0(FP), R1
+       MOVV    b_len+8(FP), R2
+       MOVBU   c+24(FP), R3
+       MOVV    R0, R5  // count
+       ADDV    R1, R2  // end
+
+loop:
+       BEQ     R1, R2, done
+       MOVBU   (R1), R6
+       ADDV    $1, R1
+       BNE     R3, R6, loop
+       ADDV    $1, R5
+       JMP     loop
+
+done:
+       MOVV    R5, ret+32(FP)
+       RET
+
+TEXT ·CountString(SB),NOSPLIT,$0-32
+       // R1 = s_base
+       // R2 = s_len
+       // R3 = byte to count
+       MOVV    s_base+0(FP), R1
+       MOVV    s_len+8(FP), R2
+       MOVBU   c+16(FP), R3
+       MOVV    R0, R5  // count
+       ADDV    R1, R2  // end
+
+loop:
+       BEQ     R1, R2, done
+       MOVBU   (R1), R6
+       ADDV    $1, R1
+       BNE     R3, R6, loop
+       ADDV    $1, R5
+       JMP     loop
+
+done:
+       MOVV    R5, ret+24(FP)
+       RET
index 90189c9fe051bd12fd25b20993282ebf83e59744..0a8caee87ea9b81fd5075a1fe299229439155f37 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build amd64 || arm || arm64 || ppc64le || ppc64 || riscv64 || s390x
+//go:build amd64 || arm || arm64 || mips64le || mips64 || ppc64le || ppc64 || riscv64 || s390x
 
 package bytealg