

A few things iOS developers ought to know about the ARM architecture - credo
http://wanderingcoder.net/2010/07/19/ought-arm/

======
antichaos
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.

~~~
daeken
> \- 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).

------
daeken
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) << 4_. If you're commonly dealing with powers of
two, this is an absolute godsend.

~~~
ZPedro
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).

