Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 3 | * |
| 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 Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 33 | // "Correct" version |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 34 | #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 Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 37 | #define ASM_PREFETCHWL2(address) "PRFM PSTL2KEEP, " address "\n" |
| 38 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 39 | // Lee's uarchsim hack |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 40 | //#define ASM_PREFETCH(address) "LDNP x20, x21, " address "\n" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 41 | |
| 42 | // No preload at all |
| 43 | //#define ASM_PREFETCH(address) "" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 44 | #else |
| 45 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 46 | // "Correct" versions for AArch32 |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 47 | #define ASM_PREFETCH(address) "PLD " address "\n" |
| 48 | #define ASM_PREFETCHW(address) "PLDW " address "\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 49 | |
| 50 | #endif |
| 51 | |
| 52 | /* |
| 53 | * Do some prefetches. |
| 54 | */ |
| 55 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 56 | static inline void prefetch_6x(const T *pfp) { |
| 57 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 58 | 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 Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 64 | : |
| 65 | : [pfp] "r" (pfp) |
| 66 | : "memory" |
| 67 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 71 | static inline void prefetch_5x(const T *pfp) { |
| 72 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 73 | ASM_PREFETCH("[%[pfp]]") |
| 74 | ASM_PREFETCH("[%[pfp], #64]") |
| 75 | ASM_PREFETCH("[%[pfp], #128]") |
| 76 | ASM_PREFETCH("[%[pfp], #192]") |
| 77 | ASM_PREFETCH("[%[pfp], #256]") |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 78 | : |
| 79 | : [pfp] "r" (pfp) |
| 80 | : "memory" |
| 81 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 85 | static inline void prefetch_4x(const T *pfp) { |
| 86 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 87 | ASM_PREFETCH("[%[pfp]]") |
| 88 | ASM_PREFETCH("[%[pfp], #64]") |
| 89 | ASM_PREFETCH("[%[pfp], #128]") |
| 90 | ASM_PREFETCH("[%[pfp], #192]") |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 91 | : |
| 92 | : [pfp] "r" (pfp) |
| 93 | : "memory" |
| 94 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 98 | static inline void prefetch_3x(const T *pfp) { |
| 99 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 100 | ASM_PREFETCH("[%[pfp]]") |
| 101 | ASM_PREFETCH("[%[pfp], #64]") |
| 102 | ASM_PREFETCH("[%[pfp], #128]") |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 103 | : |
| 104 | : [pfp] "r" (pfp) |
| 105 | : "memory" |
| 106 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 110 | static inline void prefetch_2x(const T *pfp) { |
| 111 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 112 | ASM_PREFETCH("[%[pfp]]") |
| 113 | ASM_PREFETCH("[%[pfp], #64]") |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 114 | : |
| 115 | : [pfp] "r" (pfp) |
| 116 | : "memory" |
| 117 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | template <typename T> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 121 | static inline void prefetch_1x(const T *pfp) { |
| 122 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 123 | ASM_PREFETCH("[%[pfp]]") |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 124 | : |
| 125 | : [pfp] "r" (pfp) |
| 126 | : "memory" |
| 127 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 128 | } |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 129 | |