@@ -3,6 +3,7 @@
|
||||
|
||||
#include <zlib.h>
|
||||
#include "shared.h"
|
||||
#include "cpuid_helper.h"
|
||||
#include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
@@ -26,6 +27,10 @@ jint throwException(JNIEnv *env, const char* message, int err) {
|
||||
return (*env)->Throw(env, throwable);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_checkSupported(JNIEnv* env, jobject obj) {
|
||||
return (jboolean) checkCompressionNativesSupport();
|
||||
}
|
||||
|
||||
void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_reset(JNIEnv* env, jobject obj, jlong ctx, jboolean compress) {
|
||||
z_stream* stream = (z_stream*) ctx;
|
||||
int ret = (compress) ? deflateReset(stream) : inflateReset(stream);
|
||||
|
22
native/src/main/c/cpuid_helper.h
Normal file
22
native/src/main/c/cpuid_helper.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// Header to check for SSE 4.2 support in compression natives
|
||||
// GCC only!
|
||||
|
||||
#ifndef _INCLUDE_CPUID_HELPER_H
|
||||
#define _INCLUDE_CPUID_HELPER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <cpuid.h>
|
||||
|
||||
static inline bool checkCompressionNativesSupport() {
|
||||
unsigned int eax;
|
||||
unsigned int ebx;
|
||||
unsigned int ecx;
|
||||
unsigned int edx;
|
||||
if(__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
|
||||
return (ecx & bit_PCLMUL) != 0 && (ecx & bit_SSE4_2) != 0;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _INCLUDE_CPUID_HELPER_H
|
@@ -15,6 +15,14 @@ extern "C" {
|
||||
JNIEXPORT void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_initFields
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: net_md_5_bungee_jni_zlib_NativeCompressImpl
|
||||
* Method: checkSupported
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_checkSupported
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: net_md_5_bungee_jni_zlib_NativeCompressImpl
|
||||
* Method: end
|
||||
|
Reference in New Issue
Block a user