Being the proud owner of a MacII since the beginning of this year, I was - like so many others - disappointed at the relative slowness of the SANE package. Even with the floating point coprocessor, the speedup is only a factor of 5-10 compared to the Mac SE. The coprocessor itself allows you to go much faster than that, and it is Apples SANE implementation that slows down the operations.

The reason for this is, of course, that Apple is trying to guarantee the compatibility of the SANE on the MacII with the old SANE implementation. That means that the results are supposed to be the same, down to the least significant bit (or even to the last guard bit?). The 68881 uses different algorithms for calculating transcendental functions than SANE does, therefore some of its built-in operations could not be used and had to be replaced by software. Of course, that slows down things a lot.

As a side note, Im not at all in favor of such a strategy. Artificially restraining a high performance chip just because its results, although accurate enough, dont match the old - also accurate - results to the last bit seems a little exaggerated. Stable numerical algorithms should take into account the possibility that the hardware changes slightly and the machine errors are different, and they should be immune against such changes; or at least the new SANE should have had an option built in that uses the 68881 directly! [Amen to that statement! -Ed]

Many of the development systems for the Macintosh now come with the possibility to generate code that supports the floating point coprocessor directly, many others dont; working with Forth, we dont have a real problem since we can easily redefine our floating point operators. This month Ill show you how to do that.

The 68881

Lets first have a look at the floating point coprocessor itself.

The 68881 is accessed from the 68020 in a special address area. When the 68020 encounters an instruction of the form $Fxxx (previously the F line trap), it will set its function code lines (pins FC0-FC2) all to high, indicating CPU space. It will then exchange information with the coprocessors internal registers to perform the floating point operation requested.

This information exchange occurs automatically, it is part of the 68020s design; when using the floating point instructions, you dont notice the communication between the two processors at all. The 68881 appears as an extension to the 68020, just as if we had a new set of registers available, with special instructions operating on them.

The registers FP0-FP7 can each hold one extended precision (80-bit) floating point number, in the format given by the IEEE standard: bits 0-63 contain the mantissa, 64-78 the 15-bit exponent offset by 16383, and bit 79 the sign. The instruction set of the 68881 allows you to do floating point operations on any or between any two of these registers, and transfer data between them, the 68020s registers and memory.

Mach2s assembler fully supports all 68881 instructions. The redefinition of the words in the SANE vocabulary is therefore quite straightforward. Register D7 is used by Mach2 as the floating point stack pointer, all we have to do is to transfer floating point numbers from the FP stack to the 68881s registers, do the FP operation and transfer back the result.

The 68881 expects floating point numbers in a different format than SANE does. In order to keep FP numbers aligned to the boundaries of a 32-bit long word, which speeds up operations, an extended precision number in memory will be 96 bits long instead of 80; there is a 16 bit gap between the 64-bit mantissa and the 16-bit sign and exponent field. Since SANE and the floating point stack in Mach2 use 80 bit numbers, we have to convert their format when we use the coprocessor.

Listing 1 provides the macros f>2, f>1 and 1>f for this purpose. The general format for a binary floating point operation is then

f>2
fop.x FPn, FPm
1>f

where fop.x is an extended format floating point instruction that operates on floating point registers FPn and FPm. The example always uses registers FP0 and FP1. Unary operations are encoded the same way, using only FP0.

In the example, I provided a new vocabulary f68881 that contains redefinitions of the most important SANE operations for the 68881. Of course, the concept can be far extended. We have eight registers at our disposition and can use them to optimize more complicated numerical algorithms, using only assembly language. I might give some examples how to do this in a later column.

For the moment, lets content ourselves with the speed improvement that we have achieved so far, which is already remarkable. Some simple benchmarks are listed at the end of listing 1, and the results are given here:

( MacII, direct 68881 access, 100000 loops each )

bmark1 2 Secs 18 Ticks ok <0> [0]

bmark2 4 Secs 48 Ticks ok <0> [0]

bmark3 4 Secs 14 Ticks ok <0> [0]

bmark4 4 Secs 17 Ticks ok <0> [0]

bmark5 4 Secs 14 Ticks ok <0> [0]

( MacII, SANE w/68881, 10000 loops each )

smark1 15 Ticks ok <0> [0]

smark2 37 Secs 12 Ticks ok <0> [0]

smark3 24 Ticks ok <0> [0]

smark4 1 Secs 33 Ticks ok <0> [0]

smark5 1 Secs 33 Ticks ok <0> [0]

( Mac +, SANE, 10000 loops each )

ok <0> [0]

smark1 24 Ticks ok <0> [0]

smark2 181 Secs 54 Ticks ok <0> [0]

smark3 49 Ticks ok <0> [0]

smark4 4 Secs 47 Ticks ok <0> [0]

smark5 5 Secs 14 Ticks ok <0> [0]

For the Mac+, the fnull1 and fnull2 operations had been replaced by simple fdrops. As you see, the speedup going from Mac+ to MacIIs SANE is not so breathtaking: a factor of 6 for the exponential, 4 for addition and subtraction; but when we access the 68881 directly, we gain another factor of 3 for simple addition and multiplication and 78 for the exponential. It is in the calculation of the transcendentals where the 68881 really shines.

Pop up menus

Someone approached me lately on the question of how to do pop up menu selection. Since the technical notes contain only sketchy references to popup menus at the time I write this (e.g. TN156, TN172), Id like to give you a practical example how to use pop up menus from Mach2 in a simple way.

- the top and left global coordinate of the point at which to display the menu (2*16 bits),

- the menu item which should be positioned at that point for the default selection.

Although Mach2 knows the trap name, the interface to this routine is not (yet) correct, so we have to redefine it in assembler. Note that the point returned by the @mouse function is in local coordinates, while PopUpMenuSelect expects it in global coordinates.

