1

I am trying to get the cpusubtype of the device where my app is running . Is there any chance to only get the cpusubtype? Referring to this: Detect processor ArmV7 vs ArmV7s. Objective-C

sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);

Will it return numbers like 9,11,12,64 ? If yes can I then just use

if hw.cpusubtype(64){
//code for arm64
}
Community
  • 1
  • 1
user3452589
  • 39
  • 1
  • 7

1 Answers1

1

The code from the thread Detect processor ArmV7 vs ArmV7s. Objective-C that you linked to

int32_t value = 0;
size_t length = sizeof(value);
sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);

puts the CPU subtype into the value variable, so you would compare that with the subtypes defined in <mach/machine.h>, for example:

if (value == CPU_SUBTYPE_ARM_V7) {
    // ...        
}

But if your intention is to check if your app is running on a 32-bit or a 64-bit processor then you have to get the "cputype", and not "cpusubtype", as demonstrated here https://stackoverflow.com/a/20105134/1187415:

sysctlbyname("hw.cputype", &value, &length, NULL, 0);

if (value == CPU_TYPE_ARM64) {
    // ARM 64-bit CPU
} else if (value == CPU_TYPE_ARM) {
    // ARM 32-bit CPU
} else {
    // Something else.
}
Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Thank you for your help . The problem with "hw.cputype" is if the device is arm64 but still run the armv7 or amrv7s part of the app my code won't work . – user3452589 Mar 23 '14 at 18:16
  • @user3452589: Your question was how to detect the CPU subtype. If this does not answer your question then you have to provide more information about your actual problem. – Martin R Mar 23 '14 at 18:18
  • no everything is fine :) thank you again the first code is just fine because it can detect even the 7s , whats not possible with the second code . – user3452589 Mar 23 '14 at 18:28