2018-03-05 13:51:54 -07:00
|
|
|
// 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
|
|
|
|
|
2018-04-29 08:12:50 -06:00
|
|
|
import "runtime"
|
|
|
|
|
2018-04-12 08:24:08 -06:00
|
|
|
// Check small copies are replaced with moves.
|
2018-03-14 04:07:06 -06:00
|
|
|
|
|
|
|
func movesmall4() {
|
|
|
|
x := [...]byte{1, 2, 3, 4}
|
|
|
|
// 386:-".*memmove"
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2018-03-14 04:07:06 -06:00
|
|
|
copy(x[1:], x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func movesmall7() {
|
2018-03-05 13:51:54 -07:00
|
|
|
x := [...]byte{1, 2, 3, 4, 5, 6, 7}
|
2018-03-14 04:07:06 -06:00
|
|
|
// 386:-".*memmove"
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2018-03-14 04:07:06 -06:00
|
|
|
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"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:".*memmove"
|
2018-03-14 04:07:06 -06:00
|
|
|
copy(x[1:], x[:])
|
2018-03-05 13:51:54 -07:00
|
|
|
}
|
2018-04-12 08:24:08 -06:00
|
|
|
|
|
|
|
var x [256]byte
|
|
|
|
|
2018-04-29 08:12:50 -06:00
|
|
|
// Check that large disjoint copies are replaced with moves.
|
|
|
|
|
2020-03-30 13:23:19 -06:00
|
|
|
func moveDisjointStack32() {
|
2020-04-20 14:33:19 -06:00
|
|
|
var s [32]byte
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2023-01-24 10:38:29 -07:00
|
|
|
// ppc64x/power8:"LXVD2X",-"ADD",-"BC"
|
|
|
|
// ppc64x/power9:"LXV",-"LXVD2X",-"ADD",-"BC"
|
2020-04-20 14:33:19 -06:00
|
|
|
copy(s[:], x[:32])
|
|
|
|
runtime.KeepAlive(&s)
|
2020-03-30 13:23:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func moveDisjointStack64() {
|
2020-04-20 14:33:19 -06:00
|
|
|
var s [96]byte
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2023-01-24 10:38:29 -07:00
|
|
|
// ppc64x/power8:"LXVD2X","ADD","BC"
|
|
|
|
// ppc64x/power9:"LXV",-"LXVD2X",-"ADD",-"BC"
|
2020-04-20 14:33:19 -06:00
|
|
|
copy(s[:], x[:96])
|
|
|
|
runtime.KeepAlive(&s)
|
2020-03-30 13:23:19 -06:00
|
|
|
}
|
|
|
|
|
2018-04-29 08:12:50 -06:00
|
|
|
func moveDisjointStack() {
|
|
|
|
var s [256]byte
|
|
|
|
// s390x:-".*memmove"
|
2018-05-09 14:49:22 -06:00
|
|
|
// amd64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2023-01-24 10:38:29 -07:00
|
|
|
// ppc64x/power8:"LXVD2X"
|
|
|
|
// ppc64x/power9:"LXV",-"LXVD2X"
|
2018-04-29 08:12:50 -06:00
|
|
|
copy(s[:], x[:])
|
|
|
|
runtime.KeepAlive(&s)
|
|
|
|
}
|
|
|
|
|
2018-05-09 14:49:22 -06:00
|
|
|
func moveDisjointArg(b *[256]byte) {
|
2018-04-29 08:12:50 -06:00
|
|
|
var s [256]byte
|
|
|
|
// s390x:-".*memmove"
|
2018-05-09 14:49:22 -06:00
|
|
|
// amd64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2023-01-24 10:38:29 -07:00
|
|
|
// ppc64x/power8:"LXVD2X"
|
|
|
|
// ppc64x/power9:"LXV",-"LXVD2X"
|
2018-04-29 08:12:50 -06:00
|
|
|
copy(s[:], b[:])
|
|
|
|
runtime.KeepAlive(&s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func moveDisjointNoOverlap(a *[256]byte) {
|
|
|
|
// s390x:-".*memmove"
|
2018-05-09 14:49:22 -06:00
|
|
|
// amd64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2023-01-24 10:38:29 -07:00
|
|
|
// ppc64x/power8:"LXVD2X"
|
|
|
|
// ppc64x/power9:"LXV",-"LXVD2X"
|
2018-04-29 08:12:50 -06:00
|
|
|
copy(a[:], a[128:])
|
|
|
|
}
|
|
|
|
|
2021-01-19 07:30:10 -07:00
|
|
|
// Check arch-specific memmove lowering. See issue 41662 fot details
|
|
|
|
|
|
|
|
func moveArchLowering1(b []byte, x *[1]byte) {
|
|
|
|
_ = b[1]
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2021-01-19 07:30:10 -07:00
|
|
|
copy(b, x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func moveArchLowering2(b []byte, x *[2]byte) {
|
|
|
|
_ = b[2]
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2021-01-19 07:30:10 -07:00
|
|
|
copy(b, x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func moveArchLowering4(b []byte, x *[4]byte) {
|
|
|
|
_ = b[4]
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2021-01-19 07:30:10 -07:00
|
|
|
copy(b, x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func moveArchLowering8(b []byte, x *[8]byte) {
|
|
|
|
_ = b[8]
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
// arm64:-".*memmove"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-".*memmove"
|
2021-01-19 07:30:10 -07:00
|
|
|
copy(b, x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func moveArchLowering16(b []byte, x *[16]byte) {
|
|
|
|
_ = b[16]
|
|
|
|
// amd64:-".*memmove"
|
|
|
|
copy(b, x[:])
|
|
|
|
}
|
|
|
|
|
2018-04-29 08:12:50 -06:00
|
|
|
// Check that no branches are generated when the pointers are [not] equal.
|
|
|
|
|
2018-04-12 08:24:08 -06:00
|
|
|
func ptrEqual() {
|
|
|
|
// amd64:-"JEQ",-"JNE"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-"BEQ",-"BNE"
|
2018-04-12 08:24:08 -06:00
|
|
|
// s390x:-"BEQ",-"BNE"
|
|
|
|
copy(x[:], x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func ptrOneOffset() {
|
|
|
|
// amd64:-"JEQ",-"JNE"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-"BEQ",-"BNE"
|
2018-04-12 08:24:08 -06:00
|
|
|
// s390x:-"BEQ",-"BNE"
|
|
|
|
copy(x[1:], x[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
func ptrBothOffset() {
|
|
|
|
// amd64:-"JEQ",-"JNE"
|
2023-01-25 10:53:10 -07:00
|
|
|
// ppc64x:-"BEQ",-"BNE"
|
2018-04-12 08:24:08 -06:00
|
|
|
// s390x:-"BEQ",-"BNE"
|
|
|
|
copy(x[1:], x[2:])
|
|
|
|
}
|
2023-09-18 10:29:20 -06:00
|
|
|
|
|
|
|
// Verify #62698 on PPC64.
|
|
|
|
func noMaskOnCopy(a []int, s string, x int) int {
|
|
|
|
// ppc64x:-"MOVD\t$-1", -"AND"
|
|
|
|
return a[x&^copy([]byte{}, s)]
|
|
|
|
}
|