blob: b61631e523d4d6c377bc3fa60ef087421fb33c99 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Paul Mundt4466b202008-12-12 16:34:44 +09002/* Cloned and hacked for uClibc by Paul Mundt, December 2003 */
3/* Modified by SuperH, Inc. September 2003 */
4! Entry: arg0: destination
5! arg1: source
6! Exit: result: destination
7!
8! SH5 code Copyright 2002 SuperH Ltd.
9
10#if __BYTE_ORDER == __LITTLE_ENDIAN
11#define SHHI shlld
12#define SHLO shlrd
13#else
14#define SHHI shlrd
15#define SHLO shlld
16#endif
17
18 .section .text..SHmedia32,"ax"
19 .globl strcpy
20 .type strcpy, @function
21 .align 5
22
23strcpy:
24
25 pta/l shortstring,tr1
26 ldlo.q r3,0,r4
27 ptabs r18,tr4
28 shlli r3,3,r7
29 addi r2, 8, r0
30 mcmpeq.b r4,r63,r6
31 SHHI r6,r7,r6
32 bnei/u r6,0,tr1 // shortstring
33 pta/l no_lddst, tr2
34 ori r3,-8,r23
35 sub r2, r23, r0
36 sub r3, r2, r21
37 addi r21, 8, r20
38 ldx.q r0, r21, r5
39 pta/l loop, tr0
40 ori r2,-8,r22
41 mcmpeq.b r5, r63, r6
42 bgt/u r22, r23, tr2 // no_lddst
43
44 // r22 < r23 : Need to do a load from the destination.
45 // r22 == r23 : Doesn't actually need to load from destination,
46 // but still can be handled here.
47 ldlo.q r2, 0, r9
48 movi -1, r8
49 SHLO r8, r7, r8
50 mcmv r4, r8, r9
51 stlo.q r2, 0, r9
52 beqi/l r6, 0, tr0 // loop
53
54 add r5, r63, r4
55 addi r0, 8, r0
56 blink tr1, r63 // shortstring
57no_lddst:
58 // r22 > r23: note that for r22 == r23 the sthi.q would clobber
59 // bytes before the destination region.
60 stlo.q r2, 0, r4
61 SHHI r4, r7, r4
62 sthi.q r0, -1, r4
63 beqi/l r6, 0, tr0 // loop
64
65 add r5, r63, r4
66 addi r0, 8, r0
67shortstring:
68#if __BYTE_ORDER != __LITTLE_ENDIAN
69 pta/l shortstring2,tr1
70 byterev r4,r4
71#endif
72shortstring2:
73 st.b r0,-8,r4
74 andi r4,0xff,r5
75 shlri r4,8,r4
76 addi r0,1,r0
77 bnei/l r5,0,tr1
78 blink tr4,r63 // return
79
80 .balign 8
81loop:
82 stlo.q r0, 0, r5
83 ldx.q r0, r20, r4
84 addi r0, 16, r0
85 sthi.q r0, -9, r5
86 mcmpeq.b r4, r63, r6
87 bnei/u r6, 0, tr1 // shortstring
88 ldx.q r0, r21, r5
89 stlo.q r0, -8, r4
90 sthi.q r0, -1, r4
91 mcmpeq.b r5, r63, r6
92 beqi/l r6, 0, tr0 // loop
93
94 add r5, r63, r4
95 addi r0, 8, r0
96 blink tr1, r63 // shortstring
97
98 .size strcpy,.-strcpy