Skip to content

Commit a8bc25c

Browse files
authored
Add IsProcessorFeaturePresent to c.s.j.p.win32.Kernel32 (#1595)
Signed-off-by: Daniel Widdis <[email protected]>
1 parent f68c9be commit a8bc25c

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Diff for: CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features
99
--------
1010
* [#1578](https://github.com/java-native-access/jna/pull/1578): Add support for FreeBSD aarch64 - [@alexdupre](https://github.com/alexdupre).
1111
* [#1593](https://github.com/java-native-access/jna/pull/1593): Add support for DragonFly BSD x86-64 - [@liweitianux](https://github.com/liweitianux).
12+
* [#1595](https://github.com/java-native-access/jna/pull/1595): Add `IsProcessorFeaturePresent` to `c.s.j.p.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis).
1213

1314
Bug Fixes
1415
---------

Diff for: contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+58
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,54 @@ public interface Kernel32 extends StdCallLibrary, WinNT, Wincon {
106106
*/
107107
int THREAD_PRIORITY_ERROR_RETURN = 0x7FFFFFFF;
108108

109+
/**
110+
* Processor Feature flags
111+
*/
112+
int PF_FLOATING_POINT_PRECISION_ERRATA = 0;
113+
int PF_FLOATING_POINT_EMULATED = 1;
114+
int PF_COMPARE_EXCHANGE_DOUBLE = 2;
115+
int PF_MMX_INSTRUCTIONS_AVAILABLE = 3;
116+
int PF_PPC_MOVEMEM_64BIT_OK = 4;
117+
int PF_ALPHA_BYTE_INSTRUCTIONS = 5;
118+
int PF_XMMI_INSTRUCTIONS_AVAILABLE = 6;
119+
int PF_3DNOW_INSTRUCTIONS_AVAILABLE = 7;
120+
int PF_RDTSC_INSTRUCTION_AVAILABLE = 8;
121+
int PF_PAE_ENABLED = 9;
122+
int PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10;
123+
int PF_SSE_DAZ_MODE_AVAILABLE = 11;
124+
int PF_NX_ENABLED = 12;
125+
int PF_SSE3_INSTRUCTIONS_AVAILABLE = 13;
126+
int PF_COMPARE_EXCHANGE128 = 14;
127+
int PF_COMPARE64_EXCHANGE128 = 15;
128+
int PF_CHANNELS_ENABLED = 16;
129+
int PF_XSAVE_ENABLED = 17;
130+
int PF_ARM_VFP_32_REGISTERS_AVAILABLE = 18;
131+
int PF_ARM_NEON_INSTRUCTIONS_AVAILABLE = 19;
132+
int PF_SECOND_LEVEL_ADDRESS_TRANSLATION = 20;
133+
int PF_VIRT_FIRMWARE_ENABLED = 21;
134+
int PF_RDWRFSGSBASE_AVAILABLE = 22;
135+
int PF_FASTFAIL_AVAILABLE = 23;
136+
int PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE = 24;
137+
int PF_ARM_64BIT_LOADSTORE_ATOMIC = 25;
138+
int PF_ARM_EXTERNAL_CACHE_AVAILABLE = 26;
139+
int PF_ARM_FMAC_INSTRUCTIONS_AVAILABLE = 27;
140+
int PF_RDRAND_INSTRUCTION_AVAILABLE = 28;
141+
int PF_ARM_V8_INSTRUCTIONS_AVAILABLE = 29;
142+
int PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30;
143+
int PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31;
144+
int PF_RDTSCP_INSTRUCTION_AVAILABLE = 32;
145+
int PF_RDPID_INSTRUCTION_AVAILABLE = 33;
146+
int PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34;
147+
int PF_SSSE3_INSTRUCTIONS_AVAILABLE = 36;
148+
int PF_SSE4_1_INSTRUCTIONS_AVAILABLE = 37;
149+
int PF_SSE4_2_INSTRUCTIONS_AVAILABLE = 38;
150+
int PF_AVX_INSTRUCTIONS_AVAILABLE = 39;
151+
int PF_AVX2_INSTRUCTIONS_AVAILABLE = 40;
152+
int PF_AVX512F_INSTRUCTIONS_AVAILABLE = 41;
153+
int PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE = 43;
154+
int PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE = 44;
155+
int PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE = 45;
156+
109157
/**
110158
* Reads data from the specified file or input/output (I/O) device. Reads
111159
* occur at the position specified by the file pointer if supported by the
@@ -4464,4 +4512,14 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
44644512
* </p>
44654513
*/
44664514
boolean VirtualUnlock(Pointer lpAddress, SIZE_T dwSize);
4515+
4516+
/**
4517+
* Determines whether the specified processor feature is supported by the current computer.
4518+
*
4519+
* @param ProcessorFeature The processor feature to be tested.
4520+
* @return If the feature is supported, the return value is true. If the feature is not supported, the return value
4521+
* is false. If the HAL does not support detection of the feature, whether or not the hardware supports the
4522+
* feature, the return value is also false.
4523+
*/
4524+
boolean IsProcessorFeaturePresent(int ProcessorFeature);
44674525
}

Diff for: contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+9
Original file line numberDiff line numberDiff line change
@@ -2099,4 +2099,13 @@ public void testSetThreadPriority() {
20992099
final HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentThread();
21002100
assertTrue(Kernel32.INSTANCE.SetThreadPriority(selfHandle, Kernel32.THREAD_PRIORITY_ABOVE_NORMAL));
21012101
}
2102+
2103+
public void testIsProcessorFeaturePresent() {
2104+
// Always returns false for Windows 7 or later
2105+
assertFalse(Kernel32.INSTANCE.IsProcessorFeaturePresent(Kernel32.PF_FLOATING_POINT_PRECISION_ERRATA));
2106+
// Always true in 64 bit, requirement to run Windows
2107+
assertTrue(Kernel32.INSTANCE.IsProcessorFeaturePresent(Kernel32.PF_MMX_INSTRUCTIONS_AVAILABLE));
2108+
// Invalid values always return false
2109+
assertFalse(Kernel32.INSTANCE.IsProcessorFeaturePresent(-1));
2110+
}
21022111
}

0 commit comments

Comments
 (0)