Skip to content

Commit

Permalink
Merge pull request #1 from t20100/shuffle-flags
Browse files Browse the repository at this point in the history
Add runtime checks for use of SIMD implementations and stubs functions if not available.
  • Loading branch information
mgorny authored Jul 3, 2024
2 parents 73b1225 + a0c0b88 commit ce42731
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 15 deletions.
23 changes: 21 additions & 2 deletions blosc/bitshuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "bitshuffle-altivec.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8)
Expand All @@ -33,7 +34,6 @@
#include <altivec.h>

#include <stdint.h>
#include <stdlib.h>

/* The next is useful for debugging purposes */
#if 0
Expand Down Expand Up @@ -592,4 +592,23 @@ int64_t bshuf_untrans_bit_elem_altivec(const void* in, void* out, const size_t s
return count;
}

#endif /* defined(__ALTIVEC__) */

const bool is_bshuf_altivec = true;

#else /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */

const bool is_bshuf_altivec = false;

int64_t
bshuf_trans_bit_elem_altivec(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_altivec(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* ALTIVEC-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_altivec;

BLOSC_NO_EXPORT int64_t
bshuf_trans_byte_elem_altivec(const void* in, void* out, const size_t size,
Expand Down
19 changes: 19 additions & 0 deletions blosc/bitshuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "bitshuffle-avx2.h"
#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure AVX2 is available for the compilation target and compiler. */
#if defined(__AVX2__)
Expand Down Expand Up @@ -262,4 +263,22 @@ int64_t bshuf_untrans_bit_elem_AVX(const void* in, void* out, const size_t size,
return count;
}

const bool is_bshuf_AVX = true;

#else /* defined(__AVX2__) */

const bool is_bshuf_AVX = false;

int64_t
bshuf_trans_bit_elem_AVX(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_AVX(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__AVX2__) */
7 changes: 7 additions & 0 deletions blosc/bitshuffle-avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* AVX2-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_AVX;


/**
* AVX2-accelerated bitshuffle routine.
Expand Down
28 changes: 24 additions & 4 deletions blosc/bitshuffle-avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
rights to use.
**********************************************************************/

/* Make sure AVX512 is available for the compilation target and compiler. */
#if defined(__AVX512F__) && defined (__AVX512BW__)
#include <immintrin.h>
#include "bitshuffle-avx512.h"
#include "bitshuffle-avx2.h"
#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure AVX512 is available for the compilation target and compiler. */
#if defined(__AVX512F__) && defined (__AVX512BW__)
#include <immintrin.h>


/* Transpose bits within bytes. */
Expand Down Expand Up @@ -158,4 +160,22 @@ int64_t bshuf_untrans_bit_elem_AVX512(const void* in, void* out, const size_t si
return count;
}

#endif
const bool is_bshuf_AVX512 = true;

#else /* defined(__AVX512F__) && defined (__AVX512BW__) */

const bool is_bshuf_AVX512 = false;

int64_t
bshuf_trans_bit_elem_AVX512(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_AVX512(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__AVX512F__) && defined (__AVX512BW__) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-avx512.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* AVX512-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_AVX512;

BLOSC_NO_EXPORT int64_t
bshuf_trans_bit_elem_AVX512(const void* in, void* out, const size_t size,
Expand Down
18 changes: 17 additions & 1 deletion blosc/bitshuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

#include "bitshuffle-neon.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure NEON is available for the compilation target and compiler. */
#if defined(__ARM_NEON)

#include <arm_neon.h>

#include <stdlib.h>

/* The next is useful for debugging purposes */
#if 0
Expand Down Expand Up @@ -491,4 +491,20 @@ int64_t bshuf_untrans_bit_elem_NEON(const void* in, void* out, const size_t size
return count;
}

const bool is_bshuf_NEON = true;

#else /* defined(__ARM_NEON) */

const bool is_bshuf_NEON = false;

int64_t bshuf_trans_bit_elem_NEON(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t bshuf_untrans_bit_elem_NEON(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__ARM_NEON) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* NEON-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_NEON;

/**
NEON-accelerated bitshuffle routine.
Expand Down
18 changes: 18 additions & 0 deletions blosc/bitshuffle-sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "bitshuffle-sse2.h"
#include "bitshuffle-generic.h"
#include <stdlib.h>

/* Make sure SSE2 is available for the compilation target and compiler. */
#if defined(__SSE2__)
Expand Down Expand Up @@ -481,5 +482,22 @@ int64_t bshuf_untrans_bit_elem_SSE(const void* in, void* out, const size_t size,
return count;
}

const bool is_bshuf_SSE = true;

#else /* defined(__SSE2__) */

const bool is_bshuf_SSE = false;

int64_t
bshuf_trans_bit_elem_SSE(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

int64_t
bshuf_untrans_bit_elem_SSE(const void* in, void* out, const size_t size,
const size_t elem_size) {
abort();
}

#endif /* defined(__SSE2__) */
6 changes: 6 additions & 0 deletions blosc/bitshuffle-sse2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

/**
* SSE2-accelerated bit(un)shuffle routines availability.
*/
extern const bool is_bshuf_SSE;

BLOSC_NO_EXPORT int64_t
bshuf_trans_byte_elem_SSE(const void* in, void* out, const size_t size,
Expand Down
19 changes: 18 additions & 1 deletion blosc/shuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "shuffle-altivec.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure ALTIVEC is available for the compilation target and compiler. */
#if defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8)
Expand Down Expand Up @@ -423,4 +424,20 @@ unshuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
}
}

#endif /* defined(__ALTIVEC__) */
const bool is_shuffle_altivec = true;

#else /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */

const bool is_shuffle_altivec = false;

void shuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

void unshuffle_altivec(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__ALTIVEC__) && defined(__VSX__) && defined(_ARCH_PWR8) */
6 changes: 6 additions & 0 deletions blosc/shuffle-altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* ALTIVEC-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_altivec;

/**
ALTIVEC-accelerated shuffle routine.
Expand Down
18 changes: 17 additions & 1 deletion blosc/shuffle-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "shuffle-avx2.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure AVX2 is available for the compilation target and compiler. */
#if defined(__AVX2__)

#include <immintrin.h>

#include <stdlib.h>
#include <stdint.h>

/* The next is useful for debugging purposes */
Expand Down Expand Up @@ -746,4 +746,20 @@ unshuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
}
}

const bool is_shuffle_avx2 = true;

#else

const bool is_shuffle_avx2 = false;

void shuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

void unshuffle_avx2(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__AVX2__) */
6 changes: 6 additions & 0 deletions blosc/shuffle-avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* AVX2-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_avx2;

/**
AVX2-accelerated shuffle routine.
Expand Down
17 changes: 17 additions & 0 deletions blosc/shuffle-neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "shuffle-neon.h"
#include "shuffle-generic.h"
#include <stdlib.h>

/* Make sure NEON is available for the compilation target and compiler. */
#if defined(__ARM_NEON)
Expand Down Expand Up @@ -414,4 +415,20 @@ unshuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
}
}

const bool is_shuffle_neon = true;

#else /* defined(__ARM_NEON) */

const bool is_shuffle_neon = false;

void shuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* const _src, uint8_t* const _dest) {
abort();
}

void unshuffle_neon(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, uint8_t *_dest) {
abort();
}

#endif /* defined(__ARM_NEON) */
6 changes: 6 additions & 0 deletions blosc/shuffle-neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "blosc2/blosc2-common.h"

#include <stdint.h>
#include <stdbool.h>

/**
* NEON-accelerated (un)shuffle routines availability.
*/
extern const bool is_shuffle_neon;

/**
NEON-accelerated shuffle routine.
Expand Down
Loading

0 comments on commit ce42731

Please sign in to comment.