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_vrndu_ukernel__f16c_x16(size_t n,const void * input,void * output,const union xnn_f16_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f16_vrndu_ukernel__f16c_x16(
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 >= 16 * sizeof(uint16_t); n -= 16 * sizeof(uint16_t)) {
32 __m256 vacc0 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
33 __m256 vacc1 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (i + 8)));
34 i += 16;
35
36 vacc0 = _mm256_round_ps(vacc0, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC);
37 vacc1 = _mm256_round_ps(vacc1, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC);
38
39 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc0, _MM_FROUND_NO_EXC));
40 _mm_storeu_si128((__m128i*) (o + 8), _mm256_cvtps_ph(vacc1, _MM_FROUND_NO_EXC));
41 o += 16;
42 }
43 for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
44 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
45 i += 8;
46
47 vacc = _mm256_round_ps(vacc, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC);
48
49 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_NO_EXC));
50 o += 8;
51 }
52 if XNN_UNLIKELY(n != 0) {
53 assert(n >= 1 * sizeof(uint16_t));
54 assert(n <= 7 * sizeof(uint16_t));
55 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
56 vacc = _mm256_round_ps(vacc, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC);
57 __m128i vh = _mm256_cvtps_ph(vacc, _MM_FROUND_NO_EXC);
58 if (n & (4 * sizeof(uint16_t))) {
59 _mm_storel_epi64((__m128i*) o, vh);
60 vh = _mm_unpackhi_epi64(vh, vh);
61 o += 4;
62 }
63 if (n & (2 * sizeof(uint16_t))) {
64 _mm_storeu_si32(o, vh);
65 vh = _mm_srli_epi64(vh, 32);
66 o += 2;
67 }
68 if (n & (1 * sizeof(uint16_t))) {
69 *o = (uint16_t) _mm_extract_epi16(vh, 0);
70 }
71 }
72 }
73