blob: 4f2c47bf11ac001195c856c3871db275bf4de3c4 [file] [log] [blame]
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01001/*
Georgios Pinitas4ee8b152021-07-16 16:16:43 +01002 * Copyright (c) 2017-2018,2021 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"
Michalis Spyrou778b95c2021-04-20 12:15:52 +010035#define ASM_PREFETCHU(address) "PRFUM PLDL1KEEP, " address "\n"
Anthony Barbier5f707732018-07-03 16:22:02 +010036#define ASM_PREFETCHL2(address) "PRFM PLDL2KEEP, " address "\n"
37#define ASM_PREFETCHW(address) "PRFM PSTL1KEEP, " address "\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010038#define ASM_PREFETCHWL2(address) "PRFM PSTL2KEEP, " address "\n"
39
Pablo Telloeb82fd22018-02-23 13:43:50 +000040// No preload at all
41//#define ASM_PREFETCH(address) ""
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010042#else
43
Pablo Telloeb82fd22018-02-23 13:43:50 +000044// "Correct" versions for AArch32
Anthony Barbier5f707732018-07-03 16:22:02 +010045#define ASM_PREFETCH(address) "PLD " address "\n"
46#define ASM_PREFETCHW(address) "PLDW " address "\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010047
48#endif
49
50/*
51 * Do some prefetches.
52 */
53template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010054static inline void prefetch_6x(const T *pfp) {
55 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010056 ASM_PREFETCH("[%[pfp]]")
57 ASM_PREFETCH("[%[pfp], #64]")
58 ASM_PREFETCH("[%[pfp], #128]")
59 ASM_PREFETCH("[%[pfp], #192]")
60 ASM_PREFETCH("[%[pfp], #256]")
61 ASM_PREFETCH("[%[pfp], #320]")
Anthony Barbier5f707732018-07-03 16:22:02 +010062 :
63 : [pfp] "r" (pfp)
64 : "memory"
65 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010066}
67
68template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010069static inline void prefetch_5x(const T *pfp) {
70 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010071 ASM_PREFETCH("[%[pfp]]")
72 ASM_PREFETCH("[%[pfp], #64]")
73 ASM_PREFETCH("[%[pfp], #128]")
74 ASM_PREFETCH("[%[pfp], #192]")
75 ASM_PREFETCH("[%[pfp], #256]")
Anthony Barbier5f707732018-07-03 16:22:02 +010076 :
77 : [pfp] "r" (pfp)
78 : "memory"
79 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010080}
81
82template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010083static inline void prefetch_4x(const T *pfp) {
84 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010085 ASM_PREFETCH("[%[pfp]]")
86 ASM_PREFETCH("[%[pfp], #64]")
87 ASM_PREFETCH("[%[pfp], #128]")
88 ASM_PREFETCH("[%[pfp], #192]")
Anthony Barbier5f707732018-07-03 16:22:02 +010089 :
90 : [pfp] "r" (pfp)
91 : "memory"
92 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010093}
94
95template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +010096static inline void prefetch_3x(const T *pfp) {
97 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010098 ASM_PREFETCH("[%[pfp]]")
99 ASM_PREFETCH("[%[pfp], #64]")
100 ASM_PREFETCH("[%[pfp], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100101 :
102 : [pfp] "r" (pfp)
103 : "memory"
104 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100105}
106
107template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +0100108static inline void prefetch_2x(const T *pfp) {
109 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100110 ASM_PREFETCH("[%[pfp]]")
111 ASM_PREFETCH("[%[pfp], #64]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100112 :
113 : [pfp] "r" (pfp)
114 : "memory"
115 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100116}
117
118template <typename T>
Anthony Barbier5f707732018-07-03 16:22:02 +0100119static inline void prefetch_1x(const T *pfp) {
120 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100121 ASM_PREFETCH("[%[pfp]]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100122 :
123 : [pfp] "r" (pfp)
124 : "memory"
125 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100126}
Anthony Barbier5f707732018-07-03 16:22:02 +0100127