1/* 2 Copyright (c) 2015, 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/strlen.c will be 33 used. */ 34#if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) 35 36#include "asm.h" 37#if (defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__)) \ 38 && defined (__ARC_NORM__) && defined (__ARC_BARREL_SHIFTER__) 39 40ENTRY (strlen) 41 or r3,r0,7 42 ld r2,[r3,-7] 43 ld.a r6,[r3,-3] 44 mov r4,0x01010101 45 ; uses long immediate 46#ifdef __LITTLE_ENDIAN__ 47 asl_s r1,r0,3 48 btst_s r0,2 49 asl r7,r4,r1 50 ror r5,r4 51 sub r1,r2,r7 52 bic_s r1,r1,r2 53 mov.eq r7,r4 54 sub r12,r6,r7 55 bic r12,r12,r6 56 or.eq r12,r12,r1 57 and r12,r12,r5 58 brne r12,0,.Learly_end 59#else /* BIG ENDIAN */ 60 ror r5,r4 61 btst_s r0,2 62 mov_s r1,31 63 sub3 r7,r1,r0 64 sub r1,r2,r4 65 bic_s r1,r1,r2 66 bmsk r1,r1,r7 67 sub r12,r6,r4 68 bic r12,r12,r6 69 bmsk.ne r12,r12,r7 70 or.eq r12,r12,r1 71 and r12,r12,r5 72 brne r12,0,.Learly_end 73#endif /* ENDIAN */ 74 75.Loop: 76 ld_s r2,[r3,4] 77 ld.a r6,[r3,8] 78 ; stall for load result 79 sub r1,r2,r4 80 bic_s r1,r1,r2 81 sub r12,r6,r4 82 bic r12,r12,r6 83 or_l r12,r12,r1 84 and r12,r12,r5 85 breq_l r12,0,.Loop 86.Lend: 87 and.f r1,r1,r5 88 sub.ne r3,r3,4 89 mov.eq r1,r12 90#ifdef __LITTLE_ENDIAN__ 91 sub_s r2,r1,1 92 bic_s r2,r2,r1 93 norm r1,r2 94 sub_s r0,r0,3 95 lsr_s r1,r1,3 96 sub r0,r3,r0 97 j_s.d [blink] 98 sub_l r0,r0,r1 99#else /* BIG ENDIAN */ 100 lsr_s r1,r1,7 101 mov.eq r2,r6 102 bic_s r1,r1,r2 103 norm r1,r1 104 sub r0,r3,r0 105 lsr_s r1,r1,3 106 j_s.d [blink] 107 add_l r0,r0,r1 108#endif /* ENDIAN */ 109.Learly_end: 110 b.d .Lend 111 sub_s.ne r1,r1,r1 112ENDFUNC (strlen) 113#endif /* (__ARC700__ || __ARCEM__ || __ARCHS__) && __ARC_NORM__ 114 && __ARC_BARREL_SHIFTER__ */ 115 116#endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ 117