blob: c3e046e5d70ea409b2c6a695bc2b29e1e95f9cba [file] [log] [blame]
Marat Dukhand4545452022-01-10 16:13:11 -08001// Auto-generated file. Do not edit!
2// Template: src/f16-vbinary/vopc-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
18void xnn_f16_vaddc_minmax_ukernel__f16c_x8(
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 const __m256 vb = _mm256_cvtph_ps(_mm_set1_epi16((short) *b));
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 a += 8;
42
43 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_add_ps(va, vb), _MM_FROUND_NO_EXC));
44
45 vy = _mm256_max_ps(vy, vy_min);
46 vy = _mm256_min_ps(vy, vy_max);
47
48 _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC));
49 y += 8;
50 }
51 if XNN_UNLIKELY(n != 0) {
52 const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
53
54 __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_add_ps(va, vb), _MM_FROUND_NO_EXC));
55
56 vy = _mm256_max_ps(vy, vy_min);
57 vy = _mm256_min_ps(vy, vy_max);
58
59 __m128i vh = _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC);
60 if (n & (4 * sizeof(uint16_t))) {
61 _mm_storel_epi64((__m128i*) y, vh);
62 vh = _mm_unpackhi_epi64(vh, vh);
63 y += 4;
64 }
65 if (n & (2 * sizeof(uint16_t))) {
66 *((uint32_t*) y) = (uint32_t) _mm_cvtsi128_si32(vh);
67 vh = _mm_srli_epi64(vh, 32);
68 y += 2;
69 }
70 if (n & (1 * sizeof(uint16_t))) {
71 *y = (uint16_t) _mm_extract_epi16(vh, 0);
72 }
73 }
74}