forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 20
Add SVE, SVE2, SVEBITPERM, and FP16 feature detection on Windows/ARM64 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
raneashay
wants to merge
1
commit into
microsoft:main
from
raneashay:ashay/fix-windows-arm-sve-support
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/hotspot/os_cpu/windows_aarch64/sve_helper_windows_aarch64.S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ; Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | ||
| ; DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| ; | ||
| ; This code is free software; you can redistribute it and/or modify it | ||
| ; under the terms of the GNU General Public License version 2 only, as | ||
| ; published by the Free Software Foundation. | ||
| ; | ||
| ; This code is distributed in the hope that it will be useful, but WITHOUT | ||
| ; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| ; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| ; version 2 for more details (a copy is included in the LICENSE file that | ||
| ; accompanied this code). | ||
| ; | ||
| ; You should have received a copy of the GNU General Public License version | ||
| ; 2 along with this work; if not, write to the Free Software Foundation, | ||
| ; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| ; | ||
| ; Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| ; or visit www.oracle.com if you need additional information or have any | ||
| ; questions. | ||
| ; | ||
|
|
||
| ; int get_sve_vector_length_impl(void); | ||
| ; | ||
| ; Returns the current SVE vector length in bytes. | ||
| ; Uses the RDVL instruction which returns imm * VL in bytes. | ||
| ; With imm=1 this gives the SVE vector length directly. | ||
|
|
||
| ALIGN 4 | ||
| EXPORT get_sve_vector_length_impl | ||
| AREA sve_helper_text, CODE, READONLY | ||
|
|
||
| get_sve_vector_length_impl | ||
| rdvl x0, 1 | ||
| ret | ||
|
|
||
| END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
test/hotspot/jtreg/compiler/c2/aarch64/TestSVEFeatureDetection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @summary Verify SVE/SVE2 feature detection for both Windows and Linux. | ||
| * | ||
| * @requires os.arch == "aarch64" & vm.compiler2.enabled | ||
| * @library /test/lib / | ||
| * @build jdk.test.whitebox.WhiteBox | ||
| * @run driver jdk.test.lib.helpers.ClassFileInstaller | ||
| * jdk.test.whitebox.WhiteBox | ||
| * | ||
| * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions | ||
| * -XX:+WhiteBoxAPI compiler.c2.aarch64.TestSVEFeatureDetection | ||
| */ | ||
|
|
||
| package compiler.c2.aarch64; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import jdk.test.lib.Asserts; | ||
| import jdk.test.lib.process.ProcessTools; | ||
| import jdk.test.lib.process.OutputAnalyzer; | ||
| import jdk.test.whitebox.WhiteBox; | ||
|
|
||
| public class TestSVEFeatureDetection { | ||
| private static final WhiteBox WB = WhiteBox.getWhiteBox(); | ||
| private static final String KEY_USE_SVE = "UseSVE="; | ||
| private static final String KEY_MAX_VECTOR = "MaxVectorSize="; | ||
| private static final String KEY_HAS_SVE = "has_sve="; | ||
| private static final String KEY_HAS_SVE2 = "has_sve2="; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| if (args.length > 0 && args[0].equals("flagCheck")) { | ||
| printFlags(); | ||
| } else { | ||
| runDriver(); | ||
| } | ||
| } | ||
|
|
||
| private static void printFlags() { | ||
| int sveLevel = WB.getUintVMFlag("UseSVE").intValue(); | ||
| long maxVectorSize = WB.getIntxVMFlag("MaxVectorSize"); | ||
| List<String> features = Arrays.asList(WB.getCPUFeatures().split(", ")); | ||
| boolean hasSve = features.contains("sve"); | ||
| boolean hasSve2 = features.contains("sve2"); | ||
|
|
||
| System.out.println(KEY_USE_SVE + sveLevel); | ||
| System.out.println(KEY_MAX_VECTOR + maxVectorSize); | ||
| System.out.println(KEY_HAS_SVE + hasSve); | ||
| System.out.println(KEY_HAS_SVE2 + hasSve2); | ||
| } | ||
|
|
||
| private static void runDriver() throws Exception { | ||
| int sveLevel = WB.getUintVMFlag("UseSVE").intValue(); | ||
| long maxVectorSize = WB.getIntxVMFlag("MaxVectorSize"); | ||
| List<String> features = Arrays.asList(WB.getCPUFeatures().split(", ")); | ||
| boolean hasSve = features.contains("sve"); | ||
| boolean hasSve2 = features.contains("sve2"); | ||
|
|
||
| // If SVE is not present, just verify a consistent disabled state. | ||
| if (!hasSve) { | ||
| Asserts.assertEquals(sveLevel, 0, | ||
| "UseSVE must be 0 when hardware lacks SVE"); | ||
| Asserts.assertFalse(hasSve2, | ||
| "sve2 must be absent when sve is absent"); | ||
| return; | ||
| } | ||
|
|
||
| Asserts.assertTrue(sveLevel > 0, | ||
| "UseSVE should be auto-set to > 0 when SVE hardware is present"); | ||
| Asserts.assertTrue(maxVectorSize >= 16, | ||
| "MaxVectorSize must be >= 16 for SVE, got " + maxVectorSize); | ||
| Asserts.assertTrue(Long.bitCount(maxVectorSize) == 1, | ||
| "MaxVectorSize must be a power of two, got " + maxVectorSize); | ||
| Asserts.assertTrue(maxVectorSize % 16 == 0, | ||
| "MaxVectorSize must be a multiple of 16, got " + maxVectorSize); | ||
| Asserts.assertTrue(maxVectorSize <= 256, | ||
| "MaxVectorSize must be <= 256 (2048 bits), got " + maxVectorSize); | ||
|
|
||
| if (hasSve2) { | ||
| Asserts.assertEquals(sveLevel, 2, | ||
| "UseSVE should be 2 when hardware supports SVE2"); | ||
| } else { | ||
| Asserts.assertEquals(sveLevel, 1, | ||
| "UseSVE should be 1 when hardware supports SVE but not SVE2"); | ||
| } | ||
|
|
||
| OutputAnalyzer out = spawnFlagCheck("-XX:UseSVE=0"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain(KEY_USE_SVE + "0"); | ||
| out.shouldContain(KEY_HAS_SVE + "false"); | ||
| out.shouldContain(KEY_HAS_SVE2 + "false"); | ||
|
|
||
| out = spawnFlagCheck("-XX:UseSVE=1", "-XX:MaxVectorSize=512"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain("warning"); | ||
|
|
||
| boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); | ||
| out = spawnFlagCheck("-XX:UseSVE=1", "-XX:MaxVectorSize=16"); | ||
| out.shouldHaveExitValue(0); | ||
| if (isWindows && maxVectorSize > 16) { | ||
| out.shouldContain("warning"); | ||
| out.shouldContain(KEY_MAX_VECTOR + maxVectorSize); | ||
| } else { | ||
| out.shouldContain(KEY_MAX_VECTOR + "16"); | ||
| } | ||
|
|
||
| if (hasSve2) { | ||
| out = spawnFlagCheck("-XX:UseSVE=2"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain(KEY_USE_SVE + "2"); | ||
| out.shouldContain(KEY_HAS_SVE + "true"); | ||
| out.shouldContain(KEY_HAS_SVE2 + "true"); | ||
|
|
||
| out = spawnFlagCheck("-XX:UseSVE=1"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain(KEY_USE_SVE + "1"); | ||
| out.shouldContain(KEY_HAS_SVE + "true"); | ||
| out.shouldContain(KEY_HAS_SVE2 + "false"); | ||
| } else { | ||
| out = spawnFlagCheck("-XX:UseSVE=2"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain("SVE2 specified, but not supported on current CPU"); | ||
| out.shouldContain(KEY_USE_SVE + "1"); | ||
| out.shouldContain(KEY_HAS_SVE + "true"); | ||
| out.shouldContain(KEY_HAS_SVE2 + "false"); | ||
| } | ||
|
|
||
| out = spawnFlagCheck("-XX:UseSVE=1"); | ||
| out.shouldHaveExitValue(0); | ||
| out.shouldContain(KEY_USE_SVE + "1"); | ||
| out.shouldContain(KEY_HAS_SVE + "true"); | ||
| out.shouldMatch("MaxVectorSize=\\d+"); | ||
|
|
||
| if (maxVectorSize >= 32) { | ||
| out = spawnFlagCheck("-XX:UseSVE=1", "-XX:MaxVectorSize=32"); | ||
| out.shouldHaveExitValue(0); | ||
| if (isWindows && maxVectorSize > 32) { | ||
| out.shouldContain("warning"); | ||
| out.shouldContain(KEY_MAX_VECTOR + maxVectorSize); | ||
| } else { | ||
| out.shouldContain(KEY_MAX_VECTOR + "32"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static OutputAnalyzer spawnFlagCheck(String... extraFlags) | ||
| throws Exception { | ||
| List<String> args = new ArrayList<>(); | ||
| args.add("-Xbootclasspath/a:."); | ||
| args.add("-XX:+UnlockDiagnosticVMOptions"); | ||
| args.add("-XX:+WhiteBoxAPI"); | ||
| for (String f : extraFlags) { | ||
| args.add(f); | ||
| } | ||
| args.add(TestSVEFeatureDetection.class.getName()); | ||
| args.add("flagCheck"); | ||
|
|
||
| ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( | ||
| args.toArray(new String[0])); | ||
| OutputAnalyzer output = new OutputAnalyzer(pb.start()); | ||
| output.reportDiagnosticSummary(); | ||
| return output; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inspect other similar tests that use multiple
@runlines. This might help with removing an explicit driver.