Marat Dukhan | fda12b8 | 2019-11-21 12:27:59 -0800 | [diff] [blame] | 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: src/f32-igemm/avx-broadcast.c.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 <assert.h> |
| 11 | |
| 12 | #include <immintrin.h> |
| 13 | |
| 14 | #include <xnnpack/igemm.h> |
| 15 | |
| 16 | |
| 17 | void xnn_f32_igemm_ukernel_1x8__fma3_broadcast( |
| 18 | size_t mr, |
| 19 | size_t nc, |
| 20 | size_t kc, |
| 21 | size_t ks, |
| 22 | const float**restrict a, |
| 23 | const float*restrict w, |
| 24 | float*restrict c, |
| 25 | size_t cm_stride, |
| 26 | size_t cn_stride, |
| 27 | size_t a_offset, |
| 28 | const float* zero, |
Marat Dukhan | eb09a6b | 2020-04-08 17:34:32 -0700 | [diff] [blame] | 29 | const union xnn_f32_minmax_params params[restrict static 1]) |
Marat Dukhan | fda12b8 | 2019-11-21 12:27:59 -0800 | [diff] [blame] | 30 | { |
| 31 | assert(mr != 0); |
| 32 | assert(mr <= 1); |
| 33 | assert(nc != 0); |
| 34 | assert(kc != 0); |
| 35 | assert(kc % sizeof(float) == 0); |
| 36 | assert(ks != 0); |
| 37 | assert(ks % (1 * sizeof(void*)) == 0); |
| 38 | assert(a_offset % sizeof(float) == 0); |
| 39 | assert(a != NULL); |
| 40 | assert(w != NULL); |
| 41 | assert(c != NULL); |
| 42 | |
| 43 | float* c0 = c; |
| 44 | |
| 45 | do { |
| 46 | __m256 vacc0x01234567 = _mm256_load_ps(w); |
| 47 | w += 8; |
| 48 | |
| 49 | size_t p = ks; |
| 50 | do { |
| 51 | const float* restrict a0 = a[0]; |
| 52 | assert(a0 != NULL); |
| 53 | if XNN_UNPREDICTABLE(a0 != zero) { |
| 54 | a0 = (const float*) ((uintptr_t) a0 + a_offset); |
| 55 | } |
| 56 | a += 1; |
| 57 | |
| 58 | size_t k = kc; |
| 59 | do { |
| 60 | const __m256 vb01234567 = _mm256_load_ps(w); |
| 61 | w += 8; |
| 62 | |
| 63 | const __m256 va0 = _mm256_broadcast_ss(a0); |
| 64 | a0 += 1; |
| 65 | |
| 66 | vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567, vacc0x01234567); |
| 67 | k -= sizeof(float); |
| 68 | } while (k != 0); |
| 69 | p -= 1 * sizeof(void*); |
| 70 | } while (p != 0); |
| 71 | |
| 72 | const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max); |
| 73 | vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax); |
| 74 | |
| 75 | const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min); |
| 76 | vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin); |
| 77 | |
| 78 | if XNN_LIKELY(nc >= 8) { |
| 79 | _mm256_storeu_ps(c0, vacc0x01234567); |
| 80 | c0 = (float*) ((uintptr_t) c0 + cn_stride); |
| 81 | |
| 82 | a = (const float**restrict) ((uintptr_t) a - ks); |
| 83 | nc -= 8; |
| 84 | } else { |
| 85 | __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567); |
| 86 | if (nc & 4) { |
| 87 | _mm_storeu_ps(c0, vacc0x0123); |
| 88 | |
| 89 | vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1); |
| 90 | |
| 91 | c0 += 4; |
| 92 | } |
| 93 | if (nc & 2) { |
| 94 | _mm_storel_pi((__m64*) c0, vacc0x0123); |
| 95 | |
| 96 | vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123); |
| 97 | |
| 98 | c0 += 2; |
| 99 | } |
| 100 | if (nc & 1) { |
| 101 | _mm_store_ss(c0, vacc0x0123); |
| 102 | } |
| 103 | |
| 104 | nc = 0; |
| 105 | } |
| 106 | } while (nc != 0); |
| 107 | } |