Skip to content

Commit 00d6654

Browse files
committed
Trying this.
1 parent 7c55a42 commit 00d6654

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

‎src/generic/stage1/utf8_lookup3_algorithm.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace utf8_validation {
7777
// 3 4-bit table lookups, identifying which errors that 4 bits could match, and then &'s them together.
7878
// If all 3 lookups detect the same error, it's an error.
7979
//
80-
really_inline simd8<uint8_t> check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
80+
really_inline simd8<uint8_t> check_special_cases(const simd8<uint8_t>& input, const simd8<uint8_t>& prev1) {
8181
//
8282
// These are the errors we're going to match for bytes 1-2, by looking at the first three
8383
// nibbles of the character: <high bits of byte 1>> & <low bits of byte 1> & <high bits of byte 2>
@@ -152,7 +152,7 @@ namespace utf8_validation {
152152
}
153153

154154
really_inline simd8<uint8_t> check_multibyte_lengths(const simd8<uint8_t>& input, const simd8<uint8_t>& prev_input,
155-
simd8<uint8_t> prev1) {
155+
simd8<uint8_t>& prev1) {
156156
simd8<uint8_t> prev2 = input.prev<2>(prev_input);
157157
simd8<uint8_t> prev3 = input.prev<3>(prev_input);
158158
// is_2_3_continuation uses one more instruction than lookup2

‎src/haswell/simd.h‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ namespace simd {
2727
really_inline operator __m256i&() { return this->value; }
2828

2929
// Bit operations
30-
really_inline Child operator|(const Child other) const { return _mm256_or_si256(*this, other); }
31-
really_inline Child operator&(const Child other) const { return _mm256_and_si256(*this, other); }
32-
really_inline Child operator^(const Child other) const { return _mm256_xor_si256(*this, other); }
33-
really_inline Child bit_andnot(const Child other) const { return _mm256_andnot_si256(other, *this); }
34-
really_inline Child& operator|=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast | other; return *this_cast; }
35-
really_inline Child& operator&=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast & other; return *this_cast; }
36-
really_inline Child& operator^=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast ^ other; return *this_cast; }
30+
really_inline Child operator|(const Child& other) const { return _mm256_or_si256(*this, other); }
31+
really_inline Child operator&(const Child& other) const { return _mm256_and_si256(*this, other); }
32+
really_inline Child operator^(const Child& other) const { return _mm256_xor_si256(*this, other); }
33+
really_inline Child bit_andnot(const Child& other) const { return _mm256_andnot_si256(other, *this); }
34+
really_inline Child& operator=(const Child& other) const { value = other.value; return *this; }
35+
really_inline Child& operator|=(const Child& other) { this->value = _mm256_or_si256(this->value, other.value); return (Child& )*this; }
36+
really_inline Child& operator&=(const Child& other) { this->value = _mm256_and_si256(this->value, other.value); return (Child& )*this; }
37+
really_inline Child& operator^=(const Child& other) { this->value = _mm256_xor_si256(this->value, other.value); return (Child& )*this; }
3738
};
3839

