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_qu8_f32_vcvt_ukernel__wasmsimd_x8(size_t n,const uint8_t * x,float * y,const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qu8_f32_vcvt_ukernel__wasmsimd_x8(
20 size_t n,
21 const uint8_t* x,
22 float* y,
23 const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(uint8_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 >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
33 v128_t vx = wasm_u16x8_load8x8(x);
34 vx = wasm_i16x8_add(vx, vminus_zero_point);
35 x += 8;
36
37 v128_t vy_lo = wasm_i32x4_extend_low_i16x8(vx);
38 v128_t vy_hi = wasm_i32x4_extend_high_i16x8(vx);
39
40 vy_lo = wasm_f32x4_convert_i32x4(vy_lo);
41 vy_hi = wasm_f32x4_convert_i32x4(vy_hi);
42
43 vy_lo = wasm_f32x4_mul(vy_lo, vscale);
44 vy_hi = wasm_f32x4_mul(vy_hi, vscale);
45
46 wasm_v128_store(y, vy_lo);
47 wasm_v128_store(y + 4, vy_hi);
48 y += 8;
49 }
50 if XNN_UNLIKELY(n != 0) {
51 assert(n >= 1 * sizeof(uint8_t));
52 assert(n <= 7 * sizeof(uint8_t));
53
54 v128_t vx = wasm_u16x8_load8x8(x);
55 vx = wasm_i16x8_add(vx, vminus_zero_point);
56 x += 8;
57
58 v128_t vy = wasm_i32x4_extend_low_i16x8(vx);
59 vy = wasm_f32x4_convert_i32x4(vy);
60 vy = wasm_f32x4_mul(vy, vscale);
61
62 if (n & (4 * sizeof(uint8_t))) {
63 wasm_v128_store(y, vy); y += 4;
64 vy = wasm_i32x4_extend_high_i16x8(vx);
65 vy = wasm_f32x4_convert_i32x4(vy);
66 vy = wasm_f32x4_mul(vy, vscale);
67 }
68 if (n & (2 * sizeof(uint8_t))) {
69 *((double*) y) = wasm_f64x2_extract_lane(vy, 0);
70 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
71 y += 2;
72 }
73 if (n & (1 * sizeof(uint8_t))) {
74 *y = wasm_f32x4_extract_lane(vy, 0);
75 }
76 }
77 }
78