1 // Auto-generated file. Do not edit!
2 // Template: src/f32-qs8-vcvt/neonv8.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 <arm_neon.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 #include <xnnpack/vcvt.h>
17
18
xnn_f32_qu8_vcvt_ukernel__neonv8_x16(size_t n,const float * x,uint8_t * y,const union xnn_f32_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_qu8_vcvt_ukernel__neonv8_x16(
20 size_t n,
21 const float* x,
22 uint8_t* y,
23 const union xnn_f32_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(float) == 0);
27 assert(x != NULL);
28 assert(y != NULL);
29
30 const float32x4_t vscale = vld1q_dup_f32(¶ms->neonv8.scale);
31 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->neonv8.output_zero_point);
32 const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->neonv8.output_min);
33 const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->neonv8.output_max);
34 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
35 float32x4_t vx0123 = vld1q_f32(x); x += 4;
36 float32x4_t vx4567 = vld1q_f32(x); x += 4;
37 float32x4_t vx89AB = vld1q_f32(x); x += 4;
38 float32x4_t vxCDEF = vld1q_f32(x); x += 4;
39
40 vx0123 = vmulq_f32(vx0123, vscale);
41 vx4567 = vmulq_f32(vx4567, vscale);
42 vx89AB = vmulq_f32(vx89AB, vscale);
43 vxCDEF = vmulq_f32(vxCDEF, vscale);
44
45 const int32x4_t vacc0123 = vcvtnq_s32_f32(vx0123);
46 const int32x4_t vacc4567 = vcvtnq_s32_f32(vx4567);
47 const int32x4_t vacc89AB = vcvtnq_s32_f32(vx89AB);
48 const int32x4_t vaccCDEF = vcvtnq_s32_f32(vxCDEF);
49
50 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
51 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
52
53 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
54 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
55
56 uint8x16_t vy0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc01234567), vqmovun_s16(vacc89ABCDEF));
57
58 vy0123456789ABCDEF = vmaxq_u8(vy0123456789ABCDEF, voutput_min);
59
60 vy0123456789ABCDEF = vminq_u8(vy0123456789ABCDEF, voutput_max);
61
62 vst1q_u8(y, vy0123456789ABCDEF); y += 16;
63 }
64 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
65 float32x4_t vx_lo = vld1q_f32(x); x += 4;
66 float32x4_t vx_hi = vld1q_f32(x); x += 4;
67
68 vx_lo = vmulq_f32(vx_lo, vscale);
69 vx_hi = vmulq_f32(vx_hi, vscale);
70
71 const int32x4_t vacc_lo = vcvtnq_s32_f32(vx_lo);
72 const int32x4_t vacc_hi = vcvtnq_s32_f32(vx_hi);
73
74 int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
75 vacc = vqaddq_s16(vacc, voutput_zero_point);
76
77 uint8x8_t vy = vqmovun_s16(vacc);
78 vy = vmax_u8(vy, vget_low_u8(voutput_min));
79 vy = vmin_u8(vy, vget_low_u8(voutput_max));
80 vst1_u8(y, vy); y += 8;
81 }
82 if XNN_UNLIKELY(n != 0) {
83 assert(n >= 1 * sizeof(float));
84 assert(n <= 7 * sizeof(float));
85 float32x4_t vx_lo = vld1q_f32(x);
86 const float* x_hi = (const float*) ((uintptr_t) x + (n & (4 * sizeof(float))));
87 float32x4_t vx_hi = vld1q_f32(x_hi);
88
89 vx_lo = vmulq_f32(vx_lo, vscale);
90 vx_hi = vmulq_f32(vx_hi, vscale);
91
92 const int32x4_t vacc_lo = vcvtnq_s32_f32(vx_lo);
93 const int32x4_t vacc_hi = vcvtnq_s32_f32(vx_hi);
94
95 int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
96 vacc = vqaddq_s16(vacc, voutput_zero_point);
97
98 uint8x8_t vy = vqmovun_s16(vacc);
99 vy = vmax_u8(vy, vget_low_u8(voutput_min));
100 vy = vmin_u8(vy, vget_low_u8(voutput_max));
101
102 if (n & (4 * sizeof(float))) {
103 vst1_lane_u32((void*) y, vreinterpret_u32_u8(vy), 0); y += 4;
104 vy = vext_u8(vy, vy, 4);
105 }
106 if (n & (2 * sizeof(float))) {
107 vst1_lane_u16((void*) y, vreinterpret_u16_u8(vy), 0); y += 2;
108 vy = vext_u8(vy, vy, 2);
109 }
110 if (n & (1 * sizeof(float))) {
111 vst1_lane_u8(y, vy, 0);
112 }
113 }
114 }
115