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

Mac and compatibility fixes #6

Closed
wants to merge 4 commits into from
Closed

Conversation

RJVB
Copy link

@RJVB RJVB commented May 26, 2017

These are my current fixes for getting zlib/CloudFlare to build on Mac and work as a real drop-in replacement:

  • build with clang
  • fix the crc32_pclmul assembly so it builds on Mac (NB: it will crash in 32bit mode, PCLMUL support has to be disabled some way!)
  • revert a change to the uInt and uLong types which broke building Qt and were probably dangerous anyway (several functions receive pointers to these types, and dependent software is not guaranteed to use the typedefs from zlib).

RJVB added 3 commits May 26, 2017 15:42
The change to double-width variables led to build Qt failures and possibly
out-of-bound writes with dependent software that passes pointers to the
traditional 16 or 32 bit  variables.
@vkrasnov
Copy link

vkrasnov commented Dec 3, 2017

@RJVB
Copy link
Author

RJVB commented Dec 3, 2017 via email

@neurolabusc
Copy link

It would be great to provide Mac compatibility. However, I think this patch assumes unsigned int is a 32-bit value. This might not be true for all 16 and 64 bit processors and compilers. Therefore, for backward compatibility I would have used the following code to ensure uint8_t, uint32_t, uint64_t are defined.

#ifndef uint32_t 
 #include <stdint.h>
#endif

@kornelski
Copy link

I don't see why this patch changes uint32_t. All macOS (not '90s Mac OS) compilers support <stdint.h> without any issues.

The ASM fix is needed.

@neurolabusc
Copy link

Precisely, if you look at the Files Changed you can see that deflate.c, zconf.h, zconf.h.cmakein, zconf.h.in modify the uint64_t, uint32_t, uint8_t references rather than simply including <stdint.h>. But with these modifications, it would be great to see this patch applied to provide MacOS users to have this accelerated library - the speedup is really impressive.

@RJVB
Copy link
Author

RJVB commented May 22, 2018 via email

@neurolabusc
Copy link

neurolabusc commented May 22, 2018

@RJVB - seems like a good point, this seems like a solution

#ifndef UINT32_MAX
#include <stdint.h>
#endif

Thanks for pointing out zlib-ng. Is that completely stable? I note a few outstanding issues and no stable release.

@RJVB
Copy link
Author

RJVB commented May 22, 2018 via email

@kornelski
Copy link

kornelski commented May 22, 2018

@RJVB Sparc64 has 64-bit int. The C standard allows arbitrarily large int.

<stdint.h> is guaranteed to be present in C99, and these days even MSVC supports that much.

@neurolabusc
Copy link

@RJVB : I have generated a new pull request that includes your fixes but uses <stdint.h> to define uint32_t etc if and only if needed.
I did a simple test on my late-2013 MacBook (Haswell, 2 core, 4 thread) with my sample neuroimaging datasets using the local SSD, normalized to default zlib, each using default compression ratio (with almost identical results, pigz creates files a tiny bit larger):
zlib x1.0
zlib-ng x1.45
zlib-cloudflare x2.0
pigz x2.33
In reality, pigz has a cost, as I must save the uncompressed data to disk prior to compressing with pigz, while my software (dcm2niix) can use the other tools to write the compressed data to disk (which is a big win for slow disk I/O, for example network drives). Since an individual run of fMRI data is often ~500mb uncompressed per file, this has real performance implications. I appreciate your comments that zlib-ng links to more recent zlib releases. But it is unclear if one must use compiler switches to achieve cloudflare performance or it simply is not as fast.

@@ -362,7 +362,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
CHECK_ERR(err, "inflateEnd");

if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
fprintf(stderr, "bad large inflate: %lld\n", d_stream.total_out);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to support gcc and clang have to use PRId64 from inttypes.h.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be happy with:

#include <stdint.h>
#include <inttypes.h>
...
fprintf(stderr, "bad large inflate: %10" PRId64 "\n", d_stream.total_out);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer simply % instead %10

@@ -528,9 +528,9 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
* upper bound of about 14% expansion does not seem onerous for output buffer
* allocation.
*/
uint64_t ZEXPORT deflateBound(strm, sourceLen)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really rather keep the uintN_t instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not used/required in the updated PR#11.

@LloydW93
Copy link
Member

As we took PR #8, and this is a stale/conflicting PR, I'm going to close it.

@LloydW93 LloydW93 closed this Sep 22, 2022
fhanau pushed a commit to fhanau/zlib that referenced this pull request Feb 27, 2023
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.

5 participants