2
Copyright (C) 1994 W. Schelter
4
This file is part of GNU Common Lisp, herein referred to as GCL
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)
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 Library General Public
14
License for more details.
19
/* author: William F. Schelter
20
The following is an implementation of extended_div in C suitable
21
for a machine which can do 32 bit arithmetic.
22
The assembler output could be optimized, so that carry tests
23
were read from the condition codes
28
/* #define ESTIMATE_LOG_QUOTIENT(x,l,d) estimate_logq(x,l,d) */
29
#define ESTIMATE_LOG_QUOTIENT(x,l,d) 31
33
estimate_logq(x,l,div)
35
{ unsigned int logq,w;
36
if (x==0) {w=0;x=l;} else {w=WSIZ;}
37
for(logq=0; logq < WSIZ ; logq+=1)
38
if ((div << logq) >= x)
46
extended_div(divisor,dh,dl,q,r)
47
unsigned int dh,dl , divisor, *q, *r;
48
{ unsigned int Rh,Rl,temph,templ;
57
/* if (dh) printf("\n(di %d %d %d ",divisor,dh,dl); */
62
{*q=dl/divisor; *r=dl%divisor;
65
printf("\n%d (Q %d %d) (R %d %d) %s" , -1,0,Q,Rh,Rl,"begin");
67
for (iter=ESTIMATE_LOG_QUOTIENT(dh,dl,divisor); iter >=0 ; iter-= 1)
69
/* assert(Q*divisor+R ==dividend); */
70
lshift(divisor,iter,temph,templ);
72
{lsub(temph,templ,Rh,Rl);
76
/* lshift(1,iter,temph,templ);
77
ladd(temph,templ,Qh,Ql);
79
/* ladd(0,(1<<iter),Qh,Ql); */
87
ladd(temph,templ,Rh,Rl);
88
/* lshift(1,iter,temph,templ);
89
lsub(temph,templ,Qh,Ql);
91
/* lsub(0,(1<<iter),Qh,Ql); */
95
printf("\n%d (Q %d %d) (R %d %d) %s" , iter,0,Q,Rh,Rl,op);
98
/* if (((int)Rl)< 0) {Ql--;Rl=Rl+divisor;} */
99
if (((int)Rl)< 0) {Q--;Rl=Rl+divisor;}
104
/* printf("%d %d)",*q,*r);
109
try(h,d, h1,l1, qp, rp)
110
unsigned int d, h, h1,l1,*qp, *rp;
112
extended_div (l1,h,d,qp,rp);