1 /* Optimized memset implementation for PowerPC.
2 Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
27 The memset is done in three sizes: byte (8 bits), word (32 bits),
28 cache line (256 bits). There is a special case for setting cache lines
29 to 0, to take advantage of the dcbz instruction. */
31 EALIGN (BP_SYM (memset), 5, 1)
34 #define rRTN r3 /* initial value of 1st argument */
35 #if __BOUNDED_POINTERS__
36 # define rMEMP0 r4 /* original value of 1st arg */
37 # define rCHR r5 /* char to set in each byte */
38 # define rLEN r6 /* length of region to set */
39 # define rMEMP r10 /* address at which we are storing */
41 # define rMEMP0 r3 /* original value of 1st arg */
42 # define rCHR r4 /* char to set in each byte */
43 # define rLEN r5 /* length of region to set */
44 # define rMEMP r6 /* address at which we are storing */
46 #define rALIGN r7 /* number of bytes we are setting now (when aligning) */
49 #define rPOS32 r7 /* constant +32 for clearing with dcbz */
50 #define rNEG64 r8 /* constant -64 for clearing with dcbz */
51 #define rNEG32 r9 /* constant -32 for clearing with dcbz */
53 #if __BOUNDED_POINTERS__
55 CHECK_BOUNDS_BOTH_WIDE (rMEMP0, rTMP, rTMP2, rLEN)
57 STORE_RETURN_VALUE (rMEMP0)
58 STORE_RETURN_BOUNDS (rTMP, rTMP2)
62 /* take care of case for size <= 4 */
64 andi. rALIGN, rMEMP0, 3
67 /* align to word boundary */
69 rlwimi rCHR, rCHR, 8, 16, 23
70 beq+ L(aligned) /* 8th instruction from .align */
72 subfic rALIGN, rALIGN, 4
73 add rMEMP, rMEMP, rALIGN
74 sub rLEN, rLEN, rALIGN
78 L(g0): sth rCHR, -2(rMEMP) /* 16th instruction from .align */
79 /* take care of case for size < 31 */
82 rlwimi rCHR, rCHR, 16, 0, 15
84 /* align to cache line boundary... */
85 andi. rALIGN, rMEMP, 0x1C
86 subfic rALIGN, rALIGN, 0x20
89 add rMEMP, rMEMP, rALIGN
90 sub rLEN, rLEN, rALIGN
91 cmplwi cr1, rALIGN, 0x10
97 stw rCHR, -4(rMEMP2) /* 32nd instruction from .align */
100 stwu rCHR, -16(rMEMP2)
101 L(a2): bf 29, L(caligned)
103 /* now aligned to a cache line. */
106 clrrwi. rALIGN, rLEN, 5
107 mtcrf 0x01, rLEN /* 40th instruction from .align */
108 beq cr1, L(zloopstart) /* special case for clearing memory using dcbz */
111 beq L(medium) /* we may not actually get to do a full line */
112 clrlwi. rLEN, rLEN, 27
113 add rMEMP, rMEMP, rALIGN
115 bdz L(cloopdone) /* 48th instruction from .align */
117 L(c3): dcbz rNEG64, rMEMP
122 nop /* let 601 fetch last 4 instructions of loop */
124 stw rCHR, -24(rMEMP) /* 56th instruction from .align */
125 nop /* let 601 fetch first 8 instructions of loop */
127 stwu rCHR, -32(rMEMP)
133 stw rCHR, -16(rMEMP) /* 64th instruction from .align */
138 stwu rCHR, -32(rMEMP)
140 add rMEMP, rMEMP, rALIGN
141 b L(medium_tail2) /* 72nd instruction from .align */
145 /* Clear lines of memory in 128-byte chunks. */
147 clrlwi rLEN, rLEN, 27
149 srwi. rTMP, rALIGN, 7
153 cmplwi cr1, rLEN, 16 /* 8 */
156 addi rMEMP, rMEMP, 0x20
157 L(z0): li rNEG32, -0x20
161 addi rMEMP, rMEMP, 0x40 /* 16 */
162 L(z1): cmplwi cr5, rLEN, 0
167 addi rMEMP, rMEMP, 0x80
176 /* Memset of 4 bytes or less. */
191 /* Memset of 0-31 bytes. */
196 add rMEMP, rMEMP, rLEN
198 bt- 31, L(medium_31t)
199 bt- 30, L(medium_30t)
201 bt- 29, L(medium_29t)
203 bge- cr1, L(medium_27t)
205 stw rCHR, -4(rMEMP) /* 8th instruction from .align */
211 bf- 30, L(medium_30f)
214 bf- 29, L(medium_29f)
217 blt- cr1, L(medium_27f) /* 16th instruction from .align */
222 stwu rCHR, -16(rMEMP)
229 END (BP_SYM (memset))