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
xnn_qu8_vcvt_ukernel__neon_x8(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vcvt_ukernel__neon_x8(
19 size_t n,
20 const uint8_t* x,
21 uint8_t* y,
22 const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(n != 0);
25 assert(n % sizeof(uint8_t) == 0);
26 assert(x != NULL);
27 assert(y != NULL);
28
29 const uint16x8_t vinput_zero_point = vld1q_dup_u16(¶ms->neon.input_zero_point);
30 const int16x8_t vmultiplier = vld1q_dup_s16(¶ms->neon.multiplier);
31 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->neon.output_zero_point);
32 for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
33 const uint8x8_t vx = vld1_u8(x); x += 8;
34 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
35 vacc = vshlq_n_s16(vacc, 7);
36 vacc = vqrdmulhq_s16(vacc, vmultiplier);
37 vacc = vqaddq_s16(vacc, voutput_zero_point);
38 const uint8x8_t vy = vqmovun_s16(vacc);
39 vst1_u8(y, vy); y += 8;
40 }
41 if XNN_UNLIKELY(n != 0) {
42 assert(n >= 1 * sizeof(uint8_t));
43 assert(n <= 7 * sizeof(uint8_t));
44
45 const uint8x8_t vx = vld1_u8(x);
46 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
47 vacc = vshlq_n_s16(vacc, 7);
48 vacc = vqrdmulhq_s16(vacc, vmultiplier);
49 vacc = vqaddq_s16(vacc, voutput_zero_point);
50 uint8x8_t vy = vqmovun_s16(vacc);
51
52 if (n & (4 * sizeof(uint8_t))) {
53 vst1_lane_u32((void*) y, vreinterpret_u32_u8(vy), 0); y += 4;
54 vy = vext_u8(vy, vy, 4);
55 }
56 if (n & (2 * sizeof(uint8_t))) {
57 vst1_lane_u16((void*) y, vreinterpret_u16_u8(vy), 0); y += 2;
58 vy = vext_u8(vy, vy, 2);
59 }
60 if (n & (1 * sizeof(uint8_t))) {
61 vst1_lane_u8(y, vy, 0);
62 }
63 }
64 }
65