| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f16-rminmax/avx512fp16.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2024 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/reduce.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f16_rmax_ukernel__avx512fp16_u64_acc2( |
| 19 |
size_t batch, |
| 20 |
const xnn_float16* input, |
| 21 |
xnn_float16* output, |
| 22 |
const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(uint16_t) == 0); |
| 26 |
assert(input != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
#if defined(__AVX512FP16__) |
| 30 |
const uint16_t* i = (const uint16_t*) input; |
| 31 |
__m512h vmax0 = _mm512_castsi512_ph(_mm512_set1_epi16(*i)); |
| 32 |
__m512h vmax1 = vmax0; |
| 33 |
for (; batch >= 64 * sizeof(uint16_t); batch -= 64 * sizeof(uint16_t)) { |
| 34 |
const __m512h vt0 = _mm512_loadu_ph(i); |
| 35 |
const __m512h vt1 = _mm512_loadu_ph((i + 32)); |
| 36 |
i += 64; |
| 37 |
|
| 38 |
vmax0 = _mm512_max_ph(vmax0, vt0); |
| 39 |
vmax1 = _mm512_max_ph(vmax1, vt1); |
| 40 |
} |
| 41 |
vmax0 = _mm512_max_ph(vmax0, vmax1); |
| 42 |
for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) { |
| 43 |
const __m512h vt = _mm512_loadu_ph(i); |
| 44 |
i += 32; |
| 45 |
|
| 46 |
vmax0 = _mm512_max_ph(vmax0, vt); |
| 47 |
} |
| 48 |
if XNN_UNLIKELY(batch != 0) { |
| 49 |
assert(batch >= 1 * sizeof(uint16_t)); |
| 50 |
assert(batch <= 31 * sizeof(uint16_t)); |
| 51 |
|
| 52 |
// Prepare mask for valid elements (depends on batch). |
| 53 |
batch >>= XNN_LOG2_SIZEOF_HALF; |
| 54 |
const __mmask32 vmask = _cvtu32_mask32((uint32_t) ((UINT32_C(1) << batch) - UINT32_C(1))); |
| 55 |
|
| 56 |
const __m512h vt = _mm512_castsi512_ph(_mm512_maskz_loadu_epi16(vmask, i)); |
| 57 |
|
| 58 |
vmax0 = _mm512_mask_max_ph(vmax0, vmask, vmax0, vt); |
| 59 |
} |
| 60 |
__m256h vmax256 = _mm256_max_ph(_mm512_castph512_ph256(vmax0), _mm256_castpd_ph(_mm512_extractf64x4_pd(_mm512_castph_pd(vmax0), 1))); |
| 61 |
__m128h vmax = _mm_max_ph(_mm256_castph256_ph128(vmax256), _mm_castps_ph(_mm256_extractf128_ps(_mm256_castph_ps(vmax256), 1))); |
| 62 |
vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehl_ps(_mm_castph_ps(vmax), _mm_castph_ps(vmax)))); |
| 63 |
vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehdup_ps(_mm_castph_ps(vmax)))); |
| 64 |
vmax = _mm_max_sh(vmax, _mm_castsi128_ph(_mm_srli_epi32(_mm_castph_si128(vmax), 16))); |
| 65 |
|
| 66 |
*((uint16_t*) output) = (uint16_t) _mm_extract_epi16(_mm_castph_si128(vmax), 0); |
| 67 |
#endif // defined(__AVX512FP16__) |
| 68 |
} |