Home » Archimedes archive » Micro User » MU 1992-05.adf » PD » Fractal/!Fractal/Help/!FPE_Doc/ReadMe

Fractal/!Fractal/Help/!FPE_Doc/ReadMe

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Micro User » MU 1992-05.adf » PD
Filename: Fractal/!Fractal/Help/!FPE_Doc/ReadMe
Read OK:
File size: 1343 bytes
Load address: 0000
Exec address: 0000
File contents
Floating Point Emulator Library  v1.03 November 1991, � Mike Curnow
===============================

FPELib provides a set of routines for fast floating point emulation. They
are an alternative to using the FPE instructions, with the benefit of
additional speed (typically 2-5 times as fast). Accuracy is sacrificed where
a significant speed increase is obtained. Generally 7 digits accuracy is
provided.

FPELib routines provide support for single precision floats only, ie. those
in 32 bit format. The numbers are stored in exactly the same format as that
used by the FPE. Unlike the FPE, the numbers are processed in the standard
ARM registers - use LDR/STR etc to load and store. Use my FPlib to assemble
FP constants (DFS nnn).

The Acorn float format is used to allow use of the other FP instructions.
This format is 1 bit sign, 8 bits exponent, and 23 bits fraction.

To assemble the necessary routines add the following code or similar to your
assembler source:

     LIBRARY "FPELIB"               ie. load support functions 
     DIM code% 10000
     FOR asm=0 TO 3 STEP 3          2 pass assembly MUST be used
     [OPT asm                       asm MUST be the OPT variable
     FNfpeasm(angles)               add at the end of your routines
     ]:NEXT

Set angles=TRUE to include the SIN/COS/TAN routines, otherwise angles=FALSE.

Alternatively you can just include the functions required (look inside
FNfpeasm for their names) if you want to include a sub-selection of routines.

The following register conventions apply:

R0  : input operand 1 and result on exit
R1  : input operand 2, corrupted on exit unless noted otherwise
R13 : must point to a full descending stack
R14 : is used for linkage

The routines preserve all other registers.

The routines provided are:

BL fp_add   R0=R0+R1             FNfp_add(Rd,Rn,Rm)    Rd=Rn+Rm
BL fp_sub   R0=R0-R1             FNfp_sub(Rd,Rn,Rm)    Rd=Rn-Rm
BL fp_mul   R0=R0*R1             FNfp_mul(Rd,Rn,Rm)    Rd=Rn*Rm
BL fp_div   R0=R0/R1             FNfp_div(Rd,Rn,Rm)    Rd=Rn/Rm
BL fp_sqr   R0=R0*R0             FNfp_div(Rd,Rn)       Rd=Rn*Rn
BL fp_cmp   R0:R1                FNfp_cmp(Rn,Rm)       Rn:Rm
            Compares R0 with R1 and sets PSR. R0 & R1 are preserved.
BL fp_flt   R0=float(R0)         FNfp_flt(Rd,Rn)       Rd=Float(Rn)
            Converts an integer into float format.
BL fp_fix   R0=integer(R0)       FNfp_fix(Rd,Rn)       Rd=Integer(Rn)
            Converts a float into integer format.
BL fp_rem   R0=remainder R0/R1   FNfp_rem(Rd,Rn,Rm)    Rd=Remainder Rn/Rm
BL fp_sin   R0=Sin(R0)           FNfp_sin(Rd,Rn)       Rd=Sin(Rn)
BL fp_cos   R0=Cos(R0)           FNfp_cos(Rd,Rn)       Rd=Cos(Rn)
BL fp_tan   R0=Tan(R0)           FNfp_tan(Rd,Rn)       Rd=Tan(Rn)

No exceptions are currently raised on underflow, overflow or division by
zero - the result in most cases will be 0, otherwise garbage.

The functions are called by a BL type instruction, ie.:
      BL fp_add

Alternatively you can use the equivalently named functions. With these
functions the registers can be any value - the appropriate code will be
assembled. For example :

   FNfp_add(4,5,6)    R4=R5+R6

Note that R0 & R1 still get used.

Quick Comparison Of Numbers
---------------------------
The Acorn FP format allows comparisons to be made directly if Rm is positive,
ie.
    CMP R0,R1        ; R0<>R1?
    CMP R0,#0        ; R0<>0?
    CMP R0,#127<<23  ; R0<>1?
    CMP R0,#128<<23  ; R0<>2?
    CMP R0,#126<<23  ; R0<>0.5?  etc.
will work correctly with FP numbers as long as R1 is +ve.

To compare constants other than 0 you need to carefully review the FP
format. It is usually easier to load a float constant into a register rather
than hard code it.

Quick Multiplication And Division Of Numbers
--------------------------------------------
Adding 1 to the exponent is equivalent to multiplying by 2, ie
    ADD R0,R0,#1<<23
This is the same as shifting an integer left.
Similarly division by 2 can be performed by subtracting 1 from the exponent:
    SUB R0,R0,#1<<23
Care must be taken to avoid underflow & overflow effects.

Notes On Speed
--------------
With integers considerable speed savings can be achieved by substituting
ADDs for MULs for fixed multiplies. With the FP routines provided there is
insufficient speed gain to really warrant use of this technique.

Future Developments
-------------------
Routines will be added as I find the need and get time. If you would like to
help or have added your own routines, then please contact me.

Please note that most of these routines are still in the experimental stage
and are therefore subject to change, inaccuracy and do not realise the full
speed gain possible.

