[BACK]Return to N.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Diff for /OpenXM_contrib2/asir2000/engine/N.c between version 1.1 and 1.8

version 1.1, 1999/12/03 07:39:08 version 1.8, 2007/02/18 05:36:27
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/asir99/engine/N.c,v 1.1.1.1 1999/11/10 08:12:26 noro Exp $ */  /*
    * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
    * All rights reserved.
    *
    * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
    * non-exclusive and royalty-free license to use, copy, modify and
    * redistribute, solely for non-commercial and non-profit purposes, the
    * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
    * conditions of this Agreement. For the avoidance of doubt, you acquire
    * only a limited right to use the SOFTWARE hereunder, and FLL or any
    * third party developer retains all rights, including but not limited to
    * copyrights, in and to the SOFTWARE.
    *
    * (1) FLL does not grant you a license in any way for commercial
    * purposes. You may use the SOFTWARE only for non-commercial and
    * non-profit purposes only, such as academic, research and internal
    * business use.
    * (2) The SOFTWARE is protected by the Copyright Law of Japan and
    * international copyright treaties. If you make copies of the SOFTWARE,
    * with or without modification, as permitted hereunder, you shall affix
    * to all such copies of the SOFTWARE the above copyright notice.
    * (3) An explicit reference to this SOFTWARE and its copyright owner
    * shall be made on your publication or presentation in any form of the
    * results obtained by use of the SOFTWARE.
    * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
    * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
    * for such modification or the source code of the modified part of the
    * SOFTWARE.
    *
    * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
    * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
    * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
    * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
    * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
    * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
    * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
    * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
    * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
    * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
    * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
    * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
    * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
    * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
    * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
    * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
    * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
    *
    * $OpenXM: OpenXM_contrib2/asir2000/engine/N.c,v 1.7 2004/12/04 09:39:27 noro Exp $
   */
 #include "ca.h"  #include "ca.h"
 #include "base.h"  #include "base.h"
   
 void addn();  #if defined(VISUAL) || ( defined(i386) && !defined(__DARWIN__) )
 int subn();  void addn(N n1,N n2,N *nr)
 void _bshiftn();  
 void dupn();  
   
 #if defined(VISUAL) || defined(i386)  
 void addn(n1,n2,nr)  
 N n1,n2,*nr;  
 {  {
         unsigned int *m1,*m2,*mr;          unsigned int *m1,*m2,*mr;
         unsigned int c;          unsigned int c;
Line 90  N n1,n2,*nr;
Line 132  N n1,n2,*nr;
         }          }
 }  }
   
 int subn(n1,n2,nr)  int subn(N n1,N n2,N *nr)
 N n1,n2,*nr;  
 {  {
         N r;          N r;
         unsigned int *m1,*m2,*mr,br;          unsigned int *m1,*m2,*mr,br;
Line 197  N n1,n2,*nr;
Line 238  N n1,n2,*nr;
         }          }
 }  }
   
 void _addn(n1,n2,nr)  void _addn(N n1,N n2,N nr)
 N n1,n2,nr;  
 {  {
         unsigned int *m1,*m2,*mr;          unsigned int *m1,*m2,*mr;
         unsigned int c;          unsigned int c;
Line 278  N n1,n2,nr;
Line 318  N n1,n2,nr;
         }          }
 }  }
   
 int _subn(n1,n2,nr)  int _subn(N n1,N n2,N nr)
 N n1,n2,nr;  
 {  {
         unsigned int *m1,*m2,*mr,br;          unsigned int *m1,*m2,*mr,br;
         unsigned int tmp,t;          unsigned int tmp,t;
Line 385  N n1,n2,nr;
Line 424  N n1,n2,nr;
 }  }
 #else  #else
   
 void addn(n1,n2,nr)  void addn(N n1,N n2,N *nr)
 N n1,n2,*nr;  
 {  {
         unsigned int *m1,*m2,*mr,i,c;          unsigned int *m1,*m2,*mr,i,c;
         N r;          N r;
Line 427  N n1,n2,*nr;
Line 465  N n1,n2,*nr;
         }          }
 }  }
   
 int subn(n1,n2,nr)  int subn(N n1,N n2,N *nr)
 N n1,n2,*nr;  
 {  {
         N r;          N r;
         unsigned int *m1,*m2,*mr,i,br;          unsigned int *m1,*m2,*mr,i,br;
Line 486  N n1,n2,*nr;
Line 523  N n1,n2,*nr;
         }          }
 }  }
   
 void _addn(n1,n2,nr)  void _addn(N n1,N n2,N nr)
 N n1,n2,nr;  
 {  {
         unsigned int *m1,*m2,*mr,i,c;          unsigned int *m1,*m2,*mr,i,c;
         int d1,d2;          int d1,d2;
Line 526  N n1,n2,nr;
Line 562  N n1,n2,nr;
         }          }
 }  }
   
 int _subn(n1,n2,nr)  int _subn(N n1,N n2,N nr)
 N n1,n2,nr;  
 {  {
         N r;          N r;
         unsigned int *m1,*m2,*mr,i,br;          unsigned int *m1,*m2,*mr,i,br;
Line 587  N n1,n2,nr;
Line 622  N n1,n2,nr;
   
 /* a2 += a1; n2 >= n1 */  /* a2 += a1; n2 >= n1 */
   
 void addarray_to(a1,n1,a2,n2)  void addarray_to(unsigned int *a1,int n1,unsigned int *a2,int n2)
 unsigned int *a1;  
 int n1;  
 unsigned int *a2;  
 int n2;  
 {  {
         int i;          int i;
         unsigned int c,tmp;          unsigned int c,tmp;
Line 616  int n2;
Line 647  int n2;
                 *a2 = c;                  *a2 = c;
 }  }
   
 void pwrn(n,e,nr)  void pwrn(N n,int e,N *nr)
 N n,*nr;  
 int e;  
 {  {
         N nw,nw1;          N nw,nw1;
   
Line 635  int e;
Line 664  int e;
         FREEN(nw);          FREEN(nw);
 }  }
   
   
   
 extern int igcd_algorithm;  extern int igcd_algorithm;
   
 void gcdEuclidn();  void gcdEuclidn(), gcdn_HMEXT();
   
 void gcdn(n1,n2,nr)  void lcmn(N n1,N n2,N *nr)
 N n1,n2,*nr;  
 {  {
         N m1,m2,g;          N g,t;
   
           gcdn(n1,n2,&g);
           divsn(n1,g,&t);
           muln(t,n2,nr);
   }
   
   void gcdn(N n1,N n2,N *nr)
   {
         if ( !igcd_algorithm )          if ( !igcd_algorithm )
                 gcdEuclidn(n1,n2,nr);                  gcdEuclidn(n1,n2,nr);
         else {          else {
                 if ( !n1 )                  gcdn_HMEXT(n1,n2,nr);
                         *nr = n2;  
                 else if ( !n2 )  
                         *nr = n1;  
                 else {  
                         n32ton27(n1,&m1);  
                         n32ton27(n2,&m2);  
                         gcdBinary_27n(m1,m2,&g);  
                         n27ton32(g,nr);  
                 }  
         }          }
 }  }
   
 void gcdEuclidn(n1,n2,nr)  #include "Ngcd.c"
 N n1,n2,*nr;  
   void gcdEuclidn(N n1,N n2,N *nr)
 {  {
         N m1,m2,q,r;          N m1,m2,q,r;
         unsigned int i1,i2,ir;          unsigned int i1,i2,ir;
Line 685  N n1,n2,*nr;
Line 714  N n1,n2,*nr;
                                 m1 = m2; m2 = r;                                  m1 = m2; m2 = r;
                         }                          }
                 }                  }
                 for ( i1 = BD(m1)[0], i2 = BD(m2)[0]; ir = i1 % i2; i1 = i2, i2 = ir );                  for ( i1 = BD(m1)[0], i2 = BD(m2)[0]; ir = i1 % i2; i2 = ir )
                           i1 = i2;
                 if ( i2 == 1 )                  if ( i2 == 1 )
                         COPY(ONEN,*nr);                          COPY(ONEN,*nr);
                 else {                  else {
Line 694  N n1,n2,*nr;
Line 724  N n1,n2,*nr;
         }          }
 }  }
   
 int cmpn(n1,n2)  int cmpn(N n1,N n2)
 N n1,n2;  
 {  {
         int i;          int i;
         unsigned int *m1,*m2;          unsigned int *m1,*m2;
Line 722  N n1,n2;
Line 751  N n1,n2;
         }          }
 }  }
   
 void bshiftn(n,b,r)  void bshiftn(N n,int b,N *r)
 N n;  
 int b;  
 N *r;  
 {  {
         int w,l,nl,i,j;          int w,l,nl,i,j;
         N z;          N z;
Line 793  N *r;
Line 819  N *r;
 }  }
   
 #if 0  #if 0
 void _bshiftn(n,b,z)  void _bshiftn(N n,int b,N z)
 N n;  
 int b;  
 N z;  
 {  {
         int w,l,nl,i,j;          int w,l,nl,i,j;
         unsigned int msw;          unsigned int msw;
Line 863  N z;
Line 886  N z;
 }  }
 #endif  #endif
   
 void shiftn(n,w,r)  void shiftn(N n,int w,N *r)
 N n;  
 int w;  
 N *r;  
 {  {
         int l,nl;          int l,nl;
         N z;          N z;
Line 890  N *r;
Line 910  N *r;
         }          }
 }  }
   
 void randomn(bits,r)  void randomn(int bits,N *r)
 int bits;  
 N *r;  
 {  {
         int l,i;          int l,i;
         unsigned int *tb;          unsigned int *tb;
Line 912  N *r;
Line 930  N *r;
                 PL(t) = i+1;                  PL(t) = i+1;
 }  }
   
 void freen(n)  void freen(N n)
 N n;  
 {  {
         if ( n && (n != ONEN) )          if ( n && (n != ONEN) )
                 free(n);                  free(n);
 }  }
   
 int n_bits(n)  /* accepts Z */
 N n;  int n_bits(N n)
 {  {
         unsigned int l,i,t;          unsigned int i,t;
           int l;
   
         if ( !n )          if ( !n )
                 return 0;                  return 0;
         l = PL(n); t = BD(n)[l-1];          l = PL(n);
           if ( l < 0 ) l = -l;
           t = BD(n)[l-1];
         for ( i = 0; t; t>>=1, i++);          for ( i = 0; t; t>>=1, i++);
         return i + (l-1)*BSH;          return i + (l-1)*BSH;
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>