[444] | 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/memset.c will be |
---|
| 33 | used. */ |
---|
| 34 | #if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) |
---|
| 35 | |
---|
| 36 | #include "asm.h" |
---|
| 37 | |
---|
| 38 | #if defined (__ARC601__) \ |
---|
| 39 | || (!defined (__ARC_BARREL_SHIFTER__) && !defined (__ARCHS__)) |
---|
| 40 | |
---|
| 41 | /* To deal with alignment/loop issues, SMALL must be at least 2. */ |
---|
| 42 | #define SMALL 8 /* Even faster if aligned. */ |
---|
| 43 | |
---|
| 44 | .global __strncpy_bzero |
---|
| 45 | .hidden __strncpy_bzero |
---|
| 46 | /* __strncpy_bzero provides the following interface to strncpy: |
---|
| 47 | r0: return value |
---|
| 48 | r2: zeroing length |
---|
| 49 | r3: zeroing start address |
---|
| 50 | No attempt is made here for __strncpy_memset to speed up aligned |
---|
| 51 | cases, because the copying of a string presumably leaves start address |
---|
| 52 | and length alignment for the zeroing randomly distributed. */ |
---|
| 53 | |
---|
| 54 | ENTRY (memset) |
---|
| 55 | brls.d r2,SMALL,.Ltiny |
---|
| 56 | mov_s r3,r0 |
---|
| 57 | or r12,r0,r2 |
---|
| 58 | bmsk.f r12,r12,1 |
---|
| 59 | breq_s r1,0,.Lbzero |
---|
| 60 | mov r4,0 |
---|
| 61 | stb.a r1,[sp,-4] |
---|
| 62 | stb r1,[sp,1] |
---|
| 63 | stb r1,[sp,2] |
---|
| 64 | stb r1,[sp,3] |
---|
| 65 | ld.ab r1,[sp,4] |
---|
| 66 | .Lbzero: |
---|
| 67 | beq.d .Laligned |
---|
| 68 | .Lbzero2: |
---|
| 69 | add r6,r2,r3 |
---|
| 70 | .Lnot_tiny: |
---|
| 71 | stb r1,[r6,-1] |
---|
| 72 | bclr r12,r6,0 |
---|
| 73 | stw r1,[r12,-2] |
---|
| 74 | stb.ab r1,[r3,1] |
---|
| 75 | bclr_s r3,r3,0 |
---|
| 76 | stw.ab r1,[r3,2] |
---|
| 77 | bclr_s r3,r3,1 |
---|
| 78 | .Laligned: ; This code address should be aligned for speed. |
---|
| 79 | sub r6,r6,8 |
---|
| 80 | brlo.d r6,r3,.Loop_end |
---|
| 81 | sub r6,r6,8 |
---|
| 82 | 3: |
---|
| 83 | st_l r1,[r3,4] |
---|
| 84 | brhs.d r6,r3,3b |
---|
| 85 | st.ab r1,[r3,8] |
---|
| 86 | .Loop_end: |
---|
| 87 | bic r12,r6,3 |
---|
| 88 | j_s.d [blink] |
---|
| 89 | st_s r1,[r12,12] |
---|
| 90 | .balign 4 |
---|
| 91 | __strncpy_bzero: |
---|
| 92 | brhi.d r2,8,.Lbzero2 |
---|
| 93 | mov_s r1,0 |
---|
| 94 | .Ltiny: |
---|
| 95 | sub_s r2,r2,11 |
---|
| 96 | sub1 r12,pcl,r2 |
---|
| 97 | j_s [r12] |
---|
| 98 | stb_s r1,[r3,7] |
---|
| 99 | stb_s r1,[r3,6] |
---|
| 100 | stb_s r1,[r3,5] |
---|
| 101 | stb_s r1,[r3,4] |
---|
| 102 | stb_s r1,[r3,3] |
---|
| 103 | stb_s r1,[r3,2] |
---|
| 104 | stb_s r1,[r3,1] |
---|
| 105 | stb_s r1,[r3] |
---|
| 106 | j_s [blink] |
---|
| 107 | ENDFUNC (memset) |
---|
| 108 | #endif /* __ARC601__ || (!__ARC_BARREL_SHIFTER__ && !__ARCHS__) */ |
---|
| 109 | |
---|
| 110 | #endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ |
---|