• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-prelu/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/prelu.h>
14 
15 
xnn_f32_prelu_ukernel__scalar_2x4(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)16 void xnn_f32_prelu_ukernel__scalar_2x4(
17     size_t rows,
18     size_t channels,
19     const float*restrict input,
20     size_t input_stride,
21     const float*restrict weights,
22     float*restrict output,
23     size_t output_stride)
24 {
25   assert(rows != 0);
26   assert(channels != 0);
27   assert(channels % sizeof(float) == 0);
28 
29   const float* i0 = input;
30   float* o0 = output;
31   const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
32   float* o1 = (float*) ((uintptr_t) o0 + output_stride);
33   if XNN_UNPREDICTABLE(rows < 2) {
34     i1 = i0;
35     o1 = o0;
36   }
37 
38   const size_t input_increment = input_stride * 2 - channels;
39   const size_t output_increment = output_stride * 2 - channels;
40 
41   do {
42     const float* w = weights;
43     size_t c = channels;
44     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
45       const float vw0 = w[0];
46       const float vw1 = w[1];
47       const float vw2 = w[2];
48       const float vw3 = w[3];
49 
50       const float vi0x0 = i0[0];
51       const float vi0x1 = i0[1];
52       const float vi0x2 = i0[2];
53       const float vi0x3 = i0[3];
54       i0 += 4;
55       const float vi1x0 = i1[0];
56       const float vi1x1 = i1[1];
57       const float vi1x2 = i1[2];
58       const float vi1x3 = i1[3];
59       i1 += 4;
60 
61       const float vacc0x0 = XNN_UNPREDICTABLE(vi0x0 < 0.0f) ? vi0x0 * vw0 : vi0x0;
62       const float vacc0x1 = XNN_UNPREDICTABLE(vi0x1 < 0.0f) ? vi0x1 * vw1 : vi0x1;
63       const float vacc0x2 = XNN_UNPREDICTABLE(vi0x2 < 0.0f) ? vi0x2 * vw2 : vi0x2;
64       const float vacc0x3 = XNN_UNPREDICTABLE(vi0x3 < 0.0f) ? vi0x3 * vw3 : vi0x3;
65       const float vacc1x0 = XNN_UNPREDICTABLE(vi1x0 < 0.0f) ? vi1x0 * vw0 : vi1x0;
66       const float vacc1x1 = XNN_UNPREDICTABLE(vi1x1 < 0.0f) ? vi1x1 * vw1 : vi1x1;
67       const float vacc1x2 = XNN_UNPREDICTABLE(vi1x2 < 0.0f) ? vi1x2 * vw2 : vi1x2;
68       const float vacc1x3 = XNN_UNPREDICTABLE(vi1x3 < 0.0f) ? vi1x3 * vw3 : vi1x3;
69 
70       o0[0] = vacc0x0;
71       o0[1] = vacc0x1;
72       o0[2] = vacc0x2;
73       o0[3] = vacc0x3;
74       o0 += 4;
75       o1[0] = vacc1x0;
76       o1[1] = vacc1x1;
77       o1[2] = vacc1x2;
78       o1[3] = vacc1x3;
79       o1 += 4;
80 
81       w += 4;
82     }
83     for (; c != 0; c -= sizeof(float)) {
84       const float vw = *w++;
85 
86       const float vi0 = *i0++;
87       const float vi1 = *i1++;
88 
89       const float vacc0 = XNN_UNPREDICTABLE(vi0 < 0.0f) ? vi0 * vw : vi0;
90       const float vacc1 = XNN_UNPREDICTABLE(vi1 < 0.0f) ? vi1 * vw : vi1;
91 
92       *o0++ = vacc0;
93       *o1++ = vacc1;
94     }
95     i0 = (const float*) ((uintptr_t) i0 + input_increment);
96     o0 = (float*) ((uintptr_t) o0 + output_increment);
97     i1 = (const float*) ((uintptr_t) i1 + input_increment);
98     o1 = (float*) ((uintptr_t) o1 + output_increment);
99     if XNN_UNPREDICTABLE(rows < 4) {
100       i1 = i0;
101       o1 = o0;
102     }
103     rows = doz(rows, 2);
104   } while (rows != 0);
105 }
106