• 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/rmax.h>
11 
12 
xnn_f32_rmax_ukernel__wasmsimd_arm(size_t n,const float * x,float * y)13 void xnn_f32_rmax_ukernel__wasmsimd_arm(
14     size_t n,
15     const float* x,
16     float* y)
17 {
18   assert(n != 0);
19   assert(n % sizeof(float) == 0);
20 
21   v128_t vmax0 = wasm_v128_load32_splat(x);
22   v128_t vmax1 = vmax0;
23   v128_t vmax2 = vmax0;
24   v128_t vmax3 = vmax0;
25   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
26     const v128_t vx0 = wasm_v128_load(x);
27     const v128_t vx1 = wasm_v128_load(x + 4);
28     const v128_t vx2 = wasm_v128_load(x + 8);
29     const v128_t vx3 = wasm_v128_load(x + 12);
30     x += 16;
31 
32     vmax0 = wasm_f32x4_max(vmax0, vx0);
33     vmax1 = wasm_f32x4_max(vmax1, vx1);
34     vmax2 = wasm_f32x4_max(vmax2, vx2);
35     vmax3 = wasm_f32x4_max(vmax3, vx3);
36   }
37   v128_t vmax0123 = wasm_f32x4_max(wasm_f32x4_max(vmax0, vmax1), wasm_f32x4_max(vmax2, vmax3));
38   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
39     const v128_t vx = wasm_v128_load(x);
40     vmax0123 = wasm_f32x4_max(vmax0123, vx);
41     x += 4;
42   }
43   vmax0123 = wasm_f32x4_max(vmax0123, wasm_v32x4_shuffle(vmax0123, vmax0123, 2, 3, 0, 1));
44   float vmax = __builtin_wasm_max_f32(wasm_f32x4_extract_lane(vmax0123, 0), wasm_f32x4_extract_lane(vmax0123, 1));
45   if XNN_UNLIKELY(n != 0) {
46     do {
47       const float vx = *x++;
48       vmax = __builtin_wasm_max_f32(vx, vmax);
49       n -= 4;
50     } while (n != 0);
51   }
52   *y = vmax;
53 }
54