Apple's Swift: Pipeline Depth & Memory Latency

Section by Anand Shimpi

For the first time since the iPhone's introduction in 2007, Apple is shipping a smartphone with a CPU clock frequency greater than 1GHz. The Cortex A8 in the iPhone 3GS hit 600MHz, while the iPhone 4 took it to 800MHz. With the iPhone 4S, Apple chose to maintain the same 800MHz operating frequency as it moved to dual-Cortex A9s. Staying true to its namesake, Swift runs at a maximum frequency of 1.3GHz as implemented in the iPhone 5's A6 SoC. Note that it's quite likely the 4th generation iPad will implement an even higher clocked version (1.5GHz being an obvious target).

Clock speed alone doesn't tell us everything we need to know about performance. Deeper pipelines can easily boost clock speed but come with steep penalties for mispredicted branches. ARM's Cortex A8 featured a 13 stage pipeline, while the Cortex A9 moved down to only 8 stages while maintining similar clock speeds. Reducing pipeline depth without sacrificing clock speed contributed greatly to the Cortex A9's tangible increase in performance. The Cortex A15 moves to a fairly deep 15 stage pipeline, while Krait is a bit more conservative at 11 stages. Intel's Atom has the deepest pipeline (ironically enough) at 16 stages.

To find out where Swift falls in all of this I wrote two different codepaths. The first featured an easily predictable branch that should almost always be taken. The second codepath featured a fairly unpredictable branch. Branch predictors work by looking at branch history - branches with predictable history should be, well, easy to predict while the opposite is true for branches with a more varied past. This time I measured latency in clocks for the main code loop:

