Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition) 

[ source navigation ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]
FreeBSD/Linux Kernel Cross Reference

Name  Size  Last modified (GMT)  Description  
Parent directory  20230129 20:53:10  
Changelog  1354 bytes  20230129 20:53:10  
README  12308 bytes  20230129 20:53:10  
control_w.h  3823 bytes  20230129 20:53:10  
div_small.s  3443 bytes  20230129 20:53:10  
errors.c  15582 bytes  20230129 20:53:10  
exception.h  3893 bytes  20230129 20:53:10  
fpu_arith.c  5290 bytes  20230129 20:53:10  
fpu_asm.h  3121 bytes  20230129 20:53:10  
fpu_aux.c  5363 bytes  20230129 20:53:10  
fpu_emu.h  6539 bytes  20230129 20:53:10  
fpu_entry.c  16668 bytes  20230129 20:53:10  
fpu_etc.c  4713 bytes  20230129 20:53:10  
fpu_proto.h  3387 bytes  20230129 20:53:10  
fpu_system.h  3734 bytes  20230129 20:53:10  
fpu_trig.c  32489 bytes  20230129 20:53:10  
get_address.c  6150 bytes  20230129 20:53:10  
load_store.c  9003 bytes  20230129 20:53:10  
math_emu.h  756 bytes  20230129 20:53:10  
poly_2xm1.c  4706 bytes  20230129 20:53:10  
poly_atan.c  7989 bytes  20230129 20:53:10  
poly_div.s  3883 bytes  20230129 20:53:10  
poly_l2.c  9575 bytes  20230129 20:53:10  
poly_mul64.s  3589 bytes  20230129 20:53:10  
poly_sin.c  6612 bytes  20230129 20:53:10  
poly_tan.c  7745 bytes  20230129 20:53:10  
polynomial.s  4947 bytes  20230129 20:53:10  
reg_add_sub.c  8921 bytes  20230129 20:53:10  
reg_compare.c  9613 bytes  20230129 20:53:10  
reg_constant.c  4813 bytes  20230129 20:53:10  
reg_constant.h  3198 bytes  20230129 20:53:10  
reg_div.s  6911 bytes  20230129 20:53:10  
reg_ld_str.c  35645 bytes  20230129 20:53:10  
reg_mul.c  5442 bytes  20230129 20:53:10  
reg_norm.s  4611 bytes  20230129 20:53:10  
reg_round.s  16911 bytes  20230129 20:53:10  
reg_u_add.s  5938 bytes  20230129 20:53:10  
reg_u_div.s  13234 bytes  20230129 20:53:10  
reg_u_mul.s  5258 bytes  20230129 20:53:10  
reg_u_sub.s  8387 bytes  20230129 20:53:10  
status_w.h  4122 bytes  20230129 20:53:10  
version.h  2733 bytes  20230129 20:53:10  
wm_shrx.s  7881 bytes  20230129 20:53:10  
wm_sqrt.s  11826 bytes  20230129 20:53:10 
1 /* 2 * wmFPUemu an FPU emulator for 80386 and 80486SX microprocessors. 3 * 4 * 5 * Copyright (C) 1992,1993,1994 6 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163, 7 * Australia. Email billm@vaxc.cc.monash.edu.au 8 * All rights reserved. 9 * 10 * This copyright notice covers the redistribution and use of the 11 * FPU emulator developed by W. Metzenthen. It covers only its use 12 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other 13 * use is not permitted under this copyright. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must include information specifying 21 * that source code for the emulator is freely available and include 22 * either: 23 * a) an offer to provide the source code for a nominal distribution 24 * fee, or 25 * b) list at least two alternative methods whereby the source 26 * can be obtained, e.g. a publically accessible bulletin board 27 * and an anonymous ftp site from which the software can be 28 * downloaded. 29 * 3. All advertising materials specifically mentioning features or use of 30 * this emulator must acknowledge that it was developed by W. Metzenthen. 31 * 4. The name of W. Metzenthen may not be used to endorse or promote 32 * products derived from this software without specific prior written 33 * permission. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 36 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 37 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 38 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 39 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 40 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 41 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 42 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 * 46 * 47 * The purpose of this copyright, based upon the Berkeley copyright, is to 48 * ensure that the covered software remains freely available to everyone. 49 * 50 * The software (with necessary differences) is also available, but under 51 * the terms of the GNU copyleft, for the Linux operating system and for 52 * the djgpp msdos extender. 53 * 54 * W. Metzenthen June 1994. 55 * 56 * $FreeBSD$ 57 */ 58 59 wmFPUemu is an FPU emulator for Linux. It is derived from wmemu387 60 which is my 80387 emulator for djgpp (gcc under msdos); wmemu387 was 61 in turn based upon emu387 which was written by DJ Delorie for djgpp. 62 The interface to the Linux kernel is based upon the original Linux 63 math emulator by Linus Torvalds. 64 65 My target FPU for wmFPUemu is that described in the Intel486 66 Programmer's Reference Manual (1992 edition). Numerous facets of the 67 functioning of the FPU are not well covered in the Reference Manual; 68 in the absence of clear details I have made guesses about the most 69 reasonable behaviour. Recently, this situation has improved because 70 I now have some access to the results produced by a real 80486 FPU. 71 72 wmFPUemu does not implement all of the behaviour of the 80486 FPU. 73 See "Limitations" later in this file for a partial list of some 74 differences. I believe that the missing features are never used by 75 normal C or FORTRAN programs. 76 77 78 Please report bugs, etc to me at: 79 apm233m@vaxc.cc.monash.edu.au 80 81 82 Bill Metzenthen 83 May 1993 84 85 86  Internals of wmFPUemu  87 88 Numeric algorithms: 89 (1) Add, subtract, and multiply. Nothing remarkable in these. 90 (2) Divide has been tuned to get reasonable performance. The algorithm 91 is not the obvious one which most people seem to use, but is designed 92 to take advantage of the characteristics of the 80386. I expect that 93 it has been invented many times before I discovered it, but I have not 94 seen it. It is based upon one of those ideas which one carries around 95 for years without ever bothering to check it out. 96 (3) The sqrt function has been tuned to get good performance. It is based 97 upon Newton's classic method. Performance was improved by capitalizing 98 upon the properties of Newton's method, and the code is once again 99 structured taking account of the 80386 characteristics. 100 (4) The trig, log, and exp functions are based in each case upon quasi 101 "optimal" polynomial approximations. My definition of "optimal" was 102 based upon getting good accuracy with reasonable speed. 103 104 The code of the emulator is complicated slightly by the need to 105 account for a limited form of reentrancy. Normally, the emulator will 106 emulate each FPU instruction to completion without interruption. 107 However, it may happen that when the emulator is accessing the user 108 memory space, swapping may be needed. In this case the emulator may be 109 temporarily suspended while disk i/o takes place. During this time 110 another process may use the emulator, thereby changing some static 111 variables (eg FPU_st0_ptr, etc). The code which accesses user memory 112 is confined to five files: 113 fpu_entry.c 114 reg_ld_str.c 115 load_store.c 116 get_address.c 117 errors.c 118 119  Limitations of wmFPUemu  120 121 There are a number of differences between the current wmFPUemu 122 (version beta 1.4) and the 80486 FPU (apart from bugs). Some of the 123 more important differences are listed below: 124 125 All internal computations are performed at 64 bit or higher precision 126 and rounded etc as required by the PC bits of the FPU control word. 127 Under the crt0 version for Linux current at March 1993, the FPU PC 128 bits specify 53 bits precision. 129 130 The precision flag (PE of the FPU status word) and the Roundup flag 131 (C1 of the status word) are now partially implemented. Does anyone 132 write code which uses these features? 133 134 The functions which load/store the FPU state are partially implemented, 135 but the implementation should be sufficient for handling FPU errors etc 136 in 32 bit protected mode. 137 138 The implementation of the exception mechanism is flawed for unmasked 139 interrupts. 140 141 Detection of certain conditions, such as denormal operands, is not yet 142 complete. 143 144  Performance of wmFPUemu  145 146 Speed. 147  148 149 The speed of floating point computation with the emulator will depend 150 upon instruction mix. Relative performance is best for the instructions 151 which require most computation. The simple instructions are adversely 152 affected by the fpu instruction trap overhead. 153 154 155 Timing: Some simple timing tests have been made on the emulator functions. 156 The times include load/store instructions. All times are in microseconds 157 measured on a 33MHz 386 with 64k cache. The Turbo C tests were under 158 msdos, the next two columns are for emulators running with the djgpp 159 msdos extender. The final column is for wmFPUemu in Linux 0.97, 160 using libm4.0 (hard). 161 162 function Turbo C djgpp 1.06 WMemu387 wmFPUemu 163 164 + 60.5 154.8 76.5 139.4 165  61.165.5 157.3160.8 76.279.5 142.9144.7 166 * 71.0 190.8 79.6 146.6 167 / 61.275.0 261.4266.9 75.391.6 142.2158.1 168 169 sin() 310.8 4692.0 319.0 398.5 170 cos() 284.4 4855.2 308.0 388.7 171 tan() 495.0 8807.1 394.9 504.7 172 atan() 328.9 4866.4 601.1 419.5491.9 173 174 sqrt() 128.7 crashed 145.2 227.0 175 log() 413.1419.1 5103.45354.21 254.7282.2 409.4437.1 176 exp() 479.1 6619.2 469.1 850.8 177 178 179 The performance under Linux is improved by the use of lookahead code. 180 The following results show the improvement which is obtained under 181 Linux due to the lookahead code. Also given are the times for the 182 original Linux emulator with the 4.1 'soft' lib. 183 184 [ Linus' note: I changed lookahead to be the default under linux, as 185 there was no reason not to use it after I had edited it to be 186 disabled during tracing ] 187 188 wmFPUemu w original w 189 lookahead 'soft' lib 190 + 106.4 190.2 191  108.6111.6 192.4216.2 192 * 113.4 193.1 193 / 108.8124.4 700.1706.2 194 195 sin() 390.5 2642.0 196 cos() 381.5 2767.4 197 tan() 496.5 3153.3 198 atan() 367.2435.5 2439.43396.8 199 200 sqrt() 195.1 4732.5 201 log() 358.0387.5 3359.23390.3 202 exp() 619.3 4046.4 203 204 205 These figures are now somewhat outofdate. The emulator has become 206 progressively slower for most functions as more of the 80486 features 207 have been implemented. 208 209 210  Accuracy of wmFPUemu  211 212 213 Accuracy: The following table gives the accuracy of the sqrt(), trig 214 and log functions. Each function was tested at about 400 points. Ideal 215 results would be 64 bits. The reduced accuracy of cos() and tan() for 216 arguments greater than pi/4 can be thought of as being due to the 217 precision of the argument x; e.g. an argument of pi/2(1e10) which is 218 accurate to 64 bits can result in a relative accuracy in cos() of about 219 64 + log2(cos(x)) = 31 bits. Results for the Turbo C emulator are given 220 in the last column. 221 222 223 Function Tested x range Worst result (bits) Turbo C 224 225 sqrt(x) 1 .. 2 64.1 63.2 226 atan(x) 1e10 .. 200 62.6 62.8 227 cos(x) 0 .. pi/2(1e10) 63.2 (x <= pi/4) 62.4 228 35.2 (x = pi/2(1e10)) 31.9 229 sin(x) 1e10 .. pi/2 63.0 62.8 230 tan(x) 1e10 .. pi/2(1e10) 62.4 (x <= pi/4) 62.1 231 35.2 (x = pi/2(1e10)) 31.9 232 exp(x) 0 .. 1 63.1 62.9 233 log(x) 1+1e6 .. 2 62.4 62.1 234 235 236 As of version 1.3 of the emulator, the accuracy of the basic 237 arithmetic has been improved (by a small fraction of a bit). Care has 238 been taken to ensure full accuracy of the rounding of the basic 239 arithmetic functions (+,,*,/,and fsqrt), and they all now produce 240 results which are exact to the 64th bit (unless there are any bugs 241 left). To ensure this, it was necessary to effectively get information 242 of up to about 128 bits precision. The emulator now passes the 243 "paranoia" tests (compiled with gcc 2.3.3) for 'float' variables (24 244 bit precision numbers) when precision control is set to 24, 53 or 64 245 bits, and for 'double' variables (53 bit precision numbers) when 246 precision control is set to 53 bits (a properly performing FPU cannot 247 pass the 'paranoia' tests for 'double' variables when precision 248 control is set to 64 bits). 249 250  Contributors  251 252 A number of people have contributed to the development of the 253 emulator, often by just reporting bugs, sometimes with a suggested 254 fix, and a few kind people have provided me with access in one way or 255 another to an 80486 machine. Contributors include (to those people who 256 I have forgotten, please excuse me): 257 258 Linus Torvalds 259 Tommy.Thorn@daimi.aau.dk 260 Andrew.Tridgell@anu.edu.au 261 Nick Holloway alfie@dcs.warwick.ac.uk 262 Hermano Moura moura@dcs.gla.ac.uk 263 Jon Jagger J.Jagger@scp.ac.uk 264 Lennart Benschop 265 Brian Gallew geek+@CMU.EDU 266 Thomas Staniszewski ts3v+@andrew.cmu.edu 267 Martin Howell mph@plasma.apana.org.au 268 M Saggaf alsaggaf@athena.mit.edu 269 Peter Barker PETER@socpsy.sci.fau.edu 270 tom@vlsivie.tuwien.ac.at 271 Dan Russel russed@rpi.edu 272 Daniel Carosone danielce@ee.mu.oz.au 273 cae@jpmorgan.com 274 Hamish Coleman t933093@minyos.xx.rmit.oz.au 275 276 ...and numerous others who responded to my request for help with 277 a real 80486. 278
[ source navigation ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]
This page is part of the FreeBSD/Linux Linux Kernel CrossReference, and was automatically generated using a modified version of the LXR engine.