• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vrnd/vrndz-wasmsimd-cvt.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <wasm_simd128.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/vunary.h>
17 
18 
xnn_f32_vrndz_ukernel__wasmsimd_cvt_x8(size_t n,const float * x,float * y,const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_vrndz_ukernel__wasmsimd_cvt_x8(
20     size_t n,
21     const float* x,
22     float* y,
23     const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
24 {
25   assert(n != 0);
26   assert(n % sizeof(float) == 0);
27 
28   const v128_t vsign_mask = wasm_f32x4_splat(-0.0f);
29   const v128_t vmagic_number = wasm_f32x4_splat(0x1.000000p+23f);
30   for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
31     const v128_t vx0123 = wasm_v128_load(x);
32     const v128_t vx4567 = wasm_v128_load(x + 4);
33     x += 8;
34 
35     const v128_t vintx0123 = wasm_i32x4_trunc_saturate_f32x4(vx0123);
36     const v128_t vabsx0123 = wasm_f32x4_abs(vx0123);
37     const v128_t vintx4567 = wasm_i32x4_trunc_saturate_f32x4(vx4567);
38     const v128_t vabsx4567 = wasm_f32x4_abs(vx4567);
39 
40     const v128_t vrndx0123 = wasm_f32x4_convert_i32x4(vintx0123);
41     const v128_t vrndmask0123 = wasm_v128_andnot(wasm_f32x4_lt(vabsx0123, vmagic_number), vsign_mask);
42     const v128_t vrndx4567 = wasm_f32x4_convert_i32x4(vintx4567);
43     const v128_t vrndmask4567 = wasm_v128_andnot(wasm_f32x4_lt(vabsx4567, vmagic_number), vsign_mask);
44 
45     const v128_t vy0123 = wasm_v128_bitselect(vrndx0123, vx0123, vrndmask0123);
46     const v128_t vy4567 = wasm_v128_bitselect(vrndx4567, vx4567, vrndmask4567);
47 
48     wasm_v128_store(y, vy0123);
49     wasm_v128_store(y + 4, vy4567);
50     y += 8;
51   }
52   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
53     const v128_t vx = wasm_v128_load(x);
54     x += 4;
55 
56     const v128_t vintx = wasm_i32x4_trunc_saturate_f32x4(vx);
57     const v128_t vabsx = wasm_f32x4_abs(vx);
58     const v128_t vrndx = wasm_f32x4_convert_i32x4(vintx);
59     const v128_t vrndmask = wasm_v128_andnot(wasm_f32x4_lt(vabsx, vmagic_number), vsign_mask);
60     const v128_t vy = wasm_v128_bitselect(vrndx, vx, vrndmask);
61 
62     wasm_v128_store(y, vy);
63     y += 4;
64   }
65   if XNN_UNLIKELY(n != 0) {
66     const v128_t vx = wasm_v128_load(x);
67 
68     const v128_t vintx = wasm_i32x4_trunc_saturate_f32x4(vx);
69     const v128_t vabsx = wasm_f32x4_abs(vx);
70     const v128_t vrndx = wasm_f32x4_convert_i32x4(vintx);
71     const v128_t vrndmask = wasm_v128_andnot(wasm_f32x4_lt(vabsx, vmagic_number), vsign_mask);
72     v128_t vy = wasm_v128_bitselect(vrndx, vx, vrndmask);
73 
74     if (n & (2 * sizeof(float))) {
75       *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
76       vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
77       y += 2;
78     }
79     if (n & (1 * sizeof(float))) {
80       *y = wasm_f32x4_extract_lane(vy, 0);
81     }
82   }
83 }
84