Debian Codegraph @

src/qu8-f32-vcvt/gen/qu8-f32-vcvt-wasmsimd-u32.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_u32(
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 >= 32 * sizeof(uint8_t); batch -= 32 * sizeof(uint8_t)) {
35 v128_t vx01234567 = wasm_u16x8_load8x8(input);
36 v128_t vx89ABCDEF = wasm_u16x8_load8x8(input + 8);
37 v128_t vxGHIJKLMN = wasm_u16x8_load8x8(input + 16);
38 v128_t vxOPQRSTUV = wasm_u16x8_load8x8(input + 24);
39 input += 32;
40
41 vx01234567 = wasm_i16x8_sub(vx01234567, vzero_point);
42 vx89ABCDEF = wasm_i16x8_sub(vx89ABCDEF, vzero_point);
43 vxGHIJKLMN = wasm_i16x8_sub(vxGHIJKLMN, vzero_point);
44 vxOPQRSTUV = wasm_i16x8_sub(vxOPQRSTUV, vzero_point);
45
46 v128_t vy0123 = wasm_i32x4_extend_low_i16x8(vx01234567);
47 v128_t vy4567 = wasm_i32x4_extend_high_i16x8(vx01234567);
48 v128_t vy89AB = wasm_i32x4_extend_low_i16x8(vx89ABCDEF);
49 v128_t vyCDEF = wasm_i32x4_extend_high_i16x8(vx89ABCDEF);
50 v128_t vyGHIJ = wasm_i32x4_extend_low_i16x8(vxGHIJKLMN);
51 v128_t vyKLMN = wasm_i32x4_extend_high_i16x8(vxGHIJKLMN);
52 v128_t vyOPQR = wasm_i32x4_extend_low_i16x8(vxOPQRSTUV);
53 v128_t vySTUV = wasm_i32x4_extend_high_i16x8(vxOPQRSTUV);
54
55 vy0123 = wasm_f32x4_convert_i32x4(vy0123);
56 vy4567 = wasm_f32x4_convert_i32x4(vy4567);
57 vy89AB = wasm_f32x4_convert_i32x4(vy89AB);
58 vyCDEF = wasm_f32x4_convert_i32x4(vyCDEF);
59 vyGHIJ = wasm_f32x4_convert_i32x4(vyGHIJ);
60 vyKLMN = wasm_f32x4_convert_i32x4(vyKLMN);
61 vyOPQR = wasm_f32x4_convert_i32x4(vyOPQR);
62 vySTUV = wasm_f32x4_convert_i32x4(vySTUV);
63
64 vy0123 = wasm_f32x4_mul(vy0123, vscale);
65 vy4567 = wasm_f32x4_mul(vy4567, vscale);
66 vy89AB = wasm_f32x4_mul(vy89AB, vscale);
67 vyCDEF = wasm_f32x4_mul(vyCDEF, vscale);
68 vyGHIJ = wasm_f32x4_mul(vyGHIJ, vscale);
69 vyKLMN = wasm_f32x4_mul(vyKLMN, vscale);
70 vyOPQR = wasm_f32x4_mul(vyOPQR, vscale);
71 vySTUV = wasm_f32x4_mul(vySTUV, vscale);
72
73 wasm_v128_store(output, vy0123);
74 wasm_v128_store(output + 4, vy4567);
75 wasm_v128_store(output + 8, vy89AB);
76 wasm_v128_store(output + 12, vyCDEF);
77 wasm_v128_store(output + 16, vyGHIJ);
78 wasm_v128_store(output + 20, vyKLMN);
79 wasm_v128_store(output + 24, vyOPQR);
80 wasm_v128_store(output + 28, vySTUV);
81 output += 32;
82 }
83 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
84 v128_t vx = wasm_u16x8_load8x8(input);
85 vx = wasm_i16x8_sub(vx, vzero_point);
86 input += 8;
87
88 v128_t vy_lo = wasm_i32x4_extend_low_i16x8(vx);
89 v128_t vy_hi = wasm_i32x4_extend_high_i16x8(vx);
90
91 vy_lo = wasm_f32x4_convert_i32x4(vy_lo);
92 vy_hi = wasm_f32x4_convert_i32x4(vy_hi);
93
94 vy_lo = wasm_f32x4_mul(vy_lo, vscale);
95 vy_hi = wasm_f32x4_mul(vy_hi, vscale);
96
97 wasm_v128_store(output, vy_lo);
98 wasm_v128_store(output + 4, vy_hi);
99 output += 8;
100 }
101 if XNN_UNLIKELY(batch != 0) {
102 assert(batch >= 1 * sizeof(uint8_t));
103 assert(batch <= 7 * sizeof(uint8_t));
104
105 v128_t vx = wasm_u16x8_load8x8(input);
106 vx = wasm_i16x8_sub(vx, vzero_point);
107 input += 8;
108
109 v128_t vy = wasm_i32x4_extend_low_i16x8(vx);
110 vy = wasm_f32x4_convert_i32x4(vy);
111 vy = wasm_f32x4_mul(vy, vscale);
112
113 if (batch & (4 * sizeof(uint8_t))) {
114 wasm_v128_store(output, vy); output += 4;
115 vy = wasm_i32x4_extend_high_i16x8(vx);
116 vy = wasm_f32x4_convert_i32x4(vy);
117 vy = wasm_f32x4_mul(vy, vscale);
118 }
119 if (batch & (2 * sizeof(uint8_t))) {
120 wasm_v128_store64_lane(output, vy, 0);
121 vy = wasm_v64x2_shuffle(vy, vy, 1, 1);
122 output += 2;
123 }
124 if (batch & (1 * sizeof(uint8_t))) {
125 wasm_v128_store32_lane(output, vy, 0);
126 }
127 }
128 }