OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [machine/] [xscale/] [memcmp.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
#if defined __thumb__
2
 
3
#include "../../string/memcmp.c"
4
 
5
#else
6
 
7
#include <string.h>
8
#include "xscale.h"
9
 
10
int
11
memcmp (const void * s1, const void * s2, size_t len)
12
{
13
  int result;
14
  asm (
15
#ifndef __OPTIMIZE_SIZE__ 
16
"
17
        cmp     %2, #0x3        @ Is the length a multiple of four ?
18
        bls     6f              @ no  = goto SLOW CHECK
19
        and     r2, %0, #0x3    @ get alignment of first pointer
20
        and     r3, %1, #0x3    @ get alignment of second pointer
21
        cmp     r2, r3          @ Do the two pointers share the same alignment ?
22
        bne     6f              @ no = goto SLOW CHECK
23
        mov     lr, %0          @ copy first pointer into LR
24
        mov     r4, %1          @ copy second pointer into R4
25
        cmp     r2, #0x0        @ Are we comparing word aligned pointers ?
26
        beq     3f              @ yes = goto START WORD CHECK LOOP
27
        b       1f              @ jump to LOOP TEST
28
0:                             @ LOOP START
29
        ldrb    r2, [lr], #1    @ load byte from LR, post inc.
30
"       PRELOADSTR("lr") "      @ preload
31
        ldrb    r3, [r4], #1    @ load byte from R4, post inc.
32
"       PRELOADSTR("r4") "      @ preload
33
        cmp     r2, r3          @ are the two bytes the same ?
34
        bne     5f              @ no = goto EXIT
35
        tst     lr, #0x3        @ has the LR become word aligned ?
36
        bne     1f              @ no = skip the next test
37
        cmp     %2, #4          @ is the count >= 4 ?
38
        bhs     3f              @ yes = goto START WORD CHECK LOOP
39
1:                             @ LOOP TEST
40
        sub     %2, %2, #1      @ decrement count by one
41
        cmn     %2, #0x1        @ has the count reached -1 ?
42
        bne     0b              @ no = loop back to LOOP START
43
        b       4f              @ goto PASS END
44
 
45
0:                             @ ??
46
        cmp     %2, #0x7        @ Is the count a multiple of 8 ?
47
        bls     3f              @ no = goto ???
48
        ldmia   lr,{r2, r3}     @ get two words from first pointer, post inc
49
        ldmia   r4,{r5, r6}     @ get two words from second pointer, post inc
50
        sub     %2, %2, #0x4    @ decrement count by 4
51
        cmp     r2, r5          @ has the count reached ????
52
        bne     1f              @ no = goto
53
        sub     %2, %2, #0x4    @ decrement the count by 4
54
        add     lr, lr, #0x4    @ add 4 to first pointer
55
        add     r4, r4, #0x4    @ add 4 to second pointer
56
        cmp     r3, r6          @ ???
57
        beq     0b              @ goto ???
58
1:                             @ ??
59
        add     %2, %2, #0x4    @ Add four to count
60
        sub     %0, lr, #0x4    @ decrement first pointer by 4
61
        sub     %1, r4, #0x4    @ decrement second pointer by 4
62
        b       6f              @ goto SLOW CHECK
63
 
64
3:                             @ START WORD CHECK LOOP
65
        cmp     %2, #0x3        @ is the count <= 3 ?
66
        bls     1f              @ yes = goto CHECK BYTES BY HAND
67
        ldr     r2, [lr], #4    @ get word from LR, post inc
68
        ldr     r3, [r4], #4    @ get word from R4, post inc
69
        sub     %2, %2, #4      @ decrement count by 4
70
        cmp     r2, r3          @ are the two words the same ?
71
        bne     1f              @ no = goto CHECK WORD CONTENTS
72
0:                             @ WORD CHECK LOOP
73
        cmp     %2, #0x3        @ is the count <= 3 ?
74
        bls     1f              @ yes = goto CHECK BYTES BY HAND
75
        ldr     r2, [lr], #4    @ load word from LR, post inc
76
"       PRELOADSTR("lr") "      @ preload
77
        ldr     r3, [r4], #4    @ load word from R4, post inc
78
"       PRELOADSTR("r4") "      @ preload
79
        sub     %2, %2, #4      @ decrement count by 4
80
        cmp     r2, r3          @ are the two words the same ?
81
        beq     0b              @ yes = goto WORD CHECK LOOP
82
1:                             @ CHECK BYTES BY HAND
83
        sub     %0, lr, #0x4    @ move LR back a word and put into first pointer
84
        sub     %1, r4, #0x4    @ move R4 back a word and put into second pointer
85
        add     %2, %2, #4      @ increment the count by 4
86
                                @ fall through into SLOW CHECK"
87
#endif /* !__OPTIMIZE_SIZE__ */
88
"
89
6:                             @ SLOW CHECK
90
        sub     %2, %2, #1      @ Decrement the count by one
91
        cmn     %2, #0x1        @ Has the count reached -1 ?
92
        beq     4f              @ Yes - we are finished, goto PASS END
93
0:                             @ LOOP1
94
        ldrb    r2, [%0], #1    @ get byte from first pointer
95
"       PRELOADSTR("%0") "      @ preload first pointer
96
        ldrb    r3, [%1], #1    @ get byte from second pointer
97
"       PRELOADSTR("%1") "      @ preload second pointer
98
        cmp     r2, r3          @ compare the two loaded bytes
99
        bne     5f              @ if they are not equal goto EXIT
100
        sub     %2, %2, #1      @ decremented count by 1
101
        cmn     %2, #0x1        @ has the count reached -1 ?
102
        bne     0b              @ no = then go back to LOOP1
103
4:                             @ PASS END
104
        mov     r3, r2          @ Default return value is 0
105
5:                             @ EXIT
106
        rsb     %0, r3, r2      @ return difference between last two bytes loaded"
107
       : "=r" (result), "=&r" (s2), "=&r" (len)
108
       : "0" (s1), "1" (s2), "2" (len)
109
       : "r2", "r3", "r4", "r5", "r6", "cc", "lr");
110
  return result;
111
}
112
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.