https://bytecellar.com/2022/11/16/a-secret-apple-silicon-extension-to-accommodate-an-intel-8080-artifact/ Click here to skip to main content ByteCellar Logo - "4K Scaling" Is Not a Problem on Modern Macs A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact Posted on November 16, 2022 by Blake Patterson Lately I've been spending time on Mastodon for ... reasons. Here's my link: https://oldbytes.space/@blakespot. In my recently active time on the platform, I have found quite a few excellent retrocomputing posts by creative members of the community. One such post, by Dougall , links to his blog post entitled "Why is Rosetta 2 fast?". Apple M1 Max die Rosetta 2 is the ahead-of-time compile translator that's part of macOS Big Sur (and later) that, upon launch of an x64 Intel binary, translates it to 64-bit ARM code for execution on ARM-based Apple Silicon processors before execution. It is not a real-time emulator. It translates the entire binary -- once -- at launch time, making best-guess choices along the way. Dougall delves into various aspects of Rosetta 2 in an effort to explain why it is so performant; in many instances the translated binary runs faster on Apple Silicon than on the fastest Intel machines that Apple has ever released. It's impressive. It's a fascinating read for a tech nerd like me that has a particular interest in OS technology. But one detail of the post really grabbed my attention. Apple's secret extension There are only a handful of different instructions that account for 90% of all operations executed, and, near the top of that list are addition and subtraction. On ARM these can optionally set the four-bit NZVC register, whereas on x86 these always set six flag bits: CF, ZF, SF and OF (which correspond well-enough to NZVC), as well as PF (the parity flag) and AF (the adjust flag). Emulating the last two in software is possible (and seems to be supported by Rosetta 2 for Linux), but can be rather expensive. Most software won't notice if you get these wrong, but some software will. The Apple M1 has an undocumented extension that, when enabled, ensures instructions like ADDS, SUBS and CMP compute PF and AF and store them as bits 26 and 27 of NZCV respectively, providing accurate emulation with no performance penalty. Intrigued by mention of this "secret extension," I reached out to the author and asked if he could expand on what Apple has done here. And, he obliged. As he explained in his multi-part Mastodon response: So, both the "adjust flag" (AF) and the "parity flag" (PF) come from the 8080-family CPUs from the 1970s. Today they're almost completely unused. The parity flag is set if, in the last eight bits of the result, the number of set-bits is odd. Otherwise, it's cleared. The adjust flag is set if there's a "carry out" from the low four-bits of the addition (and otherwise cleared). This was used for binary-coded decimal - that flag would indicate a carry from one 4-bit digit to the next. Both these flags are computed on every ADD or SUB instruction (extremely often), and 64-bit ARM has no such functionality. For example, to compute the parity flag on ARM, a subtraction turns into something like: subs w4, w4, w5 dup v24.16b, w4 cnt v23.16b, v24.16b umov w22, v24.b[0] and w22, w22, #1 That's a lot of work for one subtraction (5x as many instructions), and that's not all of it - we didn't compute AF. But it's not really a lot of work for Intel - in every x86 CPU, they just build some logic that computes both AF and PF at the same time as doing the subtraction. So, since Apple design their own CPUs, they decided to also build this logic. When running Rosetta 2, the CPU is configured to enable this functionality (since it'd break the ARM specification to have it enabled all the time). With that set Rosetta 2 does: subs w4, w4, w5 And both flags are computed for it by the hardware. Rosetta 2 can also run in Linux VMs on Apple Silicon. In a VM, it isn't able to configured the host CPU, so it can't use this functionality. There are two other options. Either, you can skip computing the flags, because they're mostly useless and most software won't care. Or you can compute them the long way shown above. Rosetta 2 chooses the second option, and this mostly works out fine, because they have an "unused flags" optimisation that avoids the computation a lot of the time. This fascinated me. While few modern applications likely read these AF and PF bits, Apple -- who make their own CPUs and can control the entire process -- put in place a hardware step to increase performance when running translated x64 code on their own processors. I love it. Apple's move here demonstrates the benefits of their position in controlling all aspects of the systems. A generic Snapdragon ARM SoC, say, would deliver notably less performance in this specific scenario -- getting non-native apps running solid and fast during this transition period -- that is critically important to Mac users. I relish such minor details as this in the engineering of next generation hardware and wanted to share them with readers who might find a similar appreciation. It puts me in mind of some of the very use-case-specific innovations needed by Microsoft -- but not Sony (and vice versa) -- in the fascinating tale of the joint creation of the common PowerPC core used in the Sony PS3 and the Xbox 360 as told in Shippy & Phipps' excellent book, The Race for a New Game Machine: Creating the Chips Inside the XBox 360 and the Playstation 3. Dougall Johnson, who provided this insight into the M1 and family, is driving an effort to reverse engineer and document the Apple G13 GPU architecture (used by the M1) as well as to document the Apple Firestorm/Icestorm CPU microarchitecture. His work towards these ends can be found on GitHub at these respective links: Apple GPU, Apple CPU. This entry was posted in Macintosh, OS and tagged Apple, ARM, M1, M2, x86. Bookmark the permalink. - "4K Scaling" Is Not a Problem on Modern Macs 6 Responses to A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact 1. [3102] Grammar Nazi says: November 17, 2022 at 12:29 PM Performant is not a word. Reply + [7cdc] Birdman3131 says: November 17, 2022 at 12:55 PM https://dictionary.cambridge.org/us/dictionary/english/ performant It sure seems like Cambridge disagrees with you. Reply + [24d9] ryan says: November 17, 2022 at 1:24 PM Was that as embarrassing as it looked? Reply 2. Pingback: Revealed: Apple Silicon Accommodates Intel 8080 via Secret Extension - RB Webcity 3. Pingback: Revealed: Apple Silicon Accommodates Intel 8080 via Secret Extension - Mist Vista 4. Pingback: Apple Silicon Supports 48-Year-Old Intel 8080 via Secret Extension - Infowire Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment * [ ] Name * [ ] Email * [ ] Website [ ] [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] Info + Blakespot.com + "The List" + Panorama of the "Byte Cellar" + "Today in the Byte Cellar..." + My BBS Resource Page + The Geek photo gallery + Blake's Flickr photostream + Blake's iOS Device Specifications Grid + My vinyl LPs + Recommended Reading + Blake's Retro RSS Feed OPML + RSS/XML Feed Kudos to Byte Cellar + Boing Boing: No Man's Sky as a Commodore Amiga slideshow + VG24/7: Sean Murray impressed by No Man's Sky on Amiga computer + Hack A Day: BBSing with the ESP8266 + Retro Gamer mag: On Being Featured in Retro Gamer's "Collector's Corner" + Polygon: Meet the guy who spent over $4,000 on No Man's Sky + NewEgg- HardBoiled: The Science Behind 3 Inspiring PC Battlestations + PC Mag: 7 Amazing Vintage Computer Collections + CNN HLN: Inside the 'Byte Cellar': 30 years with Apple [Archive] + Forbes: Steve Jobs In The Flesh + Lifehacker: The Byte Cellar: A Geeked-Out Ode to Computers and Video Games + Engadget: Blake Patterson's Byte Cellar: the ultimate man cave for aspiring geeks + PC World: The Byte Cellar Is the Ultimate Geek Dream Den + Gadget Review: The "Byte Cellar" Contains 122 Video Game Machines + The Games Shed: Retro Gaming Collections - Blake Patterson - The Retro Story Guy + Apartment Therapy: Blake's Byte Cellar Workstation With 4 Different Monitors + CNN (video): Apple's Mac Turns 25 + Engadget: Apple IIc as a Serial terminal to a Mac Mini + Newton Poetry: Profile: Blake Patterson of 'Touch Arcade' + TUAW: Flickr Find: Digital Steve Jobs on a bookshelf [Archive] + Cult of Mac: Steve Jobs left an imprint on tech and the skin of some devoted fans Random Post Show me ! * Search for: [ ] [Search] * Recent Posts + A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + "4K Scaling" Is Not a Problem on Modern Macs + An Apple II Tale Told Complete by the Late Tony Diaz + Microsoft Sunsets Amiga's Killer App: Internet Explorer + Fun With System Power Monitoring on the Apple IIe + A Colorful "Peek" at the Graphics Performance of the Apple II + BBSing in the Snow Is the Best Way to Login + Have a Helping of 8-bit Holiday Cheer! (2021 Edition) + Parceiro: An Extraordinary Upgrade for Amiga 1000 Users + About the Personalized, Cut Wood Apple Logo Sign from 1984 + Full Motion, Double High-Res Video Playback on the Apple IIe + Have a Helping of 8-bit Holiday Cheer! (2020 Edition) + VidHD and "Total Replay": Two Great Tastes That Taste Great Together! + I Sit at the Round Table (And Dance Whene'er I'm Able) + Looking Back on 35 Years as an Amiga User + The Infinity Modules Player: Never Turn Off Your Amiga Again + Apple //c Scene From '80s Bond Film "A View to a Kill" Perfectly Re-Created With Applesoft BASIC + The eMate 300 Out In Front for "BBS Week V" + Firing Up the Apple //c for "Not x86 Week" + Announcing "NMSspot" - My New "No Man's Sky" Blog * Recent Comments + Apple Silicon Supports 48-Year-Old Intel 8080 via Secret Extension - Infowire on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + ryan on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + Revealed: Apple Silicon Accommodates Intel 8080 via Secret Extension - Mist Vista on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + Birdman3131 on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + Revealed: Apple Silicon Accommodates Intel 8080 via Secret Extension - RB Webcity on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + Grammar Nazi on A Secret Apple Silicon Extension to Accommodate an Intel 8080 Artifact + Vini on "4K Scaling" Is Not a Problem on Modern Macs + Tom Bailey on An Apple II Tale Told Complete by the Late Tony Diaz + Bill on A Look Back at Three Decades of Word Processors + CD on "4K Scaling" Is Not a Problem on Modern Macs * Categories + Acorn + Amiga + Apple + Apple II + Atari + BBS + Commodore 64/128 + DOS / Win PC + Down Memory Lane + Gaming + Handhelds + Holidays + HP + iOS + Just Rambling + Lisa + Macintosh + Multi-Platform + News + NeXT + No Man's Sky + OS + Other Platform + Quickie + r/Retrobattlestations + Serial Terminal + SGI + Tandy / TRS-80 + TI-99 + Uncategorized + UNIX + Windows + ZX Spectrum * Links + Nostalgic Virginian + Blakespot.com + TouchArcade + wwwtxt + 20011 + Blake's iOS Device Specifications Grid + No Man's Sky Foundation (v1.1) Help Links + RSS / XML Feed + NMSspot * Archives + November 2022 + October 2022 + June 2022 + March 2022 + January 2022 + December 2021 + July 2021 + May 2021 + December 2020 + November 2020 + October 2020 + August 2020 + April 2020 + February 2020 + January 2020 + December 2019 + November 2019 + October 2019 + September 2019 + July 2019 + May 2019 + April 2019 + March 2019 + February 2019 + January 2019 + December 2018 + November 2018 + October 2018 + September 2018 + August 2018 + July 2018 + June 2018 + May 2018 + April 2018 + March 2018 + January 2018 + December 2017 + October 2017 + August 2017 + June 2017 + May 2017 + March 2017 + February 2017 + January 2017 + December 2016 + November 2016 + October 2016 + September 2016 + August 2016 + July 2016 + June 2016 + May 2016 + April 2016 + March 2016 + February 2016 + December 2015 + November 2015 + October 2015 + September 2015 + August 2015 + July 2015 + June 2015 + April 2015 + March 2015 + February 2015 + January 2015 + December 2014 + November 2014 + September 2014 + August 2014 + July 2014 + June 2014 + May 2014 + March 2014 + February 2014 + January 2014 + December 2013 + November 2013 + October 2013 + September 2013 + August 2013 + June 2013 + May 2013 + April 2013 + March 2013 + February 2013 + November 2012 + October 2012 + September 2012 + August 2012 + July 2012 + March 2012 + February 2012 + January 2012 + December 2011 + November 2011 + October 2011 + August 2011 + July 2011 + June 2011 + May 2011 + April 2011 + March 2011 + February 2011 + January 2011 + December 2010 + June 2010 + January 2010 + December 2009 + November 2009 + September 2009 + August 2009 + May 2009 + March 2009 + January 2009 + November 2008 + October 2008 + August 2008 + July 2008 + June 2008 + May 2008 + April 2008 + March 2008 + February 2008 + January 2008 + December 2007 + November 2007 + October 2007 + September 2007 + August 2007 + July 2007 + June 2007 + May 2007 + April 2007 + March 2007 + February 2007 + January 2007 + December 2006 + November 2006 + October 2006 + September 2006 + August 2006 + July 2006 + April 2006 + March 2006 + February 2006 + January 2006 + December 2005 + November 2005 + October 2005 + September 2005 + August 2005 + July 2005 + June 2005 + April 2005 + February 2005 + January 2005 + December 2004 + November 2004 + October 2004 + August 2004 + June 2004 + May 2004 + April 2004 + March 2004 Navigation for GeekRing.net, the webring that this blog is part of. ----------------------------------------------------------------- Byte Cellar. Contact me, Blake Patterson, at blakespot@ Google's mail service...