• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <xnnpack/math.h>
9 #include <xnnpack/rmax.h>
10 
11 
xnn_f32_rmax_ukernel__scalar(size_t n,const float * x,float * y)12 void xnn_f32_rmax_ukernel__scalar(
13     size_t n,
14     const float* x,
15     float* y)
16 {
17   assert(n != 0);
18   assert(n % sizeof(float) == 0);
19 
20   float vmax0 = *x;
21   float vmax1 = vmax0;
22   float vmax2 = vmax0;
23   float vmax3 = vmax0;
24   for (; n >= 16; n -= 16) {
25     const float vx0 = x[0];
26     const float vx1 = x[1];
27     const float vx2 = x[2];
28     const float vx3 = x[3];
29     x += 4;
30 
31     vmax0 = math_max_f32(vx0, vmax0);
32     vmax1 = math_max_f32(vx1, vmax1);
33     vmax2 = math_max_f32(vx2, vmax2);
34     vmax3 = math_max_f32(vx3, vmax3);
35   }
36   const float vmax01 = math_max_f32(vmax0, vmax1);
37   const float vmax23 = math_max_f32(vmax2, vmax3);
38   float vmax = math_max_f32(vmax01, vmax23);
39   if XNN_UNLIKELY(n != 0) {
40     do {
41       const float vx = *x++;
42       vmax = math_max_f32(vx, vmax);
43       n -= 4;
44     } while (n != 0);
45   }
46   *y = vmax;
47 }
48