1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vlrelu/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/vlrelu.h>
16
17
xnn_qu8_vlrelu_ukernel__neon_x8(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vlrelu_ukernel__neon_x8(
19 size_t n,
20 const uint8_t* x,
21 uint8_t* y,
22 const union xnn_qu8_lrelu_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 vpositive_multiplier = vld1q_dup_s16(¶ms->neon.positive_multiplier);
31 const int16x8_t vnegative_multiplier = vld1q_dup_s16(¶ms->neon.negative_multiplier);
32 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->neon.output_zero_point);
33 for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
34 const uint8x8_t vx = vld1_u8(x); x += 8;
35 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
36 const uint16x8_t vmask = vcltq_s16(vacc, vmovq_n_s16(0));
37 vacc = vshlq_n_s16(vacc, 7);
38 const int16x8_t vmultiplier = vbslq_s16(vmask, vpositive_multiplier, vnegative_multiplier);
39 vacc = vqrdmulhq_s16(vacc, vmultiplier);
40 vacc = vqaddq_s16(vacc, voutput_zero_point);
41 const uint8x8_t vy = vqmovun_s16(vacc);
42 vst1_u8(y, vy); y += 8;
43 }
44 if XNN_UNLIKELY(n != 0) {
45 assert(n >= 1 * sizeof(uint8_t));
46 assert(n <= 7 * sizeof(uint8_t));
47
48 const uint8x8_t vx = vld1_u8(x);
49 int16x8_t vacc = vreinterpretq_s16_u16(vsubw_u8(vinput_zero_point, vx));
50 const uint16x8_t vmask = vcltq_s16(vacc, vmovq_n_s16(0));
51 vacc = vshlq_n_s16(vacc, 7);
52 const int16x8_t vmultiplier = vbslq_s16(vmask, vpositive_multiplier, vnegative_multiplier);
53 vacc = vqrdmulhq_s16(vacc, vmultiplier);
54 vacc = vqaddq_s16(vacc, voutput_zero_point);
55 uint8x8_t vy = vqmovun_s16(vacc);
56
57 if (n & (4 * sizeof(uint8_t))) {
58 vst1_lane_u32((void*) y, vreinterpret_u32_u8(vy), 0); y += 4;
59 vy = vext_u8(vy, vy, 4);
60 }
61 if (n & (2 * sizeof(uint8_t))) {
62 vst1_lane_u16((void*) y, vreinterpret_u16_u8(vy), 0); y += 2;
63 vy = vext_u8(vy, vy, 2);
64 }
65 if (n & (1 * sizeof(uint8_t))) {
66 vst1_lane_u8(y, vy, 0);
67 }
68 }
69 }
70