1/* 2 Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are met: 6 7 1) Redistributions of source code must retain the above copyright notice, 8 this list of conditions and the following disclaimer. 9 10 2) Redistributions in binary form must reproduce the above copyright notice, 11 this list of conditions and the following disclaimer in the documentation 12 and/or other materials provided with the distribution. 13 14 3) Neither the name of the Synopsys, Inc., nor the names of its contributors 15 may be used to endorse or promote products derived from this software 16 without specific prior written permission. 17 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 POSSIBILITY OF SUCH DAMAGE. 29*/ 30 31/* This implementation is optimized for performance. For code size a generic 32 implementation of this function from newlib/libc/string/strcpy.c will be 33 used. */ 34#include <picolibc.h> 35 36#if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) \ 37 && !defined (__ARC_RF16__) 38 39#include "asm.h" 40 41#if (defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__)) \ 42 && defined (__ARC_BARREL_SHIFTER__) 43 44/* If dst and src are 4 byte aligned, copy 8 bytes at a time. 45 If the src is 4, but not 8 byte aligned, we first read 4 bytes to get 46 it 8 byte aligned. Thus, we can do a little read-ahead, without 47 dereferencing a cache line that we should not touch. 48 Note that short and long instructions have been scheduled to avoid 49 branch stalls. 50 The beq_s to r3z could be made unaligned & long to avoid a stall 51 there, but the it is not likely to be taken often, and it 52 would also be likey to cost an unaligned mispredict at the next call. */ 53 54ENTRY (strcpy) 55 or r2,r0,r1 56 bmsk_s r2,r2,1 57 brne.d r2,0,charloop 58 mov_s r10,r0 59 ld_s r3,[r1,0] 60 mov r8,0x01010101 61 bbit0.d r1,2,loop_start 62 ror r12,r8 63 sub r2,r3,r8 64 bic_s r2,r2,r3 65 tst_s r2,r12 66 bne_l r3z 67 mov_s r4,r3 68 .balign 4 69loop: 70 ld.a r3,[r1,4] 71 st.ab r4,[r10,4] 72loop_start: 73 ld.a r4,[r1,4] 74 sub r2,r3,r8 75 bic_s r2,r2,r3 76 tst_l r2,r12 77 bne_l r3z 78 st.ab r3,[r10,4] 79 sub r2,r4,r8 80 bic r2,r2,r4 81 tst_l r2,r12 82 beq_l loop 83 mov_s r3,r4 84#ifdef __LITTLE_ENDIAN__ 85r3z: bmsk.f r1,r3,7 86 lsr_s r3,r3,8 87#else 88r3z: lsr.f r1,r3,24 89 asl_s r3,r3,8 90#endif 91 bne.d r3z 92 stb.ab r1,[r10,1] 93 j_s [blink] 94 95 .balign 4 96charloop: 97 ldb.ab r3,[r1,1] 98 99 100 brne.d r3,0,charloop 101 stb.ab r3,[r10,1] 102 j [blink] 103ENDFUNC (strcpy) 104#endif /* (__ARC700__ || __ARCEM__ || __ARCHS__) && __ARC_BARREL_SHIFTER__ */ 105 106#endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ 107