version 1.1.1.1, 1999/12/03 07:39:06 |
version 1.5, 2001/10/09 01:36:02 |
|
|
/* $OpenXM: OpenXM/src/asir99/asm/ddM.c,v 1.1.1.1 1999/11/10 08:12:25 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/asm/ddM.c,v 1.4 2001/06/25 05:30:48 noro Exp $ |
|
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
#include "inline.h" |
#include "inline.h" |
|
|
void ksquareummain(int,UM,UM); |
|
void kmulummain(int,UM,UM,UM); |
|
void c_copyum(UM,int,int *); |
|
void copyum(UM,UM); |
|
void extractum(UM,int,int,UM); |
|
void ksquareum(int,UM,UM); |
|
void kmulum(int,UM,UM,UM); |
|
|
|
/* |
/* |
* mod is declared as 'int', because several xxxum functions contains signed |
* mod is declared as 'int', because several xxxum functions contains signed |
* integer addition/subtraction. So mod should be less than 2^31. |
* integer addition/subtraction. So mod should be less than 2^31. |
*/ |
*/ |
|
|
void mulum(mod,p1,p2,pr) |
void mulum(int mod,UM p1,UM p2,UM pr) |
int mod; |
|
UM p1,p2,pr; |
|
{ |
{ |
int *pc1,*pcr; |
int *pc1,*pcr; |
int *c1,*c2,*cr; |
int *c1,*c2,*cr; |
|
|
DEG(pr) = d1 + d2; |
DEG(pr) = d1 + d2; |
} |
} |
|
|
void mulsum(mod,p,n,pr) |
void mulsum(int mod,UM p,int n,UM pr) |
int mod,n; |
|
UM p,pr; |
|
{ |
{ |
int *sp,*dp; |
int *sp,*dp; |
int i; |
int i; |
|
|
} |
} |
} |
} |
|
|
int divum(mod,p1,p2,pq) |
int divum(int mod,UM p1,UM p2,UM pq) |
int mod; |
|
UM p1,p2,pq; |
|
{ |
{ |
int *pc1,*pct; |
int *pc1,*pct; |
int *c1,*c2,*ct; |
int *c1,*c2,*ct; |
|
|
return i; |
return i; |
} |
} |
|
|
void diffum(mod,f,fd) |
void diffum(int mod,UM f,UM fd) |
int mod; |
|
UM f,fd; |
|
{ |
{ |
int *dp,*sp; |
int *dp,*sp; |
int i; |
int i; |
|
#if !defined(VISUAL) |
UL ltmp; |
UL ltmp; |
|
#endif |
|
|
for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i; |
for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i; |
i >= 1; i--, dp--, sp-- ) { |
i >= 1; i--, dp--, sp-- ) { |
|
|
degum(fd,DEG(f) - 1); |
degum(fd,DEG(f) - 1); |
} |
} |
|
|
unsigned int pwrm(mod,a,n) |
unsigned int pwrm(int mod,int a,int n) |
int mod,a; |
|
int n; |
|
{ |
{ |
unsigned int s,t; |
unsigned int s,t; |
|
|
|
|
} |
} |
} |
} |
|
|
unsigned int invm(s,mod) |
unsigned int invm(unsigned int s,int mod) |
unsigned int s; |
|
int mod; |
|
{ |
{ |
unsigned int r,a2,q; |
unsigned int r,a2,q; |
unsigned int f1,f2,a1; |
unsigned int f1,f2,a1; |
|
|
return a2; |
return a2; |
} |
} |
|
|
unsigned int rem(n,m) |
unsigned int rem(N n,int m) |
N n; |
|
unsigned int m; |
|
{ |
{ |
unsigned int *x; |
unsigned int *x; |
unsigned int t,r; |
unsigned int t,r; |
|
|
} |
} |
|
|
#ifndef sparc |
#ifndef sparc |
void addpadic(mod,n,n1,n2) |
void addpadic(int mod,int n,unsigned int *n1,unsigned int *n2) |
int mod; |
|
int n; |
|
unsigned int *n1,*n2; |
|
{ |
{ |
unsigned int carry,tmp; |
unsigned int carry,tmp; |
int i; |
int i; |
Line 194 unsigned int *n1,*n2; |
|
Line 219 unsigned int *n1,*n2; |
|
} |
} |
#endif |
#endif |
|
|
void mulpadic(mod,n,n1,n2,nr) |
void mulpadic(int mod,int n,unsigned int *n1,unsigned int *n2,unsigned int *nr) |
int mod; |
|
int n; |
|
unsigned int *n1; |
|
unsigned int *n2,*nr; |
|
{ |
{ |
unsigned int *pn1,*pnr; |
unsigned int *pn1,*pnr; |
unsigned int carry,mul; |
unsigned int carry,mul; |
Line 216 unsigned int *n2,*nr; |
|
Line 237 unsigned int *n2,*nr; |
|
|
|
extern up_kara_mag; |
extern up_kara_mag; |
|
|
void kmulum(mod,n1,n2,nr) |
void kmulum(int mod,UM n1,UM n2,UM nr) |
UM n1,n2,nr; |
|
{ |
{ |
UM n,t,s,m,carry; |
UM n,t,s,m,carry; |
int d,d1,d2,len,i,l; |
int d,d1,d2,len,i,l; |
|
|
carry = W_UMALLOC(d2+1); |
carry = W_UMALLOC(d2+1); |
t = W_UMALLOC(d1+d2+1); |
t = W_UMALLOC(d1+d2+1); |
s = W_UMALLOC(d1+d2+1); |
s = W_UMALLOC(d1+d2+1); |
for ( carry = 0, i = 0, r = r0; i < d; i++, r += d2 ) { |
for ( DEG(carry) = -1, i = 0, r = r0; i < d; i++, r += d2 ) { |
extractum(n1,i*d2,d2,m); |
extractum(n1,i*d2,d2,m); |
if ( m ) { |
if ( m ) { |
kmulum(mod,m,n2,t); |
kmulum(mod,m,n2,t); |
|
|
bcopy((char *)r0,(char *)COEF(nr),l*sizeof(int)); |
bcopy((char *)r0,(char *)COEF(nr),l*sizeof(int)); |
} |
} |
|
|
void ksquareum(mod,n1,nr) |
void ksquareum(int mod,UM n1,UM nr) |
int mod; |
|
UM n1,nr; |
|
{ |
{ |
int d1; |
int d1; |
|
|
|
|
ksquareummain(mod,n1,nr); |
ksquareummain(mod,n1,nr); |
} |
} |
|
|
void extractum(n,index,len,nr) |
void extractum(UM n,int index,int len,UM nr) |
UM n; |
|
int index,len; |
|
UM nr; |
|
{ |
{ |
int *m; |
int *m; |
int l; |
int l; |
|
|
} |
} |
} |
} |
|
|
void copyum(n1,n2) |
void copyum(UM n1,UM n2) |
UM n1,n2; |
|
{ |
{ |
n2->d = n1->d; |
n2->d = n1->d; |
bcopy((char *)n1->c,(char *)n2->c,(n1->d+1)*sizeof(int)); |
bcopy((char *)n1->c,(char *)n2->c,(n1->d+1)*sizeof(int)); |
} |
} |
|
|
void c_copyum(n,len,p) |
void c_copyum(UM n,int len,int *p) |
UM n; |
|
int len; |
|
int *p; |
|
{ |
{ |
if ( n ) |
if ( n ) |
bcopy((char *)COEF(n),(char *)p,MIN((DEG(n)+1),len)*sizeof(int)); |
bcopy((char *)COEF(n),(char *)p,MIN((DEG(n)+1),len)*sizeof(int)); |
} |
} |
|
|
void kmulummain(mod,n1,n2,nr) |
void kmulummain(int mod,UM n1,UM n2,UM nr) |
int mod; |
|
UM n1,n2,nr; |
|
{ |
{ |
int d1,d2,h,len; |
int d1,d2,h,len; |
UM n1lo,n1hi,n2lo,n2hi,hi,lo,mid1,mid2,mid,s1,s2,t1,t2; |
UM n1lo,n1hi,n2lo,n2hi,hi,lo,mid1,mid2,mid,s1,s2,t1,t2; |
|
|
copyum(t1,nr); |
copyum(t1,nr); |
} |
} |
|
|
void ksquareummain(mod,n1,nr) |
void ksquareummain(int mod,UM n1,UM nr) |
int mod; |
|
UM n1,nr; |
|
{ |
{ |
int d1,h,len; |
int d1,h,len; |
UM n1lo,n1hi,hi,lo,mid1,mid2,mid,s1,t1,t2; |
UM n1lo,n1hi,hi,lo,mid1,mid2,mid,s1,t1,t2; |