• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 <wasm_simd128.h>
9 
10 #include <xnnpack/math.h>
11 #include <xnnpack/rmax.h>
12 
13 
xnn_f32_rmax_ukernel__wasmsimd_x86(size_t n,const float * x,float * y)14 void xnn_f32_rmax_ukernel__wasmsimd_x86(
15     size_t n,
16     const float* x,
17     float* y)
18 {
19   assert(n != 0);
20   assert(n % sizeof(float) == 0);
21 
22   v128_t vmax0 = wasm_v32x4_load_splat(x);
23   v128_t vmax1 = vmax0;
24   v128_t vmax2 = vmax0;
25   v128_t vmax3 = vmax0;
26   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
27     const v128_t vx0 = wasm_v128_load(x);
28     const v128_t vx1 = wasm_v128_load(x + 4);
29     const v128_t vx2 = wasm_v128_load(x + 8);
30     const v128_t vx3 = wasm_v128_load(x + 12);
31     x += 16;
32 
33     const v128_t vlt0 = wasm_f32x4_lt(vx0, vmax0);
34     const v128_t vlt1 = wasm_f32x4_lt(vx1, vmax1);
35     const v128_t vlt2 = wasm_f32x4_lt(vx2, vmax2);
36     const v128_t vlt3 = wasm_f32x4_lt(vx3, vmax3);
37 
38     vmax0 = wasm_v128_bitselect(vmax0, vx0, vlt0);
39     vmax1 = wasm_v128_bitselect(vmax1, vx1, vlt1);
40     vmax2 = wasm_v128_bitselect(vmax2, vx2, vlt2);
41     vmax3 = wasm_v128_bitselect(vmax3, vx3, vlt3);
42   }
43   const v128_t vlt01 = wasm_f32x4_lt(vmax0, vmax1);
44   const v128_t vlt23 = wasm_f32x4_lt(vmax2, vmax3);
45   const v128_t vmax01 = wasm_v128_bitselect(vmax1, vmax0, vlt01);
46   const v128_t vmax23 = wasm_v128_bitselect(vmax3, vmax2, vlt23);
47   v128_t vmax0123 = wasm_v128_bitselect(vmax23, vmax01, wasm_f32x4_lt(vmax01, vmax23));
48   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
49     const v128_t vx = wasm_v128_load(x);
50     vmax0123 = wasm_v128_bitselect(vmax0123, vx, wasm_f32x4_lt(vx, vmax0123));
51     x += 4;
52   }
53   const v128_t vmax2301 = wasm_v32x4_shuffle(vmax0123, vmax0123, 2, 3, 0, 1);
54   vmax0123 = wasm_v128_bitselect(vmax2301, vmax0123, wasm_f32x4_lt(vmax0123, vmax2301));
55   float vmax = math_max_f32(wasm_f32x4_extract_lane(vmax0123, 0), wasm_f32x4_extract_lane(vmax0123, 1));
56   if XNN_UNLIKELY(n != 0) {
57     do {
58       const float vx = *x++;
59       vmax = math_max_f32(vx, vmax);
60       n -= 4;
61     } while (n != 0);
62   }
63   *y = vmax;
64 }
65