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

« back to all changes in this revision

Viewing changes to src/neon/memcpy.S

  • Committer: Michael Hope
  • Date: 2010-09-02 00:46:57 UTC
  • Revision ID: michael.hope@linaro.org-20100902004657-4q6rn5888130zr3o
Pulled in the routines and packaged them up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 The Android Open Source Project
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *  * Redistributions of source code must retain the above copyright
 
9
 *    notice, this list of conditions and the following disclaimer.
 
10
 *  * Redistributions in binary form must reproduce the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer in
 
12
 *    the documentation and/or other materials provided with the
 
13
 *    distribution.
 
14
 *
 
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
16
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
17
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
18
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
19
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
20
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
21
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 
22
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 
23
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
24
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
25
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
26
 * SUCH DAMAGE.
 
27
 */
 
28
 
 
29
        .text
 
30
        .fpu    neon
 
31
 
 
32
        .global memcpy
 
33
        .type memcpy, %function
 
34
        .align 4
 
35
 
 
36
/* a prefetch distance of 4 cache-lines works best experimentally */
 
37
#define CACHE_LINE_SIZE     64
 
38
#define PREFETCH_DISTANCE   (CACHE_LINE_SIZE*4)
 
39
 
 
40
memcpy:
 
41
        .fnstart
 
42
        .save       {r0, lr}
 
43
        stmfd       sp!, {r0, lr}
 
44
 
 
45
        /* start preloading as early as possible */
 
46
        pld         [r1, #(CACHE_LINE_SIZE*0)]
 
47
        pld         [r1, #(CACHE_LINE_SIZE*1)]
 
48
 
 
49
        /* do we have at least 16-bytes to copy (needed for alignment below) */
 
50
        cmp         r2, #16
 
51
        blo         5f
 
52
 
 
53
        /* align destination to half cache-line for the write-buffer */
 
54
        rsb         r3, r0, #0
 
55
        ands        r3, r3, #0xF
 
56
        beq         0f
 
57
 
 
58
        /* copy up to 15-bytes (count in r3) */
 
59
        sub         r2, r2, r3
 
60
        movs        ip, r3, lsl #31
 
61
        ldrmib      lr, [r1], #1
 
62
        strmib      lr, [r0], #1
 
63
        ldrcsb      ip, [r1], #1
 
64
        ldrcsb      lr, [r1], #1
 
65
        strcsb      ip, [r0], #1
 
66
        strcsb      lr, [r0], #1
 
67
        movs        ip, r3, lsl #29
 
68
        bge         1f
 
69
        // copies 4 bytes, destination 32-bits aligned
 
70
        vld4.8      {d0[0], d1[0], d2[0], d3[0]}, [r1]!
 
71
        vst4.8      {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
 
72
1:      bcc         2f
 
73
        // copies 8 bytes, destination 64-bits aligned
 
74
        vld1.8      {d0}, [r1]!
 
75
        vst1.8      {d0}, [r0, :64]!
 
76
2:
 
77
 
 
78
0:      /* preload immediately the next cache line, which we may need */
 
79
        pld         [r1, #(CACHE_LINE_SIZE*0)]
 
80
        pld         [r1, #(CACHE_LINE_SIZE*1)]
 
81
 
 
82
        /* make sure we have at least 64 bytes to copy */
 
83
        subs        r2, r2, #64
 
84
        blo         2f
 
85
 
 
86
        /* preload all the cache lines we need.
 
87
         * NOTE: the number of pld below depends on PREFETCH_DISTANCE,
 
88
         * ideally would would increase the distance in the main loop to
 
89
         * avoid the goofy code below. In practice this doesn't seem to make
 
90
         * a big difference.
 
91
         */
 
92
        pld         [r1, #(CACHE_LINE_SIZE*2)]
 
93
        pld         [r1, #(CACHE_LINE_SIZE*3)]
 
94
        pld         [r1, #(PREFETCH_DISTANCE)]
 
95
 
 
96
1:      /* The main loop copies 64 bytes at a time */
 
97
        vld1.8      {d0  - d3},   [r1]!
 
98
        vld1.8      {d4  - d7},   [r1]!
 
99
        pld         [r1, #(PREFETCH_DISTANCE)]
 
100
        subs        r2, r2, #64
 
101
        vst1.8      {d0  - d3},   [r0, :128]!
 
102
        vst1.8      {d4  - d7},   [r0, :128]!
 
103
        bhs         1b
 
104
 
 
105
2:      /* fix-up the remaining count and make sure we have >= 32 bytes left */
 
106
        add         r2, r2, #64
 
107
        subs        r2, r2, #32
 
108
        blo         4f
 
109
 
 
110
3:      /* 32 bytes at a time. These cache lines were already preloaded */
 
111
        vld1.8      {d0 - d3},  [r1]!
 
112
        subs        r2, r2, #32
 
113
        vst1.8      {d0 - d3},  [r0, :128]!
 
114
        bhs         3b
 
115
 
 
116
4:      /* less than 32 left */
 
117
        add         r2, r2, #32
 
118
        tst         r2, #0x10
 
119
        beq         5f
 
120
        // copies 16 bytes, 128-bits aligned
 
121
        vld1.8      {d0, d1}, [r1]!
 
122
        vst1.8      {d0, d1}, [r0, :128]!
 
123
 
 
124
5:      /* copy up to 15-bytes (count in r2) */
 
125
        movs        ip, r2, lsl #29
 
126
        bcc         1f
 
127
        vld1.8      {d0}, [r1]!
 
128
        vst1.8      {d0}, [r0]!
 
129
1:      bge         2f
 
130
        vld4.8      {d0[0], d1[0], d2[0], d3[0]}, [r1]!
 
131
        vst4.8      {d0[0], d1[0], d2[0], d3[0]}, [r0]!
 
132
2:      movs        ip, r2, lsl #31
 
133
        ldrmib      r3, [r1], #1
 
134
        ldrcsb      ip, [r1], #1
 
135
        ldrcsb      lr, [r1], #1
 
136
        strmib      r3, [r0], #1
 
137
        strcsb      ip, [r0], #1
 
138
        strcsb      lr, [r0], #1
 
139
 
 
140
        ldmfd       sp!, {r0, lr}
 
141
        bx          lr
 
142
        .fnend