Skip to content

About

Java bindings for Google cpu_features

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Latest commit

 

History

36 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CpuFeaturesJni

License CI Release Snapshot

Java bindings for Google cpu_features


This project supports the following architectures:

  • aarch64
  • arm
  • riscv
  • x86

Usage

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.

Entry point

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.

Getting CPU info

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);
    }
    // ...
}

Querying CPU features

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);
}

Building from source

git clone https://github.com/aecsocket/cpu-features-jni
cd cpu-features-jni
git submodule update --init
./gradlew generateNatives build

About

Java bindings for Google cpu_features

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages