Help us shape the future of Go! Take the 2026 Go Developer Survey

Source file src/runtime/memmove_arm64_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package runtime_test
     6  
     7  import (
     8  	"fmt"
     9  	. "runtime"
    10  	"testing"
    11  )
    12  
    13  // TestMemmoveRealign runs long copies through both realignment strategies,
    14  // aligned loads and aligned stores, whichever one the host CPU uses.
    15  func TestMemmoveRealign(t *testing.T) {
    16  	sizes := []int{129, 143, 144, 160, 255, 511, 1000, 1023, 1024, 1025, 2049}
    17  	old := *Arm64UseAlignedLoads
    18  	defer func() { *Arm64UseAlignedLoads = old }()
    19  	for _, aligned := range []bool{false, true} {
    20  		t.Run(fmt.Sprintf("alignedLoads=%v", aligned), func(t *testing.T) {
    21  			*Arm64UseAlignedLoads = aligned
    22  			for _, n := range sizes {
    23  				buf := make([]byte, 2*n+64)
    24  				want := make([]byte, len(buf))
    25  				for so := 0; so < 16; so++ {
    26  					for do := 0; do < 16; do++ {
    27  						cases := []struct{ src, dst int }{
    28  							{so, n + 32 + do},  // disjoint
    29  							{32 + so, 49 + do}, // overlapping, dst after src
    30  							{32 + so, 15 + do}, // overlapping, dst before src
    31  						}
    32  						for _, c := range cases {
    33  							for i := range buf {
    34  								buf[i] = byte(i * 7)
    35  							}
    36  							copy(want, buf)
    37  							for i := 0; i < n; i++ {
    38  								want[c.dst+i] = buf[c.src+i]
    39  							}
    40  							copy(buf[c.dst:c.dst+n], buf[c.src:c.src+n])
    41  							for i := range buf {
    42  								if buf[i] != want[i] {
    43  									t.Fatalf("n=%d src=%d dst=%d: byte %d = %d, want %d", n, c.src, c.dst, i, buf[i], want[i])
    44  								}
    45  							}
    46  						}
    47  					}
    48  				}
    49  			}
    50  		})
    51  	}
    52  }
    53  

View as plain text