summaryrefslogtreecommitdiff
path: root/packages/uclibc/uclibc-0.9.28/avr32/avr32-string-ops.patch
blob: 8518ccf664777ac76fe0abbd16c186de65a5a7c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
Subject: [PATCH] AVR32-optimized string operations

Add hand-optimized AVR32-specific string operations. Some of them
need a bit more testing, though.

---

 libc/string/avr32/Makefile      |   40 +++++++++++
 libc/string/avr32/bcopy.S       |   15 ++++
 libc/string/avr32/bzero.S       |   12 +++
 libc/string/avr32/memchr.S      |   62 +++++++++++++++++
 libc/string/avr32/memcmp.S      |   50 +++++++++++++
 libc/string/avr32/memcpy.S      |  110 ++++++++++++++++++++++++++++++
 libc/string/avr32/memmove.S     |  114 +++++++++++++++++++++++++++++++
 libc/string/avr32/memset.S      |   60 ++++++++++++++++
 libc/string/avr32/strcat.S      |   95 ++++++++++++++++++++++++++
 libc/string/avr32/strcmp.S      |   80 ++++++++++++++++++++++
 libc/string/avr32/strcpy.S      |   63 +++++++++++++++++
 libc/string/avr32/stringtest.c  |  144 ++++++++++++++++++++++++++++++++++++++++
 libc/string/avr32/strlen.S      |   52 ++++++++++++++
 libc/string/avr32/strncpy.S     |   77 +++++++++++++++++++++
 libc/string/avr32/test_memcpy.c |   66 ++++++++++++++++++
 15 files changed, 1040 insertions(+)

