Debian Codegraph @

src/f16-vclamp/gen/f16-vclamp-f16c-u8.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-vclamp/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/vunary.h"
17
18
19 void xnn_f16_vclamp_ukernel__f16c_u8(
20 size_t batch,
21 const xnn_float16* restrict input,
22 xnn_float16* restrict output,
23 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(uint16_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const uint16_t* i = (const uint16_t*) input;
31 uint16_t* o = (uint16_t*) output;
32
33 const __m256 vy_min = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.min));
34 const __m256 vy_max = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.max));
35
36 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
37 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
38 i += 8;
39 vacc = _mm256_max_ps(vacc, vy_min);
40 vacc = _mm256_min_ps(vacc, vy_max);
41 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT));
42 o += 8;
43 }
44 if XNN_UNLIKELY(batch != 0) {
45 __m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
46 vacc = _mm256_max_ps(vacc, vy_min);
47 vacc = _mm256_min_ps(vacc, vy_max);
48
49 __m128i vh = _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT);
50 if (batch & (4 * sizeof(uint16_t))) {
51 _mm_storel_epi64((__m128i*) o, vh);
52 vh = _mm_unpackhi_epi64(vh, vh);
53 o += 4;
54 }
55 if (batch & (2 * sizeof(uint16_t))) {
56 _mm_storeu_si32(o, vh);
57 vh = _mm_srli_epi64(vh, 32);
58 o += 2;
59 }
60 if (batch & (1 * sizeof(uint16_t))) {
61 *o = _mm_extract_epi16(vh, 0);
62 }
63 }
64 }