~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to mp/mp_mulul3.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*          Copyright (C) 1994 W. Schelter
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
14
for more details.
 
15
 
 
16
You should have received a copy of the GNU library general public
 
17
license along with GCL; see the file COPYING.  If not, write to the
 
18
Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
 
 
22
 
 
23
#include "include.h"
 
24
#include "arith.h"
 
25
 
 
26
/* ulong a,b,y;
 
27
   (y = mulul3(a,b,&hiremainder), hiremainder:y == a*b) is TRUE.
 
28
*/   
 
29
#ifdef USE_WORD_MULUL3
 
30
 
 
31
int mulul3(x,y,hiremainder)
 
32
     ulong x,y,*hiremainder;
 
33
{
 
34
  ulong xlo,xhi,ylo,yhi;
 
35
  ulong z; TEMPVARS
 
36
 
 
37
  xlo=x&65535;xhi=x>>16;ylo=y&65535;yhi=y>>16;
 
38
  z=addll(xlo*yhi,xhi*ylo);
 
39
  *hiremainder=(overflow)?xhi*yhi+65536+(z>>16):xhi*yhi+(z>>16);
 
40
  z=addll(xlo*ylo,(z<<16));*hiremainder+=overflow;
 
41
  return z;
 
42
}
 
43
 
 
44
#else
 
45
ulong
 
46
mulul3(a,b,h)
 
47
unsigned int a,b, *h;
 
48
{unsigned int temph,templ,ah,al,i;
 
49
 ah=0;
 
50
 al=0;
 
51
 /* in case the shift by 32 does not zero an unsigned int..
 
52
    we separate out the first step.*/
 
53
 {if (b & 1)
 
54
    {temph=0;templ=a;
 
55
     lladd(temph,templ,ah,al);}
 
56
    /*    printf("\n%d b=%d a=%d (%d:%d)",i,b,a,ah,al); */
 
57
    b=b>>1;
 
58
  }
 
59
 i=1;
 
60
 while(b)
 
61
   {if (b & 1)
 
62
      {llshift(a,i,temph,templ);
 
63
       lladd(temph,templ,ah,al);}
 
64
      i++;b=b>>1;
 
65
    }
 
66
 *h=ah;
 
67
 return al;
 
68
}
 
69
#endif