1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-vcvt/wasmsimd.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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/intrinsics-polyfill.h>
16 #include <xnnpack/vcvt.h>
17
18
xnn_qs8_f32_vcvt_ukernel__wasmsimd_x32(size_t n,const int8_t * x,float * y,const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qs8_f32_vcvt_ukernel__wasmsimd_x32(
20 size_t n,
21 const int8_t* x,
22 float* y,
23 const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(int8_t) == 0);
27 assert(x != NULL);
28 assert(y != NULL);
29
30 const v128_t vminus_zero_point = wasm_v128_load64_splat(params->wasmsimd.minus_zero_point);
31 const v128_t vscale = wasm_v128_load64_splat(params->wasmsimd.scale);
32 for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) {
33 v128_t vx01234567 = wasm_i16x8_load8x8(x);
34 v128_t vx89ABCDEF = wasm_i16x8_load8x8(x + 8);
35 v128_t vxGHIJKLMN = wasm_i16x8_load8x8(x + 16);
36 v128_t vxOPQRSTUV = wasm_i16x8_load8x8(x + 24);
37 x += 32;
38
39 vx01234567 = wasm_i16x8_add(vx01234567, vminus_zero_point);
40 vx89ABCDEF = wasm_i16x8_add(vx89ABCDEF, vminus_zero_point);
41 vxGHIJKLMN = wasm_i16x8_add(vxGHIJKLMN, vminus_zero_point);
42 vxOPQRSTUV = wasm_i16x8_add(vxOPQRSTUV, vminus_zero_point);
43
44 v128_t vy0123 = wasm_i32x4_extend_low_i16x8(vx01234567);
45 v128_t vy4567 = wasm_i32x4_extend_high_i16x8(vx01234567);
46 v128_t vy89AB = wasm_i32x4_extend_low_i16x8(vx89ABCDEF);
47 v128_t vyCDEF = wasm_i32x4_extend_high_i16x8(vx89ABCDEF);
48 v128_t vyGHIJ = wasm_i32x4_extend_low_i16x8(vxGHIJKLMN);
49 v128_t vyKLMN = wasm_i32x4_extend_high_i16x8(vxGHIJKLMN);
50 v128_t vyOPQR = wasm_i32x4_extend_low_i16x8(vxOPQRSTUV);
51 v128_t vySTUV = wasm_i32x4_extend_high_i16x8(vxOPQRSTUV);
52
53 vy0123 = wasm_f32x4_convert_i32x4(vy0123);
54 vy4567 = wasm_f32x4_convert_i32x4(vy4567);
55 vy89AB = wasm_f32x4_convert_i32x4(vy89AB);
56 vyCDEF = wasm_f32x4_convert_i32x4(vyCDEF);
57 vyGHIJ = wasm_f32x4_convert_i32x4(vyGHIJ);
58 vyKLMN = wasm_f32x4_convert_i32x4(vyKLMN);
59 vyOPQR = wasm_f32x4_convert_i32x4(vyOPQR);
60 vySTUV = wasm_f32x4_convert_i32x4(vySTUV);
61
62 vy0123 = wasm_f32x4_mul(vy0123, vscale);
63 vy4567 = wasm_f32x4_mul(vy4567, vscale);
64 vy89AB = wasm_f32x4_mul(vy89AB, vscale);
65 vyCDEF = wasm_f32x4_mul(vyCDEF, vscale);
66 vyGHIJ = wasm_f32x4_mul(vyGHIJ, vscale);
67 vyKLMN = wasm_f32x4_mul(vyKLMN, vscale);
68 vyOPQR = wasm_f32x4_mul(vyOPQR, vscale);
69 vySTUV = wasm_f32x4_mul(vySTUV, vscale);
70
71 wasm_v128_store(y, vy0123);
72 wasm_v128_store(y + 4, vy4567);
73 wasm_v128_store(y + 8, vy89AB);
74 wasm_v128_store(y + 12, vyCDEF);
75 wasm_v128_store(y + 16, vyGHIJ);
76 wasm_v128_store(y + 20, vyKLMN);
77 wasm_v128_store(y + 24, vyOPQR);
78 wasm_v128_store(y + 28, vySTUV);
79 y += 32;
80 }
81 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
82 v128_t vx = wasm_i16x8_load8x8(x);
83 vx = wasm_i16x8_add(vx, vminus_zero_point);
84 x += 8;
85
86 v128_t vy_lo = wasm_i32x4_extend_low_i16x8(vx);
87 v128_t vy_hi = wasm_i32x4_extend_high_i16x8(vx);
88
89 vy_lo = wasm_f32x4_convert_i32x4(vy_lo);
90 vy_hi = wasm_f32x4_convert_i32x4(vy_hi);
91
92 vy_lo = wasm_f32x4_mul(vy_lo, vscale);
93 vy_hi = wasm_f32x4_mul(vy_hi, vscale);
94
95 wasm_v128_store(y, vy_lo);
96 wasm_v128_store(y + 4, vy_hi);
97 y += 8;
98 }
99 if XNN_UNLIKELY(n != 0) {
100 assert(n >= 1 * sizeof(int8_t));
101 assert(n <= 7 * sizeof(int8_t));
102
103 v128_t vx = wasm_i16x8_load8x8(x);
104 vx = wasm_i16x8_add(vx, vminus_zero_point);
105 x += 8;
106
107 v128_t vy = wasm_i32x4_extend_low_i16x8(vx);
108 vy = wasm_f32x4_convert_i32x4(vy);
109 vy = wasm_f32x4_mul(vy, vscale);
110
111 if (n & (4 * sizeof(int8_t))) {
112 wasm_v128_store(y, vy); y += 4;
113 vy = wasm_i32x4_extend_high_i16x8(vx);
114 vy = wasm_f32x4_convert_i32x4(vy);
115 vy = wasm_f32x4_mul(vy, vscale);
116 }
117 if (n & (2 * sizeof(int8_t))) {
118 *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
119 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
120 y += 2;
121 }
122 if (n & (1 * sizeof(int8_t))) {
123 *y = wasm_f32x4_extract_lane(vy, 0);
124 }
125 }
126 }
127