Home Home > GIT Browse
summaryrefslogtreecommitdiff
blob: fdc48bb065d89fe3b2443ef054d1a6ece3744b54 (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
/*
 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
 * Copyright (C) 2008-2009 PetaLogix
 * Copyright (C) 2008 Jim Law - Iris LP  All rights reserved.
 *
 * This file is subject to the terms and conditions of the GNU General
 * Public License.  See the file COPYING in the main directory of this
 * archive for more details.
 *
 * Written by Jim Law <jlaw@irispower.com>
 *
 * intended to replace:
 *	memcpy in memcpy.c and
 *	memmove in memmove.c
 * ... in arch/microblaze/lib
 *
 *
 * assly_fastcopy.S
 *
 * Attempt at quicker memcpy and memmove for MicroBlaze
 *	Input :	Operand1 in Reg r5 - destination address
 *		Operand2 in Reg r6 - source address
 *		Operand3 in Reg r7 - number of bytes to transfer
 *	Output: Result in Reg r3 - starting destinaition address
 *
 *
 * Explanation:
 *	Perform (possibly unaligned) copy of a block of memory
 *	between mem locations with size of xfer spec'd in bytes
 */

#include <linux/linkage.h>
	.text
	.globl	memcpy
	.type  memcpy, @function
	.ent	memcpy

memcpy:
fast_memcpy_ascending:
	/* move d to return register as value of function */
	addi	r3, r5, 0

	addi	r4, r0, 4	/* n = 4 */
	cmpu	r4, r4, r7	/* n = c - n  (unsigned) */
	blti	r4, a_xfer_end	/* if n < 0, less than one word to transfer */

	/* transfer first 0~3 bytes to get aligned dest address */
	andi	r4, r5, 3		/* n = d & 3 */
	/* if zero, destination already aligned */
	beqi	r4, a_dalign_done
	/* n = 4 - n (yields 3, 2, 1 transfers for 1, 2, 3 addr offset) */
	rsubi	r4, r4, 4
	rsub	r7, r4, r7		/* c = c - n adjust c */

a_xfer_first_loop:
	/* if no bytes left to transfer, transfer the bulk */
	beqi	r4, a_dalign_done
	lbui	r11, r6, 0		/* h = *s */
	sbi	r11, r5, 0		/* *d = h */
	addi	r6, r6, 1		/* s++ */
	addi	r5, r5, 1		/* d++ */
	brid	a_xfer_first_loop	/* loop */
	addi	r4, r4, -1		/* n-- (IN DELAY SLOT) */

a_dalign_done:
	addi	r4, r0, 32		/* n = 32 */
	cmpu	r4, r4, r7		/* n = c - n  (unsigned) */
	/* if n < 0, less than one block to transfer */
	blti	r4, a_block_done

a_block_xfer:
	andi	r4, r7, 0xffffffe0	/* n = c & ~31 */
	rsub	r7, r4, r7		/* c = c - n */

	andi	r9, r6, 3		/* t1 = s & 3 */
	/* if temp != 0, unaligned transfers needed */
	bnei	r9, a_block_unaligned

a_block_aligned:
	lwi	r9, r6, 0		/* t1 = *(s + 0) */
	lwi	r10, r6, 4		/* t2 = *(s + 4) */
	lwi	r11, r6, 8		/* t3 = *(s + 8) */
	lwi	r12, r6, 12		/* t4 = *(s + 12) */
	swi	r9, r5, 0		/* *(d + 0) = t1 */
	swi	r10, r5, 4		/* *(d + 4) = t2 */
	swi	r11, r5, 8		/* *(d + 8) = t3 */
	swi	r12, r5, 12		/* *(d + 12) = t4 */
	lwi	r9, r6, 16		/* t1 = *(s + 16) */
	lwi	r10, r6, 20		/* t2 = *(s + 20) */
	lwi	r11, r6, 24		/* t3 = *(s + 24) */
	lwi	r12, r6, 28		/* t4 = *(s + 28) */
	swi	r9, r5, 16		/* *(d + 16) = t1 */
	swi	r10, r5, 20		/* *(d + 20) = t2 */
	swi	r11, r5, 24		/* *(d + 24) = t3 */
	swi	r12, r5, 28		/* *(d + 28) = t4 */
	addi	r6, r6, 32		/* s = s + 32 */
	addi	r4, r4, -32		/* n = n - 32 */
	bneid	r4, a_block_aligned	/* while (n) loop */
	addi	r5, r5, 32		/* d = d + 32 (IN DELAY SLOT) */
	bri	a_block_done

a_block_unaligned:
	andi	r8, r6, 0xfffffffc	/* as = s & ~3 */
	add	r6, r6, r4		/* s = s + n */
	lwi	r11, r8, 0		/* h = *(as + 0) */

	addi	r9, r9, -1
	beqi	r9, a_block_u1		/* t1 was 1 => 1 byte offset */
	addi	r9, r9, -1
	beqi	r9, a_block_u2		/* t1 was 2 => 2 byte offset */

a_block_u3:
	bslli	r11, r11, 24	/* h = h << 24 */
a_bu3_loop:
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 12) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	lwi	r12, r8, 32	/* v = *(as + 32) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	addi	r8, r8, 32	/* as = as + 32 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, a_bu3_loop	/* while (n) loop */
	addi	r5, r5, 32	/* d = d + 32 (IN DELAY SLOT) */
	bri	a_block_done

