blob: 4f338eec33657f52c9ea8181a8b80c1a383b0e08 [file] [log] [blame]
Claudiu Zissulescu1f7e3dc2014-11-21 13:39:25 +05301/*
2 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/linkage.h>
10
11ENTRY(strcmp)
12 or r2, r0, r1
13 bmsk_s r2, r2, 1
14 brne r2, 0, @.Lcharloop
15
16;;; s1 and s2 are word aligned
17 ld.ab r2, [r0, 4]
18
19 mov_s r12, 0x01010101
20 ror r11, r12
21 .align 4
22.LwordLoop:
23 ld.ab r3, [r1, 4]
24 ;; Detect NULL char in str1
25 sub r4, r2, r12
26 ld.ab r5, [r0, 4]
27 bic r4, r4, r2
28 and r4, r4, r11
29 brne.d.nt r4, 0, .LfoundNULL
30 ;; Check if the read locations are the same
31 cmp r2, r3
32 beq.d .LwordLoop
33 mov.eq r2, r5
34
35 ;; A match is found, spot it out
36#ifdef __LITTLE_ENDIAN__
37 swape r3, r3
38 mov_s r0, 1
39 swape r2, r2
40#else
41 mov_s r0, 1
42#endif
43 cmp_s r2, r3
44 j_s.d [blink]
45 bset.lo r0, r0, 31
46
47 .align 4
48.LfoundNULL:
49#ifdef __BIG_ENDIAN__
50 swape r4, r4
51 swape r2, r2
52 swape r3, r3
53#endif
54 ;; Find null byte
55 ffs r0, r4
56 bmsk r2, r2, r0
57 bmsk r3, r3, r0
58 swape r2, r2
59 swape r3, r3
60 ;; make the return value
61 sub.f r0, r2, r3
62 mov.hi r0, 1
63 j_s.d [blink]
64 bset.lo r0, r0, 31
65
66 .align 4
67.Lcharloop:
68 ldb.ab r2, [r0, 1]
69 ldb.ab r3, [r1, 1]
70 nop
71 breq r2, 0, .Lcmpend
72 breq r2, r3, .Lcharloop
73
74 .align 4
75.Lcmpend:
76 j_s.d [blink]
77 sub r0, r2, r3
78END(strcmp)