]> Cypherpunks repositories - gostls13.git/commitdiff
internal/bytealg: support basic byte operation on loong64
authorXiaodong Liu <liuxiaodong@loongson.cn>
Sun, 15 Aug 2021 08:31:52 +0000 (16:31 +0800)
committerIan Lance Taylor <iant@google.com>
Tue, 17 May 2022 19:55:37 +0000 (19:55 +0000)
Contributors to the loong64 port are:
  Weining Lu <luweining@loongson.cn>
  Lei Wang <wanglei@loongson.cn>
  Lingqin Gong <gonglingqin@loongson.cn>
  Xiaolin Zhao <zhaoxiaolin@loongson.cn>
  Meidan Li <limeidan@loongson.cn>
  Xiaojuan Zhai <zhaixiaojuan@loongson.cn>
  Qiyuan Pu <puqiyuan@loongson.cn>
  Guoqi Chen <chenguoqi@loongson.cn>

This port has been updated to Go 1.15.6:
  https://github.com/loongson/go

Updates #46229

Change-Id: I4ac6d38dc632abfa0b698325ca0ae349c0d7ecd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/342316
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/internal/bytealg/compare_generic.go
src/internal/bytealg/compare_loong64.s [new file with mode: 0644]
src/internal/bytealg/compare_native.go
src/internal/bytealg/equal_loong64.s [new file with mode: 0644]
src/internal/bytealg/indexbyte_generic.go
src/internal/bytealg/indexbyte_loong64.s [new file with mode: 0644]
src/internal/bytealg/indexbyte_native.go

index c5853f503f014fc32c847e9712b68956d29af598..b04e2750611bf0983ee7d1da379b51a17eb8e61a 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 !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le && !riscv64
+//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !loong64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le && !riscv64
 
 package bytealg
 
diff --git a/src/internal/bytealg/compare_loong64.s b/src/internal/bytealg/compare_loong64.s
new file mode 100644 (file)
index 0000000..54c2dab
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright 2022 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 ·Compare(SB),NOSPLIT,$0-56
+       MOVV    a_base+0(FP), R6
+       MOVV    b_base+24(FP), R7
+       MOVV    a_len+8(FP), R4
+       MOVV    b_len+32(FP), R5
+       MOVV    $ret+48(FP), R13
+       JMP     cmpbody<>(SB)
+
+TEXT runtime·cmpstring(SB),NOSPLIT,$0-40
+       MOVV    a_base+0(FP), R6
+       MOVV    b_base+16(FP), R7
+       MOVV    a_len+8(FP), R4
+       MOVV    b_len+24(FP), R5
+       MOVV    $ret+32(FP), R13
+       JMP     cmpbody<>(SB)
+
+// On entry:
+// R4 length of a
+// R5 length of b
+// R6 points to the start of a
+// R7 points to the start of b
+// R13 points to the return value (-1/0/1)
+TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0
+       BEQ     R6, R7, samebytes // same start of a and b
+
+       SGTU    R4, R5, R9
+       BNE     R0, R9, r2_lt_r1
+       MOVV    R4, R14
+       JMP     entry
+r2_lt_r1:
+       MOVV    R5, R14 // R14 is min(R4, R5)
+entry:
+       ADDV    R6, R14, R12    // R6 start of a, R14 end of a
+       BEQ     R6, R12, samebytes // length is 0
+
+       SRLV    $4, R14         // R14 is number of chunks
+       BEQ     R0, R14, byte_loop
+
+       // make sure both a and b are aligned.
+       OR      R6, R7, R15
+       AND     $7, R15
+       BNE     R0, R15, byte_loop
+
+chunk16_loop:
+       BEQ     R0, R14, byte_loop
+       MOVV    (R6), R8
+       MOVV    (R7), R9
+       BNE     R8, R9, byte_loop
+       MOVV    8(R6), R16
+       MOVV    8(R7), R17
+       ADDV    $16, R6
+       ADDV    $16, R7
+       SUBVU   $1, R14
+       BEQ     R16, R17, chunk16_loop
+       SUBV    $8, R6
+       SUBV    $8, R7
+
+byte_loop:
+       BEQ     R6, R12, samebytes
+       MOVBU   (R6), R8
+       ADDVU   $1, R6
+       MOVBU   (R7), R9
+       ADDVU   $1, R7
+       BEQ     R8, R9, byte_loop
+
+byte_cmp:
+       SGTU    R8, R9, R12 // R12 = 1 if (R8 > R9)
+       BNE     R0, R12, ret
+       MOVV    $-1, R12
+       JMP     ret
+
+samebytes:
+       SGTU    R4, R5, R8
+       SGTU    R5, R4, R9
+       SUBV    R9, R8, R12
+
+ret:
+       MOVV    R12, (R13)
+       RET
index ad0fcd7660abb42df81aa359d469f8306ceb2602..34964e281c637c31c08f78e2d1fbc01415348fa8 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 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64
+//go:build 386 || amd64 || s390x || arm || arm64 || loong64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64
 
 package bytealg
 
