• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/s8-ibilinear/sse.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/ibilinear.h>
16 
17 
xnn_s8_ibilinear_ukernel__sse41_c8(size_t output_pixels,size_t channels,const int8_t ** restrict input,size_t input_offset,const int16_t * restrict weights,int8_t * restrict output,size_t output_increment)18 void xnn_s8_ibilinear_ukernel__sse41_c8(
19     size_t output_pixels,
20     size_t channels,
21     const int8_t**restrict input,
22     size_t input_offset,
23     const int16_t*restrict weights,
24     int8_t*restrict output,
25     size_t output_increment) XNN_OOB_READS
26 {
27   assert(output_pixels != 0);
28   assert(channels != 0);
29 
30   do {
31     const int8_t* i0 = (const int8_t*) ((uintptr_t) input[0] + input_offset);
32     const int8_t* i1 = (const int8_t*) ((uintptr_t) input[1] + input_offset);
33     const int8_t* i2 = (const int8_t*) ((uintptr_t) input[2] + input_offset);
34     const int8_t* i3 = (const int8_t*) ((uintptr_t) input[3] + input_offset);
35     input += 4;
36 
37     const __m128i valpha = _mm_cvtsi32_si128(*((const int*) weights));
38     weights += 2;
39     __m128i valphah = _mm_shufflelo_epi16(valpha, _MM_SHUFFLE(0, 0, 0, 0));
40     valphah = _mm_unpacklo_epi64(valphah, valphah);
41     __m128i valphav = _mm_srli_epi32(valpha, 16);
42     valphav = _mm_shuffle_epi32(valphav, _MM_SHUFFLE(0, 0, 0, 0));
43 
44     valphah = _mm_blend_epi16(valphah, _mm_sub_epi16(_mm_set1_epi32(0x08000000), valphah), 0xAA);
45 
46     const __m128i vrounding = _mm_set1_epi32(0x00200000);
47 
48     size_t c = channels;
49     for (; c >= 8 * sizeof(int8_t); c -= 8 * sizeof(int8_t)) {
50       const __m128i vtl01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
51       i0 += 8;
52       const __m128i vtr01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
53       i1 += 8;
54       const __m128i vbl01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
55       i2 += 8;
56       const __m128i vbr01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
57       i3 += 8;
58 
59 
60       const __m128i vdr01234567 = _mm_sub_epi16(vbr01234567, vtr01234567);
61       const __m128i vt0123 = _mm_madd_epi16(_mm_unpacklo_epi16(vtr01234567, vtl01234567), valphah);
62       const __m128i vdl01234567 = _mm_sub_epi16(vbl01234567, vtl01234567);
63       const __m128i vt4567 = _mm_madd_epi16(_mm_unpackhi_epi16(vtr01234567, vtl01234567), valphah);
64 
65       const __m128i vd0123 = _mm_madd_epi16(_mm_unpacklo_epi16(vdr01234567, vdl01234567), valphah);
66       const __m128i vd4567 = _mm_madd_epi16(_mm_unpackhi_epi16(vdr01234567, vdl01234567), valphah);
67 
68       __m128i vacc0123 = _mm_mullo_epi32(vd0123, valphav);
69       __m128i vacc4567 = _mm_mullo_epi32(vd4567, valphav);
70 
71       vacc0123 = _mm_add_epi32(_mm_slli_epi32(vt0123, 11), vacc0123);
72       vacc4567 = _mm_add_epi32(_mm_slli_epi32(vt4567, 11), vacc4567);
73 
74       vacc0123 = _mm_srai_epi32(_mm_add_epi16(vacc0123, vrounding), 22);
75       vacc4567 = _mm_srai_epi32(_mm_add_epi16(vacc4567, vrounding), 22);
76 
77       const __m128i vacc01234567 = _mm_packs_epi32(vacc0123, vacc4567);
78 
79       const __m128i vo01234567 = _mm_packs_epi16(vacc01234567, vacc01234567);
80 
81       _mm_storel_epi64((__m128i*) output, vo01234567);
82       output += 8;
83     }
84     if XNN_UNLIKELY(c != 0) {
85       const __m128i vtl01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i0));
86       const __m128i vtr01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i1));
87       const __m128i vbl01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i2));
88       const __m128i vbr01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) i3));
89 
90 
91       const __m128i vdr01234567 = _mm_sub_epi16(vbr01234567, vtr01234567);
92       const __m128i vt0123 = _mm_madd_epi16(_mm_unpacklo_epi16(vtr01234567, vtl01234567), valphah);
93       const __m128i vdl01234567 = _mm_sub_epi16(vbl01234567, vtl01234567);
94       const __m128i vt4567 = _mm_madd_epi16(_mm_unpackhi_epi16(vtr01234567, vtl01234567), valphah);
95 
96       const __m128i vd0123 = _mm_madd_epi16(_mm_unpacklo_epi16(vdr01234567, vdl01234567), valphah);
97       const __m128i vd4567 = _mm_madd_epi16(_mm_unpackhi_epi16(vdr01234567, vdl01234567), valphah);
98 
99       __m128i vacc0123 = _mm_mullo_epi32(vd0123, valphav);
100       __m128i vacc4567 = _mm_mullo_epi32(vd4567, valphav);
101 
102       vacc0123 = _mm_add_epi32(_mm_slli_epi32(vt0123, 11), vacc0123);
103       vacc4567 = _mm_add_epi32(_mm_slli_epi32(vt4567, 11), vacc4567);
104 
105       vacc0123 = _mm_srai_epi32(_mm_add_epi16(vacc0123, vrounding), 22);
106       vacc4567 = _mm_srai_epi32(_mm_add_epi16(vacc4567, vrounding), 22);
107 
108       const __m128i vacc01234567 = _mm_packs_epi32(vacc0123, vacc4567);
109 
110       __m128i vo01234567 = _mm_packs_epi16(vacc01234567, vacc01234567);
111 
112       if (c & (4 * sizeof(int8_t))) {
113         *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vo01234567);
114         output += 4;
115         vo01234567 = _mm_srli_epi64(vo01234567, 32);
116       }
117       if (c & (2 * sizeof(int8_t))) {
118         *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vo01234567, 0);
119         output += 2;
120         vo01234567 = _mm_srli_epi32(vo01234567, 16);
121       }
122       if (c & (1 * sizeof(int8_t))) {
123         *output++ = (uint8_t) _mm_extract_epi8(vo01234567, 0);
124       }
125     }
126 
127     output = (int8_t*) ((uintptr_t) output + output_increment);
128   } while (--output_pixels != 0);
129 }
130