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)
6 Modified for pic16 port by - Vangelis Rokas, vrokas@otenet.gr (2004)
8 This library is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Library General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
30 struct {unsigned char b0,b1,b2,b3 ;} b;
31 struct {unsigned short lo,hi ;} i;
33 struct { unsigned char b0; unsigned short i12; unsigned char b3;} bi;
36 #define bcast(x) ((union bil near *)&(x))
41 ----------------------------
46 ----------------------------
54 |-------> only this side 32 x 32 -> 32
57 long _mullong (long a, long b) _IL_REENTRANT
62 t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A
63 t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A
64 t.b.b3 += bcast(a)->b.b3 *
66 t.b.b3 += bcast(a)->b.b2 *
68 t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E <- b lost in .lst
69 // bcast(a)->i.hi is free !
70 t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D <- b lost in .lst
72 bcast(a)->bi.b3 = bcast(a)->b.b1 *
74 bcast(a)->bi.i12 = bcast(a)->b.b1 *
77 bcast(b)->bi.b3 = bcast(a)->b.b0 *
79 bcast(b)->bi.i12 = bcast(a)->b.b0 *
81 bcast(b)->bi.b0 = 0; // B
82 bcast(a)->bi.b0 = 0; // C
96 t.i.hi = x.b.b0 * y.b.b2;
97 t.i.lo = x.b.b0 * y.b.b0;
99 t.b.b3 += x.b.b3 * y.b.b0;
100 t.b.b3 += x.b.b2 * y.b.b1;
102 t.i.hi += x.b.b2 * y.b.b0;
103 t.i.hi += x.b.b1 * y.b.b1;
105 t1.bi.b3 = x.b.b1 * y.b.b2;
106 t1.bi.i12 = x.b.b1 * y.b.b0;
108 t2.bi.b3 = x.b.b0 * y.b.b3;
109 t2.bi.i12 = x.b.b0 * y.b.b1;