a_block_u1:
	bslli	r11, r11, 8	/* h = h << 8 */
a_bu1_loop:
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 12) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	lwi	r12, r8, 32	/* v = *(as + 32) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	addi	r8, r8, 32	/* as = as + 32 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, a_bu1_loop	/* while (n) loop */
	addi	r5, r5, 32	/* d = d + 32 (IN DELAY SLOT) */
	bri	a_block_done

a_block_u2:
	bslli	r11, r11, 16	/* h = h << 16 */
a_bu2_loop:
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 12) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	lwi	r12, r8, 32	/* v = *(as + 32) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	addi	r8, r8, 32	/* as = as + 32 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, a_bu2_loop	/* while (n) loop */
	addi	r5, r5, 32	/* d = d + 32 (IN DELAY SLOT) */

a_block_done:
	addi	r4, r0, 4	/* n = 4 */
	cmpu	r4, r4, r7	/* n = c - n  (unsigned) */
	blti	r4, a_xfer_end	/* if n < 0, less than one word to transfer */

a_word_xfer:
	andi	r4, r7, 0xfffffffc	/* n = c & ~3 */
	addi	r10, r0, 0		/* offset = 0 */

	andi	r9, r6, 3		/* t1 = s & 3 */
	/* if temp != 0, unaligned transfers needed */
	bnei	r9, a_word_unaligned

a_word_aligned:
	lw	r9, r6, r10		/* t1 = *(s+offset) */
	sw	r9, r5, r10		/* *(d+offset) = t1 */
	addi	r4, r4,-4		/* n-- */
	bneid	r4, a_word_aligned	/* loop */
	addi	r10, r10, 4		/* offset++ (IN DELAY SLOT) */

	bri	a_word_done

a_word_unaligned:
	andi	r8, r6, 0xfffffffc	/* as = s & ~3 */
	lwi	r11, r8, 0		/* h = *(as + 0) */
	addi	r8, r8, 4		/* as = as + 4 */

	addi	r9, r9, -1
	beqi	r9, a_word_u1		/* t1 was 1 => 1 byte offset */
	addi	r9, r9, -1
	beqi	r9, a_word_u2		/* t1 was 2 => 2 byte offset */

a_word_u3:
	bslli	r11, r11, 24	/* h = h << 24 */
a_wu3_loop:
	lw	r12, r8, r10	/* v = *(as + offset) */
	bsrli	r9, r12, 8	/* t1 = v >> 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r10	/* *(d + offset) = t1 */
	bslli	r11, r12, 24	/* h = v << 24 */
	addi	r4, r4,-4	/* n = n - 4 */
	bneid	r4, a_wu3_loop	/* while (n) loop */
	addi	r10, r10, 4	/* offset = ofset + 4 (IN DELAY SLOT) */

	bri	a_word_done

a_word_u1:
	bslli	r11, r11, 8	/* h = h << 8 */
a_wu1_loop:
	lw	r12, r8, r10	/* v = *(as + offset) */
	bsrli	r9, r12, 24	/* t1 = v >> 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r10	/* *(d + offset) = t1 */
	bslli	r11, r12, 8	/* h = v << 8 */
	addi	r4, r4,-4	/* n = n - 4 */
	bneid	r4, a_wu1_loop	/* while (n) loop */
	addi	r10, r10, 4	/* offset = ofset + 4 (IN DELAY SLOT) */

	bri	a_word_done

a_word_u2:
	bslli	r11, r11, 16	/* h = h << 16 */
a_wu2_loop:
	lw	r12, r8, r10	/* v = *(as + offset) */
	bsrli	r9, r12, 16	/* t1 = v >> 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r10	/* *(d + offset) = t1 */
	bslli	r11, r12, 16	/* h = v << 16 */
	addi	r4, r4,-4	/* n = n - 4 */
	bneid	r4, a_wu2_loop	/* while (n) loop */
	addi	r10, r10, 4	/* offset = ofset + 4 (IN DELAY SLOT) */

a_word_done:
	add	r5, r5, r10	/* d = d + offset */
	add	r6, r6, r10	/* s = s + offset */
	rsub	r7, r10, r7	/* c = c - offset */

a_xfer_end:
a_xfer_end_loop:
	beqi	r7, a_done		/* while (c) */
	lbui	r9, r6, 0		/* t1 = *s */
	addi	r6, r6, 1		/* s++ */
	sbi	r9, r5, 0		/* *d = t1 */
	addi	r7, r7, -1		/* c-- */
	brid	a_xfer_end_loop		/* loop */
	addi	r5, r5, 1		/* d++ (IN DELAY SLOT) */

a_done:
	rtsd	r15, 8
	nop

.size  memcpy, . - memcpy
.end memcpy
/*----------------------------------------------------------------------------*/
	.globl	memmove
	.type  memmove, @function
	.ent	memmove

memmove:
	cmpu	r4, r5, r6	/* n = s - d */
	bgei	r4,fast_memcpy_ascending

fast_memcpy_descending:
	/* move d to return register as value of function */
	addi	r3, r5, 0

	add	r5, r5, r7	/* d = d + c */
	add	r6, r6, r7	/* s = s + c */

	addi	r4, r0, 4	/* n = 4 */
	cmpu	r4, r4, r7	/* n = c - n  (unsigned) */
	blti	r4,d_xfer_end	/* if n < 0, less than one word to transfer */

	/* transfer first 0~3 bytes to get aligned dest address */
	andi	r4, r5, 3		/* n = d & 3 */
	/* if zero, destination already aligned */
	beqi	r4,d_dalign_done
	rsub	r7, r4, r7		/* c = c - n adjust c */

d_xfer_first_loop:
	/* if no bytes left to transfer, transfer the bulk */
	beqi	r4,d_dalign_done
	addi	r6, r6, -1		/* s-- */
	addi	r5, r5, -1		/* d-- */
	lbui	r11, r6, 0		/* h = *s */
	sbi	r11, r5, 0		/* *d = h */
	brid	d_xfer_first_loop	/* loop */
	addi	r4, r4, -1		/* n-- (IN DELAY SLOT) */

d_dalign_done:
	addi	r4, r0, 32	/* n = 32 */
	cmpu	r4, r4, r7	/* n = c - n  (unsigned) */
	/* if n < 0, less than one block to transfer */
	blti	r4, d_block_done

d_block_xfer:
	andi	r4, r7, 0xffffffe0	/* n = c & ~31 */
	rsub	r7, r4, r7		/* c = c - n */

	andi	r9, r6, 3		/* t1 = s & 3 */
	/* if temp != 0, unaligned transfers needed */
	bnei	r9, d_block_unaligned

