xref: /aosp_15_r20/external/XNNPACK/src/f32-f16-vcvt/gen/vcvt-neonfp16-x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-f16-vcvt/neonfp16.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/vcvt.h>
16 
17 
xnn_f32_f16_vcvt_ukernel__neonfp16_x16(size_t n,const float * input,void * output,const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_f16_vcvt_ukernel__neonfp16_x16(
19     size_t n,
20     const float* input,
21     void* output,
22     const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24   assert(n != 0);
25   assert(n % sizeof(float) == 0);
26   assert(input != NULL);
27   assert(output != NULL);
28 
29   uint16_t* o = (uint16_t*) output;
30   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
31     const float32x4_t vf0 = vld1q_f32(input); input += 4;
32     const float32x4_t vf1 = vld1q_f32(input); input += 4;
33     const float32x4_t vf2 = vld1q_f32(input); input += 4;
34     const float32x4_t vf3 = vld1q_f32(input); input += 4;
35 
36     const uint16x8_t vh0 = vreinterpretq_u16_f16(vcombine_f16(vcvt_f16_f32(vf0), vcvt_f16_f32(vf1)));
37     const uint16x8_t vh1 = vreinterpretq_u16_f16(vcombine_f16(vcvt_f16_f32(vf2), vcvt_f16_f32(vf3)));
38 
39     vst1q_u16(o, vh0); o += 8;
40     vst1q_u16(o, vh1); o += 8;
41   }
42   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
43     const float32x4_t vf = vld1q_f32(input); input += 4;
44 
45     const uint16x4_t vh = vreinterpret_u16_f16(vcvt_f16_f32(vf));
46 
47     vst1_u16(o, vh); o += 4;
48   }
49   if XNN_UNLIKELY(n != 0) {
50     assert(n % sizeof(float) == 0);
51     assert(n >= 1 * sizeof(float));
52     assert(n <= 3 * sizeof(float));
53     const float32x4_t vf = vld1q_f32(input);
54 
55     uint16x4_t vh = vreinterpret_u16_f16(vcvt_f16_f32(vf));
56 
57     if (n & (2 * sizeof(float))) {
58       vst1_lane_u32((void*) o, vreinterpret_u32_u16(vh), 0); o += 2;
59       vh = vext_u16(vh, vh, 2);
60     }
61     if (n & (1 * sizeof(float))) {
62       vst1_lane_u16(o, vh, 0);
63     }
64   }
65 }
66