+-----------------+ FPU PROGRAMMING +-----------------+ It all really started with DHS. Although they were by no means the first people to code FPU stuff on the Falcon, they were the first to create a demo so good it made buying an FPU worthwhile. That demo was '4ever' and ever since coders have been scratching their head and thinking 'perhaps that FPU thing may be worth a look'. From this starring role, the FPU has gone on to make cameo appearances in numerous other 4k demos 128 byte intros - mainly due to its inbuilt sine and cosine table. It has enough functionality to make it worthwhile using in full demos as well as intros, even more so now that most Falcon owners own one of these chips. As demo effects become more complex and 3D worlds become more prevalent, hardware floating point calculations becomes a very tempting option. Although you can get away with using fixed point, floats give you so much more flexibility and power. Fair enough, you say. But how do I program the damn thing? Fear no more because the maggie team are here to lift the shroud of secrecy from FPU programming. ---------------------------------------------------------------------- DATA FORMATS ---------------------------------------------------------------------- On the 68030 you have these basic data types : +----------+------+ | NAME | BITS | +----------+------+ | Bits | 1 | | BitField | 1-32 | | BCD | 8 | | Byte | 8 | | Word | 16 | | LongWord | 32 | | QuadWord | 64 | +----------+------+ These are all integer formats. As the FPU is floating point based the data formats are very different, although there is some overlap. The 68881/68882 support three integer types: +----------+------+ | NAME | BITS | +----------+------+ | Byte | 8 | | Word | 16 | | LongWord | 32 | +----------+------+ These are completely compatible with the 030 integer types. The 68881/68882 has three floating point types: +----------+------+----------+----------+ | NAME | BITS | EXPONENT | MANTISSA | +----------+------+----------+----------+ | Single | 32 | 8 | 23 | +----------+------+----------+----------+ | Double | 64 | 11 | 53 | +----------+------+----------+----------+ | Extended | 96 | 15 | 64 | +----------+------+----------+----------+ | Packed | 96 | 12 | 68 | +----------+------+----------+----------+ The 'Single' format is equivalent to C's "float" data type, with 'Double' being, erm, 'the double' of C's "double" type. (Now you are just confusing everyone! -ED) Whilst the 'Extended' type requires 96 bits of storage in memory (12 bytes) only 80 bits of this are actually used by the FPU. The rest is for 'future expansion'. So its a bit of of a waste using this format, especially if saving large chunks of floats in memory. Internally, the FPU performs all calculations to 80 bit precision, first converting from the source type then converting to the destination type (if necessary). Use of Double and Extended types requires more memory overhead thus more time featching/storing data so I recommend sticking to the Single type - the overhead of the FPU conversions from Single to Extended are negligble compared to memory speed. Another big advantage of the Single type is that it fits neatly in 68030 data registers so you can use these for temporary stored and/or calculations! ---------------------------------------------------------------------- REGISTERS ---------------------------------------------------------------------- The FPU follows the 68k by having 8 general purpose data registers named FP0-FP7. Each of these are 80 bit (extended format) and when data is moved into them it is converted into 80 bit precision. There are also status and control registers and a program counter. Full discussion of this is beyond the scope of this article - after all, this is meant to be an introduction. ---------------------------------------------------------------------- ADDRESSING MODES ---------------------------------------------------------------------- The FPU has access to all addressing modes of the host processor. This means you can use all the types of addressing you are used to on the 030. The FPU can carry out instructions on memory and 030 registers, not just FPU registers! Obviously things are faster in FPU registers, but you are not limited to just using these 8 registers. ---------------------------------------------------------------------- CONDITIONAL CODES ---------------------------------------------------------------------- Like the 68000, the FPU has a status register with bits representing conditions. The condition codes reflect the last arithmetic operation that occured in the FPU and can be tested. The following conditions are supported +------+----------------------------------+ | EQ | Equal | +------+----------------------------------+ | NE | Not ( Equal ) | +------+----------------------------------+ | GT | Greater Than | +------+----------------------------------+ | NGT | Not ( Greater Than ) | +------+----------------------------------+ | GE | Greater Than or Equal | +------+----------------------------------+ | NGE | Not ( Greater Than or Equal ) | +------+----------------------------------+ | GL | Greater or Less Than | +------+----------------------------------+ | NGL | Not ( Greater or Less Than ) | +------+----------------------------------+ | GLE | Greater or Less or Equal | +------+----------------------------------+ | NGLE | Not ( Greater or Less or Equal ) | +------+----------------------------------+ | OGT | Ordered Greater Than | +------+----------------------------------+ | ULE | Unordered or Less or Equal | +------+----------------------------------+ | OGE | Ordered Greater Than or Equal | +------+----------------------------------+ | ULT | Unordered or Less Than | +------+----------------------------------+ | OLT | Ordered Less Than | +------+----------------------------------+ | UGE | Unordered or Greater or Equal | +------+----------------------------------+ | OLE | Ordered Less Than or Equal | +------+----------------------------------+ | UGT | Unordered or Greater Than | +------+----------------------------------+ | OGL | Ordered Greater or Less Than | +------+----------------------------------+ | UEQ | Unordered or Equal | +------+----------------------------------+ | OR | Ordered | +------+----------------------------------+ | UN | Unordered | +------+----------------------------------+ ---------------------------------------------------------------------- INSTRUCTIONS ---------------------------------------------------------------------- Here follows a list of all the FPU instructions. Syntax: is one of .B ( byte - 8 bits Integer) .W ( word - 16 bits Integer ) .L ( long - 32 bits Integer ) .S ( single - 32 bits Float ) .D ( double - 64 bits Float ) .X ( extended - 96 bits Float ) .P ( packed - 96 bits BCD Float ) Any 68030 addressing mode