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/intrinsics-polyfill.h>
16 #include <xnnpack/vbinary.h>
17
18
xnn_f16_vadd_minmax_ukernel__f16c_x8(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)])19 void xnn_f16_vadd_minmax_ukernel__f16c_x8(
20 size_t n,
21 const void* restrict a_ptr,
22 const void* restrict b_ptr,
23 void* restrict y_ptr,
24 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
25 {
26 assert(n != 0);
27 assert(n % sizeof(uint16_t) == 0);
28 assert(a_ptr != NULL);
29 assert(b_ptr != NULL);
30 assert(y_ptr != NULL);
31
32 const uint16_t* a = (const uint16_t*) a_ptr;
33 const uint16_t* b = (const uint16_t*) b_ptr;
34 uint16_t* y = (uint16_t*) y_ptr;
35
36 const __m256 vy_min = _mm256_load_ps(params->avx.min);
37 const __m256 vy_max = _mm256_load_ps(params->avx.max);
38
39 for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
40 const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
41 const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
42 a += 8;
43 b += 8;
44
45 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_add_ps(va, vb), _MM_FROUND_NO_EXC));
46
47 vy = _mm256_max_ps(vy, vy_min);
48 vy = _mm256_min_ps(vy, vy_max);
49
50 _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC));
51 y += 8;
52 }
53 if XNN_UNLIKELY(n != 0) {
54 const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
55 const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
56
57 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_add_ps(va, vb), _MM_FROUND_NO_EXC));
58
59 vy = _mm256_max_ps(vy, vy_min);
60 vy = _mm256_min_ps(vy, vy_max);
61
62 __m128i vh = _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC);
63 if (n & (4 * sizeof(uint16_t))) {
64 _mm_storel_epi64((__m128i*) y, vh);
65 vh = _mm_unpackhi_epi64(vh, vh);
66 y += 4;
67 }
68 if (n & (2 * sizeof(uint16_t))) {
69 _mm_storeu_si32(y, vh);
70 vh = _mm_srli_epi64(vh, 32);
71 y += 2;
72 }
73 if (n & (1 * sizeof(uint16_t))) {
74 *y = (uint16_t) _mm_extract_epi16(vh, 0);
75 }
76 }
77 }
78