1
0
mirror of https://github.com/golang/go synced 2024-11-06 09:16:16 -07:00
go/src/runtime/memmove_wasm.s
Austin Clements 9b5bd30716 runtime: document special memmove requirements
Unlike C's memmove, Go's memmove must be careful to do indivisible
writes of pointer values because it may be racing with the garbage
collector reading the heap.

We've had various bugs related to this over the years (#36101, #13160,
 #12552). Indeed, memmove is a great target for optimization and it's
easy to forget the special requirements of Go's memmove.

The CL documents these (currently unwritten!) requirements. We're also
adding a test that should hopefully keep everyone honest going
forward, though it's hard to be sure we're hitting all cases of
memmove.

Change-Id: I2f59f8d8d6fb42d2f10006b55d605b5efd8ddc24
Reviewed-on: https://go-review.googlesource.com/c/go/+/213418
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-01-22 18:54:48 +00:00

155 lines
1.7 KiB
ArmAsm

// Copyright 2018 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, $0-24
MOVD to+0(FP), R0
MOVD from+8(FP), R1
MOVD n+16(FP), R2
Get R0
Get R1
I64LtU
If // forward
exit_forward_64:
Block
loop_forward_64:
Loop
Get R2
I64Const $8
I64LtU
BrIf exit_forward_64
MOVD 0(R1), 0(R0)
Get R0
I64Const $8
I64Add
Set R0
Get R1
I64Const $8
I64Add
Set R1
Get R2
I64Const $8
I64Sub
Set R2
Br loop_forward_64
End
End
loop_forward_8:
Loop
Get R2
I64Eqz
If
RET
End
Get R0
I32WrapI64
I64Load8U (R1)
I64Store8 $0
Get R0
I64Const $1
I64Add
Set R0
Get R1
I64Const $1
I64Add
Set R1
Get R2
I64Const $1
I64Sub
Set R2
Br loop_forward_8
End
Else
// backward
Get R0
Get R2
I64Add
Set R0
Get R1
Get R2
I64Add
Set R1
exit_backward_64:
Block
loop_backward_64:
Loop
Get R2
I64Const $8
I64LtU
BrIf exit_backward_64
Get R0
I64Const $8
I64Sub
Set R0
Get R1
I64Const $8
I64Sub
Set R1
Get R2
I64Const $8
I64Sub
Set R2
MOVD 0(R1), 0(R0)
Br loop_backward_64
End
End
loop_backward_8:
Loop
Get R2
I64Eqz
If
RET
End
Get R0
I64Const $1
I64Sub
Set R0
Get R1
I64Const $1
I64Sub
Set R1
Get R2
I64Const $1
I64Sub
Set R2
Get R0
I32WrapI64
I64Load8U (R1)
I64Store8 $0
Br loop_backward_8
End
End
UNDEF