xref: /aosp_15_r20/external/XNNPACK/src/math/cvt-f32-f16-neonfp16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright 2021 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 
10 #include <arm_neon.h>
11 
12 #include <xnnpack/math-stubs.h>
13 
14 
xnn_math_f32_f16_cvt__neonfp16(size_t n,const float * input,void * output)15 void xnn_math_f32_f16_cvt__neonfp16(
16     size_t n,
17     const float* input,
18     void* output)
19 {
20   assert(n % (4 * sizeof(uint16_t)) == 0);
21 
22   uint16_t* o = (uint16_t*) output;
23   for (; n != 0; n -= 4 * sizeof(uint16_t)) {
24     const float32x4_t vx = vld1q_f32(input); input += 4;
25     const uint16x4_t vy = vreinterpret_u16_f16(vcvt_f16_f32(vx));
26     vst1_u16(o, vy); o += 4;
27   }
28 }
29