| 1 |
/* |
| 2 |
Copyright(c) 2002-2017 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
|
| 16 |
For more information please visit: http://bitmagic.io |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "io_bitmagic_core_SimdUtil0.h" |
| 20 |
#include "libbmcpuid.h" |
| 21 |
#include <stdio.h> |
| 22 |
|
| 23 |
#define BMJNI "bmjni" |
| 24 |
#define BMJNI_SSE "bmjni-sse" |
| 25 |
#define BMJNI_SSE2 "bmjni-sse2" |
| 26 |
#define BMJNI_SSE3 "bmjni-sse3" |
| 27 |
#define BMJNI_SSE4_1 "bmjni-sse41" |
| 28 |
#define BMJNI_SSE4_2 "bmjni-sse42" |
| 29 |
#define BMJNI_AVX "bmjni-avx" |
| 30 |
#define BMJNI_AVX2 "bmjni-avx2" |
| 31 |
#define BMJNI_AVX512F "bmjni-avx512f" |
| 32 |
|
| 33 |
const char* BM_simd_libname(void) { |
| 34 |
unsigned simd = BM_x86_simd(); |
| 35 |
//printf("Simd code: %x\n", simd); |
| 36 |
if (simd & SIMD_AVX512F) |
| 37 |
return BMJNI_AVX2; |
| 38 |
else if (simd & SIMD_AVX2) |
| 39 |
return BMJNI_AVX2; |
| 40 |
else if (simd & SIMD_AVX) |
| 41 |
return BMJNI_SSE4_2; |
| 42 |
else if (simd & SIMD_SSE4_2) |
| 43 |
return BMJNI_SSE4_2; |
| 44 |
else if (simd & SIMD_SSE4_1) |
| 45 |
return BMJNI; |
| 46 |
else if (simd & SIMD_SSE3) |
| 47 |
return BMJNI; |
| 48 |
else if (simd & SIMD_SSE2) |
| 49 |
return BMJNI; |
| 50 |
else if (simd & SIMD_SSE) |
| 51 |
return BMJNI; |
| 52 |
else |
| 53 |
return "Unknown simd code, no library name found"; |
| 54 |
} |
| 55 |
|
| 56 |
/* |
| 57 |
* Class: io_bitmagic_core_SimdUtil0 |
| 58 |
* Method: getLibName0 |
| 59 |
* Signature: ()Ljava/lang/String; |
| 60 |
*/ |
| 61 |
JNIEXPORT jstring JNICALL Java_io_bitmagic_core_SimdUtil0_getLibName0 |
| 62 |
(JNIEnv *env, jclass clazz) { |
| 63 |
const char *libName = BM_simd_libname(); |
| 64 |
return (*env)->NewStringUTF(env, libName); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|