Skip to content

Commit 78e9625

Browse files
raneashayVladimir Kozlov
authored andcommitted
8381617: vm_version_windows_aarch64.cpp: PF_ARM_SVE_INSTRUCTIONS_AVAILABLE undeclared identifier
Reviewed-by: kvn, macarte
1 parent ae5b765 commit 78e9625

5 files changed

Lines changed: 137 additions & 85 deletions

File tree

src/hotspot/os_cpu/windows_aarch64/sve_windows_aarch64.S

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@
2424
; Support for int get_sve_vector_length();
2525
;
2626
; Returns the current SVE vector length in bytes.
27-
; This function uses the INCB instruction which increments a register
28-
; by the number of bytes in an SVE vector register.
27+
; This function uses the RDVL instruction which reads a multiple of the
28+
; vector register size into a scalar register.
2929
;
30-
; Note: This function will fault if SVE is not available or enabled.
31-
; The caller must ensure SVE support is detected before calling.
30+
; Note: This function will fault if SVE is not available or enabled. The
31+
; caller must ensure SVE support is detected before calling.
3232

3333
ALIGN 4
3434
EXPORT get_sve_vector_length
3535
AREA sve_text, CODE
3636

3737
get_sve_vector_length
38-
mov x0, #0
39-
incb x0
38+
; Older versions of Visual Studio aren't aware of SVE mnemonics, so we use
39+
; the raw instruction encoding to satisfy the compiler. This function call
40+
; is gated by `VM_Version::supports_sve()`, so this instruction will never
41+
; run on non-SVE hardware.
42+
;
43+
; See https://www.scs.stanford.edu/~zyedidia/arm64/rdvl_r_i.html for a quick
44+
; reference to the instruction encoding.
45+
46+
DCD 0x04BF5020 ; rdvl x0, #1 (i.e. x0 = 1 * vector_length_in_bytes)
4047
ret
4148

4249
END

src/hotspot/os_cpu/windows_aarch64/vm_version_windows_aarch64.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,52 @@
2626
#include "runtime/os.hpp"
2727
#include "runtime/vm_version.hpp"
2828

29-
// Assembly function to get SVE vector length using INCB instruction
29+
// Since PF_ARM_SVE_INSTRUCTIONS_AVAILABLE and related constants were added in
30+
// Windows 11 (version 24H2) and in Windows Server 2025, we define them here for
31+
// compatibility with older SDK versions.
32+
#ifndef PF_ARM_SVE_INSTRUCTIONS_AVAILABLE
33+
#define PF_ARM_SVE_INSTRUCTIONS_AVAILABLE 46
34+
#endif
35+
36+
#ifndef PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE
37+
#define PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE 47
38+
#endif
39+
40+
#ifndef PF_ARM_SVE_BITPERM_INSTRUCTIONS_AVAILABLE
41+
#define PF_ARM_SVE_BITPERM_INSTRUCTIONS_AVAILABLE 51
42+
#endif
43+
44+
#ifndef PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE
45+
#define PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE 64
46+
#endif
47+
48+
#ifndef PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE
49+
#define PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE 65
50+
#endif
51+
52+
#ifndef PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE
53+
#define PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE 67
54+
#endif
55+
56+
// Assembly function to get SVE vector length using RDVL instruction
3057
extern "C" int get_sve_vector_length();
3158

3259
int VM_Version::get_current_sve_vector_length() {
3360
assert(VM_Version::supports_sve(), "should not call this");
34-
// Use assembly instruction to get the actual SVE vector length
35-
return VM_Version::supports_sve() ? get_sve_vector_length() : 0; // This value is in bytes
61+
return VM_Version::supports_sve() ? get_sve_vector_length() : 0;
3662
}
3763

3864
int VM_Version::set_and_get_current_sve_vector_length(int length) {
3965
assert(VM_Version::supports_sve(), "should not call this");
40-
// Use assembly instruction to get the SVE vector length
41-
return VM_Version::supports_sve() ? get_sve_vector_length() : 0; // This value is in bytes
66+
67+
// Unlike Linux, Windows does not present a way to modify the VL (the
68+
// rationale is that the OS expects the application to use the maximum vector
69+
// length supported by the hardware), so we simply return the current VL. If
70+
// the user sets `MaxVectorSize` that is not the same as the maximum possible
71+
// vector length, then the caller (`VM_Version::initialize()`) will print a
72+
// warning, set `MaxVectorSize` to the value returned by this function, and
73+
// move on.
74+
return VM_Version::supports_sve() ? get_sve_vector_length() : 0;
4275
}
4376

