summaryrefslogtreecommitdiffstats
path: root/test/codegen/copy.go
blob: 0cd86d1161a9f32a58759e166b0f14d8afd6e01e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// asmcheck

// 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.

package codegen

import "runtime"

// Check small copies are replaced with moves.

func movesmall4() {
	x := [...]byte{1, 2, 3, 4}
	// 386:-".*memmove"
	// amd64:-".*memmove"
	// arm:-".*memmove"
	// arm64:-".*memmove"
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	copy(x[1:], x[:])
}

func movesmall7() {
	x := [...]byte{1, 2, 3, 4, 5, 6, 7}
	// 386:-".*memmove"
	// amd64:-".*memmove"
	// arm64:-".*memmove"
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	copy(x[1:], x[:])
}

func movesmall16() {
	x := [...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
	// amd64:-".*memmove"
	// ppc64:".*memmove"
	// ppc64le:".*memmove"
	copy(x[1:], x[:])
}

var x [256]byte

// Check that large disjoint copies are replaced with moves.

func moveDisjointStack32() {
	var s [32]byte
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	// ppc64le/power8:"LXVD2X",-"ADD",-"BC"
	// ppc64le/power9:"LXV",-"LXVD2X",-"ADD",-"BC"
	copy(s[:], x[:32])
	runtime.KeepAlive(&s)
}

func moveDisjointStack64() {
	var s [96]byte
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	// ppc64le/power8:"LXVD2X","ADD","BC"
	// ppc64le/power9:"LXV",-"LXVD2X",-"ADD",-"BC"
	copy(s[:], x[:96])
	runtime.KeepAlive(&s)
}

func moveDisjointStack() {
	var s [256]byte
	// s390x:-".*memmove"
	// amd64:-".*memmove"
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	// ppc64le/power8:"LXVD2X"
	// ppc64le/power9:"LXV",-"LXVD2X"
	copy(s[:], x[:])
	runtime.KeepAlive(&s)
}

func moveDisjointArg(b *[256]byte) {
	var s [256]byte
	// s390x:-".*memmove"
	// amd64:-".*memmove"
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	// ppc64le/power8:"LXVD2X"
	// ppc64le/power9:"LXV",-"LXVD2X"
	copy(s[:], b[:])
	runtime.KeepAlive(&s)
}

func moveDisjointNoOverlap(a *[256]byte) {
	// s390x:-".*memmove"
	// amd64:-".*memmove"
	// ppc64:-".*memmove"
	// ppc64le:-".*memmove"
	// ppc64le/power8:"LXVD2X"
	// ppc64le/power9:"LXV",-"LXVD2X"
	copy(a[:], a[128:])
}

// Check that no branches are generated when the pointers are [not] equal.

func ptrEqual() {
	// amd64:-"JEQ",-"JNE"
	// ppc64:-"BEQ",-"BNE"
	// ppc64le:-"BEQ",-"BNE"
	// s390x:-"BEQ",-"BNE"
	copy(x[:], x[:])
}

func ptrOneOffset() {
	// amd64:-"JEQ",-"JNE"
	// ppc64:-"BEQ",-"BNE"
	// ppc64le:-"BEQ",-"BNE"
	// s390x:-"BEQ",-"BNE"
	copy(x[1:], x[:])
}

func ptrBothOffset() {
	// amd64:-"JEQ",-"JNE"
	// ppc64:-"BEQ",-"BNE"
	// ppc64le:-"BEQ",-"BNE"
	// s390x:-"BEQ",-"BNE"
	copy(x[1:], x[2:])
}