Text file
src/runtime/memclr_386.s
Documentation: runtime
1// Copyright 2014 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//go:build !plan9
6
7#include "go_asm.h"
8#include "textflag.h"
9
10// See memclrNoHeapPointers Go doc for important implementation constraints.
11
12// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
13TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-8
14 MOVL ptr+0(FP), DI
15 MOVL n+4(FP), BX
16 XORL AX, AX
17
18 // MOVOU seems always faster than REP STOSL.
19tail:
20 // BSR+branch table make almost all memmove/memclr benchmarks worse. Not worth doing.
21 TESTL BX, BX
22 JEQ _0
23 CMPL BX, $2
24 JBE _1or2
25 CMPL BX, $4
26 JB _3
27 JE _4
28 CMPL BX, $8
29 JBE _5through8
30 CMPL BX, $16
31 JBE _9through16
32#ifdef GO386_softfloat
33 JMP nosse2
34#endif
35 PXOR X0, X0
36 CMPL BX, $32
37 JBE _17through32
38 CMPL BX, $64
39 JBE _33through64
40 CMPL BX, $128
41 JBE _65through128
42 CMPL BX, $256
43 JBE _129through256
44
45loop:
46 MOVOU X0, 0(DI)
47 MOVOU X0, 16(DI)
48 MOVOU X0, 32(DI)
49 MOVOU X0, 48(DI)
50 MOVOU X0, 64(DI)
51 MOVOU X0, 80(DI)
52 MOVOU X0, 96(DI)
53 MOVOU X0, 112(DI)
54 MOVOU X0, 128(DI)
55 MOVOU X0, 144(DI)
56 MOVOU X0, 160(DI)
57 MOVOU X0, 176(DI)
58 MOVOU X0, 192(DI)
59 MOVOU X0, 208(DI)
60 MOVOU X0, 224(DI)
61 MOVOU X0, 240(DI)
62 SUBL $256, BX
63 ADDL $256, DI
64 CMPL BX, $256
65 JAE loop
66 JMP tail
67
68_1or2:
69 MOVB AX, (DI)
70 MOVB AX, -1(DI)(BX*1)
71 RET
72_0:
73 RET
74_3:
75 MOVW AX, (DI)
76 MOVB AX, 2(DI)
77 RET
78_4:
79 // We need a separate case for 4 to make sure we clear pointers atomically.
80 MOVL AX, (DI)
81 RET
82_5through8:
83 MOVL AX, (DI)
84 MOVL AX, -4(DI)(BX*1)
85 RET
86_9through16:
87 MOVL AX, (DI)
88 MOVL AX, 4(DI)
89 MOVL AX, -8(DI)(BX*1)
90 MOVL AX, -4(DI)(BX*1)
91 RET
92_17through32:
93 MOVOU X0, (DI)
94 MOVOU X0, -16(DI)(BX*1)
95 RET
96_33through64:
97 MOVOU X0, (DI)
98 MOVOU X0, 16(DI)
99 MOVOU X0, -32(DI)(BX*1)
100 MOVOU X0, -16(DI)(BX*1)
101 RET
102_65through128:
103 MOVOU X0, (DI)
104 MOVOU X0, 16(DI)
105 MOVOU X0, 32(DI)
106 MOVOU X0, 48(DI)
107 MOVOU X0, -64(DI)(BX*1)
108 MOVOU X0, -48(DI)(BX*1)
109 MOVOU X0, -32(DI)(BX*1)
110 MOVOU X0, -16(DI)(BX*1)
111 RET
112_129through256:
113 MOVOU X0, (DI)
114 MOVOU X0, 16(DI)
115 MOVOU X0, 32(DI)
116 MOVOU X0, 48(DI)
117 MOVOU X0, 64(DI)
118 MOVOU X0, 80(DI)
119 MOVOU X0, 96(DI)
120 MOVOU X0, 112(DI)
121 MOVOU X0, -128(DI)(BX*1)
122 MOVOU X0, -112(DI)(BX*1)
123 MOVOU X0, -96(DI)(BX*1)
124 MOVOU X0, -80(DI)(BX*1)
125 MOVOU X0, -64(DI)(BX*1)
126 MOVOU X0, -48(DI)(BX*1)
127 MOVOU X0, -32(DI)(BX*1)
128 MOVOU X0, -16(DI)(BX*1)
129 RET
130nosse2:
131 MOVL BX, CX
132 SHRL $2, CX
133 REP
134 STOSL
135 ANDL $3, BX
136 JNE tail
137 RET
View as plain text