├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── build-logic ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Extensions.kt │ ├── NativesExtension.kt │ ├── base-conventions.gradle.kts │ ├── java-conventions.gradle.kts │ ├── natives-conventions.gradle.kts │ ├── natives-linux-conventions.gradle.kts │ ├── natives-macos-conventions.gradle.kts │ ├── natives-windows-conventions.gradle.kts │ ├── parent-conventions.gradle.kts │ └── publishing-conventions.gradle.kts ├── build.gradle.kts ├── cpu-features-java-headers ├── build.gradle.kts └── src │ └── main │ └── java │ └── cpufeatures │ └── headers │ └── x86 │ ├── CacheInfo.java │ ├── CacheLevelInfo.java │ ├── Constants$root.java │ ├── CpuInfoX86.java │ ├── RuntimeHelper.java │ ├── X86Features.java │ ├── X86Info.java │ ├── constants$0.java │ └── constants$1.java ├── cpu-features-java-natives-linux-x86 └── build.gradle.kts ├── cpu-features-java-natives-macos-x86 └── build.gradle.kts ├── cpu-features-java-natives-windows-x86 └── build.gradle.kts ├── gradle ├── libs.versions.yml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── main └── java │ └── cpufeatures │ ├── CpuArchitecture.java │ ├── CpuFeatures.java │ ├── CpuPlatform.java │ ├── arm │ ├── ArmFeature.java │ ├── ArmFeatures.java │ └── ArmInfo.java │ └── x86 │ ├── X86Feature.java │ ├── X86Features.java │ ├── X86Info.java │ └── X86Uarch.java └── test └── java └── cpufeatures └── HelloCpuFeatures.java /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: "Build" 2 | 3 | on: 4 | push: 5 | branches: [ "**" ] 6 | tags-ignore: [ "**" ] 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | # Only run on PRs if the source branch is on someone else's repo 12 | if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} 13 | strategy: 14 | matrix: 15 | os: [ ubuntu-latest, windows-latest, macos-latest ] 16 | include: 17 | - os: ubuntu-latest 18 | publish-core: true 19 | runs-on: ${{ matrix.os }} 20 | steps: 21 | - name: "Checkout source" 22 | uses: actions/checkout@v3 23 | with: 24 | submodules: true 25 | - name: "Setup Java" 26 | uses: actions/setup-java@v3 27 | with: 28 | distribution: temurin 29 | java-version: 19 30 | - name: "Setup Gradle" 31 | uses: gradle/gradle-build-action@v2 32 | - name: "Run Gradle build" 33 | run: ./gradlew --stacktrace build 34 | - name: "sh: Get version type " 35 | if: ${{ matrix.os != 'windows-latest' }} 36 | run: | 37 | VERSION_TYPE=$(./gradlew -q --console=plain --no-daemon printVersionType) 38 | echo VERSION_TYPE=$VERSION_TYPE 39 | echo VERSION_TYPE=$VERSION_TYPE >> $GITHUB_ENV 40 | - name: "ps: Get version type" 41 | if: ${{ matrix.os == 'windows-latest' }} 42 | run: | 43 | $VERSION_TYPE = ./gradlew -q --console=plain --no-daemon printVersionType 44 | echo VERSION_TYPE=$VERSION_TYPE 45 | echo VERSION_TYPE=$VERSION_TYPE >> $env:GITHUB_ENV 46 | - name: "Publish snapshot" 47 | if: ${{ env.VERSION_TYPE == 'snapshot' && github.event_name == 'push' && github.ref == 'refs/heads/main' }} 48 | run: ./gradlew publish 49 | env: 50 | CI_PUBLISH_CORE: ${{ matrix.publish-core }} 51 | ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} 52 | ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} 53 | - name: "Publish release" 54 | if: ${{ env.VERSION_TYPE == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main' }} 55 | run: ./gradlew -PforceSign=true publishToSonatype closeSonatypeStagingRepository 56 | env: 57 | CI_PUBLISH_CORE: ${{ matrix.publish-core }} 58 | ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} 59 | ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} 60 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} 61 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | 11 | # Eclipse 12 | .classpath 13 | .project 14 | .settings/ 15 | plugin/bin/ 16 | api/bin/ 17 | 18 | # VS Code 19 | *bin/ 20 | 21 | # Fleet 22 | .fleet/ 23 | 24 | # Compiled class file 25 | *.class 26 | 27 | # Log file 28 | *.log 29 | 30 | # BlueJ files 31 | *.ctxt 32 | 33 | # Package Files # 34 | *.war 35 | *.nar 36 | *.ear 37 | *.zip 38 | *.tar.gz 39 | *.rar 40 | 41 | # debugger attaches 42 | .attach_pid* 43 | 44 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 45 | hs_err_pid* 46 | 47 | *~ 48 | 49 | # temporary files which can be created if a process still has a handle open of a deleted file 50 | .fuse_hidden* 51 | 52 | # KDE directory preferences 53 | .directory 54 | 55 | # Linux trash folder which might appear on any partition or disk 56 | .Trash-* 57 | 58 | # .nfs files are created when an open file is removed but is still being accessed 59 | .nfs* 60 | 61 | # General 62 | .DS_Store 63 | .AppleDouble 64 | .LSOverride 65 | 66 | # Icon must end with two \r 67 | Icon 68 | 69 | # Thumbnails 70 | ._* 71 | 72 | # Files that might appear in the root of a volume 73 | .DocumentRevisions-V100 74 | .fseventsd 75 | .Spotlight-V100 76 | .TemporaryItems 77 | .Trashes 78 | .VolumeIcon.icns 79 | .com.apple.timemachine.donotpresent 80 | 81 | # Directories potentially created on remote AFP share 82 | .AppleDB 83 | .AppleDesktop 84 | Network Trash Folder 85 | Temporary Items 86 | .apdisk 87 | 88 | # Windows thumbnail cache files 89 | Thumbs.db 90 | Thumbs.db:encryptable 91 | ehthumbs.db 92 | ehthumbs_vista.db 93 | 94 | # Dump file 95 | *.stackdump 96 | 97 | # Folder config file 98 | [Dd]esktop.ini 99 | 100 | # Recycle Bin used on file shares 101 | $RECYCLE.BIN/ 102 | 103 | # Windows Installer files 104 | *.cab 105 | *.msi 106 | *.msix 107 | *.msm 108 | *.msp 109 | 110 | # Windows shortcuts 111 | *.lnk 112 | 113 | target/ 114 | 115 | pom.xml.tag 116 | pom.xml.releaseBackup 117 | pom.xml.versionsBackup 118 | pom.xml.next 119 | 120 | release.properties 121 | dependency-reduced-pom.xml 122 | buildNumber.properties 123 | .mvn/timing.properties 124 | .mvn/wrapper/maven-wrapper.jar 125 | .flattened-pom.xml 126 | 127 | # Common working directory 128 | run/ 129 | build 130 | .gradle 131 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cpu_features"] 2 | path = cpu_features 3 | url = https://github.com/google/cpu_features.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 aecsocket 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
34 | * If the host is not on an ARM processor, this operation will fail.
35 | * @return Processor info.
36 | */
37 | public static ArmInfo get() {
38 | throw new UnsupportedOperationException();
39 | }
40 |
41 | /**
42 | * Gets a set of all features that this info holds. If you are testing for a specific feature, prefer using
43 | * {@link #features()} instead.
44 | * @return Set of features.
45 | */
46 | public Set
42 | * If the host is not on an X86 processor, this operation will fail.
43 | * @return Processor info.
44 | */
45 | public static X86Info get() {
46 | try (var session = MemorySession.openConfined()) {
47 | var info = GetX86Info(session);
48 |
49 | var features = features$slice(info);
50 | int a = (int) a$VH.get(features);
51 | int b = (int) b$VH.get(features);
52 | int c = (int) c$VH.get(features);
53 | /*
54 | for i in range(len(flags)):
55 | curfield = ["a","b","c"][int(i / 32)]
56 | print(f"boolean {flags[i]} = get({curfield}, {i % 32});")
57 | */
58 | boolean fpu = get(a, 0);
59 | boolean tsc = get(a, 1);
60 | boolean cx8 = get(a, 2);
61 | boolean clfsh = get(a, 3);
62 | boolean mmx = get(a, 4);
63 | boolean aes = get(a, 5);
64 | boolean erms = get(a, 6);
65 | boolean f16c = get(a, 7);
66 | boolean fma4 = get(a, 8);
67 | boolean fma3 = get(a, 9);
68 | boolean vaes = get(a, 10);
69 | boolean vpclmulqdq = get(a, 11);
70 | boolean bmi1 = get(a, 12);
71 | boolean hle = get(a, 13);
72 | boolean bmi2 = get(a, 14);
73 | boolean rtm = get(a, 15);
74 | boolean rdseed = get(a, 16);
75 | boolean clflushopt = get(a, 17);
76 | boolean clwb = get(a, 18);
77 | boolean sse = get(a, 19);
78 | boolean sse2 = get(a, 20);
79 | boolean sse3 = get(a, 21);
80 | boolean ssse3 = get(a, 22);
81 | boolean sse4_1 = get(a, 23);
82 | boolean sse4_2 = get(a, 24);
83 | boolean sse4a = get(a, 25);
84 | boolean avx = get(a, 26);
85 | boolean avx_vnni = get(a, 27);
86 | boolean avx2 = get(a, 28);
87 | boolean avx512f = get(a, 29);
88 | boolean avx512cd = get(a, 30);
89 | boolean avx512er = get(a, 31);
90 | boolean avx512pf = get(b, 0);
91 | boolean avx512bw = get(b, 1);
92 | boolean avx512dq = get(b, 2);
93 | boolean avx512vl = get(b, 3);
94 | boolean avx512ifma = get(b, 4);
95 | boolean avx512vbmi = get(b, 5);
96 | boolean avx512vbmi2 = get(b, 6);
97 | boolean avx512vnni = get(b, 7);
98 | boolean avx512bitalg = get(b, 8);
99 | boolean avx512vpopcntdq = get(b, 9);
100 | boolean avx512_4vnniw = get(b, 10);
101 | boolean avx512_4vbmi2 = get(b, 11);
102 | boolean avx512_second_fma = get(b, 12);
103 | boolean avx512_4fmaps = get(b, 13);
104 | boolean avx512_bf16 = get(b, 14);
105 | boolean avx512_vp2intersect = get(b, 15);
106 | boolean avx512_fp16 = get(b, 16);
107 | boolean amx_bf16 = get(b, 17);
108 | boolean amx_tile = get(b, 18);
109 | boolean amx_int8 = get(b, 19);
110 | boolean pclmulqdq = get(b, 20);
111 | boolean smx = get(b, 21);
112 | boolean sgx = get(b, 22);
113 | boolean cx16 = get(b, 23);
114 | boolean sha = get(b, 24);
115 | boolean popcnt = get(b, 25);
116 | boolean movbe = get(b, 26);
117 | boolean rdrnd = get(b, 27);
118 | boolean dca = get(b, 28);
119 | boolean ss = get(b, 29);
120 | boolean adx = get(b, 30);
121 | boolean lzcnt = get(b, 31);
122 | boolean gfni = get(c, 0);
123 | boolean movdiri = get(c, 1);
124 | boolean movdir64b = get(c, 2);
125 | boolean fs_rep_mov = get(c, 3);
126 | boolean fz_rep_movsb = get(c, 4);
127 | boolean fs_rep_stosb = get(c, 5);
128 | boolean fs_rep_cmpsb_scasb = get(c, 6);
129 |
130 | int family = family$get(info);
131 | int model = model$get(info);
132 | int stepping = stepping$get(info);
133 | String vendor = vendor$slice(info).getUtf8String(0);
134 | String brandString = brand_string$slice(info).getUtf8String(0);
135 |
136 | X86Uarch uarch = X86Uarch.values()[GetX86Microarchitecture(info)];
137 |
138 | return new X86Info(
139 | new X86Features(fpu, tsc, cx8, clfsh, mmx, aes, erms, f16c, fma4, fma3, vaes, vpclmulqdq, bmi1, hle, bmi2, rtm, rdseed, clflushopt, clwb, sse, sse2, sse3, ssse3, sse4_1, sse4_2, sse4a, avx, avx_vnni, avx2, avx512f, avx512cd, avx512er, avx512pf, avx512bw, avx512dq, avx512vl, avx512ifma, avx512vbmi, avx512vbmi2, avx512vnni, avx512bitalg, avx512vpopcntdq, avx512_4vnniw, avx512_4vbmi2, avx512_second_fma, avx512_4fmaps, avx512_bf16, avx512_vp2intersect, avx512_fp16, amx_bf16, amx_tile, amx_int8, pclmulqdq, smx, sgx, cx16, sha, popcnt, movbe, rdrnd, dca, ss, adx, lzcnt, gfni, movdiri, movdir64b, fs_rep_mov, fz_rep_movsb, fs_rep_stosb, fs_rep_cmpsb_scasb),
140 | family,
141 | model,
142 | stepping,
143 | vendor,
144 | brandString,
145 | uarch
146 | );
147 | }
148 | }
149 |
150 | /**
151 | * Gets a set of all features that this info holds. If you are testing for a specific feature, prefer using
152 | * {@link #features()} instead.
153 | * @return Set of features.
154 | */
155 | public Set