d_block_aligned:
	addi	r6, r6, -32		/* s = s - 32 */
	addi	r5, r5, -32		/* d = d - 32 */
	lwi	r9, r6, 28		/* t1 = *(s + 28) */
	lwi	r10, r6, 24		/* t2 = *(s + 24) */
	lwi	r11, r6, 20		/* t3 = *(s + 20) */
	lwi	r12, r6, 16		/* t4 = *(s + 16) */
	swi	r9, r5, 28		/* *(d + 28) = t1 */
	swi	r10, r5, 24		/* *(d + 24) = t2 */
	swi	r11, r5, 20		/* *(d + 20) = t3 */
	swi	r12, r5, 16		/* *(d + 16) = t4 */
	lwi	r9, r6, 12		/* t1 = *(s + 12) */
	lwi	r10, r6, 8		/* t2 = *(s + 8) */
	lwi	r11, r6, 4		/* t3 = *(s + 4) */
	lwi	r12, r6, 0		/* t4 = *(s + 0) */
	swi	r9, r5, 12		/* *(d + 12) = t1 */
	swi	r10, r5, 8		/* *(d + 8) = t2 */
	swi	r11, r5, 4		/* *(d + 4) = t3 */
	addi	r4, r4, -32		/* n = n - 32 */
	bneid	r4, d_block_aligned	/* while (n) loop */
	swi	r12, r5, 0		/* *(d + 0) = t4 (IN DELAY SLOT) */
	bri	d_block_done

d_block_unaligned:
	andi	r8, r6, 0xfffffffc	/* as = s & ~3 */
	rsub	r6, r4, r6		/* s = s - n */
	lwi	r11, r8, 0		/* h = *(as + 0) */

	addi	r9, r9, -1
	beqi	r9,d_block_u1		/* t1 was 1 => 1 byte offset */
	addi	r9, r9, -1
	beqi	r9,d_block_u2		/* t1 was 2 => 2 byte offset */

d_block_u3:
	bsrli	r11, r11, 8	/* h = h >> 8 */
d_bu3_loop:
	addi	r8, r8, -32	/* as = as - 32 */
	addi	r5, r5, -32	/* d = d - 32 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 112) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bsrli	r11, r12, 8	/* h = v >> 8 */
	lwi	r12, r8, 0	/* v = *(as + 0) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, d_bu3_loop	/* while (n) loop */
	bsrli	r11, r12, 8	/* h = v >> 8 (IN DELAY SLOT) */
	bri	d_block_done

d_block_u1:
	bsrli	r11, r11, 24	/* h = h >> 24 */
d_bu1_loop:
	addi	r8, r8, -32	/* as = as - 32 */
	addi	r5, r5, -32	/* d = d - 32 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 112) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bsrli	r11, r12, 24	/* h = v >> 24 */
	lwi	r12, r8, 0	/* v = *(as + 0) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, d_bu1_loop	/* while (n) loop */
	bsrli	r11, r12, 24	/* h = v >> 24 (IN DELAY SLOT) */
	bri	d_block_done

d_block_u2:
	bsrli	r11, r11, 16	/* h = h >> 16 */
d_bu2_loop:
	addi	r8, r8, -32	/* as = as - 32 */
	addi	r5, r5, -32	/* d = d - 32 */
	lwi	r12, r8, 28	/* v = *(as + 28) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 28	/* *(d + 28) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 24	/* v = *(as + 24) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 24	/* *(d + 24) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 20	/* v = *(as + 20) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 20	/* *(d + 20) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 16	/* v = *(as + 16) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 16	/* *(d + 16) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 12	/* v = *(as + 12) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 12	/* *(d + 112) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 8	/* v = *(as + 8) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 8	/* *(d + 8) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 4	/* v = *(as + 4) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 4	/* *(d + 4) = t1 */
	bsrli	r11, r12, 16	/* h = v >> 16 */
	lwi	r12, r8, 0	/* v = *(as + 0) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	swi	r9, r5, 0	/* *(d + 0) = t1 */
	addi	r4, r4, -32	/* n = n - 32 */
	bneid	r4, d_bu2_loop	/* while (n) loop */
	bsrli	r11, r12, 16	/* h = v >> 16 (IN DELAY SLOT) */

