Add Changelog ...
[glibc.git] / sysdeps / powerpc / powerpc32 / 405 / memset.S
blobe132ce36527fb7fb97cc5c02f8d93313f55dfec3
1 /* Optimized memset implementation for PowerPC476.
2    Copyright (C) 2010 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, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <bp-sym.h>
21 #include <bp-asm.h>
23 /* memset
25        r3:destination address and return address
26        r4:source integer to copy
27        r5:byte count
28        r11:sources integer to copy in all 32 bits of reg
29        r12:temp return address
31        Save return address in r12
32        If destinationn is unaligned and count is greater tha 255 bytes
33        set 0-3 bytes to make destination aligned
34        If count is greater tha 255 bytes and setting zero to memory
35        use dbcz to set memeory when we can
36        otherwsie do the follwoing
37        If 16 or more words to set we use 16 word copy loop.
38        Finaly we set 0-15 extra bytes with string store. */
40 EALIGN (BP_SYM (memset), 5, 0)
41        rlwinm  r11,r4,0,24,31
42        rlwimi  r11,r4,8,16,23
43        rlwimi  r11,r11,16,0,15
44        addi    r12,r3,0
45        cmpwi   r5,0x00FF
46        ble     L(preword8_count_loop)
47        cmpwi   r4,0x00
48        beq     L(use_dcbz)
49        neg     r6,r3
50        clrlwi. r6,r6,30
51        beq     L(preword8_count_loop)
52        addi    r8,0,1
53        mtctr   r6
54        subi    r3,r3,1
56 L(unaligned_bytecopy_loop):
57        stbu    r11,0x1(r3)
58        subf.   r5,r8,r5
59        beq     L(end_memset)
60        bdnz    L(unaligned_bytecopy_loop)
61        addi    r3,r3,1
63 L(preword8_count_loop):
64        srwi.   r6,r5,4
65        beq     L(preword2_count_loop)
66        mtctr   r6
67        addi    r3,r3,-4
68        mr      r8,r11
69        mr      r9,r11
70        mr      r10,r11
72 L(word8_count_loop_no_dcbt):
73        stwu    r8,4(r3)
74        stwu    r9,4(r3)
75        subi    r5,r5,0x10
76        stwu    r10,4(r3)
77        stwu    r11,4(r3)
78        bdnz    L(word8_count_loop_no_dcbt)
79        addi    r3,r3,4
81 L(preword2_count_loop):
82        clrlwi. r7,r5,28
83        beq     L(end_memset)
84        mr      r8,r11
85        mr      r9,r11
86        mr      r10,r11
87        mtxer   r7
88        stswx   r8,0,r3
90 L(end_memset):
91        addi    r3,r12,0
92        blr
94 L(use_dcbz):
95        neg     r6,r3
96        clrlwi. r7,r6,28
97        beq     L(skip_string_loop)
98        mr      r8,r11
99        mr      r9,r11
100        mr      r10,r11
101        subf    r5,r7,r5
102        mtxer   r7
103        stswx   r8,0,r3
104        add     r3,r3,r7
106 L(skip_string_loop):
107        clrlwi  r8,r6,25
108        srwi.   r8,r8,4
109        beq     L(dcbz_pre_loop)
110        mtctr   r8
112 L(word_loop):
113        stw     r11,0(r3)
114        subi    r5,r5,0x10
115        stw     r11,4(r3)
116        stw     r11,8(r3)
117        stw     r11,12(r3)
118        addi    r3,r3,0x10
119        bdnz    L(word_loop)
121 L(dcbz_pre_loop):
122        srwi    r6,r5,7
123        mtctr   r6
124        addi    r7,0,0
126 L(dcbz_loop):
127        dcbz    r3,r7
128        addi    r3,r3,0x80
129        subi    r5,r5,0x80
130        bdnz    L(dcbz_loop)
131        srwi.   r6,r5,4
132        beq     L(postword2_count_loop)
133        mtctr   r6
135 L(postword8_count_loop):
136        stw     r11,0(r3)
137        subi    r5,r5,0x10
138        stw     r11,4(r3)
139        stw     r11,8(r3)
140        stw     r11,12(r3)
141        addi    r3,r3,0x10
142        bdnz    L(postword8_count_loop)
144 L(postword2_count_loop):
145        clrlwi. r7,r5,28
146        beq     L(end_memset)
147        mr      r8,r11
148        mr      r9,r11
149        mr      r10,r11
150        mtxer   r7
151        stswx   r8,0,r3
152        b       L(end_memset)
153 END (BP_SYM (memset))
154 libc_hidden_builtin_def (memset)