| 1 |
// asmcheck |
| 2 |
|
| 3 |
// Copyright 2018 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package codegen |
| 8 |
|
| 9 |
import "runtime" |
| 10 |
|
| 11 |
// Check small copies are replaced with moves. |
| 12 |
|
| 13 |
func movesmall4() { |
| 14 |
x := [...]byte{1, 2, 3, 4} |
| 15 |
// 386:-".*memmove" |
| 16 |
// amd64:-".*memmove" |
| 17 |
// arm:-".*memmove" |
| 18 |
// arm64:-".*memmove" |
| 19 |
// ppc64x:-".*memmove" |
| 20 |
copy(x[1:], x[:]) |
| 21 |
} |
| 22 |
|
| 23 |
func movesmall7() { |
| 24 |
x := [...]byte{1, 2, 3, 4, 5, 6, 7} |
| 25 |
// 386:-".*memmove" |
| 26 |
// amd64:-".*memmove" |
| 27 |
// arm64:-".*memmove" |
| 28 |
// ppc64x:-".*memmove" |
| 29 |
copy(x[1:], x[:]) |
| 30 |
} |
| 31 |
|
| 32 |
func movesmall16() { |
| 33 |
x := [...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} |
| 34 |
// amd64:-".*memmove" |
| 35 |
// ppc64x:".*memmove" |
| 36 |
copy(x[1:], x[:]) |
| 37 |
} |
| 38 |
|
| 39 |
var x [256]byte |
| 40 |
|
| 41 |
// Check that large disjoint copies are replaced with moves. |
| 42 |
|
| 43 |
func moveDisjointStack32() { |
| 44 |
var s [32]byte |
| 45 |
// ppc64x:-".*memmove" |
| 46 |
// ppc64x/power8:"LXVD2X" -"ADD" -"BC" |
| 47 |
// ppc64x/power9:"LXV" -"LXVD2X" -"ADD" -"BC" |
| 48 |
copy(s[:], x[:32]) |
| 49 |
runtime.KeepAlive(&s) |
| 50 |
} |
| 51 |
|
| 52 |
func moveDisjointStack64() { |
| 53 |
var s [96]byte |
| 54 |
// ppc64x:-".*memmove" |
| 55 |
// ppc64x/power8:"LXVD2X" "ADD" "BC" |
| 56 |
// ppc64x/power9:"LXV" -"LXVD2X" -"ADD" -"BC" |
| 57 |
copy(s[:], x[:96]) |
| 58 |
runtime.KeepAlive(&s) |
| 59 |
} |
| 60 |
|
| 61 |
func moveDisjointStack() { |
| 62 |
var s [256]byte |
| 63 |
// s390x:-".*memmove" |
| 64 |
// amd64:-".*memmove" |
| 65 |
// ppc64x:-".*memmove" |
| 66 |
// ppc64x/power8:"LXVD2X" |
| 67 |
// ppc64x/power9:"LXV" -"LXVD2X" |
| 68 |
copy(s[:], x[:]) |
| 69 |
runtime.KeepAlive(&s) |
| 70 |
} |
| 71 |
|
| 72 |
func moveDisjointArg(b *[256]byte) { |
| 73 |
var s [256]byte |
| 74 |
// s390x:-".*memmove" |
| 75 |
// amd64:-".*memmove" |
| 76 |
// ppc64x:-".*memmove" |
| 77 |
// ppc64x/power8:"LXVD2X" |
| 78 |
// ppc64x/power9:"LXV" -"LXVD2X" |
| 79 |
copy(s[:], b[:]) |
| 80 |
runtime.KeepAlive(&s) |
| 81 |
} |
| 82 |
|
| 83 |
func moveDisjointNoOverlap(a *[256]byte) { |
| 84 |
// s390x:-".*memmove" |
| 85 |
// amd64:-".*memmove" |
| 86 |
// ppc64x:-".*memmove" |
| 87 |
// ppc64x/power8:"LXVD2X" |
| 88 |
// ppc64x/power9:"LXV" -"LXVD2X" |
| 89 |
copy(a[:], a[128:]) |
| 90 |
} |
| 91 |
|
| 92 |
// Check arch-specific memmove lowering. See issue 41662 fot details |
| 93 |
|
| 94 |
func moveArchLowering1(b []byte, x *[1]byte) { |
| 95 |
_ = b[1] |
| 96 |
// amd64:-".*memmove" |
| 97 |
// arm64:-".*memmove" |
| 98 |
// loong64:-".*memmove" |
| 99 |
// ppc64x:-".*memmove" |
| 100 |
copy(b, x[:]) |
| 101 |
} |
| 102 |
|
| 103 |
func moveArchLowering2(b []byte, x *[2]byte) { |
| 104 |
_ = b[2] |
| 105 |
// amd64:-".*memmove" |
| 106 |
// arm64:-".*memmove" |
| 107 |
// loong64:-".*memmove" |
| 108 |
// ppc64x:-".*memmove" |
| 109 |
copy(b, x[:]) |
| 110 |
} |
| 111 |
|
| 112 |
func moveArchLowering4(b []byte, x *[4]byte) { |
| 113 |
_ = b[4] |
| 114 |
// amd64:-".*memmove" |
| 115 |
// arm64:-".*memmove" |
| 116 |
// loong64:-".*memmove" |
| 117 |
// ppc64x:-".*memmove" |
| 118 |
copy(b, x[:]) |
| 119 |
} |
| 120 |
|
| 121 |
func moveArchLowering8(b []byte, x *[8]byte) { |
| 122 |
_ = b[8] |
| 123 |
// amd64:-".*memmove" |
| 124 |
// arm64:-".*memmove" |
| 125 |
// ppc64x:-".*memmove" |
| 126 |
copy(b, x[:]) |
| 127 |
} |
| 128 |
|
| 129 |
func moveArchLowering16(b []byte, x *[16]byte) { |
| 130 |
_ = b[16] |
| 131 |
// amd64:-".*memmove" |
| 132 |
copy(b, x[:]) |
| 133 |
} |
| 134 |
|
| 135 |
// Check that no branches are generated when the pointers are [not] equal. |
| 136 |
|
| 137 |
func ptrEqual() { |
| 138 |
// amd64:-"JEQ" -"JNE" |
| 139 |
// ppc64x:-"BEQ" -"BNE" |
| 140 |
// s390x:-"BEQ" -"BNE" |
| 141 |
copy(x[:], x[:]) |
| 142 |
} |
| 143 |
|
| 144 |
func ptrOneOffset() { |
| 145 |
// amd64:-"JEQ" -"JNE" |
| 146 |
// ppc64x:-"BEQ" -"BNE" |
| 147 |
// s390x:-"BEQ" -"BNE" |
| 148 |
copy(x[1:], x[:]) |
| 149 |
} |
| 150 |
|
| 151 |
func ptrBothOffset() { |
| 152 |
// amd64:-"JEQ" -"JNE" |
| 153 |
// ppc64x:-"BEQ" -"BNE" |
| 154 |
// s390x:-"BEQ" -"BNE" |
| 155 |
copy(x[1:], x[2:]) |
| 156 |
} |
| 157 |
|
| 158 |
// Verify #62698 on PPC64. |
| 159 |
func noMaskOnCopy(a []int, s string, x int) int { |
| 160 |
// ppc64x:-"MOVD [$]-1", -"AND" |
| 161 |
return a[x&^copy([]byte{}, s)] |
| 162 |
} |