1 // Auto-generated file. Do not edit!
2 // Template: src/f32-qs8-vcvt/neon.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__neon_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__neon_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->neon.scale);
31 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->neon.magic_bias);
32 const int32x4_t vmagic_bias_less_zero_point = vld1q_dup_s32(¶ms->neon.magic_bias_less_zero_point);
33 const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->neon.output_min);
34 const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->neon.output_max);
35 for (; n >= 24 * sizeof(float); n -= 24 * sizeof(float)) {
36 float32x4_t vx0123 = vld1q_f32(x); x += 4;
37 float32x4_t vx4567 = vld1q_f32(x); x += 4;
38 float32x4_t vx89AB = vld1q_f32(x); x += 4;
39 float32x4_t vxCDEF = vld1q_f32(x); x += 4;
40 float32x4_t vxGHIJ = vld1q_f32(x); x += 4;
41 float32x4_t vxKLMN = vld1q_f32(x); x += 4;
42
43 vx0123 = vmulq_f32(vx0123, vscale);
44 vx4567 = vmulq_f32(vx4567, vscale);
45 vx89AB = vmulq_f32(vx89AB, vscale);
46 vxCDEF = vmulq_f32(vxCDEF, vscale);
47 vxGHIJ = vmulq_f32(vxGHIJ, vscale);
48 vxKLMN = vmulq_f32(vxKLMN, vscale);
49
50 vx0123 = vaddq_f32(vx0123, vmagic_bias);
51 vx4567 = vaddq_f32(vx4567, vmagic_bias);
52 vx89AB = vaddq_f32(vx89AB, vmagic_bias);
53 vxCDEF = vaddq_f32(vxCDEF, vmagic_bias);
54 vxGHIJ = vaddq_f32(vxGHIJ, vmagic_bias);
55 vxKLMN = vaddq_f32(vxKLMN, vmagic_bias);
56
57 const int32x4_t vacc0123 = vqsubq_s32(vreinterpretq_s32_f32(vx0123), vmagic_bias_less_zero_point);
58 const int32x4_t vacc4567 = vqsubq_s32(vreinterpretq_s32_f32(vx4567), vmagic_bias_less_zero_point);
59 const int32x4_t vacc89AB = vqsubq_s32(vreinterpretq_s32_f32(vx89AB), vmagic_bias_less_zero_point);
60 const int32x4_t vaccCDEF = vqsubq_s32(vreinterpretq_s32_f32(vxCDEF), vmagic_bias_less_zero_point);
61 const int32x4_t vaccGHIJ = vqsubq_s32(vreinterpretq_s32_f32(vxGHIJ), vmagic_bias_less_zero_point);
62 const int32x4_t vaccKLMN = vqsubq_s32(vreinterpretq_s32_f32(vxKLMN), vmagic_bias_less_zero_point);
63
64 const int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
65 const int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
66 const int16x8_t vaccGHIJKLMN = vcombine_s16(vqmovn_s32(vaccGHIJ), vqmovn_s32(vaccKLMN));
67
68 uint8x16_t vy0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc01234567), vqmovun_s16(vacc89ABCDEF));
69 uint8x8_t vyGHIJKLMN = vqmovun_s16(vaccGHIJKLMN);
70
71 vy0123456789ABCDEF = vmaxq_u8(vy0123456789ABCDEF, voutput_min);
72 vyGHIJKLMN = vmax_u8(vyGHIJKLMN, vget_low_u8(voutput_min));
73
74 vy0123456789ABCDEF = vminq_u8(vy0123456789ABCDEF, voutput_max);
75 vyGHIJKLMN = vmin_u8(vyGHIJKLMN, vget_low_u8(voutput_max));
76
77 vst1q_u8(y, vy0123456789ABCDEF); y += 16;
78 vst1_u8(y, vyGHIJKLMN); y += 8;
79 }
80 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
81 float32x4_t vx_lo = vld1q_f32(x); x += 4;
82 float32x4_t vx_hi = vld1q_f32(x); x += 4;
83
84 vx_lo = vmulq_f32(vx_lo, vscale);
85 vx_hi = vmulq_f32(vx_hi, vscale);
86
87 vx_lo = vaddq_f32(vx_lo, vmagic_bias);
88 vx_hi = vaddq_f32(vx_hi, vmagic_bias);
89
90 const int32x4_t vacc_lo = vqsubq_s32(vreinterpretq_s32_f32(vx_lo), vmagic_bias_less_zero_point);
91 const int32x4_t vacc_hi = vqsubq_s32(vreinterpretq_s32_f32(vx_hi), vmagic_bias_less_zero_point);
92
93 const int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
94
95 uint8x8_t vy = vqmovun_s16(vacc);
96 vy = vmax_u8(vy, vget_low_u8(voutput_min));
97 vy = vmin_u8(vy, vget_low_u8(voutput_max));
98 vst1_u8(y, vy); y += 8;
99 }
100 if XNN_UNLIKELY(n != 0) {
101 assert(n >= 1 * sizeof(float));
102 assert(n <= 7 * sizeof(float));
103 float32x4_t vx_lo = vld1q_f32(x);
104 const float* x_hi = (const float*) ((uintptr_t) x + (n & (4 * sizeof(float))));
105 float32x4_t vx_hi = vld1q_f32(x_hi);
106
107 vx_lo = vmulq_f32(vx_lo, vscale);
108 vx_hi = vmulq_f32(vx_hi, vscale);
109
110 vx_lo = vaddq_f32(vx_lo, vmagic_bias);
111 vx_hi = vaddq_f32(vx_hi, vmagic_bias);
112
113 const int32x4_t vacc_lo = vqsubq_s32(vreinterpretq_s32_f32(vx_lo), vmagic_bias_less_zero_point);
114 const int32x4_t vacc_hi = vqsubq_s32(vreinterpretq_s32_f32(vx_hi), vmagic_bias_less_zero_point);
115
116 const int16x8_t vacc = vcombine_s16(vqmovn_s32(vacc_lo), vqmovn_s32(vacc_hi));
117
118 uint8x8_t vy = vqmovun_s16(vacc);
119 vy = vmax_u8(vy, vget_low_u8(voutput_min));
120 vy = vmin_u8(vy, vget_low_u8(voutput_max));
121
122 if (n & (4 * sizeof(float))) {
123 vst1_lane_u32((void*) y, vreinterpret_u32_u8(vy), 0); y += 4;
124 vy = vext_u8(vy, vy, 4);
125 }
126 if (n & (2 * sizeof(float))) {
127 vst1_lane_u16((void*) y, vreinterpret_u16_u8(vy), 0); y += 2;
128 vy = vext_u8(vy, vy, 2);
129 }
130 if (n & (1 * sizeof(float))) {
131 vst1_lane_u8(y, vy, 0);
132 }
133 }
134 }
135