The example defines a menu using the Mach2 interface; the menu is created with -1 as the insertion parameter (-1 150 mymenu BOUNDS) so that after insertion into the taskss menu bar the menu will stay invisible (just as we did for the hierarchical menus). Note that a pop up menu has to be inserted into the menu bar before using it.

The content handler for the default Mach2 window is then rewritten so that on a mouse down event it will select the example pop up menu. The menu handler will just beep a number of times depending on the item selected. dopop activates the new content handler while nopop deactivates it.

Feedback dept.

This letter comes from Vassili Dzuba, Paris:

In Januarys issue Mousehole Report, Alan Dall put in his wish list the ability to define ghost copies of applications. Even without Unix capability of defining links, this can be done with a small program using the _Launch trap. This program takes only 1K on the disk. The path name of the application to launch is stored in STR  resource 1000. Its possible to set the creator and the bundle bit of the ghost to have it share the same icon as the real thing. Of course, double-clicking on a document can then launch the ghost instead of the application, but the slowing down is only marginal.

Software Updates via MacUpdate

Kodi 15.1.rc1 - Powerful media center to...

Kodi (was XBMC) is an award-winning free and open-source (GPL) software media player and entertainment hub that can be installed on Linux, OS X, Windows, iOS, and Android, featuring a 10-foot user... Read more

Bookends 12.5.8 - Reference management a...

Bookends is a full-featured bibliography/reference and information-management system for students and professionals.
Access the power of Bookends directly from Mellel, Nisus Writer Pro, or MS Word (... Read more

Chromium 44.0.2403.125 - Fast and stable...

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web.
Version 44.0.2403.125:
This release contains a number... Read more

iMazing 1.2.2 - Complete iOS device mana...

iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can:
Copy music to and from... Read more

Audio Hijack 3.2.0 - Record and enhance...

Audio Hijack (was Audio Hijack Pro) drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio... Read more

FontExplorer X Pro 5.0.1 - Font manageme...

FontExplorer X Pro is optimized for professional use; it's the solution that gives you the power you need to manage all your fonts.
Now you can more easily manage, activate and organize your... Read more

Calcbot 1.0.2 - Intelligent calculator a...

Calcbot is an intelligent calculator and unit converter for the rest of us. Featuring an easy-to-read history tape, expression view, intuitive conversion, and much more!
Features
History Tape -... Read more

MTR 5.0.0.1 - The Mac's oldest and...

MTR (was MacTheRipper)--the Mac's oldest and smartest DVD-backup app--is now updated to version 5.001
MTR -- the complete toolbox, not a one-trick, point-and-click extractor. MTR is intended for... Read more

LibreOffice 4.4.5.2 - Free, open-source...

LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more

Adobe Lightroom 6.1.1 - Import, develop,...

Adobe Lightroom is available as part of Adobe Creative Cloud for as little as $9.99/month bundled with Photoshop CC as part of the photography package. Lightroom 6 is also available for purchase as a... Read more

Bandai Namco has released Pac-Man Championship Edition DX on iOS and Android, which features the classic arcade gameplay that we've all grown to love.
Pac-Man Championship Edition DX can be enjoyed in much shorter bursts than the arcade versions... | Read more »

Angel Stone is Fincon's follow up to the massively successful Hello Hero and is out now on iOS and Android.
You play as a member of The Resistance, a group of mighty human warriors who have risen up in defiance of the Demon horde threatening to... | Read more »

The not exactly rumors were true and the birds are back. Angry Birds 2 has come to the App Store and the world will... well I suppose it'll still be the same, but now we have more bird-flinging options!
[Read more]
| Read more »

You Could Design Your Own Card for Chain...

If you've ever wanted to create your own item, weapon, trap, or even monster for Chainsaw Warrior: Lords of the Night, this is your chance. Auroch Digital is currently holding a contest so that fans can fight to the death (not really) to see which... | Read more »

Bitcoin Billionaire is Going Back in Tim...

If you thought you managed to buy everything there is to buy in Bitcoin Billionaire and make all the money, well you though wrong. Those of you who made it far enough might remember investing in time travel - and it looks like that investment is... | Read more »

Domino Drop (Games)

Domino Drop 1.0
Device: iOS Universal
Category: Games
Price: $1.99, Version: 1.0 (iTunes)
Description:
Domino Drop is a delightful new puzzle game with dominos and gravity!Learn how to play it in a minute, master it day by day.Your... | Read more »

Best Buy has iPad Air 2s on sale for up to $100 off MSRP on their online store for a limited time. Choose free shipping or free local store pickup (if available). Sale prices available for online... Read more

B&H Photo has the 13″ 1.6GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY tax only. Their price is $100 off MSRP, and it’s the lowest price available for this model.... Read more

Worldwide Tablet Market Decline Continues, Ap...

The worldwide tablet market declined -7.0% year-over-year in the second quarter of 2015 (2Q15) with shipments totaling 44.7 million units according to preliminary data from the International Data... Read more

The Apple Store has Apple Certified Refurbished iPad Air 2s available for up to $140 off the price of new models. Apple’s one-year warranty is included with each model, and shipping is free:
- 128GB... Read more

Updated Apple iPad Price Trackers

We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers.
Read more

Apple refurbished 2014 13-inch 128GB MacBook...

The Apple Store has Apple Certified Refurbished 2014 13″ MacBook Airs available starting at $759. An Apple one-year warranty is included with each MacBook, and shipping is free:
- 13″ 1.4GHz/128GB... Read more

Apple’s Education discount saves up to $300 o...

Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more

MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders. Not responsible for typographical errors.

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.