1 // Auto-generated file. Do not edit!
2 // Template: src/f16-vbinary/vop-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/vbinary.h>
16
17
xnn_f16_vdiv_minmax_ukernel__f16c_x16(size_t n,const void * restrict a_ptr,const void * restrict b_ptr,void * restrict y_ptr,const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_vdiv_minmax_ukernel__f16c_x16(
19 size_t n,
20 const void* restrict a_ptr,
21 const void* restrict b_ptr,
22 void* restrict y_ptr,
23 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(uint16_t) == 0);
27 assert(a_ptr != NULL);
28 assert(b_ptr != NULL);
29 assert(y_ptr != NULL);
30
31 const uint16_t* a = (const uint16_t*) a_ptr;
32 const uint16_t* b = (const uint16_t*) b_ptr;
33 uint16_t* y = (uint16_t*) y_ptr;
34
35 const __m256 vy_min = _mm256_load_ps(params->avx.min);
36 const __m256 vy_max = _mm256_load_ps(params->avx.max);
37
38 for (; n >= 16 * sizeof(uint16_t); n -= 16 * sizeof(uint16_t)) {
39 const __m256 va01234567 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
40 const __m256 vb01234567 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
41 const __m256 va456789AB = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (a + 8)));
42 const __m256 vb456789AB = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (b + 8)));
43 a += 16;
44 b += 16;
45
46 __m256 vy01234567 = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_div_ps(va01234567, vb01234567), _MM_FROUND_NO_EXC));
47 __m256 vy456789AB = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_div_ps(va456789AB, vb456789AB), _MM_FROUND_NO_EXC));
48
49
50 vy01234567 = _mm256_max_ps(vy01234567, vy_min);
51 vy456789AB = _mm256_max_ps(vy456789AB, vy_min);
52
53 vy01234567 = _mm256_min_ps(vy01234567, vy_max);
54 vy456789AB = _mm256_min_ps(vy456789AB, vy_max);
55
56 _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy01234567, _MM_FROUND_NO_EXC));
57 _mm_storeu_si128((__m128i*) (y + 8), _mm256_cvtps_ph(vy456789AB, _MM_FROUND_NO_EXC));
58 y += 16;
59 }
60 for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
61 const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
62 const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
63 a += 8;
64 b += 8;
65
66 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_div_ps(va, vb), _MM_FROUND_NO_EXC));
67
68 vy = _mm256_max_ps(vy, vy_min);
69 vy = _mm256_min_ps(vy, vy_max);
70
71 _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC));
72 y += 8;
73 }
74 if XNN_UNLIKELY(n != 0) {
75 const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
76 const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
77
78 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_div_ps(va, vb), _MM_FROUND_NO_EXC));
79
80 vy = _mm256_max_ps(vy, vy_min);
81 vy = _mm256_min_ps(vy, vy_max);
82
83 __m128i vh = _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC);
84 if (n & (4 * sizeof(uint16_t))) {
85 _mm_storel_epi64((__m128i*) y, vh);
86 vh = _mm_unpackhi_epi64(vh, vh);
87 y += 4;
88 }
89 if (n & (2 * sizeof(uint16_t))) {
90 *((uint32_t*) y) = (uint32_t) _mm_cvtsi128_si32(vh);
91 vh = _mm_srli_epi64(vh, 32);
92 y += 2;
93 }
94 if (n & (1 * sizeof(uint16_t))) {
95 *y = (uint16_t) _mm_extract_epi16(vh, 0);
96 }
97 }
98 }
99