4477
void VM_Version::get_os_cpu_info() {
@@ -67,6 +100,10 @@ void VM_Version::get_os_cpu_info() {
67100
if (IsProcessorFeaturePresent(PF_ARM_SVE_BITPERM_INSTRUCTIONS_AVAILABLE)) {
68101
set_feature(CPU_SVEBITPERM);
69102
}
103+
if (IsProcessorFeaturePresent(PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE)) {
104+
set_feature(CPU_FPHP);
105+
set_feature(CPU_ASIMDHP);
106+
}
70107
if (IsProcessorFeaturePresent(PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE)) {
71108
set_feature(CPU_SHA3);
72109
}

test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* @test
27-
* @bug 8308363 8336406
27+
* @bug 8308363 8336406 8381617
2828
* @summary Validate compiler IR for various Float16 scalar operations.
2929
* @modules jdk.incubator.vector
3030
* @requires vm.compiler2.enabled
@@ -714,9 +714,13 @@ public void testSqrtConstantFolding() {
714714

715715
@Test
716716
@IR(counts = {IRNode.FMA_HF, " 0 ", IRNode.REINTERPRET_S2HF, " 0 ", IRNode.REINTERPRET_HF2S, " 0 "},
717-
applyIfCPUFeatureOr = {"avx512_fp16", "true", "zfh", "true"})
717+
applyIfCPUFeatureOr = {"avx512_fp16", "true", "zfh", "true"},
718+
// On Windows, both GCC and MSVC don't set __STDC_IEC_559__, so FMAs on constants are not folded.
719+
applyIfPlatform = {"windows", "false"})
718720
@IR(counts = {IRNode.FMA_HF, " 0 ", IRNode.REINTERPRET_S2HF, " 0 ", IRNode.REINTERPRET_HF2S, " 0 "},
719-
applyIfCPUFeatureAnd = {"fphp", "true", "asimdhp", "true"})
721+
applyIfCPUFeatureAnd = {"fphp", "true", "asimdhp", "true"},
722+
// On Windows, both GCC and MSVC don't set __STDC_IEC_559__, so FMAs on constants are not folded.
723+
applyIfPlatform = {"windows", "false"})
720724
@Warmup(10000)
721725
public void testFMAConstantFolding() {
722726
// If any argument is NaN, the result is NaN.
@@ -752,9 +756,13 @@ public void testFMAConstantFolding() {
752756

753757
@Test
754758
@IR(failOn = {IRNode.ADD_HF, IRNode.SUB_HF, IRNode.MUL_HF, IRNode.DIV_HF, IRNode.SQRT_HF, IRNode.FMA_HF},
755-
applyIfCPUFeatureOr = {"avx512_fp16", "true", "zfh", "true"})
759+
applyIfCPUFeatureOr = {"avx512_fp16", "true", "zfh", "true"},
760+
// On Windows, both GCC and MSVC don't set __STDC_IEC_559__, so FMAs on constants are not folded.
761+
applyIfPlatform = {"windows", "false"})
756762
@IR(failOn = {IRNode.ADD_HF, IRNode.SUB_HF, IRNode.MUL_HF, IRNode.DIV_HF, IRNode.SQRT_HF, IRNode.FMA_HF},
757-
applyIfCPUFeatureAnd = {"fphp", "true", "asimdhp", "true"})
763+
applyIfCPUFeatureAnd = {"fphp", "true", "asimdhp", "true"},
764+
// On Windows, both GCC and MSVC don't set __STDC_IEC_559__, so FMAs on constants are not folded.
765+
applyIfPlatform = {"windows", "false"})
758766
@Warmup(10000)
759767
public void testRounding1() {
760768
dst[0] = float16ToRawShortBits(add(RANDOM1, RANDOM2));

0 commit comments

Comments
 (0)