1 /*--------------------------------------------------------------------
3 * arch/nios2nommu/lib/string.c
5 * Derived from various works, Alpha, ix86, M68K, Sparc, ...et al
7 * Copyright (C) 2004 Microtronix Datacom Ltd
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * Jan/20/2004 dgt NiosII
21 * Jun/09/2004 dgt Split out memcpy into separate source file
23 ---------------------------------------------------------------------*/
25 #include <linux/types.h>
26 #include <linux/autoconf.h>
28 #include <asm/string.h>
30 #ifdef __HAVE_ARCH_MEMSET
31 void * memset(void * s
,int c
,size_t count
)
35 int destptr
, charcnt
, dwordcnt
, fill8reg
, wrkrega
;
36 __asm__
__volatile__ (
37 // fill8 %3, %5 (c & 0xff)\n\t"
41 " slli %3, %4, 16\n\t"
44 // Word-align %0 (s) if necessary
46 " andi %4, %0, 0x01\n\t"
47 " beq %4, zero, 1f\n\t"
48 " addi %1, %1, -1\n\t"
54 // Dword-align %0 (s) if necessary
56 " andi %4, %0, 0x02\n\t"
57 " beq %4, zero, 2f\n\t"
58 " addi %1, %1, -2\n\t"
63 // %1 and %2 are how many more bytes to set
67 // %2 is how many dwords to set
72 " addi %2, %2, -1\n\t"
73 " bne %2, zero, 3b\n\t"
75 // store residual word and/or byte if necessary
77 " andi %4, %1, 0x02\n\t"
78 " beq %4, zero, 4f\n\t"
82 // store residual byte if necessary
84 " andi %4, %1, 0x01\n\t"
85 " beq %4, zero, 5f\n\t"
89 : "=r" (destptr
), /* %0 Output */
90 "=r" (charcnt
), /* %1 Output */
91 "=r" (dwordcnt
), /* %2 Output */
92 "=r" (fill8reg
), /* %3 Output */
93 "=r" (wrkrega
) /* %4 Output */
95 : "r" (c
& 0xff), /* %5 Input */
96 "0" (s
), /* %0 Input/Output */
97 "1" (count
) /* %1 Input/Output */
99 : "memory" /* clobbered */
111 #ifdef __HAVE_ARCH_MEMMOVE
112 void * memmove(void * d
, const void * s
, size_t count
)
114 unsigned long dst
, src
;
117 dst
= (unsigned long) d
;
118 src
= (unsigned long) s
;
120 if ((count
< 8) || ((dst
^ src
) & 3))
124 *(char*)dst
++=*(char*)src
++;
128 *(short*)dst
=*(short*)src
;
134 *(long*)dst
=*(long*)src
;
142 *(char*)dst
++=*(char*)src
++;
144 dst
= (unsigned long) d
+ count
;
145 src
= (unsigned long) s
+ count
;
147 if ((count
< 8) || ((dst
^ src
) & 3))
154 *(char*)dst
=*(char*)src
;
160 *(short*)dst
=*(short*)src
;
166 *(long*)dst
=*(long*)src
;
173 *(char*)dst
=*(char*)src
;