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

  • A5 - Tuesday, October 16, 2012 - link

    I don't think there's a good way to measure storage performance on the iPhone. Also not really sure why it matters.
  • repoman27 - Tuesday, October 16, 2012 - link

    I timed how long it took to transfer my music library, and clocked 11.1 MB/s writing to the user area of a 64GB model. So no significant change from previous iPhones, and still pretty typical for a smartphone. I'd be interested to get some gauge of the read speeds.

    And @A5, storage performance affects boot and application load times as well as sync and backup. With a 64GB model, syncing can take quite a while.
  • name99 - Wednesday, October 17, 2012 - link

    Transferring the music library is a LOUSY choice for speed measurement because (depending on your iTunes settings) you may be transcoding all your music to a lower bit rate to fit more on the iPhone; so you are gated by the transcoding performance, not the flash write speeds. I transcode my music (most in Apple lossless on my iMac) to 192kbps AAC for my iDevices, and on my ancient iMac it is the transcoding that throttles performance.

    A much better situation to look at is transferring large movies. On my devices
    - iPhone 4 writes at about 18MB/s
    - iPad3 writes at about 22MB/s

    Over the last 6 months Anand occasionally has published flash numbers for Android phones and they're generally around half these Apple numbers.
  • repoman27 - Wednesday, October 17, 2012 - link

    Believe you me, I don't allow iTunes to transcode anything, except to ALAC on occasion. But yes, that number I gave was on the low side, but probably more due to it being thousands of files as opposed to one large sequential write.

    I just transferred a large video file back and forth directly to and from the user storage area of one of my apps, and came up with numbers that are more in line with yours. 23.84 MB/s avg read and 20.05 avg write.

    Most MLC NAND modules capable of 20 MB/s writes should be able to do at least 40 MB/s on sequential reads, which leads me to believe that we're still gated to around 25 MB/s by the NAND interface here, which is kinda bogus.
  • Spunjji - Friday, October 19, 2012 - link

    name99, that is not a "better situation" because the performance figures you quote only apply to large block file transfers. It's no more real-world than the figures repoman quoted, which are not "LOUSY". Both are valid, so ideally a proper test should mix both types of data.

    Furthermore, the idea that your admittedly ancient iMac being crap at transcoding MP3s somehow invalidates somebody else's testing is ridiculous as well. With any decent system that would only be the case if you were shifting data to a device a *lot* faster than any smartphone NAND.

    So, you may need to rethink your "victory" a little more.
  • KPOM - Wednesday, October 17, 2012 - link

    I've had my iPhone since 9/22 and there is not a single scuff on it. My guess is that in the rush, some units got through QC, but the phone itself isn't any more prone to scratching in normal use than other phones. Meanwhile, Apple being Apple, they have held up production to improve QC even if it means fewer sales in the short run.
  • rarson - Wednesday, October 17, 2012 - link

    You've had it less than a month. There shouldn't be any scuffs on it.

    "Apple being Apple"

    Ha! That's a good one!
  • Spunjji - Friday, October 19, 2012 - link

    Trololololol

    "Mine is fine so everyone else is lying". <- Possibly my favourite bogus argument ever. Apple the generous indeed...
  • doobydoo - Saturday, October 20, 2012 - link

    Because it's so much more compelling than the 'Mine is scratched so everyone elses must be'?
  • lukarak - Wednesday, October 17, 2012 - link

    But it doesn't rust. It scratches if it comes in contact with something harder. Just as a car does. Would you buy a car that gets a scratched bumper when you hit a wall? Well, maybe you wouldn't but people do. Regularly.

    This iPhone is no different than every other iPad, MBP or MBA or the first Al MB. Or any other device constructed from aluminium. They scratch if they are brushed against something. It's just normal.

Log in

Don't have an account? Sign up now