|
-
-
- #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
- #if defined (__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
-
-
-
- #ifndef __OPT_BIG_BLOCK_SIZE
- #define __OPT_BIG_BLOCK_SIZE (4 * 16)
- #endif
-
- #ifndef __OPT_MID_BLOCK_SIZE
- #define __OPT_MID_BLOCK_SIZE (4 * 4)
- #endif
-
- #if __OPT_BIG_BLOCK_SIZE == 16
- #define BEGIN_UNROLL_BIG_BLOCK \
- .irp offset, 0,4,8,12
- #elif __OPT_BIG_BLOCK_SIZE == 32
- #define BEGIN_UNROLL_BIG_BLOCK \
- .irp offset, 0,4,8,12,16,20,24,28
- #elif __OPT_BIG_BLOCK_SIZE == 64
- #define BEGIN_UNROLL_BIG_BLOCK \
- .irp offset, 0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60
- #else
- #error "Illegal __OPT_BIG_BLOCK_SIZE"
- #endif
-
- #if __OPT_MID_BLOCK_SIZE == 8
- #define BEGIN_UNROLL_MID_BLOCK \
- .irp offset, 0,4
- #elif __OPT_MID_BLOCK_SIZE == 16
- #define BEGIN_UNROLL_MID_BLOCK \
- .irp offset, 0,4,8,12
- #else
- #error "Illegal __OPT_MID_BLOCK_SIZE"
- #endif
-
- #define END_UNROLL .endr
-
- .syntax unified
- .text
- .align 2
- .global memcpy
- .thumb
- .thumb_func
- .type memcpy, %function
- memcpy:
-
-
-
- #ifdef __ARM_FEATURE_UNALIGNED
-
-
- mov ip, r0
- #else
- push {r0}
- #endif
- orr r3, r1, r0
- ands r3, r3, #3
- bne .Lmisaligned_copy
-
- .Lbig_block:
- subs r2, __OPT_BIG_BLOCK_SIZE
- blo .Lmid_block
-
-
- .align 2
- .Lbig_block_loop:
- BEGIN_UNROLL_BIG_BLOCK
- #ifdef __ARM_ARCH_7EM__
- ldr r3, [r1], #4
- str r3, [r0], #4
- END_UNROLL
- #else
- ldr r3, [r1, \offset]
- str r3, [r0, \offset]
- END_UNROLL
- adds r0, __OPT_BIG_BLOCK_SIZE
- adds r1, __OPT_BIG_BLOCK_SIZE
- #endif
- subs r2, __OPT_BIG_BLOCK_SIZE
- bhs .Lbig_block_loop
-
- .Lmid_block:
- adds r2, __OPT_BIG_BLOCK_SIZE - __OPT_MID_BLOCK_SIZE
- blo .Lcopy_word_by_word
-
-
- .align 2
- .Lmid_block_loop:
- BEGIN_UNROLL_MID_BLOCK
- #ifdef __ARM_ARCH_7EM__
- ldr r3, [r1], #4
- str r3, [r0], #4
- END_UNROLL
- #else
- ldr r3, [r1, \offset]
- str r3, [r0, \offset]
- END_UNROLL
- adds r0, __OPT_MID_BLOCK_SIZE
- adds r1, __OPT_MID_BLOCK_SIZE
- #endif
- subs r2, __OPT_MID_BLOCK_SIZE
- bhs .Lmid_block_loop
-
- .Lcopy_word_by_word:
- adds r2, __OPT_MID_BLOCK_SIZE - 4
- blo .Lcopy_less_than_4
-
-
- .align 2
- .Lcopy_word_by_word_loop:
- ldr r3, [r1], #4
- str r3, [r0], #4
- subs r2, #4
- bhs .Lcopy_word_by_word_loop
-
- .Lcopy_less_than_4:
- adds r2, #4
- beq .Ldone
-
- lsls r2, r2, #31
- itt ne
- ldrbne r3, [r1], #1
- strbne r3, [r0], #1
-
- bcc .Ldone
- #ifdef __ARM_FEATURE_UNALIGNED
- ldrh r3, [r1]
- strh r3, [r0]
- #else
- ldrb r3, [r1]
- strb r3, [r0]
- ldrb r3, [r1, #1]
- strb r3, [r0, #1]
- #endif
-
- .Ldone:
- #ifdef __ARM_FEATURE_UNALIGNED
- mov r0, ip
- #else
- pop {r0}
- #endif
- bx lr
-
- .align 2
- .Lmisaligned_copy:
- #ifdef __ARM_FEATURE_UNALIGNED
-
-
- #define Ldst_aligned Lbig_block
-
-
-
-
- cmp r2, #8
- blo .Lbyte_copy
-
-
- lsls r3, r1, #30
- beq .Ldst_aligned
- #else
-
-
- cmp r2, #12
- blo .Lbyte_copy
- #endif
-
-
-
-
- ands r3, r0, #3
- beq .Ldst_aligned
-
- rsb r3, #4
- subs r2, r3
-
- lsls r3, r3, #31
- itt ne
- ldrbne r3, [r1], #1
- strbne r3, [r0], #1
-
- bcc .Ldst_aligned
-
- #ifdef __ARM_FEATURE_UNALIGNED
- ldrh r3, [r1], #2
- strh r3, [r0], #2
- b .Ldst_aligned
- #else
- ldrb r3, [r1], #1
- strb r3, [r0], #1
- ldrb r3, [r1], #1
- strb r3, [r0], #1
-
- .Ldst_aligned:
-
-
- ands r3, r1, #3
- beq .Lbig_block
-
-
-
- push {r4, r5}
- subs r2, #4
-
-
-
- subs r1, r3
- rsb ip, r3, #4
-
-
- ldr r4, [r1], #4
-
- cmp r3, #2
- beq .Lmisaligned_copy_2_2
- cmp r3, #3
- beq .Lmisaligned_copy_3_1
-
- .macro mis_src_copy shift
- 1:
- lsrs r4, r4, \shift
- ldr r3, [r1], #4
- lsls r5, r3, 32-\shift
- orr r4, r4, r5
- str r4, [r0], #4
- mov r4, r3
- subs r2, #4
- bhs 1b
- .endm
-
- .Lmisaligned_copy_1_3:
- mis_src_copy shift=8
- b .Lsrc_misaligned_tail
-
- .Lmisaligned_copy_3_1:
- mis_src_copy shift=24
- b .Lsrc_misaligned_tail
-
- .Lmisaligned_copy_2_2:
-
- mis_src_copy shift=16
-
- .Lsrc_misaligned_tail:
- adds r2, #4
- subs r1, ip
- pop {r4, r5}
-
- #endif
-
- .Lbyte_copy:
- subs r2, #4
- blo .Lcopy_less_than_4
-
- .Lbyte_copy_loop:
- subs r2, #1
- ldrb r3, [r1], #1
- strb r3, [r0], #1
- bhs .Lbyte_copy_loop
-
- ldrb r3, [r1]
- strb r3, [r0]
- ldrb r3, [r1, #1]
- strb r3, [r0, #1]
- ldrb r3, [r1, #2]
- strb r3, [r0, #2]
-
- #ifdef __ARM_FEATURE_UNALIGNED
- mov r0, ip
- #else
- pop {r0}
- #endif
- bx lr
-
- .size memcpy, .-memcpy
- #endif
-
- #endif // __MK20DX128__ || __MK20DX256__ || __MK66FX1M0__
|