/src/xnnpack/src/f32-igemm/gen/f32-igemm-1x32-minmax-avx512f-broadcast.c
Line | Count | Source |
1 | | // clang-format off |
2 | | // Auto-generated file. Do not edit! |
3 | | // Template: src/f32-igemm/avx512-broadcast.c.in |
4 | | // Generator: tools/xngen |
5 | | // |
6 | | // Copyright 2019 Google LLC |
7 | | // |
8 | | // This source code is licensed under the BSD-style license found in the |
9 | | // LICENSE file in the root directory of this source tree. |
10 | | |
11 | | #include <assert.h> |
12 | | #include <stddef.h> |
13 | | #include <stdint.h> |
14 | | |
15 | | #include <immintrin.h> |
16 | | |
17 | | #include "src/xnnpack/common.h" |
18 | | #include "src/xnnpack/microparams.h" |
19 | | #include "src/xnnpack/igemm.h" |
20 | | #include "src/xnnpack/intrinsics-polyfill.h" |
21 | | |
22 | | |
23 | | void xnn_f32_igemm_minmax_ukernel_1x32__avx512f_broadcast( |
24 | | size_t mr, |
25 | | size_t nc, |
26 | | size_t kc, |
27 | | size_t ks, |
28 | | const float** restrict a, |
29 | | const float* restrict w, |
30 | | float* restrict c, |
31 | | size_t cm_stride, |
32 | | size_t cn_stride, |
33 | | size_t a_offset, |
34 | | const float* zero, |
35 | | const struct xnn_f32_minmax_params* restrict params) |
36 | 0 | { |
37 | 0 | assert(mr != 0); |
38 | 0 | assert(mr <= 1); |
39 | 0 | assert(nc != 0); |
40 | 0 | assert(kc != 0); |
41 | 0 | assert(kc % sizeof(float) == 0); |
42 | 0 | assert(ks != 0); |
43 | 0 | assert(ks % (1 * sizeof(void*)) == 0); |
44 | 0 | assert(a_offset % sizeof(float) == 0); |
45 | 0 | assert(a != NULL); |
46 | 0 | assert(w != NULL); |
47 | 0 | assert(c != NULL); |
48 | | |
49 | 0 | float* c0 = c; |
50 | |
|
51 | 0 | do { |
52 | 0 | __m512 vacc0x0 = _mm512_load_ps(w); |
53 | 0 | __m512 vacc0x1 = _mm512_load_ps(w + 16); |
54 | 0 | w += 32; |
55 | |
|
56 | 0 | size_t p = ks; |
57 | 0 | do { |
58 | 0 | const float* restrict a0 = a[0]; |
59 | 0 | assert(a0 != NULL); |
60 | 0 | if XNN_UNPREDICTABLE(a0 != zero) { |
61 | 0 | a0 = (const float*) ((uintptr_t) a0 + a_offset); |
62 | 0 | } |
63 | 0 | a += 1; |
64 | |
|
65 | 0 | size_t k = kc; |
66 | 0 | do { |
67 | 0 | const __m512 vb0 = _mm512_load_ps(w); |
68 | 0 | const __m512 vb1 = _mm512_load_ps(w + 16); |
69 | 0 | w += 32; |
70 | |
|
71 | 0 | const __m512 va0 = _mm512_set1_ps(*a0); |
72 | 0 | vacc0x0 = _mm512_fmadd_ps(va0, vb0, vacc0x0); |
73 | 0 | vacc0x1 = _mm512_fmadd_ps(va0, vb1, vacc0x1); |
74 | |
|
75 | 0 | a0 += 1; |
76 | |
|
77 | 0 | k -= sizeof(float); |
78 | 0 | } while (k != 0); |
79 | 0 | p -= 1 * sizeof(void*); |
80 | 0 | } while (p != 0); |
81 | | |
82 | 0 | const __m512 vmin = _mm512_set1_ps(params->scalar.min); |
83 | 0 | vacc0x0 = _mm512_max_ps(vmin, vacc0x0); |
84 | 0 | vacc0x1 = _mm512_max_ps(vmin, vacc0x1); |
85 | |
|
86 | 0 | const __m512 vmax = _mm512_set1_ps(params->scalar.max); |
87 | 0 | vacc0x0 = _mm512_min_ps(vmax, vacc0x0); |
88 | 0 | vacc0x1 = _mm512_min_ps(vmax, vacc0x1); |
89 | |
|
90 | 0 | if XNN_LIKELY(nc >= 32) { |
91 | 0 | _mm512_storeu_ps(c0, vacc0x0); |
92 | 0 | _mm512_storeu_ps(c0 + 16, vacc0x1); |
93 | 0 | c0 = (float*) ((uintptr_t) c0 + cn_stride); |
94 | |
|
95 | 0 | a = (const float**restrict) ((uintptr_t) a - ks); |
96 | 0 | nc -= 32; |
97 | 0 | } else { |
98 | | // NC remainder (1..31) |
99 | 0 | assert(nc >= 1); |
100 | 0 | assert(nc <= 31); |
101 | | // Prepare mask for valid 32-bit elements (depends on nc). |
102 | 0 | const __mmask16 vmask0 = _cvtu32_mask16((uint32_t) (((UINT64_C(1) << nc) - 1) >> 0)); |
103 | 0 | const __mmask16 vmask1 = _cvtu32_mask16((uint32_t) (((UINT64_C(1) << nc) - 1) >> 16)); |
104 | |
|
105 | 0 | _mm512_mask_storeu_ps(c0 + 0, vmask0, vacc0x0); |
106 | 0 | _mm512_mask_storeu_ps(c0 + 16, vmask1, vacc0x1); |
107 | 0 | nc = 0; |
108 | 0 | } |
109 | 0 | } while (nc != 0); |
110 | 0 | } |