Created
August 22, 2024 16:08
-
-
Save bentman/d0b147f3848a7cb33071fbfa4f593074 to your computer and use it in GitHub Desktop.
Will my PC run w11-24h2?... oh no! my Surface Go v1.0 will not be because of POPCNT - so I put Linux on it! https://github.com/linux-surface/linux-surface
This file contains 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
function Test-CPUFeature { | |
param ( | |
[Parameter(Mandatory=$true)] | |
[ValidateSet("SSE4.2", "SSE4A")] | |
[string]$Feature | |
) | |
$signature = @" | |
[DllImport("kernel32.dll")] | |
public static extern IntPtr GetCurrentProcess(); | |
[DllImport("kernel32.dll")] | |
public static extern IntPtr GetCurrentThread(); | |
[DllImport("kernel32.dll", SetLastError=true)] | |
public static extern bool GetThreadContext(IntPtr hThread, ref CONTEXT lpContext); | |
[StructLayout(LayoutKind.Sequential)] | |
public struct CONTEXT | |
{ | |
public uint ContextFlags; | |
public uint Dr0; | |
public uint Dr1; | |
public uint Dr2; | |
public uint Dr3; | |
public uint Dr6; | |
public uint Dr7; | |
public FLOATING_SAVE_AREA FloatSave; | |
public uint SegGs; | |
public uint SegFs; | |
public uint SegEs; | |
public uint SegDs; | |
public uint Edi; | |
public uint Esi; | |
public uint Ebx; | |
public uint Edx; | |
public uint Ecx; | |
public uint Eax; | |
public uint Ebp; | |
public uint Eip; | |
public uint SegCs; | |
public uint EFlags; | |
public uint Esp; | |
public uint SegSs; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] | |
public byte[] ExtendedRegisters; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct FLOATING_SAVE_AREA | |
{ | |
public uint ControlWord; | |
public uint StatusWord; | |
public uint TagWord; | |
public uint ErrorOffset; | |
public uint ErrorSelector; | |
public uint DataOffset; | |
public uint DataSelector; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)] | |
public byte[] RegisterArea; | |
public uint Cr0NpxState; | |
} | |
"@ | |
Add-Type -MemberDefinition $signature -Name Win32Utils -Namespace Win32API | |
$context = New-Object Win32API.Win32Utils+CONTEXT | |
$context.ContextFlags = 0x10001 # CONTEXT_FULL | |
$thread = [Win32API.Win32Utils]::GetCurrentThread() | |
[Win32API.Win32Utils]::GetThreadContext($thread, [ref]$context) | |
# CPUID | |
$context.Eax = 1 | |
[Win32API.Win32Utils]::GetThreadContext($thread, [ref]$context) | |
switch ($Feature) { | |
"SSE4.2" { $support = ($context.Ecx -band 0x100000) -ne 0 } | |
"SSE4A" { $support = ($context.Ecx -band 0x200) -ne 0 } | |
} | |
return $support | |
} | |
$sse42Support = Test-CPUFeature -Feature "SSE4.2" | |
$sse4aSupport = Test-CPUFeature -Feature "SSE4A" | |
if ($sse42Support -or $sse4aSupport) { | |
Write-Host "This processor supports SSE4.2 or SSE4A." | |
if ($sse42Support) { Write-Host "SSE4.2 is supported." } | |
if ($sse4aSupport) { Write-Host "SSE4A is supported." } | |
} else { | |
Write-Host "This processor does not support SSE4.2 or SSE4A." | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment