version 1.13, 2001/06/07 05:14:48 |
version 1.21, 2001/09/17 07:16:58 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/array.c,v 1.12 2001/06/07 04:54:38 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/array.c,v 1.20 2001/09/17 03:33:57 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 67 void mat_to_gfmmat(MAT,unsigned int,GFMMAT *); |
|
Line 67 void mat_to_gfmmat(MAT,unsigned int,GFMMAT *); |
|
|
|
int generic_gauss_elim_mod(int **,int,int,int,int *); |
int generic_gauss_elim_mod(int **,int,int,int,int *); |
int generic_gauss_elim(MAT ,MAT *,Q *,int **,int **); |
int generic_gauss_elim(MAT ,MAT *,Q *,int **,int **); |
|
void reduce_sp_by_red_mod_compress (int *,CDP *,int *,int,int,int); |
|
|
int gauss_elim_mod(int **,int,int,int); |
int gauss_elim_mod(int **,int,int,int); |
int gauss_elim_mod1(int **,int,int,int); |
int gauss_elim_mod1(int **,int,int,int); |
Line 90 void Px962_irredpoly_up2(); |
|
Line 91 void Px962_irredpoly_up2(); |
|
void Pirredpoly_up2(); |
void Pirredpoly_up2(); |
void Pnbpoly_up2(); |
void Pnbpoly_up2(); |
void Pqsort(); |
void Pqsort(); |
|
void Pexponent_vector(); |
|
|
struct ftab array_tab[] = { |
struct ftab array_tab[] = { |
{"solve_by_lu_gfmmat",Psolve_by_lu_gfmmat,4}, |
{"solve_by_lu_gfmmat",Psolve_by_lu_gfmmat,4}, |
Line 97 struct ftab array_tab[] = { |
|
Line 99 struct ftab array_tab[] = { |
|
{"mat_to_gfmmat",Pmat_to_gfmmat,2}, |
{"mat_to_gfmmat",Pmat_to_gfmmat,2}, |
{"generic_gauss_elim_mod",Pgeneric_gauss_elim_mod,2}, |
{"generic_gauss_elim_mod",Pgeneric_gauss_elim_mod,2}, |
{"newvect",Pnewvect,-2}, |
{"newvect",Pnewvect,-2}, |
|
{"vector",Pnewvect,-2}, |
|
{"exponent_vector",Pexponent_vector,-99999999}, |
{"newmat",Pnewmat,-3}, |
{"newmat",Pnewmat,-3}, |
|
{"matrix",Pnewmat,-3}, |
{"newbytearray",Pnewbytearray,-2}, |
{"newbytearray",Pnewbytearray,-2}, |
{"sepmat_destructive",Psepmat_destructive,2}, |
{"sepmat_destructive",Psepmat_destructive,2}, |
{"sepvect",Psepvect,2}, |
{"sepvect",Psepvect,2}, |
|
|
*rp = vect; |
*rp = vect; |
} |
} |
|
|
|
void Pexponent_vector(arg,rp) |
|
NODE arg; |
|
DP *rp; |
|
{ |
|
nodetod(arg,rp); |
|
} |
|
|
void Pnewbytearray(arg,rp) |
void Pnewbytearray(arg,rp) |
NODE arg; |
NODE arg; |
BYTEARRAY *rp; |
BYTEARRAY *rp; |
|
|
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
} |
} |
for ( ; k >= 0; k-- ) { |
for ( ; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
|
|
hc = md-hc; |
hc = md-hc; |
s = redmat[i]+j; |
s = redmat[i]+j; |
tj = sp+j; |
tj = sp+j; |
for ( k = col-j; k >= 0; k-- ) { |
for ( k = col-j; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
|
/* |
|
mat[i] : compressed reducers (i=0,...,nred-1) |
|
mat[0] < mat[1] < ... < mat[nred-1] w.r.t the term order |
|
*/ |
|
|
|
int red_by_compress(m,p,r,ri,hc,len) |
|
int m; |
|
unsigned int *p; |
|
register unsigned int *r; |
|
register unsigned short *ri; |
|
unsigned int hc; |
|
register int len; |
|
{ |
|
unsigned int up,lo; |
|
unsigned int dmy; |
|
unsigned int *pj; |
|
|
|
p[*ri] = 0; r++; ri++; |
|
for ( len--; len; len--, r++, ri++ ) { |
|
pj = p+ *ri; |
|
DMA(*r,hc,*pj,up,lo); |
|
if ( up ) { |
|
DSAB(m,up,lo,dmy,*pj); |
|
} else |
|
*pj = lo; |
|
} |
|
} |
|
|
|
/* p -= hc*r */ |
|
|
|
int red_by_vect(m,p,r,hc,len) |
|
int m; |
|
unsigned int *p,*r; |
|
unsigned int hc; |
|
int len; |
|
{ |
|
register unsigned int up,lo; |
|
unsigned int dmy; |
|
|
|
*p++ = 0; r++; len--; |
|
for ( ; len; len--, r++, p++ ) |
|
if ( *r ) { |
|
DMA(*r,hc,*p,up,lo); |
|
if ( up ) { |
|
DSAB(m,up,lo,dmy,*p); |
|
} else |
|
*p = lo; |
|
} |
|
} |
|
|
|
extern unsigned int **psca; |
|
|
|
void reduce_sp_by_red_mod_compress (sp,redmat,ind,nred,col,md) |
|
int *sp; |
|
CDP *redmat; |
|
int *ind; |
|
int nred,col; |
|
int md; |
|
{ |
|
int i,j,k,len; |
|
unsigned int *tj; |
|
CDP ri; |
|
unsigned int hc,up,lo,up1,lo1,c; |
|
unsigned int *usp; |
|
|
|
usp = (unsigned int *)sp; |
|
/* reduce the spolys by redmat */ |
|
for ( i = nred-1; i >= 0; i-- ) { |
|
/* reduce sp by redmat[i] */ |
|
usp[ind[i]] %= md; |
|
if ( hc = usp[ind[i]] ) { |
|
/* sp = sp-hc*redmat[i] */ |
|
hc = md-hc; |
|
ri = redmat[i]; |
|
len = ri->len; |
|
red_by_compress(md,usp,psca[ri->psindex],ri->body,hc,len); |
|
} |
|
} |
|
for ( i = 0; i < col; i++ ) |
|
if ( usp[i] >= md ) |
|
usp[i] %= md; |
|
} |
|
|
#define ONE_STEP2 if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
#define ONE_STEP2 if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
|
int generic_gauss_elim_mod(mat,row,col,md,colstat) |
int generic_gauss_elim_mod(mat0,row,col,md,colstat) |
int **mat; |
int **mat0; |
int row,col,md; |
int row,col,md; |
int *colstat; |
int *colstat; |
{ |
{ |
int i,j,k,l,inv,a,rank,zzz; |
int i,j,k,l,inv,a,rank,zzz; |
int *t,*pivot,*pk,*tk; |
unsigned int *t,*pivot,*pk,*tk; |
|
unsigned int **mat; |
|
|
|
mat = (unsigned int **)mat0; |
for ( rank = 0, j = 0; j < col; j++ ) { |
for ( rank = 0, j = 0; j < col; j++ ) { |
for ( i = rank; i < row && !mat[i][j]; i++ ); |
for ( i = rank; i < row; i++ ) |
|
mat[i][j] %= md; |
|
for ( i = rank; i < row; i++ ) |
|
if ( mat[i][j] ) |
|
break; |
if ( i == row ) { |
if ( i == row ) { |
colstat[j] = 0; |
colstat[j] = 0; |
continue; |
continue; |
|
|
inv = invm(pivot[j],md); |
inv = invm(pivot[j],md); |
for ( k = j, pk = pivot+k; k < col; k++, pk++ ) |
for ( k = j, pk = pivot+k; k < col; k++, pk++ ) |
if ( *pk ) { |
if ( *pk ) { |
|
if ( *pk >= md ) |
|
*pk %= md; |
DMAR(*pk,inv,0,md,*pk) |
DMAR(*pk,inv,0,md,*pk) |
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) { |
if ( a = t[j] ) |
a = md - a; pk = pivot+j; tk = t+j; |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
k = col-j; |
|
for ( ; k >= 64; k -= 64 ) { |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
} |
|
for ( ; k >= 0; k -- ) { |
|
if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
} |
|
} |
|
} |
} |
rank++; |
rank++; |
} |
} |
|
|
pivot = mat[l]; |
pivot = mat[l]; |
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) { |
t[j] %= md; |
a = md-a; pk = pivot+j; tk = t+j; |
if ( a = t[j] ) |
k = col-j; |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
for ( ; k >= 64; k -= 64 ) { |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
} |
|
for ( ; k >= 0; k -- ) { |
|
if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
} |
|
} |
|
} |
} |
l--; |
l--; |
|
} |
|
for ( j = 0, l = 0; l < rank; j++ ) |
|
if ( colstat[j] ) { |
|
t = mat[l]; |
|
for ( k = j; k < col; k++ ) |
|
if ( t[k] >= md ) |
|
t[k] %= md; |
|
l++; |
} |
} |
return rank; |
return rank; |
} |
} |