Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
0003 
0004 #include <linux/linkage.h>
0005 #include "sysdep.h"
0006 
0007     .weak memmove
0008 ENTRY(__memmove)
0009 ENTRY(memmove)
0010     subu    r3, r0, r1
0011     cmphs   r3, r2
0012     bt  memcpy
0013 
0014     mov r12, r0
0015     addu    r0, r0, r2
0016     addu    r1, r1, r2
0017 
0018     /* Test if len less than 4 bytes.  */
0019     cmplti  r2, 4
0020     bt  .L_copy_by_byte
0021 
0022     andi    r13, r0, 3
0023     /* Test if dest is not 4 bytes aligned.  */
0024     bnez    r13, .L_dest_not_aligned
0025     /* Hardware can handle unaligned access directly.  */
0026 .L_dest_aligned:
0027     /* If dest is aligned, then copy.  */
0028     zext    r18, r2, 31, 4
0029     /* Test if len less than 16 bytes.  */
0030     bez r18, .L_len_less_16bytes
0031     movi    r19, 0
0032 
0033     /* len > 16 bytes */
0034     LABLE_ALIGN
0035 .L_len_larger_16bytes:
0036     subi    r1, 16
0037     subi    r0, 16
0038 #if defined(__CK860__)
0039     ldw r3, (r1, 12)
0040     stw r3, (r0, 12)
0041     ldw r3, (r1, 8)
0042     stw r3, (r0, 8)
0043     ldw r3, (r1, 4)
0044     stw r3, (r0, 4)
0045     ldw r3, (r1, 0)
0046     stw r3, (r0, 0)
0047 #else
0048     ldw r20, (r1, 0)
0049     ldw r21, (r1, 4)
0050     ldw r22, (r1, 8)
0051     ldw r23, (r1, 12)
0052     stw r20, (r0, 0)
0053     stw r21, (r0, 4)
0054     stw r22, (r0, 8)
0055     stw r23, (r0, 12)
0056     PRE_BNEZAD (r18)
0057 #endif
0058     BNEZAD (r18, .L_len_larger_16bytes)
0059 
0060 .L_len_less_16bytes:
0061     zext    r18, r2, 3, 2
0062     bez r18, .L_copy_by_byte
0063 .L_len_less_16bytes_loop:
0064     subi    r1, 4
0065     subi    r0, 4
0066     ldw r3, (r1, 0)
0067     PRE_BNEZAD (r18)
0068     stw r3, (r0, 0)
0069     BNEZAD (r18, .L_len_less_16bytes_loop)
0070 
0071     /* Test if len less than 4 bytes.  */
0072 .L_copy_by_byte:
0073     zext    r18, r2, 1, 0
0074     bez r18, .L_return
0075 .L_copy_by_byte_loop:
0076     subi    r1, 1
0077     subi    r0, 1
0078     ldb r3, (r1, 0)
0079     PRE_BNEZAD (r18)
0080     stb r3, (r0, 0)
0081     BNEZAD (r18, .L_copy_by_byte_loop)
0082 
0083 .L_return:
0084     mov r0, r12
0085     rts
0086 
0087     /* If dest is not aligned, just copy some bytes makes the dest
0088        align.  */
0089 .L_dest_not_aligned:
0090     sub r2, r13
0091 .L_dest_not_aligned_loop:
0092     subi    r1, 1
0093     subi    r0, 1
0094     /* Makes the dest align.  */
0095     ldb r3, (r1, 0)
0096     PRE_BNEZAD (r13)
0097     stb r3, (r0, 0)
0098     BNEZAD (r13, .L_dest_not_aligned_loop)
0099     cmplti  r2, 4
0100     bt  .L_copy_by_byte
0101     /* Check whether the src is aligned.  */
0102     jbr .L_dest_aligned
0103 ENDPROC(memmove)
0104 ENDPROC(__memmove)