1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vrnd/vrndne-wasmsimd-addsub.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_vrndne_ukernel__wasmsimd_addsub_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_vrndne_ukernel__wasmsimd_addsub_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 vabsx0123 = wasm_v128_andnot(vx0123, vsign_mask);
36 const v128_t vabsx4567 = wasm_v128_andnot(vx4567, vsign_mask);
37
38 const v128_t vrndmask0123 = wasm_v128_or(vsign_mask, wasm_f32x4_le(vmagic_number, vabsx0123));
39 const v128_t vrndmask4567 = wasm_v128_or(vsign_mask, wasm_f32x4_le(vmagic_number, vabsx4567));
40
41 const v128_t vrndabsx0123 = wasm_f32x4_sub(wasm_f32x4_add(vabsx0123, vmagic_number), vmagic_number);
42 const v128_t vrndabsx4567 = wasm_f32x4_sub(wasm_f32x4_add(vabsx4567, vmagic_number), vmagic_number);
43
44 const v128_t vy0123 = wasm_v128_bitselect(vx0123, vrndabsx0123, vrndmask0123);
45 const v128_t vy4567 = wasm_v128_bitselect(vx4567, vrndabsx4567, vrndmask4567);
46
47 wasm_v128_store(y, vy0123);
48 wasm_v128_store(y + 4, vy4567);
49 y += 8;
50 }
51 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
52 const v128_t vx = wasm_v128_load(x);
53 x += 4;
54
55 const v128_t vabsx = wasm_v128_andnot(vx, vsign_mask);
56 const v128_t vrndmask = wasm_v128_or(vsign_mask, wasm_f32x4_le(vmagic_number, vabsx));
57 const v128_t vrndabsx = wasm_f32x4_sub(wasm_f32x4_add(vabsx, vmagic_number), vmagic_number);
58 const v128_t vy = wasm_v128_bitselect(vx, vrndabsx, vrndmask);
59
60 wasm_v128_store(y, vy);
61 y += 4;
62 }
63 if XNN_UNLIKELY(n != 0) {
64 const v128_t vx = wasm_v128_load(x);
65
66 const v128_t vabsx = wasm_v128_andnot(vx, vsign_mask);
67 const v128_t vrndmask = wasm_v128_or(vsign_mask, wasm_f32x4_le(vmagic_number, vabsx));
68 const v128_t vrndabsx = wasm_f32x4_sub(wasm_f32x4_add(vabsx, vmagic_number), vmagic_number);
69 v128_t vy = wasm_v128_bitselect(vx, vrndabsx, vrndmask);
70
71 if (n & (2 * sizeof(float))) {
72 *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
73 vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3);
74 y += 2;
75 }
76 if (n & (1 * sizeof(float))) {
77 *y = wasm_f32x4_extract_lane(vy, 0);
78 }
79 }
80 }
81