Skip to content

Commit

Permalink
Fix c-blosc2 for universal2 build
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Dec 14, 2022
1 parent 1f9a9e8 commit 03ec768
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 62 deletions.
7 changes: 4 additions & 3 deletions src/c-blosc2/blosc/bitshuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
#include "bitshuffle-altivec.h"

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if !defined(__ALTIVEC__)
#error ALTIVEC is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__ALTIVEC__)

#include <altivec.h>
#include "transpose-altivec.h"

Expand Down Expand Up @@ -590,3 +589,5 @@ int64_t bshuf_untrans_bit_elem_altivec(void* in, void* out, const size_t size,

return count;
}

#endif /* defined(__ALTIVEC__) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/bitshuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@


/* Make sure AVX2 is available for the compilation target and compiler. */
#if !defined(__AVX2__)
#error AVX2 is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__AVX2__)

#include <immintrin.h>

Expand Down Expand Up @@ -255,3 +253,5 @@ int64_t bshuf_untrans_bit_elem_avx2(void* in, void* out, const size_t size,

return count;
}

#endif /* defined(__AVX2__) */
8 changes: 4 additions & 4 deletions src/c-blosc2/blosc/bitshuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "bitshuffle-neon.h"

/* Make sure NEON is available for the compilation target and compiler. */
#if !defined(__ARM_NEON)
#error NEON is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__ARM_NEON)

#include <arm_neon.h>

Expand Down Expand Up @@ -1000,6 +998,8 @@ bitunshuffle_neon(void* _src, void* _dest, const size_t size,
so we're done processing here. */
return count;
}

return (int64_t)size * (int64_t)elem_size;
}

#endif /* defined(__ARM_NEON) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/bitshuffle-sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include "bitshuffle-sse2.h"

/* Make sure SSE2 is available for the compilation target and compiler. */
#if !defined(__SSE2__)
#error SSE2 is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__SSE2__)

#include <emmintrin.h>

Expand Down Expand Up @@ -474,3 +472,5 @@ int64_t bshuf_untrans_bit_elem_sse2(void* in, void* out, const size_t size,

return count;
}

#endif /* defined(__SSE2__) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/shuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "shuffle-altivec.h"

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if !defined(__ALTIVEC__)
#error ALTIVEC is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__ALTIVEC__)

#include <altivec.h>
#include "transpose-altivec.h"
Expand Down Expand Up @@ -421,3 +419,5 @@ unshuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
unshuffle_generic_inline(bytesoftype, vectorizable_bytes, blocksize, _src, _dest);
}
}

#endif /* defined(__ALTIVEC__) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/shuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "shuffle-avx2.h"

/* Make sure AVX2 is available for the compilation target and compiler. */
#if !defined(__AVX2__)
#error AVX2 is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__AVX2__)

#include <immintrin.h>

Expand Down Expand Up @@ -745,3 +743,5 @@ unshuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
unshuffle_generic_inline(bytesoftype, vectorizable_bytes, blocksize, _src, _dest);
}
}

#endif /* defined(__AVX2__) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/shuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include "shuffle-neon.h"

/* Make sure NEON is available for the compilation target and compiler. */
#if !defined(__ARM_NEON)
#error NEON is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__ARM_NEON)

#include <arm_neon.h>

Expand Down Expand Up @@ -414,3 +412,5 @@ unshuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
unshuffle_generic_inline(bytesoftype, vectorizable_bytes, blocksize, _src, _dest);
}
}

#endif /* defined(__ARM_NEON) */
6 changes: 3 additions & 3 deletions src/c-blosc2/blosc/shuffle-sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "shuffle-sse2.h"

/* Make sure SSE2 is available for the compilation target and compiler. */
#if !defined(__SSE2__)
#error SSE2 is not supported by the target architecture/platform and/or this compiler.
#endif
#if defined(__SSE2__)

#include <emmintrin.h>

Expand Down Expand Up @@ -615,3 +613,5 @@ unshuffle_sse2(const int32_t bytesoftype, const int32_t blocksize,
unshuffle_generic_inline(bytesoftype, vectorizable_bytes, blocksize, _src, _dest);
}
}

#endif /* defined(__SSE2__) */
42 changes: 21 additions & 21 deletions src/c-blosc2/blosc/shuffle.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
/* Include hardware-accelerated shuffle/unshuffle routines based on
the target architecture. Note that a target architecture may support
more than one type of acceleration!*/
#if defined(SHUFFLE_AVX2_ENABLED)
#if defined(SHUFFLE_USE_AVX2)
#include "shuffle-avx2.h"
#include "bitshuffle-avx2.h"
#endif /* defined(SHUFFLE_AVX2_ENABLED) */
#endif /* defined(SHUFFLE_USE_AVX2) */

#if defined(SHUFFLE_SSE2_ENABLED)
#if defined(SHUFFLE_USE_SSE2)
#include "shuffle-sse2.h"
#include "bitshuffle-sse2.h"
#endif /* defined(SHUFFLE_SSE2_ENABLED) */
#endif /* defined(SHUFFLE_USE_SSE2) */

