• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-ppmm/scalar.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 <xnnpack/math.h>
13 #include <xnnpack/ppmm.h>
14 
15 
xnn_f32_ppmm_minmax_ukernel_4x2__scalar(size_t mr,size_t nc,size_t kc,const float * restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_ppmm_minmax_ukernel_4x2__scalar(
17   size_t mr,
18   size_t nc,
19   size_t kc,
20   const float*restrict a,
21   const float*restrict w,
22   float*restrict c,
23   size_t cm_stride,
24   size_t cn_stride,
25   const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
26 {
27   assert(mr != 0);
28   assert(mr <= 4);
29   assert(nc != 0);
30   assert(kc != 0);
31   assert(kc % sizeof(float) == 0);
32 
33   float* c0 = c;
34   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
35   if XNN_UNPREDICTABLE(mr < 2) {
36     c1 = c0;
37   }
38   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
39   if XNN_UNPREDICTABLE(mr <= 2) {
40     c2 = c1;
41   }
42   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
43   if XNN_UNPREDICTABLE(mr != 4) {
44     c3 = c2;
45   }
46 
47   do {
48     float vacc0x0 = w[0];
49     float vacc0x1 = w[1];
50     float vacc1x0 = vacc0x0;
51     float vacc1x1 = vacc0x1;
52     float vacc2x0 = vacc0x0;
53     float vacc2x1 = vacc0x1;
54     float vacc3x0 = vacc0x0;
55     float vacc3x1 = vacc0x1;
56     w += 2;
57 
58     size_t k = kc;
59     do {
60       const float va0 = a[0];
61       const float va1 = a[1];
62       const float va2 = a[2];
63       const float va3 = a[3];
64       a += 4;
65 
66       const float vb0 = w[0];
67       const float vb1 = w[1];
68       w += 2;
69 
70       vacc0x0 += va0 * vb0;
71       vacc1x0 += va1 * vb0;
72       vacc2x0 += va2 * vb0;
73       vacc3x0 += va3 * vb0;
74       vacc0x1 += va0 * vb1;
75       vacc1x1 += va1 * vb1;
76       vacc2x1 += va2 * vb1;
77       vacc3x1 += va3 * vb1;
78 
79       k -= sizeof(float);
80     } while (k != 0);
81 
82     const float vmax = params->scalar.max;
83     vacc0x0 = math_min_f32(vacc0x0, vmax);
84     vacc1x0 = math_min_f32(vacc1x0, vmax);
85     vacc2x0 = math_min_f32(vacc2x0, vmax);
86     vacc3x0 = math_min_f32(vacc3x0, vmax);
87     vacc0x1 = math_min_f32(vacc0x1, vmax);
88     vacc1x1 = math_min_f32(vacc1x1, vmax);
89     vacc2x1 = math_min_f32(vacc2x1, vmax);
90     vacc3x1 = math_min_f32(vacc3x1, vmax);
91 
92     const float vmin = params->scalar.min;
93     vacc0x0 = math_max_f32(vacc0x0, vmin);
94     vacc1x0 = math_max_f32(vacc1x0, vmin);
95     vacc2x0 = math_max_f32(vacc2x0, vmin);
96     vacc3x0 = math_max_f32(vacc3x0, vmin);
97     vacc0x1 = math_max_f32(vacc0x1, vmin);
98     vacc1x1 = math_max_f32(vacc1x1, vmin);
99     vacc2x1 = math_max_f32(vacc2x1, vmin);
100     vacc3x1 = math_max_f32(vacc3x1, vmin);
101 
102     if XNN_LIKELY(nc >= 2) {
103       c3[0] = vacc3x0;
104       c3[1] = vacc3x1;
105       c2[0] = vacc2x0;
106       c2[1] = vacc2x1;
107       c1[0] = vacc1x0;
108       c1[1] = vacc1x1;
109       c0[0] = vacc0x0;
110       c0[1] = vacc0x1;
111 
112       a = (const float*) ((uintptr_t) a - kc * 4);
113 
114       c3 = (float*) ((uintptr_t) c3 + cn_stride);
115       c2 = (float*) ((uintptr_t) c2 + cn_stride);
116       c1 = (float*) ((uintptr_t) c1 + cn_stride);
117       c0 = (float*) ((uintptr_t) c0 + cn_stride);
118 
119       nc -= 2;
120     } else {
121       if (nc & 1) {
122         *c3 = vacc3x0;
123         *c2 = vacc2x0;
124         *c1 = vacc1x0;
125         *c0 = vacc0x0;
126       }
127 
128       nc = 0;
129     }
130   } while (nc != 0);
131 }
132