diff --git a/src/internal/bytealg/equal_loong64.s b/src/internal/bytealg/equal_loong64.s
new file mode 100644 (file)
index 0000000..dcdde89
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2022 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        REGCTXT R29
+
+// memequal(a, b unsafe.Pointer, size uintptr) bool
+TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25
+       MOVV    a+0(FP), R4
+       MOVV    b+8(FP), R5
+       BEQ     R4, R5, eq
+       MOVV    size+16(FP), R6
+       ADDV    R4, R6, R7
+loop:
+       BNE     R4, R7, test
+       MOVV    $1, R4
+       MOVB    R4, ret+24(FP)
+       RET
+test:
+       MOVBU   (R4), R9
+       ADDV    $1, R4
+       MOVBU   (R5), R10
+       ADDV    $1, R5
+       BEQ     R9, R10, loop
+
+       MOVB    R0, ret+24(FP)
+       RET
+eq:
+       MOVV    $1, R4
+       MOVB    R4, ret+24(FP)
+       RET
+
+// memequal_varlen(a, b unsafe.Pointer) bool
+TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
+       MOVV    a+0(FP), R4
+       MOVV    b+8(FP), R5
+       BEQ     R4, R5, eq
+       MOVV    8(REGCTXT), R6    // compiler stores size at offset 8 in the closure
+       MOVV    R4, 8(R3)
+       MOVV    R5, 16(R3)
+       MOVV    R6, 24(R3)
+       JAL     runtime·memequal(SB)
+       MOVBU   32(R3), R4
+       MOVB    R4, ret+16(FP)
+       RET
+eq:
+       MOVV    $1, R4
+       MOVB    R4, ret+16(FP)
+       RET
index 0a45f903843edd8ae28d3ed07a63de5e7db35995..b89d34ff231aecd6e082a3bda08f1b5a2cde80cc 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 !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm
+//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !loong64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm
 
 package bytealg
 
diff --git a/src/internal/bytealg/indexbyte_loong64.s b/src/internal/bytealg/indexbyte_loong64.s
new file mode 100644 (file)
index 0000000..baa9c86
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2022 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
+       MOVV    b_base+0(FP), R4
+       MOVV    b_len+8(FP), R5
+       MOVBU   c+24(FP), R6    // byte to find
+       MOVV    R4, R7          // store base for later
+       ADDV    R4, R5          // end
+       ADDV    $-1, R4
+
+loop:
+       ADDV    $1, R4
+       BEQ     R4, R5, notfound
+       MOVBU   (R4), R8
+       BNE     R6, R8, loop
+
+       SUBV    R7, R4          // remove base
+       MOVV    R4, ret+32(FP)
+       RET
+
+notfound:
+       MOVV    $-1, R4
+       MOVV    R4, ret+32(FP)
+       RET
+
+TEXT ·IndexByteString(SB),NOSPLIT,$0-32
+       MOVV    s_base+0(FP), R4
+       MOVV    s_len+8(FP), R5
+       MOVBU   c+16(FP), R6    // byte to find
+       MOVV    R4, R7          // store base for later
+       ADDV    R4, R5          // end
+       ADDV    $-1, R4
+
+loop:
+       ADDV    $1, R4
+       BEQ     R4, R5, notfound
+       MOVBU   (R4), R8
+       BNE     R6, R8, loop
+
+       SUBV    R7, R4          // remove base
+       MOVV    R4, ret+24(FP)
+       RET
+
+notfound:
+       MOVV    $-1, R4
+       MOVV    R4, ret+24(FP)
+       RET
index 2101021e2d0254bcdc5b66b6a3633f01816cc38f..c5bb2df5ea1e686b0be00267e60ee9c7b2bcb96f 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 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || mips64 || mips64le || riscv64 || wasm
+//go:build 386 || amd64 || s390x || arm || arm64 || loong64 || ppc64 || ppc64le || mips || mipsle || mips64 || mips64le || riscv64 || wasm
 
 package bytealg