Debian Codegraph @

src/qs8-vcvt/gen/qs8-vcvt-neon-u32.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vcvt/neon.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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 <arm_neon.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/vcvt.h"
16
17
18 void xnn_qs8_vcvt_ukernel__neon_u32(
19 size_t batch,
20 const int8_t* input,
21 int8_t* output,
22 const struct xnn_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(int8_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const int16x8_t vinput_zero_point = vld1q_dup_s16(&params->scalar.input_zero_point);
30 const int16x8_t vmultiplier = vdupq_n_s16(-params->scalar.multiplier);
31 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->scalar.output_zero_point);
32 for (; batch >= 32 * sizeof(int8_t); batch -= 32 * sizeof(int8_t)) {
33 const int8x16_t vx0 = vld1q_s8(input); input += 16;
34 const int8x16_t vx1 = vld1q_s8(input); input += 16;
35
36 int16x8_t vacc0 = vsubw_s8(vinput_zero_point, vget_low_s8(vx0));
37 int16x8_t vacc1 = vsubw_s8(vinput_zero_point, vget_high_s8(vx0));
38 int16x8_t vacc2 = vsubw_s8(vinput_zero_point, vget_low_s8(vx1));
39 int16x8_t vacc3 = vsubw_s8(vinput_zero_point, vget_high_s8(vx1));
40
41 vacc0 = vshlq_n_s16(vacc0, 7);
42 vacc1 = vshlq_n_s16(vacc1, 7);
43 vacc2 = vshlq_n_s16(vacc2, 7);
44 vacc3 = vshlq_n_s16(vacc3, 7);
45
46 vacc0 = vqrdmulhq_s16(vacc0, vmultiplier);
47 vacc1 = vqrdmulhq_s16(vacc1, vmultiplier);
48 vacc2 = vqrdmulhq_s16(vacc2, vmultiplier);
49 vacc3 = vqrdmulhq_s16(vacc3, vmultiplier);
50
51 vacc0 = vqaddq_s16(vacc0, voutput_zero_point);
52 vacc1 = vqaddq_s16(vacc1, voutput_zero_point);
53 vacc2 = vqaddq_s16(vacc2, voutput_zero_point);
54 vacc3 = vqaddq_s16(vacc3, voutput_zero_point);
55
56 const int8x16_t vy0 = vcombine_s8(vqmovn_s16(vacc0), vqmovn_s16(vacc1));
57 const int8x16_t vy1 = vcombine_s8(vqmovn_s16(vacc2), vqmovn_s16(vacc3));
58
59 vst1q_s8(output, vy0); output += 16;
60 vst1q_s8(output, vy1); output += 16;
61 }
62 for (; batch >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) {
63 const int8x8_t vx = vld1_s8(input); input += 8;
64 int16x8_t vacc = vsubw_s8(vinput_zero_point, vx);
65 vacc = vshlq_n_s16(vacc, 7);
66 vacc = vqrdmulhq_s16(vacc, vmultiplier);
67 vacc = vqaddq_s16(vacc, voutput_zero_point);
68 const int8x8_t vy = vqmovn_s16(vacc);
69 vst1_s8(output, vy); output += 8;
70 }
71 if XNN_UNLIKELY(batch != 0) {
72 assert(batch >= 1 * sizeof(int8_t));
73 assert(batch <= 7 * sizeof(int8_t));
74
75 const int8x8_t vx = vld1_s8(input);
76 int16x8_t vacc = vsubw_s8(vinput_zero_point, vx);
77 vacc = vshlq_n_s16(vacc, 7);
78 vacc = vqrdmulhq_s16(vacc, vmultiplier);
79 vacc = vqaddq_s16(vacc, voutput_zero_point);
80 int8x8_t vy = vqmovn_s16(vacc);
81
82 if (batch & (4 * sizeof(int8_t))) {
83 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vy), 0); output += 4;
84 vy = vext_s8(vy, vy, 4);
85 }
86 if (batch & (2 * sizeof(int8_t))) {
87 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vy), 0); output += 2;
88 vy = vext_s8(vy, vy, 2);
89 }
90 if (batch & (1 * sizeof(int8_t))) {
91 vst1_lane_s8(output, vy, 0);
92 }
93 }
94 }