Debian Codegraph @

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