0

When I run this I get that my system is 32-bit but I am running an Intel 7700k cpu which is a 64-bit even in control panel it says the windows arch is 64bit

#include <iostream>
#include <intrin.h>

using namespace std;

bool check_cpu()
{
    int CPUINFO[4] = {0};
    __cpuid(CPUINFO,0);
    bool b64 = (CPUINFO[3] & 0x20000000 ) || false;

    if (b64)
    {
        cout << "System is 64bit "<< endl;
        return b64;
    }
    else
    {
        cout << "System is 32bit "<< endl;
        return b64;
    }
}



int main()
{
    check_cpu();
    return 0;

}

what am I doing wrong here

loaded_dypper
  • 262
  • 3
  • 12
  • Assuming that the `0` in the `__cpuid` call is the value that gets passed in `eax` for the actual call, then `0` means "get vendor id". Have you checked the actual values returned in the `CPUINFO` array? – Some programmer dude Jan 20 '22 at 15:41
  • @Someprogrammerdude [Microsoft example](https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?redirectedfrom=MSDN&view=msvc-170) uses the same thing – loaded_dypper Jan 20 '22 at 15:44
  • Yes the example uses `0`. To get the vendor id. What resource or reference have you otherwise used? Where did you get this check from? – Some programmer dude Jan 20 '22 at 15:48
  • @Someprogrammerdude what do you suggest i do – loaded_dypper Jan 20 '22 at 15:49
  • [Detect 32-bit or 64-bit of Windows](https://stackoverflow.com/questions/7011071/detect-32-bit-or-64-bit-of-windows)? – Some programmer dude Jan 20 '22 at 15:51
  • Why do you think bit `0x20000000` of ECX returned from CPUID(0) implies 64 bit? Which documentation are you following to assume that? – Mike Vine Jan 20 '22 at 15:52
  • why do you use `bool b64 = (CPUINFO[3] & 0x20000000 ) || false` instead of `bool b64 = !!(CPUINFO[3] & 0x20000000)`? – phuclv Jan 20 '22 at 16:00
  • 2
    @phuclv Probably because double-negation like that is rather obscure, especially for beginners. – Some programmer dude Jan 20 '22 at 16:01
  • 2
    The checl `CPUINFO[3] & 0x20000000` seems to be correct, but the information required seems to be returned by `__cpuid(CPUINFO,0x80000001)`, not by `__cpuid(CPUINFO,0)`. – Martin Rosenau Jan 20 '22 at 16:01
  • @Someprogrammerdude but that's a "standard" way to convert to bool and is very commonly used in many places like the Linux kernel – phuclv Jan 20 '22 at 16:06
  • @MartinRosenau Yeah. With EAX=0 on the CPUID call, EDX (= `cpuInfo[3]`) will be the `ineI` characters from "GenuineIntel". – Adrian Mole Jan 20 '22 at 16:58
  • @phuclv And the linux kernel is the "standard" way to learn C(++) programming? – Sebastian Jan 20 '22 at 19:48

0 Answers0