xref: /aosp_15_r20/external/cpu_features/src/impl_x86_windows.c (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "cpu_features_macros.h"
16 
17 #ifdef CPU_FEATURES_ARCH_X86
18 #ifdef CPU_FEATURES_OS_WINDOWS
19 
20 #include "impl_x86__base_implementation.inl"
21 
OverrideOsPreserves(OsPreserves * os_preserves)22 static void OverrideOsPreserves(OsPreserves* os_preserves) {
23   (void)os_preserves;
24   // No override
25 }
26 
27 #include "internal/windows_utils.h"
28 
29 #if defined(CPU_FEATURES_MOCK_CPUID_X86)
30 extern bool GetWindowsIsProcessorFeaturePresent(DWORD);
31 #else  // CPU_FEATURES_MOCK_CPUID_X86
GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature)32 static bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
33   return IsProcessorFeaturePresent(ProcessorFeature);
34 }
35 #endif
36 
DetectFeaturesFromOs(X86Info * info,X86Features * features)37 static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
38   // Handling Windows platform through IsProcessorFeaturePresent.
39   // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
40   features->sse =
41       GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
42   features->sse2 =
43       GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
44   features->sse3 =
45       GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE);
46   features->ssse3 =
47       GetWindowsIsProcessorFeaturePresent(PF_SSSE3_INSTRUCTIONS_AVAILABLE);
48   features->sse4_1 =
49       GetWindowsIsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE);
50   features->sse4_2 =
51       GetWindowsIsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE);
52 
53 // do not bother checking PF_AVX*
54 // cause AVX enabled processor will have XCR0 be exposed and this function will be skipped at all
55 }
56 
57 #endif  // CPU_FEATURES_OS_WINDOWS
58 #endif  // CPU_FEATURES_ARCH_X86
59