version 1.1, 1999/12/27 04:16:32 |
version 1.3, 2000/08/21 08:31:41 |
|
|
/* $OpenXM$ */ |
/* |
|
* 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@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/lib/dmul,v 1.2 2000/01/11 06:43:37 noro Exp $ |
|
*/ |
#define MAX(a,b) ((a)>(b)?(a):(b)) |
#define MAX(a,b) ((a)>(b)?(a):(b)) |
#define MIN(a,b) ((a)>(b)?(b):(a)) |
#define MIN(a,b) ((a)>(b)?(b):(a)) |
|
|
|
|
Procs = getopt(proc); |
Procs = getopt(proc); |
if ( type(Procs) == -1 ) |
if ( type(Procs) == -1 ) |
Procs = []; |
Procs = []; |
|
Mod = getopt(mod); |
|
if ( type(Mod) == -1 ) |
|
Mod = 0; |
NP = length(Procs)+1; |
NP = length(Procs)+1; |
V =var(F1); |
V =var(F1); |
|
if ( !V ) { |
|
T = F1*F2; |
|
if ( Mod ) |
|
return T % Mod; |
|
else |
|
return T; |
|
} |
D1 = deg(F1,V); |
D1 = deg(F1,V); |
D2 = deg(F2,V); |
D2 = deg(F2,V); |
Dmin = MIN(D1,D2); |
Dmin = MIN(D1,D2); |
Dfft = p_mag(D1+D2+1)+1; |
Dfft = p_mag(D1+D2+1)+1; |
Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1; |
Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1; |
|
if ( Bound < 32 ) |
|
Bound = 32; |
Marray = newvect(NP); |
Marray = newvect(NP); |
MIarray = newvect(NP); |
MIarray = newvect(NP); |
for ( I = 0; I < NP; I++ ) { |
for ( I = 0; I < NP; I++ ) { |
|
Line 112 def d_mul(F1,F2) |
|
for ( J = 0; J < NP-1; J++ ) |
for ( J = 0; J < NP-1; J++ ) |
R += ox_pop_cmo(Procs[J]); |
R += ox_pop_cmo(Procs[J]); |
T3 = time(); |
T3 = time(); |
print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); |
/* print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); */ |
return R%M; |
if ( Mod ) |
|
return (R%M)%Mod; |
|
else |
|
return uadj_coef(R%M,M,ishift(M,1)); |
} |
} |
|
|
/* |
/* |
|
Line 130 def d_square(F1) |
|
Procs = getopt(proc); |
Procs = getopt(proc); |
if ( type(Procs) == -1 ) |
if ( type(Procs) == -1 ) |
Procs = []; |
Procs = []; |
|
Mod = getopt(mod); |
|
if ( type(Mod) == -1 ) |
|
Mod = 0; |
NP = length(Procs)+1; |
NP = length(Procs)+1; |
V =var(F1); |
V =var(F1); |
|
if ( !V ) { |
|
T = F1^2; |
|
if ( Mod ) |
|
return T % Mod; |
|
else |
|
return T; |
|
} |
D1 = deg(F1,V); |
D1 = deg(F1,V); |
Dfft = p_mag(2*D1+1)+1; |
Dfft = p_mag(2*D1+1)+1; |
Bound = 2*maxblen(F1)+p_mag(D1)+1; |
Bound = 2*maxblen(F1)+p_mag(D1)+1; |
|
if ( Bound < 32 ) |
|
Bound = 32; |
Marray = newvect(NP); |
Marray = newvect(NP); |
MIarray = newvect(NP); |
MIarray = newvect(NP); |
for ( I = 0; I < NP; I++ ) { |
for ( I = 0; I < NP; I++ ) { |
Line 104 def d_square(F1) |
|
Line 177 def d_square(F1) |
|
for ( J = 0; J < NP-1; J++ ) |
for ( J = 0; J < NP-1; J++ ) |
R += ox_pop_cmo(Procs[J]); |
R += ox_pop_cmo(Procs[J]); |
T3 = time(); |
T3 = time(); |
print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); |
/* print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); */ |
return R%M; |
if ( Mod ) |
|
return (R%M)%Mod; |
|
else |
|
return uadj_coef(R%M,M,ishift(M,1)); |
} |
} |
|
|
/* |
/* |
Line 119 def d_tmul(F1,F2,D) |
|
Line 195 def d_tmul(F1,F2,D) |
|
Procs = getopt(proc); |
Procs = getopt(proc); |
if ( type(Procs) == -1 ) |
if ( type(Procs) == -1 ) |
Procs = []; |
Procs = []; |
|
Mod = getopt(mod); |
|
if ( type(Mod) == -1 ) |
|
Mod = 0; |
NP = length(Procs)+1; |
NP = length(Procs)+1; |
V =var(F1); |
V =var(F1); |
|
if ( !V ) { |
|
T = utrunc(F1*F2,D); |
|
if ( Mod ) |
|
return T % Mod; |
|
else |
|
return T; |
|
} |
D1 = deg(F1,V); |
D1 = deg(F1,V); |
D2 = deg(F2,V); |
D2 = deg(F2,V); |
Dmin = MIN(D1,D2); |
Dmin = MIN(D1,D2); |
Dfft = p_mag(D1+D2+1)+1; |
Dfft = p_mag(D1+D2+1)+1; |
Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1; |
Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1; |
|
if ( Bound < 32 ) |
|
Bound = 32; |
Marray = newvect(NP); |
Marray = newvect(NP); |
MIarray = newvect(NP); |
MIarray = newvect(NP); |
for ( I = 0; I < NP; I++ ) { |
for ( I = 0; I < NP; I++ ) { |
Line 157 def d_tmul(F1,F2,D) |
|
Line 244 def d_tmul(F1,F2,D) |
|
for ( J = 0; J < NP-1; J++ ) |
for ( J = 0; J < NP-1; J++ ) |
R += ox_pop_cmo(Procs[J]); |
R += ox_pop_cmo(Procs[J]); |
T3 = time(); |
T3 = time(); |
print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); |
/* print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]); */ |
return R%M; |
if ( Mod ) |
|
return (R%M)%Mod; |
|
else |
|
return uadj_coef(R%M,M,ishift(M,1)); |
} |
} |
|
|
|
def d_rembymul(F1,F2,INVF2) |
|
{ |
|
Procs = getopt(proc); |
|
if ( type(Procs) == -1 ) |
|
Procs = []; |
|
Mod = getopt(mod); |
|
if ( type(Mod) == -1 ) |
|
Mod = 0; |
|
NP = length(Procs)+1; |
|
if ( !F2 ) |
|
error("d_rembymul : division by 0"); |
|
V =var(F1); |
|
if ( !V ) { |
|
T = srem(F1,F2); |
|
if ( Mod ) |
|
return T % Mod; |
|
else |
|
return T; |
|
} |
|
D1 = deg(F1,V); |
|
D2 = deg(F2,V); |
|
if ( !F1 || !D2 ) |
|
return 0; |
|
if ( D1 < D2 ) |
|
return F1; |
|
D = D1-D2; |
|
R1 = utrunc(ureverse(F1),D); |
|
Q = ureverse(utrunc(d_tmul(R1,INVF2,D|proc=Procs,mod=Mod),D)); |
|
if ( Mod ) |
|
return (utrunc(F1,D2-1)-d_tmul(Q,F2,D2-1|proc=Procs,mod=Mod))%Mod; |
|
else |
|
return utrunc(F1,D2-1)-d_tmul(Q,F2,D2-1|proc=Procs); |
|
} |
|
|
def call_umul(F1,F2,Ind,M1,M) |
def call_umul(F1,F2,Ind,M1,M) |
{ |
{ |
C = umul_specialmod(F1,F2,Ind); |
C = umul_specialmod(F1,F2,Ind); |
Mhat = idiv(M,M1); |
Mhat = idiv(M,M1); |
MhatInv = inv(Mhat,M1); |
MhatInv = inv(Mhat,M1); |
return (MhatInv*Mhat)*C; |
return Mhat*((MhatInv*C)%M1); |
} |
} |
|
|
def call_usquare(F1,Ind,M1,M) |
def call_usquare(F1,Ind,M1,M) |
Line 174 def call_usquare(F1,Ind,M1,M) |
|
Line 298 def call_usquare(F1,Ind,M1,M) |
|
C = usquare_specialmod(F1,Ind); |
C = usquare_specialmod(F1,Ind); |
Mhat = idiv(M,M1); |
Mhat = idiv(M,M1); |
MhatInv = inv(Mhat,M1); |
MhatInv = inv(Mhat,M1); |
return (MhatInv*Mhat)*C; |
return Mhat*((MhatInv*C)%M1); |
} |
} |
|
|
def call_utmul(F1,F2,D,Ind,M1,M) |
def call_utmul(F1,F2,D,Ind,M1,M) |
Line 182 def call_utmul(F1,F2,D,Ind,M1,M) |
|
Line 306 def call_utmul(F1,F2,D,Ind,M1,M) |
|
C = utmul_specialmod(F1,F2,D,Ind); |
C = utmul_specialmod(F1,F2,D,Ind); |
Mhat = idiv(M,M1); |
Mhat = idiv(M,M1); |
MhatInv = inv(Mhat,M1); |
MhatInv = inv(Mhat,M1); |
return (MhatInv*Mhat)*C; |
return Mhat*((MhatInv*C)%M1); |
} |
} |
end$ |
end$ |