~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to src/linaro-a9/memcpy-hybrid.S

  • Committer: Will Newton
  • Date: 2013-03-26 10:19:35 UTC
  • Revision ID: will.newton@linaro.org-20130326101935-c4i81dht78p9voqf
Integrate NEON/VFP/ARM optimised memcpy implementation.
Add --with-vfp configure option to allow testing VFP code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2010-2011, Linaro Limited
2
 
   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
6
 
   are met:
7
 
 
8
 
      * Redistributions of source code must retain the above copyright
9
 
      notice, this list of conditions and the following disclaimer.
10
 
 
11
 
      * Redistributions in binary form must reproduce the above copyright
12
 
      notice, this list of conditions and the following disclaimer in the
13
 
      documentation and/or other materials provided with the distribution.
14
 
 
15
 
      * Neither the name of Linaro Limited nor the names of its
16
 
      contributors may be used to endorse or promote products derived
17
 
      from this software without specific prior written permission.
18
 
 
19
 
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
 
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
 
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
 
   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
 
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
 
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
 
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
 
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
 
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
 
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 
 
31
 
   Written by Dave Gilbert <david.gilbert@linaro.org>
32
 
 
33
 
   This memcpy routine is optimised on a Cortex-A9 and should work on
34
 
   all ARMv7 processors with NEON. */
35
 
 
36
 
@ 2011-09-01 david.gilbert@linaro.org
37
 
@    Extracted from local git 2f11b436
38
 
 
39
 
        .syntax unified
40
 
        .arch armv7-a
41
 
 
42
 
@ this lets us check a flag in a 00/ff byte easily in either endianness
43
 
#ifdef __ARMEB__
44
 
#define CHARTSTMASK(c) 1<<(31-(c*8))
45
 
#else
46
 
#define CHARTSTMASK(c) 1<<(c*8)
47
 
#endif
48
 
        .text
49
 
        .thumb
50
 
 
51
 
@ ---------------------------------------------------------------------------
52
 
        .thumb_func
53
 
        .align 2
54
 
        .p2align 4,,15
55
 
        .global memcpy
56
 
        .type memcpy,%function
57
 
memcpy:
58
 
        @ r0 = dest
59
 
        @ r1 = source
60
 
        @ r2 = count
61
 
        @ returns dest in r0
62
 
        @ Overlaps of source/dest not allowed according to spec
63
 
        @ Note this routine relies on v7 misaligned loads/stores
64
 
        pld     [r1]
65
 
        mov     r12, r0         @ stash original r0
66
 
        cmp     r2,#32
67
 
        blt     10f             @ take the small copy case separately
68
 
 
69
 
        @ test for either source or destination being misaligned
70
 
        @ (We only rely on word align)
71
 
        tst     r0,#3
72
 
        it      eq
73
 
        tsteq   r1,#3
74
 
        bne     30f             @ misaligned case
75
 
 
76
 
4:
77
 
        @ at this point we are word (or better) aligned and have at least
78
 
        @ 32 bytes to play with
79
 
 
80
 
        @ If it's a huge copy,  try Neon
81
 
        cmp     r2, #128*1024
82
 
        bge     35f             @ Sharing general non-aligned case here, aligned could be faster
83
 
        
84
 
        push    {r3,r4,r5,r6,r7,r8,r10,r11}
85
 
5:
86
 
        ldmia   r1!,{r3,r4,r5,r6,r7,r8,r10,r11}
87
 
        sub     r2,r2,#32
88
 
        pld     [r1,#96]
89
 
        cmp     r2,#32
90
 
        stmia   r0!,{r3,r4,r5,r6,r7,r8,r10,r11}
91
 
        bge     5b
92
 
 
93
 
        pop     {r3,r4,r5,r6,r7,r8,r10,r11}
94
 
        @ We are now down to less than 32 bytes
95
 
        cbz     r2,15f          @ quick exit for the case where we copied a multiple of 32
96
 
 
97
 
10:  @ small copies (not necessarily aligned - note might be slightly more than 32bytes)
98
 
        cmp     r2,#4
99
 
        blt     12f
100
 
11:
101
 
        sub     r2,r2,#4
102
 
        cmp     r2,#4
103
 
        ldr     r3, [r1],#4
104
 
        str     r3, [r0],#4
105
 
        bge     11b
106
 
12:
107
 
        tst     r2,#2
108
 
        itt     ne
109
 
        ldrhne  r3, [r1],#2
110
 
        strhne  r3, [r0],#2
111
 
        
112
 
        tst     r2,#1
113
 
        itt     ne
114
 
        ldrbne  r3, [r1],#1
115
 
        strbne  r3, [r0],#1
116
 
        
117
 
15:  @ exit
118
 
        mov     r0,r12          @ restore r0
119
 
        bx      lr
120
 
 
121
 
        .align 2
122
 
        .p2align 4,,15
123
 
30:  @ non-aligned - at least 32 bytes to play with
124
 
        @ Test for co-misalignment
125
 
        eor     r3, r0, r1
126
 
        tst     r3,#3
127
 
        beq     50f
128
 
 
129
 
        @ Use Neon for misaligned
130
 
35:
131
 
        vld1.8  {d0,d1,d2,d3}, [r1]!
132
 
        sub     r2,r2,#32
133
 
        cmp     r2,#32
134
 
        pld     [r1,#96]
135
 
        vst1.8  {d0,d1,d2,d3}, [r0]!
136
 
        bge     35b
137
 
        b       10b             @ TODO: Probably a bad idea to switch to ARM at this point
138
 
 
139
 
        .align 2
140
 
        .p2align 4,,15
141
 
50: @ Co-misaligned
142
 
        @ At this point we've got at least 32 bytes
143
 
51:
144
 
        ldrb    r3,[r1],#1
145
 
        sub     r2,r2,#1
146
 
        strb    r3,[r0],#1
147
 
        tst     r0,#7
148
 
        bne     51b
149
 
 
150
 
        cmp     r2,#32
151
 
        blt     10b
152
 
        b       4b