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 $
67 #include <gnu/i386/fpemul/fpu_asm.h>
85 jne L_div_special /* Not (both numbers TW_Valid) */
88 /* Check for denormals */
89 cmpl EXP_UNDER,EXP(%esi)
90 jg xL_arg1_not_denormal
92 call _denormal_operand
97 cmpl EXP_UNDER,EXP(%ebx)
98 jg xL_arg2_not_denormal
100 call _denormal_operand
104 xL_arg2_not_denormal:
105 #endif DENORM_OPERAND
107 /* Both arguments are TW_Valid */
108 movb TW_Valid,TAG(%edi)
112 setne (%edi) /* Set the sign, requires SIGN_NEG=1, SIGN_POS=0 */
123 /*-----------------------------------------------------------------------*/
125 cmpb TW_NaN,TAG(%esi) /* A NaN with anything to give NaN */
128 cmpb TW_NaN,TAG(%ebx) /* A NaN with anything to give NaN */
131 /* Operations on NaNs */
134 pushl %edi /* Destination */
140 /* Invalid operations */
143 pushl %edi /* Destination */
144 call _arith_invalid /* 0/0 or Infinity/Infinity */
148 cmpb TW_Infinity,TAG(%esi)
151 cmpb TW_Infinity,TAG(%ebx)
152 je L_inf_inf /* invalid operation */
154 cmpb TW_Valid,TAG(%ebx)
158 /* arg2 must be zero or valid */
159 cmpb TW_Zero,TAG(%ebx)
163 /* Note that p16-9 says that infinity/0 returns infinity */
164 jmp L_copy_arg1 /* Answer is Inf */
167 #ifdef DENORM_OPERAND
168 cmpl EXP_UNDER,EXP(%ebx)
169 jg L_copy_arg1 /* Answer is Inf */
171 call _denormal_operand
174 #endif DENORM_OPERAND
176 jmp L_copy_arg1 /* Answer is Inf */
179 cmpb TW_Zero,TAG(%ebx) /* Priority to div-by-zero error */
182 cmpb TW_Zero,TAG(%esi)
183 je L_zero_zero /* invalid operation */
186 /* arg1 must be valid */
187 cmpb TW_Valid,TAG(%esi)
191 /* Division by zero error */
192 pushl %edi /* destination */
195 pushl %eax /* lower 8 bits have the sign */
200 cmpb TW_Infinity,TAG(%ebx)
203 #ifdef DENORM_OPERAND
204 cmpb TW_Valid,TAG(%esi)
207 cmpl EXP_UNDER,EXP(%esi)
208 jg L_return_zero /* Answer is zero */
210 call _denormal_operand
213 #endif DENORM_OPERAND
215 jmp L_return_zero /* Answer is zero */
220 cmpb TW_Zero,TAG(%esi)
224 /* arg1 is zero, arg2 is not Infinity or a NaN */
226 #ifdef DENORM_OPERAND
227 cmpl EXP_UNDER,EXP(%ebx)
228 jg L_copy_arg1 /* Answer is zero */
230 call _denormal_operand
233 #endif DENORM_OPERAND
247 jne LDiv_negative_result
249 movb SIGN_POS,SIGN(%edi)
252 LDiv_set_result_sign:
255 jne LDiv_negative_result
257 movb SIGN_POS,SIGN(%ebx)
260 LDiv_negative_result:
261 movb SIGN_NEG,SIGN(%edi)
274 movb TW_Zero,TAG(%edi)
275 jmp LDiv_set_result_sign
279 push EX_INTERNAL | 0x208
282 /* Generate a NaN for unknown tags */
283 movl _CONST_QNaN,%eax
285 movl _CONST_QNaN+4,%eax
287 movl _CONST_QNaN+8,%eax