Debian Codegraph @

src/qu8-vcvt/gen/qu8-vcvt-neon-u16.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_qu8_vcvt_ukernel__neon_u16(
19 size_t batch,
20 const uint8_t* input,
21 uint8_t* output,
22 const struct xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(uint8_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const uint16x8_t vinput_zero_point = vld1q_dup_u16(&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 >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
33 const uint8x16_t vx0 = vld1q_u8(input); input += 16;
34
35 int16x8_t vacc0 = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vget_low_u8(vx0)));
36 int16x8_t vacc1 = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vget_high_u8(vx0)));
37
38 vacc0 = vshlq_n_s16(vacc0, 7);
39 vacc1 = vshlq_n_s16(vacc1, 7);
40
41 vacc0 = vqrdmulhq_s16(vacc0, vmultiplier);
42 vacc1 = vqrdmulhq_s16(vacc1, vmultiplier);
43
44 vacc0 = vqaddq_s16(vacc0, voutput_zero_point);
45 vacc1 = vqaddq_s16(vacc1, voutput_zero_point);
46
47 const uint8x16_t vy0 = vcombine_u8(vqmovun_s16(vacc0), vqmovun_s16(vacc1));
48
49 vst1q_u8(output, vy0); output += 16;
50 }
51 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
52 const uint8x8_t vx = vld1_u8(input); input += 8;
53 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
54 vacc = vshlq_n_s16(vacc, 7);
55 vacc = vqrdmulhq_s16(vacc, vmultiplier);
56 vacc = vqaddq_s16(vacc, voutput_zero_point);
57 const uint8x8_t vy = vqmovun_s16(vacc);
58 vst1_u8(output, vy); output += 8;
59 }
60 if XNN_UNLIKELY(batch != 0) {
61 assert(batch >= 1 * sizeof(uint8_t));
62 assert(batch <= 7 * sizeof(uint8_t));
63
64 const uint8x8_t vx = vld1_u8(input);
65 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
66 vacc = vshlq_n_s16(vacc, 7);
67 vacc = vqrdmulhq_s16(vacc, vmultiplier);
68 vacc = vqaddq_s16(vacc, voutput_zero_point);
69 uint8x8_t vy = vqmovun_s16(vacc);
70
71 if (batch & (4 * sizeof(uint8_t))) {
72 vst1_lane_u32((void*) output, vreinterpret_u32_u8(vy), 0); output += 4;
73 vy = vext_u8(vy, vy, 4);
74 }
75 if (batch & (2 * sizeof(uint8_t))) {
76 vst1_lane_u16((void*) output, vreinterpret_u16_u8(vy), 0); output += 2;
77 vy = vext_u8(vy, vy, 2);
78 }
79 if (batch & (1 * sizeof(uint8_t))) {
80 vst1_lane_u8(output, vy, 0);
81 }
82 }
83 }