5 * Add two valid (TW_Valid) FPU_REG numbers, of the same sign, and put the
6 * result in a destination FPU_REG.
9 * void reg_u_add(FPU_REG *arg1, FPU_REG *arg2, FPU_REG *answ,
13 * Copyright (C) 1992,1993,1994
14 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
15 * Australia. E-mail billm@vaxc.cc.monash.edu.au
16 * All rights reserved.
18 * This copyright notice covers the redistribution and use of the
19 * FPU emulator developed by W. Metzenthen. It covers only its use
20 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
21 * use is not permitted under this copyright.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must include information specifying
29 * that source code for the emulator is freely available and include
31 * a) an offer to provide the source code for a nominal distribution
33 * b) list at least two alternative methods whereby the source
34 * can be obtained, e.g. a publically accessible bulletin board
35 * and an anonymous ftp site from which the software can be
37 * 3. All advertising materials specifically mentioning features or use of
38 * this emulator must acknowledge that it was developed by W. Metzenthen.
39 * 4. The name of W. Metzenthen may not be used to endorse or promote
40 * products derived from this software without specific prior written
43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
44 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
45 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
46 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
50 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
51 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 * The purpose of this copyright, based upon the Berkeley copyright, is to
56 * ensure that the covered software remains freely available to everyone.
58 * The software (with necessary differences) is also available, but under
59 * the terms of the GNU copyleft, for the Linux operating system and for
60 * the djgpp ms-dos extender.
62 * W. Metzenthen June 1994.
65 * $FreeBSD: src/sys/gnu/i386/fpemul/reg_u_add.s,v 1.9 1999/08/28 00:42:57 peter Exp $
66 * $DragonFly: src/sys/platform/pc32/gnu/fpemul/Attic/reg_u_add.s,v 1.2 2003/06/17 04:28:34 dillon Exp $
72 | Kernel addition routine reg_u_add(reg *arg1, reg *arg2, reg *answ).
73 | Takes two valid reg f.p. numbers (TW_Valid), which are
74 | treated as unsigned numbers,
75 | and returns their sum as a TW_Valid or TW_S f.p. number.
76 | The returned number is normalized.
77 | Basic checks are performed if PARANOID is defined.
80 #include <gnu/i386/fpemul/fpu_asm.h>
91 movl PARAM1,%esi /* source 1 */
92 movl PARAM2,%edi /* source 2 */
95 cmpl EXP_UNDER,EXP(%esi)
98 call _denormal_operand
103 cmpl EXP_UNDER,EXP(%edi)
106 call _denormal_operand
111 #endif DENORM_OPERAND
115 subl EXP(%edi),%ecx /* exp1 - exp2 */
116 /* jnc L_arg1_larger*/
119 /* num1 is smaller */
128 /* num1 has larger or equal exponent */
133 movl PARAM3,%edi /* destination */
135 movb %dl,SIGN(%edi) /* Copy the sign from the first arg */
139 movl %edx,EXP(%edi) /* Copy exponent to destination */
141 xorl %edx,%edx /* clear the extension */
144 testl $0x80000000,%eax
147 testl $0x80000000,SIGH(%esi)
151 /* The number to be shifted is in %eax:%ebx:%edx*/
152 cmpw $32,%cx /* shrd only works for 0..31 bits */
155 /* less than 32 bits */
171 jz L_more_31_no_low /* none of the lowest bits is set*/
173 orl $1,%edx /* record the fact in the extension*/
198 movl $1,%edx /* The shifted nr always at least one '1'*/
205 /* Now do the addition */
208 jnc L_round_the_result
210 /* Overflow, adjust the result */
222 jmp FPU_round /* Round the result*/
227 /* If we ever get here then we have problems! */
229 pushl EX_INTERNAL|0x201