Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / mathffp / spmul.c
blob768fbc15e70517c97f68205e096601bfb8b2e674
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*
9 FUNCTION
10 Multiply two ffp numbers
11 fnum = fnum1 * fnum2;
13 RESULT
14 FFP number
16 Flags:
17 zero : result is zero
18 negative : result is negative
19 overflow : result is out of range
21 NOTES
23 EXAMPLE
25 BUGS
27 SEE ALSO
29 INTERNALS
31 HISTORY
34 AROS_LH2(float, SPMul,
35 AROS_LHA(float, fnum1, D1),
36 AROS_LHA(float, fnum2, D0),
37 struct LibHeader *, MathBase, 13, Mathffp
40 AROS_LIBFUNC_INIT
42 char Exponent = ((char) fnum1 & FFPExponent_Mask)
43 + ((char) fnum2 & FFPExponent_Mask) - 0x41;
44 ULONG Mant1H = ( (ULONG) (fnum1 & FFPMantisse_Mask)) >> 20;
45 ULONG Mant2H = ( (ULONG) (fnum2 & FFPMantisse_Mask)) >> 20;
46 ULONG Mant1L = (((ULONG) (fnum1 & FFPMantisse_Mask)) >> 8) & 0x00000fff;
47 ULONG Mant2L = (((ULONG) (fnum2 & FFPMantisse_Mask)) >> 8) & 0x00000fff;
48 LONG Res;
50 Res = (Mant1H * Mant2H) << 8;
51 Res += ((Mant1H * Mant2L) >> 4);
52 Res += ((Mant1L * Mant2H) >> 4);
53 Res += ((Mant1L * Mant2L) >> 16);
55 /* Bit 32 is not set */
56 if ((LONG)Res > 0)
58 Res <<= 1; /* rotate the mantisse by one bit to the left */
60 else
62 Exponent ++;
65 if (0 == Res)
67 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
68 return 0;
71 Res |= ((fnum1 & FFPSign_Mask) ^ (fnum2 & FFPSign_Mask) );
73 /* overflow? */
74 if ((char) Exponent < 0 || (char) Exponent == 0x7f)
76 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
77 kprintf("%x * %x = %x\n",fnum1,fnum2,Res);
78 return (Res | (FFPMantisse_Mask + FFPExponent_Mask));
81 Res |= Exponent;
83 if ((char) Res < 0)
85 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
88 kprintf("%x * %x = %x\n",fnum1,fnum2,Res);
90 return Res;
92 AROS_LIBFUNC_EXIT