• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vmulcaddc/psimd.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 <psimd.h>
13 
14 #include <xnnpack/math.h>
15 #include <xnnpack/vmulcaddc.h>
16 
17 
xnn_f32_vmulcaddc_ukernel_c4__psimd_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_output_params params[restrict static1])18 void xnn_f32_vmulcaddc_ukernel_c4__psimd_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_output_params params[restrict static 1])
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   if XNN_UNPREDICTABLE(rows < 2) {
37     i1 = i0;
38     o1 = o0;
39   }
40 
41   const size_t input_increment = input_stride * 2 - channels;
42   const size_t output_increment = output_stride * 2 - channels;
43 
44   const psimd_f32 vmin = psimd_load_splat_f32(&params->scalar.min);
45   const psimd_f32 vmax = psimd_load_splat_f32(&params->scalar.max);
46   do {
47     const float* w = weights;
48     size_t c = channels;
49     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
50       const psimd_f32 vscale0123 = psimd_load_f32(w);
51 
52       psimd_f32 vacc0x0123 = psimd_load_f32(i0);
53       i0 += 4;
54       psimd_f32 vacc1x0123 = psimd_load_f32(i1);
55       i1 += 4;
56 
57       const psimd_f32 vbias0123 = psimd_load_f32(w + 4);
58 
59       vacc0x0123 = psimd_qfma_f32(vbias0123, vscale0123, vacc0x0123);
60       vacc1x0123 = psimd_qfma_f32(vbias0123, vscale0123, vacc1x0123);
61 
62       vacc0x0123 = psimd_max_f32(vacc0x0123, vmin);
63       vacc1x0123 = psimd_max_f32(vacc1x0123, vmin);
64 
65       vacc0x0123 = psimd_min_f32(vacc0x0123, vmax);
66       vacc1x0123 = psimd_min_f32(vacc1x0123, vmax);
67 
68       psimd_store_f32(o0, vacc0x0123);
69       o0 += 4;
70       psimd_store_f32(o1, vacc1x0123);
71       o1 += 4;
72 
73       w += 8;
74     }
75     if XNN_UNLIKELY(c != 0) {
76       const psimd_f32 vscale0123 = psimd_load_f32(w);
77 
78       psimd_f32 vacc0x0123 = psimd_load_f32(i0);
79       i0 = (const float*) ((uintptr_t) i0 + c);
80       psimd_f32 vacc1x0123 = psimd_load_f32(i1);
81       i1 = (const float*) ((uintptr_t) i1 + c);
82 
83       const psimd_f32 vbias0123 = psimd_load_f32(w + 4);
84 
85       vacc0x0123 = psimd_qfma_f32(vbias0123, vscale0123, vacc0x0123);
86       vacc1x0123 = psimd_qfma_f32(vbias0123, vscale0123, vacc1x0123);
87 
88       vacc0x0123 = psimd_max_f32(vacc0x0123, vmin);
89       vacc1x0123 = psimd_max_f32(vacc1x0123, vmin);
90 
91       vacc0x0123 = psimd_min_f32(vacc0x0123, vmax);
92       vacc1x0123 = psimd_min_f32(vacc1x0123, vmax);
93 
94       if (c & (2 * sizeof(float))) {
95         psimd_store2_f32(o0, vacc0x0123);
96         psimd_store2_f32(o1, vacc1x0123);
97 
98         vacc0x0123 = psimd_concat_hi_f32(vacc0x0123, vacc0x0123);
99         vacc1x0123 = psimd_concat_hi_f32(vacc1x0123, vacc1x0123);
100 
101         o0 += 2;
102         o1 += 2;
103       }
104       if (c & (1 * sizeof(float))) {
105         psimd_store1_f32(o0, vacc0x0123);
106         psimd_store1_f32(o1, vacc1x0123);
107 
108         o0 += 1;
109         o1 += 1;
110       }
111     }
112     i0 = (const float*) ((uintptr_t) i0 + input_increment);
113     o0 = (float*) ((uintptr_t) o0 + output_increment);
114     i1 = (const float*) ((uintptr_t) i1 + input_increment);
115     o1 = (float*) ((uintptr_t) o1 + output_increment);
116     if XNN_UNPREDICTABLE(rows < 4) {
117       i1 = i0;
118       o1 = o0;
119     }
120     rows = doz(rows, 2);
121   } while (rows != 0);
122 }
123