]> Cypherpunks repositories - gostls13.git/commitdiff
internal/cpu,internal/bytealg: add support for riscv64
authorJoel Sing <joel@sing.id.au>
Sun, 3 Nov 2019 18:12:11 +0000 (05:12 +1100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 11 Nov 2019 22:13:42 +0000 (22:13 +0000)
Based on riscv-go port.

Updates #27532

Change-Id: Ia3aed521d4109e7b73f762c5a3cdacc7cdac430d
Reviewed-on: https://go-review.googlesource.com/c/go/+/204635
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/internal/bytealg/equal_riscv64.s [new file with mode: 0644]
src/internal/bytealg/indexbyte_generic.go
src/internal/bytealg/indexbyte_native.go
src/internal/bytealg/indexbyte_riscv64.s [new file with mode: 0644]
src/internal/cpu/cpu_riscv64.go [new file with mode: 0644]

diff --git a/src/internal/bytealg/equal_riscv64.s b/src/internal/bytealg/equal_riscv64.s
new file mode 100644 (file)
index 0000000..22cb4fa
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright 2019 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.
+
+#include "go_asm.h"
+#include "textflag.h"
+
+#define        CTXT    S4
+
+// func memequal(a, b unsafe.Pointer, size uintptr) bool
+TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25
+       MOV     a+0(FP), A1
+       MOV     b+8(FP), A2
+       BEQ     A1, A2, eq
+       MOV     size+16(FP), A3
+       ADD     A1, A3, A4
+loop:
+       BEQ     A1, A4, eq
+
+       MOVBU   (A1), A6
+       ADD     $1, A1
+       MOVBU   (A2), A7
+       ADD     $1, A2
+       BEQ     A6, A7, loop
+
+       MOVB    ZERO, ret+24(FP)
+       RET
+eq:
+       MOV     $1, A1
+       MOVB    A1, ret+24(FP)
+       RET
+
+// func memequal_varlen(a, b unsafe.Pointer) bool
+TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
+       MOV     a+0(FP), A1
+       MOV     b+8(FP), A2
+       BEQ     A1, A2, eq
+       MOV     8(CTXT), A3    // compiler stores size at offset 8 in the closure
+       MOV     A1, 8(X2)
+       MOV     A2, 16(X2)
+       MOV     A3, 24(X2)
+       CALL    runtime·memequal(SB)
+       MOVBU   32(X2), A1
+       MOVB    A1, ret+16(FP)
+       RET
+eq:
+       MOV     $1, A1
+       MOVB    A1, ret+16(FP)
+       RET
index fce1b0fc542eb90a77b20afee5b49005c0a98c99..0b012a8850a2393aa9562ae2f4b6a69d99fa8ca1 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.
 
-// +build !386,!amd64,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!mips64,!mips64le,!wasm
+// +build !386,!amd64,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!mips64,!mips64le,!riscv64,!wasm
 
 package bytealg
 
index 157caa34c4a4c852f6b85b2a8a846b1433671b88..f96c5be49106c1b1ca0c6d45cb3c0b911ded3a94 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.
 
-// +build 386 amd64 s390x arm arm64 ppc64 ppc64le mips mipsle mips64 mips64le wasm
+// +build 386 amd64 s390x arm arm64 ppc64 ppc64le mips mipsle mips64 mips64le riscv64 wasm
 
 package bytealg
 
diff --git a/src/internal/bytealg/indexbyte_riscv64.s b/src/internal/bytealg/indexbyte_riscv64.s
new file mode 100644 (file)
index 0000000..087be86
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2019 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.
+
+#include "go_asm.h"
+#include "textflag.h"
+
+TEXT ·IndexByte(SB),NOSPLIT,$0-40
+       MOV     s+0(FP), A1
+       MOV     s_len+8(FP), A2
+       MOVBU   c+24(FP), A3    // byte to find
+       MOV     A1, A4          // store base for later
+       ADD     A1, A2          // end
+       ADD     $-1, A1
+
+loop:
+       ADD     $1, A1
+       BEQ     A1, A2, notfound
+       MOVBU   (A1), A5
+       BNE     A3, A5, loop
+
+       SUB     A4, A1          // remove base
+       MOV     A1, ret+32(FP)
+       RET
+
+notfound:
+       MOV     $-1, A1
+       MOV     A1, ret+32(FP)
+       RET
+
+TEXT ·IndexByteString(SB),NOSPLIT,$0-32
+       MOV     p+0(FP), A1
+       MOV     b_len+8(FP), A2
+       MOVBU   c+16(FP), A3    // byte to find
+       MOV     A1, A4          // store base for later
+       ADD     A1, A2          // end
+       ADD     $-1, A1
+
+loop:
+       ADD     $1, A1
+       BEQ     A1, A2, notfound
+       MOVBU   (A1), A5
+       BNE     A3, A5, loop
+
+       SUB     A4, A1          // remove base
+       MOV     A1, ret+24(FP)
+       RET
+
+notfound:
+       MOV     $-1, A1
+       MOV     A1, ret+24(FP)
+       RET
diff --git a/src/internal/cpu/cpu_riscv64.go b/src/internal/cpu/cpu_riscv64.go
new file mode 100644 (file)
index 0000000..c49cab7
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2019 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.
+
+package cpu
+
+const CacheLinePadSize = 32