jpeg2png icon indicating copy to clipboard operation
jpeg2png copied to clipboard

Compile using aligned_alloc() from Boost.

Open m000 opened this issue 4 years ago • 3 comments

Some minor modifications to compile when aligned_alloc() is not provided by the system libraries. A notable example of such systems are MacOS versions < 10.15. To resolve this, we link against Boost's implementation of aligned_alloc. A wrapper is used to link the Boost C++ library with the C code of jpeg2png. This behaviour is enabled by setting the BOOST build variable.

After this, jpeg2png can be compiled on MacOS < 10.15 using: CC=clang CXX=clang++ MACOS=1 BOOST=1 OPENMP=0 make (uses Boost aligned_alloc, and libjpeg from homebrew)

For MacOS >= 10.15, this should work: CC=clang CXX=clang++ MACOS=1 OPENMP=0 make (uses system's aligned_alloc, and libjpeg from homebrew)

m000 avatar Jul 19 '20 17:07 m000

macos has posix_memalign(), much better than dragging in boost just for this. boost isn't exactly something you want...

boost's aligned_alloc is just some tens of headers of complicated C++ that in the end just calls posix_memalign() on macos and other "posix" platforms (however it defines it).

edit: can you test this patch on macos? it should be identical to what boost ends up doing on macos etc.:

diff --git utils.h utils.h
  index 2116fef..e19d3b9 100644
  --- utils.h
  +++ utils.h
  @@ -89,10 +89,13 @@ static inline float sqf(float x) {
   static inline void *alloc_simd(size_t n) {
   #if defined(_WIN32)
           void *p = _aligned_malloc(n, 16);
  -#else
  -        void *p = aligned_alloc(16, n);
  -#endif
           if(!p) { die("allocation error"); }
  +#else
  +        void *p = NULL;
  +        if (posix_memalign(&p, 16, n) != 0) {
  +            die("aligned allocation error");
  +        }
  +#endif
           ASSUME_ALIGNED(p);
           return p;
   }

sandsmark avatar Jul 22 '20 13:07 sandsmark

@sandsmark Didn't know about posix_memalign() (didn't show up in any search :)). Will test and report back.

m000 avatar Jul 29 '20 08:07 m000

sorry for the less than cordial tone, btw, I just had some recent less-than-stellar run-ins with boost. :-)

but yeah, posix_memalign is what boost uses as well, so the behavior should be identical.

sandsmark avatar Aug 05 '20 14:08 sandsmark