blob: 38f51ae72c7913f33d35067280d2aad1ad5c2c41 [file] [log] [blame]
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01001/*
Pablo Telloeb82fd22018-02-23 13:43:50 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#pragma once
25
26#ifdef __aarch64__
27// Macro to use in assembler to get a preload. Needed because of various
28// workarounds needed to get working preload behaviour.
29//
30// Code using these macros needs to clobber x20 and x21 as they might be
31// used by the workaround.
32
Pablo Telloeb82fd22018-02-23 13:43:50 +000033// "Correct" version
Anthony Barbier5f707732018-07-03 16:22:02 +010034#define ASM_PREFETCH(address) "PRFM PLDL1KEEP, " address "\n"
35#define ASM_PREFETCHL2(address) "PRFM PLDL2KEEP, " address "\n"
36#define ASM_PREFETCHW(address) "PRFM PSTL1KEEP, " address "\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010037#define ASM_PREFETCHWL2(address) "PRFM PSTL2KEEP, " address "\n"
38
Pablo Telloeb82fd22018-02-23 13:43:50 +000039// Lee's uarchsim hack
Anthony Barbier5f707732018-07-03 16:22:02 +010040//#define ASM_PREFETCH(address) "LDNP x20, x21, " address "\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +000041
42// No preload at all
43//#define ASM_PREFETCH(address) ""
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010044#else
45
Pablo Telloeb82fd22018-02-23 13:43:50 +000046// "Correct" versions for AArch32
Anthony Barbier5f707732018-07-03 16:22:02 +010047#define ASM_PREFETCH(address) "PLD " address "\n"
48#define ASM_PREFETCHW(address) "PLDW " address "\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010049
50#endif
51
52/*
53 * Do some prefetches.
54 */
55template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010056static inline void prefetch_6x(const T *pfp) {
57 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010058 ASM_PREFETCH("[%[pfp]]")
59 ASM_PREFETCH("[%[pfp], #64]")
60 ASM_PREFETCH("[%[pfp], #128]")
61 ASM_PREFETCH("[%[pfp], #192]")
62 ASM_PREFETCH("[%[pfp], #256]")
63 ASM_PREFETCH("[%[pfp], #320]")
Anthony Barbier5f707732018-07-03 16:22:02 +010064 :
65 : [pfp] "r" (pfp)
66 : "memory"
67 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010068}
69
70template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010071static inline void prefetch_5x(const T *pfp) {
72 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010073 ASM_PREFETCH("[%[pfp]]")
74 ASM_PREFETCH("[%[pfp], #64]")
75 ASM_PREFETCH("[%[pfp], #128]")
76 ASM_PREFETCH("[%[pfp], #192]")
77 ASM_PREFETCH("[%[pfp], #256]")
Anthony Barbier5f707732018-07-03 16:22:02 +010078 :
79 : [pfp] "r" (pfp)
80 : "memory"
81 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010082}
83
84template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010085static inline void prefetch_4x(const T *pfp) {
86 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010087 ASM_PREFETCH("[%[pfp]]")
88 ASM_PREFETCH("[%[pfp], #64]")
89 ASM_PREFETCH("[%[pfp], #128]")
90 ASM_PREFETCH("[%[pfp], #192]")
Anthony Barbier5f707732018-07-03 16:22:02 +010091 :
92 : [pfp] "r" (pfp)
93 : "memory"
94 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010095}
96
97template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010098static inline void prefetch_3x(const T *pfp) {
99 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100100 ASM_PREFETCH("[%[pfp]]")
101 ASM_PREFETCH("[%[pfp], #64]")
102 ASM_PREFETCH("[%[pfp], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100103 :
104 : [pfp] "r" (pfp)
105 : "memory"
106 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100107}
108
109template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +0100110static inline void prefetch_2x(const T *pfp) {
111 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100112 ASM_PREFETCH("[%[pfp]]")
113 ASM_PREFETCH("[%[pfp], #64]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100114 :
115 : [pfp] "r" (pfp)
116 : "memory"
117 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100118}
119
120template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +0100121static inline void prefetch_1x(const T *pfp) {
122 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100123 ASM_PREFETCH("[%[pfp]]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100124 :
125 : [pfp] "r" (pfp)
126 : "memory"
127 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100128}
Anthony Barbier5f707732018-07-03 16:22:02 +0100129