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

  • name99 - Wednesday, October 17, 2012 - link

    If you want to read non-technical reviews, there are a million other sites you can go to, from NYT and WSJ to Engadget and TheVerge.

    The WHOLE POINT of people reading Anand's reviews is to get tech details we don't get elsewhere.
    Perhaps as a followup you might want to suggest that John Siracusa in future limit his OSX reviews to a single letter-sized page?
  • rarson - Wednesday, October 17, 2012 - link

    No, it's not the "WHOLE POINT," the whole point is that reviews are reviews and tech articles are tech articles.
  • GotThumbs - Tuesday, October 16, 2012 - link

    "Those longing for an HTC One X or Galaxy S 3 sized device running iOS are out of luck. "

    I find it hard to believe there is even one person that is in this group. Apple's walled garden is mostly OS and portal based (Itunes).

    Especially with Apples maps being sub-standard.

    Please stick to facts.
  • A5 - Tuesday, October 16, 2012 - link

    If you don't want any editorial judgement or statements, there are plenty of places where you can just read a spec sheet and benchmark results.
  • Omophorus - Tuesday, October 16, 2012 - link

    I think the opposite is more likely... or at least I fall into that category.

    Mobile computing device aside, Android 4.0+ is shockingly much nicer to use (and this coming from a long time iPhone user) than iOS 5 or iOS6.

    If I could get the iPhone 5 handset, maybe with slightly better anodization, running Android 4.0+ I'd be in hog heaven.

    After playing with an iPhone 5, I really dig the hardware, but found the software woefully lacking.
  • crankerchick - Tuesday, October 16, 2012 - link

    I think you and the original commenter missed what the statement was saying. It said, "HTC One X or Galaxy S3 'sized' device..."

    Specifically, a larger screen iPhone, is where I think they were going with the statement, especially given the context of the paragraph where the statement was made.

    That said, I'm very much in the same camp as you. My number one device would be an iPhone-size and iPhone-build device running Android (but with a few tweaks since we are talking the ideal device). In fact, that is part of the reason I have an iPhone now and my Galaxy Nexus is sitting in a drawer by the bed--it's just too big and battery life is awful. I want a 4-4.2" 720p screen that doesn't have last year's hardware inside. The One S comes closest, but it's not on VZW to my knowledge, and it's still not "the best" hardware available, which you need with Android, especially on a manufacturer's skinned device.
  • perpetualdark - Monday, October 22, 2012 - link

    What about the Incredible 4g? I think this phone was overlooked because of it's proximity to the S3 release and the fact that the market is generally trending toward a nearly 5" display..

    I like this phone because it has the current generation of technology, is pretty darn thin, has a replaceable battery, has the 4" display (ie I am not holding a small tablet to my ear or carrying it in my pocket), and is, more importantly, android.

    Yes, the SLCD display may not be quite what the apple display is on paper, but to be perfectly honest, I have never noticed the differences.. Perhaps in a test environment, or to someone who calibrates displays all day, the Apple display would be better, I just don't see it.

    The s4 processor is not only fast, but plenty efficient, and the battery lasts easily 2 full days of heavy use. I can use it to read a kindle book for 6-8 hours over 2 days, talk a few hours, surf the web a few dozen times, text a few hundred texts, and even play games for an hour or two before I run out of battery. I have yet to go below 40% in one 24 hour period of time with the exception of using it with GPS and maps up.. the gps on 100% burns up the battery fast.

    gig of ram, 8 gigs on board storage, 32 more gigs with the sd card, etc, plenty of storage. 8 megapixal camera on back and a vga camera on front.
    ICS, LTE, Beats Audio, pretty much all the latest in tech..

    No, it can't quite compete with the S3, but it is pretty close to a One X in a 4" package and the closest thing to a One X you can get from Verizon, and honestly the phone that SHOULD be compared to the iphone5, given it is the only one with the current generation of hardware that is the same size. Sure, the iphone5 has an edge on the inc 4g in terms of tech specs, but when you add cost to the mix, the playing field is more level there as well, and to be honest, in real world applications the differences are going to amount to very small percentages.

    What people really want is a phone that fits their needs. Usually the most important things are screen size, OS preference, cost, and battery life. Performance is ONLY an issue when there is a problem with it.. Like when the iphone 4 dropped calls and couldn't do internet when you touched it.. The difference from the S4 to the A6 in real world application is a second or two in loading an app.. if even that.. most of my apps open instantly and with chrome and a good 4G connection I am betting that side by side loading web pages would be nearly identical. Specs are cool when comparing e-peen size but otherwise don't mean much in application.

    Not everyone is interested in big screens for a phone. Not everyone is interested in having a flexible OS. Not everyone is interested in the latest tech. Not everyone wants to spend a fortune on a phone that is, in practice, marginally better than what they have already. Not everyone is interested in bleeding edge technology. Sometimes you are looking for the phone that best suits YOUR needs. For me, that is an android platform, small form factor to fit in my front pocket comfortably as well as in my hand. A processor that was fast but power conservative. A battery that lasted a full day with reserve to spare, and could be used for 2 or 3 days if conserved well, AND could be swapped with a fully charged battery when travelling. I also like a phone that I can drop and scratch and not notice the dings and scratches.. since I put it in my pocket, I don't want to add a bulky case to keep it safe.. (I have dropped this phone dozens of times and 24" away you would never know it). I like to only pay $6.99 for insurance and be able to replace it if lost or stolen or broken for less than $100 ($12 per month for apple with $170 replacement deductible). And I like that I can use ANY micro-usb charger or cable to charge or connect to a computer. I don't have to buy any special adapters to make it work with my existing devices.

    Quite frankly, I think the difference between an android fan and an apple fan is that an android fan will not settle for the one device available to suit his needs, he will shop around to find the RIGHT one. If that happens to be an iphone, that is what he will get. But with dozens of models to choose from that are every bit as good if not better in every way that really matters, the chances of going with an iphone are pretty slim. An apple fan will settle for what is available and try to convince everyone around him that this one device will fit everyone's needs perfectly without exception.
  • crankerchick - Tuesday, October 16, 2012 - link

    I don't follow all the technicals like that, I'm more of an end user when it comes to mobile technology, but I think the trend towards the larger screens is more the MFRs pushing that a selling point (moar moar moar) to cover the fact that they can't fit the latest and greatest and cutting edge (NFC, quad core, LTE, etc) in the chassies of a 4" screen phone.

    Just my hunch. Wouldn't mind being schooled on this by someone in the know.
  • KPOM - Tuesday, October 16, 2012 - link

    I'd agree with that assessment. Apple was one of the last to move to 3G and one of the last to move to LTE because of battery life. The other manufacturers got around it by building thicker phones in the 3G era, and then with the LTE era started putting in bigger screens, which gave them room for bigger batteries (though the larger displays also required more power). It turned out enough people liked the bigger screens.

    Now that the power consumption levels are down, it will be interesting to see if others shrink their screens back down to Apple levels. The Galaxy SIII Mini is a half-hearted attempt, as it lacks LTE and has mediocre specs. But maybe someone else will take the bait.
  • rarson - Thursday, October 18, 2012 - link

    I feel like the iPhone 5 screen is actually too small (and I've heard complaints that the phone is too light, which I sort of agree with as well), but I think the Galaxy S3 is too big. I'm still using a Verizon Fascinate. It's got a bigger screen than the 5, but it's a bit smaller than the S2 and S3, perfect size. Thin but not too thin, and light but not too light. In fact, all I really want is a phone exactly like it, but with more power, better battery life, and maybe a slightly better screen (can't complain too much about the screen I already have).

    When I picked up the Fascinate, I knew it was the phone I wanted (helps that the price was only $50). When the S2 came out, I was excited to see it but disappointed by how much bigger the phone had gotten. I don't want a phone that I have to contort to get into my pocket. Apple's iPhone 5 is great in that respect, but after using this Fascinate for so long, its small size feels a bit cramped.

    I'd love to have the hardware of the Apple phone, but proprietary connectors and iOS are absolutely a no-go for me. I really don't care for iOS at all, because Android is so much easier to use.

Log in

Don't have an account? Sign up now