1 /*-------------------------------------------------------------------------
2 _mullong.c - routine for multiplication of 32 bit (unsigned) long
4 Written By - Jean Louis VERN jlvern@writeme.com (1999)
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
26 /* Signed and unsigned multiplication are the same - as long as the output
27 has the same precision as the input.
29 Assembler-functions are provided for:
31 mcs51 small stack-auto
40 struct {unsigned char b3,b2,b1,b0 ;} b;
41 struct {unsigned short hi,lo ;} i;
43 struct { unsigned char b3; unsigned short i12; unsigned char b0;} bi;
46 # define bcast(x) ((union bil *)&(x))
51 ----------------------------
56 ----------------------------
64 |-------> only this side 32 x 32 -> 32
67 _mullong (long a, long b)
71 t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A
72 t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A
73 t.b.b3 += bcast(a)->b.b3 *
75 t.b.b3 += bcast(a)->b.b2 *
77 t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E <- b lost in .lst
78 // bcast(a)->i.hi is free !
79 t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D <- b lost in .lst
81 bcast(a)->bi.b3 = bcast(a)->b.b1 *
83 bcast(a)->bi.i12 = bcast(a)->b.b1 *
86 bcast(b)->bi.b3 = bcast(a)->b.b0 *
88 bcast(b)->bi.i12 = bcast(a)->b.b0 *
90 bcast(b)->bi.b0 = 0; // B
91 bcast(a)->bi.b0 = 0; // C