Debian Codegraph @

src/f16-vrsqrt/gen/f16-vrsqrt-f16c-rsqrt-u16.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-vrsqrt/f16c-rsqrt.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 #include <stddef.h>
12 #include <stdint.h>
13
14 #include <immintrin.h>
15
16 #include "xnnpack/common.h"
17 #include "xnnpack/intrinsics-polyfill.h"
18 #include "xnnpack/microparams.h"
19 #include "xnnpack/vunary.h"
20
21
22 // Since the result will be converted back to an `f16` value with a 10-bit
23 // mantissa, the 12-bit `rsqrt` approximation is more than sufficiently
24 // accurate.
25
26 void xnn_f16_vrsqrt_ukernel__f16c_rsqrt_u16(
27 size_t batch,
28 const xnn_float16* input,
29 xnn_float16* output,
30 const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(batch != 0);
33 assert(batch % sizeof(uint16_t) == 0);
34 assert(input != NULL);
35 assert(output != NULL);
36
37 const uint16_t* i = (const uint16_t*) input;
38 uint16_t* o = (uint16_t*) output;
39 for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) {
40 __m256 vacc0 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
41 __m256 vacc1 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (i + 8)));
42 i += 16;
43
44 vacc0 = _mm256_rsqrt_ps(vacc0);
45 vacc1 = _mm256_rsqrt_ps(vacc1);
46
47 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc0, _MM_FROUND_TO_NEAREST_INT));
48 _mm_storeu_si128((__m128i*) (o + 8), _mm256_cvtps_ph(vacc1, _MM_FROUND_TO_NEAREST_INT));
49 o += 16;
50 }
51 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
52 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
53 i += 8;
54 vacc = _mm256_rsqrt_ps(vacc);
55 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT));
56 o += 8;
57 }
58 if XNN_UNLIKELY(batch != 0) {
59 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
60 vacc = _mm256_rsqrt_ps(vacc);
61 __m128i vh = _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT);
62 if (batch & (4 * sizeof(uint16_t))) {
63 _mm_storel_epi64((__m128i*) o, vh);
64 o += 4;
65 vh = _mm_unpackhi_epi64(vh, vh);
66 }
67 if (batch & (2 * sizeof(uint16_t))) {
68 _mm_storeu_si32(o, vh);
69 o += 2;
70 vh = _mm_srli_epi64(vh, 32);
71 }
72 if (batch & (1 * sizeof(uint16_t))) {
73 *o = (uint16_t) _mm_extract_epi16(vh, 0);
74 }
75 }
76 }