| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-igemm/4x8-aarch64-neonfma-cortex-a53.S.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2019 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include "xnnpack/assembly.h" |
| 11 |
|
| 12 |
# void xnn_f32_igemm_minmax_ukernel_4x8__asm_aarch64_neonfma_cortex_a53( |
| 13 |
# size_t mr, x0 |
| 14 |
# size_t nc, x1 |
| 15 |
# size_t kc, x2 / x0 |
| 16 |
# size_t ks, x3 / x9 |
| 17 |
# const float** restrict a, x4 |
| 18 |
# const void* restrict w, x5 |
| 19 |
# uint8_t* restrict c, x6 |
| 20 |
# size_t cm_stride, x7 |
| 21 |
# size_t cn_stride, [sp] -> x10 |
| 22 |
# size_t a_offset, [sp + 8] -> x11 |
| 23 |
# const float* zero, [sp + 16] -> x12 |
| 24 |
# const xnn_f32_minmax_params params [sp + 24] -> (x8) |
| 25 |
|
| 26 |
# d8-d15, x19-x30 need to be preserved if used. x18 is reserved by the OS. |
| 27 |
|
| 28 |
# Register usage |
| 29 |
# A0 x13 v0 v3 |
| 30 |
# A1 x14 v0[1] v3[1] |
| 31 |
# A2 x15 v1 v4 |
| 32 |
# A3 x20 v1[1] v4[1] |
| 33 |
# B x5 v12 v13 v14 v15 second set of B |
| 34 |
# B v16 v17 v18 v19 first set |
| 35 |
# C x6 v20 v21 |
| 36 |
# C x16 v22 v23 |
| 37 |
# C x17 v24 v25 |
| 38 |
# C x7 v26 v27 |
| 39 |
# Clamp v6 v7 |
| 40 |
# temporary vector shadow register x19 |
| 41 |
|
| 42 |
# unused A v8 v9 v10 v11 |
| 43 |
# x12 a4 |
| 44 |
# x4 a5 |
| 45 |
# x13 c4 |
| 46 |
# x7 c5 |
| 47 |
# A4 v2 v5 |
| 48 |
# A5 v2[1] v5[1] |
| 49 |
# C v28 v29 |
| 50 |
# C v30 v31 |
| 51 |
|
| 52 |
BEGIN_FUNCTION xnn_f32_igemm_minmax_ukernel_4x8__asm_aarch64_neonfma_cortex_a53 |
| 53 |
|
| 54 |
# Clamp C pointers |
| 55 |
CMP x0, 2 // if mr < 2 |
| 56 |
ADD x16, x6, x7 // c1 = c0 + cm_stride |
| 57 |
CSEL x16, x6, x16, LO // c1 = c0 |
| 58 |
|
| 59 |
ADD x17, x16, x7 // c2 = c1 + cm_stride |
| 60 |
// if mr <= 2 |
| 61 |
CSEL x17, x16, x17, LS // c2 = c1 |
| 62 |
|
| 63 |
CMP x0, 4 // if mr < 4 |
| 64 |
ADD x7, x17, x7 // c3 = c2 + cm_stride |
| 65 |
CSEL x7, x17, x7, LO // c3 = c2 |
| 66 |
|
| 67 |
# Load cn_stride, a_offset |
| 68 |
LDP x10, x11, [sp] |
| 69 |
|
| 70 |
# Load zero, params pointer |
| 71 |
LDP x12, x8, [sp, 16] |
| 72 |
|
| 73 |
# Load min/max values |
| 74 |
LD2R {v6.4s, v7.4s}, [x8] |
| 75 |
|
| 76 |
# Save x19, d12-d15 on stack |
| 77 |
STP d12, d13, [sp, -48]! |
| 78 |
STP d14, d15, [sp, 16] |
| 79 |
STP x19, x20, [sp, 32] |
| 80 |
|
| 81 |
0: |
| 82 |
# Load initial bias from w into accumulators |
| 83 |
LDP q20, q21, [x5], 32 |
| 84 |
MOV v22.16b, v20.16b |
| 85 |
MOV v23.16b, v21.16b |
| 86 |
MOV v24.16b, v20.16b |
| 87 |
MOV v25.16b, v21.16b |
| 88 |
MOV v26.16b, v20.16b |
| 89 |
MOV v27.16b, v21.16b |
| 90 |
|
| 91 |
MOV x9, x3 // p = ks |
| 92 |
|
| 93 |
1: |
| 94 |
# Load next 4 A pointers |
| 95 |
LDP x13, x14, [x4], 16 |
| 96 |
LDP x15, x20, [x4], 16 |
| 97 |
|
| 98 |
CMP x13, x12 // if a0 == zero |
| 99 |
ADD x13, x13, x11 // a0 += a_offset |
| 100 |
CSEL x13, x12, x13, EQ // a0 = zero, else += a0 + a_offset |
| 101 |
CMP x14, x12 // if a1 == zero |
| 102 |
ADD x14, x14, x11 // a1 += a_offset |
| 103 |
CSEL x14, x12, x14, EQ // a1 = zero, else += a1 + a_offset |
| 104 |
CMP x15, x12 // if a2 == zero |
| 105 |
ADD x15, x15, x11 // a2 += a_offset |
| 106 |
CSEL x15, x12, x15, EQ // a2 = zero, else += a2 + a_offset |
| 107 |
CMP x20, x12 // if a3 == zero |
| 108 |
ADD x20, x20, x11 // a3 += a_offset |
| 109 |
CSEL x20, x12, x20, EQ // a3 = zero, else += a3 + a_offset |
| 110 |
|
| 111 |
# Is there at least 4 floats (16 bytes) for prologue + epilogue? |
| 112 |
SUBS x0, x2, 16 // k = kc - 16 |
| 113 |
B.LO 4f |
| 114 |
|
| 115 |
# Prologue - First group loads, no FMA |
| 116 |
LDR d0, [x13], 8 // a0 |
| 117 |
LDP q16, q17, [x5], 32 // b |
| 118 |
LDR d1, [x15], 8 // a2 |
| 119 |
LD1 {v0.d}[1], [x14], 8 // a1 |
| 120 |
LD1 {v1.d}[1], [x20], 8 // a3 |
| 121 |
SUBS x0, x0, 16 |
| 122 |
LDR q18, [x5], 16 |
| 123 |
LDR d19, [x5], 8 |
| 124 |
LDR x19, [x5], 8 // ins is in BLOCK 0 |
| 125 |
|
| 126 |
# Is there at least 4 floats (16 bytes) for main loop? |
| 127 |
B.LO 3f |
| 128 |
|
| 129 |
# Main loop - 4 floats of A (16 bytes) |
| 130 |
# 32 FMA + 8 LD64 A + 8 LDR B |
| 131 |
2: |
| 132 |
# First group of 16 FMA, Second group loads |
| 133 |
# BLOCK 0 |
| 134 |
LDR d3, [x13], 8 // a0 |
| 135 |
INS v19.d[1], x19 // b from second group |
| 136 |
FMLA v20.4s, v16.4s, v0.s[0] |
| 137 |
LDR x19, [x14], 8 // a1 |
| 138 |
FMLA v22.4s, v16.4s, v0.s[2] |
| 139 |
FMLA v24.4s, v16.4s, v1.s[0] |
| 140 |
|
| 141 |
# BLOCK 1 |
| 142 |
LDR d12, [x5] |
| 143 |
INS v3.d[1], x19 // a1 ins |
| 144 |
FMLA v26.4s, v16.4s, v1.s[2] |
| 145 |
LDR x19, [x5, 8] // b |
| 146 |
FMLA v21.4s, v17.4s, v0.s[0] |
| 147 |
FMLA v23.4s, v17.4s, v0.s[2] |
| 148 |
|
| 149 |
# BLOCK 2 |
| 150 |
LDR d4, [x15], 8 // a2 |
| 151 |
INS v12.d[1], x19 // b ins |
| 152 |
FMLA v25.4s, v17.4s, v1.s[0] |
| 153 |
LDR x19, [x20], 8 // a3 |
| 154 |
FMLA v27.4s, v17.4s, v1.s[2] |
| 155 |
FMLA v20.4s, v18.4s, v0.s[1] |
| 156 |
|
| 157 |
# BLOCK 3 |
| 158 |
LDR d13, [x5, 16] |
| 159 |
INS v4.d[1], x19 // a3 ins |
| 160 |
FMLA v22.4s, v18.4s, v0.s[3] |
| 161 |
LDR x19, [x5, 24] |
| 162 |
FMLA v24.4s, v18.4s, v1.s[1] |
| 163 |
FMLA v26.4s, v18.4s, v1.s[3] |
| 164 |
|
| 165 |
# BLOCK 4 |
| 166 |
LDR d14, [x5, 32] |
| 167 |
INS v13.d[1], x19 // b |
| 168 |
FMLA v21.4s, v19.4s, v0.s[1] |
| 169 |
LDR x19, [x5, 40] |
| 170 |
FMLA v23.4s, v19.4s, v0.s[3] |
| 171 |
FMLA v25.4s, v19.4s, v1.s[1] |
| 172 |
|
| 173 |
# BLOCK 5 |
| 174 |
# NOPs to ensure 4 cycle LDR lands on next LDR |
| 175 |
LDR d15, [x5, 48] |
| 176 |
INS v14.d[1], x19 // b from previous |
| 177 |
FMLA v27.4s, v19.4s, v1.s[3] |
| 178 |
LDR x19, [x5, 56] |
| 179 |
NOP |
| 180 |
NOP |
| 181 |
NOP |
| 182 |
NOP |
| 183 |
|
| 184 |
# Second group of 16 FMA, First group of loads |
| 185 |
# BLOCK 0 |
| 186 |
LDR d0, [x13], 8 // a0 |
| 187 |
INS v15.d[1], x19 // b from previous |
| 188 |
FMLA v20.4s, v12.4s, v3.s[0] |
| 189 |
LDR x19, [x14], 8 // a1 |
| 190 |
FMLA v22.4s, v12.4s, v3.s[2] |
| 191 |
FMLA v24.4s, v12.4s, v4.s[0] |
| 192 |
|
| 193 |
# BLOCK 1 |
| 194 |
LDR d16, [x5, 64] |
| 195 |
INS v0.d[1], x19 // a1 ins |
| 196 |
FMLA v26.4s, v12.4s, v4.s[2] |
| 197 |
LDR x19, [x5, 72] // b |
| 198 |
FMLA v21.4s, v13.4s, v3.s[0] |
| 199 |
FMLA v23.4s, v13.4s, v3.s[2] |
| 200 |
|
| 201 |
# BLOCK 2 |
| 202 |
LDR d1, [x15], 8 // a2 |
| 203 |
INS v16.d[1], x19 // b |
| 204 |
FMLA v25.4s, v13.4s, v4.s[0] |
| 205 |
LDR x19, [x20], 8 // a3 |
| 206 |
FMLA v27.4s, v13.4s, v4.s[2] |
| 207 |
FMLA v20.4s, v14.4s, v3.s[1] |
| 208 |
|
| 209 |
# BLOCK 3 |
| 210 |
LDR d17, [x5, 80] |
| 211 |
INS v1.d[1], x19 // a3 ins |
| 212 |
FMLA v22.4s, v14.4s, v3.s[3] |
| 213 |
LDR x19, [x5, 88] |
| 214 |
FMLA v24.4s, v14.4s, v4.s[1] |
| 215 |
FMLA v26.4s, v14.4s, v4.s[3] |
| 216 |
|
| 217 |
# BLOCK 4 |
| 218 |
LDR d18, [x5, 96] |
| 219 |
INS v17.d[1], x19 // b |
| 220 |
FMLA v21.4s, v15.4s, v3.s[1] |
| 221 |
LDR x19, [x5, 104] |
| 222 |
FMLA v23.4s, v15.4s, v3.s[3] |
| 223 |
FMLA v25.4s, v15.4s, v4.s[1] |
| 224 |
|
| 225 |
# BLOCK 5 |
| 226 |
# NOTE that block needs to be 4 cycles for LDR not to stall |
| 227 |
LDR d19, [x5, 112] |
| 228 |
INS v18.d[1], x19 |
| 229 |
FMLA v27.4s, v15.4s, v4.s[3] |
| 230 |
LDR x19, [x5, 120] |
| 231 |
SUBS x0, x0, 16 |
| 232 |
ADD x5, x5, 128 |
| 233 |
B.HS 2b |
| 234 |
|
| 235 |
# Epilogue - 4 floats of A (16 bytes) |
| 236 |
# 32 FMA + 8 LD64 A + 8 LDR B |
| 237 |
3: |
| 238 |
# First group of 16 FMA, Second group loads |
| 239 |
# BLOCK 0 |
| 240 |
LDR d3, [x13], 8 // a0 |
| 241 |
INS v19.d[1], x19 // b from second group |
| 242 |
FMLA v20.4s, v16.4s, v0.s[0] |
| 243 |
LDR x19, [x14], 8 // a1 |
| 244 |
FMLA v22.4s, v16.4s, v0.s[2] |
| 245 |
FMLA v24.4s, v16.4s, v1.s[0] |
| 246 |
|
| 247 |
# BLOCK 1 |
| 248 |
LDR d12, [x5] |
| 249 |
INS v3.d[1], x19 // a1 ins |
| 250 |
FMLA v26.4s, v16.4s, v1.s[2] |
| 251 |
LDR x19, [x5, 8] // b |
| 252 |
FMLA v21.4s, v17.4s, v0.s[0] |
| 253 |
FMLA v23.4s, v17.4s, v0.s[2] |
| 254 |
|
| 255 |
# BLOCK 2 |
| 256 |
LDR d4, [x15], 8 // a2 |
| 257 |
INS v12.d[1], x19 // b ins |
| 258 |
FMLA v25.4s, v17.4s, v1.s[0] |
| 259 |
LDR x19, [x20], 8 // a3 |
| 260 |
FMLA v27.4s, v17.4s, v1.s[2] |
| 261 |
FMLA v20.4s, v18.4s, v0.s[1] |
| 262 |
|
| 263 |
# BLOCK 3 |
| 264 |
LDR d13, [x5, 16] |
| 265 |
INS v4.d[1], x19 // a3 ins |
| 266 |
FMLA v22.4s, v18.4s, v0.s[3] |
| 267 |
LDR x19, [x5, 24] |
| 268 |
FMLA v24.4s, v18.4s, v1.s[1] |
| 269 |
FMLA v26.4s, v18.4s, v1.s[3] |
| 270 |
|
| 271 |
# BLOCK 4 |
| 272 |
LDR d14, [x5, 32] |
| 273 |
INS v13.d[1], x19 // b |
| 274 |
FMLA v21.4s, v19.4s, v0.s[1] |
| 275 |
LDR x19, [x5, 40] |
| 276 |
FMLA v23.4s, v19.4s, v0.s[3] |
| 277 |
FMLA v25.4s, v19.4s, v1.s[1] |
| 278 |
|
| 279 |
# BLOCK 5 |
| 280 |
# NOPs to ensure 4 cycle LDR lands on next LDR |
| 281 |
LDR d15, [x5, 48] |
| 282 |
INS v14.d[1], x19 |
| 283 |
FMLA v27.4s, v19.4s, v1.s[3] |
| 284 |
LDR x19, [x5, 56] |
| 285 |
NOP // fma |
| 286 |
NOP |
| 287 |
NOP // fma |
| 288 |
NOP |
| 289 |
|
| 290 |
# Second group of 16 FMA, no loads |
| 291 |
# BLOCK 0 |
| 292 |
INS v15.d[1], x19 // b from previous |
| 293 |
FMLA v20.4s, v12.4s, v3.s[0] |
| 294 |
FMLA v22.4s, v12.4s, v3.s[2] |
| 295 |
FMLA v24.4s, v12.4s, v4.s[0] |
| 296 |
|
| 297 |
# BLOCK 1 |
| 298 |
FMLA v26.4s, v12.4s, v4.s[2] |
| 299 |
FMLA v21.4s, v13.4s, v3.s[0] |
| 300 |
FMLA v23.4s, v13.4s, v3.s[2] |
| 301 |
|
| 302 |
# BLOCK 2 |
| 303 |
FMLA v25.4s, v13.4s, v4.s[0] |
| 304 |
FMLA v27.4s, v13.4s, v4.s[2] |
| 305 |
FMLA v20.4s, v14.4s, v3.s[1] |
| 306 |
|
| 307 |
# BLOCK 3 |
| 308 |
FMLA v22.4s, v14.4s, v3.s[3] |
| 309 |
FMLA v24.4s, v14.4s, v4.s[1] |
| 310 |
FMLA v26.4s, v14.4s, v4.s[3] |
| 311 |
|
| 312 |
# BLOCK 4 |
| 313 |
FMLA v21.4s, v15.4s, v3.s[1] |
| 314 |
FMLA v23.4s, v15.4s, v3.s[3] |
| 315 |
FMLA v25.4s, v15.4s, v4.s[1] |
| 316 |
ADD x5, x5, 64 |
| 317 |
|
| 318 |
# BLOCK 5 |
| 319 |
FMLA v27.4s, v15.4s, v4.s[3] |
| 320 |
|
| 321 |
4: |
| 322 |
# Is there a remainder?- 2 floats of A (8 bytes) |
| 323 |
TBNZ x0, 3, 6f |
| 324 |
# Is there a remainder?- 1 float of A (4 bytes) |
| 325 |
TBNZ x0, 2, 7f |
| 326 |
5: |
| 327 |
# ks loop |
| 328 |
SUBS x9, x9, 32 // ks -= MR * sizeof(void*) |
| 329 |
B.HI 1b |
| 330 |
|
| 331 |
# Clamp |
| 332 |
FMAX v20.4s, v20.4s, v6.4s |
| 333 |
FMAX v21.4s, v21.4s, v6.4s |
| 334 |
FMAX v22.4s, v22.4s, v6.4s |
| 335 |
FMAX v23.4s, v23.4s, v6.4s |
| 336 |
FMAX v24.4s, v24.4s, v6.4s |
| 337 |
FMAX v25.4s, v25.4s, v6.4s |
| 338 |
FMAX v26.4s, v26.4s, v6.4s |
| 339 |
FMAX v27.4s, v27.4s, v6.4s |
| 340 |
FMIN v20.4s, v20.4s, v7.4s |
| 341 |
FMIN v21.4s, v21.4s, v7.4s |
| 342 |
FMIN v22.4s, v22.4s, v7.4s |
| 343 |
FMIN v23.4s, v23.4s, v7.4s |
| 344 |
FMIN v24.4s, v24.4s, v7.4s |
| 345 |
FMIN v25.4s, v25.4s, v7.4s |
| 346 |
FMIN v26.4s, v26.4s, v7.4s |
| 347 |
FMIN v27.4s, v27.4s, v7.4s |
| 348 |
|
| 349 |
# Store full 4 x 8 |
| 350 |
SUBS x1, x1, 8 |
| 351 |
B.LO 8f |
| 352 |
|
| 353 |
STP q26, q27, [x7] |
| 354 |
ADD x7, x7, x10 |
| 355 |
STP q24, q25, [x17] |
| 356 |
ADD x17, x17, x10 |
| 357 |
STP q22, q23, [x16] |
| 358 |
ADD x16, x16, x10 |
| 359 |
STP q20, q21, [x6] |
| 360 |
ADD x6, x6, x10 |
| 361 |
|
| 362 |
SUB x4, x4, x3 // a -= ks |
| 363 |
|
| 364 |
# nc loop |
| 365 |
B.HI 0b |
| 366 |
|
| 367 |
# Restore x19, d12-d15 from stack |
| 368 |
LDP x19, x20, [sp, 32] |
| 369 |
LDP d14, d15, [sp, 16] |
| 370 |
LDP d12, d13, [sp], 48 |
| 371 |
RET |
| 372 |
|
| 373 |
# Remainder - 2 floats of A (8 bytes) |
| 374 |
# 16 FMA + 4 LD64 A + 2 LDP B |
| 375 |
6: |
| 376 |
LDR d0, [x13], 8 |
| 377 |
LDP q16, q17, [x5], 32 |
| 378 |
LD1 {v0.d}[1], [x14], 8 |
| 379 |
LDR d1, [x15], 8 |
| 380 |
LD1 {v1.d}[1], [x20], 8 |
| 381 |
LDP q18, q19, [x5], 32 |
| 382 |
FMLA v20.4s, v16.4s, v0.s[0] |
| 383 |
FMLA v22.4s, v16.4s, v0.s[2] |
| 384 |
FMLA v24.4s, v16.4s, v1.s[0] |
| 385 |
FMLA v26.4s, v16.4s, v1.s[2] |
| 386 |
FMLA v21.4s, v17.4s, v0.s[0] |
| 387 |
FMLA v23.4s, v17.4s, v0.s[2] |
| 388 |
FMLA v25.4s, v17.4s, v1.s[0] |
| 389 |
FMLA v27.4s, v17.4s, v1.s[2] |
| 390 |
|
| 391 |
FMLA v20.4s, v18.4s, v0.s[1] |
| 392 |
FMLA v22.4s, v18.4s, v0.s[3] |
| 393 |
FMLA v24.4s, v18.4s, v1.s[1] |
| 394 |
FMLA v26.4s, v18.4s, v1.s[3] |
| 395 |
FMLA v21.4s, v19.4s, v0.s[1] |
| 396 |
FMLA v23.4s, v19.4s, v0.s[3] |
| 397 |
FMLA v25.4s, v19.4s, v1.s[1] |
| 398 |
FMLA v27.4s, v19.4s, v1.s[3] |
| 399 |
|
| 400 |
# Is there a remainder?- 1 float of A (4 bytes) |
| 401 |
TBZ x0, 2, 5b |
| 402 |
|
| 403 |
7: |
| 404 |
# Remainder- 1 float of A (4 bytes) |
| 405 |
LDR s0, [x13], 4 |
| 406 |
LDP q16, q17, [x5], 32 |
| 407 |
LD1 {v0.s}[2], [x14], 4 |
| 408 |
LDR s1, [x15], 4 |
| 409 |
LD1 {v1.s}[2], [x20], 4 |
| 410 |
|
| 411 |
FMLA v20.4s, v16.4s, v0.s[0] |
| 412 |
FMLA v22.4s, v16.4s, v0.s[2] |
| 413 |
FMLA v24.4s, v16.4s, v1.s[0] |
| 414 |
FMLA v26.4s, v16.4s, v1.s[2] |
| 415 |
FMLA v21.4s, v17.4s, v0.s[0] |
| 416 |
FMLA v23.4s, v17.4s, v0.s[2] |
| 417 |
FMLA v25.4s, v17.4s, v1.s[0] |
| 418 |
FMLA v27.4s, v17.4s, v1.s[2] |
| 419 |
B 5b |
| 420 |
|
| 421 |
# Store odd width |
| 422 |
8: |
| 423 |
TBZ x1, 2, 9f |
| 424 |
STR q26, [x7], 16 |
| 425 |
MOV v26.16b, v27.16b |
| 426 |
STR q24, [x17], 16 |
| 427 |
MOV v24.16b, v25.16b |
| 428 |
STR q22, [x16], 16 |
| 429 |
MOV v22.16b, v23.16b |
| 430 |
STR q20, [x6], 16 |
| 431 |
MOV v20.16b, v21.16b |
| 432 |
9: |
| 433 |
TBZ x1, 1, 10f |
| 434 |
STR d26, [x7], 8 |
| 435 |
STR d24, [x17], 8 |
| 436 |
DUP d26, v26.d[1] |
| 437 |
DUP d24, v24.d[1] |
| 438 |
STR d22, [x16], 8 |
| 439 |
STR d20, [x6], 8 |
| 440 |
DUP d22, v22.d[1] |
| 441 |
DUP d20, v20.d[1] |
| 442 |
|
| 443 |
10: |
| 444 |
TBZ x1, 0, 11f |
| 445 |
STR s26, [x7] |
| 446 |
STR s24, [x17] |
| 447 |
STR s22, [x16] |
| 448 |
STR s20, [x6] |
| 449 |
11: |
| 450 |
# Restore x19, d12-d15 from stack |
| 451 |
LDP x19, x20, [sp, 32] |
| 452 |
LDP d14, d15, [sp, 16] |
| 453 |
LDP d12, d13, [sp], 48 |
| 454 |
RET |
| 455 |
|
| 456 |
END_FUNCTION xnn_f32_igemm_minmax_ukernel_4x8__asm_aarch64_neonfma_cortex_a53 |
| 457 |
|
| 458 |
#ifdef __ELF__ |
| 459 |
.section ".note.GNU-stack","",%progbits |
| 460 |
#endif |