xref: /aosp_15_r20/external/XNNPACK/src/f16-vrnd/gen/vrndz-f16c-x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f16-vrnd/f16c.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2022 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/intrinsics-polyfill.h>
16 #include <xnnpack/math.h>
17 #include <xnnpack/vunary.h>
18 
19 
xnn_f16_vrndz_ukernel__f16c_x8(size_t n,const void * input,void * output,const union xnn_f16_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f16_vrndz_ukernel__f16c_x8(
21     size_t n,
22     const void* input,
23     void* output,
24     const union xnn_f16_rnd_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(n != 0);
27   assert(n % sizeof(uint16_t) == 0);
28 
29   const uint16_t* i = (const uint16_t*) input;
30   uint16_t* o = (uint16_t*) output;
31   for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
32     __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
33     i += 8;
34 
35     vacc = _mm256_round_ps(vacc, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC);
36 
37     _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_NO_EXC));
38     o += 8;
39   }
40   if XNN_UNLIKELY(n != 0) {
41     assert(n >= 1 * sizeof(uint16_t));
42     assert(n <= 7 * sizeof(uint16_t));
43     __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
44     vacc = _mm256_round_ps(vacc, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC);
45     __m128i vh = _mm256_cvtps_ph(vacc, _MM_FROUND_NO_EXC);
46     if (n & (4 * sizeof(uint16_t))) {
47       _mm_storel_epi64((__m128i*) o, vh);
48       vh = _mm_unpackhi_epi64(vh, vh);
49       o += 4;
50     }
51     if (n & (2 * sizeof(uint16_t))) {
52       _mm_storeu_si32(o, vh);
53       vh = _mm_srli_epi64(vh, 32);
54       o += 2;
55     }
56     if (n & (1 * sizeof(uint16_t))) {
57       *o = (uint16_t) _mm_extract_epi16(vh, 0);
58     }
59   }
60 }
61