Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 1 | /* |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +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. |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +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. |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #pragma once |
| 26 | |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 27 | #if defined(ARM_COMPUTE_ENABLE_SME) |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 28 | |
| 29 | namespace { |
| 30 | |
| 31 | void sme_transpose_interleave_16VL_2x2_fp32bf16(bfloat16 *out, const float *in, size_t width, size_t in_stride, size_t height) |
| 32 | { |
| 33 | float *pad_row = reinterpret_cast<float *>(alloca(width * sizeof(float))); |
| 34 | |
| 35 | if (height % 2) { |
| 36 | memset(pad_row, 0, width * sizeof(float)); |
| 37 | } |
| 38 | |
| 39 | size_t out_stride = 16 * roundup<size_t>(height, 2) * sme::get_vector_length<uint16_t>(); |
| 40 | |
| 41 | __asm__ __volatile__( |
| 42 | ".inst 0xd503477f // SMSTART ZA\n" |
| 43 | "ptrue p7.b\n" |
| 44 | "1:" // Main row loop: Head |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 45 | "mov x25, %x[in]\n" |
| 46 | "add x24, x25, %x[in_stride]\n" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 47 | "cmp %x[height], #0x1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 48 | "add %x[in], x24, %x[in_stride]\n" |
| 49 | "mov x23, %x[out]\n" |
| 50 | "csel x24, x24, %x[pad_row], GT\n" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 51 | "sub %x[height], %x[height], #0x2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 52 | "mov x22, %x[width]\n" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 53 | "2:" // Main row loop: Column loop |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 54 | "mov x21, x22\n" |
| 55 | "whilelt p1.s, XZR, x21\n" |
| 56 | "ld1w { z16.s }, p1/Z, [x25]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 57 | ".inst 0x658abe00 // bfcvt z0.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 58 | "decw x21\n" |
| 59 | "whilelt p0.s, XZR, x21\n" |
| 60 | "ld1w { z16.s }, p0/Z, [x25, #1, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 61 | ".inst 0x658abe1f // bfcvt z31.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 62 | "decw x21\n" |
| 63 | "whilelt p6.s, XZR, x21\n" |
| 64 | "ld1w { z16.s }, p6/Z, [x25, #2, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 65 | ".inst 0x658abe1e // bfcvt z30.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 66 | "decw x21\n" |
| 67 | "whilelt p5.s, XZR, x21\n" |
| 68 | "ld1w { z16.s }, p5/Z, [x25, #3, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 69 | ".inst 0x658abe1d // bfcvt z29.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 70 | "decw x21\n" |
| 71 | "whilelt p4.s, XZR, x21\n" |
| 72 | "ld1w { z16.s }, p4/Z, [x25, #4, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 73 | ".inst 0x658abe1c // bfcvt z28.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 74 | "decw x21\n" |
| 75 | "whilelt p3.s, XZR, x21\n" |
| 76 | "ld1w { z16.s }, p3/Z, [x25, #5, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 77 | ".inst 0x658abe1b // bfcvt z27.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 78 | "decw x21\n" |
| 79 | "whilelt p2.s, XZR, x21\n" |
| 80 | "ld1w { z16.s }, p2/Z, [x25, #6, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 81 | ".inst 0x658abe1a // bfcvt z26.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 82 | "decw x21\n" |
| 83 | "ld1w { z16.s }, p1/Z, [x24]\n" |
| 84 | "whilelt p1.s, XZR, x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 85 | ".inst 0x648abe00 // bfcvtnt z0.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 86 | "decw x21\n" |
| 87 | "ld1w { z16.s }, p1/Z, [x25, #7, MUL VL]\n" |
| 88 | "addvl x25, x25, #16\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 89 | ".inst 0x658abe19 // bfcvt z25.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 90 | "ld1w { z16.s }, p0/Z, [x24, #1, MUL VL]\n" |
| 91 | "whilelt p0.s, XZR, x21\n" |
| 92 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 93 | ".inst 0x648abe1f // bfcvtnt z31.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 94 | "ld1w { z16.s }, p0/Z, [x25, #-8, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 95 | ".inst 0x658abe18 // bfcvt z24.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 96 | "mov x20, x23\n" |
| 97 | "decw x22, ALL, MUL #16\n" |
| 98 | "ld1w { z16.s }, p6/Z, [x24, #2, MUL VL]\n" |
| 99 | "whilelt p6.s, XZR, x21\n" |
| 100 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 101 | ".inst 0x648abe1e // bfcvtnt z30.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 102 | "ld1w { z16.s }, p6/Z, [x25, #-7, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 103 | ".inst 0x658abe17 // bfcvt z23.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 104 | "add x23, x23, %x[out_stride]\n" |
| 105 | "ld1w { z16.s }, p5/Z, [x24, #3, MUL VL]\n" |
| 106 | "whilelt p5.s, XZR, x21\n" |
| 107 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 108 | ".inst 0x648abe1d // bfcvtnt z29.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 109 | "ld1w { z16.s }, p5/Z, [x25, #-6, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 110 | ".inst 0x658abe16 // bfcvt z22.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 111 | "ld1w { z16.s }, p4/Z, [x24, #4, MUL VL]\n" |
| 112 | "whilelt p4.s, XZR, x21\n" |
| 113 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 114 | ".inst 0x648abe1c // bfcvtnt z28.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 115 | "ld1w { z16.s }, p4/Z, [x25, #-5, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 116 | ".inst 0x658abe15 // bfcvt z21.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 117 | "ld1w { z16.s }, p3/Z, [x24, #5, MUL VL]\n" |
| 118 | "whilelt p3.s, XZR, x21\n" |
| 119 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 120 | ".inst 0x648abe1b // bfcvtnt z27.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 121 | "ld1w { z16.s }, p3/Z, [x25, #-4, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 122 | ".inst 0x658abe14 // bfcvt z20.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 123 | "ld1w { z16.s }, p2/Z, [x24, #6, MUL VL]\n" |
| 124 | "whilelt p2.s, XZR, x21\n" |
| 125 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 126 | ".inst 0x648abe1a // bfcvtnt z26.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 127 | "ld1w { z16.s }, p2/Z, [x25, #-3, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 128 | ".inst 0x658abe13 // bfcvt z19.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 129 | "ld1w { z16.s }, p1/Z, [x24, #7, MUL VL]\n" |
| 130 | "whilelt p1.s, XZR, x21\n" |
| 131 | "decw x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 132 | ".inst 0x648abe19 // bfcvtnt z25.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 133 | "ld1w { z16.s }, p1/Z, [x25, #-2, MUL VL]\n" |
| 134 | "addvl x24, x24, #16\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 135 | ".inst 0x658abe12 // bfcvt z18.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 136 | "ld1w { z16.s }, p0/Z, [x24, #-8, MUL VL]\n" |
| 137 | "whilelt p0.s, XZR, x21\n" |
| 138 | "cmp x22, #0x0\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 139 | ".inst 0x648abe18 // bfcvtnt z24.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 140 | "ld1w { z16.s }, p0/Z, [x25, #-1, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 141 | ".inst 0x658abe11 // bfcvt z17.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 142 | "ld1w { z16.s }, p6/Z, [x24, #-7, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 143 | ".inst 0x648abe17 // bfcvtnt z23.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 144 | "ld1w { z16.s }, p5/Z, [x24, #-6, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 145 | ".inst 0x648abe16 // bfcvtnt z22.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 146 | "ld1w { z16.s }, p4/Z, [x24, #-5, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 147 | ".inst 0x648abe15 // bfcvtnt z21.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 148 | "ld1w { z16.s }, p3/Z, [x24, #-4, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 149 | ".inst 0x648abe14 // bfcvtnt z20.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 150 | "ld1w { z16.s }, p2/Z, [x24, #-3, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 151 | ".inst 0x648abe13 // bfcvtnt z19.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 152 | "ld1w { z16.s }, p1/Z, [x24, #-2, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 153 | ".inst 0x648abe12 // bfcvtnt z18.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 154 | "ld1w { z16.s }, p0/Z, [x24, #-1, MUL VL]\n" |
| 155 | "st1h { z0.h }, p7, [x20]\n" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 156 | ".inst 0x648abe11 // bfcvtnt z17.h, p7/M, z16.s\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 157 | "st1h { z31.h }, p7, [x20, #1, MUL VL]\n" |
| 158 | "st1h { z30.h }, p7, [x20, #2, MUL VL]\n" |
| 159 | "st1h { z29.h }, p7, [x20, #3, MUL VL]\n" |
| 160 | "st1h { z28.h }, p7, [x20, #4, MUL VL]\n" |
| 161 | "st1h { z27.h }, p7, [x20, #5, MUL VL]\n" |
| 162 | "st1h { z26.h }, p7, [x20, #6, MUL VL]\n" |
| 163 | "st1h { z25.h }, p7, [x20, #7, MUL VL]\n" |
| 164 | "addvl x20, x20, #16\n" |
| 165 | "st1h { z24.h }, p7, [x20, #-8, MUL VL]\n" |
| 166 | "st1h { z23.h }, p7, [x20, #-7, MUL VL]\n" |
| 167 | "st1h { z22.h }, p7, [x20, #-6, MUL VL]\n" |
| 168 | "st1h { z21.h }, p7, [x20, #-5, MUL VL]\n" |
| 169 | "st1h { z20.h }, p7, [x20, #-4, MUL VL]\n" |
| 170 | "st1h { z19.h }, p7, [x20, #-3, MUL VL]\n" |
| 171 | "st1h { z18.h }, p7, [x20, #-2, MUL VL]\n" |
| 172 | "st1h { z17.h }, p7, [x20, #-1, MUL VL]\n" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 173 | "bgt 2b\n" |
| 174 | "3:" // Main row loop: Column loop skip |
| 175 | "cmp %x[height], #0x1\n" |
| 176 | "addvl %x[out], %x[out], #16\n" |
| 177 | "bge 1b\n" |
| 178 | ".inst 0xd503467f // SMSTOP\n" |
| 179 | : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out) |
| 180 | : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [pad_row] "r" (pad_row), [width] "r" (width) |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 181 | : "cc", "memory", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", "x20", "x21", "x22", "x23", "x24", "x25", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31" |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 182 | ); |
| 183 | } |
| 184 | |
| 185 | } // anonymous namespace |
| 186 | template<> |
| 187 | void Transform<16, 2, true, VLType::SME>( |
| 188 | bfloat16 *out, const float *in, int stride, int x0, int xmax, int k0, int kmax) |
| 189 | { |
| 190 | sme_transpose_interleave_16VL_2x2_fp32bf16( |
| 191 | out, |
| 192 | in + k0 * stride + x0, |
| 193 | (xmax-x0), |
| 194 | stride * sizeof(float), |
| 195 | (kmax-k0) |
| 196 | ); |
| 197 | } |
| 198 | |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 199 | |
| 200 | #endif // defined(ARM_COMPUTE_ENABLE_SME) |