Is there a way to detect VFP/NEON/Thumb/... on iOS at runtime?
Asked Answered
P

3

4

So it's fairly easy to figure out what kind of CPU an iOS device runs by querying sysctlbyname("hw.cpusubtype", ...), but there seems to be no obvious way to figure out what features the CPU actually has (think VFP, NEON, Thumb, ...). Can someone think of a way to do this?

Basically, what I need is something similar to getauxval(AT_HWCAP) on Linux/Android, which returns a bit mask of features supported by the CPU.

A few things to note:

  1. The information must be retrieved at runtime from the OS. No preprocessor defines.
  2. Fat binaries is not a solution. I really do need to know this stuff in an ARM v6 binary.

Thanks in advance!

Pennoncel answered 18/7, 2013 at 0:33 Comment(2)
I looked at man sysctl but did not find anything myself. The reason for fat binaries not being a solution is (a) it's a significant size increase (b) the decision of what architecture versions to use in apps is not actually made by me, but by customers. So if they choose to have an ARM v6 binary, that binary must work on v7 and v7s. Similarly, a fat binary with ARM v6 and v7s code must work on v7, and so on.Pennoncel
Given the very reasonable number of iOS devices, you may want to simplify your problem by documenting yourself on the available CPU features for each of them, list them, and simply detect which device you're on at runtime using the UIDevice class to retrieve the list of available features.Absorptance
H
3

sysctlbyname has “hw.optional.neon”. I do not see a name for VFP, except “hw.optional.vfp_shortvector”, which is a deprecated feature.

Husk answered 18/7, 2013 at 14:42 Comment(0)
B
1

Do a matrix float multiplaction via accelerate.framework and measure the execution time. The difference will be huge enough between Neon and VFP driven math, you simply cannot miss.

Thumb is always there, and the presence of NEON means armv7= Thumb2.

Bacteriophage answered 18/7, 2013 at 3:28 Comment(0)
B
0

First, consider carefully whether or not you really need to support armv6 binaries for iOS. According to published version share statistics, something like 98.5% of iOS devices are running iOS 5.0 or later, which does not support armv6 devices (armv6 binaries will still run on current iOS versions, obviously, but all new apps should really be targeting armv7; there’s basically zero reason for your customers to be shipping armv6 binaries for iOS today).

Similarly, your concerns about code size are misplaced. If you provide a fat library, and your customer builds an armv6 binary against it, only the armv6 bits of your library will be built into their application. Furthermore, code size is usually a nearly trivial fraction of application bundle size; most of the size of an application comes from other resources.

Ok. All that aside, if you really want to pursue this: VFP and thumb are supported on all iOS devices, so there’s no need to check for support. You can check for NEON and thumb-2 using the method that Eric Postpischil suggested (all armv7 iOS devices have NEON support, so availability of NEON coincides exactly with availability of thumb-2).

Byssus answered 18/7, 2013 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.