1 // Copyright 2013 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.
12 func TestMemmove(t
*testing
.T
) {
17 src
:= make([]byte, size
)
18 dst
:= make([]byte, size
)
19 for i
:= 0; i
< size
; i
++ {
20 src
[i
] = byte(128 + (i
& 127))
22 for i
:= 0; i
< size
; i
++ {
23 dst
[i
] = byte(i
& 127)
25 for n
:= 0; n
<= size
; n
++ {
26 for x
:= 0; x
<= size
-n
; x
++ { // offset in src
27 for y
:= 0; y
<= size
-n
; y
++ { // offset in dst
28 copy(dst
[y
:y
+n
], src
[x
:x
+n
])
29 for i
:= 0; i
< y
; i
++ {
30 if dst
[i
] != byte(i
&127) {
31 t
.Fatalf("prefix dst[%d] = %d", i
, dst
[i
])
34 for i
:= y
; i
< y
+n
; i
++ {
35 if dst
[i
] != byte(128+((i
-y
+x
)&127)) {
36 t
.Fatalf("copied dst[%d] = %d", i
, dst
[i
])
38 dst
[i
] = byte(i
& 127) // reset dst
40 for i
:= y
+ n
; i
< size
; i
++ {
41 if dst
[i
] != byte(i
&127) {
42 t
.Fatalf("suffix dst[%d] = %d", i
, dst
[i
])
50 func TestMemmoveAlias(t
*testing
.T
) {
55 buf
:= make([]byte, size
)
56 for i
:= 0; i
< size
; i
++ {
59 for n
:= 0; n
<= size
; n
++ {
60 for x
:= 0; x
<= size
-n
; x
++ { // src offset
61 for y
:= 0; y
<= size
-n
; y
++ { // dst offset
62 copy(buf
[y
:y
+n
], buf
[x
:x
+n
])
63 for i
:= 0; i
< y
; i
++ {
64 if buf
[i
] != byte(i
) {
65 t
.Fatalf("prefix buf[%d] = %d", i
, buf
[i
])
68 for i
:= y
; i
< y
+n
; i
++ {
69 if buf
[i
] != byte(i
-y
+x
) {
70 t
.Fatalf("copied buf[%d] = %d", i
, buf
[i
])
72 buf
[i
] = byte(i
) // reset buf
74 for i
:= y
+ n
; i
< size
; i
++ {
75 if buf
[i
] != byte(i
) {
76 t
.Fatalf("suffix buf[%d] = %d", i
, buf
[i
])
84 func bmMemmove(b
*testing
.B
, n
int) {
88 for i
:= 0; i
< b
.N
; i
++ {
93 func BenchmarkMemmove0(b
*testing
.B
) { bmMemmove(b
, 0) }
94 func BenchmarkMemmove1(b
*testing
.B
) { bmMemmove(b
, 1) }
95 func BenchmarkMemmove2(b
*testing
.B
) { bmMemmove(b
, 2) }
96 func BenchmarkMemmove3(b
*testing
.B
) { bmMemmove(b
, 3) }
97 func BenchmarkMemmove4(b
*testing
.B
) { bmMemmove(b
, 4) }
98 func BenchmarkMemmove5(b
*testing
.B
) { bmMemmove(b
, 5) }
99 func BenchmarkMemmove6(b
*testing
.B
) { bmMemmove(b
, 6) }
100 func BenchmarkMemmove7(b
*testing
.B
) { bmMemmove(b
, 7) }
101 func BenchmarkMemmove8(b
*testing
.B
) { bmMemmove(b
, 8) }
102 func BenchmarkMemmove9(b
*testing
.B
) { bmMemmove(b
, 9) }
103 func BenchmarkMemmove10(b
*testing
.B
) { bmMemmove(b
, 10) }
104 func BenchmarkMemmove11(b
*testing
.B
) { bmMemmove(b
, 11) }
105 func BenchmarkMemmove12(b
*testing
.B
) { bmMemmove(b
, 12) }
106 func BenchmarkMemmove13(b
*testing
.B
) { bmMemmove(b
, 13) }
107 func BenchmarkMemmove14(b
*testing
.B
) { bmMemmove(b
, 14) }
108 func BenchmarkMemmove15(b
*testing
.B
) { bmMemmove(b
, 15) }
109 func BenchmarkMemmove16(b
*testing
.B
) { bmMemmove(b
, 16) }
110 func BenchmarkMemmove32(b
*testing
.B
) { bmMemmove(b
, 32) }
111 func BenchmarkMemmove64(b
*testing
.B
) { bmMemmove(b
, 64) }
112 func BenchmarkMemmove128(b
*testing
.B
) { bmMemmove(b
, 128) }
113 func BenchmarkMemmove256(b
*testing
.B
) { bmMemmove(b
, 256) }
114 func BenchmarkMemmove512(b
*testing
.B
) { bmMemmove(b
, 512) }
115 func BenchmarkMemmove1024(b
*testing
.B
) { bmMemmove(b
, 1024) }
116 func BenchmarkMemmove2048(b
*testing
.B
) { bmMemmove(b
, 2048) }
117 func BenchmarkMemmove4096(b
*testing
.B
) { bmMemmove(b
, 4096) }
119 func TestMemclr(t
*testing
.T
) {
124 mem
:= make([]byte, size
)
125 for i
:= 0; i
< size
; i
++ {
128 for n
:= 0; n
< size
; n
++ {
129 for x
:= 0; x
<= size
-n
; x
++ { // offset in mem
130 MemclrBytes(mem
[x
: x
+n
])
131 for i
:= 0; i
< x
; i
++ {
133 t
.Fatalf("overwrite prefix mem[%d] = %d", i
, mem
[i
])
136 for i
:= x
; i
< x
+n
; i
++ {
138 t
.Fatalf("failed clear mem[%d] = %d", i
, mem
[i
])
142 for i
:= x
+ n
; i
< size
; i
++ {
144 t
.Fatalf("overwrite suffix mem[%d] = %d", i
, mem
[i
])
151 func bmMemclr(b
*testing
.B
, n
int) {
154 for i
:= 0; i
< b
.N
; i
++ {
158 func BenchmarkMemclr5(b
*testing
.B
) { bmMemclr(b
, 5) }
159 func BenchmarkMemclr16(b
*testing
.B
) { bmMemclr(b
, 16) }
160 func BenchmarkMemclr64(b
*testing
.B
) { bmMemclr(b
, 64) }
161 func BenchmarkMemclr256(b
*testing
.B
) { bmMemclr(b
, 256) }
162 func BenchmarkMemclr4096(b
*testing
.B
) { bmMemclr(b
, 4096) }
163 func BenchmarkMemclr65536(b
*testing
.B
) { bmMemclr(b
, 65536) }
165 func BenchmarkClearFat32(b
*testing
.B
) {
166 for i
:= 0; i
< b
.N
; i
++ {
171 func BenchmarkClearFat64(b
*testing
.B
) {
172 for i
:= 0; i
< b
.N
; i
++ {
177 func BenchmarkClearFat128(b
*testing
.B
) {
178 for i
:= 0; i
< b
.N
; i
++ {
183 func BenchmarkClearFat256(b
*testing
.B
) {
184 for i
:= 0; i
< b
.N
; i
++ {
189 func BenchmarkClearFat512(b
*testing
.B
) {
190 for i
:= 0; i
< b
.N
; i
++ {
195 func BenchmarkClearFat1024(b
*testing
.B
) {
196 for i
:= 0; i
< b
.N
; i
++ {
202 func BenchmarkCopyFat32(b
*testing
.B
) {
204 for i
:= 0; i
< b
.N
; i
++ {
209 func BenchmarkCopyFat64(b
*testing
.B
) {
211 for i
:= 0; i
< b
.N
; i
++ {
216 func BenchmarkCopyFat128(b
*testing
.B
) {
217 var x
[128 / 4]uint32
218 for i
:= 0; i
< b
.N
; i
++ {
223 func BenchmarkCopyFat256(b
*testing
.B
) {
224 var x
[256 / 4]uint32
225 for i
:= 0; i
< b
.N
; i
++ {
230 func BenchmarkCopyFat512(b
*testing
.B
) {
231 var x
[512 / 4]uint32
232 for i
:= 0; i
< b
.N
; i
++ {
237 func BenchmarkCopyFat1024(b
*testing
.B
) {
238 var x
[1024 / 4]uint32
239 for i
:= 0; i
< b
.N
; i
++ {