1
2
3
4
5 beq $r1, $r0, quit_memcpy
6 beqz $r2, quit_memcpy
7 srli $r3, $r2, #5 ! check if len < cache-line size 32
8 beqz $r3, word_copy_entry
9 andi $r4, $r0, #0x3 ! check byte-align
10 beqz $r4, unalign_word_copy_entry
11
12 addi $r4, $r4,#-4
13 abs $r4, $r4 ! check how many un-align byte to copy
14 sub $r2, $r2, $r4 ! update $R2
15
16 unalign_byte_copy:
17 lbi1 $r3, $r1, #1
18 addi $r4, $r4, #-1
19 sbi1 $r3, $r0, #1
20 bnez $r4, unalign_byte_copy
21 beqz $r2, quit_memcpy
22
23 unalign_word_copy_entry:
24 andi $r3, $r0, 0x1f ! check cache-line unaligncount
25 beqz $r3, cache_copy
26
27 addi $r3, $r3, #-32
28 abs $r3, $r3
29 sub $r2, $r2, $r3 ! update $R2
30
31 unalign_word_copy:
32 lmw1 $r4, $r1, $r4
33 addi $r3, $r3, #-4
34 smw1 $r4, $r0, $r4
35 bnez $r3, unalign_word_copy
36 beqz $r2, quit_memcpy
37
38 addi $r3, $r2, #-32 ! to check $r2< cache_line , than go to word_copy
39 bltz $r3, word_copy_entry
40 cache_copy:
41 srli $r3, $r2, #5
42 beqz $r3, word_copy_entry
43 3:
44 lmw1 $r17, $r1, $r24
45 addi $r3, $r3, #-1
46 smw1 $r17, $r0, $r24
47 bnez $r3, 3b
48
49 word_copy_entry:
50 andi $r2, $r2, #31
51
52 beqz $r2, quit_memcpy
53 5:
54 srli $r3, $r2, #2
55 beqz $r3, byte_copy
56 word_copy:
57 lmw1 $r4, $r1, $r4
58 addi $r3, $r3, #-1
59 smw1 $r4, $r0, $r4
60 bnez $r3, word_copy
61 andi $r2, $r2, #3
62 beqz $r2, quit_memcpy
63 byte_copy:
64 lbi1 $r3, $r1, #1
65 addi $r2, $r2, #-1
66
67 sbi1 $r3, $r0, #1
68 bnez $r2, byte_copy
69 quit_memcpy: