1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vmulcaddc/sse.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 <xmmintrin.h>
13
14 #include <xnnpack/math.h>
15 #include <xnnpack/vmulcaddc.h>
16
17
xnn_f32_vmulcaddc_minmax_ukernel_c4__sse_2x(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_vmulcaddc_minmax_ukernel_c4__sse_2x(
19 size_t rows,
20 size_t channels,
21 const float*restrict input,
22 size_t input_stride,
23 const float*restrict weights,
24 float*restrict output,
25 size_t output_stride,
26 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
27 {
28 assert(rows != 0);
29 assert(channels != 0);
30 assert(channels % sizeof(float) == 0);
31
32 const float* i0 = input;
33 float* o0 = output;
34 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
35 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
36
37 const size_t input_increment = input_stride * 2 - channels;
38 const size_t output_increment = output_stride * 2 - channels;
39
40 const __m128 vmin = _mm_load_ps(params->sse.min);
41 const __m128 vmax = _mm_load_ps(params->sse.max);
42 do {
43 if XNN_UNPREDICTABLE(rows < 2) {
44 i1 = i0;
45 o1 = o0;
46 }
47
48 const float* w = weights;
49 size_t c = channels;
50 for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
51 const __m128 vscale0123 = _mm_load_ps(w);
52
53 __m128 vacc0x0123 = _mm_loadu_ps(i0);
54 i0 += 4;
55 __m128 vacc1x0123 = _mm_loadu_ps(i1);
56 i1 += 4;
57
58 vacc0x0123 = _mm_mul_ps(vacc0x0123, vscale0123);
59 vacc1x0123 = _mm_mul_ps(vacc1x0123, vscale0123);
60
61 const __m128 vbias0123 = _mm_load_ps(w + 4);
62
63 vacc0x0123 = _mm_add_ps(vacc0x0123, vbias0123);
64 vacc1x0123 = _mm_add_ps(vacc1x0123, vbias0123);
65
66 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
67 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
68
69 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
70 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
71
72 _mm_storeu_ps(o0, vacc0x0123);
73 o0 += 4;
74 _mm_storeu_ps(o1, vacc1x0123);
75 o1 += 4;
76
77 w += 8;
78 }
79 if XNN_UNLIKELY(c != 0) {
80 const __m128 vscale0123 = _mm_load_ps(w);
81
82 __m128 vacc0x0123 = _mm_loadu_ps(i0);
83 i0 = (const float*) ((uintptr_t) i0 + c);
84 __m128 vacc1x0123 = _mm_loadu_ps(i1);
85 i1 = (const float*) ((uintptr_t) i1 + c);
86
87 vacc0x0123 = _mm_mul_ps(vacc0x0123, vscale0123);
88 vacc1x0123 = _mm_mul_ps(vacc1x0123, vscale0123);
89
90 const __m128 vbias0123 = _mm_load_ps(w + 4);
91
92 vacc0x0123 = _mm_add_ps(vacc0x0123, vbias0123);
93 vacc1x0123 = _mm_add_ps(vacc1x0123, vbias0123);
94
95 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
96 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
97
98 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
99 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
100
101 if (c & (2 * sizeof(float))) {
102 _mm_storel_pi((__m64*) o0, vacc0x0123);
103 _mm_storel_pi((__m64*) o1, vacc1x0123);
104
105 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
106 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
107
108 o0 += 2;
109 o1 += 2;
110 }
111 if (c & (1 * sizeof(float))) {
112 _mm_store_ss(o0, vacc0x0123);
113 _mm_store_ss(o1, vacc1x0123);
114
115 o0 += 1;
116 o1 += 1;
117 }
118 }
119 i0 = (const float*) ((uintptr_t) i0 + input_increment);
120 o0 = (float*) ((uintptr_t) o0 + output_increment);
121 i1 = (const float*) ((uintptr_t) i1 + input_increment);
122 o1 = (float*) ((uintptr_t) o1 + output_increment);
123 rows = doz(rows, 2);
124 } while (rows != 0);
125 }
126