grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathffp / spmul.c
blob8f128dee7b660f044f9b2d3f6919a59d2d91244f
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH2(float, SPMul,
14 /* SYNOPSIS */
15 AROS_LHA(float, fnum1, D1),
16 AROS_LHA(float, fnum2, D0),
18 /* LOCATION */
19 struct LibHeader *, MathBase, 13, Mathffp)
21 /* FUNCTION
22 Multiply two ffp numbers
23 fnum = fnum1 * fnum2;
25 INPUTS
27 RESULT
28 FFP number
30 Flags:
31 zero : result is zero
32 negative : result is negative
33 overflow : result is out of range
35 BUGS
37 INTERNALS
39 *****************************************************************************/
41 AROS_LIBFUNC_INIT
43 char Exponent = ((char) fnum1 & FFPExponent_Mask)
44 + ((char) fnum2 & FFPExponent_Mask) - 0x41;
45 ULONG Mant1H = ( (ULONG) (fnum1 & FFPMantisse_Mask)) >> 20;
46 ULONG Mant2H = ( (ULONG) (fnum2 & FFPMantisse_Mask)) >> 20;
47 ULONG Mant1L = (((ULONG) (fnum1 & FFPMantisse_Mask)) >> 8) & 0x00000fff;
48 ULONG Mant2L = (((ULONG) (fnum2 & FFPMantisse_Mask)) >> 8) & 0x00000fff;
49 LONG Res;
51 Res = (Mant1H * Mant2H) << 8;
52 Res += ((Mant1H * Mant2L) >> 4);
53 Res += ((Mant1L * Mant2H) >> 4);
54 Res += ((Mant1L * Mant2L) >> 16);
55 Res &= FFPMantisse_Mask;
57 /* Bit 32 is not set */
58 if ((LONG)Res > 0)
60 Res <<= 1; /* rotate the mantisse by one bit to the left */
62 else
64 Exponent ++;
67 if (0 == Res)
69 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
70 return 0;
73 Res |= ((fnum1 & FFPSign_Mask) ^ (fnum2 & FFPSign_Mask) );
75 /* overflow? */
76 if ((char) Exponent < 0 || (char) Exponent == 0x7f)
78 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
79 D(kprintf("SPMul(%x * %x) = %x\n",fnum1,fnum2,Res));
80 return (Res | (FFPMantisse_Mask + FFPExponent_Mask));
83 Res |= Exponent;
85 if ((char) Res < 0)
87 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
90 D(kprintf("SPMul(%x * %x) = %x\n", fnum1, fnum2, Res));
92 return Res;
94 AROS_LIBFUNC_EXIT