5 * Divide one FPU_REG by another and put the result in a destination FPU_REG.
8 * void reg_div(FPU_REG *a, FPU_REG *b, FPU_REG *dest,
11 * Copyright (C) 1992,1993,1994
12 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
13 * Australia. E-mail billm@vaxc.cc.monash.edu.au
14 * All rights reserved.
16 * This copyright notice covers the redistribution and use of the
17 * FPU emulator developed by W. Metzenthen. It covers only its use
18 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
19 * use is not permitted under this copyright.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must include information specifying
27 * that source code for the emulator is freely available and include
29 * a) an offer to provide the source code for a nominal distribution
31 * b) list at least two alternative methods whereby the source
32 * can be obtained, e.g. a publically accessible bulletin board
33 * and an anonymous ftp site from which the software can be
35 * 3. All advertising materials specifically mentioning features or use of
36 * this emulator must acknowledge that it was developed by W. Metzenthen.
37 * 4. The name of W. Metzenthen may not be used to endorse or promote
38 * products derived from this software without specific prior written
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
42 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
43 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
44 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
49 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 * The purpose of this copyright, based upon the Berkeley copyright, is to
54 * ensure that the covered software remains freely available to everyone.
56 * The software (with necessary differences) is also available, but under
57 * the terms of the GNU copyleft, for the Linux operating system and for
58 * the djgpp ms-dos extender.
60 * W. Metzenthen June 1994.
63 * $FreeBSD: src/sys/gnu/i386/fpemul/reg_div.s,v 1.9.2.1 2000/07/07 00:38:42 obrien Exp $
64 * $DragonFly: src/sys/i386/gnu/fpemul/Attic/reg_div.s,v 1.4 2003/08/07 21:17:20 dillon Exp $
86 jne L_div_special /* Not (both numbers TW_Valid) */
89 /* Check for denormals */
90 cmpl EXP_UNDER,EXP(%esi)
91 jg xL_arg1_not_denormal
98 cmpl EXP_UNDER,EXP(%ebx)
99 jg xL_arg2_not_denormal
101 call denormal_operand
105 xL_arg2_not_denormal:
106 #endif DENORM_OPERAND
108 /* Both arguments are TW_Valid */
109 movb TW_Valid,TAG(%edi)
113 setne (%edi) /* Set the sign, requires SIGN_NEG=1, SIGN_POS=0 */
124 /*-----------------------------------------------------------------------*/
126 cmpb TW_NaN,TAG(%esi) /* A NaN with anything to give NaN */
129 cmpb TW_NaN,TAG(%ebx) /* A NaN with anything to give NaN */
132 /* Operations on NaNs */
135 pushl %edi /* Destination */
141 /* Invalid operations */
144 pushl %edi /* Destination */
145 call arith_invalid /* 0/0 or Infinity/Infinity */
149 cmpb TW_Infinity,TAG(%esi)
152 cmpb TW_Infinity,TAG(%ebx)
153 je L_inf_inf /* invalid operation */
155 cmpb TW_Valid,TAG(%ebx)
159 /* arg2 must be zero or valid */
160 cmpb TW_Zero,TAG(%ebx)
164 /* Note that p16-9 says that infinity/0 returns infinity */
165 jmp L_copy_arg1 /* Answer is Inf */
168 #ifdef DENORM_OPERAND
169 cmpl EXP_UNDER,EXP(%ebx)
170 jg L_copy_arg1 /* Answer is Inf */
172 call denormal_operand
175 #endif DENORM_OPERAND
177 jmp L_copy_arg1 /* Answer is Inf */
180 cmpb TW_Zero,TAG(%ebx) /* Priority to div-by-zero error */
183 cmpb TW_Zero,TAG(%esi)
184 je L_zero_zero /* invalid operation */
187 /* arg1 must be valid */
188 cmpb TW_Valid,TAG(%esi)
192 /* Division by zero error */
193 pushl %edi /* destination */
196 pushl %eax /* lower 8 bits have the sign */
201 cmpb TW_Infinity,TAG(%ebx)
204 #ifdef DENORM_OPERAND
205 cmpb TW_Valid,TAG(%esi)
208 cmpl EXP_UNDER,EXP(%esi)
209 jg L_return_zero /* Answer is zero */
211 call denormal_operand
214 #endif DENORM_OPERAND
216 jmp L_return_zero /* Answer is zero */
221 cmpb TW_Zero,TAG(%esi)
225 /* arg1 is zero, arg2 is not Infinity or a NaN */
227 #ifdef DENORM_OPERAND
228 cmpl EXP_UNDER,EXP(%ebx)
229 jg L_copy_arg1 /* Answer is zero */
231 call denormal_operand
234 #endif DENORM_OPERAND
248 jne LDiv_negative_result
250 movb SIGN_POS,SIGN(%edi)
253 LDiv_set_result_sign:
256 jne LDiv_negative_result
258 movb SIGN_POS,SIGN(%ebx)
261 LDiv_negative_result:
262 movb SIGN_NEG,SIGN(%edi)
275 movb TW_Zero,TAG(%edi)
276 jmp LDiv_set_result_sign
280 push EX_INTERNAL | 0x208
283 /* Generate a NaN for unknown tags */
284 movl _CONST_QNaN,%eax
286 movl _CONST_QNaN+4,%eax
288 movl _CONST_QNaN+8,%eax