Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 1 | /* |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021, 2023 Arm Limited. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +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 | * |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 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 |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 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. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #ifdef __aarch64__ |
| 26 | |
| 27 | template<> |
| 28 | void interleave_block<8, 4, VLType::None, false>( |
| 29 | bfloat16 * &out_ptr, const float * const * in, size_t width, size_t height, |
| 30 | size_t row_offset, bool |
| 31 | ) |
| 32 | { |
| 33 | __asm__ __volatile__( |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 34 | "ldr x28, [%x[in], #0x0]\n" |
| 35 | "ldr x27, [%x[in], #0x8]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 36 | "cmp %x[height], #0x8\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 37 | "add x28, x28, %x[row_offset], LSL #2\n" |
| 38 | "ldr x26, [%x[in], #0x10]\n" |
| 39 | "ldr x25, [%x[in], #0x18]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 40 | "add x27, x27, %x[row_offset], LSL #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 41 | "add x26, x26, %x[row_offset], LSL #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 42 | "ldr x24, [%x[in], #0x20]\n" |
| 43 | "ldr x23, [%x[in], #0x28]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 44 | "add x25, x25, %x[row_offset], LSL #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 45 | "add x24, x24, %x[row_offset], LSL #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 46 | "ldr x22, [%x[in], #0x30]\n" |
| 47 | "ldr x21, [%x[in], #0x38]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 48 | "add x23, x23, %x[row_offset], LSL #2\n" |
| 49 | "add x22, x22, %x[row_offset], LSL #2\n" |
| 50 | "add x21, x21, %x[row_offset], LSL #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 51 | "beq 1f\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 52 | "cmp %x[height], #0x2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 53 | "csel x27, x27, x28, GE\n" |
| 54 | "csel x26, x26, x28, GT\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 55 | "cmp %x[height], #0x4\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 56 | "csel x25, x25, x28, GE\n" |
| 57 | "csel x24, x24, x28, GT\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 58 | "cmp %x[height], #0x6\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 59 | "mov x21, x28\n" |
| 60 | "csel x23, x23, x28, GE\n" |
| 61 | "csel x22, x22, x28, GT\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 62 | "1:" // no_pointer_adj |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 63 | "cmp %x[width], #0x4\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 64 | "prfm pldl1keep, [x28, #0x0]\n" |
| 65 | "prfm pldl1keep, [x27, #0x0]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 66 | "prfm pldl1keep, [x26, #0x0]\n" |
| 67 | "prfm pldl1keep, [x25, #0x0]\n" |
| 68 | "prfm pldl1keep, [x24, #0x0]\n" |
| 69 | "prfm pldl1keep, [x23, #0x0]\n" |
| 70 | "prfm pldl1keep, [x22, #0x0]\n" |
| 71 | "prfm pldl1keep, [x21, #0x0]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 72 | "prfm pldl1keep, [x28, #0x40]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 73 | "prfm pldl1keep, [x27, #0x40]\n" |
| 74 | "prfm pldl1keep, [x26, #0x40]\n" |
| 75 | "prfm pldl1keep, [x25, #0x40]\n" |
| 76 | "prfm pldl1keep, [x24, #0x40]\n" |
| 77 | "prfm pldl1keep, [x23, #0x40]\n" |
| 78 | "prfm pldl1keep, [x22, #0x40]\n" |
| 79 | "prfm pldl1keep, [x21, #0x40]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 80 | "blt 3f\n" |
| 81 | "2:" // Main loop head |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 82 | "ldr q17, [x28], #0x10\n" |
| 83 | "ldr q16, [x26], #0x10\n" |
| 84 | ".inst 0x0ea16a37 // bfcvtn v23.4h, v17.4s\n" |
| 85 | ".inst 0x0ea16a16 // bfcvtn v22.4h, v16.4s\n" |
| 86 | "ldr q17, [x24], #0x10\n" |
| 87 | "ldr q16, [x22], #0x10\n" |
| 88 | ".inst 0x0ea16a35 // bfcvtn v21.4h, v17.4s\n" |
| 89 | ".inst 0x0ea16a14 // bfcvtn v20.4h, v16.4s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 90 | "ldr q19, [x27], #0x10\n" |
| 91 | "ldr q18, [x25], #0x10\n" |
| 92 | "subs %x[width], %x[width], #0x4\n" |
| 93 | "cmp %x[width], #0x4\n" |
| 94 | "ldr q17, [x23], #0x10\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 95 | "ldr q16, [x21], #0x10\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 96 | ".inst 0x4ea16a77 // bfcvtn2 v23.8h, v19.4s\n" |
| 97 | ".inst 0x4ea16a56 // bfcvtn2 v22.8h, v18.4s\n" |
| 98 | "prfm pldl1keep, [x28, #0x70]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 99 | "prfm pldl1keep, [x27, #0x70]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 100 | ".inst 0x4ea16a35 // bfcvtn2 v21.8h, v17.4s\n" |
| 101 | ".inst 0x4ea16a14 // bfcvtn2 v20.8h, v16.4s\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 102 | "prfm pldl1keep, [x26, #0x70]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 103 | "prfm pldl1keep, [x25, #0x70]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 104 | "str q23, [%x[out_ptr], #0x0]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 105 | "prfm pldl1keep, [x24, #0x70]\n" |
| 106 | "prfm pldl1keep, [x23, #0x70]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 107 | "str q22, [%x[out_ptr], #0x10]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 108 | "prfm pldl1keep, [x22, #0x70]\n" |
| 109 | "prfm pldl1keep, [x21, #0x70]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 110 | "str q21, [%x[out_ptr], #0x20]\n" |
| 111 | "str q20, [%x[out_ptr], #0x30]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 112 | "add %x[out_ptr], %x[out_ptr], #0x40\n" |
| 113 | "bge 2b\n" |
| 114 | "3:" // Main loop skip |
| 115 | "cbz %x[width], 6f\n" |
| 116 | "tbz %x[width], #1, 4f\n" |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 117 | "ldr d19, [x28], #0x8\n" |
| 118 | "ldr d23, [x27], #0x8\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 119 | "mov x20, #0x1\n" |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 120 | "ldr d18, [x26], #0x8\n" |
| 121 | "ldr d22, [x25], #0x8\n" |
| 122 | "ldr d17, [x24], #0x8\n" |
| 123 | "ldr d21, [x23], #0x8\n" |
| 124 | "ldr d16, [x22], #0x8\n" |
| 125 | "ldr d20, [x21], #0x8\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 126 | "tbz %x[width], #0, 5f\n" |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 127 | "ld1 { v19.s }[2], [x28]\n" |
| 128 | "ld1 { v23.s }[2], [x27]\n" |
| 129 | "ld1 { v18.s }[2], [x26]\n" |
| 130 | "ld1 { v22.s }[2], [x25]\n" |
| 131 | "ld1 { v17.s }[2], [x24]\n" |
| 132 | "ld1 { v21.s }[2], [x23]\n" |
| 133 | "ld1 { v16.s }[2], [x22]\n" |
| 134 | "ld1 { v20.s }[2], [x21]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 135 | "b 5f\n" |
| 136 | "4:" // odd_loads_1_0 |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 137 | "ldr s19, [x28, #0x0]\n" |
| 138 | "ldr s23, [x27, #0x0]\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 139 | "mov x20, #0x1\n" |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 140 | "ldr s18, [x26, #0x0]\n" |
| 141 | "ldr s22, [x25, #0x0]\n" |
| 142 | "ldr s17, [x24, #0x0]\n" |
| 143 | "ldr s21, [x23, #0x0]\n" |
| 144 | "ldr s16, [x22, #0x0]\n" |
| 145 | "ldr s20, [x21, #0x0]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 146 | "5:" // Odd load end |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 147 | ".inst 0x0ea16a73 // bfcvtn v19.4h, v19.4s\n" |
| 148 | ".inst 0x0ea16a52 // bfcvtn v18.4h, v18.4s\n" |
| 149 | ".inst 0x0ea16a31 // bfcvtn v17.4h, v17.4s\n" |
| 150 | ".inst 0x0ea16a10 // bfcvtn v16.4h, v16.4s\n" |
| 151 | ".inst 0x4ea16af3 // bfcvtn2 v19.8h, v23.4s\n" |
| 152 | ".inst 0x4ea16ad2 // bfcvtn2 v18.8h, v22.4s\n" |
| 153 | "str q19, [%x[out_ptr], #0x0]\n" |
| 154 | ".inst 0x4ea16ab1 // bfcvtn2 v17.8h, v21.4s\n" |
| 155 | ".inst 0x4ea16a90 // bfcvtn2 v16.8h, v20.4s\n" |
| 156 | "str q18, [%x[out_ptr], #0x10]\n" |
| 157 | "str q17, [%x[out_ptr], #0x20]\n" |
| 158 | "str q16, [%x[out_ptr], #0x30]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 159 | "add %x[out_ptr], %x[out_ptr], #0x40\n" |
| 160 | "6:" // Odds skip |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 161 | : [out_ptr] "+&r" (out_ptr), [width] "+&r" (width) |
| 162 | : [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset) |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 163 | : "cc", "memory", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 164 | ); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | #endif // __aarch64__ |