3940
// Forward-declared so they can be used by splat and friends.
@@ -48,12 +49,12 @@ namespace simd {
4849
really_inline base8() : base<simd8<T>>() {}
4950
really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
5051

51-
really_inline Mask operator==(const simd8<T> other) const { return _mm256_cmpeq_epi8(*this, other); }
52+
really_inline Mask operator==(const simd8<T>& other) const { return _mm256_cmpeq_epi8(*this, other); }
5253

5354
static const int SIZE = sizeof(base<T>::value);
5455

5556
template<int N=1>
56-
really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
57+
really_inline simd8<T> prev(const simd8<T>& prev_chunk) const {
5758
return _mm256_alignr_epi8(*this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
5859
}
5960
};
@@ -224,6 +225,7 @@ namespace simd {
224225
template<>
225226
struct simd8<uint8_t>: base8_numeric<uint8_t> {
226227
really_inline simd8() : base8_numeric<uint8_t>() {}
228+
227229
really_inline simd8(const __m256i _value) : base8_numeric<uint8_t>(_value) {}
228230
// Splat constructor
229231
really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
@@ -255,31 +257,31 @@ namespace simd {
255257
}
256258

257259
// Saturated math
258-
really_inline simd8<uint8_t> saturating_add(const simd8<uint8_t> other) const { return _mm256_adds_epu8(*this, other); }
259-
really_inline simd8<uint8_t> saturating_sub(const simd8<uint8_t> other) const { return _mm256_subs_epu8(*this, other); }
260+
really_inline simd8<uint8_t> saturating_add(const simd8<uint8_t>& other) const { return _mm256_adds_epu8(*this, other); }
261+
really_inline simd8<uint8_t> saturating_sub(const simd8<uint8_t>& other) const { return _mm256_subs_epu8(*this, other); }
260262

261263
// Order-specific operations
262-
really_inline simd8<uint8_t> max(const simd8<uint8_t> other) const { return _mm256_max_epu8(*this, other); }
263-
really_inline simd8<uint8_t> min(const simd8<uint8_t> other) const { return _mm256_min_epu8(other, *this); }
264+
really_inline simd8<uint8_t> max(const simd8<uint8_t>& other) const { return _mm256_max_epu8(*this, other); }
265+
really_inline simd8<uint8_t> min(const simd8<uint8_t>& other) const { return _mm256_min_epu8(other, *this); }
264266
// Same as >, but only guarantees true is nonzero (< guarantees true = -1)
265-
really_inline simd8<uint8_t> gt_bits(const simd8<uint8_t> other) const { return this->saturating_sub(other); }
267+
really_inline simd8<uint8_t> gt_bits(const simd8<uint8_t>& other) const { return this->saturating_sub(other); }
266268
// Same as <, but only guarantees true is nonzero (< guarantees true = -1)
267-
really_inline simd8<uint8_t> lt_bits(const simd8<uint8_t> other) const { return other.saturating_sub(*this); }
268-
really_inline simd8<bool> operator<=(const simd8<uint8_t> other) const { return other.max(*this) == other; }
269-
really_inline simd8<bool> operator>=(const simd8<uint8_t> other) const { return other.min(*this) == other; }
270-
really_inline simd8<bool> operator>(const simd8<uint8_t> other) const { return this->gt_bits(other).any_bits_set(); }
271-
really_inline simd8<bool> operator<(const simd8<uint8_t> other) const { return this->lt_bits(other).any_bits_set(); }
269+
really_inline simd8<uint8_t> lt_bits(const simd8<uint8_t>& other) const { return other.saturating_sub(*this); }
270+
really_inline simd8<bool> operator<=(const simd8<uint8_t>& other) const { return other.max(*this) == other; }
271+
really_inline simd8<bool> operator>=(const simd8<uint8_t>& other) const { return other.min(*this) == other; }
272+
really_inline simd8<bool> operator>(const simd8<uint8_t>& other) const { return this->gt_bits(other).any_bits_set(); }
273+
really_inline simd8<bool> operator<(const simd8<uint8_t>& other) const { return this->lt_bits(other).any_bits_set(); }
272274

273275
// Bit-specific operations
274276
really_inline simd8<bool> bits_not_set() const { return *this == uint8_t(0); }
275-
really_inline simd8<bool> bits_not_set(simd8<uint8_t> bits) const { return (*this & bits).bits_not_set(); }
277+
really_inline simd8<bool> bits_not_set(simd8<uint8_t>& bits) const { return (*this & bits).bits_not_set(); }
276278
really_inline simd8<bool> any_bits_set() const { return ~this->bits_not_set(); }
277-
really_inline simd8<bool> any_bits_set(simd8<uint8_t> bits) const { return ~this->bits_not_set(bits); }
279+
really_inline simd8<bool> any_bits_set(simd8<uint8_t>& bits) const { return ~this->bits_not_set(bits); }
278280
really_inline bool is_ascii() const { return _mm256_movemask_epi8(*this) == 0; }
279281
really_inline bool bits_not_set_anywhere() const { return _mm256_testz_si256(*this, *this); }
280282
really_inline bool any_bits_set_anywhere() const { return !bits_not_set_anywhere(); }
281-
really_inline bool bits_not_set_anywhere(simd8<uint8_t> bits) const { return _mm256_testz_si256(*this, bits); }
282-
really_inline bool any_bits_set_anywhere(simd8<uint8_t> bits) const { return !bits_not_set_anywhere(bits); }
283+
really_inline bool bits_not_set_anywhere(simd8<uint8_t>& bits) const { return _mm256_testz_si256(*this, bits); }
284+
really_inline bool any_bits_set_anywhere(simd8<uint8_t>& bits) const { return !bits_not_set_anywhere(bits); }
283285
template<int N>
284286
really_inline simd8<uint8_t> shr() const { return simd8<uint8_t>(_mm256_srli_epi16(*this, N)) & uint8_t(0xFFu >> N); }
285287
template<int N>
@@ -297,7 +299,7 @@ namespace simd {
297299
const simd8<T> chunks[NUM_CHUNKS];
298300

299301
simd8x64(const simd8x64<T>& o) = delete; // no copy allowed
300-
simd8x64<T>& operator=(const simd8<T> other) = delete; // no assignment allowed
302+
simd8x64<T>& operator=(const simd8<T>& other) = delete; // no assignment allowed
301303
simd8x64() = delete; // no default constructor allowed
302304

303305
really_inline simd8x64(const simd8<T> chunk0, const simd8<T> chunk1) : chunks{chunk0, chunk1} {}

0 commit comments

Comments
 (0)