1 /* Optimized strcpy for Xtensa.
2 Copyright (C) 2001, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <bits/xtensa-config.h>
23 #define MASK0 0xff000000
24 #define MASK1 0x00ff0000
25 #define MASK2 0x0000ff00
26 #define MASK3 0x000000ff
28 #define MASK0 0x000000ff
29 #define MASK1 0x0000ff00
30 #define MASK2 0x00ff0000
31 #define MASK3 0xff000000
36 /* a2 = dst, a3 = src */
38 mov a10, a2 /* leave dst in return value register */
43 bbsi.l a3, 0, .Lsrc1mod2
44 bbsi.l a3, 1, .Lsrc2mod4
47 /* Check if the destination is aligned. */
49 bnone a10, a8, .Laligned
53 .Lsrc1mod2: /* src address is odd */
54 l8ui a8, a3, 0 /* get byte 0 */
55 addi a3, a3, 1 /* advance src pointer */
56 s8i a8, a10, 0 /* store byte 0 */
57 beqz a8, 1f /* if byte 0 is zero */
58 addi a10, a10, 1 /* advance dst pointer */
59 bbci.l a3, 1, .Lsrcaligned /* if src is now word-aligned */
61 .Lsrc2mod4: /* src address is 2 mod 4 */
62 l8ui a8, a3, 0 /* get byte 0 */
63 /* 1-cycle interlock */
64 s8i a8, a10, 0 /* store byte 0 */
65 beqz a8, 1f /* if byte 0 is zero */
66 l8ui a8, a3, 1 /* get byte 0 */
67 addi a3, a3, 2 /* advance src pointer */
68 s8i a8, a10, 1 /* store byte 0 */
69 addi a10, a10, 2 /* advance dst pointer */
74 /* dst is word-aligned; src is word-aligned. */
78 /* (2 mod 4) alignment for loop instruction */
80 _movi.n a8, 0 /* set up for the maximum loop count */
81 loop a8, .Lz3 /* loop forever (almost anyway) */
82 l32i a8, a3, 0 /* get word from src */
83 addi a3, a3, 4 /* advance src pointer */
84 bnone a8, a4, .Lz0 /* if byte 0 is zero */
85 bnone a8, a5, .Lz1 /* if byte 1 is zero */
86 bnone a8, a6, .Lz2 /* if byte 2 is zero */
87 s32i a8, a10, 0 /* store word to dst */
88 bnone a8, a7, .Lz3 /* if byte 3 is zero */
89 addi a10, a10, 4 /* advance dst pointer */
91 #else /* !XCHAL_HAVE_LOOPS */
93 1: addi a10, a10, 4 /* advance dst pointer */
95 l32i a8, a3, 0 /* get word from src */
96 addi a3, a3, 4 /* advance src pointer */
97 bnone a8, a4, .Lz0 /* if byte 0 is zero */
98 bnone a8, a5, .Lz1 /* if byte 1 is zero */
99 bnone a8, a6, .Lz2 /* if byte 2 is zero */
100 s32i a8, a10, 0 /* store word to dst */
101 bany a8, a7, 1b /* if byte 3 is zero */
102 #endif /* !XCHAL_HAVE_LOOPS */
104 .Lz3: /* Byte 3 is zero. */
107 .Lz0: /* Byte 0 is zero. */
114 .Lz1: /* Byte 1 is zero. */
121 .Lz2: /* Byte 2 is zero. */
131 /* (2 mod 4) alignment for loop instruction */
135 _movi.n a8, 0 /* set up for the maximum loop count */
136 loop a8, 2f /* loop forever (almost anyway) */
149 libc_hidden_def (strcpy)