8518ccf664777ac76fe0abbd16c186de65a5a7c0
[openwrt.git] / toolchain / uClibc / patches / 0.9.28.2 / 402-avr32-string-ops.patch
1 Subject: [PATCH] AVR32-optimized string operations
2
3 Add hand-optimized AVR32-specific string operations. Some of them
4 need a bit more testing, though.
5
6 ---
7
8 libc/string/avr32/Makefile | 40 +++++++++++
9 libc/string/avr32/bcopy.S | 15 ++++
10 libc/string/avr32/bzero.S | 12 +++
11 libc/string/avr32/memchr.S | 62 +++++++++++++++++
12 libc/string/avr32/memcmp.S | 50 +++++++++++++
13 libc/string/avr32/memcpy.S | 110 ++++++++++++++++++++++++++++++
14 libc/string/avr32/memmove.S | 114 +++++++++++++++++++++++++++++++
15 libc/string/avr32/memset.S | 60 ++++++++++++++++
16 libc/string/avr32/strcat.S | 95 ++++++++++++++++++++++++++
17 libc/string/avr32/strcmp.S | 80 ++++++++++++++++++++++
18 libc/string/avr32/strcpy.S | 63 +++++++++++++++++
19 libc/string/avr32/stringtest.c | 144 ++++++++++++++++++++++++++++++++++++++++
20 libc/string/avr32/strlen.S | 52 ++++++++++++++
21 libc/string/avr32/strncpy.S | 77 +++++++++++++++++++++
22 libc/string/avr32/test_memcpy.c | 66 ++++++++++++++++++
23 15 files changed, 1040 insertions(+)
24
25 Index: uClibc-0.9.28-avr32/libc/string/avr32/bcopy.S
26 ===================================================================
27 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
28 +++ uClibc-0.9.28-avr32/libc/string/avr32/bcopy.S 2006-10-19 15:05:52.000000000 +0200
29 @@ -0,0 +1,15 @@
30 +/*
31 + * Copyright (C) 2004 Atmel Norway
32 + */
33 +
34 + .text
35 + .global bcopy
36 + .type bcopy, @function
37 + .align 1
38 +bcopy:
39 + /* Swap the first two arguments */
40 + eor r11, r12
41 + eor r12, r11
42 + eor r11, r12
43 + rjmp __memmove
44 + .size bcopy, . - bcopy
45 Index: uClibc-0.9.28-avr32/libc/string/avr32/bzero.S
46 ===================================================================
47 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
48 +++ uClibc-0.9.28-avr32/libc/string/avr32/bzero.S 2006-10-19 15:05:52.000000000 +0200
49 @@ -0,0 +1,12 @@
50 +/*
51 + * Copyright (C) 2004 Atmel Norway
52 + */
53 +
54 + .text
55 + .global bzero
56 + .type bzero, @function
57 + .align 1
58 +bzero:
59 + mov r10, r11
60 + mov r11, 0
61 + rjmp __memset
62 Index: uClibc-0.9.28-avr32/libc/string/avr32/Makefile
63 ===================================================================
64 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
65 +++ uClibc-0.9.28-avr32/libc/string/avr32/Makefile 2006-10-19 15:05:52.000000000 +0200
66 @@ -0,0 +1,40 @@
67 +# Makefile for uClibc
68 +#
69 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
70 +#
71 +# This program is free software; you can redistribute it and/or modify it under
72 +# the terms of the GNU Library General Public License as published by the Free
73 +# Software Foundation; either version 2 of the License, or (at your option) any
74 +# later version.
75 +#
76 +# This program is distributed in the hope that it will be useful, but WITHOUT
77 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
78 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
79 +# details.
80 +#
81 +# You should have received a copy of the GNU Library General Public License
82 +# along with this program; if not, write to the Free Software Foundation, Inc.,
83 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
84 +
85 +TOPDIR=../../../
86 +include $(TOPDIR)Rules.mak
87 +
88 +SSRC := bcopy.S bzero.S memcmp.S memcpy.S memmove.S
89 +SSRC += memset.S strcmp.S strlen.S
90 +# memchr.S, strcat.S, strcpy.S, strncpy.S is broken
91 +SOBJS := $(patsubst %.S,%.o, $(SSRC))
92 +OBJS := $(SOBJS)
93 +
94 +OBJ_LIST:= ../../obj.string.$(TARGET_ARCH)
95 +
96 +all: $(OBJ_LIST)
97 +
98 +$(OBJ_LIST): $(OBJS)
99 + echo $(addprefix string/$(TARGET_ARCH)/, $(OBJS)) > $@
100 +
101 +$(SOBJS): %.o: %.S
102 + $(CC) $(ASFLAGS) -c $< -o $@
103 + $(STRIPTOOL) -x -R .note -R .comment $@
104 +
105 +clean:
106 + $(RM) *.[oa] *~ core
107 Index: uClibc-0.9.28-avr32/libc/string/avr32/memchr.S
108 ===================================================================
109 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
110 +++ uClibc-0.9.28-avr32/libc/string/avr32/memchr.S 2006-10-19 15:05:52.000000000 +0200
111 @@ -0,0 +1,62 @@
112 +/*
113 + * Copyright (C) 2004 Atmel Norway
114 + */
115 +
116 +#define str r12
117 +#define chr r11
118 +#define len r10
119 +
120 + .text
121 + .global memchr
122 + .type memchr, @function
123 +memchr:
124 + or chr, chr, chr << 8
125 + or chr, chr, chr << 16
126 +
127 + mov r9, str
128 + andl r9, 3, COH
129 + brne .Lunaligned_str
130 +
131 +1: sub len, 4
132 + brlt 2f
133 + ld.w r8, str++
134 + psub.b r9, r8, r11
135 + tnbz r9
136 + brne 1b
137 +
138 + sub str, 4
139 + bfextu r9, r8, 24, 8
140 + cp.b r9, r11
141 + reteq str
142 + sub str, -1
143 + bfextu r9, r8, 16, 8
144 + cp.b r9, r11
145 + reteq str
146 + sub str, -1
147 + bfextu r9, r8, 8, 8
148 + cp.b r9, r11
149 + reteq str
150 + sub str, -1
151 + retal str
152 +
153 +2: sub len, -4
154 + reteq 0
155 +
156 +3: ld.ub r8, str++
157 + cp.w r8, 0
158 + reteq str
159 + sub len, 1
160 + brne 3b
161 +
162 + retal 0
163 +
164 +.Lunaligned_str:
165 +1: sub len, 1
166 + retlt 0
167 + ld.ub r8, str++
168 + cp.b r8, r11
169 + reteq str
170 + sub r9, 1
171 + brge 1b
172 +
173 + rjmp .Laligned_search
174 Index: uClibc-0.9.28-avr32/libc/string/avr32/memcmp.S
175 ===================================================================
176 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
177 +++ uClibc-0.9.28-avr32/libc/string/avr32/memcmp.S 2006-10-20 10:42:09.000000000 +0200
178 @@ -0,0 +1,50 @@
179 +/*
180 + * Copyright (C) 2004 Atmel Norway.
181 + */
182 +
183 +#define s1 r12
184 +#define s2 r11
185 +#define len r10
186 +
187 + .text
188 + .global memcmp
189 + .type memcmp, @function
190 + .align 1
191 +memcmp:
192 + sub len, 4
193 + brlt .Lless_than_4
194 +
195 +1: ld.w r8, s1++
196 + ld.w r9, s2++
197 + cp.w r8, r9
198 + brne .Lfound_word
199 + sub len, 4
200 + brge 1b
201 +
202 +.Lless_than_4:
203 + sub len, -4
204 + reteq 0
205 +
206 +1: ld.ub r8, s1++
207 + ld.ub r9, s2++
208 + sub r8, r9
209 + retne r8
210 + sub len, 1
211 + brgt 1b
212 +
213 + retal 0
214 +
215 +.Lfound_word:
216 + psub.b r9, r8, r9
217 + bfextu r8, r9, 24, 8
218 + retne r8
219 + bfextu r8, r9, 16, 8
220 + retne r8
221 + bfextu r8, r9, 8, 8
222 + retne r8
223 + retal r9
224 +
225 + .size memcmp, . - memcmp
226 +
227 + .weak bcmp
228 + bcmp = memcmp
229 Index: uClibc-0.9.28-avr32/libc/string/avr32/memcpy.S
230 ===================================================================
231 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
232 +++ uClibc-0.9.28-avr32/libc/string/avr32/memcpy.S 2006-10-19 15:05:52.000000000 +0200
233 @@ -0,0 +1,110 @@
234 +/*
235 + * Copyright (C) 2004 Atmel Norway
236 + */
237 +
238 +/* Don't use r12 as dst since we must return it unmodified */
239 +#define dst r9
240 +#define src r11
241 +#define len r10
242 +
243 + .text
244 + .global memcpy
245 + .type memcpy, @function
246 +
247 + .global __memcpy
248 + .hidden __memcpy
249 + .type __memcpy, @function
250 +memcpy:
251 +__memcpy:
252 + pref src[0]
253 + mov dst, r12
254 +
255 + /* If we have less than 32 bytes, don't do anything fancy */
256 + cp.w len, 32
257 + brge .Lmore_than_31
258 +
259 + sub len, 1
260 + retlt r12
261 +1: ld.ub r8, src++
262 + st.b dst++, r8
263 + sub len, 1
264 + brge 1b
265 + retal r12
266 +
267 +.Lmore_than_31:
268 + pushm r0-r7, lr
269 +
270 + /* Check alignment */
271 + mov r8, src
272 + andl r8, 31, COH
273 + brne .Lunaligned_src
274 + mov r8, dst
275 + andl r8, 3, COH
276 + brne .Lunaligned_dst
277 +
278 +.Laligned_copy:
279 + sub len, 32
280 + brlt .Lless_than_32
281 +
282 +1: /* Copy 32 bytes at a time */
283 + ldm src, r0-r7
284 + sub src, -32
285 + stm dst, r0-r7
286 + sub dst, -32
287 + sub len, 32
288 + brge 1b
289 +
290 +.Lless_than_32:
291 + /* Copy 16 more bytes if possible */
292 + sub len, -16
293 + brlt .Lless_than_16
294 + ldm src, r0-r3
295 + sub src, -16
296 + sub len, 16
297 + stm dst, r0-r3
298 + sub dst, -16
299 +
300 +.Lless_than_16:
301 + /* Do the remaining as byte copies */
302 + neg len
303 + add pc, pc, len << 2
304 + .rept 15
305 + ld.ub r0, src++
306 + st.b dst++, r0
307 + .endr
308 +
309 + popm r0-r7, pc
310 +
311 +.Lunaligned_src:
312 + /* Make src cacheline-aligned. r8 = (src & 31) */
313 + rsub r8, r8, 32
314 + sub len, r8
315 +1: ld.ub r0, src++
316 + st.b dst++, r0
317 + sub r8, 1
318 + brne 1b
319 +
320 + /* If dst is word-aligned, we're ready to go */
321 + pref src[0]
322 + mov r8, 3
323 + tst dst, r8
324 + breq .Laligned_copy
325 +
326 +.Lunaligned_dst:
327 + /* src is aligned, but dst is not. Expect bad performance */
328 + sub len, 4
329 + brlt 2f
330 +1: ld.w r0, src++
331 + st.w dst++, r0
332 + sub len, 4
333 + brge 1b
334 +
335 +2: neg len
336 + add pc, pc, len << 2
337 + .rept 3
338 + ld.ub r0, src++
339 + st.b dst++, r0
340 + .endr
341 +
342 + popm r0-r7, pc
343 + .size memcpy, . - memcpy
344 Index: uClibc-0.9.28-avr32/libc/string/avr32/memmove.S
345 ===================================================================
346 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
347 +++ uClibc-0.9.28-avr32/libc/string/avr32/memmove.S 2006-10-19 15:05:52.000000000 +0200
348 @@ -0,0 +1,114 @@
349 +/*
350 + * Copyright (C) 2004 Atmel Norway
351 + */
352 +
353 +#define dst r12
354 +#define src r11
355 +#define len r10
356 +
357 + .text
358 + .global memmove
359 + .type memmove, @function
360 +
361 + .global __memmove
362 + .hidden __memmove
363 + .type __memmove, @function
364 +memmove:
365 +__memmove:
366 + cp.w src, dst
367 + brge __memcpy
368 +
369 + add dst, len
370 + add src, len
371 + pref src[-1]
372 +
373 + /*
374 + * The rest is basically the same as in memcpy.S except that
375 + * the direction is reversed.
376 + */
377 + cp.w len, 32
378 + brge .Lmore_than_31
379 +
380 + sub len, 1
381 + retlt r12
382 +1: ld.ub r8, --src
383 + st.b --dst, r8
384 + sub len, 1
385 + brge 1b
386 + retal r12
387 +
388 +.Lmore_than_31:
389 + pushm r0-r7, lr
390 +
391 + /* Check alignment */
392 + mov r8, src
393 + andl r8, 31, COH
394 + brne .Lunaligned_src
395 + mov r8, r12
396 + andl r8, 3, COH
397 + brne .Lunaligned_dst
398 +
399 +.Laligned_copy:
400 + sub len, 32
401 + brlt .Lless_than_32
402 +
403 +1: /* Copy 32 bytes at a time */
404 + sub src, 32
405 + ldm src, r0-r7
406 + sub dst, 32
407 + sub len, 32
408 + stm dst, r0-r7
409 + brge 1b
410 +
411 +.Lless_than_32:
412 + /* Copy 16 more bytes if possible */
413 + sub len, -16
414 + brlt .Lless_than_16
415 + sub src, 16
416 + ldm src, r0-r3
417 + sub dst, 16
418 + sub len, 16
419 + stm dst, r0-r3
420 +
421 +.Lless_than_16:
422 + /* Do the remaining as byte copies */
423 + sub len, -16
424 + breq 2f
425 +1: ld.ub r0, --src
426 + st.b --dst, r0
427 + sub len, 1
428 + brne 1b
429 +
430 +2: popm r0-r7, pc
431 +
432 +.Lunaligned_src:
433 + /* Make src cacheline-aligned. r8 = (src & 31) */
434 + sub len, r8
435 +1: ld.ub r0, --src
436 + st.b --dst, r0
437 + sub r8, 1
438 + brne 1b
439 +
440 + /* If dst is word-aligned, we're ready to go */
441 + pref src[-4]
442 + mov r8, 3
443 + tst dst, r8
444 + breq .Laligned_copy
445 +
446 +.Lunaligned_dst:
447 + /* src is aligned, but dst is not. Expect bad performance */
448 + sub len, 4
449 + brlt 2f
450 +1: ld.w r0, --src
451 + st.w --dst, r0
452 + sub len, 4
453 + brge 1b
454 +
455 +2: neg len
456 + add pc, pc, len << 2
457 + .rept 3
458 + ld.ub r0, --src
459 + st.b --dst, r0
460 + .endr
461 +
462 + popm r0-r7, pc
463 Index: uClibc-0.9.28-avr32/libc/string/avr32/memset.S
464 ===================================================================
465 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
466 +++ uClibc-0.9.28-avr32/libc/string/avr32/memset.S 2006-10-20 10:42:15.000000000 +0200
467 @@ -0,0 +1,60 @@
468 +/*
469 + * Copyright (C) 2004 Atmel Norway.
470 + */
471 +
472 +#define s r12
473 +#define c r11
474 +#define n r10
475 +
476 + .text
477 + .global memset
478 + .type memset, @function
479 +
480 + .global __memset
481 + .hidden __memset
482 + .type __memset, @function
483 +
484 + .align 1
485 +memset:
486 +__memset:
487 + cp.w n, 32
488 + mov r9, s
489 + brge .Llarge_memset
490 +
491 + sub n, 1
492 + retlt s
493 +1: st.b s++, c
494 + sub n, 1
495 + brge 1b
496 +
497 + retal r9
498 +
499 +.Llarge_memset:
500 + mov r8, r11
501 + mov r11, 3
502 + bfins r8, r8, 8, 8
503 + bfins r8, r8, 16, 16
504 + tst s, r11
505 + breq 2f
506 +
507 +1: st.b s++, r8
508 + sub n, 1
509 + tst s, r11
510 + brne 1b
511 +
512 +2: mov r11, r9
513 + mov r9, r8
514 + sub n, 8
515 +
516 +3: st.d s++, r8
517 + sub n, 8
518 + brge 3b
519 +
520 + /* If we are done, n == -8 and we'll skip all st.b insns below */
521 + neg n
522 + lsl n, 1
523 + add pc, n
524 + .rept 7
525 + st.b s++, r8
526 + .endr
527 + retal r11
528 Index: uClibc-0.9.28-avr32/libc/string/avr32/strcat.S
529 ===================================================================
530 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
531 +++ uClibc-0.9.28-avr32/libc/string/avr32/strcat.S 2006-10-19 15:05:52.000000000 +0200
532 @@ -0,0 +1,95 @@
533 +/*
534 + * Copyright (C) 2004 Atmel Norway
535 + */
536 +
537 +#define s1 r9
538 +#define s2 r11
539 +
540 + .text
541 + .global strcat
542 + .type strcat, @function
543 + .align 1
544 +strcat:
545 + mov s1, r12
546 +
547 + /* Make sure s1 is word-aligned */
548 + mov r10, s1
549 + andl r10, 3, COH
550 + breq 2f
551 +
552 + add pc, pc, r10 << 3
553 + sub r0, r0, 0 /* 4-byte nop */
554 + ld.ub r8, s1++
555 + sub r8, r8, 0
556 + breq 2f
557 + ld.ub r8, s1++
558 + sub r8, r8, 0
559 + breq 3f
560 + ld.ub r8, s1++
561 + sub r8, r8, 0
562 + breq 4f
563 +
564 + /* Find the end of the first string */
565 +5: ld.w r8, s1++
566 + tnbz r8
567 + brne 5b
568 +
569 + sub s1, 4
570 +
571 + bfextu r10, r8, 24, 8
572 + cp.w r10, 0
573 + breq 1f
574 + sub s1, -1
575 + bfextu r10, r8, 16, 8
576 + cp.w r10, 0
577 + breq 2f
578 + sub s1, -1
579 + bfextu r10, r8, 8, 8
580 + cp.w r10, 0
581 + breq 3f
582 + sub s1, -1
583 + rjmp 4f
584 +
585 + /* Now, append s2 */
586 +1: ld.ub r8, s2++
587 + st.b s1++, r8
588 + cp.w r8, 0
589 + reteq r12
590 +2: ld.ub r8, s2++
591 + st.b s1++, r8
592 + cp.w r8, 0
593 + reteq r12
594 +3: ld.ub r8, s2++
595 + st.b s1++, r8
596 + cp.w r8, 0
597 + reteq r12
598 +4: ld.ub r8, s2++
599 + st.b s1++, r8
600 + cp.w r8, 0
601 + reteq r12
602 +
603 + /* Copy one word at a time */
604 + ld.w r8, s2++
605 + tnbz r8
606 + breq 2f
607 +1: st.w r8, s2++
608 + ld.w r8, s2++
609 + tnbz r8
610 + brne 1b
611 +
612 + /* Copy the remaining bytes */
613 + bfextu r10, r8, 24, 8
614 + st.b s1++, r10
615 + cp.w r10, 0
616 + reteq r12
617 + bfextu r10, r8, 16, 8
618 + st.b s1++, r10
619 + cp.w r10, 0
620 + reteq r12
621 + bfextu r10, r8, 8, 8
622 + st.b s1++, r10
623 + cp.w r10, 0
624 + reteq r12
625 + st.b s1++, r8
626 + retal r12
627 + .size strcat, . - strcat
628 Index: uClibc-0.9.28-avr32/libc/string/avr32/strcmp.S
629 ===================================================================
630 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
631 +++ uClibc-0.9.28-avr32/libc/string/avr32/strcmp.S 2006-10-19 15:05:52.000000000 +0200
632 @@ -0,0 +1,80 @@
633 +/*
634 + * Copyright (C) 2004 Atmel Norway.
635 + */
636 +
637 +#define s1 r12
638 +#define s2 r11
639 +#define len r10
640 +
641 + .text
642 + .global strcmp
643 + .type strcmp, @function
644 + .align 1
645 +strcmp:
646 + mov r8, 3
647 + tst s1, r8
648 + brne .Lunaligned_s1
649 + tst s2, r8
650 + brne .Lunaligned_s2
651 +
652 +1: ld.w r8, s1++
653 + ld.w r9, s2++
654 + cp.w r8, r9
655 + brne 2f
656 + tnbz r8
657 + brne 1b
658 + retal 0
659 +
660 +2: bfextu r12, r8, 24, 8
661 + bfextu r11, r9, 24, 8
662 + sub r12, r11
663 + retne r12
664 + cp.w r11, 0
665 + reteq 0
666 + bfextu r12, r8, 16, 8
667 + bfextu r11, r9, 16, 8
668 + sub r12, r11
669 + retne r12
670 + cp.w r11, 0
671 + reteq 0
672 + bfextu r12, r8, 8, 8
673 + bfextu r11, r9, 8, 8
674 + sub r12, r11
675 + retne r12
676 + cp.w r11, 0
677 + reteq 0
678 + bfextu r12, r8, 0, 8
679 + bfextu r11, r9, 0, 8
680 + sub r12, r11
681 + retal r12
682 +
683 +.Lunaligned_s1:
684 +3: tst s1, r8
685 + breq 4f
686 + ld.ub r10, s1++
687 + ld.ub r9, s2++
688 + sub r10, r9
689 + retne r10
690 + cp.w r9, 0
691 + brne 3b
692 + retal r10
693 +
694 +4: tst s2, r8
695 + breq 1b
696 +
697 +.Lunaligned_s2:
698 + /*
699 + * s1 and s2 can't both be aligned, and unaligned word loads
700 + * can trigger spurious exceptions if we cross a page boundary.
701 + * Do it the slow way...
702 + */
703 +1: ld.ub r8, s1++
704 + ld.ub r9, s2++
705 + sub r8, r9
706 + retne r8
707 + cp.w r9, 0
708 + brne 1b
709 + retal 0
710 +
711 + .weak strcoll
712 + strcoll = strcmp
713 Index: uClibc-0.9.28-avr32/libc/string/avr32/strcpy.S
714 ===================================================================
715 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
716 +++ uClibc-0.9.28-avr32/libc/string/avr32/strcpy.S 2006-10-19 15:05:52.000000000 +0200
717 @@ -0,0 +1,63 @@
718 +/*
719 + * Copyright (C) 2004 Atmel Norway
720 + *
721 + * To reduce the size, this one might simply call strncpy with len = -1.
722 + */
723 +
724 +#define dst r9
725 +#define src r11
726 +
727 + .text
728 + .global strcpy
729 + .type strcpy, @function
730 +strcpy:
731 + mov dst, r12
732 +
733 + pref src[0]
734 +
735 + /*
736 + * Check alignment. If src is aligned but dst isn't, we can't
737 + * do much about it...
738 + */
739 + mov r8, src
740 + andl r8, 3 COH
741 + brne .Lunaligned_src
742 +
743 +.Laligned_copy:
744 +1: ld.w r8, src++
745 + tnbz r8
746 + breq 2f
747 + st.w dst++, r8
748 + rjmp 1b
749 +
750 +2: /*
751 + * Ok, r8 now contains the terminating '\0'. Copy the
752 + * remaining bytes individually.
753 + */
754 + bfextu r10, r8, 24, 8
755 + st.b dst++, r10
756 + cp.w r10, 0
757 + reteq r12
758 + bfextu r10, r8, 16, 8
759 + st.b dst++, r10
760 + cp.w r10, 0
761 + reteq r12
762 + bfextu r10, r8, 8, 8
763 + st.b dst++, r10
764 + cp.w r10, 0
765 + reteq r12
766 + st.b dst++, r8
767 + retal r12
768 +
769 +.Lunaligned_src:
770 + /* Copy bytes until we're aligned */
771 + rsub r8, r8, 4
772 + add pc, pc, r8 << 3
773 + nop
774 + nop
775 + ld.ub r10, src++
776 + st.b dst++, r10
777 + cp.w r10, 0
778 + reteq r12
779 +
780 + rjmp .Laligned_copy
781 Index: uClibc-0.9.28-avr32/libc/string/avr32/stringtest.c
782 ===================================================================
783 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
784 +++ uClibc-0.9.28-avr32/libc/string/avr32/stringtest.c 2006-10-19 15:05:52.000000000 +0200
785 @@ -0,0 +1,144 @@
786 +
787 +#include <stdio.h>
788 +#include <string.h>
789 +#include <time.h>
790 +#include <sys/mman.h>
791 +
792 +#define BUF_SIZE (8 * 1024)
793 +
794 +static char *buf1;
795 +static char *buf1_ref;
796 +static char *buf2;
797 +
798 +extern void *optimized_memcpy(void *dest, void *src, size_t len);
799 +extern void *optimized_memmove(void *dest, void *src, size_t len);
800 +extern char *optimized_strcpy(char *dest, char *src);
801 +extern char *optimized_strncpy(char *dest, char *src, size_t len);
802 +
803 +void dump_mismatch(char *buf, char *ref, size_t len)
804 +{
805 + int i, j;
806 +
807 + for (i = 0; i < len; i += 16) {
808 + if (memcmp(buf + i, ref + i, 16) == 0)
809 + continue;
810 +
811 + printf("%4x buf:", i);
812 + for (j = i; j < (i + 16); j++)
813 + printf(" %02x", buf[j]);
814 + printf("\n ref:");
815 + for (j = i; j < (i + 16); j++)
816 + printf(" %02x", ref[j]);
817 + printf("\n");
818 + }
819 +}
820 +
821 +static void test_memcpy(int src_offset, int dst_offset, int len)
822 +{
823 + clock_t start, old, new;
824 + int i;
825 +
826 + memset(buf1, 0x55, BUF_SIZE);
827 + memset(buf1_ref, 0x55, BUF_SIZE);
828 + memset(buf2, 0xaa, BUF_SIZE);
829 +
830 + printf("Testing memcpy with offsets %d => %d and len %d...",
831 + src_offset, dst_offset, len);
832 +
833 + start = clock();
834 + for (i = 0; i < 8192; i++)
835 + optimized_memcpy(buf1 + dst_offset, buf2 + src_offset, len);
836 + new = clock() - start;
837 + start = clock();
838 + for ( i = 0; i < 8192; i++)
839 + memcpy(buf1_ref + dst_offset, buf2 + src_offset, len);
840 + old = clock() - start;
841 +
842 + if (memcmp(buf1, buf1_ref, BUF_SIZE) == 0)
843 + printf("OK\n");
844 + else {
845 + printf("FAILED\n");
846 + dump_mismatch(buf1, buf1_ref, BUF_SIZE);
847 + }
848 + printf("CPU time used: %d vs. %d\n", new, old);
849 +}
850 +
851 +static void test_memmove(int src_offset, int dst_offset, int len)
852 +{
853 + clock_t start, old, new;
854 +
855 + memset(buf1, 0x55, BUF_SIZE);
856 + memset(buf1_ref, 0x55, BUF_SIZE);
857 + memset(buf2, 0xaa, BUF_SIZE);
858 +
859 + printf("Testing memmove with offsets %d => %d and len %d...",
860 + src_offset, dst_offset, len);
861 +
862 + start = clock();
863 + optimized_memmove(buf1 + dst_offset, buf2 + src_offset, len);
864 + new = clock() - start;
865 + start = clock();
866 + memmove(buf1_ref + dst_offset, buf2 + src_offset, len);
867 + old = clock() - start;
868 +
869 + if (memcmp(buf1, buf1_ref, BUF_SIZE) == 0)
870 + printf("OK\n");
871 + else {
872 + printf("FAILED\n");
873 + dump_mismatch(buf1, buf1_ref, BUF_SIZE);
874 + }
875 + printf("CPU time used: %d vs. %d\n", new, old);
876 +}
877 +
878 +int main(int argc, char *argv[])
879 +{
880 + buf2 = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
881 + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
882 + if (buf2 == MAP_FAILED) {
883 + perror("Failed to allocate memory for buf2");
884 + return 1;
885 + }
886 + buf1 = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
887 + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
888 + if (buf1 == MAP_FAILED) {
889 + perror("Failed to allocate memory for buf1");
890 + return 1;
891 + }
892 + buf1_ref = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
893 + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
894 + if (buf1_ref == MAP_FAILED) {
895 + perror("Failed to allocate memory for buf1_ref");
896 + return 1;
897 + }
898 + printf("\n === MEMCPY ===\n\n");
899 +
900 + test_memcpy(0, 0, BUF_SIZE - 32);
901 + test_memcpy(0, 0, 1);
902 + test_memcpy(0, 0, 31);
903 + test_memcpy(0, 0, 32);
904 + test_memcpy(0, 0, 127);
905 + test_memcpy(0, 0, 128);
906 + test_memcpy(4, 4, BUF_SIZE - 32 - 4);
907 + test_memcpy(1, 1, BUF_SIZE - 32 - 1);
908 + test_memcpy(1, 1, 126);
909 + test_memcpy(0, 3, 128);
910 + test_memcpy(1, 4, 128);
911 + test_memcpy(0, 0, 0);
912 +
913 + printf("\n === MEMMOVE ===\n\n");
914 +
915 + test_memmove(0, 0, BUF_SIZE - 32);
916 + test_memmove(0, 0, 1);
917 + test_memmove(0, 0, 31);
918 + test_memmove(0, 0, 32);
919 + test_memmove(0, 0, BUF_SIZE - 33);
920 + test_memmove(0, 0, 128);
921 + test_memmove(4, 4, BUF_SIZE - 32 - 4);
922 + test_memmove(1, 1, BUF_SIZE - 32 - 1);
923 + test_memmove(1, 1, BUF_SIZE - 130);
924 + test_memmove(0, 3, BUF_SIZE - 128);
925 + test_memmove(1, 4, BUF_SIZE - 128);
926 + test_memmove(0, 0, 0);
927 +
928 + return 0;
929 +}
930 Index: uClibc-0.9.28-avr32/libc/string/avr32/strlen.S
931 ===================================================================
932 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
933 +++ uClibc-0.9.28-avr32/libc/string/avr32/strlen.S 2006-10-19 15:05:52.000000000 +0200
934 @@ -0,0 +1,52 @@
935 +/*
936 + * Copyright (C) 2004 Atmel Norway
937 + */
938 +
939 +#define str r12
940 +
941 + .text
942 + .global strlen
943 + .type strlen, @function
944 +strlen:
945 + mov r11, r12
946 +
947 + mov r9, str
948 + andl r9, 3, COH
949 + brne .Lunaligned_str
950 +
951 +1: ld.w r8, str++
952 + tnbz r8
953 + brne 1b
954 +
955 + sub r12, r11
956 + bfextu r9, r8, 24, 8
957 + cp.w r9, 0
958 + subeq r12, 4
959 + reteq r12
960 + bfextu r9, r8, 16, 8
961 + cp.w r9, 0
962 + subeq r12, 3
963 + reteq r12
964 + bfextu r9, r8, 8, 8
965 + cp.w r9, 0
966 + subeq r12, 2
967 + reteq r12
968 + sub r12, 1
969 + retal r12
970 +
971 +.Lunaligned_str:
972 + add pc, pc, r9 << 3
973 + sub r0, r0, 0 /* 4-byte nop */
974 + ld.ub r8, str++
975 + sub r8, r8, 0
976 + breq 1f
977 + ld.ub r8, str++
978 + sub r8, r8, 0
979 + breq 1f
980 + ld.ub r8, str++
981 + sub r8, r8, 0
982 + brne 1b
983 +
984 +1: sub r12, 1
985 + sub r12, r11
986 + retal r12
987 Index: uClibc-0.9.28-avr32/libc/string/avr32/strncpy.S
988 ===================================================================
989 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
990 +++ uClibc-0.9.28-avr32/libc/string/avr32/strncpy.S 2006-10-19 15:05:52.000000000 +0200
991 @@ -0,0 +1,77 @@
992 +/*
993 + * Copyright (C) 2004 Atmel Norway
994 + */
995 +
996 +#define dst r9
997 +#define src r11
998 +
999 + .text
1000 + .global strcpy
1001 + .type strncpy, @function
1002 +strncpy:
1003 + mov dst, r12
1004 +
1005 + pref src[0]
1006 + mov dst, r12
1007 +
1008 + /*
1009 + * Check alignment. If src is aligned but dst isn't, we can't
1010 + * do much about it...
1011 + */
1012 + mov r8, src
1013 + andl r8, 3 COH
1014 + brne .Lunaligned_src
1015 +
1016 +.Laligned_copy:
1017 + sub r10, 4
1018 + brlt 3f
1019 +1: ld.w r8, src++
1020 + tnbz r8
1021 + breq 2f
1022 + st.w dst++, r8
1023 + sub r10, 4
1024 + brne 1b
1025 +
1026 +3: sub r10, -4
1027 + reteq r12
1028 +
1029 + /* This is safe as long as src is word-aligned and r10 > 0 */
1030 + ld.w r8, src++
1031 +
1032 +2: /*
1033 + * Ok, r8 now contains the terminating '\0'. Copy the
1034 + * remaining bytes individually.
1035 + */
1036 + bfextu r11, r8, 24, 8
1037 + st.b dst++, r11
1038 + cp.w r11, 0
1039 + reteq r12
1040 + sub r10, 1
1041 + reteq r12
1042 + bfextu r11, r8, 16, 8
1043 + st.b dst++, r11
1044 + cp.w r11, 0
1045 + reteq r12
1046 + sub r10, 1
1047 + reteq r12
1048 + bfextu r11, r8, 8, 8
1049 + st.b dst++, r11
1050 + cp.w r11, 0
1051 + reteq r12
1052 + sub r10, 1
1053 + reteq r12
1054 + st.b dst++, r8
1055 + retal r12
1056 +
1057 +.Lunaligned_src:
1058 + /* Copy bytes until we're aligned */
1059 + min r8, r8, r10
1060 + sub r10, r8
1061 + sub r8, 1
1062 + retlt r12
1063 +1: ld.ub r10, src++
1064 + st.b dst++, r10
1065 + sub r8, 1
1066 + brge 1b
1067 +
1068 + rjmp .Laligned_copy
1069 Index: uClibc-0.9.28-avr32/libc/string/avr32/test_memcpy.c
1070 ===================================================================
1071 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1072 +++ uClibc-0.9.28-avr32/libc/string/avr32/test_memcpy.c 2006-10-19 15:05:52.000000000 +0200
1073 @@ -0,0 +1,66 @@
1074 +
1075 +#include <stdio.h>
1076 +#include <string.h>
1077 +
1078 +#define BUF_SIZE 32768
1079 +
1080 +static char buf1[BUF_SIZE] __attribute__((aligned(32)));
1081 +static char buf1_ref[BUF_SIZE] __attribute__((aligned(32)));
1082 +static char buf2[BUF_SIZE] __attribute__((aligned(32)));
1083 +
1084 +extern void *new_memcpy(void *dest, void *src, size_t len);
1085 +
1086 +void dump_mismatch(char *buf, char *ref, size_t len)
1087 +{
1088 + int i, j;
1089 +
1090 + for (i = 0; i < len; i += 16) {
1091 + if (memcmp(buf + i, ref + i, 16) == 0)
1092 + continue;
1093 +
1094 + printf("% 4x buf:", i);
1095 + for (j = i; j < (i + 16); j++)
1096 + printf(" %02x", buf[j]);
1097 + printf("\n ref:");
1098 + for (j = i; j < (i + 16); j++)
1099 + printf(" %02x", ref[j]);
1100 + printf("\n");
1101 + }
1102 +}
1103 +
1104 +void test(int src_offset, int dst_offset, int len)
1105 +{
1106 + memset(buf1, 0x55, sizeof(buf1));
1107 + memset(buf1_ref, 0x55, sizeof(buf1_ref));
1108 + memset(buf2, 0xaa, sizeof(buf2));
1109 +
1110 + printf("Testing with offsets %d => %d and len %d...",
1111 + src_offset, dst_offset, len);
1112 +
1113 + new_memcpy(buf1 + dst_offset, buf2 + src_offset, len);
1114 + memcpy(buf1_ref + dst_offset, buf2 + src_offset, len);
1115 +
1116 + if (memcmp(buf1, buf1_ref, sizeof(buf1)) == 0)
1117 + printf("OK\n");
1118 + else {
1119 + printf("FAILED\n");
1120 + dump_mismatch(buf1, buf1_ref, sizeof(buf1));
1121 + }
1122 +}
1123 +
1124 +int main(int argc, char *argv[])
1125 +{
1126 + test(0, 0, BUF_SIZE);
1127 + test(0, 0, 1);
1128 + test(0, 0, 31);
1129 + test(0, 0, 32);
1130 + test(0, 0, 127);
1131 + test(0, 0, 128);
1132 + test(4, 4, BUF_SIZE - 4);
1133 + test(1, 1, BUF_SIZE - 1);
1134 + test(1, 1, 126);
1135 + test(0, 3, 128);
1136 + test(1, 4, 128);
1137 +
1138 + return 0;
1139 +}
This page took 0.081295 seconds and 3 git commands to generate.