1 .file "reg_u_mul.S" 2/* 3 * reg_u_mul.S 4 * 5 * Core multiplication routine 6 * 7 * 8 * Copyright (C) 1992, 1993 W. Metzenthen, 22 Parker St, Ormond, 9 * Vic 3163, Australia. 10 * E-mail apm233m@vaxc.cc.monash.edu.au 11 * All rights reserved. 12 * 13 * This copyright notice covers the redistribution and use of the 14 * FPU emulator developed by W. Metzenthen. It covers only its use 15 * in the 386BSD operating system. Any other use is not permitted 16 * under this copyright. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions 20 * are met: 21 * 1. Redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer. 23 * 2. Redistributions in binary form must include information specifying 24 * that source code for the emulator is freely available and include 25 * either: 26 * a) an offer to provide the source code for a nominal distribution 27 * fee, or 28 * b) list at least two alternative methods whereby the source 29 * can be obtained, e.g. a publically accessible bulletin board 30 * and an anonymous ftp site from which the software can be 31 * downloaded. 32 * 3. All advertising materials specifically mentioning features or use of 33 * this emulator must acknowledge that it was developed by W. Metzenthen. 34 * 4. The name of W. Metzenthen may not be used to endorse or promote 35 * products derived from this software without specific prior written 36 * permission. 37 * 38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 39 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 40 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 41 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 42 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 43 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 44 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 45 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 46 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 * 49 */ 50 51/*---------------------------------------------------------------------------+ 52 | Basic multiplication routine. | 53 | Does not check the resulting exponent for overflow/underflow | 54 | | 55 | reg_u_mul(FPU_REG *a, FPU_REG *b, FPU_REG *c, unsigned int cw); | 56 | | 57 | Internal working is at approx 128 bits. | 58 | Result is rounded to nearest 53 or 64 bits, using "nearest or even". | 59 +---------------------------------------------------------------------------*/ 60 61#include "exception.h" 62#include "fpu_asm.h" 63#include "control_w.h" 64 65 66.data 67 .align 2,0 68accum_0: 69 .long 0 70accum_1: 71 .long 0 72 73 74.text 75 .align 2,144 76 77.globl _reg_u_mul 78_reg_u_mul: 79 pushl %ebp 80 movl %esp,%ebp 81 pushl %esi 82 pushl %edi 83 pushl %ebx 84 85 movl PARAM1,%esi 86 movl PARAM2,%edi 87 88#ifdef PARANOID 89 testl $0x80000000,SIGH(%esi) 90 jz L_bugged 91 testl $0x80000000,SIGH(%edi) 92 jz L_bugged 93#endif PARANOID 94 95#ifdef DENORM_OPERAND 96 movl EXP(%esi),%eax 97 cmpl EXP_UNDER,%eax 98 jg xOp1_not_denorm 99 100 call _denormal_operand 101 orl %eax,%eax 102 jnz FPU_Arith_exit 103 104xOp1_not_denorm: 105 movl EXP(%edi),%eax 106 cmpl EXP_UNDER,%eax 107 jg xOp2_not_denorm 108 109 call _denormal_operand 110 orl %eax,%eax 111 jnz FPU_Arith_exit 112 113xOp2_not_denorm: 114#endif DENORM_OPERAND 115 116 xorl %ecx,%ecx 117 xorl %ebx,%ebx 118 119 movl SIGL(%esi),%eax 120 mull SIGL(%edi) 121 movl %eax,accum_0 122 movl %edx,accum_1 123 124 movl SIGL(%esi),%eax 125 mull SIGH(%edi) 126 addl %eax,accum_1 127 adcl %edx,%ebx 128 #// adcl $0,%ecx // overflow here is not possible 129 130 movl SIGH(%esi),%eax 131 mull SIGL(%edi) 132 addl %eax,accum_1 133 adcl %edx,%ebx 134 adcl $0,%ecx 135 136 movl SIGH(%esi),%eax 137 mull SIGH(%edi) 138 addl %eax,%ebx 139 adcl %edx,%ecx 140 141 movl EXP(%esi),%eax /* Compute the exponent */ 142 addl EXP(%edi),%eax 143 subl EXP_BIAS-1,%eax 144 #// Have now finished with the sources 145 movl PARAM3,%edi // Point to the destination 146 movl %eax,EXP(%edi) 147 148 #// Now make sure that the result is normalized 149 testl $0x80000000,%ecx 150 jnz LResult_Normalised 151 152 /* Normalize by shifting left one bit */ 153 shll $1,accum_0 154 rcll $1,accum_1 155 rcll $1,%ebx 156 rcll $1,%ecx 157 decl EXP(%edi) 158 159LResult_Normalised: 160 movl accum_0,%eax 161 movl accum_1,%edx 162 orl %eax,%eax 163 jz L_extent_zero 164 165 orl $1,%edx 166 167L_extent_zero: 168 movl %ecx,%eax 169 jmp FPU_round 170 171 172#ifdef PARANOID 173L_bugged: 174 pushl EX_INTERNAL|0x205 175 call EXCEPTION 176 pop %ebx 177 jmp L_exit 178 179L_exit: 180 popl %ebx 181 popl %edi 182 popl %esi 183 leave 184 ret 185#endif PARANOID 186 187