• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_vsqrdiff_ukernel__f16c_x16(size_t n,const void * restrict a_ptr,const void * restrict b_ptr,void * restrict y_ptr,const union xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f16_vsqrdiff_ukernel__f16c_x16(
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_default_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 
37   for (; n >= 16 * sizeof(uint16_t); n -= 16 * sizeof(uint16_t)) {
38     const __m256 va01234567 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
39     const __m256 vb01234567 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
40     const __m256 va456789AB = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (a + 8)));
41     const __m256 vb456789AB = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (b + 8)));
42     a += 16;
43     b += 16;
44 
45     __m256 vy01234567 = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_sub_ps(va01234567, vb01234567), _MM_FROUND_NO_EXC));
46     __m256 vy456789AB = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_sub_ps(va456789AB, vb456789AB), _MM_FROUND_NO_EXC));
47 
48     vy01234567 = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_mul_ps(vy01234567, vy01234567), _MM_FROUND_NO_EXC));
49     vy456789AB = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_mul_ps(vy456789AB, vy456789AB), _MM_FROUND_NO_EXC));
50 
51 
52     _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy01234567, _MM_FROUND_NO_EXC));
53     _mm_storeu_si128((__m128i*) (y + 8), _mm256_cvtps_ph(vy456789AB, _MM_FROUND_NO_EXC));
54     y += 16;
55   }
56   for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
57     const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
58     const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
59     a += 8;
60     b += 8;
61 
62     __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_sub_ps(va, vb), _MM_FROUND_NO_EXC));
63     vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_mul_ps(vy, vy), _MM_FROUND_NO_EXC));
64 
65 
66     _mm_storeu_si128((__m128i*) y, _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC));
67     y += 8;
68   }
69   if XNN_UNLIKELY(n != 0) {
70     const __m256 va = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) a));
71     const __m256 vb = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) b));
72 
73     __m256 vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_sub_ps(va, vb), _MM_FROUND_NO_EXC));
74     vy = _mm256_cvtph_ps(_mm256_cvtps_ph(_mm256_mul_ps(vy, vy), _MM_FROUND_NO_EXC));
75 
76 
77     __m128i vh = _mm256_cvtps_ph(vy, _MM_FROUND_NO_EXC);
78     if (n & (4 * sizeof(uint16_t))) {
79       _mm_storel_epi64((__m128i*) y, vh);
80       vh = _mm_unpackhi_epi64(vh, vh);
81       y += 4;
82     }
83     if (n & (2 * sizeof(uint16_t))) {
84       _mm_storeu_si32(y, vh);
85       vh = _mm_srli_epi64(vh, 32);
86       y += 2;
87     }
88     if (n & (1 * sizeof(uint16_t))) {
89       *y = (uint16_t) _mm_extract_epi16(vh, 0);
90     }
91   }
92 }
93