| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 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 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
void xnn_f16_vrsqrt_ukernel__f16c_rsqrt_u8( |
| 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 >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) { |
| 40 |
__m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i)); |
| 41 |
i += 8; |
| 42 |
vacc = _mm256_rsqrt_ps(vacc); |
| 43 |
_mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vacc, _MM_FROUND_TO_NEAREST_INT)); |
| 44 |
o += 8; |
| 45 |
} |
| 46 |
if XNN_UNLIKELY(batch != 0) { |
| 47 |
__m256 vacc = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i)); |
| 48 |
vacc = _mm256_rsqrt_ps(vacc); |
| 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 |
o += 4; |
| 53 |
vh = _mm_unpackhi_epi64(vh, vh); |
| 54 |
} |
| 55 |
if (batch & (2 * sizeof(uint16_t))) { |
| 56 |
_mm_storeu_si32(o, vh); |
| 57 |
o += 2; |
| 58 |
vh = _mm_srli_epi64(vh, 32); |
| 59 |
} |
| 60 |
if (batch & (1 * sizeof(uint16_t))) { |
| 61 |
*o = (uint16_t) _mm_extract_epi16(vh, 0); |
| 62 |
} |
| 63 |
} |
| 64 |
} |