1 /*-------------------------------------------------------------------------
2 _mululong.c - routine for multiplication of 32 bit unsigned long
4 Written By - Jean Louis VERN jlvern@writeme.com (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
30 struct {unsigned char b0,b1,b2,b3 ;} b;
31 struct {unsigned int lo,hi ;} i;
33 struct { unsigned char b0; unsigned int i12; unsigned char b3;} bi;
35 #if defined(SDCC_MODEL_LARGE) || defined (SDCC_ds390)
36 #define bcast(x) ((union bil _xdata *)&(x))
37 #elif defined(__z80) || defined(__gbz80)
38 #define bcast(x) ((union bil *)&(x))
40 #define bcast(x) ((union bil _near *)&(x))
46 ----------------------------
51 ----------------------------
59 |-------> only this side 32 x 32 -> 32
62 unsigned long _mululong (unsigned long a, unsigned long b)
66 t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A
67 t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A
69 t.b.b3 += bcast(a)->b.b3 *
71 t.b.b3 += bcast(a)->b.b2 *
73 t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E <- b lost in .lst
74 // bcast(a)->i.hi is free !
75 t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D <- b lost in .lst
77 bcast(a)->bi.b3 = bcast(a)->b.b1 *
79 bcast(a)->bi.i12 = bcast(a)->b.b1 *
82 bcast(b)->bi.b3 = bcast(a)->b.b0 *
84 bcast(b)->bi.i12 = bcast(a)->b.b0 *
86 bcast(b)->bi.b0 = 0; // B
87 bcast(a)->bi.b0 = 0; // C