xref: /aosp_15_r20/external/XNNPACK/src/f16-f32-vcvt/gen/vcvt-f16c-x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f16-f32-vcvt/f16c.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 <immintrin.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/vcvt.h>
16 
17 
xnn_f16_f32_vcvt_ukernel__f16c_x16(size_t n,const void * input,float * output,const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_f32_vcvt_ukernel__f16c_x16(
19     size_t n,
20     const void* input,
21     float* output,
22     const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24   assert(n != 0);
25   assert(n % sizeof(uint16_t) == 0);
26   assert(input != NULL);
27   assert(output != NULL);
28 
29   const uint16_t* i = (const uint16_t*) input;
30   for (; n >= 16 * sizeof(uint16_t); n -= 16 * sizeof(uint16_t)) {
31     const __m256 vacc0 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
32     const __m256 vacc1 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (i + 8)));
33     i += 16;
34 
35     _mm256_storeu_ps(output, vacc0);
36     _mm256_storeu_ps(output + 8, vacc1);
37     output += 16;
38   }
39   for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
40     const __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
41     i += 8;
42 
43     _mm256_storeu_ps(output, vacc);
44     output += 8;
45   }
46   if XNN_UNLIKELY(n != 0) {
47     assert(n >= 1 * sizeof(uint16_t));
48     assert(n <= 7 * sizeof(uint16_t));
49     const __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
50 
51     __m128 vacc_lo = _mm256_castps256_ps128(vacc);
52     if (n & (4 * sizeof(uint16_t))) {
53       _mm_storeu_ps(output, vacc_lo);
54       vacc_lo = _mm256_extractf128_ps(vacc, 1);
55       output += 4;
56     }
57     if (n & (2 * sizeof(uint16_t))) {
58       _mm_storel_pi((__m64*) output, vacc_lo);
59       vacc_lo = _mm_movehl_ps(vacc_lo, vacc_lo);
60       output += 2;
61     }
62     if (n & (1 * sizeof(uint16_t))) {
63       _mm_store_ss(output, vacc_lo);
64     }
65   }
66 }
67