Skip to content

Clean up U8TO*_LE macro implementations #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Clean up U8TO*_LE macro implementations #8

wants to merge 1 commit into from

Conversation

mattst88
Copy link

@mattst88 mattst88 commented Nov 4, 2019

The code guarded by #ifndef U32_ALIGNMENT_REQUIRED attempts to optimize
byte-swapping by doing unaligned loads, but accessing data through
unaligned pointers is undefined behavior in C. Moreover, compilers are
more than capable of recognizing these open-coded byte-swap patterns and
emitting a bswap instruction, or an unaligned load instruction, or a
combined load, etc. There's no need for multiple paths to attain the
desired result.

The same commit went into perl in commit e8864dba8095 but with a typo in
U8TO64_LE. See Perl/perl5#17249

See https://rt.perl.org/Ticket/Display.html?id=133495
See Perl/perl5#17244

@demerphq
Copy link
Owner

demerphq commented Nov 5, 2019 via email

The code guarded by #ifndef U32_ALIGNMENT_REQUIRED attempts to optimize
byte-swapping by doing unaligned loads, but accessing data through
unaligned pointers is undefined behavior in C. Moreover, compilers are
more than capable of recognizing these open-coded byte-swap patterns and
emitting a bswap instruction, or an unaligned load instruction, or a
combined load, etc. There's no need for multiple paths to attain the
desired result.

The same commit went into perl in commit e8864dba8095 but with some
embarrassing bugs.

See https://rt.perl.org/Ticket/Display.html?id=133495
See Perl/perl5#17244
@mattst88
Copy link
Author

mattst88 commented Nov 5, 2019

Ugh. Thank you for the review. I've corrected the patch now.

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.

2 participants