#if defined(SHUFFLE_NEON_ENABLED)
#if defined(SHUFFLE_USE_NEON)
#if defined(__linux__)
#include <sys/auxv.h>
#ifdef ARM_ASM_HWCAP
Expand All @@ -44,12 +44,12 @@
#endif
#include "shuffle-neon.h"
#include "bitshuffle-neon.h"
#endif /* defined(SHUFFLE_NEON_ENABLED) */
#endif /* defined(SHUFFLE_USE_NEON) */

#if defined(SHUFFLE_ALTIVEC_ENABLED)
#if defined(SHUFFLE_USE_ALTIVEC)
#include "shuffle-altivec.h"
#include "bitshuffle-altivec.h"
#endif /* defined(SHUFFLE_ALTIVEC_ENABLED) */
#endif /* defined(SHUFFLE_USE_ALTIVEC) */


/* Define function pointer types for shuffle/unshuffle routines. */
Expand Down Expand Up @@ -84,7 +84,7 @@ typedef enum {

/* Detect hardware and set function pointers to the best shuffle/unshuffle
implementations supported by the host processor. */
#if defined(SHUFFLE_AVX2_ENABLED) || defined(SHUFFLE_SSE2_ENABLED) /* Intel/i686 */
#if defined(SHUFFLE_USE_AVX2) || defined(SHUFFLE_USE_SSE2) /* Intel/i686 */

/* Disabled the __builtin_cpu_supports() call, as it has issues with
new versions of gcc (like 5.3.1 in forthcoming ubuntu/xenial:
Expand Down Expand Up @@ -141,7 +141,7 @@ __cpuidex(int32_t cpuInfo[4], int32_t function_id, int32_t subfunction_id) {

// GCC folks added _xgetbv in immintrin.h starting in GCC 9
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71659
#if !(defined(_IMMINTRIN_H_INCLUDED) && (BLOSC_GCC_VERSION >= 900))
#if !(defined(__clang__)) && !(defined(_IMMINTRIN_H_INCLUDED) && (BLOSC_GCC_VERSION >= 900))
/* Reads the content of an extended control register.
https://software.intel.com/en-us/articles/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family
*/
Expand Down Expand Up @@ -250,7 +250,7 @@ static blosc_cpu_features blosc_get_cpu_features(void) {
}
#endif /* HAVE_CPU_FEAT_INTRIN */

#elif defined(SHUFFLE_NEON_ENABLED) /* ARM-NEON */
#elif defined(SHUFFLE_USE_NEON) /* ARM-NEON */
static blosc_cpu_features blosc_get_cpu_features(void) {
blosc_cpu_features cpu_features = BLOSC_HAVE_NOTHING;
#if defined(__aarch64__)
Expand All @@ -263,7 +263,7 @@ static blosc_cpu_features blosc_get_cpu_features(void) {
#endif
return cpu_features;
}
#elif defined(SHUFFLE_ALTIVEC_ENABLED) /* POWER9-ALTIVEC preliminary test*/
#elif defined(SHUFFLE_USE_ALTIVEC) /* POWER9-ALTIVEC preliminary test*/
static blosc_cpu_features blosc_get_cpu_features(void) {
blosc_cpu_features cpu_features = BLOSC_HAVE_NOTHING;
cpu_features |= BLOSC_HAVE_ALTIVEC;
Expand All @@ -280,11 +280,11 @@ static blosc_cpu_features blosc_get_cpu_features(void) {
return BLOSC_HAVE_NOTHING;
}

#endif /* defined(SHUFFLE_AVX2_ENABLED) || defined(SHUFFLE_SSE2_ENABLED) */
#endif /* defined(SHUFFLE_USE_AVX2) || defined(SHUFFLE_USE_SSE2) */

static shuffle_implementation_t get_shuffle_implementation(void) {
blosc_cpu_features cpu_features = blosc_get_cpu_features();
#if defined(SHUFFLE_AVX2_ENABLED)
#if defined(SHUFFLE_USE_AVX2)
if (cpu_features & BLOSC_HAVE_AVX2) {
shuffle_implementation_t impl_avx2;
impl_avx2.name = "avx2";
Expand All @@ -294,9 +294,9 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
impl_avx2.bitunshuffle = (bitunshuffle_func)bshuf_untrans_bit_elem_avx2;
return impl_avx2;
}
#endif /* defined(SHUFFLE_AVX2_ENABLED) */
#endif /* defined(SHUFFLE_USE_AVX2) */

#if defined(SHUFFLE_SSE2_ENABLED)
#if defined(SHUFFLE_USE_SSE2)
if (cpu_features & BLOSC_HAVE_SSE2) {
shuffle_implementation_t impl_sse2;
impl_sse2.name = "sse2";
Expand All @@ -306,9 +306,9 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
impl_sse2.bitunshuffle = (bitunshuffle_func)bshuf_untrans_bit_elem_sse2;
return impl_sse2;
}
#endif /* defined(SHUFFLE_SSE2_ENABLED) */
#endif /* defined(SHUFFLE_USE_SSE2) */

#if defined(SHUFFLE_NEON_ENABLED)
#if defined(SHUFFLE_USE_NEON)
if (cpu_features & BLOSC_HAVE_NEON) {
shuffle_implementation_t impl_neon;
impl_neon.name = "neon";
Expand All @@ -326,9 +326,9 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
impl_neon.bitunshuffle = (bitunshuffle_func)bshuf_untrans_bit_elem_scal;
return impl_neon;
}
#endif /* defined(SHUFFLE_NEON_ENABLED) */
#endif /* defined(SHUFFLE_USE_NEON) */

#if defined(SHUFFLE_ALTIVEC_ENABLED)
#if defined(SHUFFLE_USE_ALTIVEC)
if (cpu_features & BLOSC_HAVE_ALTIVEC) {
shuffle_implementation_t impl_altivec;
impl_altivec.name = "altivec";
Expand All @@ -338,7 +338,7 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
impl_altivec.bitunshuffle = (bitunshuffle_func)bshuf_untrans_bit_elem_altivec;
return impl_altivec;
}
#endif /* defined(SHUFFLE_ALTIVEC_ENABLED) */
#endif /* defined(SHUFFLE_USE_ALTIVEC) */

/* Processor doesn't support any of the hardware-accelerated implementations,
so use the generic implementation. */
Expand Down
19 changes: 19 additions & 0 deletions src/c-blosc2/blosc/shuffle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@

#include "blosc2/blosc2-common.h"

/* Toggle hardware-accelerated routines based on SHUFFLE_*_ENABLED macros
and availability on the target architecture.
*/
#if defined(SHUFFLE_AVX2_ENABLED) && defined(__AVX2__)
#define SHUFFLE_USE_AVX2
#endif

#if defined(SHUFFLE_SSE2_ENABLED) && defined(__SSE2__)
#define SHUFFLE_USE_SSE2
#endif

#if defined(SHUFFLE_ALTIVEC_ENABLED) && defined(__ALTIVEC__)
#define SHUFFLE_USE_ALTIVEC
#endif

#if defined(SHUFFLE_NEON_ENABLED) && defined(__ARM_NEON)
#define SHUFFLE_USE_NEON
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/c-blosc2/tests/test_shuffle_roundtrip_altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@

/* Include ALTIVEC-accelerated shuffle implementation if supported by this compiler.
TODO: Need to also do run-time CPU feature support here. */
#if defined(SHUFFLE_ALTIVEC_ENABLED)
#if defined(SHUFFLE_USE_ALTIVEC)
#include "../blosc/shuffle-altivec.h"
#else
#if defined(_MSC_VER)
#pragma message("ALTIVEC shuffle tests not enabled.")
#else
#warning ALTIVEC shuffle tests not enabled.
#endif
#endif /* defined(SHUFFLE_ALTIVEC_ENABLED) */
#endif /* defined(SHUFFLE_USE_ALTIVEC) */


/** Roundtrip tests for the ALTIVEC-accelerated shuffle/unshuffle. */
static int test_shuffle_roundtrip_altivec(int32_t type_size, int32_t num_elements,
size_t buffer_alignment, int test_type) {
#if defined(SHUFFLE_ALTIVEC_ENABLED)
#if defined(SHUFFLE_USE_ALTIVEC)
int32_t buffer_size = type_size * num_elements;

/* Allocate memory for the test. */
Expand Down Expand Up @@ -77,7 +77,7 @@ static int test_shuffle_roundtrip_altivec(int32_t type_size, int32_t num_element
return exit_code;
#else
return EXIT_SUCCESS;
#endif /* defined(SHUFFLE_ALTIVEC_ENABLED) */
#endif /* defined(SHUFFLE_USE_ALTIVEC) */
}


Expand Down
8 changes: 4 additions & 4 deletions src/c-blosc2/tests/test_shuffle_roundtrip_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
/* Include accelerated shuffles if supported by this compiler.
TODO: Need to also do run-time CPU feature support here. */

#if defined(SHUFFLE_AVX2_ENABLED)
#if defined(SHUFFLE_USE_AVX2)
#include "../blosc/shuffle-avx2.h"
#else
#if defined(_MSC_VER)
#pragma message("AVX2 shuffle tests not enabled.")
#else
#warning AVX2 shuffle tests not enabled.
#endif
#endif /* defined(SHUFFLE_AVX2_ENABLED) */
#endif /* defined(SHUFFLE_USE_AVX2) */


/** Roundtrip tests for the AVX2-accelerated shuffle/unshuffle. */
static int test_shuffle_roundtrip_avx2(int32_t type_size, int32_t num_elements,
size_t buffer_alignment, int test_type) {
#if defined(SHUFFLE_AVX2_ENABLED)
#if defined(SHUFFLE_USE_AVX2)
int32_t buffer_size = type_size * num_elements;

/* Allocate memory for the test. */
Expand Down Expand Up @@ -78,7 +78,7 @@ static int test_shuffle_roundtrip_avx2(int32_t type_size, int32_t num_elements,
return exit_code;
#else
return EXIT_SUCCESS;
#endif /* defined(SHUFFLE_AVX2_ENABLED) */
#endif /* defined(SHUFFLE_USE_AVX2) */
}


Expand Down

0 comments on commit 03ec768

Please sign in to comment.