162306a36Sopenharmony_ci +---------------------------------------------------------------------------+
262306a36Sopenharmony_ci |  wm-FPU-emu   an FPU emulator for 80386 and 80486SX microprocessors.      |
362306a36Sopenharmony_ci |                                                                           |
462306a36Sopenharmony_ci | Copyright (C) 1992,1993,1994,1995,1996,1997,1999                          |
562306a36Sopenharmony_ci |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
662306a36Sopenharmony_ci |                       Australia.  E-mail billm@melbpc.org.au              |
762306a36Sopenharmony_ci |                                                                           |
862306a36Sopenharmony_ci |    This program is free software; you can redistribute it and/or modify   |
962306a36Sopenharmony_ci |    it under the terms of the GNU General Public License version 2 as      |
1062306a36Sopenharmony_ci |    published by the Free Software Foundation.                             |
1162306a36Sopenharmony_ci |                                                                           |
1262306a36Sopenharmony_ci |    This program is distributed in the hope that it will be useful,        |
1362306a36Sopenharmony_ci |    but WITHOUT ANY WARRANTY; without even the implied warranty of         |
1462306a36Sopenharmony_ci |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          |
1562306a36Sopenharmony_ci |    GNU General Public License for more details.                           |
1662306a36Sopenharmony_ci |                                                                           |
1762306a36Sopenharmony_ci |    You should have received a copy of the GNU General Public License      |
1862306a36Sopenharmony_ci |    along with this program; if not, write to the Free Software            |
1962306a36Sopenharmony_ci |    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              |
2062306a36Sopenharmony_ci |                                                                           |
2162306a36Sopenharmony_ci +---------------------------------------------------------------------------+
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciwm-FPU-emu is an FPU emulator for Linux. It is derived from wm-emu387
2662306a36Sopenharmony_ciwhich was my 80387 emulator for early versions of djgpp (gcc under
2762306a36Sopenharmony_cimsdos); wm-emu387 was in turn based upon emu387 which was written by
2862306a36Sopenharmony_ciDJ Delorie for djgpp.  The interface to the Linux kernel is based upon
2962306a36Sopenharmony_cithe original Linux math emulator by Linus Torvalds.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciMy target FPU for wm-FPU-emu is that described in the Intel486
3262306a36Sopenharmony_ciProgrammer's Reference Manual (1992 edition). Unfortunately, numerous
3362306a36Sopenharmony_cifacets of the functioning of the FPU are not well covered in the
3462306a36Sopenharmony_ciReference Manual. The information in the manual has been supplemented
3562306a36Sopenharmony_ciwith measurements on real 80486's. Unfortunately, it is simply not
3662306a36Sopenharmony_cipossible to be sure that all of the peculiarities of the 80486 have
3762306a36Sopenharmony_cibeen discovered, so there is always likely to be obscure differences
3862306a36Sopenharmony_ciin the detailed behaviour of the emulator and a real 80486.
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciwm-FPU-emu does not implement all of the behaviour of the 80486 FPU,
4162306a36Sopenharmony_cibut is very close.  See "Limitations" later in this file for a list of
4262306a36Sopenharmony_cisome differences.
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciPlease report bugs, etc to me at:
4562306a36Sopenharmony_ci       billm@melbpc.org.au
4662306a36Sopenharmony_cior     b.metzenthen@medoto.unimelb.edu.au
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciFor more information on the emulator and on floating point topics, see
4962306a36Sopenharmony_cimy web pages, currently at  http://www.suburbia.net/~billm/
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci--Bill Metzenthen
5362306a36Sopenharmony_ci  December 1999
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci----------------------- Internals of wm-FPU-emu -----------------------
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciNumeric algorithms:
5962306a36Sopenharmony_ci(1) Add, subtract, and multiply. Nothing remarkable in these.
6062306a36Sopenharmony_ci(2) Divide has been tuned to get reasonable performance. The algorithm
6162306a36Sopenharmony_ci    is not the obvious one which most people seem to use, but is designed
6262306a36Sopenharmony_ci    to take advantage of the characteristics of the 80386. I expect that
6362306a36Sopenharmony_ci    it has been invented many times before I discovered it, but I have not
6462306a36Sopenharmony_ci    seen it. It is based upon one of those ideas which one carries around
6562306a36Sopenharmony_ci    for years without ever bothering to check it out.
6662306a36Sopenharmony_ci(3) The sqrt function has been tuned to get good performance. It is based
6762306a36Sopenharmony_ci    upon Newton's classic method. Performance was improved by capitalizing
6862306a36Sopenharmony_ci    upon the properties of Newton's method, and the code is once again
6962306a36Sopenharmony_ci    structured taking account of the 80386 characteristics.
7062306a36Sopenharmony_ci(4) The trig, log, and exp functions are based in each case upon quasi-
7162306a36Sopenharmony_ci    "optimal" polynomial approximations. My definition of "optimal" was
7262306a36Sopenharmony_ci    based upon getting good accuracy with reasonable speed.
7362306a36Sopenharmony_ci(5) The argument reducing code for the trig function effectively uses
7462306a36Sopenharmony_ci    a value of pi which is accurate to more than 128 bits. As a consequence,
7562306a36Sopenharmony_ci    the reduced argument is accurate to more than 64 bits for arguments up
7662306a36Sopenharmony_ci    to a few pi, and accurate to more than 64 bits for most arguments,
7762306a36Sopenharmony_ci    even for arguments approaching 2^63. This is far superior to an
7862306a36Sopenharmony_ci    80486, which uses a value of pi which is accurate to 66 bits.
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciThe code of the emulator is complicated slightly by the need to
8162306a36Sopenharmony_ciaccount for a limited form of re-entrancy. Normally, the emulator will
8262306a36Sopenharmony_ciemulate each FPU instruction to completion without interruption.
8362306a36Sopenharmony_ciHowever, it may happen that when the emulator is accessing the user
8462306a36Sopenharmony_cimemory space, swapping may be needed. In this case the emulator may be
8562306a36Sopenharmony_citemporarily suspended while disk i/o takes place. During this time
8662306a36Sopenharmony_cianother process may use the emulator, thereby perhaps changing static
8762306a36Sopenharmony_civariables. The code which accesses user memory is confined to five
8862306a36Sopenharmony_cifiles:
8962306a36Sopenharmony_ci    fpu_entry.c
9062306a36Sopenharmony_ci    reg_ld_str.c
9162306a36Sopenharmony_ci    load_store.c
9262306a36Sopenharmony_ci    get_address.c
9362306a36Sopenharmony_ci    errors.c
9462306a36Sopenharmony_ciAs from version 1.12 of the emulator, no static variables are used
9562306a36Sopenharmony_ci(apart from those in the kernel's per-process tables). The emulator is
9662306a36Sopenharmony_citherefore now fully re-entrant, rather than having just the restricted
9762306a36Sopenharmony_ciform of re-entrancy which is required by the Linux kernel.
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci----------------------- Limitations of wm-FPU-emu -----------------------
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciThere are a number of differences between the current wm-FPU-emu
10262306a36Sopenharmony_ci(version 2.01) and the 80486 FPU (apart from bugs).  The differences
10362306a36Sopenharmony_ciare fewer than those which applied to the 1.xx series of the emulator.
10462306a36Sopenharmony_ciSome of the more important differences are listed below:
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciThe Roundup flag does not have much meaning for the transcendental
10762306a36Sopenharmony_cifunctions and its 80486 value with these functions is likely to differ
10862306a36Sopenharmony_cifrom its emulator value.
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciIn a few rare cases the Underflow flag obtained with the emulator will
11162306a36Sopenharmony_cibe different from that obtained with an 80486. This occurs when the
11262306a36Sopenharmony_cifollowing conditions apply simultaneously:
11362306a36Sopenharmony_ci(a) the operands have a higher precision than the current setting of the
11462306a36Sopenharmony_ci    precision control (PC) flags.
11562306a36Sopenharmony_ci(b) the underflow exception is masked.
11662306a36Sopenharmony_ci(c) the magnitude of the exact result (before rounding) is less than 2^-16382.
11762306a36Sopenharmony_ci(d) the magnitude of the final result (after rounding) is exactly 2^-16382.
11862306a36Sopenharmony_ci(e) the magnitude of the exact result would be exactly 2^-16382 if the
11962306a36Sopenharmony_ci    operands were rounded to the current precision before the arithmetic
12062306a36Sopenharmony_ci    operation was performed.
12162306a36Sopenharmony_ciIf all of these apply, the emulator will set the Underflow flag but a real
12262306a36Sopenharmony_ci80486 will not.
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciNOTE: Certain formats of Extended Real are UNSUPPORTED. They are
12562306a36Sopenharmony_ciunsupported by the 80486. They are the Pseudo-NaNs, Pseudoinfinities,
12662306a36Sopenharmony_ciand Unnormals. None of these will be generated by an 80486 or by the
12762306a36Sopenharmony_ciemulator. Do not use them. The emulator treats them differently in
12862306a36Sopenharmony_cidetail from the way an 80486 does.
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ciSelf modifying code can cause the emulator to fail. An example of such
13162306a36Sopenharmony_cicode is:
13262306a36Sopenharmony_ci          movl %esp,[%ebx]
13362306a36Sopenharmony_ci	  fld1
13462306a36Sopenharmony_ciThe FPU instruction may be (usually will be) loaded into the pre-fetch
13562306a36Sopenharmony_ciqueue of the CPU before the mov instruction is executed. If the
13662306a36Sopenharmony_cidestination of the 'movl' overlaps the FPU instruction then the bytes
13762306a36Sopenharmony_ciin the prefetch queue and memory will be inconsistent when the FPU
13862306a36Sopenharmony_ciinstruction is executed. The emulator will be invoked but will not be
13962306a36Sopenharmony_ciable to find the instruction which caused the device-not-present
14062306a36Sopenharmony_ciexception. For this case, the emulator cannot emulate the behaviour of
14162306a36Sopenharmony_cian 80486DX.
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciHandling of the address size override prefix byte (0x67) has not been
14462306a36Sopenharmony_ciextensively tested yet. A major problem exists because using it in
14562306a36Sopenharmony_civm86 mode can cause a general protection fault. Address offsets
14662306a36Sopenharmony_cigreater than 0xffff appear to be illegal in vm86 mode but are quite
14762306a36Sopenharmony_ciacceptable (and work) in real mode. A small test program developed to
14862306a36Sopenharmony_cicheck the addressing, and which runs successfully in real mode,
14962306a36Sopenharmony_cicrashes dosemu under Linux and also brings Windows down with a general
15062306a36Sopenharmony_ciprotection fault message when run under the MS-DOS prompt of Windows
15162306a36Sopenharmony_ci3.1. (The program simply reads data from a valid address).
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ciThe emulator supports 16-bit protected mode, with one difference from
15462306a36Sopenharmony_cian 80486DX.  A 80486DX will allow some floating point instructions to
15562306a36Sopenharmony_ciwrite a few bytes below the lowest address of the stack.  The emulator
15662306a36Sopenharmony_ciwill not allow this in 16-bit protected mode: no instructions are
15762306a36Sopenharmony_ciallowed to write outside the bounds set by the protection.
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci----------------------- Performance of wm-FPU-emu -----------------------
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ciSpeed.
16262306a36Sopenharmony_ci-----
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciThe speed of floating point computation with the emulator will depend
16562306a36Sopenharmony_ciupon instruction mix. Relative performance is best for the instructions
16662306a36Sopenharmony_ciwhich require most computation. The simple instructions are adversely
16762306a36Sopenharmony_ciaffected by the FPU instruction trap overhead.
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ciTiming: Some simple timing tests have been made on the emulator functions.
17162306a36Sopenharmony_ciThe times include load/store instructions. All times are in microseconds
17262306a36Sopenharmony_cimeasured on a 33MHz 386 with 64k cache. The Turbo C tests were under
17362306a36Sopenharmony_cims-dos, the next two columns are for emulators running with the djgpp
17462306a36Sopenharmony_cims-dos extender. The final column is for wm-FPU-emu in Linux 0.97,
17562306a36Sopenharmony_ciusing libm4.0 (hard).
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cifunction      Turbo C        djgpp 1.06        WM-emu387     wm-FPU-emu
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci   +          60.5           154.8              76.5          139.4
18062306a36Sopenharmony_ci   -          61.1-65.5      157.3-160.8        76.2-79.5     142.9-144.7
18162306a36Sopenharmony_ci   *          71.0           190.8              79.6          146.6
18262306a36Sopenharmony_ci   /          61.2-75.0      261.4-266.9        75.3-91.6     142.2-158.1
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci sin()        310.8          4692.0            319.0          398.5
18562306a36Sopenharmony_ci cos()        284.4          4855.2            308.0          388.7
18662306a36Sopenharmony_ci tan()        495.0          8807.1            394.9          504.7
18762306a36Sopenharmony_ci atan()       328.9          4866.4            601.1          419.5-491.9
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci sqrt()       128.7          crashed           145.2          227.0
19062306a36Sopenharmony_ci log()        413.1-419.1    5103.4-5354.21    254.7-282.2    409.4-437.1
19162306a36Sopenharmony_ci exp()        479.1          6619.2            469.1          850.8
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ciThe performance under Linux is improved by the use of look-ahead code.
19562306a36Sopenharmony_ciThe following results show the improvement which is obtained under
19662306a36Sopenharmony_ciLinux due to the look-ahead code. Also given are the times for the
19762306a36Sopenharmony_cioriginal Linux emulator with the 4.1 'soft' lib.
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci [ Linus' note: I changed look-ahead to be the default under linux, as
20062306a36Sopenharmony_ci   there was no reason not to use it after I had edited it to be
20162306a36Sopenharmony_ci   disabled during tracing ]
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci            wm-FPU-emu w     original w
20462306a36Sopenharmony_ci            look-ahead       'soft' lib
20562306a36Sopenharmony_ci   +         106.4             190.2
20662306a36Sopenharmony_ci   -         108.6-111.6      192.4-216.2
20762306a36Sopenharmony_ci   *         113.4             193.1
20862306a36Sopenharmony_ci   /         108.8-124.4      700.1-706.2
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci sin()       390.5            2642.0
21162306a36Sopenharmony_ci cos()       381.5            2767.4
21262306a36Sopenharmony_ci tan()       496.5            3153.3
21362306a36Sopenharmony_ci atan()      367.2-435.5     2439.4-3396.8
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci sqrt()      195.1            4732.5
21662306a36Sopenharmony_ci log()       358.0-387.5     3359.2-3390.3
21762306a36Sopenharmony_ci exp()       619.3            4046.4
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ciThese figures are now somewhat out-of-date. The emulator has become
22162306a36Sopenharmony_ciprogressively slower for most functions as more of the 80486 features
22262306a36Sopenharmony_cihave been implemented.
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci----------------------- Accuracy of wm-FPU-emu -----------------------
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ciThe accuracy of the emulator is in almost all cases equal to or better
22962306a36Sopenharmony_cithan that of an Intel 80486 FPU.
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ciThe results of the basic arithmetic functions (+,-,*,/), and fsqrt
23262306a36Sopenharmony_cimatch those of an 80486 FPU. They are the best possible; the error for
23362306a36Sopenharmony_cithese never exceeds 1/2 an lsb. The fprem and fprem1 instructions
23462306a36Sopenharmony_cireturn exact results; they have no error.
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ciThe following table compares the emulator accuracy for the sqrt(),
23862306a36Sopenharmony_citrig and log functions against the Turbo C "emulator". For this table,
23962306a36Sopenharmony_cieach function was tested at about 400 points. Ideal worst-case results
24062306a36Sopenharmony_ciwould be 64 bits. The reduced Turbo C accuracy of cos() and tan() for
24162306a36Sopenharmony_ciarguments greater than pi/4 can be thought of as being related to the
24262306a36Sopenharmony_ciprecision of the argument x; e.g. an argument of pi/2-(1e-10) which is
24362306a36Sopenharmony_ciaccurate to 64 bits can result in a relative accuracy in cos() of
24462306a36Sopenharmony_ciabout 64 + log2(cos(x)) = 31 bits.
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ciFunction      Tested x range            Worst result                Turbo C
24862306a36Sopenharmony_ci                                        (relative bits)
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_cisqrt(x)       1 .. 2                    64.1                         63.2
25162306a36Sopenharmony_ciatan(x)       1e-10 .. 200              64.2                         62.8
25262306a36Sopenharmony_cicos(x)        0 .. pi/2-(1e-10)         64.4 (x <= pi/4)             62.4
25362306a36Sopenharmony_ci                                        64.1 (x = pi/2-(1e-10))      31.9
25462306a36Sopenharmony_cisin(x)        1e-10 .. pi/2             64.0                         62.8
25562306a36Sopenharmony_citan(x)        1e-10 .. pi/2-(1e-10)     64.0 (x <= pi/4)             62.1
25662306a36Sopenharmony_ci                                        64.1 (x = pi/2-(1e-10))      31.9
25762306a36Sopenharmony_ciexp(x)        0 .. 1                    63.1 **                      62.9
25862306a36Sopenharmony_cilog(x)        1+1e-6 .. 2               63.8 **                      62.1
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci** The accuracy for exp() and log() is low because the FPU (emulator)
26162306a36Sopenharmony_cidoes not compute them directly; two operations are required.
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ciThe emulator passes the "paranoia" tests (compiled with gcc 2.3.3 or
26562306a36Sopenharmony_cilater) for 'float' variables (24 bit precision numbers) when precision
26662306a36Sopenharmony_cicontrol is set to 24, 53 or 64 bits, and for 'double' variables (53
26762306a36Sopenharmony_cibit precision numbers) when precision control is set to 53 bits (a
26862306a36Sopenharmony_ciproperly performing FPU cannot pass the 'paranoia' tests for 'double'
26962306a36Sopenharmony_civariables when precision control is set to 64 bits).
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ciThe code for reducing the argument for the trig functions (fsin, fcos,
27262306a36Sopenharmony_cifptan and fsincos) has been improved and now effectively uses a value
27362306a36Sopenharmony_cifor pi which is accurate to more than 128 bits precision. As a
27462306a36Sopenharmony_ciconsequence, the accuracy of these functions for large arguments has
27562306a36Sopenharmony_cibeen dramatically improved (and is now very much better than an 80486
27662306a36Sopenharmony_ciFPU). There is also now no degradation of accuracy for fcos and fptan
27762306a36Sopenharmony_cifor operands close to pi/2. Measured results are (note that the
27862306a36Sopenharmony_cidefinition of accuracy has changed slightly from that used for the
27962306a36Sopenharmony_ciabove table):
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ciFunction      Tested x range          Worst result
28262306a36Sopenharmony_ci                                     (absolute bits)
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_cicos(x)        0 .. 9.22e+18              62.0
28562306a36Sopenharmony_cisin(x)        1e-16 .. 9.22e+18          62.1
28662306a36Sopenharmony_citan(x)        1e-16 .. 9.22e+18          61.8
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ciIt is possible with some effort to find very large arguments which
28962306a36Sopenharmony_cigive much degraded precision. For example, the integer number
29062306a36Sopenharmony_ci           8227740058411162616.0
29162306a36Sopenharmony_ciis within about 10e-7 of a multiple of pi. To find the tan (for
29262306a36Sopenharmony_ciexample) of this number to 64 bits precision it would be necessary to
29362306a36Sopenharmony_cihave a value of pi which had about 150 bits precision. The FPU
29462306a36Sopenharmony_ciemulator computes the result to about 42.6 bits precision (the correct
29562306a36Sopenharmony_ciresult is about -9.739715e-8). On the other hand, an 80486 FPU returns
29662306a36Sopenharmony_ci0.01059, which in relative terms is hopelessly inaccurate.
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ciFor arguments close to critical angles (which occur at multiples of
29962306a36Sopenharmony_cipi/2) the emulator is more accurate than an 80486 FPU. For very large
30062306a36Sopenharmony_ciarguments, the emulator is far more accurate.
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ciPrior to version 1.20 of the emulator, the accuracy of the results for
30462306a36Sopenharmony_cithe transcendental functions (in their principal range) was not as
30562306a36Sopenharmony_cigood as the results from an 80486 FPU. From version 1.20, the accuracy
30662306a36Sopenharmony_cihas been considerably improved and these functions now give measured
30762306a36Sopenharmony_ciworst-case results which are better than the worst-case results given
30862306a36Sopenharmony_ciby an 80486 FPU.
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ciThe following table gives the measured results for the emulator. The
31162306a36Sopenharmony_cinumber of randomly selected arguments in each case is about half a
31262306a36Sopenharmony_cimillion.  The group of three columns gives the frequency of the given
31362306a36Sopenharmony_ciaccuracy in number of times per million, thus the second of these
31462306a36Sopenharmony_cicolumns shows that an accuracy of between 63.80 and 63.89 bits was
31562306a36Sopenharmony_cifound at a rate of 133 times per one million measurements for fsin.
31662306a36Sopenharmony_ciThe results show that the fsin, fcos and fptan instructions return
31762306a36Sopenharmony_ciresults which are in error (i.e. less accurate than the best possible
31862306a36Sopenharmony_ciresult (which is 64 bits)) for about one per cent of all arguments
31962306a36Sopenharmony_cibetween -pi/2 and +pi/2.  The other instructions have a lower
32062306a36Sopenharmony_cifrequency of results which are in error.  The last two columns give
32162306a36Sopenharmony_cithe worst accuracy which was found (in bits) and the approximate value
32262306a36Sopenharmony_ciof the argument which produced it.
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci                                frequency (per M)
32562306a36Sopenharmony_ci                               -------------------   ---------------
32662306a36Sopenharmony_ciinstr   arg range    # tests   63.7   63.8    63.9   worst   at arg
32762306a36Sopenharmony_ci                               bits   bits    bits    bits
32862306a36Sopenharmony_ci-----  ------------  -------   ----   ----   -----   -----  --------
32962306a36Sopenharmony_cifsin     (0,pi/2)     547756      0    133   10673   63.89  0.451317
33062306a36Sopenharmony_cifcos     (0,pi/2)     547563      0    126   10532   63.85  0.700801
33162306a36Sopenharmony_cifptan    (0,pi/2)     536274     11    267   10059   63.74  0.784876
33262306a36Sopenharmony_cifpatan  4 quadrants   517087      0      8    1855   63.88  0.435121 (4q)
33362306a36Sopenharmony_cifyl2x     (0,20)      541861      0      0    1323   63.94  1.40923  (x)
33462306a36Sopenharmony_cifyl2xp1 (-.293,.414)  520256      0      0    5678   63.93  0.408542 (x)
33562306a36Sopenharmony_cif2xm1     (-1,1)      538847      4    481    6488   63.79  0.167709
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ciTests performed on an 80486 FPU showed results of lower accuracy. The
33962306a36Sopenharmony_cifollowing table gives the results which were obtained with an AMD
34062306a36Sopenharmony_ci486DX2/66 (other tests indicate that an Intel 486DX produces
34162306a36Sopenharmony_ciidentical results).  The tests were basically the same as those used
34262306a36Sopenharmony_cito measure the emulator (the values, being random, were in general not
34362306a36Sopenharmony_cithe same).  The total number of tests for each instruction are given
34462306a36Sopenharmony_ciat the end of the table, in case each about 100k tests were performed.
34562306a36Sopenharmony_ciAnother line of figures at the end of the table shows that most of the
34662306a36Sopenharmony_ciinstructions return results which are in error for more than 10
34762306a36Sopenharmony_cipercent of the arguments tested.
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ciThe numbers in the body of the table give the approx number of times a
35062306a36Sopenharmony_ciresult of the given accuracy in bits (given in the left-most column)
35162306a36Sopenharmony_ciwas obtained per one million arguments. For three of the instructions,
35262306a36Sopenharmony_citwo columns of results are given: * The second column for f2xm1 gives
35362306a36Sopenharmony_cithe number cases where the results of the first column were for a
35462306a36Sopenharmony_cipositive argument, this shows that this instruction gives better
35562306a36Sopenharmony_ciresults for positive arguments than it does for negative.  * In the
35662306a36Sopenharmony_cicases of fcos and fptan, the first column gives the results when all
35762306a36Sopenharmony_cicases where arguments greater than 1.5 were removed from the results
35862306a36Sopenharmony_cigiven in the second column. Unlike the emulator, an 80486 FPU returns
35962306a36Sopenharmony_ciresults of relatively poor accuracy for these instructions when the
36062306a36Sopenharmony_ciargument approaches pi/2. The table does not show those cases when the
36162306a36Sopenharmony_ciaccuracy of the results were less than 62 bits, which occurs quite
36262306a36Sopenharmony_cioften for fsin and fptan when the argument approaches pi/2. This poor
36362306a36Sopenharmony_ciaccuracy is discussed above in relation to the Turbo C "emulator", and
36462306a36Sopenharmony_cithe accuracy of the value of pi.
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_cibits   f2xm1  f2xm1 fpatan   fcos   fcos  fyl2x fyl2xp1  fsin  fptan  fptan
36862306a36Sopenharmony_ci62.0       0      0      0      0    437      0      0      0      0    925
36962306a36Sopenharmony_ci62.1       0      0     10      0    894      0      0      0      0   1023
37062306a36Sopenharmony_ci62.2      14      0      0      0   1033      0      0      0      0    945
37162306a36Sopenharmony_ci62.3      57      0      0      0   1202      0      0      0      0   1023
37262306a36Sopenharmony_ci62.4     385      0      0     10   1292      0     23      0      0   1178
37362306a36Sopenharmony_ci62.5    1140      0      0    119   1649      0     39      0      0   1149
37462306a36Sopenharmony_ci62.6    2037      0      0    189   1620      0     16      0      0   1169
37562306a36Sopenharmony_ci62.7    5086     14      0    646   2315     10    101     35     39   1402
37662306a36Sopenharmony_ci62.8    8818     86      0    984   3050     59    287    131    224   2036
37762306a36Sopenharmony_ci62.9   11340   1355      0   2126   4153     79    605    357    321   1948
37862306a36Sopenharmony_ci63.0   15557   4750      0   3319   5376    246   1281    862    808   2688
37962306a36Sopenharmony_ci63.1   20016   8288      0   4620   6628    511   2569   1723   1510   3302
38062306a36Sopenharmony_ci63.2   24945  11127     10   6588   8098   1120   4470   2968   2990   4724
38162306a36Sopenharmony_ci63.3   25686  12382     69   8774  10682   1906   6775   4482   5474   7236
38262306a36Sopenharmony_ci63.4   29219  14722     79  11109  12311   3094   9414   7259   8912  10587
38362306a36Sopenharmony_ci63.5   30458  14936    393  13802  15014   5874  12666   9609  13762  15262
38462306a36Sopenharmony_ci63.6   32439  16448   1277  17945  19028  10226  15537  14657  19158  20346
38562306a36Sopenharmony_ci63.7   35031  16805   4067  23003  23947  18910  20116  21333  25001  26209
38662306a36Sopenharmony_ci63.8   33251  15820   7673  24781  25675  24617  25354  24440  29433  30329
38762306a36Sopenharmony_ci63.9   33293  16833  18529  28318  29233  31267  31470  27748  29676  30601
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ciPer cent with error:
39062306a36Sopenharmony_ci        30.9           3.2          18.5    9.8   13.1   11.6          17.4
39162306a36Sopenharmony_ciTotal arguments tested:
39262306a36Sopenharmony_ci       70194  70099 101784 100641 100641 101799 128853 114893 102675 102675
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci------------------------- Contributors -------------------------------
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ciA number of people have contributed to the development of the
39862306a36Sopenharmony_ciemulator, often by just reporting bugs, sometimes with suggested
39962306a36Sopenharmony_cifixes, and a few kind people have provided me with access in one way
40062306a36Sopenharmony_cior another to an 80486 machine. Contributors include (to those people
40162306a36Sopenharmony_ciwho I may have forgotten, please forgive me):
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ciLinus Torvalds
40462306a36Sopenharmony_ciTommy.Thorn@daimi.aau.dk
40562306a36Sopenharmony_ciAndrew.Tridgell@anu.edu.au
40662306a36Sopenharmony_ciNick Holloway, alfie@dcs.warwick.ac.uk
40762306a36Sopenharmony_ciHermano Moura, moura@dcs.gla.ac.uk
40862306a36Sopenharmony_ciJon Jagger, J.Jagger@scp.ac.uk
40962306a36Sopenharmony_ciLennart Benschop
41062306a36Sopenharmony_ciBrian Gallew, geek+@CMU.EDU
41162306a36Sopenharmony_ciThomas Staniszewski, ts3v+@andrew.cmu.edu
41262306a36Sopenharmony_ciMartin Howell, mph@plasma.apana.org.au
41362306a36Sopenharmony_ciM Saggaf, alsaggaf@athena.mit.edu
41462306a36Sopenharmony_ciPeter Barker, PETER@socpsy.sci.fau.edu
41562306a36Sopenharmony_citom@vlsivie.tuwien.ac.at
41662306a36Sopenharmony_ciDan Russel, russed@rpi.edu
41762306a36Sopenharmony_ciDaniel Carosone, danielce@ee.mu.oz.au
41862306a36Sopenharmony_cicae@jpmorgan.com
41962306a36Sopenharmony_ciHamish Coleman, t933093@minyos.xx.rmit.oz.au
42062306a36Sopenharmony_ciBruce Evans, bde@kralizec.zeta.org.au
42162306a36Sopenharmony_ciTimo Korvola, Timo.Korvola@hut.fi
42262306a36Sopenharmony_ciRick Lyons, rick@razorback.brisnet.org.au
42362306a36Sopenharmony_ciRick, jrs@world.std.com
42462306a36Sopenharmony_ci 
42562306a36Sopenharmony_ci...and numerous others who responded to my request for help with
42662306a36Sopenharmony_cia real 80486.
42762306a36Sopenharmony_ci
428