Branch Prediction Code
  Apple A3 (Cortex A8 @ 600MHz Apple A5 (2 x Cortex A9 @ 800MHz Apple A6 (2 x Swift @ 1300MHz
Easy Branch 14 clocks 9 clocks 12 clocks
Hard Branch 70 clocks 48 clocks 73 clocks

The hard branch involves more compares and some division (I'm basically branching on odd vs. even values of an incremented variable) so the loop takes much longer to execute, but note the dramatic increase in cycle count between the Cortex A9 and Swift/Cortex A8. If I'm understanding this data correctly it looks like the mispredict penalty for Swift is around 50% longer than for ARM's Cortex A9, and very close to the Cortex A8. Based on this data I would peg Swift's pipeline depth at around 12 stages, very similar to Qualcomm's Krait and just shy of ARM's Cortex A8.

Note that despite the significant increase in pipeline depth Apple appears to have been able to keep IPC, at worst, constant (remember back to our scaled Geekbench scores - Swift never lost to a 1.3GHz Cortex A9). The obvious explanation there is a significant improvement in branch prediction accuracy, which any good chip designer would focus on when increasing pipeline depth like this. Very good work on Apple's part.

The remaining aspect of Swift that we have yet to quantify is memory latency. From our iPhone 5 performance preview we already know there's a tremendous increase in memory bandwidth to the CPU cores, but as the external memory interface remains at 64-bits wide all of the changes must be internal to the cache and memory controllers. I went back to Nirdhar's iOS test vehicle and wrote some new code, this time to access a large data array whose size I could vary. I created an array of a finite size and added numbers stored in the array. I increased the array size and measured the relationship between array size and code latency. With enough data points I should get a good idea of cache and memory latency for Swift compared to Apple's implementation of the Cortex A8 and A9.

At relatively small data structure sizes Swift appears to be a bit quicker than the Cortex A8/A9, but there's near convergence around 4 - 16KB. Take a look at what happens once we grow beyond the 32KB L1 data cache of these chips. Swift manages around half the latency for running this code as the Cortex A9 (the Cortex A8 has a 256KB L2 cache so its latency shoots up much sooner). Even at very large array sizes Swift's latency is improved substantially. Note that this data is substantiated by all of the other iOS memory benchmarks we've seen. A quick look at Geekbench's memory and stream tests show huge improvements in bandwidth utilization:

Couple the dedicated load/store port with a much lower latency memory subsystem and you get 2.5 - 3.2x the memory performance of the iPhone 4S. It's the changes to the memory subsystem that really enable Swift's performance.

 

Apple's Swift: Visualized Six Generations of iPhones: Performance Compared
POST A COMMENT

278 Comments

View All Comments

  • doobydoo - Friday, October 19, 2012 - link

    'Right, so if you have good vision, like I do, then at a foot away, you can see those pixels.'

    If you can see that then you would also be capable of observing that the SG3 doesn't have full pixels, it uses a PenTile display which overall has fewer sub pixels over a greater area than the iPhone 5 screen, making it both absolutely lower quality and relatively lower quality per area.
    Reply
  • KoolAidMan1 - Friday, October 19, 2012 - link

    You can discern individual pixels on an iPhone 5 display?

    Lies.
    Reply
  • dsumanik - Wednesday, October 17, 2012 - link

    Im sure this guy said the same thing when the 4 came out...3.5 was "big enough"

    Just watch when apple adds an even bigger screen he will be saying it is "perfect"

    The problem with iSheeps is that they need to get out there and actually use a different phone from a different ecosystem for a month, then switch back.

    Apple's devices are well built and tightly integrated, but there are serious shortcomings, drawbacks, and flaws that you will notice once you return to the platform.

    That said,

    Personally i purchase apple products due to the insanely high resale value, which allows me to keep up with new gear on a yearly basis for a reasonable price.

    Sent from my iphone 5
    Reply
  • khurtwilliams - Thursday, October 18, 2012 - link

    "iSheeps"? Must you resort to name calling to make your point? Reply
  • rarson - Thursday, October 18, 2012 - link

    "Personally i purchase apple products due to the insanely high resale value, which allows me to keep up with new gear on a yearly basis for a reasonable price."

    I don't see it. Maybe if you buy the newest thing as soon as it comes out and sell your old last-gen device that most people are still happy with, then you're selling it for a decent amount, but you're still spending way more money than any reasonable person would. There's absolutely no monetary argument to buy Apple products, because if money is your concern, then you shouldn't be buying them in the first place.

    Apple's phone prices are much closer in line with their hardware; for laptops and desktops, the resale value argument goes WAY out of whack.
    Reply
  • darwiniandude - Friday, October 19, 2012 - link

    I bought an early 2011 MBP last year for $2650 AUD. got a high res screen option etc. I heard rumours of the retina model and sold it just before the 12 months was up so the new purchaser still had a little warranty me could buy AppleCare if they wished. I sold it for $2300 AUD. This means I lost $350 over the year, it cost me $350 to have that machine for a year. I didn't buy AppleCare ($429 AUD) either.
    The retina model came out, and retailed for $2499 AUD

    I've been doing this since my first Mac, in 2006. I can't believe the crazy used prices on Macs especially if they are still current model and about a year old. I pay about $300-$400 a year to have the latest and greatest and a machine that is always in warranty. If I bought a cheap PC notebook for $400 I'd be suffering with an underpowered plastic machine with little ram, no SSD, and it might last more than a year but I wouldn't be happy with it anyway. Each to their own. I could never stay current with PCs because a year later the system was next to worthless, even if I'd put a $1000 video card in it at the time. (I now, reluctantly, game on consoles or a little in bootcamp)
    Reply
  • david22 - Thursday, October 18, 2012 - link

    "there are serious shortcomings, drawbacks, and flaws"

    So what are they?

    The problem with trolls is that they just spout bull.
    Reply
  • MobiusStrip - Friday, October 19, 2012 - link

    Apple refuses to pull its head out of its ass or LEARN. One profound impediment to making iOS devices useful is Apple's ridiculous fear, which you can see in its crippled SDK. One example: the lack of developer access to the dock port.

    But then there is just plain stupidity. There's no excuse for bullshit like this: http://goldmanosi.blogspot.com/2012/06/will-apple-...
    Reply
  • darwiniandude - Friday, October 19, 2012 - link

    Um, when someone calls me and I miss the call, iPhone shows a missed call. Then my carrier (Telstra) sends me a text message "You have a missed call from 0412xxxxxx" then "Please call 101 you have 1 new voicemail(s)"
    I get multiple alerts for both those SMS messages.
    Reply
  • rex251 - Sunday, October 21, 2012 - link

    Why going all the way in calling people that like apple products as sheeps?
    I think you should accept the fact that some people like small phones, and maybe like small smartphones, which neither iphone5 or sgs3 are.
    From my perspective iphone 4/4s screen was maximum I would go with something called phone into my pocket, but I do not, instead finding xperia mini great sized, although too thick.
    My point, why would we have to considere as progress only bigger screen phones as such, we do have plenty of tablets to pick from for that usage?
    Reply

Log in

Don't have an account? Sign up now