d_block_done:
	addi	r4, r0, 4	/* n = 4 */
	cmpu	r4, r4, r7	/* n = c - n  (unsigned) */
	blti	r4,d_xfer_end	/* if n < 0, less than one word to transfer */

d_word_xfer:
	andi	r4, r7, 0xfffffffc	/* n = c & ~3 */
	rsub	r5, r4, r5		/* d = d - n */
	rsub	r6, r4, r6		/* s = s - n */
	rsub	r7, r4, r7		/* c = c - n */

	andi	r9, r6, 3		/* t1 = s & 3 */
	/* if temp != 0, unaligned transfers needed */
	bnei	r9, d_word_unaligned

d_word_aligned:
	addi	r4, r4,-4		/* n-- */
	lw	r9, r6, r4		/* t1 = *(s+n) */
	bneid	r4, d_word_aligned	/* loop */
	sw	r9, r5, r4		/* *(d+n) = t1 (IN DELAY SLOT) */

	bri	d_word_done

d_word_unaligned:
	andi	r8, r6, 0xfffffffc	/* as = s & ~3 */
	lw	r11, r8, r4		/* h = *(as + n) */

	addi	r9, r9, -1
	beqi	r9,d_word_u1		/* t1 was 1 => 1 byte offset */
	addi	r9, r9, -1
	beqi	r9,d_word_u2		/* t1 was 2 => 2 byte offset */

d_word_u3:
	bsrli	r11, r11, 8	/* h = h >> 8 */
d_wu3_loop:
	addi	r4, r4,-4	/* n = n - 4 */
	lw	r12, r8, r4	/* v = *(as + n) */
	bslli	r9, r12, 24	/* t1 = v << 24 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r4	/* *(d + n) = t1 */
	bneid	r4, d_wu3_loop	/* while (n) loop */
	bsrli	r11, r12, 8	/* h = v >> 8 (IN DELAY SLOT) */

	bri	d_word_done

d_word_u1:
	bsrli	r11, r11, 24	/* h = h >> 24 */
d_wu1_loop:
	addi	r4, r4,-4	/* n = n - 4 */
	lw	r12, r8, r4	/* v = *(as + n) */
	bslli	r9, r12, 8	/* t1 = v << 8 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r4	/* *(d + n) = t1 */
	bneid	r4, d_wu1_loop	/* while (n) loop */
	bsrli	r11, r12, 24	/* h = v >> 24 (IN DELAY SLOT) */

	bri	d_word_done

d_word_u2:
	bsrli	r11, r11, 16	/* h = h >> 16 */
d_wu2_loop:
	addi	r4, r4,-4	/* n = n - 4 */
	lw	r12, r8, r4	/* v = *(as + n) */
	bslli	r9, r12, 16	/* t1 = v << 16 */
	or	r9, r11, r9	/* t1 = h | t1 */
	sw	r9, r5, r4	/* *(d + n) = t1 */
	bneid	r4, d_wu2_loop	/* while (n) loop */
	bsrli	r11, r12, 16	/* h = v >> 16 (IN DELAY SLOT) */

d_word_done:

d_xfer_end:
d_xfer_end_loop:
	beqi	r7, a_done		/* while (c) */
	addi	r6, r6, -1		/* s-- */
	lbui	r9, r6, 0		/* t1 = *s */
	addi	r5, r5, -1		/* d-- */
	sbi	r9, r5, 0		/* *d = t1 */
	brid	d_xfer_end_loop		/* loop */
	addi	r7, r7, -1		/* c-- (IN DELAY SLOT) */

d_done:
	rtsd	r15, 8
	nop

.size  memmove, . - memmove
.end memmove