Fix Makefile to generate a platform-independent binary
This commit is contained in:
parent
0df5e90422
commit
695af1b189
3
Makefile
3
Makefile
|
@ -49,7 +49,8 @@ $(SNAPPY_OUT)/%.o : $(BITSHUFFLE_SRC_DIR)/%.c
|
|||
|
||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) $(patsubst %.c,%.o,$(BITSHUFFLE_C)) SnappyNative.o)
|
||||
|
||||
CXXFLAGS:=$(CXXFLAGS) -DSNAPPY_BITSHUFFLE_ENABLED -I$(SNAPPY_SRC_DIR) -I$(BITSHUFFLE_SRC_DIR)
|
||||
# Undefined macros for sse2/avx2 to generate a platform-independent binary
|
||||
CXXFLAGS:=$(CXXFLAGS) -U__AVX2__ -U__SSE2__ -I$(SNAPPY_SRC_DIR) -I$(BITSHUFFLE_SRC_DIR)
|
||||
|
||||
ifeq ($(OS_NAME),SunOS)
|
||||
TAR:= gtar
|
||||
|
|
|
@ -51,11 +51,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static byte[] bitShuffle(short[] input) throws IOException {
|
||||
byte[] output = new byte[input.length * 2];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitShuffle(input, 0, 2, input.length * 2, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length * 2, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitShuffle(input, 0, 2, input.length * 2, output, 0);
|
||||
assert(numProcessed == input.length * 2);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -68,11 +65,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static byte[] bitShuffle(int[] input) throws IOException {
|
||||
byte[] output = new byte[input.length * 4];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitShuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length * 4, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitShuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
assert(numProcessed == input.length * 4);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -85,11 +79,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static byte[] bitShuffle(long[] input) throws IOException {
|
||||
byte[] output = new byte[input.length * 8];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitShuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length * 8, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitShuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
assert(numProcessed == input.length * 8);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -102,11 +93,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static byte[] bitShuffle(float[] input) throws IOException {
|
||||
byte[] output = new byte[input.length * 4];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitShuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length * 4, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitShuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
assert(numProcessed == input.length * 4);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -119,11 +107,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static byte[] bitShuffle(double[] input) throws IOException {
|
||||
byte[] output = new byte[input.length * 8];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitShuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length * 8, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitShuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
assert(numProcessed == input.length * 8);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -136,11 +121,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static short[] bitUnShuffleShortArray(byte[] input) throws IOException {
|
||||
short[] output = new short[input.length / 2];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitUnShuffle(input, 0, 2, input.length, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitUnShuffle(input, 0, 2, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -153,11 +135,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static int[] bitUnShuffleIntArray(byte[] input) throws IOException {
|
||||
int[] output = new int[input.length / 4];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitUnShuffle(input, 0, 4, input.length, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitUnShuffle(input, 0, 4, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -170,11 +149,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static long[] bitUnShuffleLongArray(byte[] input) throws IOException {
|
||||
long[] output = new long[input.length / 8];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitUnShuffle(input, 0, 8, input.length, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitUnShuffle(input, 0, 8, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -187,11 +163,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static float[] bitUnShuffleFloatArray(byte[] input) throws IOException {
|
||||
float[] output = new float[input.length / 4];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitUnShuffle(input, 0, 4, input.length, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitUnShuffle(input, 0, 4, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -204,11 +177,8 @@ public class BitShuffle
|
|||
*/
|
||||
public static double[] bitUnShuffleDoubleArray(byte[] input) throws IOException {
|
||||
double[] output = new double[input.length / 8];
|
||||
if (impl.supportBitSuffle()) {
|
||||
impl.bitUnShuffle(input, 0, 8, input.length, output, 0);
|
||||
} else {
|
||||
Snappy.arrayCopy(input, 0, input.length, output, 0);
|
||||
}
|
||||
int numProcessed = impl.bitUnShuffle(input, 0, 8, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,6 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: supportBitSuffle
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_BitShuffleNative_supportBitSuffle
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: bitShuffle
|
||||
|
|
|
@ -45,11 +45,6 @@ public class BitShuffleNative
|
|||
// A quick benchmark result can be found in a gist below;
|
||||
// https://gist.github.com/maropu/01103215df34b317a7a7
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Returns true iff a native library loaded in JVMs can run bit-shuffling.
|
||||
// Bit-shuffling is executable only in x86 environments that support SSE/AVX instructions.
|
||||
public native boolean supportBitSuffle();
|
||||
|
||||
public native int bitShuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
|
|
|
@ -15,15 +15,13 @@
|
|||
*--------------------------------------------------------------------------*/
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include <snappy.h>
|
||||
#include <bitshuffle.h>
|
||||
|
||||
#include "SnappyNative.h"
|
||||
#include "BitShuffleNative.h"
|
||||
|
||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||
#include <bitshuffle.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
||||
{
|
||||
jclass c = env->FindClass("org/xerial/snappy/SnappyNative");
|
||||
|
@ -302,20 +300,6 @@ JNIEXPORT void JNICALL Java_org_xerial_snappy_SnappyNative_arrayCopy
|
|||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_SnappyNative
|
||||
* Method: supportBitSuffle
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_BitShuffleNative_supportBitSuffle
|
||||
(JNIEnv *, jobject) {
|
||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||
return (jboolean) true;
|
||||
#else
|
||||
return (jboolean) false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_SnappyNative
|
||||
* Method: bitShuffle
|
||||
|
@ -324,7 +308,6 @@ JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_BitShuffleNative_supportBitSuf
|
|||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitShuffle
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
|
@ -346,11 +329,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitShuffle
|
|||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
#else
|
||||
// Returns an error code for unsupported operations
|
||||
throw_exception(env, self, 1);
|
||||
return (jint) 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -361,7 +339,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitShuffle
|
|||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitUnShuffle
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
|
@ -383,10 +360,5 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitUnShuffle
|
|||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
#else
|
||||
// Returns an error code for unsupported operations
|
||||
throw_exception(env, self, 1);
|
||||
return (jint) 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue