Debian Codegraph @

src/x8-lut/gen/x8-lut-ssse3-u16.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x8-lut/ssse3.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 <tmmintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/lut.h"
16 #include "xnnpack/unaligned.h"
17
18
19 void xnn_x8_lut_ukernel__ssse3_u16(
20 size_t batch,
21 const uint8_t* input,
22 uint8_t* output,
23 const uint8_t table[restrict XNN_MIN_ELEMENTS(256)])
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(uint8_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const __m128i vt0 = _mm_load_si128((const __m128i*) table);
31 const __m128i vt1 = _mm_load_si128((const __m128i*) (table + 16));
32 const __m128i vt2 = _mm_load_si128((const __m128i*) (table + 32));
33 const __m128i vt3 = _mm_load_si128((const __m128i*) (table + 48));
34 const __m128i vt4 = _mm_load_si128((const __m128i*) (table + 64));
35 const __m128i vt5 = _mm_load_si128((const __m128i*) (table + 80));
36 const __m128i vt6 = _mm_load_si128((const __m128i*) (table + 96));
37 const __m128i vt7 = _mm_load_si128((const __m128i*) (table + 112));
38 const __m128i vt8 = _mm_load_si128((const __m128i*) (table + 128));
39 const __m128i vt9 = _mm_load_si128((const __m128i*) (table + 144));
40 const __m128i vtA = _mm_load_si128((const __m128i*) (table + 160));
41 const __m128i vtB = _mm_load_si128((const __m128i*) (table + 176));
42 const __m128i vtC = _mm_load_si128((const __m128i*) (table + 192));
43 const __m128i vtD = _mm_load_si128((const __m128i*) (table + 208));
44 const __m128i vtE = _mm_load_si128((const __m128i*) (table + 224));
45 const __m128i vtF = _mm_load_si128((const __m128i*) (table + 240));
46
47 const __m128i vtable0 = vt0;
48 const __m128i vtable1 = _mm_xor_si128(vt0, vt1);
49 const __m128i vtable2 = _mm_xor_si128(vt1, vt2);
50 const __m128i vtable3 = _mm_xor_si128(vt2, vt3);
51 const __m128i vtable4 = _mm_xor_si128(vt3, vt4);
52 const __m128i vtable5 = _mm_xor_si128(vt4, vt5);
53 const __m128i vtable6 = _mm_xor_si128(vt5, vt6);
54 const __m128i vtable7 = _mm_xor_si128(vt6, vt7);
55 const __m128i vtable8 = _mm_xor_si128(_mm_xor_si128(vt7, vt8), vtable0);
56 const __m128i vtable9 = _mm_xor_si128(_mm_xor_si128(vt8, vt9), vtable1);
57 const __m128i vtableA = _mm_xor_si128(_mm_xor_si128(vt9, vtA), vtable2);
58 const __m128i vtableB = _mm_xor_si128(_mm_xor_si128(vtA, vtB), vtable3);
59 const __m128i vtableC = _mm_xor_si128(_mm_xor_si128(vtB, vtC), vtable4);
60 const __m128i vtableD = _mm_xor_si128(_mm_xor_si128(vtC, vtD), vtable5);
61 const __m128i vtableE = _mm_xor_si128(_mm_xor_si128(vtD, vtE), vtable6);
62 const __m128i vtableF = _mm_xor_si128(_mm_xor_si128(vtE, vtF), vtable7);
63
64 const __m128i voffset = _mm_set1_epi8(16);
65 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
66 __m128i vx = _mm_loadu_si128((const __m128i*) input);
67 input += 16;
68
69 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
70
71 vx = _mm_sub_epi8(vx, voffset);
72 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
73 vx = _mm_sub_epi8(vx, voffset);
74 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
75 vx = _mm_sub_epi8(vx, voffset);
76 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
77 vx = _mm_sub_epi8(vx, voffset);
78 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
79 vx = _mm_sub_epi8(vx, voffset);
80 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
81 vx = _mm_sub_epi8(vx, voffset);
82 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
83 vx = _mm_sub_epi8(vx, voffset);
84 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
85 vx = _mm_sub_epi8(vx, voffset);
86 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
87
88 vx = _mm_subs_epi8(vx, voffset);
89 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
90 vx = _mm_subs_epi8(vx, voffset);
91 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
92 vx = _mm_subs_epi8(vx, voffset);
93 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
94 vx = _mm_subs_epi8(vx, voffset);
95 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
96 vx = _mm_subs_epi8(vx, voffset);
97 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
98 vx = _mm_subs_epi8(vx, voffset);
99 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
100 vx = _mm_subs_epi8(vx, voffset);
101 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
102
103 _mm_storeu_si128((__m128i*) output, vy);
104 output += 16;
105 }
106 if XNN_UNLIKELY(batch != 0) {
107 __m128i vx = _mm_loadu_si128((const __m128i*) input);
108
109 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
110
111 vx = _mm_sub_epi8(vx, voffset);
112 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
113 vx = _mm_sub_epi8(vx, voffset);
114 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
115 vx = _mm_sub_epi8(vx, voffset);
116 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
117 vx = _mm_sub_epi8(vx, voffset);
118 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
119 vx = _mm_sub_epi8(vx, voffset);
120 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
121 vx = _mm_sub_epi8(vx, voffset);
122 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
123 vx = _mm_sub_epi8(vx, voffset);
124 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
125 vx = _mm_sub_epi8(vx, voffset);
126 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
127
128 vx = _mm_subs_epi8(vx, voffset);
129 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
130 vx = _mm_subs_epi8(vx, voffset);
131 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
132 vx = _mm_subs_epi8(vx, voffset);
133 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
134 vx = _mm_subs_epi8(vx, voffset);
135 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
136 vx = _mm_subs_epi8(vx, voffset);
137 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
138 vx = _mm_subs_epi8(vx, voffset);
139 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
140 vx = _mm_subs_epi8(vx, voffset);
141 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
142
143 if (batch & (8 * sizeof(uint8_t))) {
144 _mm_storel_epi64((__m128i*) output, vy);
145 vy = _mm_unpackhi_epi64(vy, vy);
146 output += 8;
147 }
148 if (batch & (4 * sizeof(uint8_t))) {
149 unaligned_store_u32(output, (uint32_t) _mm_cvtsi128_si32(vy));
150 vy = _mm_srli_epi64(vy, 32);
151 output += 4;
152 }
153 uint32_t vy_lo = (uint32_t) _mm_cvtsi128_si32(vy);
154 if (batch & (2 * sizeof(uint8_t))) {
155 unaligned_store_u16(output, (uint16_t) vy_lo);
156 vy_lo >>= 16;
157 output += 2;
158 }
159 if (batch & (1 * sizeof(uint8_t))) {
160 *output = (uint8_t) vy_lo;
161 }
162 }
163 }