------------------------------------------------------------

This code may be freely copied and used as long as no charges are levied at
any stage. Copyright belongs to Mike Curnow.

Mike Curnow
30 Bowen Drive
West Dulwich
London
SE21 8PN
00000000  0a 46 6c 6f 61 74 69 6e  67 20 50 6f 69 6e 74 20  |.Floating Point |
00000010  45 6d 75 6c 61 74 6f 72  20 4c 69 62 72 61 72 79  |Emulator Library|
00000020  20 20 76 31 2e 30 33 20  4e 6f 76 65 6d 62 65 72  |  v1.03 November|
00000030  20 31 39 39 31 2c 20 a9  20 4d 69 6b 65 20 43 75  | 1991, . Mike Cu|
00000040  72 6e 6f 77 0a 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |rnow.===========|
00000050  3d 3d 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |================|
00000060  3d 3d 3d 3d 0a 0a 46 50  45 4c 69 62 20 70 72 6f  |====..FPELib pro|
00000070  76 69 64 65 73 20 61 20  73 65 74 20 6f 66 20 72  |vides a set of r|
00000080  6f 75 74 69 6e 65 73 20  66 6f 72 20 66 61 73 74  |outines for fast|
00000090  20 66 6c 6f 61 74 69 6e  67 20 70 6f 69 6e 74 20  | floating point |
000000a0  65 6d 75 6c 61 74 69 6f  6e 2e 20 54 68 65 79 0a  |emulation. They.|
000000b0  61 72 65 20 61 6e 20 61  6c 74 65 72 6e 61 74 69  |are an alternati|
000000c0  76 65 20 74 6f 20 75 73  69 6e 67 20 74 68 65 20  |ve to using the |
000000d0  46 50 45 20 69 6e 73 74  72 75 63 74 69 6f 6e 73  |FPE instructions|
000000e0  2c 20 77 69 74 68 20 74  68 65 20 62 65 6e 65 66  |, with the benef|
000000f0  69 74 20 6f 66 0a 61 64  64 69 74 69 6f 6e 61 6c  |it of.additional|
00000100  20 73 70 65 65 64 20 28  74 79 70 69 63 61 6c 6c  | speed (typicall|
00000110  79 20 32 2d 35 20 74 69  6d 65 73 20 61 73 20 66  |y 2-5 times as f|
00000120  61 73 74 29 2e 20 41 63  63 75 72 61 63 79 20 69  |ast). Accuracy i|
00000130  73 20 73 61 63 72 69 66  69 63 65 64 20 77 68 65  |s sacrificed whe|
00000140  72 65 0a 61 20 73 69 67  6e 69 66 69 63 61 6e 74  |re.a significant|
00000150  20 73 70 65 65 64 20 69  6e 63 72 65 61 73 65 20  | speed increase |
00000160  69 73 20 6f 62 74 61 69  6e 65 64 2e 20 47 65 6e  |is obtained. Gen|
00000170  65 72 61 6c 6c 79 20 37  20 64 69 67 69 74 73 20  |erally 7 digits |
00000180  61 63 63 75 72 61 63 79  20 69 73 0a 70 72 6f 76  |accuracy is.prov|
00000190  69 64 65 64 2e 0a 0a 46  50 45 4c 69 62 20 72 6f  |ided...FPELib ro|
000001a0  75 74 69 6e 65 73 20 70  72 6f 76 69 64 65 20 73  |utines provide s|
000001b0  75 70 70 6f 72 74 20 66  6f 72 20 73 69 6e 67 6c  |upport for singl|
000001c0  65 20 70 72 65 63 69 73  69 6f 6e 20 66 6c 6f 61  |e precision floa|
000001d0  74 73 20 6f 6e 6c 79 2c  20 69 65 2e 20 74 68 6f  |ts only, ie. tho|
000001e0  73 65 0a 69 6e 20 33 32  20 62 69 74 20 66 6f 72  |se.in 32 bit for|
000001f0  6d 61 74 2e 20 54 68 65  20 6e 75 6d 62 65 72 73  |mat. The numbers|
00000200  20 61 72 65 20 73 74 6f  72 65 64 20 69 6e 20 65  | are stored in e|
00000210  78 61 63 74 6c 79 20 74  68 65 20 73 61 6d 65 20  |xactly the same |
00000220  66 6f 72 6d 61 74 20 61  73 20 74 68 61 74 0a 75  |format as that.u|
00000230  73 65 64 20 62 79 20 74  68 65 20 46 50 45 2e 20  |sed by the FPE. |
00000240  55 6e 6c 69 6b 65 20 74  68 65 20 46 50 45 2c 20  |Unlike the FPE, |
00000250  74 68 65 20 6e 75 6d 62  65 72 73 20 61 72 65 20  |the numbers are |
00000260  70 72 6f 63 65 73 73 65  64 20 69 6e 20 74 68 65  |processed in the|
00000270  20 73 74 61 6e 64 61 72  64 0a 41 52 4d 20 72 65  | standard.ARM re|
00000280  67 69 73 74 65 72 73 20  2d 20 75 73 65 20 4c 44  |gisters - use LD|
00000290  52 2f 53 54 52 20 65 74  63 20 74 6f 20 6c 6f 61  |R/STR etc to loa|
000002a0  64 20 61 6e 64 20 73 74  6f 72 65 2e 20 55 73 65  |d and store. Use|
000002b0  20 6d 79 20 46 50 6c 69  62 20 74 6f 20 61 73 73  | my FPlib to ass|
000002c0  65 6d 62 6c 65 0a 46 50  20 63 6f 6e 73 74 61 6e  |emble.FP constan|
000002d0  74 73 20 28 44 46 53 20  6e 6e 6e 29 2e 0a 0a 54  |ts (DFS nnn)...T|
000002e0  68 65 20 41 63 6f 72 6e  20 66 6c 6f 61 74 20 66  |he Acorn float f|
000002f0  6f 72 6d 61 74 20 69 73  20 75 73 65 64 20 74 6f  |ormat is used to|
00000300  20 61 6c 6c 6f 77 20 75  73 65 20 6f 66 20 74 68  | allow use of th|
00000310  65 20 6f 74 68 65 72 20  46 50 20 69 6e 73 74 72  |e other FP instr|
00000320  75 63 74 69 6f 6e 73 2e  0a 54 68 69 73 20 66 6f  |uctions..This fo|
00000330  72 6d 61 74 20 69 73 20  31 20 62 69 74 20 73 69  |rmat is 1 bit si|
00000340  67 6e 2c 20 38 20 62 69  74 73 20 65 78 70 6f 6e  |gn, 8 bits expon|
00000350  65 6e 74 2c 20 61 6e 64  20 32 33 20 62 69 74 73  |ent, and 23 bits|
00000360  20 66 72 61 63 74 69 6f  6e 2e 0a 0a 54 6f 20 61  | fraction...To a|
00000370  73 73 65 6d 62 6c 65 20  74 68 65 20 6e 65 63 65  |ssemble the nece|
00000380  73 73 61 72 79 20 72 6f  75 74 69 6e 65 73 20 61  |ssary routines a|
00000390  64 64 20 74 68 65 20 66  6f 6c 6c 6f 77 69 6e 67  |dd the following|
000003a0  20 63 6f 64 65 20 6f 72  20 73 69 6d 69 6c 61 72  | code or similar|
000003b0  20 74 6f 20 79 6f 75 72  0a 61 73 73 65 6d 62 6c  | to your.assembl|
000003c0  65 72 20 73 6f 75 72 63  65 3a 0a 0a 20 20 20 20  |er source:..    |
000003d0  20 4c 49 42 52 41 52 59  20 22 46 50 45 4c 49 42  | LIBRARY "FPELIB|
000003e0  22 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |"               |
000003f0  69 65 2e 20 6c 6f 61 64  20 73 75 70 70 6f 72 74  |ie. load support|
00000400  20 66 75 6e 63 74 69 6f  6e 73 20 0a 20 20 20 20  | functions .    |
00000410  20 44 49 4d 20 63 6f 64  65 25 20 31 30 30 30 30  | DIM code% 10000|
00000420  0a 20 20 20 20 20 46 4f  52 20 61 73 6d 3d 30 20  |.     FOR asm=0 |
00000430  54 4f 20 33 20 53 54 45  50 20 33 20 20 20 20 20  |TO 3 STEP 3     |
00000440  20 20 20 20 20 32 20 70  61 73 73 20 61 73 73 65  |     2 pass asse|
00000450  6d 62 6c 79 20 4d 55 53  54 20 62 65 20 75 73 65  |mbly MUST be use|
00000460  64 0a 20 20 20 20 20 5b  4f 50 54 20 61 73 6d 20  |d.     [OPT asm |
00000470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000480  20 20 20 20 20 20 61 73  6d 20 4d 55 53 54 20 62  |      asm MUST b|
00000490  65 20 74 68 65 20 4f 50  54 20 76 61 72 69 61 62  |e the OPT variab|
000004a0  6c 65 0a 20 20 20 20 20  46 4e 66 70 65 61 73 6d  |le.     FNfpeasm|
000004b0  28 61 6e 67 6c 65 73 29  20 20 20 20 20 20 20 20  |(angles)        |
000004c0  20 20 20 20 20 20 20 61  64 64 20 61 74 20 74 68  |       add at th|
000004d0  65 20 65 6e 64 20 6f 66  20 79 6f 75 72 20 72 6f  |e end of your ro|
000004e0  75 74 69 6e 65 73 0a 20  20 20 20 20 5d 3a 4e 45  |utines.     ]:NE|
000004f0  58 54 0a 0a 53 65 74 20  61 6e 67 6c 65 73 3d 54  |XT..Set angles=T|
00000500  52 55 45 20 74 6f 20 69  6e 63 6c 75 64 65 20 74  |RUE to include t|
00000510  68 65 20 53 49 4e 2f 43  4f 53 2f 54 41 4e 20 72  |he SIN/COS/TAN r|
00000520  6f 75 74 69 6e 65 73 2c  20 6f 74 68 65 72 77 69  |outines, otherwi|
00000530  73 65 20 61 6e 67 6c 65  73 3d 46 41 4c 53 45 2e  |se angles=FALSE.|
00000540  0a 0a 41 6c 74 65 72 6e  61 74 69 76 65 6c 79 20  |..Alternatively |
00000550  79 6f 75 20 63 61 6e 20  6a 75 73 74 20 69 6e 63  |you can just inc|
00000560  6c 75 64 65 20 74 68 65  20 66 75 6e 63 74 69 6f  |lude the functio|
00000570  6e 73 20 72 65 71 75 69  72 65 64 20 28 6c 6f 6f  |ns required (loo|
00000580  6b 20 69 6e 73 69 64 65  0a 46 4e 66 70 65 61 73  |k inside.FNfpeas|
00000590  6d 20 66 6f 72 20 74 68  65 69 72 20 6e 61 6d 65  |m for their name|
000005a0  73 29 20 69 66 20 79 6f  75 20 77 61 6e 74 20 74  |s) if you want t|
000005b0  6f 20 69 6e 63 6c 75 64  65 20 61 20 73 75 62 2d  |o include a sub-|
000005c0  73 65 6c 65 63 74 69 6f  6e 20 6f 66 20 72 6f 75  |selection of rou|
000005d0  74 69 6e 65 73 2e 0a 0a  54 68 65 20 66 6f 6c 6c  |tines...The foll|
000005e0  6f 77 69 6e 67 20 72 65  67 69 73 74 65 72 20 63  |owing register c|
000005f0  6f 6e 76 65 6e 74 69 6f  6e 73 20 61 70 70 6c 79  |onventions apply|
00000600  3a 0a 0a 52 30 20 20 3a  20 69 6e 70 75 74 20 6f  |:..R0  : input o|
00000610  70 65 72 61 6e 64 20 31  20 61 6e 64 20 72 65 73  |perand 1 and res|
00000620  75 6c 74 20 6f 6e 20 65  78 69 74 0a 52 31 20 20  |ult on exit.R1  |
00000630  3a 20 69 6e 70 75 74 20  6f 70 65 72 61 6e 64 20  |: input operand |
00000640  32 2c 20 63 6f 72 72 75  70 74 65 64 20 6f 6e 20  |2, corrupted on |
00000650  65 78 69 74 20 75 6e 6c  65 73 73 20 6e 6f 74 65  |exit unless note|
00000660  64 20 6f 74 68 65 72 77  69 73 65 0a 52 31 33 20  |d otherwise.R13 |
00000670  3a 20 6d 75 73 74 20 70  6f 69 6e 74 20 74 6f 20  |: must point to |
00000680  61 20 66 75 6c 6c 20 64  65 73 63 65 6e 64 69 6e  |a full descendin|
00000690  67 20 73 74 61 63 6b 0a  52 31 34 20 3a 20 69 73  |g stack.R14 : is|
000006a0  20 75 73 65 64 20 66 6f  72 20 6c 69 6e 6b 61 67  | used for linkag|
000006b0  65 0a 0a 54 68 65 20 72  6f 75 74 69 6e 65 73 20  |e..The routines |
000006c0  70 72 65 73 65 72 76 65  20 61 6c 6c 20 6f 74 68  |preserve all oth|
000006d0  65 72 20 72 65 67 69 73  74 65 72 73 2e 0a 0a 54  |er registers...T|
000006e0  68 65 20 72 6f 75 74 69  6e 65 73 20 70 72 6f 76  |he routines prov|
000006f0  69 64 65 64 20 61 72 65  3a 0a 0a 42 4c 20 66 70  |ided are:..BL fp|
00000700  5f 61 64 64 20 20 20 52  30 3d 52 30 2b 52 31 20  |_add   R0=R0+R1 |
00000710  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
00000720  5f 61 64 64 28 52 64 2c  52 6e 2c 52 6d 29 20 20  |_add(Rd,Rn,Rm)  |
00000730  20 20 52 64 3d 52 6e 2b  52 6d 0a 42 4c 20 66 70  |  Rd=Rn+Rm.BL fp|
00000740  5f 73 75 62 20 20 20 52  30 3d 52 30 2d 52 31 20  |_sub   R0=R0-R1 |
00000750  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
00000760  5f 73 75 62 28 52 64 2c  52 6e 2c 52 6d 29 20 20  |_sub(Rd,Rn,Rm)  |
00000770  20 20 52 64 3d 52 6e 2d  52 6d 0a 42 4c 20 66 70  |  Rd=Rn-Rm.BL fp|
00000780  5f 6d 75 6c 20 20 20 52  30 3d 52 30 2a 52 31 20  |_mul   R0=R0*R1 |
00000790  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
000007a0  5f 6d 75 6c 28 52 64 2c  52 6e 2c 52 6d 29 20 20  |_mul(Rd,Rn,Rm)  |
000007b0  20 20 52 64 3d 52 6e 2a  52 6d 0a 42 4c 20 66 70  |  Rd=Rn*Rm.BL fp|
000007c0  5f 64 69 76 20 20 20 52  30 3d 52 30 2f 52 31 20  |_div   R0=R0/R1 |
000007d0  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
000007e0  5f 64 69 76 28 52 64 2c  52 6e 2c 52 6d 29 20 20  |_div(Rd,Rn,Rm)  |
000007f0  20 20 52 64 3d 52 6e 2f  52 6d 0a 42 4c 20 66 70  |  Rd=Rn/Rm.BL fp|
00000800  5f 73 71 72 20 20 20 52  30 3d 52 30 2a 52 30 20  |_sqr   R0=R0*R0 |
00000810  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
00000820  5f 64 69 76 28 52 64 2c  52 6e 29 20 20 20 20 20  |_div(Rd,Rn)     |
00000830  20 20 52 64 3d 52 6e 2a  52 6e 0a 42 4c 20 66 70  |  Rd=Rn*Rn.BL fp|
00000840  5f 63 6d 70 20 20 20 52  30 3a 52 31 20 20 20 20  |_cmp   R0:R1    |
00000850  20 20 20 20 20 20 20 20  20 20 20 20 46 4e 66 70  |            FNfp|
00000860  5f 63 6d 70 28 52 6e 2c  52 6d 29 20 20 20 20 20  |_cmp(Rn,Rm)     |
00000870  20 20 52 6e 3a 52 6d 0a  20 20 20 20 20 20 20 20  |  Rn:Rm.        |
00000880  20 20 20 20 43 6f 6d 70  61 72 65 73 20 52 30 20  |    Compares R0 |
00000890  77 69 74 68 20 52 31 20  61 6e 64 20 73 65 74 73  |with R1 and sets|
000008a0  20 50 53 52 2e 20 52 30  20 26 20 52 31 20 61 72  | PSR. R0 & R1 ar|
000008b0  65 20 70 72 65 73 65 72  76 65 64 2e 0a 42 4c 20  |e preserved..BL |
000008c0  66 70 5f 66 6c 74 20 20  20 52 30 3d 66 6c 6f 61  |fp_flt   R0=floa|
000008d0  74 28 52 30 29 20 20 20  20 20 20 20 20 20 46 4e  |t(R0)         FN|
000008e0  66 70 5f 66 6c 74 28 52  64 2c 52 6e 29 20 20 20  |fp_flt(Rd,Rn)   |
000008f0  20 20 20 20 52 64 3d 46  6c 6f 61 74 28 52 6e 29  |    Rd=Float(Rn)|
00000900  0a 20 20 20 20 20 20 20  20 20 20 20 20 43 6f 6e  |.            Con|
00000910  76 65 72 74 73 20 61 6e  20 69 6e 74 65 67 65 72  |verts an integer|
00000920  20 69 6e 74 6f 20 66 6c  6f 61 74 20 66 6f 72 6d  | into float form|
00000930  61 74 2e 0a 42 4c 20 66  70 5f 66 69 78 20 20 20  |at..BL fp_fix   |
00000940  52 30 3d 69 6e 74 65 67  65 72 28 52 30 29 20 20  |R0=integer(R0)  |
00000950  20 20 20 20 20 46 4e 66  70 5f 66 69 78 28 52 64  |     FNfp_fix(Rd|
00000960  2c 52 6e 29 20 20 20 20  20 20 20 52 64 3d 49 6e  |,Rn)       Rd=In|
00000970  74 65 67 65 72 28 52 6e  29 0a 20 20 20 20 20 20  |teger(Rn).      |
00000980  20 20 20 20 20 20 43 6f  6e 76 65 72 74 73 20 61  |      Converts a|
00000990  20 66 6c 6f 61 74 20 69  6e 74 6f 20 69 6e 74 65  | float into inte|
000009a0  67 65 72 20 66 6f 72 6d  61 74 2e 0a 42 4c 20 66  |ger format..BL f|
000009b0  70 5f 72 65 6d 20 20 20  52 30 3d 72 65 6d 61 69  |p_rem   R0=remai|
000009c0  6e 64 65 72 20 52 30 2f  52 31 20 20 20 46 4e 66  |nder R0/R1   FNf|
000009d0  70 5f 72 65 6d 28 52 64  2c 52 6e 2c 52 6d 29 20  |p_rem(Rd,Rn,Rm) |
000009e0  20 20 20 52 64 3d 52 65  6d 61 69 6e 64 65 72 20  |   Rd=Remainder |
000009f0  52 6e 2f 52 6d 0a 42 4c  20 66 70 5f 73 69 6e 20  |Rn/Rm.BL fp_sin |
00000a00  20 20 52 30 3d 53 69 6e  28 52 30 29 20 20 20 20  |  R0=Sin(R0)    |
00000a10  20 20 20 20 20 20 20 46  4e 66 70 5f 73 69 6e 28  |       FNfp_sin(|
00000a20  52 64 2c 52 6e 29 20 20  20 20 20 20 20 52 64 3d  |Rd,Rn)       Rd=|
00000a30  53 69 6e 28 52 6e 29 0a  42 4c 20 66 70 5f 63 6f  |Sin(Rn).BL fp_co|
00000a40  73 20 20 20 52 30 3d 43  6f 73 28 52 30 29 20 20  |s   R0=Cos(R0)  |
00000a50  20 20 20 20 20 20 20 20  20 46 4e 66 70 5f 63 6f  |         FNfp_co|
00000a60  73 28 52 64 2c 52 6e 29  20 20 20 20 20 20 20 52  |s(Rd,Rn)       R|
00000a70  64 3d 43 6f 73 28 52 6e  29 0a 42 4c 20 66 70 5f  |d=Cos(Rn).BL fp_|
00000a80  74 61 6e 20 20 20 52 30  3d 54 61 6e 28 52 30 29  |tan   R0=Tan(R0)|
00000a90  20 20 20 20 20 20 20 20  20 20 20 46 4e 66 70 5f  |           FNfp_|
00000aa0  74 61 6e 28 52 64 2c 52  6e 29 20 20 20 20 20 20  |tan(Rd,Rn)      |
00000ab0  20 52 64 3d 54 61 6e 28  52 6e 29 0a 0a 4e 6f 20  | Rd=Tan(Rn)..No |
00000ac0  65 78 63 65 70 74 69 6f  6e 73 20 61 72 65 20 63  |exceptions are c|
00000ad0  75 72 72 65 6e 74 6c 79  20 72 61 69 73 65 64 20  |urrently raised |
00000ae0  6f 6e 20 75 6e 64 65 72  66 6c 6f 77 2c 20 6f 76  |on underflow, ov|
00000af0  65 72 66 6c 6f 77 20 6f  72 20 64 69 76 69 73 69  |erflow or divisi|
00000b00  6f 6e 20 62 79 0a 7a 65  72 6f 20 2d 20 74 68 65  |on by.zero - the|
00000b10  20 72 65 73 75 6c 74 20  69 6e 20 6d 6f 73 74 20  | result in most |
00000b20  63 61 73 65 73 20 77 69  6c 6c 20 62 65 20 30 2c  |cases will be 0,|
00000b30  20 6f 74 68 65 72 77 69  73 65 20 67 61 72 62 61  | otherwise garba|
00000b40  67 65 2e 0a 0a 54 68 65  20 66 75 6e 63 74 69 6f  |ge...The functio|
00000b50  6e 73 20 61 72 65 20 63  61 6c 6c 65 64 20 62 79  |ns are called by|
00000b60  20 61 20 42 4c 20 74 79  70 65 20 69 6e 73 74 72  | a BL type instr|
00000b70  75 63 74 69 6f 6e 2c 20  69 65 2e 3a 0a 20 20 20  |uction, ie.:.   |
00000b80  20 20 20 42 4c 20 66 70  5f 61 64 64 0a 0a 41 6c  |   BL fp_add..Al|
00000b90  74 65 72 6e 61 74 69 76  65 6c 79 20 79 6f 75 20  |ternatively you |
00000ba0  63 61 6e 20 75 73 65 20  74 68 65 20 65 71 75 69  |can use the equi|
00000bb0  76 61 6c 65 6e 74 6c 79  20 6e 61 6d 65 64 20 66  |valently named f|
00000bc0  75 6e 63 74 69 6f 6e 73  2e 20 57 69 74 68 20 74  |unctions. With t|
00000bd0  68 65 73 65 0a 66 75 6e  63 74 69 6f 6e 73 20 74  |hese.functions t|
00000be0  68 65 20 72 65 67 69 73  74 65 72 73 20 63 61 6e  |he registers can|
00000bf0  20 62 65 20 61 6e 79 20  76 61 6c 75 65 20 2d 20  | be any value - |
00000c00  74 68 65 20 61 70 70 72  6f 70 72 69 61 74 65 20  |the appropriate |
00000c10  63 6f 64 65 20 77 69 6c  6c 20 62 65 0a 61 73 73  |code will be.ass|
00000c20  65 6d 62 6c 65 64 2e 20  46 6f 72 20 65 78 61 6d  |embled. For exam|
00000c30  70 6c 65 20 3a 0a 0a 20  20 20 46 4e 66 70 5f 61  |ple :..   FNfp_a|
00000c40  64 64 28 34 2c 35 2c 36  29 20 20 20 20 52 34 3d  |dd(4,5,6)    R4=|
00000c50  52 35 2b 52 36 0a 0a 4e  6f 74 65 20 74 68 61 74  |R5+R6..Note that|
00000c60  20 52 30 20 26 20 52 31  20 73 74 69 6c 6c 20 67  | R0 & R1 still g|
00000c70  65 74 20 75 73 65 64 2e  0a 0a 51 75 69 63 6b 20  |et used...Quick |
00000c80  43 6f 6d 70 61 72 69 73  6f 6e 20 4f 66 20 4e 75  |Comparison Of Nu|
00000c90  6d 62 65 72 73 0a 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |mbers.----------|
00000ca0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000cb0  2d 0a 54 68 65 20 41 63  6f 72 6e 20 46 50 20 66  |-.The Acorn FP f|
00000cc0  6f 72 6d 61 74 20 61 6c  6c 6f 77 73 20 63 6f 6d  |ormat allows com|
00000cd0  70 61 72 69 73 6f 6e 73  20 74 6f 20 62 65 20 6d  |parisons to be m|
00000ce0  61 64 65 20 64 69 72 65  63 74 6c 79 20 69 66 20  |ade directly if |
00000cf0  52 6d 20 69 73 20 70 6f  73 69 74 69 76 65 2c 0a  |Rm is positive,.|
00000d00  69 65 2e 0a 20 20 20 20  43 4d 50 20 52 30 2c 52  |ie..    CMP R0,R|
00000d10  31 20 20 20 20 20 20 20  20 3b 20 52 30 3c 3e 52  |1        ; R0<>R|
00000d20  31 3f 0a 20 20 20 20 43  4d 50 20 52 30 2c 23 30  |1?.    CMP R0,#0|
00000d30  20 20 20 20 20 20 20 20  3b 20 52 30 3c 3e 30 3f  |        ; R0<>0?|
00000d40  0a 20 20 20 20 43 4d 50  20 52 30 2c 23 31 32 37  |.    CMP R0,#127|
00000d50  3c 3c 32 33 20 20 3b 20  52 30 3c 3e 31 3f 0a 20  |<<23  ; R0<>1?. |
00000d60  20 20 20 43 4d 50 20 52  30 2c 23 31 32 38 3c 3c  |   CMP R0,#128<<|
00000d70  32 33 20 20 3b 20 52 30  3c 3e 32 3f 0a 20 20 20  |23  ; R0<>2?.   |
00000d80  20 43 4d 50 20 52 30 2c  23 31 32 36 3c 3c 32 33  | CMP R0,#126<<23|
00000d90  20 20 3b 20 52 30 3c 3e  30 2e 35 3f 20 20 65 74  |  ; R0<>0.5?  et|
00000da0  63 2e 0a 77 69 6c 6c 20  77 6f 72 6b 20 63 6f 72  |c..will work cor|
00000db0  72 65 63 74 6c 79 20 77  69 74 68 20 46 50 20 6e  |rectly with FP n|
00000dc0  75 6d 62 65 72 73 20 61  73 20 6c 6f 6e 67 20 61  |umbers as long a|
00000dd0  73 20 52 31 20 69 73 20  2b 76 65 2e 0a 0a 54 6f  |s R1 is +ve...To|
00000de0  20 63 6f 6d 70 61 72 65  20 63 6f 6e 73 74 61 6e  | compare constan|
00000df0  74 73 20 6f 74 68 65 72  20 74 68 61 6e 20 30 20  |ts other than 0 |
00000e00  79 6f 75 20 6e 65 65 64  20 74 6f 20 63 61 72 65  |you need to care|
00000e10  66 75 6c 6c 79 20 72 65  76 69 65 77 20 74 68 65  |fully review the|
00000e20  20 46 50 0a 66 6f 72 6d  61 74 2e 20 49 74 20 69  | FP.format. It i|
00000e30  73 20 75 73 75 61 6c 6c  79 20 65 61 73 69 65 72  |s usually easier|
00000e40  20 74 6f 20 6c 6f 61 64  20 61 20 66 6c 6f 61 74  | to load a float|
00000e50  20 63 6f 6e 73 74 61 6e  74 20 69 6e 74 6f 20 61  | constant into a|
00000e60  20 72 65 67 69 73 74 65  72 20 72 61 74 68 65 72  | register rather|
00000e70  0a 74 68 61 6e 20 68 61  72 64 20 63 6f 64 65 20  |.than hard code |
00000e80  69 74 2e 0a 0a 51 75 69  63 6b 20 4d 75 6c 74 69  |it...Quick Multi|
00000e90  70 6c 69 63 61 74 69 6f  6e 20 41 6e 64 20 44 69  |plication And Di|
00000ea0  76 69 73 69 6f 6e 20 4f  66 20 4e 75 6d 62 65 72  |vision Of Number|
00000eb0  73 0a 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |s.--------------|
00000ec0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000ed0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 0a 41  |--------------.A|
00000ee0  64 64 69 6e 67 20 31 20  74 6f 20 74 68 65 20 65  |dding 1 to the e|
00000ef0  78 70 6f 6e 65 6e 74 20  69 73 20 65 71 75 69 76  |xponent is equiv|
00000f00  61 6c 65 6e 74 20 74 6f  20 6d 75 6c 74 69 70 6c  |alent to multipl|
00000f10  79 69 6e 67 20 62 79 20  32 2c 20 69 65 0a 20 20  |ying by 2, ie.  |
00000f20  20 20 41 44 44 20 52 30  2c 52 30 2c 23 31 3c 3c  |  ADD R0,R0,#1<<|
00000f30  32 33 0a 54 68 69 73 20  69 73 20 74 68 65 20 73  |23.This is the s|
00000f40  61 6d 65 20 61 73 20 73  68 69 66 74 69 6e 67 20  |ame as shifting |
00000f50  61 6e 20 69 6e 74 65 67  65 72 20 6c 65 66 74 2e  |an integer left.|
00000f60  0a 53 69 6d 69 6c 61 72  6c 79 20 64 69 76 69 73  |.Similarly divis|
00000f70  69 6f 6e 20 62 79 20 32  20 63 61 6e 20 62 65 20  |ion by 2 can be |
00000f80  70 65 72 66 6f 72 6d 65  64 20 62 79 20 73 75 62  |performed by sub|
00000f90  74 72 61 63 74 69 6e 67  20 31 20 66 72 6f 6d 20  |tracting 1 from |
00000fa0  74 68 65 20 65 78 70 6f  6e 65 6e 74 3a 0a 20 20  |the exponent:.  |
00000fb0  20 20 53 55 42 20 52 30  2c 52 30 2c 23 31 3c 3c  |  SUB R0,R0,#1<<|
00000fc0  32 33 0a 43 61 72 65 20  6d 75 73 74 20 62 65 20  |23.Care must be |
00000fd0  74 61 6b 65 6e 20 74 6f  20 61 76 6f 69 64 20 75  |taken to avoid u|
00000fe0  6e 64 65 72 66 6c 6f 77  20 26 20 6f 76 65 72 66  |nderflow & overf|
00000ff0  6c 6f 77 20 65 66 66 65  63 74 73 2e 0a 0a 4e 6f  |low effects...No|
00001000  74 65 73 20 4f 6e 20 53  70 65 65 64 0a 2d 2d 2d  |tes On Speed.---|
00001010  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 0a 57 69 74 68  |-----------.With|
00001020  20 69 6e 74 65 67 65 72  73 20 63 6f 6e 73 69 64  | integers consid|
00001030  65 72 61 62 6c 65 20 73  70 65 65 64 20 73 61 76  |erable speed sav|
00001040  69 6e 67 73 20 63 61 6e  20 62 65 20 61 63 68 69  |ings can be achi|
00001050  65 76 65 64 20 62 79 20  73 75 62 73 74 69 74 75  |eved by substitu|
00001060  74 69 6e 67 0a 41 44 44  73 20 66 6f 72 20 4d 55  |ting.ADDs for MU|
00001070  4c 73 20 66 6f 72 20 66  69 78 65 64 20 6d 75 6c  |Ls for fixed mul|
00001080  74 69 70 6c 69 65 73 2e  20 57 69 74 68 20 74 68  |tiplies. With th|
00001090  65 20 46 50 20 72 6f 75  74 69 6e 65 73 20 70 72  |e FP routines pr|
000010a0  6f 76 69 64 65 64 20 74  68 65 72 65 20 69 73 0a  |ovided there is.|
000010b0  69 6e 73 75 66 66 69 63  69 65 6e 74 20 73 70 65  |insufficient spe|
000010c0  65 64 20 67 61 69 6e 20  74 6f 20 72 65 61 6c 6c  |ed gain to reall|
000010d0  79 20 77 61 72 72 61 6e  74 20 75 73 65 20 6f 66  |y warrant use of|
000010e0  20 74 68 69 73 20 74 65  63 68 6e 69 71 75 65 2e  | this technique.|
000010f0  0a 0a 46 75 74 75 72 65  20 44 65 76 65 6c 6f 70  |..Future Develop|
00001100  6d 65 6e 74 73 0a 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |ments.----------|
00001110  2d 2d 2d 2d 2d 2d 2d 2d  2d 0a 52 6f 75 74 69 6e  |---------.Routin|
00001120  65 73 20 77 69 6c 6c 20  62 65 20 61 64 64 65 64  |es will be added|
00001130  20 61 73 20 49 20 66 69  6e 64 20 74 68 65 20 6e  | as I find the n|
00001140  65 65 64 20 61 6e 64 20  67 65 74 20 74 69 6d 65  |eed and get time|
00001150  2e 20 49 66 20 79 6f 75  20 77 6f 75 6c 64 20 6c  |. If you would l|
00001160  69 6b 65 20 74 6f 0a 68  65 6c 70 20 6f 72 20 68  |ike to.help or h|
00001170  61 76 65 20 61 64 64 65  64 20 79 6f 75 72 20 6f  |ave added your o|
00001180  77 6e 20 72 6f 75 74 69  6e 65 73 2c 20 74 68 65  |wn routines, the|
00001190  6e 20 70 6c 65 61 73 65  20 63 6f 6e 74 61 63 74  |n please contact|
000011a0  20 6d 65 2e 0a 0a 50 6c  65 61 73 65 20 6e 6f 74  | me...Please not|
000011b0  65 20 74 68 61 74 20 6d  6f 73 74 20 6f 66 20 74  |e that most of t|
000011c0  68 65 73 65 20 72 6f 75  74 69 6e 65 73 20 61 72  |hese routines ar|
000011d0  65 20 73 74 69 6c 6c 20  69 6e 20 74 68 65 20 65  |e still in the e|
000011e0  78 70 65 72 69 6d 65 6e  74 61 6c 20 73 74 61 67  |xperimental stag|
000011f0  65 0a 61 6e 64 20 61 72  65 20 74 68 65 72 65 66  |e.and are theref|
00001200  6f 72 65 20 73 75 62 6a  65 63 74 20 74 6f 20 63  |ore subject to c|
00001210  68 61 6e 67 65 2c 20 69  6e 61 63 63 75 72 61 63  |hange, inaccurac|
00001220  79 20 61 6e 64 20 64 6f  20 6e 6f 74 20 72 65 61  |y and do not rea|
00001230  6c 69 73 65 20 74 68 65  20 66 75 6c 6c 0a 73 70  |lise the full.sp|
00001240  65 65 64 20 67 61 69 6e  20 70 6f 73 73 69 62 6c  |eed gain possibl|
00001250  65 2e 0a 0a 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |e...------------|
00001260  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
00001290  0a 0a 54 68 69 73 20 63  6f 64 65 20 6d 61 79 20  |..This code may |
000012a0  62 65 20 66 72 65 65 6c  79 20 63 6f 70 69 65 64  |be freely copied|
000012b0  20 61 6e 64 20 75 73 65  64 20 61 73 20 6c 6f 6e  | and used as lon|
000012c0  67 20 61 73 20 6e 6f 20  63 68 61 72 67 65 73 20  |g as no charges |
000012d0  61 72 65 20 6c 65 76 69  65 64 20 61 74 0a 61 6e  |are levied at.an|
000012e0  79 20 73 74 61 67 65 2e  20 43 6f 70 79 72 69 67  |y stage. Copyrig|
000012f0  68 74 20 62 65 6c 6f 6e  67 73 20 74 6f 20 4d 69  |ht belongs to Mi|
00001300  6b 65 20 43 75 72 6e 6f  77 2e 0a 0a 4d 69 6b 65  |ke Curnow...Mike|
00001310  20 43 75 72 6e 6f 77 0a  33 30 20 42 6f 77 65 6e  | Curnow.30 Bowen|
00001320  20 44 72 69 76 65 0a 57  65 73 74 20 44 75 6c 77  | Drive.West Dulw|
00001330  69 63 68 0a 4c 6f 6e 64  6f 6e 0a 53 45 32 31 20  |ich.London.SE21 |
00001340  38 50 4e                                          |8PN|
00001343