Slashdot Mirror


Mac OS X Built For CISC, Not RISC

WCityMike writes "One of the programmers at Unsanity, maker of haxies, recently posted a rather shocking relevation on the company's weblog. He says that Mac OS X's Mach-O runtime ABI (Application Binary Interface) comes from a NeXTStep design for 68K processorts, and is not designed for the PowerPC architechture. Had they used the latter, things would have been approximately 10-12 percent faster. And supposedly, they can't fix it now without breaking all existing applications." The developer mentions there are workarounds in the newest GCC, but only for newly compiled programs.

82 comments

  1. the return of "fat" binaries? by tps12 · · Score: 4, Funny

    This is good news for long-time Mac fans. Back in the day ("the day" was 1994 or so, IIRC) we Mac users took seeking out the correct 68k or PPC binaries as a sign of our superiority to PC users. While Windozers happily downloaded software that would run on circa 1987 hardware, we enlightened ones could narrow our searches to programs specifically compiled for our platforms. We could even get "fat" binaries, and optionally remove the unneeded binary code using a small freeware app.

    With OS X, I had hoped we would again have a situation where just using the Mac required that extra step of compatibility checking, setting us apart from the drooling masses of Gates-worshippers. Sadly, with the Classic compatibility layer, it did not come to pass. Hopefully this revelation will set things aright.

    --

    Karma: Good (despite my invention of the Karma: sig)
  2. Future by Zephy · · Score: 0, Flamebait

    Maybe Apple Are Anticipating a Move to A CISC style processor in the future?

    1. Re:Future by trash+eighty · · Score: 5, Funny

      yeah can't wait for my new 68040 ubermac ;)

    2. Re:Future by Quixotic+Raindrop · · Score: 1

      *ahem* Silly TRS80, that Ubermac will probably be based on a Pentium. *shudder*

      Nah, couldn't be. Steve Jobs still thinks that Moore is a Moore-On, and that Andy Grove guy is just plain stupid. He'd never allow Apple to move to the Pentium ... would he?

      --
      Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Einstein)
    3. Re:Future by Anonymous Coward · · Score: 0

      Read the article, it's most likely a relic from the NeXT days not properly ported over to save lots of time.

    4. Re:Future by cappadocius · · Score: 3, Funny

      Wait, does this mean I could potentially run OS X on my Mac Classic? Time to move out goldfish.

      --

      omnia tua castra sunt nobis

  3. Now we know why it was so slow, right? by Nutrimentia · · Score: 4, Funny

    But tell me, if they could slide a PPC ABI in with the new journaling system update, couldn't they just get the performance hit and gain to cancel out? It'd be like journalling system for free! How hard can it be? 10.2.5 maybe?

  4. what's it going to be like w/ the 970? by banky · · Score: 5, Interesting

    Read World Tech talks about the 970 in depth... I wonder how the addition of 64-bit arch AND the 32-bit compat mode will affect things.

    Like the Itanium, with its poor backwards compat performance? Or will it be speedy?

    --
    ZOMG I WOULD LOVE TO KNOW ABOUT YOUR FEELINGS ON MACINTOSH VERSUS WINDOWS, VI VERSUS EMACS, AND HOW YOU'RE NOT A DORK
    1. Re:what's it going to be like w/ the 970? by ianpatt · · Score: 3, Informative

      A 64-bit PowerPC chip doesn't need to "emulate" anything to run 32-bit code, unlike the Itanium, which uses completely different instructions. There should be no speed hit: the only real difference is that the CPU can perform calculations using all 64 bits. This also won't remove the speed hit caused by the ABI.

    2. Re:what's it going to be like w/ the 970? by Lars+T. · · Score: 5, Informative
      From The PowerPC Compiler Writer's Guide (warning: PDF):
      Both 32-bit and 64-bit implementations support most of the instructions defined by the PowerPC architecture. The 64-bit implementations support all the application instructions supported 32-bit implementations as well as the following application instructions: [...]

      The 64-bit implementations have two modes of operation determined by the 64-bit mode (SF) bit in the Machine State Register: 64-bit mode (SF set to 1) and 32-bit mode (SF cleared to 0), for compatibility with 32-bit implementations. Application code for 32-bit implementations executes without modification on 64-bit implementations running in 32-bit mode, yielding identical results. All 64-bit implementation instructions are available in both modes. Identical instructions, however, may produce different results in 32-bit and 64-bit modes:

      Addressing--Although effective addresses in 64-bit implementations have 64 bits, in 32-bit mode, the high-order 32 bits are ignored during data access and set to zero during instruction fetching. This modification of the high-order bits of the address might produce an unexpected jump following the transition from 64-bit mode to 32-bit mode. Status Bits--The register result of arithmetic and logical instructions is independent of mode, but setting of status bits depends on the mode. In particular, recording, carry-bit-setting, or overflow-bit-setting instruction forms write the status bits relative to the mode. Changing the mode in the middle of a code sequence that depends on one of these status bits can lead to unexpected results. Count Register--The entire 64-bit value in the Count Register of a 64-bit implementation is decremented, even though conditional branches in 32-bit mode only test the low-order 32 bits for zero.
      IOW, even if they use "32-bit compat mode", there should be now speed penalty whatsoever.
      --

      Lars T.

      To the guy who modded me down from perfect to terrible Karma - Apple haters still suck

  5. i have a funny feeling that by paradesign · · Score: 4, Insightful

    that apple knows what their doing, and probably had a very good reason or doing what they did. I mean its not like they havent had the past four years to change it or anything, but whatever.

    --
    I want 2D games back.
    1. Re:i have a funny feeling that by mikedaisey · · Score: 5, Insightful


      I would agree with you, but this is a legacy decision that would have saved them crucial months early in the OSX creation process...so I can just as easily see them making the choice then, to get a shipping system out the door, THEN discovering that OSX's biggest problem is that it isn't fast enough, and now trying to retrofit a solution. That matches all the information I've gleaned from mac sites in the past.

      It sucks, but if they hadn't gotten X out the door when they did Apple would have been dead in the water--it was already horrendously late for those who started waiting for Copland.

    2. Re:i have a funny feeling that by Anonymous Coward · · Score: 1, Insightful

      ... And I would agree with you, except no programmer worth a cent will ever wait until the last minute to wonder if his OS is fast enough. A good programmer will ALWAYS assume his OS is NEVER fast enough.

      But yes, this sounds like a 'hi, we're from NextStep, we're going to save you' attitude. The detail got lost in the fury and the excitement. That's what it sounds like at any rate. Sure they thought about it; but by now they know they didn't think about it 'right'.

    3. Re:i have a funny feeling that by exp(pi*sqrt(163)) · · Score: 1

      I have a feeling they don't know. Look how fast MacOS X does 2D rendering and you'll see that they are a little lacking in the optimization department. Even with Quartz Extreme the performance can be painfully slow as it draws things like Postscript documents.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    4. Re:i have a funny feeling that by GreatDave · · Score: 1

      The fact that Darwin appears to have a CISC-oriented design begs the hunch that Apple doesn't want to tie themselves to the MPPC platform. This could mean one of two things:

      1) Apple wants to ensure that should Motorola ever tank on them, they have the ability to port OS X to a wider range of processors, and/or

      2) Apple has specific possible platforms for OS X in mind in the future. x86 immediately comes to mind. Granted, this is a rumor that has run its course a million times over, but don't jump to conclusions. This may not mean an OS X port to x86. Looking at OS X and its multiple APIs (Carbon, Cocoa, Classic, "native Java"...) perhaps Apple may be plotting to roll out some sort of cross-platform API that would enable Mac OS X apps to run on, say, Windows. Support for such an API close to the kernel, as Apple would be capable of producing, would make such an API much faster on the Mac than, say, applications based on certain browser cum cross-platform COM system.

      Just some speculation here.

      --
      "I am root. Bow before me." To this I say, "You are root, and you bear the sins of the world upon your shoulders."
  6. In Case Unsanity Gets /.ed by mikedaisey · · Score: 2, Informative


    Here is the text:

    Unsanity.org
    October 21, 2002
    Mach-O ABI

    Here I go again, ranting about Mac OS X bowels. This time I want to talk about particular implementation details of Mach-O runtime ABI (Application Binary Interface). Before you get too confused, there are two different things under the 'Mach-O' name:

    * Mach-O ABI, which defines how every application in the system executes and calls functions (stack conventions, register usage, and more);
    * Mach-O File Format, which defines a way for compiled executables to store different parts of them in the same file (compiled code, data, strings, etc).

    The latter is not what I want to talk about today; the first is what puzzles me most. I admit I am just a "small programmer" with no relationship with the powers-that-be at Apple at all (this means, no insider contacts who can explain the reasoning behind the particular important design decisions to me), so my impressions, judgements and guesses expressed in this article may be slightly or totally off the mark. I, however, as many other developers who have dug deep into the implementation of such things, can see obvious drawbacks and oddities about Mach-O ABI, and this is what I am going to talk about.

    Mach-O originates from NeXTstep, an operating system created at NeXT for its NeXTstation machines, and later expanded to x86 hardware. NeXTstations were originally based on Motorola 68k CPUs, just like old Macintoshes. Mac OS (classic), on the other hand, used an ABI for PowerPC which followed the ABI principles defined in a document by IBM/Moto for PPC processors. So as you all may already know, m68k and x86 are CISC architectures; PowerPC used in all new Macs is RISC.

    To make a long story short, Mac OS X uses an ABI designed for CISC processors, mostly ignoring RISC design principles.

    What do I mean by that? Mach-O ABI we see now used in Mac OS X is more or less a direct port of NeXT's Mach-O designed for m68k - it relies on PC (program counter) register to perform various manipulations with data (for the geeks: PC-relative addressing). There's nothing wrong with that, as its an effective and common practice, except for one little thing: there is no PC register in RISC processors (programmatically accessible). That is not a show-stopper though - Mach-O for PowerPC just takes one of 32 general purpose registers and turns it into a program counter-style register, to base all offset calculations off it. That works well, as you can see, as all of Mac OS X applications (except for the ones compiled with Carbon/CFM) use the Mach-O ABI.

    That approach works well, except for one small thing: global/static data access adds about 7 cycle overhead per function, and about triple of that for cross-context calls (that is for the G4 class processor) compared to the old, Mac OS Classic ABI (excuse me for the geek talk). Mac OS Classic CFM ABI, in comparison, needed almost 0 cycles for static data access and about 5 for cross-context calls. To rephrase - applications in Mac OS X could be faster, if the Mach-O ABI followed the principles set for the PowerPC chip, and not the ones created over a decade ago for CISC ones.

    This brings us the question, "how much faster would the applications be if the ABI was done right?". The answer is, according to some tests done by my friends at #macdev IRC channel, the speed gain would be 10-30%, depending on each particular application (how often does it calls functions). Realistically, the speed gain would be around 10 to 12 per cent (how do I get these numbers, below).

    So why did Apple used an outdated ABI for a modern operating system? Frankly, I don't know the reason. About the best one I have heard - it saved Apple a few months in the Mac OS X development time so they didn't have to do massive updates to its NeXT-derived tool chain.

    There are signs of change though -- the recent update to GCC, the compiler shipped with OSX, allows it to perform so-called -mdynamic-no-pic optimization, which hard-codes the data addresses in the code, so the result is roughly equivalent to the CFM ABI used in Mac OS Classic -- so the GCC itself, compiled with that optimization, is 10% faster. Applications, to take advantage of that, need to be recompiled, so it doesn't affect 80% of the titles already shipped for Mac OS X. Then again, the optimization above only works for executables and not shared libraries.

    Either way, there is no way to change the ABI now, as it would break all of the existing applications - which is obviously not what Apple (or us) would want.

    And after all, who cares about a 10% speed loss? You can always get a faster Mac, right?

    Further reading:
    Mach-O Runtime Architecture [developer.apple.com]
    CFM-Based Runtime Architecture [developer.apple.com]

    Thanks to #macdev regulars and an anonymous Apple engineer for helping me with this article.

    Update 10/21: fixed a few phrases in the text to make it more clear; I've also been told OPENstep runs on RISC processors (non-PowerPC) - however, I have not investigated how the Mach-O ABI works there - quite possible it obeys the PowerPC guidelines, although I am pretty sure it does the same as on PowerPC.
    Posted by slava at October 21, 2002 03:40 AM

    1. Re:In Case Unsanity Gets /.ed by anarkhos · · Score: 2, Interesting

      If Apple would just use CFM/PEF natively we woudln't need the PEF shim crap for PEF Carbon apps.

      I mean where does Apple go from here? Do they create a 3rd spec so they have to upkeep two non-native formats? Will they have to create three sets of libraries or shims?

      Not very forward-thinking Apple.

      --
      >80 column hard wrapped e-mail is not a sign of intelligent
      >life
  7. I have known this for months by Leimy · · Score: 5, Insightful

    Uhm... This is news? I am not shocked at all. In order to get the product out sooner rather than later they stuck with the old ABI that was used for Motorola 68k[probably wrong but I have had no coffee yet]. Anyway some people say that the performance loss as a result of this "corner cutting" may be up to 7 cycles per function call which just means we should all write our code as inlines and macros :).

    Just kidding.... Anyway it may or may not be easy/hard to fix... the problem is now that its out there changing the ABI [the C ABI !!! the way functions get called and parameters get passed] is going to break everything. Maybe they can fix it but not at a significant cost to 3rd party software... I could be wrong and not have thought this out well enough though.

    1. Re:I have known this for months by Paradise+Pete · · Score: 1, Funny
      Uhm... This is news?

      Sorry Leimy. didn't realize you'd known about this and therefore it shouldn't have been posted. Slashdot editors, in the future please check with this guy before posting any stories.

    2. Re:I have known this for months by Leimy · · Score: 3, Interesting

      Anyone who has been paying much attention around the web should/would have been able to read this information elsewhere just like me :). There are MANY people who knew of this problem existed well before the release of Jaguar.

      Perhaps because I look into things and try to tinker and understand them as well as do silly things like assembly language programming I picked up on this sooner than others. This isn't news to a lot of people I hang with... :)

      Sorry if I came off sounding arrogant :)

    3. Re:I have known this for months by Anonymous Coward · · Score: 2, Insightful

      >Anyone who has been paying much attention around the web should/would have been able to read this information elsewhere just like me :).

      This can be said about ANYTHING and EVERYTHING that gets posted to Slashdot. Why don't we just close down the site, call it a day, and stop wasting our time? Google, after all is all we need, right.

      Yeah...any-way. Consider that the stories themselves are only half of what makes Slashdot an interesting place. I come for the DISCUSSION more than the stories.

      >This isn't news to a lot of people I hang with... :)

      I hate to break it to you, but the people who read Slashdot are a lot more diverse than just the people you happen to hang with. I come here for the occasional interesting science article (and the DISCUSSION that follows). I don't know shit about CS, although I'm interested in computers, and particularly Macs. This is the first I've heard of this issue (I'm sure loads of other Slashbots can say the same. I may not ever have heard about this issue if it wasn't for this Slashdot story. Please accept my formal apology.

      >Sorry if I came off sounding arrogant :)

      You did. You're forgiven. Don't let it happen again.

      -ac

    4. Re:I have known this for months by Anonymous Coward · · Score: 0

      Jesus Christ man... you come here for the discussion but you haven't contributed anything useful... So what if this guy came off as arrogant?

      At least he had something good to contribute :) All you are doing is criticizing people

      Your overly sarcastic toungue in cheek bullshit is quite annoying and I wish you'd stop. This guy probably just wishes he didn't use the subject line he did. Notice the content of his message isn't that arrogant at all.

      "don't let it happen again!"... Are you fuckin kidding? This is slashdot! Good luck to you

    5. Re:I have known this for months by Anonymous Coward · · Score: 0

      >Jesus Christ man... you come here for the discussion but you haven't contributed anything useful...

      How the fuck do you know. I posted that response as AC. You don't have a clue who I am or what I've posted on /. now or in the past.

      >All you are doing is criticizing people. Your overly sarcastic toungue in cheek bullshit is quite annoying and I wish you'd stop.

      1) You are doing the same in your post so shut your hole. 2) Are YOU fuckin' kidding? This is slashdot! Kiss my ass.

      >"don't let it happen again!"... Are you fuckin kidding? This is slashdot! Good luck to you

      WTF? It's sarcasm man! I'm tempted to say you've been trolled (because that's basically the spirit in which I wrote that remark).

      fuckwit.

      -ac

  8. Yay! FUD! by Anonymous Coward · · Score: 5, Insightful

    And supposedly, they can't fix it now without breaking all existing applications.

    There is no reason that an operating system can't support multiple ABIs. That means that New applications wouldn't work on older versions of the OS, but it certainly doesn't mean that they can't fix the "problem" without breaking current applications.

    1. Re:Yay! FUD! by anarkhos · · Score: 2, Informative

      So what ABI will the libraries use?

      Supporting an extra ABI isn't difficult at the execution level provided you have a separate set of libraries or shims like they do for PEF binaries now. That's also how you can run 32 and 64bit apps on the same system.

      But what now? Another set of shims?

      The whole situation is ridiculous. They should use PEF/CFM natively.

      --
      >80 column hard wrapped e-mail is not a sign of intelligent
      >life
  9. Only if Mac == Motorola by jafuser · · Score: 3, Insightful

    Who says they need to "fix" it? Perhaps Motorola may be losing a big customer in the future... I've heard from more than one source now that big changes may be coming in Mac hardware... Absolutely all rumors of course, but this fact fits in nicely with what I've already heard...

    --
    Please consider making an automatic monthly recurring donation to the EFF
  10. Wonder if they tried to keep it a secret? by LeapingGnomeArs · · Score: 0, Interesting

    I wonder if Apple tried to keep this secret and this is the reason they kept so many of their APIs and underlying OSX undocumented? I think Apple is none too happy with Unsanity right now and might purposefully break their haxies with their next update, guess we'll wait and see. :)

    1. Re:Wonder if they tried to keep it a secret? by MarkX · · Score: 5, Insightful

      Seeing as the systems incorporates Darwin which is open source I don't really think they could keep this a secret. Anyone can download Darwin and see the implementation of the ABI. Also they have been using GCC for some time and the implementation of the ABI would also be exposed there.

      At the fundamental levels of OS X, below the GUI, there is very little that Apple can dissemble about. It is OSS. Anyone can download it and read the code.

      MarkX

    2. Re:Wonder if they tried to keep it a secret? by Dougal · · Score: 2, Informative

      > I wonder if Apple tried to keep this secret...

      No. The ABI is documented with the developer tools - without it you'd have to try and reverse engineer it from existing binaries to write assembly code.

    3. Re:Wonder if they tried to keep it a secret? by anarkhos · · Score: 1

      Note that their CFM/PEF compatibility layer isn't in Darwin. I wonder how inefficient THAT is!

      --
      >80 column hard wrapped e-mail is not a sign of intelligent
      >life
    4. Re:Wonder if they tried to keep it a secret? by Aqua+OS+X · · Score: 2

      Not only that, but a vast amount of OS X is open source.

      --
      "Things are more moderner than before- bigger, and yet smaller- it's computers-- San Dimas High School football RULES!"
  11. a likely manner in which this will be corrected... by constantnormal · · Score: 5, Interesting

    While I am in complete agreement that it was originally done this way in the interests of expediency, we can all see a point very soon where the instruction set will be in a (minor/major?) state of upheaval -- when they revamp OS X for 64-bit operation on the IBM 970 chipset.

    However, it's not quite as easy as rolling it into that architecture, as they wil probably rely of the 32-bit PPC compatibility mode of the 970 to bring along a lot of the existing baggage, ruling out a wholesale conversion to another API. Which means they will either implement a foundation to migrate toward the new API, or invoke yet another API (probably 64-bit 970 only) that uses the appropriate model. Either way, it will be some years (if ever, as we can still code 68X apps using an API from decades ago that run under emulation on OS X) before we see an efficient API in widespread use.

    In any event, they will certainly retain a CISC-oriented API in the OS X stable of architectures, if only to be able to continue to wave the specter of an open source OS X on X86 in front of Microsoft, as sort of a "mutual assured destruction" weapon to prevent Microsoft from wiping them out, and possibly as a negotiating tool in keeping Microsoft coding for the Mac.

    But -- since Apple is pretty well (apparently) hamstrung on making great strides in hardware performance over the next year or so, maybe they will push the software changes as the next best way to get needed speed. It wouldn't be the first time Apple capriciously honked off developers by changing all the rules and rendering years of development obsolete.

    And the whole thing may be moot, as it appears that one can get equivalent performance improvement by compiling with gcc3.

  12. Re:a likely manner in which this will be corrected by Anonymous Coward · · Score: 3, Informative

    Keep in mind that gcc3 optimizations mentioned would only affect applications, *not* the dynamic shared libraries, which are a significant part of the OS (think /System/Library/Frameworks)

  13. Some tweaking req'd by BoomerSooner · · Score: 5, Insightful

    The tweaking is at the Kernel/OS level so applications can run without modification (in theory). My guess is some apps will need patches while others will be okay. A perfect example of this is apps that run under 10.0 and 10.1 but not 10.2.

    With the speed of current and future processors the delivery of a stable OS is preferable to a 3 year late, and tweaked OS that runs the same things just a little faster.

    1. Re:Some tweaking req'd by bobdotorg · · Score: 3, Funny

      With the speed of current and future processors the delivery of a stable OS is preferable to a 3 year late, and tweaked OS that runs the same things just a little faster.


      Exactly. When Copeland comes out it's gonna be smokin'.

      --
      __ Someday, but not this morning, I'll finally learn to use the preview button.
    2. Re:Some tweaking req'd by MalleusEBHC · · Score: 2

      I believe the reason why some apps will run under 10.0.x and 10.1.x but not Jaguar is the change to a new version of gcc. I think before Jaguar it was gcc 2.9.something and now it's gcc 3.1(.1?). In reality, the fact that Apple was able to pull off such a switch relatively flawlessly is amazing and most people don't realize it.

    3. Re:Some tweaking req'd by WatertonMan · · Score: 1

      What always amazes me are the kinds of apps that break. Typically they *aren't* ones that ought to be doing low level stuff. I mean perhaps they are relying on questionable libraries. But still. The typical "high level" app shouldn't be breaking as one moves from 10.0 to 10.1 to 10.2.

  14. Possibly fixed with a 64-bit OS X? by kuwan · · Score: 5, Interesting

    It seems that Apple could easily correct this when they update OS X for a 64-bit chip (namely the PowerPC 970). Applications will need to be recompiled to be 64-bit anyway, so why not update the ABI in the process? It would certainly be incentive for developers to update their apps...

    Imagine:

    Apple:"Update your apps to 64-bit and see a 10% performance gain."

    (Of course most apps really won't need to be 64-bit, but this would be incentive for developers to update them and users to buy new machines.)

    As for Carbon, it states in the article that only Mach-o binaries use the CISC-style ABI, Carbon is not affected and uses a PowerPC-style ABI. This could be a way to "prove" his theory that you could get a 10-12% performance increase. Build two test apps, one in Cocoa and one in Carbon and then compare them to see if there really is a 10-12% speed difference.

    1. Re:Possibly fixed with a 64-bit OS X? by Anonymous Coward · · Score: 1, Informative
      As for Carbon, it states in the article that only Mach-o binaries use the CISC-style ABI, Carbon is not affected and uses a PowerPC-style ABI. This could be a way to "prove" his theory that you could get a 10-12% performance increase. Build two test apps, one in Cocoa and one in Carbon and then compare them to see if there really is a 10-12% speed difference.
      Wrong. Carbon CFM Apps (only CodeWarrior and MPW can make these) don't use Mach-O when calling functions INSIDE themselves. They use some Mach-o CFM glue when calling functions in the system libraries. Carbon Mach-O apps (like iTunes 3.0) still use Mach-O
  15. Yeah, an open sourced "secret" by BoomerSooner · · Score: 4, Insightful

    The code is open source and the gcc 3 code is open source. It doesn't appear to me they are hiding anything.

  16. I'm confused by nadador · · Score: 2

    This leads me to believe that PowerPC does run of the mill PC-relative addressing, so that, for example, branches only take one instruction width, rather than having to store an entire 32-bit address in another location, etc. I'm confused by the purpose of the article, but I think the point was that PC-relative addressing forces the compiler to compute the address of a branch target in a function call to a fully-linked part of the binary. I don't think that address computation of that sort is responsible for a 10-15% performance hit, because wouldn't full time absolute addressing require more memory access on the already saturated MPX bus? If I'm incorrect in this, please tell me, and I will look for more information.

    --

    Outside of a dog, a book is a man's best friend. Inside a dog, its too dark to read.
    1. Re:I'm confused by nadador · · Score: 5, Informative

      It just so happens that I friend of mine has a copy of "PowerPC Mircoprocessor Family: Programming Environments for 32-bit Microprocessors" sitting on his desk, which I grabbed. Here is how PowerPC processors branch (from sectino 4.2.4.1 of said dead-tree document):

      1. Branch relative addressing mode - the immediate displacement operand is sign exteneded and added to the current instruction address to produce the branch target address. So, PC relative addressing. There is no need for a programmatically accessible program counter because this is all done by the branch execution unit. Single 32-bit instruction.

      2. Branch conditional to relative addressing mode - same as branch relative addressing, except that the branch is only executed if the proper condition codes are set. Single 32-bit instruction.

      3. Branch to absolute addressing - the operand address is sign extended and used as the branch target. As the name implies, this is absolute addressing. Only problem is, the operand address is only 23 bits wide in a 32-bit implementation, and with the zero pad, it gives only 25 bits of absolute address (word alignment required). So, if you absolute address anything, you can only absolute address 25 bits worth of the address space.

      4. Branch conditional to absolute - same as regular absolute addressing, except that you have to encode condition codes, so the operand address is nowo only 13 bits if I read the diagrams correctly, meaning that you can only absolutely address 15 bits of address space with the zero pad.

      5. Branch conditional to link register - if you clobber the link register, you can branch to a 32-bit address. Of course, you have to clobble the link register, so I would think this would be most helpful in returning from a function call, not going to it, since the link register holds the return address. And if you use it forward instead of returning, you have to load the link register.

      6. Branch conditional to count register - same as link register branching as above.

      All of that said, the reason that the Mac OS ABI uses PC relative addressing is because the only way to fully address a 32-bit address space is to do PC relative addressing. According to this book, there is no two instruction width branch, eg a branch instruction which encodes an entire 32-bit absolute address in two 32-bit words (one word for branch encoding and condition codes, one word for the whole 32-bit address).

      This leads me to believe that there is no way to do all absolute addressing on PowerPC unless you implement new instructions (which will take more time to get to the processor, and to decode) or limit yourself to 15 or 25 bits of the address space.

      So, the short version is that that there is no way for the Mac OS ABI to do absolute addressing.

      --

      Outside of a dog, a book is a man's best friend. Inside a dog, its too dark to read.
    2. Re:I'm confused by Anonymous Coward · · Score: 1, Insightful

      Its not about branching. Its about data references using PC relative addressing. The PowerPC has no PC relative data addressing modes.

    3. Re:I'm confused by nadador · · Score: 4, Interesting

      > Its not about branching. Its about data references using PC relative addressing. The PowerPC has no PC relative data addressing modes.

      Point taken. Section 4.2.3.1 of the same book is "Integer load and store address generation".

      1. Register indirect with immediate index addressing for integer loads and stores - In this case, you get a 16-bit index in the instruction added to the value in a general purpose register, which is used to compute the effective address.

      2. Register indirect with index addressing for integer loads and stores - this is the same as above, except that two registers are used and there is no encoded index.

      3. Register indirect addressing integer loads and stores - use just one general purpose register as an address for a load or store.

      So, the point is that in every case, some form of relative addressing is used. In order to make relocatable code, ie code that can be linked happily with other binary objects, you have to have some sort of reference address, and PC-relative addressing is the only way to do this.

      Even though there is no PC-relative addressing mode, the only way to guarentee that the relative addresses used in different object files won't clash is to do PC-relative. The fact that this is not easy on the PowerPC doesn't make it any less necessary.

      --

      Outside of a dog, a book is a man's best friend. Inside a dog, its too dark to read.
    4. Re:I'm confused by Anonymous Coward · · Score: 5, Informative

      > So, the point is that in every case, some form of relative addressing is used. In order to make relocatable code, ie code that can be linked happily with other binary objects, you have to have some sort of reference address, and PC-relative addressing is the only way to do this.

      This is wrong. The PowerPC ABI, as defined by IBM, uses r2 as a TOC (Table of Contents) pointer. The PC is never needed or used as all data space references are made relative to the TOC, not the PC. Apart from being faster, this has several other advantages, not the least of which is that one copy of code can have multiple data contexts without involving VM.

      int foo;
      int bar(void) { return foo; }

      with macho:
      _bar:
      mflr r0,lr
      bl *+4
      mflr r2
      mtlr r0
      addis r3,r2,ha16(foo)
      lwz r3,lo16(foo)(r3)
      blr

      with IBM conventions:
      .bar:
      lwz r3,foo(rTOC)
      blr

    5. Re:I'm confused by nadador · · Score: 2

      Cool. I agree. I was wrong.

      --

      Outside of a dog, a book is a man's best friend. Inside a dog, its too dark to read.
    6. Re:I'm confused by clem.dickey · · Score: 5, Interesting

      (The parent needs to be modded up. He may be an AC, but his information is accurate.)

      One problem with TOC is that is you are limited to 16K external addresses. Offset "foo" in the TOC example is 16 bits, and the low two are zero. With 64-bit addressing I suppose that drops to 8K externals.

      Another characteristic calling a separately compiled function requires that you load a different TOC. The PC-relative scheme requires that you load one value: the PC; the TOC scheme requires that you load two new values: the new PC and the new TOC.

      On the plus side, TOC makes shared libraries easier to manage because external addresses are bound to a non-shared data area.

    7. Re:I'm confused by norwoodites · · Score: 2

      Actually it is 64K and still 64K in 64bit because you can load from unaligned locations and in 64 bit PPC the instructions are still the same.

    8. Re:I'm confused by clem.dickey · · Score: 2
      Actually it is 64K and still 64K in 64bit because you can load from unaligned locations

      But the TOC entries are addresses, which are 4 or 8 bytes long. Unless you manage to find addresses which can overlap due to common bit patterns, you have to divide the 64K maximum TOC size (the offset of an lwz instriction is 16 bits long) by 4 or 8.

      As for alignment, section 6.4.6.1 here indicates that one response to unaligned integers is an alignment exception. So you can load unaligned, and the PowerPC may fix things up in hardware, but if it doesn't your O/S is expected to simulate the instruction.
    9. Re:I'm confused by norwoodites · · Score: 2

      but you still get 64Kbytes of memory though. Because a byte is one address, you only get 16*2^10 words or 8*2^10 dual words though. It is still 64Kbytes. Any way you can load in 8bits at a time using lbz, so you get 64Kb of memory.

  17. "processorts?" by Doktor+Memory · · Score: 3, Funny

    Millions of dollars in burned money from VA-Linux, thousands of man-hours invested in slashcode, untold numbers of CPUs and hard drives sacrificed to the cause, and slashdot's editors/maintainers still can't be bothered to put a spellchecker into their story posting system.

    Why, exactly, do they expect people to pay money for this again?

    --

    News for Nerds. Stuff that Matters? Like hell.

    1. Re:"processorts?" by zman99 · · Score: 2, Funny

      can't be bothered to put a spellchecker into their story posting system.

      Get yourself a machine to run OSX on and every app written in cocoa can spell check every text entry field. (including my web browser)

      -Z
      --
      Tolerance does not tolerate intolerance, or hypocrisy.
  18. Some ways to get away from PIC code by norwoodites · · Score: 5, Informative

    1. Don't use externs or static variables.
    2. If you are going to use an extern variable in a tight loop, don't use a local variable and assign it after the loop.
    3. Pass the option -mdyanmic-no-pic to gcc if the source is in the final program because it does not work in a boundle or a dynamic library (or framework).

    The AIX ABI/PEF ABI uses a register called the TOC for PIC code but it is stored with the function reference so you lose one register if the Darwin ABI goes over to the PEF ABI. You get one more register to play around with if you do not use extern or static variables.

    1. Re:Some ways to get away from PIC code by norwoodites · · Score: 2

      I forgot to mention that strings count as static variables unless gcc optimizes it a way.

  19. Of Babies and Bath Water. by JQuick · · Score: 5, Insightful
    Before jumping to conclusions and flinching lest we be struck by the falling sky, let's take a step back.

    First look at the most crucial benefits of the runtime environment. Mach supports an efficient and flexible framework for multiple memory objects. Objc leverages this by supporting the efficient mapping and unmapping of new bundles.

    You may think of a bundle as a set of related objects in a language like Java, but don't take that analogy too far. The concepts of delegation, and protocols, usually mean that different bundles of code have clean interfaces that do not require recompilation when one or the other changes. Sometimes even knowledge of each other's type is irrelevant.

    In any case, the best design for objc applications is a collection of separate UI definitions or nib files, and one or more libraries of code which are searched and loaded as needed at runtime.

    Statically linked code, is more efficient for some tasks, but in the context of good objc design does not fit very well. Text which is statically linked is more fragile, it must be recompiled more often. It can also take more time to initialize and load; using late binding and lazy loading, only the sections to text and definitions of objects actually called will be mapped in memory.

    Position independent code is absolutely needed for this kind of flexibility at runtime. The gcc compiler grew up on CISC, on 32 bit or 16 architectures. Position independent code, had to be relative to something, and the most commonly useful location was always "You are here", the program counter.

    I'm not sure whether a less frequently changed relative address such as a start of bundle address makes more sense for gcc on ppc. In any event, however, I would certainly not be willing to categorize Apple's reliance on position independent code as a bug. By default, use pic.

  20. Still stuck with 68K emulation? by guuyuk · · Score: 3, Interesting

    It's entirely possible that they are using the m68k ABI to allow really old Classic applications (pre PowerPC) to continue to run in Classic... I still run into the occasional program that was built for 680X0 machines, even though Apple switched to the PowerPC back in 1995.

    Some of the educational software that a lot of schools use is still built with MS-DOS 5 and Apple System 7.5 in mind. Until you can get some of these developers to move to something a little more modern, you will still have a lot of excess baggage to carry in your OS. Perhaps that is why Apple is moving to systems that won't boot MacOS 9 in January 2003.

    --
    We're sorry, the phone number you have reached is imaginary. Please rotate your phone 90 degrees and try your call again
    1. Re:Still stuck with 68K emulation? by norwoodites · · Score: 3, Informative

      I remember those days, A4 and A5 worlds, one was used for globals in applications while the other was used for globals in resource code (i.e. extensions, control panels, and modules for programs). But Apple never used the PC as the basis for the position independence on the 68K or the PPC until Darwin (Mac OS X). The problem for using the PC is that you have to do a branch and store the result only if you need to externs and such. The problem for using a register that stores the value all the time is that you are wasting a register (68K case: A4 and A5; PPC case RTOC or r2).

    2. Re:Still stuck with 68K emulation? by mrseigen · · Score: 2, Interesting

      OS X still runs a lot of old 68k software very well under Classic -- surprising, even runs some stuff my old trusty 604 refused to. Unfortunately, a lot of old 68k stuff is hard to find anymore. My mother wishes they'd carbonize Gunshy one of these days, the Classic launch is a bit of a pain.

    3. Re:Still stuck with 68K emulation? by burgess · · Score: 1

      photosop 0.63b runs a dream on my dual g4.

      so yep i am fine with this. if they break compatability with my flavourite photoshop i will be pissed.

  21. NeXTStep 68k or x86 ?! by Anonymous Coward · · Score: 0, Redundant

    Since the most recent versions of NeXTStep were also released in Intel versions, perhaps this has more to do with code from the Intel x86 branch than the ( truly legacy ) x86 branch?
    Perhaps...

  22. Ugh, go back to using PEF/CFM!! by anarkhos · · Score: 2, Informative

    Apple supposedly saved some time using Mach-O because they wouldn't have to rewrite their linker to use CFM/PEF. If we're going to hack Mach-O so it uses the standard PowerPC ABI why not just support PEF/CFM?!

    There are many reasons for this. Not only are there tools already available to handle PEF/CFM, you wouldn't need the whole PEF interpreter w/shim libraries to run PEF Carbon apps!

    --
    >80 column hard wrapped e-mail is not a sign of intelligent
    >life
  23. Big deal. by 0x0d0a · · Score: 5, Insightful

    This is mindblowingly unimportant. Can *anyone* think of *any* company that has a perfect ABI? No, because processors evolve, and the ABI has to stay the same. When I write an x86 program on my Linux box, it pushes *all* the arguments onto the stack. Is that the best way to do things? No. Is it done anyway? Yup. Does anyone go into a tizzy about it? No.

    Seriously, the x86 Linux ABI is probably worse off...different (worse) byte alignment from Windows, the abovementioned everything-goes-on-the-stack....

  24. Not really all that suprising by MoneyT · · Score: 1

    It makes logical sense. OS X takes it's roots (no pun intended) from UNIX, UNIX grew up on x86 architectures long before Apple started using it, therefore it only makes sense that the code would be mostly optimised for CISC.

    --
    T Money
    World Domination with a plastic spoon since 1984
    1. Re:Not really all that suprising by Anonymous Coward · · Score: 0

      Nope, unix "grew up" on the wonderful PDP series of microcomputers. And vax, don't forget the vax. Then of course came the 68k computers which were used for unix soooo many times. oh, yeah, then came those dumpy 8086's

  25. portability by Nomad37 · · Score: 5, Interesting
    It seems the real reason apple did this is to maintain portability. Jobs has said multiple times that 'We like to have options' when asked about future chips in macs. It's been backed up by the top brass at apple too (eg, Infoworld article with VP's).

    It seems that they can emulate a pc-register in a risc architecture, but could they (easily) do it the other way around? Perhaps this is the real reason why they kept the abi the way it is: so they could easily port os x to whatever platform they like...

    --
    Pessimism of the intellect, optimism of the will! - Antonio Gramsci.
  26. GCC 3 by Anonymous Coward · · Score: 4, Interesting

    Using gcc 3 with OS X Jaguar 10.2.1, I checked this out using gcc's option to produce assembly-language code (gcc -S). It turns out that a function call uses only a single additional instruction (branch to link register). Since Apple has compiled OS X Jaguar with gcc 3, only legacy shared libraries and pre-OS 10.2 applications should be affected by the RISC/CISC problem. This is still a significant performance hit, but I would imagine that it is less than 10 percent figure given earlier, and also easier to fix.

  27. Re:a likely manner in which this will be corrected by Anonymous Coward · · Score: 0

    Too wordy. You can't keep my interest. You lose me.

    Did you have something important to say?

  28. Check your facts by Anonymous Coward · · Score: 0

    > It seems that Apple could easily correct this when they update OS X for a 64-bit chip

    Why is that? Pray share your wisdom with us. Or is this just a street corner guesstimate?

    > Applications will need to be recompiled to be 64-bit anyway

    No they won't. That's the whole point.

    > why not update the ABI in the process?

    Why not? I'm not sure, but I do know one thing: there's a good reason the people at Apple are developers and you're not.

  29. This is SUCH old news. by Trillan · · Score: 0, Troll

    I remember reading about this on the OpenTransportDev list well over a year ago.

  30. Not really all that suprising Unix grew up on x86? by Anonymous Coward · · Score: 0
    That has to be the stupidest thing I have ever, ever heard. Thompson, Ritchie are laughing their asses off when loon tunes like you some up with shit like this. Are you stupid? The PDP is the machine where what UNIX today grew up on. The 286 was the first x86 that did make running full-fledged UNIX painful realistically the 386. I'll say the 286 ran UNIX. That was out in quantity in late 1982. That's over a decade before the x86 was even remotely close to being able to be considered a viable UNIX platform, more like 16 years (1985) for the realistic. The Linux kernel wasn't very useful until 2.0.x, June 1996. The cheesy, shitty Mach kernel (and most people considering a pure microkernel) was deprecated by Carnegie Mellon in 1994. So, what the fuck are you talking about, UNIX growing up on an x86? Both BSD and 8 "revisions" of UNIX were completed before x86 ever ran UNIX.

    At the same time Thompson was working on his program, Bell Labs entered into a partnership with Honeywell, General Electric, and the Massachusetts Institute of Technology (MIT) to develop an operating system for a large computer that could handle up to a thousand simultaneous users and could run 24 hours a day, 365 days a year. Thompson and Dennis Ritchie were assigned to work on the design from the Bell Labs side. Unfortunately, none of the companies had a computer that could handle the development of their program. Bell Labs eventually withdrew from the project, but Thompson continued his work on a PDP-7 computer in the lab. Thompson developed a working model on the PDP-7 but he needed a larger computer to finish the project. Eventually, Bell Labs was convinced to buy a $100,000-plus PDP 11/20 by promises from Thompson and Ritchie that their group would develop a word processing system for the lab. In 1969, Thompson and Ritchie gave the lab their word processing program, but in the meantime managed to develop the UNIX system, which was their ultimate goal all along.

    UNIX was a major advance in computing, giving users features and functions unavailable before. In addition, it was simple and proved that a small operating system could be portable, machine independent, and affordable. It had a profound impact on the development of DOS, the Mac OS, Windows NT, and other operating systems.

    In 1972, Ritchie created the C programming language and, in 1973, Thompson rewrote the UNIX operating system kernel in C. The enormous popularity of C in the computer industry has resulted in it becoming virtually the standard programming language in the microcomputer/workstation market. UNIX, because it is written in the C language, is more portable--less machine-specific--than other operating systems. In 1976, Thompson and Ritchie realized that this portability was a breakthrough. UNIX could be used on any machine and clients were no longer required to use the operating system that came prepackaged with the hardware they bought. This was a radical change at a time when every computer and its operating system were inseparable. By 1977, more than 500 sites were running UNIX.

    1957 Bell Labs found they needed an operating system for their computer center which at the time was running various batch jobs. The BESYS operating system was created at Bell Labs to deal with these needs.
    1965 Bell Labs was adopting third generation computer equipment and decided to join forces with General Electric and MIT to create Multics (Multiplexed Information and Computing Service).
    1969 By April 1969, AT&T made a decision to withdraw Multics and go with GECOS. When Multics was withdrawn Ken Thompson and Dennis Ritchie needed to rewrite an operating system in order to play space travel on another smaller machine (a DEC PDP-7 [Programmed Data Processor 4K memory for user programs). The result was a system which a punning colleague called UNICS (UNiplexed Information and Computing Service)--an 'emasculated Multics'.
    1969 Summer 1969 UNIX was developed.
    1971 First edition of UNIX released 11/03/1971. The first edition of the "UNIX PROGRAMMER'S MANUAL [by] K. Thompson [and] D. M. Ritchie" is also dated "November 3, 1971". It includes over 60 commands like: b (compile B program); boot (reboot system); cat (concatenate files); chdir (change working directory); chmod (change access mode); chown (change owner); cp (copy file); ls (list directory contents); mv (move or rename file); roff (run off text); wc (get word count); who (who is one the system). The main thing missing was pipes.
    1972 Second edition of UNIX released 12/06/1972
    1972 Ritchie rewrote B and called the new language C.
    1973 UNIX had been installed on 16 sites (all within AT&T/Western Electric); it was publically unveiled at a conference in October.
    1973 Third edition of UNIX released 02/xx/1973
    1973 Forth edition of UNIX released 11/xx/1973
    1974 Fifth edition of UNIX released 06/xx/1974
    1974 Thompson went to UC Berkeley to teach for a year, Bill Joy arrived as a new graduate student. Frustrated with ed, Joy developed a more featured editor em.
    1975 Sixth edition of UNIX released 05/xx/1975
    1977 1BSD released late 1977
    1978 2BSD released mid 1978
    1979 Seventh edition of UNIX released 01/xx/1979
    1979 3BSD released late 1979
    1979 SCO founded by Doug and Larry Michels as UNIX porting and consulting company.
    1980 4.0BSD released 10/xx/1980
    1982 SGI introduces IRIX.
    1983 SCO delivers its first packaged UNIX system called SCO XENIX System V for Intel 8086 and 8088 processor-based PCs.
    1984 Ultrix 1.0 was released.
    1985 Eighth edition of UNIX released 02/xx/1985
    1985 The GNU manifesto is published in the March 1985 issue of Dr. Dobb's Journal. The GNU project starts a year and a half later.
    1986 HP-UX 1.0 released.
    1986 Ninth edition of UNIX released 09/xx/1986
    1987 Sun and AT&T lay the groundwork for business computing in the next decade with an alliance to develop UNIX System V Release 4.
    1988 HP-UX 2.0 released.
    1988 HP-UX 3.0 released.
    1989 SCO ships SCO UNIX System V/386, the first volume commercial product licensed by AT&T to use the UNIX System trademark.
    1989 HP-UX 7.0 released.
    1989 Tenth edition of UNIX released 10/xx/1989
    1990 AIX short for Advanced Interactive eXecutive was first entered into the market by IBM February 1990.
    1991 Sun unveils Solaris 2 operating environment, specially tuned for symmetric multiprocessing.
    1991 Linux is introduced by Linus Torvalds, a student in Finland. Who post to the comp.os.minix newsgroup with the words: Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.
    1991 HP-UX 8.0 released.
    1991 BSD/386 ALPHA First code released to people outside BSDI 12/xx/1991
    1992 HP-UX 9.0 released.
    1993 NetBSD 0.8 released 04/20/1993
    1993 FreeBSD 1.0 released December of 1993
    1994 Red Hat Linux is introduced.
    1994 Caldera, Inc was founded in 1994 by Ransom Love and Bryan Sparks.
    1994 NetBSD 1.0 released 10/26/1994
    1995 FreeBSD 2.0 released 01/xx/1995
    1995 SCO acquires UNIX Systems source technology business from Novell Corporation (which had acquired it from AT&T's UNIX System Laboratories). SCO also acquires UnixWare 2 operating system from Novell.
    1995 HP-UX 10.0 released.
    1995 4.4 BSD Lite Release 2 the true final distribution from the CSRG 06/xx/1995
    1997 HP-UX 11.0 released.
    1997 Caldera ships OpenLinux Standard 1.1 May 5, 1997, the second offering in Caldera's OpenLinux product line
    1998 IRIX 6.5 the fifth generation of SGI UNIX is released July 6, 1998.
    1998 SCO delivers UnixWare 7 operating system.
    1998 Sun Solaris 7 operating system released.
    1998 FreeBSD 3.0 released 10/16/1998
    2000 FreeBSD 4.0 released 03/13/2000
    2000 Caldera Systems Inc. announces that Caldera Systems has entered into agreement to acquire the SCO Server Software Division and the Professional Services Division

  31. ignore this buttfucking sugarbitch by Anonymous Coward · · Score: 0

    testes money is a complete idiot, dont get bent out of shape on him.

  32. Huh? by Trillan · · Score: 1

    The needs of the Classic runtime have nothing to do with the native ABI. As for targetting System 7.5 in schools... when most of the computers in use are LCIIIs and earlier, you don't have a lot of choice.

  33. Re:Not really all that suprising Unix grew up on x by MoneyT · · Score: 2

    You missed what I said. I said that UNIX had grown up on the x86 before Apple or Next had started using it. There fore it only makes sense that the code you are using would come from x86 code rather than PC. I realize x86 was not the first UNIX architecture, but that was the most logical place for Apple to start drawing code from.

    --
    T Money
    World Domination with a plastic spoon since 1984
  34. why don't they use PowerOpen by Gizzmonic · · Score: 2

    PowerOpen would be a suitable ABI for any UNIX app that's POSIX compliant. Perhaps it could even be extended to work with cocoa apps?

    --
    (-1, Raw and Uncut is the only way to read)
  35. Re:a likely manner in which this will be corrected by Anonymous Coward · · Score: 0
    In any event, they will certainly retain a CISC-oriented API in the OS X stable of architectures, if only to be able to continue to wave the specter of an open source OS X on X86 in front of Microsoft, as sort of a "mutual assured destruction" weapon to prevent Microsoft from wiping them out, and possibly as a negotiating tool in keeping Microsoft coding for the Mac.

    Do you really think that "an open source OS X on X86" would be a threat to Microsoft? Why would anyone want to run such a creature? There wouldn't be any apps for it. Don't tell me that it's just a simple recompile to get existing apps running on the new architecture. Things are rarely that simple, and in the case of Carbon apps, I suspect they're considerably more complex.

    So why would developers target the platform? Without a company to own it and market it, they would (rightly) conclude that it was dead in the water. Yeah, there are some companies targeting Linux with products right now, but they're generally focusing on server apps, not desktop stuff.