• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/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/gemm.h>
15 
16 
xnn_f32_gemminc_ukernel_1x8__avx_broadcast(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const float * restrict acc,const union xnn_f32_output_params params[restrict static1])17 void xnn_f32_gemminc_ukernel_1x8__avx_broadcast(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     const float*restrict a,
22     size_t a_stride,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     const float*restrict acc,
28     const union xnn_f32_output_params params[restrict static 1])
29 {
30   assert(mr != 0);
31   assert(mr <= 1);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38   assert(acc != NULL);
39 
40   const float* a0 = a;
41   float* c0 = c;
42 
43   do {
44     __m256 vacc0x01234567 = _mm256_load_ps(acc + 0);
45     acc += 8;
46 
47     size_t k = kc;
48     do {
49       const __m256 va0 = _mm256_broadcast_ss(a0);
50       a0 += 1;
51 
52       const __m256 vb01234567 = _mm256_load_ps(w);
53       w += 8;
54 
55       vacc0x01234567 = _mm256_add_ps(vacc0x01234567, _mm256_mul_ps(va0, vb01234567));
56 
57       k -= sizeof(float);
58     } while (k != 0);
59 
60     const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
61     vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
62 
63     const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
64     vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
65 
66     if XNN_LIKELY(nc >= 8) {
67       _mm256_storeu_ps(c0, vacc0x01234567);
68       c0 = (float*) ((uintptr_t) c0 + cn_stride);
69 
70       a0 = (const float*) ((uintptr_t) a0 - kc);
71 
72       nc -= 8;
73     } else {
74       __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
75       if (nc & 4) {
76         _mm_storeu_ps(c0, vacc0x0123);
77 
78         vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
79 
80         c0 += 4;
81       }
82       if (nc & 2) {
83         _mm_storel_pi((__m64*) c0, vacc0x0123);
84 
85         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
86 
87         c0 += 2;
88       }
89       if (nc & 1) {
90         _mm_store_ss(c0, vacc0x0123);
91       }
92 
93       nc = 0;
94     }
95   } while (nc != 0);
96 }
97