home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.0 / LINUX-1.0 / LINUX-1 / linux / drivers / FPU-emu / README < prev    next >
Encoding:
Text File  |  1994-02-14  |  15.0 KB  |  317 lines

  1.  +---------------------------------------------------------------------------+
  2.  |  wm-FPU-emu   an FPU emulator for 80386 and 80486SX microprocessors.      |
  3.  |                                                                           |
  4.  | Copyright (C) 1992,1993,1994                                              |
  5.  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
  6.  |                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au    |
  7.  |                                                                           |
  8.  |    This program is free software; you can redistribute it and/or modify   |
  9.  |    it under the terms of the GNU General Public License version 2 as      |
  10.  |    published by the Free Software Foundation.                             |
  11.  |                                                                           |
  12.  |    This program is distributed in the hope that it will be useful,        |
  13.  |    but WITHOUT ANY WARRANTY; without even the implied warranty of         |
  14.  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          |
  15.  |    GNU General Public License for more details.                           |
  16.  |                                                                           |
  17.  |    You should have received a copy of the GNU General Public License      |
  18.  |    along with this program; if not, write to the Free Software            |
  19.  |    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              |
  20.  |                                                                           |
  21.  +---------------------------------------------------------------------------+
  22.  
  23.  
  24.  
  25. wm-FPU-emu is an FPU emulator for Linux. It is derived from wm-emu387
  26. which is my 80387 emulator for djgpp (gcc under msdos); wm-emu387 was
  27. in turn based upon emu387 which was written by DJ Delorie for djgpp.
  28. The interface to the Linux kernel is based upon the original Linux
  29. math emulator by Linus Torvalds.
  30.  
  31. My target FPU for wm-FPU-emu is that described in the Intel486
  32. Programmer's Reference Manual (1992 edition). Unfortunately, numerous
  33. facets of the functioning of the FPU are not well covered in the
  34. Reference Manual. The information in the manual has been supplemented
  35. with measurements on real 80486's. Unfortunately, it is simply not
  36. possible to be sure that all of the peculiarities of the 80486 have
  37. been discovered, so there is always likely to be obscure differences
  38. in the detailed behaviour of the emulator and a real 80486.
  39.  
  40. wm-FPU-emu does not implement all of the behaviour of the 80486 FPU.
  41. See "Limitations" later in this file for a list of some differences.
  42.  
  43. Please report bugs, etc to me at:
  44.        billm@vaxc.cc.monash.edu.au
  45.   or at:
  46.        billm@jacobi.maths.monash.edu.au
  47.  
  48.  
  49. --Bill Metzenthen
  50.   Feb 1994
  51.  
  52.  
  53. ----------------------- Internals of wm-FPU-emu -----------------------
  54.  
  55. Numeric algorithms:
  56. (1) Add, subtract, and multiply. Nothing remarkable in these.
  57. (2) Divide has been tuned to get reasonable performance. The algorithm
  58.     is not the obvious one which most people seem to use, but is designed
  59.     to take advantage of the characteristics of the 80386. I expect that
  60.     it has been invented many times before I discovered it, but I have not
  61.     seen it. It is based upon one of those ideas which one carries around
  62.     for years without ever bothering to check it out.
  63. (3) The sqrt function has been tuned to get good performance. It is based
  64.     upon Newton's classic method. Performance was improved by capitalizing
  65.     upon the properties of Newton's method, and the code is once again
  66.     structured taking account of the 80386 characteristics.
  67. (4) The trig, log, and exp functions are based in each case upon quasi-
  68.     "optimal" polynomial approximations. My definition of "optimal" was
  69.     based upon getting good accuracy with reasonable speed.
  70. (5) The argument reducing code for the trig function effectively uses
  71.     a value of pi which is accurate to more than 128 bits. As a consequence,
  72.     the reduced argument is accurate to more than 64 bits for arguments up
  73.     to a few pi, and accurate to more than 64 bits for most arguments,
  74.     even for arguments approaching 2^63. This is far superior to an
  75.     80486, which uses a value of pi which is accurate to 66 bits.
  76.  
  77. The code of the emulator is complicated slightly by the need to
  78. account for a limited form of re-entrancy. Normally, the emulator will
  79. emulate each FPU instruction to completion without interruption.
  80. However, it may happen that when the emulator is accessing the user
  81. memory space, swapping may be needed. In this case the emulator may be
  82. temporarily suspended while disk i/o takes place. During this time
  83. another process may use the emulator, thereby changing some static
  84. variables (eg FPU_st0_ptr, etc). The code which accesses user memory
  85. is confined to five files:
  86.     fpu_entry.c
  87.     reg_ld_str.c
  88.     load_store.c
  89.     get_address.c
  90.     errors.c
  91.  
  92. ----------------------- Limitations of wm-FPU-emu -----------------------
  93.  
  94. There are a number of differences between the current wm-FPU-emu
  95. (version beta 1.10) and the 80486 FPU (apart from bugs). Some of the
  96. more important differences are listed below:
  97.  
  98. The Roundup flag does not have much meaning for the transcendental
  99. functions and its 80486 value with these functions is likely to differ
  100. from its emulator value.
  101.  
  102. In a few rare cases the Underflow flag obtained with the emulator will
  103. be different from that obtained with an 80486. This occurs when the
  104. following conditions apply simultaneously:
  105. (a) the operands have a higher precision than the current setting of the
  106.     precision control (PC) flags.
  107. (b) the underflow exception is masked.
  108. (c) the magnitude of the exact result (before rounding) is less than 2^-16382.
  109. (d) the magnitude of the final result (after rounding) is exactly 2^-16382.
  110. (e) the magnitude of the exact result would be exactly 2^-16382 if the
  111.     operands were rounded to the current precision before the arithmetic
  112.     operation was performed.
  113. If all of these apply, the emulator will set the Underflow flag but a real
  114. 80486 will not.
  115.  
  116. NOTE: Certain formats of Extended Real are UNSUPPORTED. They are
  117. unsupported by the 80486. They are the Pseudo-NaNs, Pseudoinfinities,
  118. and Unnormals. None of these will be generated by an 80486 or by the
  119. emulator. Do not use them. The emulator treats them differently in
  120. detail from the way an 80486 does.
  121.  
  122. The emulator treats PseudoDenormals differently from an 80486. These
  123. numbers are in fact properly normalised numbers with the exponent
  124. offset by 1, and the emulator treats them as such. Unlike the 80486,
  125. the emulator does not generate a Denormal Operand exception for these
  126. numbers. The arithmetical results produced when using such a number as
  127. an operand are the same for the emulator and a real 80486 (apart from
  128. any slight precision difference for the transcendental functions).
  129. Neither the emulator nor an 80486 produces one of these numbers as the
  130. result of any arithmetic operation. An 80486 can keep one of these
  131. numbers in an FPU register with its identity as a PseudoDenormal, but
  132. the emulator will not; they are always converted to a valid number.
  133.  
  134. Self modifying code can cause the emulator to fail. An example of such
  135. code is:
  136.           movl %esp,[%ebx]
  137.       fld1
  138. The FPU instruction may be (usually will be) loaded into the pre-fetch
  139. queue of the cpu before the mov instruction is executed. If the
  140. destination of the 'movl' overlaps the FPU instruction then the bytes
  141. in the prefetch queue and memory will be inconsistent when the FPU
  142. instruction is executed. The emulator will be invoked but will not be
  143. able to find the instruction which caused the device-not-present
  144. exception. For this case, the emulator cannot emulate the behaviour of
  145. an 80486DX.
  146.  
  147. ----------------------- Performance of wm-FPU-emu -----------------------
  148.  
  149. Speed.
  150. -----
  151.  
  152. The speed of floating point computation with the emulator will depend
  153. upon instruction mix. Relative performance is best for the instructions
  154. which require most computation. The simple instructions are adversely
  155. affected by the fpu instruction trap overhead.
  156.  
  157.  
  158. Timing: Some simple timing tests have been made on the emulator functions.
  159. The times include load/store instructions. All times are in microseconds
  160. measured on a 33MHz 386 with 64k cache. The Turbo C tests were under
  161. ms-dos, the next two columns are for emulators running with the djgpp
  162. ms-dos extender. The final column is for wm-FPU-emu in Linux 0.97,
  163. using libm4.0 (hard).
  164.  
  165. function      Turbo C        djgpp 1.06        WM-emu387     wm-FPU-emu
  166.  
  167.    +          60.5           154.8              76.5          139.4
  168.    -          61.1-65.5      157.3-160.8        76.2-79.5     142.9-144.7
  169.    *          71.0           190.8              79.6          146.6
  170.    /          61.2-75.0      261.4-266.9        75.3-91.6     142.2-158.1
  171.  
  172.  sin()        310.8          4692.0            319.0          398.5
  173.  cos()        284.4          4855.2            308.0          388.7
  174.  tan()        495.0          8807.1            394.9          504.7
  175.  atan()       328.9          4866.4            601.1          419.5-491.9
  176.  
  177.  sqrt()       128.7          crashed           145.2          227.0
  178.  log()        413.1-419.1    5103.4-5354.21    254.7-282.2    409.4-437.1
  179.  exp()        479.1          6619.2            469.1          850.8
  180.  
  181.  
  182. The performance under Linux is improved by the use of look-ahead code.
  183. The following results show the improvement which is obtained under
  184. Linux due to the look-ahead code. Also given are the times for the
  185. original Linux emulator with the 4.1 'soft' lib.
  186.  
  187.  [ Linus' note: I changed look-ahead to be the default under linux, as
  188.    there was no reason not to use it after I had edited it to be
  189.    disabled during tracing ]
  190.  
  191.             wm-FPU-emu w     original w
  192.             look-ahead       'soft' lib
  193.    +         106.4             190.2
  194.    -         108.6-111.6      192.4-216.2
  195.    *         113.4             193.1
  196.    /         108.8-124.4      700.1-706.2
  197.  
  198.  sin()       390.5            2642.0
  199.  cos()       381.5            2767.4
  200.  tan()       496.5            3153.3
  201.  atan()      367.2-435.5     2439.4-3396.8
  202.  
  203.  sqrt()      195.1            4732.5
  204.  log()       358.0-387.5     3359.2-3390.3
  205.  exp()       619.3            4046.4
  206.  
  207.  
  208. These figures are now somewhat out-of-date. The emulator has become
  209. progressively slower for most functions as more of the 80486 features
  210. have been implemented.
  211.  
  212.  
  213. ----------------------- Accuracy of wm-FPU-emu -----------------------
  214.  
  215.  
  216. Accuracy: The following table gives the accuracy of the sqrt(), trig
  217. and log functions. Each function was tested at about 400 points. Ideal
  218. results would be 64 bits. The reduced accuracy of cos() and tan() for
  219. arguments greater than pi/4 can be thought of as being due to the
  220. precision of the argument x; e.g. an argument of pi/2-(1e-10) which is
  221. accurate to 64 bits can result in a relative accuracy in cos() of about
  222. 64 + log2(cos(x)) = 31 bits. Results for the Turbo C emulator are given
  223. in the last column.
  224.  
  225.  
  226. Function      Tested x range            Worst result                Turbo C
  227.                                         (relative bits)
  228.  
  229. sqrt(x)       1 .. 2                    64.1                         63.2
  230. atan(x)       1e-10 .. 200              62.6                         62.8
  231. cos(x)        0 .. pi/2-(1e-10)         63.2 (x <= pi/4)             62.4
  232.                                         35.2 (x = pi/2-(1e-10))      31.9
  233. sin(x)        1e-10 .. pi/2             63.0                         62.8
  234. tan(x)        1e-10 .. pi/2-(1e-10)     62.4 (x <= pi/4)             62.1
  235.                                         35.2 (x = pi/2-(1e-10))      31.9
  236. exp(x)        0 .. 1                    63.1                         62.9
  237. log(x)        1+1e-6 .. 2               62.4                         62.1
  238.  
  239.  
  240. As of version 1.3 of the emulator, the accuracy of the basic
  241. arithmetic has been improved (by a small fraction of a bit). Care has
  242. been taken to ensure full accuracy of the rounding of the basic
  243. arithmetic functions (+,-,*,/,and fsqrt), and they all now produce
  244. results which are exact to the 64th bit (unless there are any bugs
  245. left). To ensure this, it was necessary to effectively get information
  246. of up to about 128 bits precision. The emulator now passes the
  247. "paranoia" tests (compiled with gcc 2.3.3) for 'float' variables (24
  248. bit precision numbers) when precision control is set to 24, 53 or 64
  249. bits, and for 'double' variables (53 bit precision numbers) when
  250. precision control is set to 53 bits (a properly performing FPU cannot
  251. pass the 'paranoia' tests for 'double' variables when precision
  252. control is set to 64 bits).
  253.  
  254. For version 1.5, the accuracy of fprem and fprem1 has been improved.
  255. These functions now produce exact results. The code for reducing the
  256. argument for the trig functions (fsin, fcos, fptan and fsincos) has
  257. been improved and now effectively uses a value for pi which is
  258. accurate to more than 128 bits precision. As a consquence, the
  259. accuracy of these functions for large arguments has been dramatically
  260. improved (and is now very much better than an 80486 FPU). There is
  261. also now no degradation of accuracy for fcos and ftan for operands
  262. close to pi/2. Measured results are (note that the definition of
  263. accuracy has changed slightly from that used for the above table):
  264.  
  265. Function      Tested x range          Worst result
  266.                                      (absolute bits)
  267.  
  268. cos(x)        0 .. 9.22e+18              62.0
  269. sin(x)        1e-16 .. 9.22e+18          62.1
  270. tan(x)        1e-16 .. 9.22e+18          61.8
  271.  
  272. It is possible with some effort to find very large arguments which
  273. give much degraded precision. For example, the integer number
  274.            8227740058411162616.0
  275. is within about 10e-7 of a multiple of pi. To find the tan (for
  276. example) of this number to 64 bits precision it would be necessary to
  277. have a value of pi which had about 150 bits precision. The FPU
  278. emulator computes the result to about 42.6 bits precision (the correct
  279. result is about -9.739715e-8). On the other hand, an 80486 FPU returns
  280. 0.01059, which in relative terms is hopelessly inaccurate.
  281.  
  282. For arguments close to critical angles (which occur at multiples of
  283. pi/2) the emulator is more accurate than an 80486 FPU. For very large
  284. arguments, the emulator is far more accurate.
  285.  
  286. ------------------------- Contributors -------------------------------
  287.  
  288. A number of people have contributed to the development of the
  289. emulator, often by just reporting bugs, sometimes with suggested
  290. fixes, and a few kind people have provided me with access in one way
  291. or another to an 80486 machine. Contributors include (to those people
  292. who I may have forgotten, please forgive me):
  293.  
  294. Linus Torvalds
  295. Tommy.Thorn@daimi.aau.dk
  296. Andrew.Tridgell@anu.edu.au
  297. Nick Holloway, alfie@dcs.warwick.ac.uk
  298. Hermano Moura, moura@dcs.gla.ac.uk
  299. Jon Jagger, J.Jagger@scp.ac.uk
  300. Lennart Benschop
  301. Brian Gallew, geek+@CMU.EDU
  302. Thomas Staniszewski, ts3v+@andrew.cmu.edu
  303. Martin Howell, mph@plasma.apana.org.au
  304. M Saggaf, alsaggaf@athena.mit.edu
  305. Peter Barker, PETER@socpsy.sci.fau.edu
  306. tom@vlsivie.tuwien.ac.at
  307. Dan Russel, russed@rpi.edu
  308. Daniel Carosone, danielce@ee.mu.oz.au
  309. cae@jpmorgan.com
  310. Hamish Coleman, t933093@minyos.xx.rmit.oz.au
  311. Bruce Evans, bde@kralizec.zeta.org.au
  312. Timo Korvola, Timo.Korvola@hut.fi
  313.  
  314. ...and numerous others who responded to my request for help with
  315. a real 80486.
  316.  
  317.