2 Copyright (c) 2013, Raspberry Pi Foundation
3 Copyright (c) 2013, RISC OS Open Ltd
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions 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 the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the
14 names of its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 .macro preload_leading_step1 backwards, ptr, base
36 /* If the destination is already 16-byte aligned, then we need to preload
37 * between 0 and prefetch_distance (inclusive) cache lines ahead so there
38 * are no gaps when the inner loop starts.
47 .rept prefetch_distance+1
50 .set OFFSET, OFFSET-32
52 .set OFFSET, OFFSET+32
57 .macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
58 /* However, if the destination is not 16-byte aligned, we may need to
59 * preload one more cache line than that. The question we need to ask is:
60 * are the leading bytes more than the amount by which the source
61 * pointer will be rounded down for preloading, and if so, by how many
65 /* Here we compare against how many bytes we are into the
66 * cache line, counting down from the highest such address.
67 * Effectively, we want to calculate
68 * leading_bytes = dst&15
69 * cacheline_offset = 31-((src-leading_bytes-1)&31)
70 * extra_needed = leading_bytes - cacheline_offset
71 * and test if extra_needed is <= 0, or rearranging:
72 * leading_bytes + (src-leading_bytes-1)&31 <= 31
74 mov tmp, base, lsl #32-5
75 sbc tmp, tmp, leading_bytes, lsl #32-5
76 adds tmp, tmp, leading_bytes, lsl #32-5
78 pld [ptr, #-32*(prefetch_distance+1)]
80 /* Effectively, we want to calculate
81 * leading_bytes = (-dst)&15
82 * cacheline_offset = (src+leading_bytes)&31
83 * extra_needed = leading_bytes - cacheline_offset
84 * and test if extra_needed is <= 0.
86 mov tmp, base, lsl #32-5
87 add tmp, tmp, leading_bytes, lsl #32-5
88 rsbs tmp, tmp, leading_bytes, lsl #32-5
90 pld [ptr, #32*(prefetch_distance+1)]
95 .macro preload_trailing backwards, base, remain, tmp
96 /* We need either 0, 1 or 2 extra preloads */
99 mov tmp, tmp, lsl #32-5
101 mov tmp, base, lsl #32-5
103 adds tmp, tmp, remain, lsl #32-5
105 /* The instruction above has two effects: ensures Z is only
106 * set if C was clear (so Z indicates that both shifted quantities
107 * were 0), and clears C if Z was set (so C indicates that the sum
108 * of the shifted quantities was greater and not equal to 32) */
118 pld [tmp, #-32*(prefetch_distance+1)]
120 pld [tmp, #-32*prefetch_distance]
122 pld [tmp, #32*(prefetch_distance+2)]
124 pld [tmp, #32*(prefetch_distance+1)]
129 .macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
134 sub tmp1, base, remain, lsl #shift
138 add tmp1, base, remain, lsl #shift
145 /* In this case, all the data fits in either 1 or 2 cache lines */