aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorXiaodong Liu <liuxiaodong@loongson.cn>2022-05-19 20:01:10 +0800
committerGopher Robot <gobot@golang.org>2022-05-19 19:13:01 +0000
commit2a5114f49af42c1df293e64841b28c22a84211f0 (patch)
tree05ce3f5734e09353f6b39be3bbad3ef99a22cd11 /src/runtime
parent946b4baaf6521d521928500b2b57429c149854e7 (diff)
downloadgo-2a5114f49af42c1df293e64841b28c22a84211f0.tar.xz
runtime: support memclr/memmove for linux/loong64
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: I7c1f39670034db6714630d479bc41b6620ba2b1a Reviewed-on: https://go-review.googlesource.com/c/go/+/368079 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/memclr_loong64.s41
-rw-r--r--src/runtime/memmove_loong64.s105
2 files changed, 146 insertions, 0 deletions
diff --git a/src/runtime/memclr_loong64.s b/src/runtime/memclr_loong64.s
new file mode 100644
index 0000000000..e4f20587b7
--- /dev/null
+++ b/src/runtime/memclr_loong64.s
@@ -0,0 +1,41 @@
+// 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"
+
+// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
+TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
+ MOVV ptr+0(FP), R6
+ MOVV n+8(FP), R7
+ ADDV R6, R7, R4
+
+ // if less than 8 bytes, do one byte at a time
+ SGTU $8, R7, R8
+ BNE R8, out
+
+ // do one byte at a time until 8-aligned
+ AND $7, R6, R8
+ BEQ R8, words
+ MOVB R0, (R6)
+ ADDV $1, R6
+ JMP -4(PC)
+
+words:
+ // do 8 bytes at a time if there is room
+ ADDV $-7, R4, R7
+
+ SGTU R7, R6, R8
+ BEQ R8, out
+ MOVV R0, (R6)
+ ADDV $8, R6
+ JMP -4(PC)
+
+out:
+ BEQ R6, R4, done
+ MOVB R0, (R6)
+ ADDV $1, R6
+ JMP -3(PC)
+done:
+ RET
diff --git a/src/runtime/memmove_loong64.s b/src/runtime/memmove_loong64.s
new file mode 100644
index 0000000000..b7b9c56627
--- /dev/null
+++ b/src/runtime/memmove_loong64.s
@@ -0,0 +1,105 @@
+// 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 "textflag.h"
+
+// See memmove Go doc for important implementation constraints.
+
+// func memmove(to, from unsafe.Pointer, n uintptr)
+TEXT runtime·memmove(SB), NOSPLIT|NOFRAME, $0-24
+ MOVV to+0(FP), R4
+ MOVV from+8(FP), R5
+ MOVV n+16(FP), R6
+ BNE R6, check
+ RET
+
+check:
+ SGTU R4, R5, R7
+ BNE R7, backward
+
+ ADDV R4, R6, R9 // end pointer
+
+ // if the two pointers are not of same alignments, do byte copying
+ SUBVU R5, R4, R7
+ AND $7, R7
+ BNE R7, out
+
+ // if less than 8 bytes, do byte copying
+ SGTU $8, R6, R7
+ BNE R7, out
+
+ // do one byte at a time until 8-aligned
+ AND $7, R4, R8
+ BEQ R8, words
+ MOVB (R5), R7
+ ADDV $1, R5
+ MOVB R7, (R4)
+ ADDV $1, R4
+ JMP -6(PC)
+
+words:
+ // do 8 bytes at a time if there is room
+ ADDV $-7, R9, R6 // R6 is end pointer-7
+
+ SGTU R6, R4, R8
+ BEQ R8, out
+ MOVV (R5), R7
+ ADDV $8, R5
+ MOVV R7, (R4)
+ ADDV $8, R4
+ JMP -6(PC)
+
+out:
+ BEQ R4, R9, done
+ MOVB (R5), R7
+ ADDV $1, R5
+ MOVB R7, (R4)
+ ADDV $1, R4
+ JMP -5(PC)
+done:
+ RET
+
+backward:
+ ADDV R6, R5 // from-end pointer
+ ADDV R4, R6, R9 // to-end pointer
+
+ // if the two pointers are not of same alignments, do byte copying
+ SUBVU R9, R5, R7
+ AND $7, R7
+ BNE R7, out1
+
+ // if less than 8 bytes, do byte copying
+ SGTU $8, R6, R7
+ BNE R7, out1
+
+ // do one byte at a time until 8-aligned
+ AND $7, R9, R8
+ BEQ R8, words1
+ ADDV $-1, R5
+ MOVB (R5), R7
+ ADDV $-1, R9
+ MOVB R7, (R9)
+ JMP -6(PC)
+
+words1:
+ // do 8 bytes at a time if there is room
+ ADDV $7, R4, R6 // R6 is start pointer+7
+
+ SGTU R9, R6, R8
+ BEQ R8, out1
+ ADDV $-8, R5
+ MOVV (R5), R7
+ ADDV $-8, R9
+ MOVV R7, (R9)
+ JMP -6(PC)
+
+out1:
+ BEQ R4, R9, done1
+ ADDV $-1, R5
+ MOVB (R5), R7
+ ADDV $-1, R9
+ MOVB R7, (R9)
+ JMP -5(PC)
+done1:
+ RET