Debian Codegraph @

src/f16-vrsqrt/gen/f16-vrsqrt-f16c-rsqrt-u32.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_u32(
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 >= 32 * sizeof(uint16_t); batch -= 32 * 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 __m256 vacc2 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (i + 16)));
43 __m256 vacc3 = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) (i + 24)));
44 i += 32;
45
46 vacc0 = _mm256_rsqrt_ps(vacc0);
47 vacc1 = _mm256_rsqrt_ps(vacc1);
48 vacc2 = _mm256_rsqrt_ps(vacc2);
49 vacc3 = _mm256_rsqrt_ps(vacc3);
50
51 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc0, _MM_FROUND_TO_NEAREST_INT));
52 _mm_storeu_si128((__m128i*) (o + 8), _mm256_cvtps_ph(vacc1, _MM_FROUND_TO_NEAREST_INT));
53 _mm_storeu_si128((__m128i*) (o + 16), _mm256_cvtps_ph(vacc2, _MM_FROUND_TO_NEAREST_INT));
54 _mm_storeu_si128((__m128i*) (o + 24), _mm256_cvtps_ph(vacc3, _MM_FROUND_TO_NEAREST_INT));
55 o += 32;
56 }
57 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
58 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
59 i += 8;
60 vacc = _mm256_rsqrt_ps(vacc);
61 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT));
62 o += 8;
63 }
64 if XNN_UNLIKELY(batch != 0) {
65 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
66 vacc = _mm256_rsqrt_ps(vacc);
67 __m128i vh = _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT);
68 if (batch & (4 * sizeof(uint16_t))) {
69 _mm_storel_epi64((__m128i*) o, vh);
70 o += 4;
71 vh = _mm_unpackhi_epi64(vh, vh);
72 }
73 if (batch & (2 * sizeof(uint16_t))) {
74 _mm_storeu_si32(o, vh);
75 o += 2;
76 vh = _mm_srli_epi64(vh, 32);
77 }
78 if (batch & (1 * sizeof(uint16_t))) {
79 *o = (uint16_t) _mm_extract_epi16(vh, 0);
80 }
81 }
82 }