Debian Codegraph @

src/qu8-f32-vcvt/gen/qu8-f32-vcvt-wasmsimd-u16.c

raw
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
19 void xnn_qu8_f32_vcvt_ukernel__wasmsimd_u16(
20 size_t batch,
21 const uint8_t* input,
22 float* output,
23 const struct xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(uint8_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const v128_t vzero_point = wasm_v128_load16_splat(&params->scalar.zero_point);
31 const v128_t vscale = wasm_v128_load32_splat(&params->scalar.scale);
32 XNN_FORCE_REALIZATION(vzero_point);
33 XNN_FORCE_REALIZATION(vscale);
34 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
35 v128_t vx01234567 = wasm_u16x8_load8x8(input);
36 v128_t vx89ABCDEF = wasm_u16x8_load8x8(input + 8);
37 input += 16;
38
39 vx01234567 = wasm_i16x8_sub(vx01234567, vzero_point);
40 vx89ABCDEF = wasm_i16x8_sub(vx89ABCDEF, vzero_point);
41
42 v128_t vy0123 = wasm_i32x4_extend_low_i16x8(vx01234567);
43 v128_t vy4567 = wasm_i32x4_extend_high_i16x8(vx01234567);
44 v128_t vy89AB = wasm_i32x4_extend_low_i16x8(vx89ABCDEF);
45 v128_t vyCDEF = wasm_i32x4_extend_high_i16x8(vx89ABCDEF);
46
47 vy0123 = wasm_f32x4_convert_i32x4(vy0123);
48 vy4567 = wasm_f32x4_convert_i32x4(vy4567);
49 vy89AB = wasm_f32x4_convert_i32x4(vy89AB);
50 vyCDEF = wasm_f32x4_convert_i32x4(vyCDEF);
51
52 vy0123 = wasm_f32x4_mul(vy0123, vscale);
53 vy4567 = wasm_f32x4_mul(vy4567, vscale);
54 vy89AB = wasm_f32x4_mul(vy89AB, vscale);
55 vyCDEF = wasm_f32x4_mul(vyCDEF, vscale);
56
57 wasm_v128_store(output, vy0123);
58 wasm_v128_store(output + 4, vy4567);
59 wasm_v128_store(output + 8, vy89AB);
60 wasm_v128_store(output + 12, vyCDEF);
61 output += 16;
62 }
63 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
64 v128_t vx = wasm_u16x8_load8x8(input);
65 vx = wasm_i16x8_sub(vx, vzero_point);
66 input += 8;
67
68 v128_t vy_lo = wasm_i32x4_extend_low_i16x8(vx);
69 v128_t vy_hi = wasm_i32x4_extend_high_i16x8(vx);
70
71 vy_lo = wasm_f32x4_convert_i32x4(vy_lo);
72 vy_hi = wasm_f32x4_convert_i32x4(vy_hi);
73
74 vy_lo = wasm_f32x4_mul(vy_lo, vscale);
75 vy_hi = wasm_f32x4_mul(vy_hi, vscale);
76
77 wasm_v128_store(output, vy_lo);
78 wasm_v128_store(output + 4, vy_hi);
79 output += 8;
80 }
81 if XNN_UNLIKELY(batch != 0) {
82 assert(batch >= 1 * sizeof(uint8_t));
83 assert(batch <= 7 * sizeof(uint8_t));
84
85 v128_t vx = wasm_u16x8_load8x8(input);
86 vx = wasm_i16x8_sub(vx, vzero_point);
87 input += 8;
88
89 v128_t vy = wasm_i32x4_extend_low_i16x8(vx);
90 vy = wasm_f32x4_convert_i32x4(vy);
91 vy = wasm_f32x4_mul(vy, vscale);
92
93 if (batch & (4 * sizeof(uint8_t))) {
94 wasm_v128_store(output, vy); output += 4;
95 vy = wasm_i32x4_extend_high_i16x8(vx);
96 vy = wasm_f32x4_convert_i32x4(vy);
97 vy = wasm_f32x4_mul(vy, vscale);
98 }
99 if (batch & (2 * sizeof(uint8_t))) {
100 wasm_v128_store64_lane(output, vy, 0);
101 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
102 output += 2;
103 }
104 if (batch & (1 * sizeof(uint8_t))) {
105 wasm_v128_store32_lane(output, vy, 0);
106 }
107 }
108 }