[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/strcmp.c will be |
---|
| 33 | used. */ |
---|
| 34 | #if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) |
---|
| 35 | |
---|
| 36 | #include "asm.h" |
---|
| 37 | |
---|
| 38 | #ifdef __ARCHS__ |
---|
| 39 | ENTRY (strcmp) |
---|
| 40 | or r2, r0, r1 |
---|
| 41 | bmsk_s r2, r2, 1 |
---|
| 42 | brne r2, 0, @.Lcharloop |
---|
| 43 | |
---|
| 44 | ; s1 and s2 are word aligned |
---|
| 45 | ld.ab r2, [r0, 4] |
---|
| 46 | |
---|
| 47 | mov_s r12, 0x01010101 |
---|
| 48 | ror r11, r12 |
---|
| 49 | .align 4 |
---|
| 50 | .LwordLoop: |
---|
| 51 | ld.ab r3, [r1, 4] |
---|
| 52 | ; Detect NULL char in str1 |
---|
| 53 | sub r4, r2, r12 |
---|
| 54 | ld.ab r5, [r0, 4] |
---|
| 55 | bic r4, r4, r2 |
---|
| 56 | and r4, r4, r11 |
---|
| 57 | brne.d.nt r4, 0, .LfoundNULL |
---|
| 58 | ; Check if the read locations are the same |
---|
| 59 | cmp r2, r3 |
---|
| 60 | beq.d .LwordLoop |
---|
| 61 | mov.eq r2, r5 |
---|
| 62 | |
---|
| 63 | ; A match is found, spot it out |
---|
| 64 | #ifdef __LITTLE_ENDIAN__ |
---|
| 65 | swape r3, r3 |
---|
| 66 | mov_s r0, 1 |
---|
| 67 | swape r2, r2 |
---|
| 68 | #else |
---|
| 69 | mov_s r0, 1 |
---|
| 70 | #endif |
---|
| 71 | cmp_s r2, r3 |
---|
| 72 | j_s.d [blink] |
---|
| 73 | bset.lo r0, r0, 31 |
---|
| 74 | |
---|
| 75 | .align 4 |
---|
| 76 | .LfoundNULL: |
---|
| 77 | #ifdef __BIG_ENDIAN__ |
---|
| 78 | swape r4, r4 |
---|
| 79 | swape r2, r2 |
---|
| 80 | swape r3, r3 |
---|
| 81 | #endif |
---|
| 82 | ; Find null byte |
---|
| 83 | ffs r0, r4 |
---|
| 84 | bmsk r2, r2, r0 |
---|
| 85 | bmsk r3, r3, r0 |
---|
| 86 | swape r2, r2 |
---|
| 87 | swape r3, r3 |
---|
| 88 | ; make the return value |
---|
| 89 | sub.f r0, r2, r3 |
---|
| 90 | mov.hi r0, 1 |
---|
| 91 | j_s.d [blink] |
---|
| 92 | bset.lo r0, r0, 31 |
---|
| 93 | |
---|
| 94 | .align 4 |
---|
| 95 | .Lcharloop: |
---|
| 96 | ldb.ab r2, [r0, 1] |
---|
| 97 | ldb.ab r3, [r1, 1] |
---|
| 98 | nop |
---|
| 99 | breq r2, 0, .Lcmpend |
---|
| 100 | breq r2, r3, .Lcharloop |
---|
| 101 | |
---|
| 102 | .align 4 |
---|
| 103 | .Lcmpend: |
---|
| 104 | j_s.d [blink] |
---|
| 105 | sub r0, r2, r3 |
---|
| 106 | ENDFUNC (strcmp) |
---|
| 107 | #endif /* __ARCHS__ */ |
---|
| 108 | |
---|
| 109 | #endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ |
---|