Skip to content

Uncomment happy path for ASCII validation and fix big-endian issues - #445

Merged
Bodigrim merged 2 commits into
haskell:masterfrom
Bodigrim:happy-ascii
Dec 6, 2021
Merged

Bodigrim merged 2 commits into
haskell:masterfrom
Bodigrim:happy-ascii

Conversation

@Bodigrim

@Bodigrim Bodigrim commented Dec 4, 2021

Copy link
Copy Markdown
Contributor

As discussed in #423 (comment), this code appeared problematic on big-endian platforms and was commented out:

uint64_t results[4] = {(*big_ptr) & high_bits_mask,
(*(big_ptr + 1)) & high_bits_mask,
(*(big_ptr + 2)) & high_bits_mask,
(*(big_ptr + 3)) & high_bits_mask};
if (results[0] == 0) {
ptr += 8;
if (results[1] == 0) {
ptr += 8;
if (results[2] == 0) {
ptr += 8;
if (results[3] == 0) {
ptr += 8;
} else {
ptr += (__builtin_ctzl(results[3]) / 8);
}
} else {
ptr += (__builtin_ctzl(results[2]) / 8);
}
} else {
ptr += (__builtin_ctzl(results[1]) / 8);
}
} else {
ptr += (__builtin_ctzl(results[0]) / 8);
}
}

This PR fixes it for big-endian platforms and uncomments this code. It is tested by CI jobs: i386, arm32 and ppc64le on behalf of little-endian systems without vectorized instructions and s390x on behalf of big-endian systems.

CC @vdukhovni @kozross

@Bodigrim
Bodigrim requested a review from sjakobi December 4, 2021 01:07
@Bodigrim Bodigrim added this to the 0.11.2.0 milestone Dec 4, 2021
@Bodigrim Bodigrim linked an issue Dec 4, 2021 that may be closed by this pull request
@kozross

kozross commented Dec 4, 2021

Copy link
Copy Markdown
Contributor

Looks good to me.

@Bodigrim Bodigrim mentioned this pull request Dec 4, 2021
@Bodigrim

Bodigrim commented Dec 6, 2021

Copy link
Copy Markdown
Contributor Author

There are two instances of this code, so fixing in both. It is not strictly necessary, because the second instance is x86/x64 only, which is never big-endian, but better to keep both in line.

@Bodigrim
Bodigrim merged commit 12303b8 into haskell:master Dec 6, 2021
@Bodigrim
Bodigrim deleted the happy-ascii branch December 6, 2021 20:40
Bodigrim added a commit to Bodigrim/bytestring that referenced this pull request Dec 7, 2021
…askell#445)

* Uncomment happy path for ASCII validation and fix big-endian issues

* Same in another instance of bytestring_is_valid_utf8
noughtmare pushed a commit to noughtmare/bytestring that referenced this pull request Dec 12, 2021
…askell#445)

* Uncomment happy path for ASCII validation and fix big-endian issues

* Same in another instance of bytestring_is_valid_utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide isValidUtf8 function

3 participants