]>
Commit | Line | Data |
---|---|---|
3e9a9758 | 1 | /* Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
af43a565 AJ |
2 | This file is part of the GNU C Library. |
3 | Contributed by Hartvig Ekner <hartvige@mips.com>, 2002. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
af43a565 AJ |
18 | |
19 | #include <sysdep.h> | |
20 | #include <endian.h> | |
21 | ||
22 | ||
500308e1 | 23 | /* void *memset(void *s, int c, size_t n). */ |
af43a565 AJ |
24 | |
25 | #if __BYTE_ORDER == __BIG_ENDIAN | |
26 | # define SWHI swl /* high part is left in big-endian */ | |
27 | #else | |
28 | # define SWHI swr /* high part is right in little-endian */ | |
29 | #endif | |
30 | ||
31 | ENTRY (memset) | |
32 | .set noreorder | |
33 | ||
34 | slti t1, a2, 8 # Less than 8? | |
3e9a9758 | 35 | bne t1, zero, L(last8) |
af43a565 AJ |
36 | move v0, a0 # Setup exit value before too late |
37 | ||
3e9a9758 | 38 | beq a1, zero, L(ueven) # If zero pattern, no need to extend |
af43a565 AJ |
39 | andi a1, 0xff # Avoid problems with bogus arguments |
40 | sll t0, a1, 8 | |
41 | or a1, t0 | |
42 | sll t0, a1, 16 | |
43 | or a1, t0 # a1 is now pattern in full word | |
44 | ||
2b15a211 AO |
45 | L(ueven): |
46 | subu t0, zero, a0 # Unaligned address? | |
af43a565 | 47 | andi t0, 0x3 |
3e9a9758 | 48 | beq t0, zero, L(chkw) |
af43a565 AJ |
49 | subu a2, t0 |
50 | SWHI a1, 0(a0) # Yes, handle first unaligned part | |
51 | addu a0, t0 # Now both a0 and a2 are updated | |
52 | ||
2b15a211 AO |
53 | L(chkw): |
54 | andi t0, a2, 0x7 # Enough left for one loop iteration? | |
3e9a9758 | 55 | beq t0, a2, L(chkl) |
af43a565 AJ |
56 | subu a3, a2, t0 |
57 | addu a3, a0 # a3 is last loop address +1 | |
58 | move a2, t0 # a2 is now # of bytes left after loop | |
2b15a211 AO |
59 | L(loopw): |
60 | addiu a0, 8 # Handle 2 words pr. iteration | |
af43a565 | 61 | sw a1, -8(a0) |
3e9a9758 | 62 | bne a0, a3, L(loopw) |
af43a565 AJ |
63 | sw a1, -4(a0) |
64 | ||
2b15a211 AO |
65 | L(chkl): |
66 | andi t0, a2, 0x4 # Check if there is at least a full | |
3e9a9758 | 67 | beq t0, zero, L(last8) # word remaining after the loop |
af43a565 AJ |
68 | subu a2, t0 |
69 | sw a1, 0(a0) # Yes... | |
70 | addiu a0, 4 | |
71 | ||
2b15a211 AO |
72 | L(last8): |
73 | blez a2, L(exit) # Handle last 8 bytes (if cnt>0) | |
af43a565 | 74 | addu a3, a2, a0 # a3 is last address +1 |
2b15a211 AO |
75 | L(lst8l): |
76 | addiu a0, 1 | |
3e9a9758 | 77 | bne a0, a3, L(lst8l) |
af43a565 | 78 | sb a1, -1(a0) |
2b15a211 AO |
79 | L(exit): |
80 | j ra # Bye, bye | |
af43a565 AJ |
81 | nop |
82 | ||
83 | .set reorder | |
84 | END (memset) | |
79b7c863 | 85 | libc_hidden_builtin_def (memset) |