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_x24(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_x24(
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 >= 24 * sizeof(float); n -= 24 * 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 float32x4_t vxGHIJ = vld1q_f32(x); x += 4;
40 float32x4_t vxKLMN = vld1q_f32(x); x += 4;
41
42 vx0123 = vmulq_f32(vx0123, vscale);
43 vx4567 = vmulq_f32(vx4567, vscale);
44 vx89AB = vmulq_f32(vx89AB, vscale);
45 vxCDEF = vmulq_f32(vxCDEF, vscale);
46 vxGHIJ = vmulq_f32(vxGHIJ, vscale);
47 vxKLMN = vmulq_f32(vxKLMN, vscale);
48
49 const int32x4_t vacc0123 = vcvtnq_s32_f32(vx0123);
50 const int32x4_t vacc4567 = vcvtnq_s32_f32(vx4567);
51 const int32x4_t vacc89AB = vcvtnq_s32_f32(vx89AB);
52 const int32x4_t vaccCDEF = vcvtnq_s32_f32(vxCDEF);
53 const int32x4_t vaccGHIJ = vcvtnq_s32_f32(vxGHIJ);
54 const int32x4_t vaccKLMN = vcvtnq_s32_f32(vxKLMN);
55
56 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
57 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
58 int16x8_t vaccGHIJKLMN = vcombine_s16(vqmovn_s32(vaccGHIJ), vqmovn_s32(vaccKLMN));
59
60 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
61 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
62 vaccGHIJKLMN = vqaddq_s16(vaccGHIJKLMN, voutput_zero_point);
63
64 uint8x16_t vy0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc01234567), vqmovun_s16(vacc89ABCDEF));
65 uint8x8_t vyGHIJKLMN = vqmovun_s16(vaccGHIJKLMN);
66
67 vy0123456789ABCDEF = vmaxq_u8(vy0123456789ABCDEF, voutput_min);
68 vyGHIJKLMN = vmax_u8(vyGHIJKLMN, vget_low_u8(voutput_min));
69
70 vy0123456789ABCDEF = vminq_u8(vy0123456789ABCDEF, voutput_max);
71 vyGHIJKLMN = vmin_u8(vyGHIJKLMN, vget_low_u8(voutput_max));
72
73 vst1q_u8(y, vy0123456789ABCDEF); y += 16;
74 vst1_u8(y, vyGHIJKLMN); y += 8;
75 }
76 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
77 float32x4_t vx_lo = vld1q_f32(x); x += 4;
78 float32x4_t vx_hi = vld1q_f32(x); x += 4;
79
80 vx_lo = vmulq_f32(vx_lo, vscale);
81 vx_hi = vmulq_f32(vx_hi, vscale);
82
83 const int32x4_t vacc_lo = vcvtnq_s32_f32(vx_lo);
84 const int32x4_t vacc_hi = vcvtnq_s32_f32(vx_hi);
85
86 int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
87 vacc = vqaddq_s16(vacc, voutput_zero_point);
88
89 uint8x8_t vy = vqmovun_s16(vacc);
90 vy = vmax_u8(vy, vget_low_u8(voutput_min));
91 vy = vmin_u8(vy, vget_low_u8(voutput_max));
92 vst1_u8(y, vy); y += 8;
93 }
94 if XNN_UNLIKELY(n != 0) {
95 assert(n >= 1 * sizeof(float));
96 assert(n <= 7 * sizeof(float));
97 float32x4_t vx_lo = vld1q_f32(x);
98 const float* x_hi = (const float*) ((uintptr_t) x + (n & (4 * sizeof(float))));
99 float32x4_t vx_hi = vld1q_f32(x_hi);
100
101 vx_lo = vmulq_f32(vx_lo, vscale);
102 vx_hi = vmulq_f32(vx_hi, vscale);
103
104 const int32x4_t vacc_lo = vcvtnq_s32_f32(vx_lo);
105 const int32x4_t vacc_hi = vcvtnq_s32_f32(vx_hi);
106
107 int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
108 vacc = vqaddq_s16(vacc, voutput_zero_point);
109
110 uint8x8_t vy = vqmovun_s16(vacc);
111 vy = vmax_u8(vy, vget_low_u8(voutput_min));
112 vy = vmin_u8(vy, vget_low_u8(voutput_max));
113
114 if (n & (4 * sizeof(float))) {
115 vst1_lane_u32((void*) y, vreinterpret_u32_u8(vy), 0); y += 4;
116 vy = vext_u8(vy, vy, 4);
117 }
118 if (n & (2 * sizeof(float))) {
119 vst1_lane_u16((void*) y, vreinterpret_u16_u8(vy), 0); y += 2;
120 vy = vext_u8(vy, vy, 2);
121 }
122 if (n & (1 * sizeof(float))) {
123 vst1_lane_u8(y, vy, 0);
124 }
125 }
126 }
127