| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f16-igemm/avx2-broadcast.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/igemm.h" |
| 15 |
#include "xnnpack/intrinsics-polyfill.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f16_f32acc_igemm_minmax_ukernel_1x8__avx2_broadcast( |
| 19 |
size_t mr, |
| 20 |
size_t nc, |
| 21 |
size_t kc, |
| 22 |
size_t ks, |
| 23 |
const xnn_float16** restrict a, |
| 24 |
const xnn_float16* restrict w, |
| 25 |
xnn_float16* restrict c, |
| 26 |
size_t cm_stride, |
| 27 |
size_t cn_stride, |
| 28 |
size_t a_offset, |
| 29 |
const xnn_float16* zero, |
| 30 |
const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 31 |
{ |
| 32 |
assert(mr != 0); |
| 33 |
assert(mr <= 1); |
| 34 |
assert(nc != 0); |
| 35 |
assert(kc != 0); |
| 36 |
assert(kc % sizeof(uint16_t) == 0); |
| 37 |
assert(ks != 0); |
| 38 |
assert(ks % (1 * sizeof(void*)) == 0); |
| 39 |
assert(a_offset % sizeof(uint16_t) == 0); |
| 40 |
assert(a != NULL); |
| 41 |
assert(w != NULL); |
| 42 |
assert(c != NULL); |
| 43 |
|
| 44 |
const __m256 vmin = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) ¶ms->scalar.min)); |
| 45 |
const __m256 vmax = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) ¶ms->scalar.max)); |
| 46 |
XNN_FORCE_REALIZATION(vmin); |
| 47 |
XNN_FORCE_REALIZATION(vmax); |
| 48 |
|
| 49 |
uint16_t* c0 = (uint16_t*) c; |
| 50 |
|
| 51 |
do { |
| 52 |
__m256 vacc0x0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w)); |
| 53 |
w = (const xnn_float16*) w + 8; |
| 54 |
|
| 55 |
size_t p = ks; |
| 56 |
do { |
| 57 |
const uint16_t* restrict a0 = (const uint16_t*) a[0]; |
| 58 |
assert(a0 != NULL); |
| 59 |
if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) { |
| 60 |
a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset); |
| 61 |
} |
| 62 |
a += 1; |
| 63 |
|
| 64 |
size_t k = kc; |
| 65 |
do { |
| 66 |
const __m256 vb0 = _mm256_cvtph_ps(_mm_load_si128((const __m128i*) w)); |
| 67 |
w = (const xnn_float16*) w + 8; |
| 68 |
|
| 69 |
const __m256 va0 = _mm256_cvtph_ps(_mm_set1_epi16((short) *a0)); |
| 70 |
a0 += 1; |
| 71 |
|
| 72 |
vacc0x0 = _mm256_fmadd_ps(va0, vb0, vacc0x0); |
| 73 |
|
| 74 |
k -= sizeof(uint16_t); |
| 75 |
} while (k != 0); |
| 76 |
p -= 1 * sizeof(void*); |
| 77 |
} while (p != 0); |
| 78 |
|
| 79 |
vacc0x0 = _mm256_max_ps(vacc0x0, vmin); |
| 80 |
|
| 81 |
vacc0x0 = _mm256_min_ps(vacc0x0, vmax); |
| 82 |
|
| 83 |
if XNN_LIKELY(nc >= 8) { |
| 84 |
_mm_storeu_si128((__m128i*) c0, _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT)); |
| 85 |
c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride); |
| 86 |
|
| 87 |
a = (const xnn_float16**restrict) ((uintptr_t) a - ks); |
| 88 |
nc -= 8; |
| 89 |
} else { |
| 90 |
__m128i vh0x0 = _mm256_cvtps_ph(vacc0x0, _MM_FROUND_TO_NEAREST_INT); |
| 91 |
if (nc & 4) { |
| 92 |
_mm_storel_epi64((__m128i*) c0, vh0x0); |
| 93 |
|
| 94 |
vh0x0 = _mm_unpackhi_epi64(vh0x0, vh0x0); |
| 95 |
|
| 96 |
c0 += 4; |
| 97 |
} |
| 98 |
if (nc & 2) { |
| 99 |
_mm_storeu_si32(c0, vh0x0); |
| 100 |
|
| 101 |
vh0x0 = _mm_srli_epi64(vh0x0, 32); |
| 102 |
|
| 103 |
c0 += 2; |
| 104 |
} |
| 105 |
if (nc & 1) { |
| 106 |
*c0 = _mm_extract_epi16(vh0x0, 0); |
| 107 |
} |
| 108 |
|
| 109 |
nc = 0; |
| 110 |
} |
| 111 |
} while (nc != 0); |
| 112 |
} |