1/* cpu_x86_Windows.ipp
2 *
3 * Author           : Alexander J. Yee
4 * Date Created     : 04/12/2014
5 * Last Modified    : 04/12/2014
6 *
7 */
8
9////////////////////////////////////////////////////////////////////////////////
10////////////////////////////////////////////////////////////////////////////////
11////////////////////////////////////////////////////////////////////////////////
12////////////////////////////////////////////////////////////////////////////////
13//  Dependencies
14#include <Windows.h>
15#include <intrin.h>
16#include "cpu_x86.h"
17namespace FeatureDetector{
18////////////////////////////////////////////////////////////////////////////////
19////////////////////////////////////////////////////////////////////////////////
20////////////////////////////////////////////////////////////////////////////////
21////////////////////////////////////////////////////////////////////////////////
22void cpu_x86::cpuid(int32_t out[4], int32_t x){
23    __cpuidex(out, x, 0);
24}
25__int64 xgetbv(unsigned int x){
26    return _xgetbv(x);
27}
28////////////////////////////////////////////////////////////////////////////////
29////////////////////////////////////////////////////////////////////////////////
30//  Detect 64-bit - Note that this snippet of code for detecting 64-bit has been copied from MSDN.
31typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
32BOOL IsWow64()
33{
34    BOOL bIsWow64 = FALSE;
35
36    LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
37        GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
38
39    if (NULL != fnIsWow64Process)
40    {
41        if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
42        {
43            printf("Error Detecting Operating System.\n");
44            printf("Defaulting to 32-bit OS.\n\n");
45            bIsWow64 = FALSE;
46        }
47    }
48    return bIsWow64;
49}
50bool cpu_x86::detect_OS_x64(){
51#ifdef _M_X64
52    return true;
53#else
54    return IsWow64() != 0;
55#endif
56}
57////////////////////////////////////////////////////////////////////////////////
58////////////////////////////////////////////////////////////////////////////////
59////////////////////////////////////////////////////////////////////////////////
60////////////////////////////////////////////////////////////////////////////////
61}
62