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

« back to all changes in this revision

Viewing changes to o/ndiv.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 Library General Public 
 
14
License for more details.
 
15
 
 
16
*/
 
17
 
 
18
 
 
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
 
24
*/   
 
25
 
 
26
#include "arith.h"
 
27
 
 
28
/* #define ESTIMATE_LOG_QUOTIENT(x,l,d) estimate_logq(x,l,d) */
 
29
#define ESTIMATE_LOG_QUOTIENT(x,l,d) 31
 
30
 
 
31
/*
 
32
int  
 
33
estimate_logq(x,l,div)
 
34
unsigned int x,div,l;
 
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)
 
39
      break;
 
40
  return 31;
 
41
  return logq+w;}
 
42
 
 
43
*/
 
44
 
 
45
 
 
46
extended_div(divisor,dh,dl,q,r)
 
47
unsigned int dh,dl , divisor, *q, *r;
 
48
{   unsigned int Rh,Rl,temph,templ;
 
49
    unsigned int Q;
 
50
    int iter;
 
51
#ifdef DEBUG 
 
52
    char *op;
 
53
#endif 
 
54
    Rh=dh;
 
55
    Rl=dl;
 
56
 
 
57
    /*  if (dh) printf("\n(di %d %d %d ",divisor,dh,dl); */
 
58
 
 
59
    NORMALIZE(Rh,Rl);
 
60
    Q=0;
 
61
    if (dh==0)
 
62
      {*q=dl/divisor; *r=dl%divisor;
 
63
       return;}
 
64
#ifdef DEBUG 
 
65
    printf("\n%d (Q %d %d) (R %d %d) %s" , -1,0,Q,Rh,Rl,"begin");
 
66
#endif 
 
67
    for (iter=ESTIMATE_LOG_QUOTIENT(dh,dl,divisor); iter >=0 ; iter-= 1)
 
68
      {
 
69
        /* assert(Q*divisor+R ==dividend); */
 
70
        lshift(divisor,iter,temph,templ);
 
71
        if ((int)Rh>=0)
 
72
          {lsub(temph,templ,Rh,Rl);
 
73
#ifdef DEBUG
 
74
           op="add";
 
75
#endif    
 
76
           /*    lshift(1,iter,temph,templ);
 
77
                 ladd(temph,templ,Qh,Ql);
 
78
                 */    
 
79
           /*     ladd(0,(1<<iter),Qh,Ql); */
 
80
           Q=Q+ (1<<iter);
 
81
         }
 
82
        else
 
83
          {
 
84
#ifdef DEBUG        
 
85
            op="sub"; 
 
86
#endif
 
87
            ladd(temph,templ,Rh,Rl);
 
88
            /*      lshift(1,iter,temph,templ);
 
89
                    lsub(temph,templ,Qh,Ql);
 
90
                    */      
 
91
            /*      lsub(0,(1<<iter),Qh,Ql); */
 
92
            Q=Q- (1<<iter);
 
93
          }
 
94
#ifdef DEBUG           
 
95
        printf("\n%d (Q %d %d) (R %d %d) %s" , iter,0,Q,Rh,Rl,op);
 
96
#endif   
 
97
      }
 
98
    /* if (((int)Rl)< 0) {Ql--;Rl=Rl+divisor;} */
 
99
    if (((int)Rl)< 0) {Q--;Rl=Rl+divisor;} 
 
100
    KCLNORMALIZE(Rh,Rl);     
 
101
    *q=Q;
 
102
    /* *q=Ql; */
 
103
    *r=Rl;
 
104
    /* printf("%d %d)",*q,*r); 
 
105
       fflush(stdout); */
 
106
  } 
 
107
 
 
108
#ifndef VSSIZE
 
109
try(h,d, h1,l1, qp, rp)
 
110
unsigned int d, h, h1,l1,*qp, *rp;
 
111
{
 
112
extended_div (l1,h,d,qp,rp);
 
113
}
 
114
#endif
 
115
 
 
116
 
 
117
 
 
118