xref: /aosp_15_r20/external/XNNPACK/src/math/cvt-f32-f16-f16c.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 <immintrin.h>
11 
12 #include <xnnpack/math-stubs.h>
13 
14 
xnn_math_f32_f16_cvt__f16c(size_t n,const float * input,void * output)15 void xnn_math_f32_f16_cvt__f16c(
16     size_t n,
17     const float* input,
18     void* output)
19 {
20   assert(n % (8 * sizeof(uint16_t)) == 0);
21 
22   uint16_t* o = (uint16_t*) output;
23   for (; n != 0; n -= 8 * sizeof(uint16_t)) {
24     const __m256 vx = _mm256_loadu_ps(input);
25     input += 8;
26 
27     const __m128i vy = _mm256_cvtps_ph(vx, _MM_FROUND_NO_EXC);
28 
29     _mm_storeu_si128((__m128i*) o, vy);
30     o += 8;
31   }
32 }
33