Slashdot Mirror


Aqua Enhancements

Marsee writes: "Mike Beam looks at two Aqua enhancements -- one seemingly frivolous and the other not: animated window resizing and drawers." O'Reilly's really invested in Mac OS X, and they often have nice articles for developers on a wide range of subjects in their Mac DevCenter.

2 of 15 comments (clear)

  1. Slower floating point?? by brettper · · Score: 2, Informative

    Also, typically floating point operations are much slower than equivalent integer operations

    Erm. On a 386 maybe. These days FP mults and adds are as quick as (and sometimes faster than)integer ones.

  2. Fixed point by Matthias+Wiesmann · · Score: 4, Informative
    Actually, floating point is quite fast on a PPC. As people already pointed out, for matrix-like computation, PPC has a special instruction that does one multiplication and one addition in one cycle. If this is to slow, on a G4 you can use altivec.

    If you really want not to use floating point calculation, then rational numbers are not the way to go. Instead you should use fixed point numbers. Old 68K based macintoshes (without FPUs) relied on those for fast calculation - in fact as far as I remember, the original Quickdraw toolbox relied of fixed point number for geometric calculations (arcs, slopes, etc.).

    Basically, the idea is to use integers divided by a fixed number, so that the binary number has a fixed point. For instance if you have 32 bits numbers, you assume they are divided by 65536. This means that you have 16 bits before the point, and 16 bits after. This way for additions and substractions, you can use integer operations, calculation can also use the zero and sign flags of the processor. For mulitplication and division, you need to fiddle the integer system a bit (by multiplying or dividing by 2^16), but this could be done using shift operations, which are quite fast.

    The rational structure you propose is not good because a simple addition requires many assembly level operations. For instance to calculate 6/5 + 2/3, you need to do the following calculation:

    1. Find the greatest common dividers of 5 and 3 (this is quite an expensive calculation)
    2. If none is found, multiply 3 by 5.
    3. Multiply 6 by 3 and 2 by 5.
    4. Add the result
    So this basically for a single addition, you need to do perform at least a GCD calculation, one test, three multiplications and one addition. Multiplications and division are a little less costly, but you still need to check if the fraction is simplified.
    Rational numbers are good if you want absolute precision, but for they are not very fast - because there is no support for such a format in current processor instruction sets.

    As for OS X using a vector format, this is, of course the case. Quarty relies on the PDF abstractions and it does support anti-aliasing, and sub-pixel positioning (I don't know for screen scaling). But having a vector format is not sufficient Quickdraw was also vector based, but used an integer coordinate system. This meant that lines, rectangles and arcs had to have their extremities on round coordinates of the Quickdraw grid - the result was not always very satisfactory.