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
Comments Locked

276 Comments

View All Comments

  • youwonder - Wednesday, October 17, 2012 - link

    I find it kind of ...odd that the S3 has a much larger battery than the one X and the same SoC yet posts significantly worse LTE browsing numbers, and is the only phone using LTE to get worse results with it than using 3G(granted that is the international vers, doesn't look like they had time to do testing on the AT&T or verizon variant running 3G). Does the samoled screen really draw THAT much more power than an LCD? also there's this which makes me wonder more:

    http://blogs.which.co.uk/technology/smartphones/be...

    Of course, I don't respect these guys as much as anandtech when it comes to accurate results, and they did things much differently (broadcasting their own 3g signal and putting all phones on max brightness), but still the odd results here make me wonder if a small mistake wasn't made.
  • Zink - Wednesday, October 17, 2012 - link

    Max brightness gives the gs3 an advantage because its screen is so dim. The other phones are using LED lighting as well but they go much brighter and have to shine through the LCD panel.
  • youwonder - Wednesday, October 17, 2012 - link

    Good point, I guess it's mostly just me wondering why the GS3 LTE variant posts such horrible numbers even compared to it's 3G version when anand specs a good amount of time explaining why the opposite is true.
  • phillyry - Sunday, October 21, 2012 - link

    Don't know why but it does tank on LTE.
  • rarson - Wednesday, October 17, 2012 - link

    I'm getting so sick and tired of seeing the word "literally" injected into all sorts of sentences that it doesn't belong in. This word only needs to be used when describing something literal. It's not a synonym for "really" (not yet, anyway).
  • andykins - Wednesday, October 17, 2012 - link

    Alright, language purist. :P
  • joos2000 - Thursday, October 18, 2012 - link

    http://theoatmeal.com/comics/literally
  • phillyry - Sunday, October 21, 2012 - link

    Great link. That's too funny - literally!
  • dfonseca - Wednesday, October 17, 2012 - link

    On the last page, section "Final Words" / "iPhone 5 Device Conclusions", it's written:

    > At a high level, the iPhone 5’s cameras appeared to be some of the least unchanged elements of the new device however in practice the improvements are significant.

    "Least unchanged" means "most changed." It should probably say "most unchanged," or "least changed."

    Nice review, kudos to all authors.
  • mattlach - Wednesday, October 17, 2012 - link

    I had the original iPhone, followed by the iPhone 3G and then the iPhone 4, and just switched to a Samsung Galaxy S3 in July.

    When the original iPhone came out, while it was the first to do what it did - and that's why I bought it at its steep no-contract introductory price - it wasn't exactly revolutionary, everything in the market was moving in this direction, but it was pretty well executed and nothing else did it at the time.

    I upgraded to the 3G on launch, as I thought the edge speeds were dreadful, but was disappointed, as the phone wasn't fast enough to take advantage of 3G, and AT&T's 3G was pretty mediocre anyway. It didn't get important features its competitors had, like copy and paste until very late in the game, and I started to think that I should have gotten an Android phone instead.

    By the time I got the iPhone 4, I was tired of my slow 3G experience and just wanted an upgrade to something faster. The iPhone 4 was a good upgrade, but I really only got it because I didn't like AT&T's Android offerings at the time. I had been thinking about going to Verizon and getting an Android for some time. The 3G should have been my last iPhone, it was a mistake to buy the 4.

    Having realized my mistake, I waited 2 long years with the 4 until I could finally get out of my AT&T contract and go to Verizon and get a GS3, and it felt great.

    The additional freedom of what I run on my phone, not being controlled by Apple and their agenda as to what makes it into the App store, and the fact that I finally no longer had to have iTunes installed on my computer were fantastic.

    My computer has been iTunes free for 3 months now, and it feels great!

    I was concerned for a while that once the iPhone 5 was released, they would come out with something that would make me regret my choice of the GS3, but it turns out they didn't.

    I'll likely never buy anything Apple again. It feels like a huge relief to say that.

Log in

Don't have an account? Sign up now