Skip to content
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

Question about WITH_UNALIGNED #1652

Open
FantasqueX opened this issue Jan 27, 2024 · 2 comments
Open

Question about WITH_UNALIGNED #1652

FantasqueX opened this issue Jan 27, 2024 · 2 comments
Labels

Comments

@FantasqueX
Copy link
Contributor

Hi, I have some questions about WITH_UNALIGNED. I use ArchLinux as my daily distro. When I took a look at zlib-ng build options used by ArchLinux, I found something strange. https://gitlab.archlinux.org/archlinux/packaging/packages/zlib-ng/-/blob/main/PKGBUILD?ref_type=heads#L37 ArchLinux disables WITH_UNALIGNED explicitly. After reading the blog listed in comments, I realized converting pointers in general (except for converting anything to char *) is a dangerous business while using memcpy is quite safe. After looking through zlib-ng code. I found three places about UNALIGNED_OK, which are CHUNKMEMSET_SAFE, compare256_rle_unaligned and LONGEST_MATCH. Both compare256_rle_unaligned and LONGEST_MATCH use memcpy, however I'm not sure about CHUNKMEMSET_SAFE. So, I opened this issue to confirm the safety with -DWITH_UNALIGNED=ON. If so, I'll discuss this issue with ArchLinux package manager. Thanks in advance.

@KungFuJesus
Copy link
Contributor

KungFuJesus commented Jan 27, 2024

CHUNKMEMSET_SAFE does byte at a time copies up until an alignment is meant or if the remaining len in the buffer is less than 3x whatever size a "chunk" is defined to be for a given vectorization. Other it dispatches to chunkmemset post alignment for the remaining bytes, where vector intrinsics are used that have well defined semantics for loading things arbitrarily aligned.

@ccawley2011
Copy link
Contributor

If CHUNKMEMSET_SAFE ensures that the initial output pointer is aligned before CHUNKMEMSET is called, is it also guaranteed to be aligned when CHUNKMEMSET is called directly from INFLATE_FAST?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants