@@ -90,39 +90,23 @@ namespace simdjson::haswell::simd {
9090 really_inline simd8<T>& operator +=(const simd8<T> other) { *this = *this + other; return *this ; }
9191 really_inline simd8<T>& operator -=(const simd8<T> other) { *this = *this - other; return *this ; }
9292
93- // Perform a lookup of the lower 4 bits
93+ // Perform a lookup assuming the value is between 0 and 16 (undefined behavior for out of range values)
9494 template <typename L>
95- really_inline simd8<L> lookup_lower_4_bits (
96- L replace0, L replace1, L replace2, L replace3,
97- L replace4, L replace5, L replace6, L replace7,
98- L replace8, L replace9, L replace10, L replace11,
99- L replace12, L replace13, L replace14, L replace15) const {
100- simd8<L> lookup_table (
101- replace0, replace1, replace2, replace3,
102- replace4, replace5, replace6, replace7,
103- replace8, replace9, replace10, replace11,
104- replace12, replace13, replace14, replace15,
105- replace0, replace1, replace2, replace3,
106- replace4, replace5, replace6, replace7,
107- replace8, replace9, replace10, replace11,
108- replace12, replace13, replace14, replace15
109- );
95+ really_inline simd8<L> lookup_16 (simd8<L> lookup_table) const {
11096 return _mm256_shuffle_epi8 (lookup_table, *this );
11197 }
112-
113- // Perform a lookup assuming the value is between 0 and 16
11498 template <typename L>
11599 really_inline simd8<L> lookup_16 (
116100 L replace0, L replace1, L replace2, L replace3,
117101 L replace4, L replace5, L replace6, L replace7,
118102 L replace8, L replace9, L replace10, L replace11,
119103 L replace12, L replace13, L replace14, L replace15) const {
120- return lookup_lower_4_bits (
104+ return lookup_16 (simd8<L>:: repeat_16 (
121105 replace0, replace1, replace2, replace3,
122106 replace4, replace5, replace6, replace7,
123107 replace8, replace9, replace10, replace11,
124108 replace12, replace13, replace14, replace15
125- );
109+ )) ;
126110 }
127111 };
128112
@@ -147,6 +131,18 @@ namespace simdjson::haswell::simd {
147131 v16,v17,v18,v19,v20,v21,v22,v23,
148132 v24,v25,v26,v27,v28,v29,v30,v31
149133 )) {}
134+ // Repeat 16 values as many times as necessary (usually for lookup tables)
135+ really_inline static simd8<int8_t > repeat_16 (
136+ int8_t v0, int8_t v1, int8_t v2, int8_t v3, int8_t v4, int8_t v5, int8_t v6, int8_t v7,
137+ int8_t v8, int8_t v9, int8_t v10, int8_t v11, int8_t v12, int8_t v13, int8_t v14, int8_t v15
138+ ) {
139+ return simd8<int8_t >(
140+ v0, v1, v2, v3, v4, v5, v6, v7,
141+ v8, v9, v10,v11,v12,v13,v14,v15,
142+ v0, v1, v2, v3, v4, v5, v6, v7,
143+ v8, v9, v10,v11,v12,v13,v14,v15
144+ );
145+ }
150146
151147 // Order-sensitive comparisons
152148 really_inline simd8<int8_t > max (const simd8<int8_t > other) const { return _mm256_max_epi8 (*this , other); }
@@ -175,6 +171,18 @@ namespace simdjson::haswell::simd {
175171 v16,v17,v18,v19,v20,v21,v22,v23,
176172 v24,v25,v26,v27,v28,v29,v30,v31
177173 )) {}
174+ // Repeat 16 values as many times as necessary (usually for lookup tables)
175+ really_inline static simd8<uint8_t > repeat_16 (
176+ uint8_t v0, uint8_t v1, uint8_t v2, uint8_t v3, uint8_t v4, uint8_t v5, uint8_t v6, uint8_t v7,
177+ uint8_t v8, uint8_t v9, uint8_t v10, uint8_t v11, uint8_t v12, uint8_t v13, uint8_t v14, uint8_t v15
178+ ) {
179+ return simd8<uint8_t >(
180+ v0, v1, v2, v3, v4, v5, v6, v7,
181+ v8, v9, v10,v11,v12,v13,v14,v15,
182+ v0, v1, v2, v3, v4, v5, v6, v7,
183+ v8, v9, v10,v11,v12,v13,v14,v15
184+ );
185+ }
178186
179187 // Saturated math
180188 really_inline simd8<uint8_t > saturating_add (const simd8<uint8_t > other) const { return _mm256_adds_epu8 (*this , other); }
0 commit comments