Index: uClibc-0.9.28-avr32/libc/string/avr32/bcopy.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/bcopy.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+	.text
+	.global bcopy
+	.type	bcopy, @function
+	.align	1
+bcopy:
+	/* Swap the first two arguments */
+	eor	r11, r12
+	eor	r12, r11
+	eor	r11, r12
+	rjmp	__memmove
+	.size	bcopy, . - bcopy
Index: uClibc-0.9.28-avr32/libc/string/avr32/bzero.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/bzero.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+	.text
+	.global bzero
+	.type	bzero, @function
+	.align	1
+bzero:
+	mov	r10, r11
+	mov	r11, 0
+	rjmp	__memset
Index: uClibc-0.9.28-avr32/libc/string/avr32/Makefile
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/Makefile	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,40 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Library General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+TOPDIR=../../../
+include $(TOPDIR)Rules.mak
+
+SSRC	:= bcopy.S bzero.S memcmp.S memcpy.S memmove.S
+SSRC	+= memset.S strcmp.S strlen.S
+# memchr.S, strcat.S, strcpy.S, strncpy.S is broken
+SOBJS	:= $(patsubst %.S,%.o, $(SSRC))
+OBJS	:= $(SOBJS)
+
+OBJ_LIST:= ../../obj.string.$(TARGET_ARCH)
+
+all: $(OBJ_LIST)
+
+$(OBJ_LIST): $(OBJS)
+	echo $(addprefix string/$(TARGET_ARCH)/, $(OBJS)) > $@
+
+$(SOBJS): %.o: %.S
+	$(CC) $(ASFLAGS) -c $< -o $@
+	$(STRIPTOOL) -x -R .note -R .comment $@
+
+clean:
+	$(RM) *.[oa] *~ core
Index: uClibc-0.9.28-avr32/libc/string/avr32/memchr.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/memchr.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+#define str r12
+#define chr r11
+#define len r10
+
+	.text
+	.global memchr
+	.type	memchr, @function
+memchr:
+	or	chr, chr, chr << 8
+	or	chr, chr, chr << 16
+
+	mov	r9, str
+	andl	r9, 3, COH
+	brne	.Lunaligned_str
+
+1:	sub	len, 4
+	brlt	2f
+	ld.w	r8, str++
+	psub.b	r9, r8, r11
+	tnbz	r9
+	brne	1b
+
+	sub	str, 4
+	bfextu	r9, r8, 24, 8
+	cp.b	r9, r11
+	reteq	str
+	sub	str, -1
+	bfextu	r9, r8, 16, 8
+	cp.b	r9, r11
+	reteq	str
+	sub	str, -1
+	bfextu	r9, r8, 8, 8
+	cp.b	r9, r11
+	reteq	str
+	sub	str, -1
+	retal	str
+
+2:	sub	len, -4
+	reteq	0
+
+3:	ld.ub	r8, str++
+	cp.w	r8, 0
+	reteq	str
+	sub	len, 1
+	brne	3b
+
+	retal	0
+
+.Lunaligned_str:
+1:	sub	len, 1
+	retlt	0
+	ld.ub	r8, str++
+	cp.b	r8, r11
+	reteq	str
+	sub	r9, 1
+	brge	1b
+
+	rjmp	.Laligned_search
Index: uClibc-0.9.28-avr32/libc/string/avr32/memcmp.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/memcmp.S	2006-10-20 10:42:09.000000000 +0200
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2004 Atmel Norway.
+ */
+
+#define s1 r12
+#define s2 r11
+#define len r10
+
+	.text
+	.global memcmp
+	.type	memcmp, @function
+	.align	1
+memcmp:
+	sub	len, 4
+	brlt	.Lless_than_4
+
+1:	ld.w	r8, s1++
+	ld.w	r9, s2++
+	cp.w	r8, r9
+	brne	.Lfound_word
+	sub	len, 4
+	brge	1b
+
+.Lless_than_4:
+	sub	len, -4
+	reteq	0
+
+1:	ld.ub	r8, s1++
+	ld.ub	r9, s2++
+	sub	r8, r9
+	retne	r8
+	sub	len, 1
+	brgt	1b
+
+	retal	0
+
+.Lfound_word:
+	psub.b	r9, r8, r9
+	bfextu	r8, r9, 24, 8
+	retne	r8
+	bfextu	r8, r9, 16, 8
+	retne	r8
+	bfextu	r8, r9, 8, 8
+	retne	r8
+	retal	r9
+
+	.size	memcmp, . - memcmp
+
+	.weak	bcmp
+	bcmp = memcmp
Index: uClibc-0.9.28-avr32/libc/string/avr32/memcpy.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/memcpy.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+/* Don't use r12 as dst since we must return it unmodified */
+#define dst r9
+#define src r11
+#define len r10
+
+	.text
+	.global	memcpy
+	.type	memcpy, @function
+
+	.global	__memcpy
+	.hidden	__memcpy
+	.type	__memcpy, @function
+memcpy:
+__memcpy:
+	pref	src[0]
+	mov	dst, r12
+
+	/* If we have less than 32 bytes, don't do anything fancy */
+	cp.w	len, 32
+	brge	.Lmore_than_31
+
+	sub	len, 1
+	retlt	r12
+1:	ld.ub	r8, src++
+	st.b	dst++, r8
+	sub	len, 1
+	brge	1b
+	retal	r12
+
+.Lmore_than_31:
+	pushm	r0-r7, lr
+
+	/* Check alignment */
+	mov	r8, src
+	andl	r8, 31, COH
+	brne	.Lunaligned_src
+	mov	r8, dst
+	andl	r8, 3, COH
+	brne	.Lunaligned_dst
+
+.Laligned_copy:
+	sub	len, 32
+	brlt	.Lless_than_32
+
+1:	/* Copy 32 bytes at a time */
+	ldm	src, r0-r7
+	sub	src, -32
+	stm	dst, r0-r7
+	sub	dst, -32
+	sub	len, 32
+	brge	1b
+
+.Lless_than_32:
+	/* Copy 16 more bytes if possible */
+	sub	len, -16
+	brlt	.Lless_than_16
+	ldm	src, r0-r3
+	sub	src, -16
+	sub	len, 16
+	stm	dst, r0-r3
+	sub	dst, -16
+
+.Lless_than_16:
+	/* Do the remaining as byte copies */
+	neg	len
+	add	pc, pc, len << 2
+	.rept	15
+	ld.ub	r0, src++
+	st.b	dst++, r0
+	.endr
+
+	popm	r0-r7, pc
+
+.Lunaligned_src:
+	/* Make src cacheline-aligned. r8 = (src & 31) */
+	rsub	r8, r8, 32
+	sub	len, r8
+1:	ld.ub	r0, src++
+	st.b	dst++, r0
+	sub	r8, 1
+	brne	1b
+
+	/* If dst is word-aligned, we're ready to go */
+	pref	src[0]
+	mov	r8, 3
+	tst	dst, r8
+	breq	.Laligned_copy
+
+.Lunaligned_dst:
+	/* src is aligned, but dst is not. Expect bad performance */
+	sub	len, 4
+	brlt	2f
+1:	ld.w	r0, src++
+	st.w	dst++, r0
+	sub	len, 4
+	brge	1b
+
+2:	neg	len
+	add	pc, pc, len << 2
+	.rept	3
+	ld.ub	r0, src++
+	st.b	dst++, r0
+	.endr
+
+	popm	r0-r7, pc
+	.size	memcpy, . - memcpy
Index: uClibc-0.9.28-avr32/libc/string/avr32/memmove.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/memmove.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+#define dst r12
+#define src r11
+#define len r10
+
+	.text
+	.global memmove
+	.type	memmove, @function
+
+	.global	__memmove
+	.hidden	__memmove
+	.type	__memmove, @function
+memmove:
+__memmove:
+	cp.w	src, dst
+	brge	__memcpy
+
+	add	dst, len
+	add	src, len
+	pref	src[-1]
+
+	/*
+	 * The rest is basically the same as in memcpy.S except that
+	 * the direction is reversed.
+	 */
+	cp.w	len, 32
+	brge	.Lmore_than_31
+
+	sub	len, 1
+	retlt	r12
+1:	ld.ub	r8, --src
+	st.b	--dst, r8
+	sub	len, 1
+	brge	1b
+	retal	r12
+
+.Lmore_than_31:
+	pushm	r0-r7, lr
+
+	/* Check alignment */
+	mov	r8, src
+	andl	r8, 31, COH
+	brne	.Lunaligned_src
+	mov	r8, r12
+	andl	r8, 3, COH
+	brne	.Lunaligned_dst
+
+.Laligned_copy:
+	sub	len, 32
+	brlt	.Lless_than_32
+
+1:	/* Copy 32 bytes at a time */
+	sub	src, 32
+	ldm	src, r0-r7
+	sub	dst, 32
+	sub	len, 32
+	stm	dst, r0-r7
+	brge	1b
+
+.Lless_than_32:
+	/* Copy 16 more bytes if possible */
+	sub	len, -16
+	brlt	.Lless_than_16
+	sub	src, 16
+	ldm	src, r0-r3
+	sub	dst, 16
+	sub	len, 16
+	stm	dst, r0-r3
+
+.Lless_than_16:
+	/* Do the remaining as byte copies */
+	sub	len, -16
+	breq	2f
+1:	ld.ub	r0, --src
+	st.b	--dst, r0
+	sub	len, 1
+	brne	1b
+
+2:	popm	r0-r7, pc
+
+.Lunaligned_src:
+	/* Make src cacheline-aligned. r8 = (src & 31) */
+	sub	len, r8
+1:	ld.ub	r0, --src
+	st.b	--dst, r0
+	sub	r8, 1
+	brne	1b
+
+	/* If dst is word-aligned, we're ready to go */
+	pref	src[-4]
+	mov	r8, 3
+	tst	dst, r8
+	breq	.Laligned_copy
+
+.Lunaligned_dst:
+	/* src is aligned, but dst is not. Expect bad performance */
+	sub	len, 4
+	brlt	2f
+1:	ld.w	r0, --src
+	st.w	--dst, r0
+	sub	len, 4
+	brge	1b
+
+2:	neg	len
+	add	pc, pc, len << 2
+	.rept	3
+	ld.ub	r0, --src
+	st.b	--dst, r0
+	.endr
+
+	popm	r0-r7, pc
Index: uClibc-0.9.28-avr32/libc/string/avr32/memset.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/memset.S	2006-10-20 10:42:15.000000000 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2004 Atmel Norway.
+ */
+
+#define s r12
+#define c r11
+#define n r10
+
+	.text
+	.global memset
+	.type	memset, @function
+
+	.global	__memset
+	.hidden	__memset
+	.type	__memset, @function
+
+	.align	1
+memset:
+__memset:
+	cp.w	n, 32
+	mov	r9, s
+	brge	.Llarge_memset
+
+	sub	n, 1
+	retlt	s
+1:	st.b	s++, c
+	sub	n, 1
+	brge	1b
+
+	retal	r9
+
+.Llarge_memset:
+	mov	r8, r11
+	mov	r11, 3
+	bfins	r8, r8, 8, 8
+	bfins	r8, r8, 16, 16
+	tst	s, r11
+	breq	2f
+
+1:	st.b	s++, r8
+	sub	n, 1
+	tst	s, r11
+	brne	1b
+
+2:	mov	r11, r9
+	mov	r9, r8
+	sub	n, 8
+
+3:	st.d	s++, r8
+	sub	n, 8
+	brge	3b
+
+	/* If we are done, n == -8 and we'll skip all st.b insns below */
+	neg	n
+	lsl	n, 1
+	add	pc, n
+	.rept	7
+	st.b	s++, r8
+	.endr
+	retal	r11
Index: uClibc-0.9.28-avr32/libc/string/avr32/strcat.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/strcat.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+#define s1 r9
+#define s2 r11
+
+	.text
+	.global strcat
+	.type	strcat, @function
+	.align	1
+strcat:
+	mov	s1, r12
+
+	/* Make sure s1 is word-aligned */
+	mov	r10, s1
+	andl	r10, 3, COH
+	breq	2f
+
+	add	pc, pc, r10 << 3
+	sub	r0, r0, 0	/* 4-byte nop */
+	ld.ub	r8, s1++
+	sub	r8, r8, 0
+	breq	2f
+	ld.ub	r8, s1++
+	sub	r8, r8, 0
+	breq	3f
+	ld.ub	r8, s1++
+	sub	r8, r8, 0
+	breq	4f
+
+	/* Find the end of the first string */
+5:	ld.w	r8, s1++
+	tnbz	r8
+	brne	5b
+
+	sub	s1, 4
+
+	bfextu	r10, r8, 24, 8
+	cp.w	r10, 0
+	breq	1f
+	sub	s1, -1
+	bfextu	r10, r8, 16, 8
+	cp.w	r10, 0
+	breq	2f
+	sub	s1, -1
+	bfextu	r10, r8, 8, 8
+	cp.w	r10, 0
+	breq	3f
+	sub	s1, -1
+	rjmp	4f
+
+	/* Now, append s2 */
+1:	ld.ub	r8, s2++
+	st.b	s1++, r8
+	cp.w	r8, 0
+	reteq	r12
+2:	ld.ub	r8, s2++
+	st.b	s1++, r8
+	cp.w	r8, 0
+	reteq	r12
+3:	ld.ub	r8, s2++
+	st.b	s1++, r8
+	cp.w	r8, 0
+	reteq	r12
+4:	ld.ub	r8, s2++
+	st.b	s1++, r8
+	cp.w	r8, 0
+	reteq	r12
+
+	/* Copy one word at a time */
+	ld.w	r8, s2++
+	tnbz	r8
+	breq	2f
+1:	st.w	r8, s2++
+	ld.w	r8, s2++
+	tnbz	r8
+	brne	1b
+
+	/* Copy the remaining bytes */
+	bfextu	r10, r8, 24, 8
+	st.b	s1++, r10
+	cp.w	r10, 0
+	reteq	r12
+	bfextu	r10, r8, 16, 8
+	st.b	s1++, r10
+	cp.w	r10, 0
+	reteq	r12
+	bfextu	r10, r8, 8, 8
+	st.b	s1++, r10
+	cp.w	r10, 0
+	reteq	r12
+	st.b	s1++, r8
+	retal	r12
+	.size	strcat, . - strcat
Index: uClibc-0.9.28-avr32/libc/string/avr32/strcmp.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/strcmp.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2004 Atmel Norway.
+ */
+
+#define s1 r12
+#define s2 r11
+#define len r10
+
+	.text
+	.global strcmp
+	.type	strcmp, @function
+	.align	1
+strcmp:
+	mov	r8, 3
+	tst	s1, r8
+	brne	.Lunaligned_s1
+	tst	s2, r8
+	brne	.Lunaligned_s2
+
+1:	ld.w	r8, s1++
+	ld.w	r9, s2++
+	cp.w	r8, r9
+	brne	2f
+	tnbz	r8
+	brne	1b
+	retal	0
+
+2:	bfextu	r12, r8, 24, 8
+	bfextu	r11, r9, 24, 8
+	sub	r12, r11
+	retne	r12
+	cp.w	r11, 0
+	reteq	0
+	bfextu	r12, r8, 16, 8
+	bfextu	r11, r9, 16, 8
+	sub	r12, r11
+	retne	r12
+	cp.w	r11, 0
+	reteq	0
+	bfextu	r12, r8, 8, 8
+	bfextu	r11, r9, 8, 8
+	sub	r12, r11
+	retne	r12
+	cp.w	r11, 0
+	reteq	0
+	bfextu	r12, r8, 0, 8
+	bfextu	r11, r9, 0, 8
+	sub	r12, r11
+	retal	r12
+
+.Lunaligned_s1:
+3:	tst	s1, r8
+	breq	4f
+	ld.ub	r10, s1++
+	ld.ub	r9, s2++
+	sub	r10, r9
+	retne	r10
+	cp.w	r9, 0
+	brne	3b
+	retal	r10
+
+4:	tst	s2, r8
+	breq	1b
+
+.Lunaligned_s2:
+	/*
+	 * s1 and s2 can't both be aligned, and unaligned word loads
+	 * can trigger spurious exceptions if we cross a page boundary.
+	 * Do it the slow way...
+	 */
+1:	ld.ub	r8, s1++
+	ld.ub	r9, s2++
+	sub	r8, r9
+	retne	r8
+	cp.w	r9, 0
+	brne	1b
+	retal	0
+
+	.weak	strcoll
+	strcoll	= strcmp
Index: uClibc-0.9.28-avr32/libc/string/avr32/strcpy.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/strcpy.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ *
+ * To reduce the size, this one might simply call strncpy with len = -1.
+ */
+
+#define dst r9
+#define src r11
+
+	.text
+	.global strcpy
+	.type	strcpy, @function
+strcpy:
+	mov	dst, r12
+
+	pref	src[0]
+
+	/*
+	 * Check alignment. If src is aligned but dst isn't, we can't
+	 * do much about it...
+	 */
+	mov	r8, src
+	andl	r8, 3 COH
+	brne	.Lunaligned_src
+
+.Laligned_copy:
+1:	ld.w	r8, src++
+	tnbz	r8
+	breq	2f
+	st.w	dst++, r8
+	rjmp	1b
+
+2:	/*
+	 * Ok, r8 now contains the terminating '\0'. Copy the
+	 * remaining bytes individually.
+	 */
+	bfextu	r10, r8, 24, 8
+	st.b	dst++, r10
+	cp.w	r10, 0
+	reteq	r12
+	bfextu	r10, r8, 16, 8
+	st.b	dst++, r10
+	cp.w	r10, 0
+	reteq	r12
+	bfextu	r10, r8, 8, 8
+	st.b	dst++, r10
+	cp.w	r10, 0
+	reteq	r12
+	st.b	dst++, r8
+	retal	r12
+
+.Lunaligned_src:
+	/* Copy bytes until we're aligned */
+	rsub	r8, r8, 4
+	add	pc, pc, r8 << 3
+	nop
+	nop
+	ld.ub	r10, src++
+	st.b	dst++, r10
+	cp.w	r10, 0
+	reteq	r12
+
+	rjmp	.Laligned_copy
Index: uClibc-0.9.28-avr32/libc/string/avr32/stringtest.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/stringtest.c	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,144 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/mman.h>
+
+#define BUF_SIZE (8 * 1024)
+
+static char *buf1;
+static char *buf1_ref;
+static char *buf2;
+
+extern void *optimized_memcpy(void *dest, void *src, size_t len);
+extern void *optimized_memmove(void *dest, void *src, size_t len);
+extern char *optimized_strcpy(char *dest, char *src);
+extern char *optimized_strncpy(char *dest, char *src, size_t len);
+
+void dump_mismatch(char *buf, char *ref, size_t len)
+{
+	int i, j;
+
+	for (i = 0; i < len; i += 16) {
+		if (memcmp(buf + i, ref + i, 16) == 0)
+			continue;
+
+		printf("%4x buf:", i);
+		for (j = i; j < (i + 16); j++)
+			printf(" %02x", buf[j]);
+		printf("\n     ref:");
+		for (j = i; j < (i + 16); j++)
+			printf(" %02x", ref[j]);
+		printf("\n");
+	}
+}
+
+static void test_memcpy(int src_offset, int dst_offset, int len)
+{
+	clock_t start, old, new;
+	int i;
+
+	memset(buf1, 0x55, BUF_SIZE);
+	memset(buf1_ref, 0x55, BUF_SIZE);
+	memset(buf2, 0xaa, BUF_SIZE);
+
+	printf("Testing memcpy with offsets %d => %d and len %d...",
+	       src_offset, dst_offset, len);
+
+	start = clock();
+	for (i = 0; i < 8192; i++)
+		optimized_memcpy(buf1 + dst_offset, buf2 + src_offset, len);
+	new = clock() - start;
+	start = clock();
+	for ( i = 0; i < 8192; i++)
+		memcpy(buf1_ref + dst_offset, buf2 + src_offset, len);
+	old = clock() - start;
+
+	if (memcmp(buf1, buf1_ref, BUF_SIZE) == 0)
+		printf("OK\n");
+	else {
+		printf("FAILED\n");
+		dump_mismatch(buf1, buf1_ref, BUF_SIZE);
+	}
+	printf("CPU time used: %d vs. %d\n", new, old);
+}
+
+static void test_memmove(int src_offset, int dst_offset, int len)
+{
+	clock_t start, old, new;
+
+	memset(buf1, 0x55, BUF_SIZE);
+	memset(buf1_ref, 0x55, BUF_SIZE);
+	memset(buf2, 0xaa, BUF_SIZE);
+
+	printf("Testing memmove with offsets %d => %d and len %d...",
+	       src_offset, dst_offset, len);
+
+	start = clock();
+	optimized_memmove(buf1 + dst_offset, buf2 + src_offset, len);
+	new = clock() - start;
+	start = clock();
+	memmove(buf1_ref + dst_offset, buf2 + src_offset, len);
+	old = clock() - start;
+
+	if (memcmp(buf1, buf1_ref, BUF_SIZE) == 0)
+		printf("OK\n");
+	else {
+		printf("FAILED\n");
+		dump_mismatch(buf1, buf1_ref, BUF_SIZE);
+	}
+	printf("CPU time used: %d vs. %d\n", new, old);
+}
+
+int main(int argc, char *argv[])
+{
+	buf2 = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
+		    MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (buf2 == MAP_FAILED) {
+		perror("Failed to allocate memory for buf2");
+		return 1;
+	}
+	buf1 = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
+		    MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (buf1 == MAP_FAILED) {
+		perror("Failed to allocate memory for buf1");
+		return 1;
+	}
+	buf1_ref = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (buf1_ref == MAP_FAILED) {
+		perror("Failed to allocate memory for buf1_ref");
+		return 1;
+	}
+	printf("\n === MEMCPY ===\n\n");
+
+	test_memcpy(0, 0, BUF_SIZE - 32);
+	test_memcpy(0, 0, 1);
+	test_memcpy(0, 0, 31);
+	test_memcpy(0, 0, 32);
+	test_memcpy(0, 0, 127);
+	test_memcpy(0, 0, 128);
+	test_memcpy(4, 4, BUF_SIZE - 32 - 4);
+	test_memcpy(1, 1, BUF_SIZE - 32 - 1);
+	test_memcpy(1, 1, 126);
+	test_memcpy(0, 3, 128);
+	test_memcpy(1, 4, 128);
+	test_memcpy(0, 0, 0);
+
+	printf("\n === MEMMOVE ===\n\n");
+
+	test_memmove(0, 0, BUF_SIZE - 32);
+	test_memmove(0, 0, 1);
+	test_memmove(0, 0, 31);
+	test_memmove(0, 0, 32);
+	test_memmove(0, 0, BUF_SIZE - 33);
+	test_memmove(0, 0, 128);
+	test_memmove(4, 4, BUF_SIZE - 32 - 4);
+	test_memmove(1, 1, BUF_SIZE - 32 - 1);
+	test_memmove(1, 1, BUF_SIZE - 130);
+	test_memmove(0, 3, BUF_SIZE - 128);
+	test_memmove(1, 4, BUF_SIZE - 128);
+	test_memmove(0, 0, 0);
+
+	return 0;
+}
Index: uClibc-0.9.28-avr32/libc/string/avr32/strlen.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/strlen.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+#define str r12
+
+	.text
+	.global strlen
+	.type	strlen, @function
+strlen:
+	mov	r11, r12
+
+	mov	r9, str
+	andl	r9, 3, COH
+	brne	.Lunaligned_str
+
+1:	ld.w	r8, str++
+	tnbz	r8
+	brne	1b
+
+	sub	r12, r11
+	bfextu	r9, r8, 24, 8
+	cp.w	r9, 0
+	subeq	r12, 4
+	reteq	r12
+	bfextu	r9, r8, 16, 8
+	cp.w	r9, 0
+	subeq	r12, 3
+	reteq	r12
+	bfextu	r9, r8, 8, 8
+	cp.w	r9, 0
+	subeq	r12, 2
+	reteq	r12
+	sub	r12, 1
+	retal	r12
+
+.Lunaligned_str:
+	add	pc, pc, r9 << 3
+	sub	r0, r0, 0	/* 4-byte nop */
+	ld.ub	r8, str++
+	sub	r8, r8, 0
+	breq	1f
+	ld.ub	r8, str++
+	sub	r8, r8, 0
+	breq	1f
+	ld.ub	r8, str++
+	sub	r8, r8, 0
+	brne	1b
+
+1:	sub	r12, 1
+	sub	r12, r11
+	retal	r12
Index: uClibc-0.9.28-avr32/libc/string/avr32/strncpy.S
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/strncpy.S	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2004 Atmel Norway
+ */
+
+#define dst r9
+#define src r11
+
+	.text
+	.global strcpy
+	.type	strncpy, @function
+strncpy:
+	mov	dst, r12
+
+	pref	src[0]
+	mov	dst, r12
+
+	/*
+	 * Check alignment. If src is aligned but dst isn't, we can't
+	 * do much about it...
+	 */
+	mov	r8, src
+	andl	r8, 3 COH
+	brne	.Lunaligned_src
+
+.Laligned_copy:
+	sub	r10, 4
+	brlt	3f
+1:	ld.w	r8, src++
+	tnbz	r8
+	breq	2f
+	st.w	dst++, r8
+	sub	r10, 4
+	brne	1b
+
+3:	sub	r10, -4
+	reteq	r12
+
+	/* This is safe as long as src is word-aligned and r10 > 0 */
+	ld.w	r8, src++
+
+2:	/*
+	 * Ok, r8 now contains the terminating '\0'. Copy the
+	 * remaining bytes individually.
+	 */
+	bfextu	r11, r8, 24, 8
+	st.b	dst++, r11
+	cp.w	r11, 0
+	reteq	r12
+	sub	r10, 1
+	reteq	r12
+	bfextu	r11, r8, 16, 8
+	st.b	dst++, r11
+	cp.w	r11, 0
+	reteq	r12
+	sub	r10, 1
+	reteq	r12
+	bfextu	r11, r8, 8, 8
+	st.b	dst++, r11
+	cp.w	r11, 0
+	reteq	r12
+	sub	r10, 1
+	reteq	r12
+	st.b	dst++, r8
+	retal	r12
+
+.Lunaligned_src:
+	/* Copy bytes until we're aligned */
+	min	r8, r8, r10
+	sub	r10, r8
+	sub	r8, 1
+	retlt	r12
+1:	ld.ub	r10, src++
+	st.b	dst++, r10
+	sub	r8, 1
+	brge	1b
+
+	rjmp	.Laligned_copy
Index: uClibc-0.9.28-avr32/libc/string/avr32/test_memcpy.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ uClibc-0.9.28-avr32/libc/string/avr32/test_memcpy.c	2006-10-19 15:05:52.000000000 +0200
@@ -0,0 +1,66 @@
+
+#include <stdio.h>
+#include <string.h>
+
+#define BUF_SIZE 32768
+
+static char buf1[BUF_SIZE] __attribute__((aligned(32)));
+static char buf1_ref[BUF_SIZE] __attribute__((aligned(32)));
+static char buf2[BUF_SIZE] __attribute__((aligned(32)));
+
+extern void *new_memcpy(void *dest, void *src, size_t len);
+
+void dump_mismatch(char *buf, char *ref, size_t len)
+{
+	int i, j;
+
+	for (i = 0; i < len; i += 16) {
+		if (memcmp(buf + i, ref + i, 16) == 0)
+			continue;
+
+		printf("% 4x buf:", i);
+		for (j = i; j < (i + 16); j++)
+			printf(" %02x", buf[j]);
+		printf("\n     ref:");
+		for (j = i; j < (i + 16); j++)
+			printf(" %02x", ref[j]);
+		printf("\n");
+	}
+}
+
+void test(int src_offset, int dst_offset, int len)
+{
+	memset(buf1, 0x55, sizeof(buf1));
+	memset(buf1_ref, 0x55, sizeof(buf1_ref));
+	memset(buf2, 0xaa, sizeof(buf2));
+
+	printf("Testing with offsets %d => %d and len %d...",
+	       src_offset, dst_offset, len);
+
+	new_memcpy(buf1 + dst_offset, buf2 + src_offset, len);
+	memcpy(buf1_ref + dst_offset, buf2 + src_offset, len);
+
+	if (memcmp(buf1, buf1_ref, sizeof(buf1)) == 0)
+		printf("OK\n");
+	else {
+		printf("FAILED\n");
+		dump_mismatch(buf1, buf1_ref, sizeof(buf1));
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	test(0, 0, BUF_SIZE);
+	test(0, 0, 1);
+	test(0, 0, 31);
+	test(0, 0, 32);
+	test(0, 0, 127);
+	test(0, 0, 128);
+	test(4, 4, BUF_SIZE - 4);
+	test(1, 1, BUF_SIZE - 1);
+	test(1, 1, 126);
+	test(0, 3, 128);
+	test(1, 4, 128);
+
+	return 0;
+}