Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 1 | // Copyright 2019 Google LLC |
| 2 | // |
| 3 | // This source code is licensed under the BSD-style license found in the |
| 4 | // LICENSE file in the root directory of this source tree. |
| 5 | |
| 6 | #include <xnnpack/assembly.h> |
| 7 | |
Marat Dukhan | de06f49 | 2020-04-09 00:19:31 -0700 | [diff] [blame] | 8 | # void xnn_f32_gemm${"inc" if INC else ""}_minmax_ukernel_1x8__aarch64_neonfma_cortex_a53( |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 9 | # size_t mr, (x0) - unused. mr = 1 |
| 10 | # size_t nc, x1 |
| 11 | # size_t kc, x2 / x0 |
| 12 | # const uint8_t*restrict a, x3 |
| 13 | # size_t a_stride, (x4) - unused |
| 14 | # const void*restrict w, x5 |
| 15 | # uint8_t*restrict c, x6 |
| 16 | # size_t cm_stride, (x7) - unused |
| 17 | # size_t cn_stride, [sp] -> x14 |
| 18 | $if INC: |
| 19 | # const float*restrict acc, [sp + 8] -> x15 |
Marat Dukhan | f196d01 | 2020-04-15 11:50:03 -0700 | [diff] [blame] | 20 | # const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) [sp + 16] -> x8 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 21 | $else: |
Marat Dukhan | f196d01 | 2020-04-15 11:50:03 -0700 | [diff] [blame] | 22 | # const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) [sp + 8] -> x8 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 23 | |
Frank Barchard | 909564c | 2020-06-09 03:54:33 -0700 | [diff] [blame^] | 24 | # d8-d15, x19-x30 need to be preserved if used. x18 is reserved by the OS. |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 25 | |
| 26 | # A pointer |
| 27 | # x3 a0 |
| 28 | |
| 29 | # C pointer |
| 30 | # x6 c0 |
| 31 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 32 | # Clamp v4 v5 |
| 33 | |
| 34 | # A53 based on A57/A75 but with LD64 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 35 | |
Marat Dukhan | de06f49 | 2020-04-09 00:19:31 -0700 | [diff] [blame] | 36 | BEGIN_FUNCTION xnn_f32_gemm${"inc" if INC else ""}_minmax_ukernel_1x8__aarch64_neonfma_cortex_a53 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 37 | |
| 38 | $if INC: |
| 39 | # Load cn_stride, acc |
| 40 | LDP x14, x15, [sp] |
| 41 | # Load params pointer |
| 42 | LDR x8, [sp, 16] |
| 43 | $else: |
| 44 | # Load cn_stride, params pointer |
| 45 | LDP x14, x8, [sp] |
| 46 | |
Marat Dukhan | eb09a6b | 2020-04-08 17:34:32 -0700 | [diff] [blame] | 47 | # Load min/max values |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 48 | LD2R {v4.4s, v5.4s}, [x8] |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 49 | 0: |
| 50 | $if INC: |
| 51 | # Load initial accumulators |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 52 | LDP q16, q17, [x15], 32 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 53 | $else: |
| 54 | # Load initial bias from w into accumulators |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 55 | LDP q16, q17, [x5], 32 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 56 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 57 | MOVI v18.4s, 0 // second set of C for pipelining FMLA |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 58 | PRFM PLDL1KEEP, [x5] |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 59 | MOVI v19.4s, 0 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 60 | PRFM PLDL1KEEP, [x5, 64] |
| 61 | PRFM PLDL1KEEP, [x5, 128] |
| 62 | PRFM PLDL1KEEP, [x5, 192] |
| 63 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 64 | # Is there at least 8 floats (32 bytes) for prologue + epilogue? |
| 65 | SUBS x0, x2, 32 // k = kc - 32 |
| 66 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 67 | B.LO 3f |
| 68 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 69 | # 16 prologue |
| 70 | # Read first block of 1 A and B. |
| 71 | LDP q20, q21, [x5], 32 |
| 72 | LDP q22, q23, [x5], 32 |
| 73 | LDP q24, q25, [x5], 32 |
| 74 | LDP q26, q27, [x5], 32 |
| 75 | LDR q0, [x3], 16 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 76 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 77 | # Is there at least 32. yes do main loop |
| 78 | SUBS x0, x0, 32 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 79 | B.LO 2f |
| 80 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 81 | # Main loop - 8 floats of A (32 bytes) |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 82 | 1: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 83 | # First block of 4. FMA for first 4, loads for 2nd block of 4. |
| 84 | FMLA v16.4s, v20.4s, v0.s[0] |
| 85 | LDR q1, [x3], 16 |
| 86 | FMLA v17.4s, v21.4s, v0.s[0] |
| 87 | LDR q20, [x5], 16 |
| 88 | FMLA v18.4s, v22.4s, v0.s[1] |
| 89 | LDR q21, [x5], 16 |
| 90 | FMLA v19.4s, v23.4s, v0.s[1] |
| 91 | LDR q22, [x5], 16 |
| 92 | FMLA v16.4s, v24.4s, v0.s[2] |
| 93 | LDR q23, [x5], 16 |
| 94 | FMLA v17.4s, v25.4s, v0.s[2] |
| 95 | LDR q24, [x5], 16 |
| 96 | FMLA v18.4s, v26.4s, v0.s[3] |
| 97 | LDR q25, [x5], 16 |
| 98 | FMLA v19.4s, v27.4s, v0.s[3] |
| 99 | LDR q26, [x5], 16 |
| 100 | LDR q27, [x5], 16 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 101 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 102 | # Second block of 4. FMA for second 4, loads for 1st block of 4. |
| 103 | FMLA v16.4s, v20.4s, v1.s[0] |
| 104 | LDR q0, [x3], 16 |
| 105 | FMLA v17.4s, v21.4s, v1.s[0] |
| 106 | LDR q20, [x5], 16 |
| 107 | FMLA v18.4s, v22.4s, v1.s[1] |
| 108 | LDR q21, [x5], 16 |
| 109 | FMLA v19.4s, v23.4s, v1.s[1] |
| 110 | LDR q22, [x5], 16 |
| 111 | FMLA v16.4s, v24.4s, v1.s[2] |
| 112 | LDR q23, [x5], 16 |
| 113 | FMLA v17.4s, v25.4s, v1.s[2] |
| 114 | LDR q24, [x5], 16 |
| 115 | FMLA v18.4s, v26.4s, v1.s[3] |
| 116 | LDR q25, [x5], 16 |
| 117 | FMLA v19.4s, v27.4s, v1.s[3] |
| 118 | LDR q26, [x5], 16 |
| 119 | SUBS x0, x0, 32 |
| 120 | LDR q27, [x5], 16 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 121 | B.HS 1b |
| 122 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 123 | 2: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 124 | # Epilogue |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 125 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 126 | # First block of 4. FMA for first 4, loads for 2nd block of 4. |
| 127 | FMLA v16.4s, v20.4s, v0.s[0] |
| 128 | LDR q1, [x3], 16 |
| 129 | FMLA v17.4s, v21.4s, v0.s[0] |
| 130 | LDR q20, [x5], 16 |
| 131 | FMLA v18.4s, v22.4s, v0.s[1] |
| 132 | LDR q21, [x5], 16 |
| 133 | FMLA v19.4s, v23.4s, v0.s[1] |
| 134 | LDR q22, [x5], 16 |
| 135 | FMLA v16.4s, v24.4s, v0.s[2] |
| 136 | LDR q23, [x5], 16 |
| 137 | FMLA v17.4s, v25.4s, v0.s[2] |
| 138 | LDR q24, [x5], 16 |
| 139 | FMLA v18.4s, v26.4s, v0.s[3] |
| 140 | LDR q25, [x5], 16 |
| 141 | FMLA v19.4s, v27.4s, v0.s[3] |
| 142 | LDR q26, [x5], 16 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 143 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 144 | # Second block of 4. no loads |
| 145 | FMLA v16.4s, v20.4s, v1.s[0] |
| 146 | LDR q27, [x5], 16 |
| 147 | FMLA v17.4s, v21.4s, v1.s[0] |
| 148 | FMLA v18.4s, v22.4s, v1.s[1] |
| 149 | FMLA v19.4s, v23.4s, v1.s[1] |
| 150 | FMLA v16.4s, v24.4s, v1.s[2] |
| 151 | FMLA v17.4s, v25.4s, v1.s[2] |
| 152 | FMLA v18.4s, v26.4s, v1.s[3] |
| 153 | FMLA v19.4s, v27.4s, v1.s[3] |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 154 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 155 | 3: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 156 | # Is there a remainder?- 4 floats of A (16 bytes) |
| 157 | TBNZ x0, 4, 5f |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 158 | # Is there a remainder?- 2 floats of A (8 bytes) |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 159 | TBNZ x0, 3, 6f |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 160 | # Is there a remainder?- 1 floats of A (4 bytes) |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 161 | TBNZ x0, 2, 8f |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 162 | |
| 163 | 4: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 164 | FADD v16.4s, v16.4s, v18.4s |
| 165 | FADD v17.4s, v17.4s, v19.4s |
| 166 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 167 | # Clamp |
Marat Dukhan | a51cf48 | 2020-04-08 16:16:19 -0700 | [diff] [blame] | 168 | FMAX v16.4s, v16.4s, v4.4s |
Frank Barchard | 73ccfb4 | 2019-12-11 22:15:22 -0800 | [diff] [blame] | 169 | SUBS x1, x1, 8 |
Marat Dukhan | a51cf48 | 2020-04-08 16:16:19 -0700 | [diff] [blame] | 170 | FMAX v17.4s, v17.4s, v4.4s |
| 171 | FMIN v16.4s, v16.4s, v5.4s |
| 172 | FMIN v17.4s, v17.4s, v5.4s |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 173 | |
| 174 | # Store full 1 x 8 |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 175 | B.LO 9f |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 176 | |
Frank Barchard | 5abe43c | 2019-11-13 16:02:01 -0800 | [diff] [blame] | 177 | ST1 {v16.16b, v17.16b}, [x6], x14 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 178 | SUB x3, x3, x2 // a0 -= kc |
| 179 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 180 | B.HI 0b |
| 181 | |
| 182 | RET |
| 183 | |
| 184 | 5: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 185 | # Remainder- 4 floats of A (16 bytes) |
| 186 | LDR q20, [x5], 16 |
| 187 | LDR q21, [x5], 16 |
| 188 | LDR q0, [x3], 16 |
| 189 | FMLA v16.4s, v20.4s, v0.s[0] |
| 190 | FMLA v17.4s, v21.4s, v0.s[0] |
| 191 | LDR q22, [x5], 16 |
| 192 | LDR q23, [x5], 16 |
| 193 | LDR q24, [x5], 16 |
| 194 | LDR q25, [x5], 16 |
| 195 | LDR q26, [x5], 16 |
| 196 | LDR q27, [x5], 16 |
| 197 | FMLA v18.4s, v22.4s, v0.s[1] |
| 198 | FMLA v19.4s, v23.4s, v0.s[1] |
| 199 | FMLA v16.4s, v24.4s, v0.s[2] |
| 200 | FMLA v17.4s, v25.4s, v0.s[2] |
| 201 | FMLA v18.4s, v26.4s, v0.s[3] |
| 202 | FMLA v19.4s, v27.4s, v0.s[3] |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 203 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 204 | TBZ x0, 3, 7f |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 205 | 6: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 206 | # Remainder- 2 floats of A (8 bytes) |
| 207 | LDR q20, [x5], 16 |
| 208 | LDR q21, [x5], 16 |
| 209 | LDR d0, [x3], 8 |
| 210 | FMLA v16.4s, v20.4s, v0.s[0] |
| 211 | FMLA v17.4s, v21.4s, v0.s[0] |
| 212 | LDR q22, [x5], 16 |
| 213 | LDR q23, [x5], 16 |
| 214 | FMLA v18.4s, v22.4s, v0.s[1] |
| 215 | FMLA v19.4s, v23.4s, v0.s[1] |
| 216 | 7: |
| 217 | TBZ x0, 2, 4b |
| 218 | 8: |
| 219 | # Remainder- 1 float of A (4 bytes) |
| 220 | LDR q20, [x5], 16 |
| 221 | LDR q21, [x5], 16 |
| 222 | LDR s0, [x3], 4 |
| 223 | FMLA v16.4s, v20.4s, v0.s[0] |
| 224 | FMLA v17.4s, v21.4s, v0.s[0] |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 225 | B 4b |
| 226 | |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 227 | # Store odd channels |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 228 | 9: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 229 | TBZ x1, 2, 10f |
| 230 | STR q16, [x6], 16 |
| 231 | MOV v16.16b, v17.16b |
| 232 | |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 233 | 10: |
Frank Barchard | 8e3c551 | 2019-10-18 18:45:08 -0700 | [diff] [blame] | 234 | TBZ x1, 1, 11f |
| 235 | STR d16, [x6], 8 |
| 236 | DUP d16, v16.d[1] |
| 237 | |
| 238 | 11: |
| 239 | TBZ x1, 0, 12f |
| 240 | STR s16, [x6] |
| 241 | 12: |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 242 | RET |
| 243 | |
Marat Dukhan | de06f49 | 2020-04-09 00:19:31 -0700 | [diff] [blame] | 244 | END_FUNCTION xnn_f32_gemm${"inc" if INC else ""}_minmax_ukernel_1x8__aarch64_neonfma_cortex_a53 |
Frank Barchard | 21be34f | 2019-10-09 19:32:19 -0700 | [diff] [blame] | 245 | |
| 246 | #ifdef __ELF__ |
| 247 | .section ".note.GNU-stack","",%progbits |
| 248 | #endif |