This project supports the following architectures:
- aarch64
- arm
- riscv
- x86
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.aecsocket", "cpu-features-jni", "VERSION")
runtimeOnly("io.github.aecsocket", "cpu-features-jni-natives-linux", "VERSION")
runtimeOnly("io.github.aecsocket", "cpu-features-jni-natives-windows", "VERSION")
runtimeOnly("io.github.aecsocket", "cpu-features-jni-natives-macos", "VERSION")
runtimeOnly("io.github.aecsocket", "cpu-features-jni-natives-macos-arm64", "VERSION")
}Usage is very similar to cpu_features. See HelloCpuFeatures.java to get a minimal implementation.
The class cpufeatures.CpuFeatures is the entry point to the library. Frist run CpuFeatures.load() to load the
native libraries from the jar (in cpufeatures/), or load them yourself using System.load.
CpuArchitecture arch = CpuFeatures.getArchitecture();
switch (arch) {
X86 -> {
X86Info info = CpuFeatures.getX86Info();
System.out.println(info.vendor);
}
ARM -> {
ArmInfo info = CpuFeatures.getArmInfo();
System.out.println(info.implementer);
}
// ...
}public static boolean useAVX2 = false;
public static void init() {
X86Info info = CpuFeatures.getX86Info();
useAVX2 = info.features.avx2;
List<X86Feature> features = info.featureList();
System.out.println("features: " + features);
}git clone https://github.com/aecsocket/cpu-features-jni
cd cpu-features-jni
git submodule update --init
./gradlew generateNatives build