1 /*
2 * Copyright (c) 2022 Arm Limited.
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
14 * all 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
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #if defined(__ARM_FEATURE_SVE)
26
27 template <>
interleave_block(bfloat16 * & out,const float * const * in,size_t width,size_t height,size_t row_offset,bool first)28 void interleave_block<1, 2, VLType::SME, false>(
29 bfloat16 * &out, const float * const *in,
30 size_t width, size_t height, size_t row_offset, bool first
31 )
32 {
33 ARM_COMPUTE_UNUSED(first);
34
35 __asm__ __volatile__(
36 ".inst 0xd503477f // SMSTART ZA\n"
37 "cntw x21, ALL, MUL #2\n"
38 "sub x27, %x[width], #0x1\n"
39 "cntw x20, ALL, MUL #2\n"
40 "sub x19, x21, #0x1\n"
41 "whilelt p10.s, XZR, %x[height]\n"
42 "add x27, x27, x20\n"
43 "ands x26, %x[width], x19\n"
44 "udiv x27, x27, x20\n"
45 "csel x26, x26, x21, NE\n"
46 "mov x25, #0x0\n"
47 "and x24, x27, #0x1\n"
48 "sub x27, x27, #0x1\n"
49 "add x26, x26, #0x1\n"
50 "mov x19, %x[width]\n"
51 "ptrue p0.b\n"
52 "mov x23, %x[outptr_raw]\n"
53 "mov x22, %x[row_offset]\n"
54 "cntw x21\n"
55 "lsr x27, x27, #0x1\n"
56 "lsr x26, x26, #0x1\n"
57 "mov x12, #0x0\n"
58 ".inst 0x25b34731 // whilelt pn9.s, x25, x19, VLx2\n"
59 "mov x20, %x[in]\n"
60 "1:" // Width loop: Preamble: Loop
61 "ldr x19, [x20], #0x8\n"
62 ".inst 0x25306548 // psel p8.s, p9.s/Z, p10.s[w12]\n"
63 ".inst 0xa0164266 // ld1w { z6.s-z7.s }, pn8.s/Z, [x19, x22, LSL #2]\n"
64 ".inst 0xc160e0c6 // bfcvt z6.h, { z6.s-z7.s }\n"
65 ".inst 0xc08000c0 // mova za0h.s[x12], p0/M, z6.s\n"
66 "add x12, x12, #0x1\n"
67 "cmp x12, x21\n"
68 "blt 1b\n"
69 "incw x22, ALL, MUL #2\n"
70 "incw x25, ALL, MUL #2\n"
71 "cbz x27, 5f\n"
72 "2:" // Width loop
73 "mov x19, %x[width]\n"
74 "mov x12, #0x0\n"
75 ".inst 0x25b34731 // whilelt pn9.s, x25, x19, VLx2\n"
76 "mov x20, %x[in]\n"
77 "3:" // Width loop: Odd: Loop
78 "ldr x19, [x20], #0x8\n"
79 ".inst 0x25306548 // psel p8.s, p9.s/Z, p10.s[w12]\n"
80 ".inst 0xa016427e // ld1w { z30.s-z31.s }, pn8.s/Z, [x19, x22, LSL #2]\n"
81 ".inst 0xc160e3de // bfcvt z30.h, { z30.s-z31.s }\n"
82 ".inst 0xc08003c8 // mova za2h.s[x12], p0/M, z30.s\n"
83 ".inst 0xc082800f // mova z15.s, p0/M, za0v.s[x12]\n"
84 "add x12, x12, #0x1\n"
85 "cmp x12, x21\n"
86 "st1w { z15.s }, p0, [x23]\n"
87 "addvl x23, x23, #1\n"
88 "blt 3b\n"
89 "incw x25, ALL, MUL #2\n"
90 "mov x19, %x[width]\n"
91 "incw x22, ALL, MUL #2\n"
92 "mov x12, #0x0\n"
93 ".inst 0x25b34731 // whilelt pn9.s, x25, x19, VLx2\n"
94 "mov x20, %x[in]\n"
95 "4:" // Width loop: Even: Loop
96 "ldr x19, [x20], #0x8\n"
97 ".inst 0x25306548 // psel p8.s, p9.s/Z, p10.s[w12]\n"
98 ".inst 0xa0164278 // ld1w { z24.s-z25.s }, pn8.s/Z, [x19, x22, LSL #2]\n"
99 ".inst 0xc160e318 // bfcvt z24.h, { z24.s-z25.s }\n"
100 ".inst 0xc0800300 // mova za0h.s[x12], p0/M, z24.s\n"
101 ".inst 0xc0828110 // mova z16.s, p0/M, za2v.s[x12]\n"
102 "add x12, x12, #0x1\n"
103 "cmp x12, x21\n"
104 "st1w { z16.s }, p0, [x23]\n"
105 "addvl x23, x23, #1\n"
106 "blt 4b\n"
107 "subs x27, x27, #0x1\n"
108 "incw x22, ALL, MUL #2\n"
109 "incw x25, ALL, MUL #2\n"
110 "bgt 2b\n"
111 "5:" // Width loop: Tails
112 "cbnz x24, 8f\n"
113 "mov x19, %x[width]\n"
114 "mov x12, #0x0\n"
115 ".inst 0x25b34731 // whilelt pn9.s, x25, x19, VLx2\n"
116 "mov x20, %x[in]\n"
117 "6:" // Width loop: Tails: Even: Odd: Loop
118 "ldr x19, [x20], #0x8\n"
119 ".inst 0x25306548 // psel p8.s, p9.s/Z, p10.s[w12]\n"
120 ".inst 0xa016426e // ld1w { z14.s-z15.s }, pn8.s/Z, [x19, x22, LSL #2]\n"
121 ".inst 0xc160e1ce // bfcvt z14.h, { z14.s-z15.s }\n"
122 ".inst 0xc08001c8 // mova za2h.s[x12], p0/M, z14.s\n"
123 ".inst 0xc0828010 // mova z16.s, p0/M, za0v.s[x12]\n"
124 "add x12, x12, #0x1\n"
125 "cmp x12, x21\n"
126 "st1w { z16.s }, p0, [x23]\n"
127 "addvl x23, x23, #1\n"
128 "blt 6b\n"
129 "mov x12, #0x0\n"
130 "7:" // Width loop: Tails: Even: Even: Loop
131 ".inst 0xc0828110 // mova z16.s, p0/M, za2v.s[x12]\n"
132 "add x12, x12, #0x1\n"
133 "cmp x12, x26\n"
134 "st1w { z16.s }, p0, [x23]\n"
135 "addvl x23, x23, #1\n"
136 "blt 7b\n"
137 "b 10f\n"
138 "8:" // Width loop: Tails: Odd
139 "mov x12, #0x0\n"
140 "9:" // Width loop: Tails: Odd: Loop
141 ".inst 0xc0828010 // mova z16.s, p0/M, za0v.s[x12]\n"
142 "add x12, x12, #0x1\n"
143 "cmp x12, x26\n"
144 "st1w { z16.s }, p0, [x23]\n"
145 "addvl x23, x23, #1\n"
146 "blt 9b\n"
147 "10:" // End
148 "mov %x[outptr_raw], x23\n"
149 ".inst 0xd503467f // SMSTOP\n"
150 : [outptr_raw] "+&r" (out)
151 : [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset), [width] "r" (width)
152 : "cc", "memory", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", "x12", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "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"
153 );
154 }
155
156 #endif // defined(__ARM_FEATURE_SVE)
157