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 ENTRY(memcmp)
0008     /* Test if len less than 4 bytes.  */
0009     mov r3, r0
0010     movi    r0, 0
0011     mov r12, r4
0012     cmplti  r2, 4
0013     bt  .L_compare_by_byte
0014 
0015     andi    r13, r0, 3
0016     movi    r19, 4
0017 
0018     /* Test if s1 is not 4 bytes aligned.  */
0019     bnez    r13, .L_s1_not_aligned
0020 
0021     LABLE_ALIGN
0022 .L_s1_aligned:
0023     /* If dest is aligned, then copy.  */
0024     zext    r18, r2, 31, 4
0025     /* Test if len less than 16 bytes.  */
0026     bez r18, .L_compare_by_word
0027 
0028 .L_compare_by_4word:
0029     /* If aligned, load word each time.  */
0030     ldw r20, (r3, 0)
0031     ldw r21, (r1, 0)
0032     /* If s1[i] != s2[i], goto .L_byte_check.  */
0033     cmpne   r20, r21
0034     bt  .L_byte_check
0035 
0036     ldw r20, (r3, 4)
0037     ldw r21, (r1, 4)
0038     cmpne   r20, r21
0039     bt  .L_byte_check
0040 
0041     ldw r20, (r3, 8)
0042     ldw r21, (r1, 8)
0043     cmpne   r20, r21
0044     bt  .L_byte_check
0045 
0046     ldw r20, (r3, 12)
0047     ldw r21, (r1, 12)
0048     cmpne   r20, r21
0049     bt  .L_byte_check
0050 
0051     PRE_BNEZAD (r18)
0052     addi    a3, 16
0053     addi    a1, 16
0054 
0055     BNEZAD (r18, .L_compare_by_4word)
0056 
0057 .L_compare_by_word:
0058     zext    r18, r2, 3, 2
0059     bez r18, .L_compare_by_byte
0060 .L_compare_by_word_loop:
0061     ldw r20, (r3, 0)
0062     ldw r21, (r1, 0)
0063     addi    r3, 4
0064     PRE_BNEZAD (r18)
0065     cmpne   r20, r21
0066     addi    r1, 4
0067     bt  .L_byte_check
0068     BNEZAD (r18, .L_compare_by_word_loop)
0069 
0070 .L_compare_by_byte:
0071         zext    r18, r2, 1, 0
0072         bez     r18, .L_return
0073 .L_compare_by_byte_loop:
0074         ldb     r0, (r3, 0)
0075         ldb     r4, (r1, 0)
0076         addi    r3, 1
0077         subu    r0, r4
0078         PRE_BNEZAD (r18)
0079         addi    r1, 1
0080         bnez    r0, .L_return
0081         BNEZAD (r18, .L_compare_by_byte_loop)
0082 
0083 .L_return:
0084         mov     r4, r12
0085         rts
0086 
0087 # ifdef __CSKYBE__
0088 /* d[i] != s[i] in word, so we check byte 0.  */
0089 .L_byte_check:
0090         xtrb0   r0, r20
0091         xtrb0   r2, r21
0092         subu    r0, r2
0093         bnez    r0, .L_return
0094 
0095         /* check byte 1 */
0096         xtrb1   r0, r20
0097         xtrb1   r2, r21
0098         subu    r0, r2
0099         bnez    r0, .L_return
0100 
0101         /* check byte 2 */
0102         xtrb2   r0, r20
0103         xtrb2   r2, r21
0104         subu    r0, r2
0105         bnez    r0, .L_return
0106 
0107         /* check byte 3 */
0108         xtrb3   r0, r20
0109         xtrb3   r2, r21
0110         subu    r0, r2
0111 # else
0112 /* s1[i] != s2[i] in word, so we check byte 3.  */
0113 .L_byte_check:
0114     xtrb3   r0, r20
0115     xtrb3   r2, r21
0116         subu    r0, r2
0117         bnez    r0, .L_return
0118 
0119     /* check byte 2 */
0120     xtrb2   r0, r20
0121     xtrb2   r2, r21
0122         subu    r0, r2
0123         bnez    r0, .L_return
0124 
0125     /* check byte 1 */
0126     xtrb1   r0, r20
0127     xtrb1   r2, r21
0128     subu    r0, r2
0129     bnez    r0, .L_return
0130 
0131     /* check byte 0 */
0132     xtrb0   r0, r20
0133     xtrb0   r2, r21
0134     subu    r0, r2
0135     br  .L_return
0136 # endif /* !__CSKYBE__ */
0137 
0138 /* Compare when s1 is not aligned.  */
0139 .L_s1_not_aligned:
0140     sub r13, r19, r13
0141     sub r2, r13
0142 .L_s1_not_aligned_loop:
0143     ldb r0, (r3, 0)
0144     ldb r4, (r1, 0)
0145     addi    r3, 1
0146     subu    r0, r4
0147     PRE_BNEZAD (r13)
0148     addi    r1, 1
0149     bnez    r0, .L_return
0150     BNEZAD (r13, .L_s1_not_aligned_loop)
0151     br  .L_s1_aligned
0152 ENDPROC(memcmp)