Live data from Hacker News

A few things iOS developers ought to know about the ARM architecture

wanderingcoder.net

1–7 of 7 posts

Re: A few things iOS developers ought to know about the ARM architecture

#2
Key takeaways:

- ARM is a little-endian, 32-bit RISC architecture widely used by mobile devices.

- The original iPhone's core processor is ARM1176JZF-S (aka ARM11) which implements an instruction set called ARMv6.

- iPhone 3GS and later models use the Cortex A8 processor core that implements ARMv7, a newer instruction set.

- The so-called A4 processor is in fact a bundle of the Cortex A8 core and several other systems-on-a-chip components including the graphics accelerator and audio/video codecs.

- To take advantage of ARMv7 features while supporting ARMv6, your code must be compiled for both targets and put into a fat binary.

- When you debug optimized ARM code, remember that most ARM instructions can be conditionally executed -- the processor may go through a code block without actually running it.

- Thumb is a compressed subset of ARM instructions. 16-bit thumb code is generally smaller but can not be freely mixed with 32-bit uncompressed ARM code.

- Thumb for ARMv6 has a run-time overhead that makes it undesirable for high-performance apps; however, Thumb for ARMv7 has no such drawbacks and should be turned on by default.

- iOS supports unaligned memory access, but it's slooooow. Don't use it.

- Integer division on ARM is not natively supported. Surprise, surprise!

- GCC sucks at optimizing ARM code, particularly weak at 64-bit integer arithmetic.

Re: A few things iOS developers ought to know about the ARM architecture

#3

Key takeaways: - ARM is a little-endian, 32-bit RISC architecture widely used by mobile devices. - The original iPhone's core processor is ARM1176JZF-S (aka ARM11) which implements an instruction set called ARMv6. - iPhone 3GS and later models use the Cortex A8 processor core that implements ARMv7, a newer instruction set. - The so-called A4 processor is in fact a bundle of the Cortex A8 core and several other system…

[deleted]

Re: A few things iOS developers ought to know about the ARM architecture

#4
When I joined the iPhone dev team, about a week after the first iPhone came out, I came in as an experienced reverse-engineer on x86/PPC but had never touched ARM. Within a few weeks (after writing a dead simple decompiler, among other things), it became one of my favorite ISAs. Why? Conditional execution and free shifting.

They touch on conditional execution, but they don't really point out how amazing it is. It makes conditional math code, if nothing else, insanely simple and elegant, not to mention fast as hell.

As for the free shifts, I'm sort of amazed they aren't touched on in the article -- they make life very easy. In ARM, you can do a shift on the result of most instructions. E.g. you can do add r0, r1, r2, LSL #4, which is equivalent to r0 = (r1 + r2) . If you're commonly dealing with powers of two, this is an absolute godsend.

Re: A few things iOS developers ought to know about the ARM architecture

#5

Key takeaways: - ARM is a little-endian, 32-bit RISC architecture widely used by mobile devices. - The original iPhone's core processor is ARM1176JZF-S (aka ARM11) which implements an instruction set called ARMv6. - iPhone 3GS and later models use the Cortex A8 processor core that implements ARMv7, a newer instruction set. - The so-called A4 processor is in fact a bundle of the Cortex A8 core and several other system…

> - ARM is a little-endian, 32-bit RISC architecture widely used by mobile devices.

Gotta make a small note here: ARM is bi-endian (bytesexual, if you will); you can toggle the endianness from the lowest level. It just happens that iOS uses it as little endian. I seem to remember the baseband chip (which is also an ARM core, at least with the original iPhone -- never dealt with the others) being big endian, in fact.

Sadly, you can't do this on a per-process level, IIRC, like you can with PowerPC (a huuuuge perk for emulators).

Re: A few things iOS developers ought to know about the ARM architecture

#6
post #3

Key takeaways: - ARM is a little-endian, 32-bit RISC architecture widely used by mobile devices. - The original iPhone's core processor is ARM1176JZF-S (aka ARM11) which implements an instruction set called ARMv6. - iPhone 3GS and later models use the Cortex A8 processor core that implements ARMv7, a newer instruction set. - The so-called A4 processor is in fact a bundle of the Cortex A8 core and several other system…

[deleted]

that is pretty common, for example Intel's (Marvell's now IIRC) PXA (i.e. Xscale) is not exactly SoC but still includes NOR flash die in same package.

Re: A few things iOS developers ought to know about the ARM architecture

#7
post #4

When I joined the iPhone dev team, about a week after the first iPhone came out, I came in as an experienced reverse-engineer on x86/PPC but had never touched ARM. Within a few weeks (after writing a dead simple decompiler, among other things), it became one of my favorite ISAs. Why? Conditional execution and free shifting. They touch on conditional execution, but they don't really point out how amazing it is. It mak…

Ah, a kindred spirit, I too am an assembly/ISA buff. However, if you pay attention you'll notice that this article is precisely not for ISA buffs: as I've written, I wouldn't have mentioned conditional execution if not for the debugging side effect. It is aimed at ordinary iOS developers who may be carrying assumptions from desktop architectures and not realize some ARM specificities that may impact them; I titled it "[…]things iOS developers ought to know[…]", not "hey, did you know about that cool thing?". Hence why I didn't mention free shifting (and it's the second operand that can be shaf-- er, shifted, IIRC).