1 // Auto-generated file. Do not edit!
2 // Template: src/f16-f32-vcvt/sse-int32.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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 <smmintrin.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/vcvt.h>
16
17
xnn_f16_f32_vcvt_ukernel__avx_int32_x8(size_t n,const void * input,float * output,const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_f32_vcvt_ukernel__avx_int32_x8(
19 size_t n,
20 const void* input,
21 float* output,
22 const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(n != 0);
25 assert(n % sizeof(uint16_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const __m128i vsign_mask = _mm_load_si128((const __m128i*) params->sse_int32.sign_mask);
30 const __m128i vexp_offset = _mm_load_si128((const __m128i*) params->sse_int32.exp_offset);
31 const __m128 vexp_scale = _mm_load_ps(params->sse_int32.exp_scale);
32 const __m128i vmagic_bias = _mm_load_si128((const __m128i*) params->sse_int32.magic_bias);
33 const __m128i vdenorm_cutoff = _mm_load_si128((const __m128i*) params->sse_int32.denorm_cutoff);
34
35 const uint16_t* i = (const uint16_t*) input;
36 for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
37 const __m128i vh = _mm_loadu_si128((const __m128i*) i);
38 i += 8;
39
40 const __m128i vw_lo = _mm_unpacklo_epi16(_mm_setzero_si128(), vh);
41 const __m128i vw_hi = _mm_unpackhi_epi16(_mm_setzero_si128(), vh);
42
43 const __m128i vsign_lo = _mm_and_si128(vw_lo, vsign_mask);
44 const __m128i vsign_hi = _mm_and_si128(vw_hi, vsign_mask);
45
46 const __m128i vnonsign_lo = _mm_xor_si128(vw_lo, vsign_lo);
47 const __m128i vnonsign_hi = _mm_xor_si128(vw_hi, vsign_hi);
48
49 const __m128i vnorm_lo = _mm_castps_si128(_mm_mul_ps(_mm_castsi128_ps(_mm_add_epi32(_mm_srli_epi32(vnonsign_lo, 3), vexp_offset)), vexp_scale));
50 const __m128i vnorm_hi = _mm_castps_si128(_mm_mul_ps(_mm_castsi128_ps(_mm_add_epi32(_mm_srli_epi32(vnonsign_hi, 3), vexp_offset)), vexp_scale));
51
52 const __m128i vdenorm_lo = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_or_si128(_mm_srli_epi32(vnonsign_lo, 16), vmagic_bias)), _mm_castsi128_ps(vmagic_bias)));
53 const __m128i vdenorm_hi = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_or_si128(_mm_srli_epi32(vnonsign_hi, 16), vmagic_bias)), _mm_castsi128_ps(vmagic_bias)));
54
55 const __m128i vmask_lo = _mm_cmpgt_epi32(vnonsign_lo, vdenorm_cutoff);
56 const __m128i vf_lo = _mm_or_si128(vsign_lo, _mm_blendv_epi8(vdenorm_lo, vnorm_lo, vmask_lo));
57
58 const __m128i vmask_hi = _mm_cmpgt_epi32(vnonsign_hi, vdenorm_cutoff);
59 const __m128i vf_hi = _mm_or_si128(vsign_hi, _mm_blendv_epi8(vdenorm_hi, vnorm_hi, vmask_hi));
60
61 _mm_storeu_ps(output, _mm_castsi128_ps(vf_lo));
62 _mm_storeu_ps(output + 4, _mm_castsi128_ps(vf_hi));
63 output += 8;
64 }
65 if XNN_UNPREDICTABLE(n != 0) {
66 const __m128i vh = _mm_loadu_si128((const __m128i*) i);
67
68 const __m128i vw_lo = _mm_unpacklo_epi16(_mm_setzero_si128(), vh);
69 const __m128i vw_hi = _mm_unpackhi_epi16(_mm_setzero_si128(), vh);
70
71 const __m128i vsign_lo = _mm_and_si128(vw_lo, vsign_mask);
72 const __m128i vsign_hi = _mm_and_si128(vw_hi, vsign_mask);
73
74 const __m128i vnonsign_lo = _mm_xor_si128(vw_lo, vsign_lo);
75 const __m128i vnonsign_hi = _mm_xor_si128(vw_hi, vsign_hi);
76
77 const __m128i vnorm_lo = _mm_castps_si128(_mm_mul_ps(_mm_castsi128_ps(_mm_add_epi32(_mm_srli_epi32(vnonsign_lo, 3), vexp_offset)), vexp_scale));
78 const __m128i vnorm_hi = _mm_castps_si128(_mm_mul_ps(_mm_castsi128_ps(_mm_add_epi32(_mm_srli_epi32(vnonsign_hi, 3), vexp_offset)), vexp_scale));
79
80 const __m128i vdenorm_lo = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_or_si128(_mm_srli_epi32(vnonsign_lo, 16), vmagic_bias)), _mm_castsi128_ps(vmagic_bias)));
81 const __m128i vdenorm_hi = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_or_si128(_mm_srli_epi32(vnonsign_hi, 16), vmagic_bias)), _mm_castsi128_ps(vmagic_bias)));
82
83 const __m128i vmask_lo = _mm_cmpgt_epi32(vnonsign_lo, vdenorm_cutoff);
84 __m128i vf = _mm_or_si128(vsign_lo, _mm_blendv_epi8(vdenorm_lo, vnorm_lo, vmask_lo));
85
86 if (n & (4 * sizeof(uint16_t))) {
87 _mm_storeu_ps(output, _mm_castsi128_ps(vf));
88 output += 4;
89
90 const __m128i vmask_hi = _mm_cmpgt_epi32(vnonsign_hi, vdenorm_cutoff);
91 vf = _mm_or_si128(vsign_hi, _mm_blendv_epi8(vdenorm_hi, vnorm_hi, vmask_hi));
92 }
93 if (n & (2 * sizeof(uint16_t))) {
94 _mm_storel_pi((__m64*) output, _mm_castsi128_ps(vf));
95 output += 2;
96
97 vf = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(vf), _mm_castsi128_ps(vf)));
98 }
99 if (n & (1 * sizeof(uint16_t))) {
100 _mm_store_ss(output, _mm_castsi128_ps(vf));
101 }
102 }
103 }
104