Skip to content

Commit

Permalink
Add stubs and runtime checks for ALTIVEC shuffle/bitshuffle implement…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
t20100 committed Jul 3, 2024
1 parent 9afb7b9 commit a7fdcef
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 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: 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
4 changes: 2 additions & 2 deletions blosc/shuffle.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
#endif /* defined(SHUFFLE_SSE2_ENABLED) */

#if defined(SHUFFLE_NEON_ENABLED)
if (cpu_features & BLOSC_HAVE_NEON && is_shuffle_neon) { // && is_bshuf_NEON is using NEON bitshuffle
if (cpu_features & BLOSC_HAVE_NEON && is_shuffle_neon) { // && is_bshuf_NEON if using NEON bitshuffle
shuffle_implementation_t impl_neon;
impl_neon.name = "neon";
impl_neon.shuffle = (shuffle_func)shuffle_neon;
Expand All @@ -351,7 +351,7 @@ static shuffle_implementation_t get_shuffle_implementation(void) {
#endif /* defined(SHUFFLE_NEON_ENABLED) */

#if defined(SHUFFLE_ALTIVEC_ENABLED)
if (cpu_features & BLOSC_HAVE_ALTIVEC) {
if (cpu_features & BLOSC_HAVE_ALTIVEC && is_shuffle_altivec && is_bshuf_altivec) {
shuffle_implementation_t impl_altivec;
impl_altivec.name = "altivec";
impl_altivec.shuffle = (shuffle_func)shuffle_altivec;
Expand Down

0 comments on commit a7fdcef

Please sign in to comment.