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 <psimd.h>
9
10 #include <xnnpack/math.h>
11 #include <xnnpack/rmax.h>
12
13
xnn_f32_rmax_ukernel__psimd(size_t n,const float * x,float * y)14 void xnn_f32_rmax_ukernel__psimd(
15 size_t n,
16 const float* x,
17 float* y)
18 {
19 assert(n != 0);
20 assert(n % sizeof(float) == 0);
21
22 psimd_f32 vmax0 = psimd_load_splat_f32(x);
23 psimd_f32 vmax1 = vmax0;
24 psimd_f32 vmax2 = vmax0;
25 psimd_f32 vmax3 = vmax0;
26 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
27 const psimd_f32 vx0 = psimd_load_f32(x);
28 const psimd_f32 vx1 = psimd_load_f32(x + 4);
29 const psimd_f32 vx2 = psimd_load_f32(x + 8);
30 const psimd_f32 vx3 = psimd_load_f32(x + 12);
31 x += 16;
32
33 vmax0 = psimd_max_f32(vmax0, vx0);
34 vmax1 = psimd_max_f32(vmax1, vx1);
35 vmax2 = psimd_max_f32(vmax2, vx2);
36 vmax3 = psimd_max_f32(vmax3, vx3);
37 }
38 psimd_f32 vmax0123 = psimd_max_f32(psimd_max_f32(vmax0, vmax1), psimd_max_f32(vmax2, vmax3));
39 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
40 const psimd_f32 vx = psimd_load_f32(x);
41 vmax0123 = psimd_max_f32(vmax0123, vx);
42 x += 4;
43 }
44 float vmax = psimd_reduce_max_f32(vmax0123);
45 if XNN_UNLIKELY(n != 0) {
46 do {
47 const float vx = *x++;
48 vmax = math_max_f32(vx, vmax);
49 n -= 4;
50 } while (n != 0);
51 }
52 *y = vmax;
53 }
54