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

  • darwinosx - Tuesday, October 16, 2012 - link

    The iPhone 5 display is better than any current Android display.
    But Motorola and Android if you want a company that is dying and being sold and a copycat cheap phone with no service and support.
    Reply
  • V-Money - Tuesday, October 16, 2012 - link

    Your wisdom and informative argument adds tremendous value to this post. For the record though, the OP said specifically battery life and 720p display, so the response was relevant.

    The rest of your post is petty, get over yourself. If you are going to play the copycat card you should have done it before Apple decided to go with a bigger screen and use a (eerily similar) notification bar to what Android phones have had for years.

    As for quality (of display or otherwise), that is subjective analysis and considering that Apple only releases one phone at a time and Android manufacturers many, its a stupid argument for anyone to make. Case and point, I can find many android phones that are much more terrible than the iPhone, but I can also find many that are better. The iPhone is a decent phone, but its not for everyone. Every consumer has their preference.

    My point being there is not one-size-fits-all phone, so quit acting high and mighty with your close mindedness. You are not better than those around you because you bought into Apple's marketing, you are just a fool dealing with the first world problem of living such a meaningless existence that you have to hold on to the imaginary power an inanimate object pretends to give to you.
    Reply
  • Alucard291 - Tuesday, October 16, 2012 - link

    I feel that your argument may be too good for him to reply to :)

    He seems awfully angry :D
    Reply
  • crankerchick - Tuesday, October 16, 2012 - link

    Great reply. If there's one place I just want to exchange comments without playing the "my toy is better than yours" game, it's here on AnandTech. Reply
  • Gradly - Wednesday, October 17, 2012 - link

    I'm sick of ppl comparing iPhone to other devices. I'm sick of those telling you iPhone borrowed the notifications slider form android and skipping the myriad of things that other borrowed form iPhone. Apple has always said that "we are not the first but we do it the best". I'm sick of those who still don't realize that before iPhone ppl were living in caves actually.

    I'm an Apple lover not an Apple fanboy. I just adore the design, aesthetics, and GUI of Apple devices.
    Reply
  • Penti - Wednesday, October 17, 2012 - link

    It's sadly Apple that goes and patent UI-elements to use against their competitors that is why it's always brought up. It would be totally unnecessary otherwise. You might look at who's the inspiration otherwise and it's often not Apple. In reality we had capacitive touch screens (it's not Apples tech of course) before, app store before, Android even had an SDK out before Apple. Competitors like Symbian/Nokia, HP WebOS, and Blackberry are even allowed to use stuff like bounce back effect even without (or before) any agreement with Apple. They should have credit but they didn't all the sudden bring out their device with what we now call smartphone features, it lacked most functions at first and slowly iterated, it did a lot poorer in many areas then it's competitors was doing even before iPhone and the first few years it also showed in sales numbers which were not high at the first 2-3 years. It did show us how important a good platform was. Guys like Rubin had already figured that out though. So I'm not sure what they would borrow. Full WebKit-browsers on mobile is a good example of stuff they are co-developing but it was out in Nokia devices in 2006, netfront and Opera was never good alternatives to build into your platform. Stock Android don't have the bounce back effect, UI's looking like Apples and so on. Not even TouchWiz on Samsung's tablets looks like or infringes anything (design-wise) by Apple. They clearly have their own ideas. They are not the "me too", others might try to emulate them more in a business sense though. But they will be punished by the market by their execution instead of by Apple. It's not like any of the major players are fruit ninja-clones though.

    iPhone was desperately rudimentary at first. It didn't do applications and the web, messaging, photos etc better then anybody. What they did good was to iterate and improve. They take enterprise / corporate customers more seriously then Microsoft and so on in this field. Even if it took some time for them to get there. So they do plenty of good. It's a good platform, but it's not like they gave their competitors their blueprints for their devices / os of today back in 2007 and both have made many improvements. Well maybe not Microsoft but it takes a few years to start over. Apple has even got into hardware (components) a bit. Commoditization and convergence has reached far beyond the mobile field. That's great even if Apple won't enter them. Still don't know why any competitor would like to turn themselves into a retail giant and employ mostly store staff as Apple does – Microsoft should start doing what they are good at instead. Google would be the most evil company in the world if they had started to patent and sue based on UI-features and methods. Or if they really tried to stop Bing and Bing Maps (and getting it banned in some markets) for example. It doesn't really matter who was first and who invented what if you take it to court were that doesn't really count and that creates a lot of BS surrounding the whole issue and companies involved that is largely unnecessary. But the real silly thing is why they fight. It's not based on IPR, it's basically that they want to be alone in doing whatever, even if they can't really make that claim to have sole rights to something. But ultimately courts do get that under control even when corporate leaders turn to fighting outside of releasing product.
    Reply
  • slickr - Tuesday, October 16, 2012 - link

    LOL. Don't make me laugh. It has still the worst display and has had the worst display for at least 3 years. Reply
  • A5 - Tuesday, October 16, 2012 - link

    Your response is just as dumb as his. The iPhones have excellent displays. Reply
  • medi01 - Wednesday, October 17, 2012 - link

    None of the iPhones have anything to compare with AMOLEDs, on top of having idiotic resolution.

    On tablet space, only iPad 3 matched color gamut of THE FIRST Samsung Galaxy Tab.
    Reply
  • thunng8 - Wednesday, October 17, 2012 - link

    How does 67.5% of sRGB on the galaxy tab 10.1 match the 94.4% on the ipad 3?

    http://www.anandtech.com/show/5688/apple-ipad-2012...
    Reply

Log in

Don't have an account? Sign up now