Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone detecting processor model / NEON support

I'm looking for a way to differentiate at runtime between devices equipped with the new ARM processor (such as iPhone 3GS and some iPods 3G) and devices equipped with the old ARM processors. I know I can use uname() to determine the device model, but as only some of the iPod touches 3G received a boost in their ARM processor, this isn't enough.

Therefore, I'm looking for one of these:

  1. A way of detecting processor model - I suppose there's none.
  2. A way of determining whether ARM neon instructions are supported - from this I could derive an answer.
  3. A way of determining the devices total storage size - combining this with the already known device model could hackishly lead me to the answer.
  4. < ENTER RANDOM IDEA >

Thanks in advance :)

like image 233
yonilevy Avatar asked Oct 21 '09 13:10

yonilevy


Video Answer


1 Answers

Not exactly what you're asking, but one easy solution is to build your application fat, so that it contains executable code for both ARMv6 and ARMv7. If you do this, the appropriate code will run on the processor automatically, and you don't need to do any runtime checking. Effectively, you're letting the loader do the runtime detection for you.

To do this, change the Architectures setting in your XCode project from "Standard (armv6)" to "Optimized (armv6 armv7)"

Then, in your implementation, you do this:

#if defined __ARM_NEON__
    // Code that uses NEON goes here
#else  // defined __ARM_NEON__
    // Fallback code without NEON goes here
#endif // defined __ARM_NEON__

There is a similar macro that you can use to check for (non NEON) ARMv7 features, which I can't remember off the top of my head.

If you really want to do runtime dispatch, take a look at the sysctlbyname function in libc. Specifically, I think that looking up the HW_MACHINE_ARCH parameter may prove useful to you.

like image 136
Stephen Canon Avatar answered Nov 25 '22 15:11

Stephen Canon