rem
stringlengths
0
274k
add
stringlengths
0
169k
context
stringlengths
9
471k
pari_sp av = avma; long l = precision(x); if (!l) l = prec;
pari_sp av = avma, av2; long L, l = precision(x); if (!l) l = prec;
agm1cx(GEN x, long prec){ GEN a1, b1; pari_sp av = avma; long l = precision(x); if (!l) l = prec; a1 = x; b1 = gun; l = 5-bit_accuracy(l); do { GEN a = a1; a1 = gmul2n(gadd(a,b1),-1); b1 = gsqrt(gmul(a,b1), prec); } while (gexpo(gsub(b1,a1)) - gexpo(b1) >= l); return gerepilecopy(av,a1);}
a1 = x; b1 = gun; l = 5-bit_accuracy(l); do
L = 5-bit_accuracy(l); a1 = gmul2n(gadd(realun(l), x), -1); av2 = avma; b1 = gsqrt(x, prec); while (gexpo(gsub(b1,a1)) - gexpo(b1) >= L)
agm1cx(GEN x, long prec){ GEN a1, b1; pari_sp av = avma; long l = precision(x); if (!l) l = prec; a1 = x; b1 = gun; l = 5-bit_accuracy(l); do { GEN a = a1; a1 = gmul2n(gadd(a,b1),-1); b1 = gsqrt(gmul(a,b1), prec); } while (gexpo(gsub(b1,a1)) - gexpo(b1) >= l); return gerepilecopy(av,a1);}
while (gexpo(gsub(b1,a1)) - gexpo(b1) >= l); return gerepilecopy(av,a1);
avma = av2; return gerepileupto(av,a1);
agm1cx(GEN x, long prec){ GEN a1, b1; pari_sp av = avma; long l = precision(x); if (!l) l = prec; a1 = x; b1 = gun; l = 5-bit_accuracy(l); do { GEN a = a1; a1 = gmul2n(gadd(a,b1),-1); b1 = gsqrt(gmul(a,b1), prec); } while (gexpo(gsub(b1,a1)) - gexpo(b1) >= l); return gerepilecopy(av,a1);}
GEN y, z;
GEN z;
mpch(GEN x){ pari_sp av; GEN y, z; if (gcmp0(x)) { /* 1 + x */ long e = expo(x); if (e > 0) return realzero_bit(e); return realun(3 + ((-e)>>TWOPOTBITS_IN_LONG)); } y = cgetr(lg(x)); av = avma; z = mpexp(x); z = addrr(z, ginv(z)); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;}
y = cgetr(lg(x)); av = avma; z = mpexp(x); z = addrr(z, ginv(z)); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;
av = avma; z = mpexp(x); z = addrr(z, ginv(z)); setexpo(z, expo(z)-1); return gerepileuptoleaf(av, z);
mpch(GEN x){ pari_sp av; GEN y, z; if (gcmp0(x)) { /* 1 + x */ long e = expo(x); if (e > 0) return realzero_bit(e); return realun(3 + ((-e)>>TWOPOTBITS_IN_LONG)); } y = cgetr(lg(x)); av = avma; z = mpexp(x); z = addrr(z, ginv(z)); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;}
if (Z) *Z = shiftpol(x, v);
if (Z) *Z = shiftpol_i(x, v);
polvaluation_inexact(GEN x, GEN *Z){ long v; if (!signe(x)) { if (Z) *Z = zeropol(varn(x)); return VERYBIGINT; } for (v = 0;; v++) if (!gcmp0((GEN)x[2+v])) break; if (Z) *Z = shiftpol(x, v); return v;}
GEN AL, E = (GEN)tabE[pk];
GEN AL, E = (GEN)tabE[pkfalse];
get_AL(GEN N, int pk){ const int r = smodis(N, pk); GEN AL, E = (GEN)tabE[pk]; int i, LE = lg(E); AL = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p1 = cgetg(3,t_VECSMALL); AL[i] = (long)p1; p1[1] = E[i]; p1[2] = (r*E[i]) / pk; } return AL;}
a,b, lg(oldCM_L)-1, CM_L? lg(CM_L)-1: 1, TIMER(&TI));
a,b, lg(m)-1, CM_L? lg(CM_L)-1: 1, TIMER(&TI));
LLL_cmbf(GEN P, GEN famod, GEN p, GEN pa, GEN bound, long a, long rec){ const long N0 = 1; /* # of traces added at each step */ double BitPerFactor = 0.5; /* nb bits in p^(a-b) / modular factor */ long i,j,tmax,n0,C, dP = degpol(P); double logp = log((double)itos(p)), LOGp2 = LOG2/logp; double b0 = log((double)dP*2) / logp, logBr; GEN lP, Br, Bnorm, Tra, T2, TT, CM_L, m, list, ZERO; gpmem_t av, av2, lim; long ti_LLL = 0, ti_CF = 0; pari_timer ti, ti2, TI; if (DEBUGLEVEL>2) (void)TIMER(&ti); lP = absi(leading_term(P)); if (is_pm1(lP)) lP = NULL; Br = root_bound(P); if (lP) Br = gmul(lP, Br); logBr = gtodouble(glog(Br, DEFAULTPREC)) / logp; n0 = lg(famod) - 1; C = (long)ceil( sqrt(N0 * n0 / 4.) ); /* > 1 */ Bnorm = dbltor(n0 * (C*C + N0*n0/4.) * 1.00001); ZERO = zeromat(n0, N0); av = avma; lim = stack_lim(av, 1); TT = cgetg(n0+1, t_VEC); Tra = cgetg(n0+1, t_MAT); for (i=1; i<=n0; i++) { TT[i] = 0; Tra[i] = lgetg(N0+1, t_COL); } CM_L = gscalsmat(C, n0); /* tmax = current number of traces used (and computed so far) */ for (tmax = 0;; tmax += N0) { long b, bmin, bgood, delta, tnew = tmax + N0, r = lg(CM_L)-1; GEN M_L, q, CM_Lp, oldCM_L; int first = 1; bmin = (long)ceil(b0 + tnew*logBr); if (DEBUGLEVEL>2) fprintferr("\nLLL_cmbf: %ld potential factors (tmax = %ld, bmin = %ld)\n", r, tmax, bmin); /* compute Newton sums (possibly relifting first) */ if (a <= bmin) { a = (long)ceil(bmin + 3*N0*logBr) + 1; /* enough for 3 more rounds */ a = next2pow(a); pa = gpowgs(p,a); famod = hensel_lift_fact(P,famod,NULL,p,pa,a); for (i=1; i<=n0; i++) TT[i] = 0; } for (i=1; i<=n0; i++) { GEN p1 = (GEN)Tra[i]; GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tnew, NULL, pa); TT[i] = (long)p2; p2 += 1+tmax; /* ignore traces number 0...tmax */ for (j=1; j<=N0; j++) p1[j] = p2[j]; if (lP) { /* make Newton sums integral */ GEN lPpow = gpowgs(lP, tmax); for (j=1; j<=N0; j++) { lPpow = mulii(lPpow,lP); p1[j] = lmulii((GEN)p1[j], lPpow); } } } /* compute truncation parameter */ if (DEBUGLEVEL>2) { TIMERstart(&ti2); TIMERstart(&TI); } oldCM_L = CM_L; av2 = avma; delta = b = 0; /* -Wall */AGAIN: M_L = gdivexact(CM_L, stoi(C)); T2 = centermod( gmul(Tra, M_L), pa ); if (first) { /* initialize lattice, using few p-adic digits for traces */ double t = gexpo(T2) - max(32, BitPerFactor*r); bgood = (long) (t * LOGp2); b = max(bmin, bgood); delta = a - b; } else { /* add more p-adic digits and continue reduction */ long b0 = gexpo(T2) * LOGp2; if (b0 < b) b = b0; b = max(b-delta, bmin); if (b - delta/2 < bmin) b = bmin; /* near there. Go all the way */ } q = gpowgs(p, b); m = vconcat( CM_L, gdivround(T2, q) ); if (first) { GEN P1 = gscalmat(gpowgs(p, a-b), N0); first = 0; m = concatsp( m, vconcat(ZERO, P1) ); /* [ C M_L 0 ] * m = [ ] square matrix * [ T2' p^(a-b) I_s ] T2' = Tra * M_L truncated */ } CM_L = LLL_check_progress(Bnorm, n0, m, b == bmin, /*dbg:*/ &ti, &ti_LLL); if (DEBUGLEVEL>2) fprintferr("LLL_cmbf: (a,b) =%4ld,%4ld; r =%3ld -->%3ld, time = %ld\n", a,b, lg(oldCM_L)-1, CM_L? lg(CM_L)-1: 1, TIMER(&TI)); if (!CM_L) { list = _col(P); break; } if (b > bmin) { CM_L = gerepilecopy(av2, CM_L); goto AGAIN; } if (DEBUGLEVEL>2) msgTIMER(&ti2, "for this block of traces"); i = lg(CM_L) - 1; if (i == r && gegal(CM_L, oldCM_L)) { CM_L = oldCM_L; avma = av2; continue; } CM_Lp = FpM_image(CM_L, stoi(27449)); /* inexpensive test */ if (lg(CM_Lp) != lg(CM_L)) { if (DEBUGLEVEL>2) fprintferr("LLL_cmbf: rank decrease\n"); CM_L = ZM_HNFimage(CM_L); } if (i <= r && i*rec < n0) { if (DEBUGLEVEL>2) (void)TIMER(&ti); list = check_factors(P, M_L, bound, famod, pa); if (DEBUGLEVEL>2) ti_CF += TIMER(&ti); if (list) break; CM_L = gerepilecopy(av2, CM_L); } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"LLL_cmbf"); gerepileall(av, 5, &CM_L, &TT, &Tra, &famod, &pa); } } if (DEBUGLEVEL>2) fprintferr("* Time LLL: %ld\n* Time Check Factor: %ld\n",ti_LLL,ti_CF); return list;}
long ffs,fs,resp,flbou,tdi,nba, k2,karch,kka,nbarch,jjj,jj,square;
long ffs,fs,resp,flbou,nba, k2,karch,kka,nbarch,jjj,jj,square;
discrayabslistarchintern(GEN bnf, GEN arch, long bound, long ramip){ byteptr ptdif=diffptr; long degk,lim,av0,av,av1,tetpil,i,j,k,p2s,lfa,lp1,sqbou,cex, allarch; long ffs,fs,resp,flbou,tdi,nba, k2,karch,kka,nbarch,jjj,jj,square; long ii2,ii,ly,clhray,lfa2,ep,som,clhss,normps,normi,nbdezero,r1,R1,n,c; ulong q; GEN nf,p,z,pol,p1,p2,p3,fa,pr,normp,ideal,bidp,z2,matarchunit; GEN bigres,funits,racunit,embunit,sous,clh,sousray,raylist; GEN clhrayall,discall,faall,Id,idealrel,idealrelinit; GEN sousdisc,module,fa2,ex,fac,no1,no2,fad,fad1,fad2,fadkabs,pz; GEN arch2,dlk,disclist,bidsimp,p4,faussefa,pex,fauxpr,gprime; GEN *gptr[2]; clhray = nbdezero = 0; /* gcc -Wall */ module = Id = dlk = ideal = clhrayall = discall = faall = NULL; /* ce qui suit recopie d'assez pres ideallistzstarall */ if (DEBUGLEVEL>2) timer2(); if (bound <= 0) err(talker,"non-positive bound in discrayabslist"); av0=avma; bnf = checkbnf(bnf); flbou=0; nf=(GEN)bnf[7]; bigres=(GEN)bnf[8]; pol=(GEN)nf[1]; degk=lgef(pol)-3; r1 = nf_get_r1(nf); fadkabs=factor(absi((GEN)nf[3])); clh=gmael(bigres,1,1); funits = check_units(bnf,"discrayabslistarchintern"); racunit=gmael(bigres,4,2); if (ramip >= 0) square = 0; else { square = 1; ramip = -ramip; if (ramip==1) ramip=0; } nba = 0; allarch = (arch==NULL); if (allarch) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=un; nba=r1; } else if (gcmp0(arch)) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=zero; } else { if (lg(arch)!=r1+1) err(talker,"incorrect archimedean argument in discrayabslistlong"); for (i=1; i<=r1; i++) if (signe(arch[i])) nba++; if (nba) module=cgetg(3,t_VEC); } p1=cgetg(3,t_VEC); p1[1]=(long)idmat(degk); p1[2]=(long)arch; bidp=zidealstarinitall(nf,p1,0); matarchunit = allarch? logunitmatrix(nf,funits,racunit,bidp): (GEN)NULL; p=cgeti(3); p[1]=evalsigne(1)|evallgef(3); sqbou=itos(racine(stoi(bound)))+1; av=avma; lim=stack_lim(av,1); z=bigcgetvec(bound); for (i=2; i<=bound; i++) putcompobig(z,i,cgetg(1,t_VEC)); if (allarch) bidp=zidealstarinitall(nf,idmat(degk),0); embunit=logunitmatrix(nf,funits,racunit,bidp); p1=cgetg(2,t_VEC); putcompobig(z,1,p1); p1[1]=(long)zsimp(bidp,embunit); if (DEBUGLEVEL>=2) fprintferr("Starting zidealstarunits computations\n"); for (p[2]=0; p[2]<=bound; ) { if (!*ptdif) err(primer1); p[2] += *ptdif++; if (!flbou && p[2]>sqbou) { flbou=1; if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); /* maintenant on suit rayclassnolist */ for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } tetpil=avma; raylist=gerepile(av1,tetpil,gcopy(raylist)); z2=bigcgetvec(sqbou); for (i=1; i<=sqbou; i++) { p1=gcopy(getcompobig(z,i)); putcompobig(z2,i,p1); } z = z2; } fa=primedec(nf,p); lfa=lg(fa)-1; for (j=1; j<=lfa; j++) { pr=(GEN)fa[j]; normp=powgi(p,(GEN)pr[4]); cex=0; if (DEBUGLEVEL>=2) { fprintferr("%ld ",p[2]); flusherr(); } if (gcmpgs(normp,bound)<=0) { fauxpr=stoi(p[2]*degk*degk+(itos((GEN)pr[4])-1)*degk+j-1); q=p2s=itos(normp); ideal=pr; while (q <= (ulong)bound) { bidp=zidealstarinitall(nf,ideal,0); faussefa=cgetg(3,t_MAT); p1=cgetg(2,t_COL); faussefa[1]=(long)p1; p1[1]=(long)fauxpr; pex=cgetg(2,t_COL); faussefa[2]=(long)pex; cex++; pex[1]=lstoi(cex); embunit=logunitmatrix(nf,funits,racunit,bidp); for (i=q; i<=bound; i+=q) { p1=getcompobig(z,i/q); lp1=lg(p1); if (lp1>1) { p2=cgetg(lp1,t_VEC); c=0; for (k=1; k<lp1; k++) { p3=(GEN)p1[k]; if (i==q || ((p4=gmael(p3,1,1)) && !isinvector(p4,fauxpr,lg(p4)-1))) { c++; p2[c]=(long)zsimpjoin(p3,bidp,faussefa,embunit); } } setlg(p2,c+1); if (c) { if (p[2]<=sqbou) { pz=getcompobig(z,i); if (lg(pz)>1) putcompobig(z,i,concatsp(pz,p2)); else putcompobig(z,i,p2); } else { sousray=rayclassnointernarch(p2,clh,matarchunit); pz=getcompobig(raylist,i); if (lg(pz)>1) putcompobig(raylist,i,concatsp(pz,sousray)); else putcompobig(raylist,i,sousray); } } } } if (ramip && ramip % p[2]) q=bound+1; else { pz=mulss(q,p2s); q=(gcmpgs(pz,bound)>0)?bound+1:pz[2]; if (q <= (ulong)bound) ideal=idealmul(nf,ideal,pr); } } } } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: discrayabslistarch"); if (!flbou) { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(z) = %ld ",avma-bot,taille2(z)); tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); } else { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); gptr[0]=&z; gptr[1]=&raylist; gerepilemany(av,gptr,2); } if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } if (!flbou) /* maintenant on suit rayclassnolist */ { if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } } if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); tetpil=avma; raylist=gerepile(av,tetpil,gcopy(raylist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); msgtimer("zidealstarlist"); } /* maintenant on suit discrayabslist */ if (DEBUGLEVEL>=2) { fprintferr("Starting discrayabs computations\n"); flusherr(); } if (allarch) nbarch = 1<<r1; else { nbarch = 1; clhrayall = cgetg(2,t_VEC); discall = cgetg(2,t_VEC); faall = cgetg(2,t_VEC); Id = idmat(degk); } idealrelinit=cgetg(3,t_MAT); idealrelinit[1]=lgetg(1,t_COL); idealrelinit[2]=lgetg(1,t_COL); av1=avma; lim=stack_lim(av1,1); if (square) bound = sqbou-1; disclist=bigcgetvec(bound); for (ii=1; ii<=bound; ii++) putcompobig(disclist,ii,cgetg(1,t_VEC)); for (ii2=1; ii2<=bound; ii2++) { ii = square? ii2*ii2: ii2; if (DEBUGLEVEL>=2 && ii%100==0) { fprintferr("%ld ",ii); flusherr(); } sous=getcompobig(raylist,ii); ly=lg(sous); sousdisc=cgetg(ly,t_VEC); putcompobig(disclist, square? ii2: ii,sousdisc); for (jj=1; jj<ly; jj++) { bidsimp=(GEN)sous[jj]; fa=(GEN)bidsimp[1]; fac=gcopy(fa); fa2=(GEN)fa[1]; ex=(GEN)fa[2]; lfa2=lg(fa2); if (allarch) { clhrayall = (GEN)bidsimp[2]; discall=cgetg(nbarch+1,t_VEC); } else clhray = itos((GEN)bidsimp[2]); for (karch=0; karch<nbarch; karch++) { if (!allarch) ideal = Id; else { kka=karch; nba=0; for (jjj=1; jjj<=r1; jjj++) { if (kka%2) nba++; kka>>=1; } clhray=itos((GEN)clhrayall[karch+1]); for (k2=1,k=1; k<=r1; k++,k2<<=1) { if (karch&k2 && clhray==itos((GEN)clhrayall[karch-k2+1])) { clhray=0; goto LDISCRAY; } } } idealrel = idealrelinit; for (k=1; k<lfa2; k++) { fauxpr=(GEN)fa2[k]; ep=itos((GEN)ex[k]); ffs=itos(fauxpr); /* Hack for NeXTgcc 2.5.8 -- splitting "resp=fs%degk+1" */ fs=ffs/degk; resp=fs%degk; resp++; gprime=stoi((long)(fs/degk)); if (!allarch && nba) { p1=(GEN)primedec(nf,gprime)[ffs%degk+1]; ideal = idealmul(nf,ideal,idealpow(nf,p1,(GEN)ex[k])); } som=0; clhss=0; normp=gpuigs(gprime,resp); normps=itos(normp); normi=ii; normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); no1[1]=(long)gprime; normp[1]=(long)no1; no2=cgetg(2,t_COL); no2[1]=lstoi(resp); normp[2]=(long)no2; for (j=1; j<=ep; j++) { if (clhss==1) som++; else { if (j<ep) { coeff(fac,k,2)=lstoi(ep-j); fad=fac; } else { fad=cgetg(3,t_MAT); fad1=cgetg(lfa2-1,t_COL); fad[1]=(long)fad1; fad2=cgetg(lfa2-1,t_COL); fad[2]=(long)fad2; for (i=1; i<k; i++) { fad1[i]=coeff(fac,i,1); fad2[i]=coeff(fac,i,2); } for ( ; i<lfa2-1; i++) { fad1[i]=coeff(fac,i+1,1); fad2[i]=coeff(fac,i+1,2); } } normi /= normps; /* Hack for NeXTgcc 2.5.8 -- using dlk as temporary variable */ dlk=rayclassnolistessimp(getcompobig(raylist,normi),fad); if (allarch) dlk = (GEN)dlk[karch+1]; clhss = itos(dlk); if (j==1 && clhss==clhray) { clhray=0; coeff(fac,k,2)=ex[k]; goto LDISCRAY; } som += clhss; } } coeff(fac,k,2)=ex[k]; idealrel=factormul(idealrel,factorpow(normp,som)); } dlk=factordivexact(factorpow(factor(stoi(ii)),clhray),idealrel); if (!allarch && nba) { module[1]=(long)ideal; arch2=gcopy(arch); module[2]=(long)arch2; nbdezero=0; for (k=1; k<=r1; k++) { if (signe(arch[k])) { arch2[k]=zero; clhss=itos(rayclassno(bnf,module)); arch2[k]=un; if (clhss==clhray) { clhray=0; goto LDISCRAY; } } else nbdezero++; } } else nbdezero = r1-nba;LDISCRAY: p1=cgetg(4,t_VEC); discall[karch+1]=(long)p1; if (!clhray) p1[1]=p1[2]=p1[3]=zero; else { p3=factorpow(fadkabs,clhray); n=clhray*degk; R1=nbdezero*clhray; if (((n-R1)&3)==2) { normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); normp[1]=(long)no1; no1[1]=lstoi(-1); no2=cgetg(2,t_COL); normp[2]=(long)no2; no2[1]=un; dlk=factormul(normp,dlk); } p1[1]=lstoi(n); p1[2]=lstoi(R1); p1[3]=(long)factormul(dlk,p3); } } if (allarch) { p1 = cgetg(3,t_VEC); p1[1]=(long)fa; p1[2]=(long)discall; } else { faall[1]=(long)fa; p1 = concatsp(faall, p1); } sousdisc[jj]=(long)p1; if (low_stack(lim, stack_lim(av1,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: discrayabslistarch"); if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(d) = %ld ",avma-bot,taille2(disclist)); tetpil=avma; disclist=gerepile(av1,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } } if (DEBUGLEVEL>2) msgtimer("discrayabs"); tdi=taille2(disclist); if (DEBUGLEVEL>2) { fprintferr("avma = %ld, t(d) = %ld ",avma-bot,tdi); flusherr(); } if (tdi<avma-bot) { tetpil=avma; disclist=gerepile(av0,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } return disclist;}
if (i==q ||
if (q == (ulong)i ||
discrayabslistarchintern(GEN bnf, GEN arch, long bound, long ramip){ byteptr ptdif=diffptr; long degk,lim,av0,av,av1,tetpil,i,j,k,p2s,lfa,lp1,sqbou,cex, allarch; long ffs,fs,resp,flbou,tdi,nba, k2,karch,kka,nbarch,jjj,jj,square; long ii2,ii,ly,clhray,lfa2,ep,som,clhss,normps,normi,nbdezero,r1,R1,n,c; ulong q; GEN nf,p,z,pol,p1,p2,p3,fa,pr,normp,ideal,bidp,z2,matarchunit; GEN bigres,funits,racunit,embunit,sous,clh,sousray,raylist; GEN clhrayall,discall,faall,Id,idealrel,idealrelinit; GEN sousdisc,module,fa2,ex,fac,no1,no2,fad,fad1,fad2,fadkabs,pz; GEN arch2,dlk,disclist,bidsimp,p4,faussefa,pex,fauxpr,gprime; GEN *gptr[2]; clhray = nbdezero = 0; /* gcc -Wall */ module = Id = dlk = ideal = clhrayall = discall = faall = NULL; /* ce qui suit recopie d'assez pres ideallistzstarall */ if (DEBUGLEVEL>2) timer2(); if (bound <= 0) err(talker,"non-positive bound in discrayabslist"); av0=avma; bnf = checkbnf(bnf); flbou=0; nf=(GEN)bnf[7]; bigres=(GEN)bnf[8]; pol=(GEN)nf[1]; degk=lgef(pol)-3; r1 = nf_get_r1(nf); fadkabs=factor(absi((GEN)nf[3])); clh=gmael(bigres,1,1); funits = check_units(bnf,"discrayabslistarchintern"); racunit=gmael(bigres,4,2); if (ramip >= 0) square = 0; else { square = 1; ramip = -ramip; if (ramip==1) ramip=0; } nba = 0; allarch = (arch==NULL); if (allarch) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=un; nba=r1; } else if (gcmp0(arch)) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=zero; } else { if (lg(arch)!=r1+1) err(talker,"incorrect archimedean argument in discrayabslistlong"); for (i=1; i<=r1; i++) if (signe(arch[i])) nba++; if (nba) module=cgetg(3,t_VEC); } p1=cgetg(3,t_VEC); p1[1]=(long)idmat(degk); p1[2]=(long)arch; bidp=zidealstarinitall(nf,p1,0); matarchunit = allarch? logunitmatrix(nf,funits,racunit,bidp): (GEN)NULL; p=cgeti(3); p[1]=evalsigne(1)|evallgef(3); sqbou=itos(racine(stoi(bound)))+1; av=avma; lim=stack_lim(av,1); z=bigcgetvec(bound); for (i=2; i<=bound; i++) putcompobig(z,i,cgetg(1,t_VEC)); if (allarch) bidp=zidealstarinitall(nf,idmat(degk),0); embunit=logunitmatrix(nf,funits,racunit,bidp); p1=cgetg(2,t_VEC); putcompobig(z,1,p1); p1[1]=(long)zsimp(bidp,embunit); if (DEBUGLEVEL>=2) fprintferr("Starting zidealstarunits computations\n"); for (p[2]=0; p[2]<=bound; ) { if (!*ptdif) err(primer1); p[2] += *ptdif++; if (!flbou && p[2]>sqbou) { flbou=1; if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); /* maintenant on suit rayclassnolist */ for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } tetpil=avma; raylist=gerepile(av1,tetpil,gcopy(raylist)); z2=bigcgetvec(sqbou); for (i=1; i<=sqbou; i++) { p1=gcopy(getcompobig(z,i)); putcompobig(z2,i,p1); } z = z2; } fa=primedec(nf,p); lfa=lg(fa)-1; for (j=1; j<=lfa; j++) { pr=(GEN)fa[j]; normp=powgi(p,(GEN)pr[4]); cex=0; if (DEBUGLEVEL>=2) { fprintferr("%ld ",p[2]); flusherr(); } if (gcmpgs(normp,bound)<=0) { fauxpr=stoi(p[2]*degk*degk+(itos((GEN)pr[4])-1)*degk+j-1); q=p2s=itos(normp); ideal=pr; while (q <= (ulong)bound) { bidp=zidealstarinitall(nf,ideal,0); faussefa=cgetg(3,t_MAT); p1=cgetg(2,t_COL); faussefa[1]=(long)p1; p1[1]=(long)fauxpr; pex=cgetg(2,t_COL); faussefa[2]=(long)pex; cex++; pex[1]=lstoi(cex); embunit=logunitmatrix(nf,funits,racunit,bidp); for (i=q; i<=bound; i+=q) { p1=getcompobig(z,i/q); lp1=lg(p1); if (lp1>1) { p2=cgetg(lp1,t_VEC); c=0; for (k=1; k<lp1; k++) { p3=(GEN)p1[k]; if (i==q || ((p4=gmael(p3,1,1)) && !isinvector(p4,fauxpr,lg(p4)-1))) { c++; p2[c]=(long)zsimpjoin(p3,bidp,faussefa,embunit); } } setlg(p2,c+1); if (c) { if (p[2]<=sqbou) { pz=getcompobig(z,i); if (lg(pz)>1) putcompobig(z,i,concatsp(pz,p2)); else putcompobig(z,i,p2); } else { sousray=rayclassnointernarch(p2,clh,matarchunit); pz=getcompobig(raylist,i); if (lg(pz)>1) putcompobig(raylist,i,concatsp(pz,sousray)); else putcompobig(raylist,i,sousray); } } } } if (ramip && ramip % p[2]) q=bound+1; else { pz=mulss(q,p2s); q=(gcmpgs(pz,bound)>0)?bound+1:pz[2]; if (q <= (ulong)bound) ideal=idealmul(nf,ideal,pr); } } } } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: discrayabslistarch"); if (!flbou) { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(z) = %ld ",avma-bot,taille2(z)); tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); } else { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); gptr[0]=&z; gptr[1]=&raylist; gerepilemany(av,gptr,2); } if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } if (!flbou) /* maintenant on suit rayclassnolist */ { if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } } if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); tetpil=avma; raylist=gerepile(av,tetpil,gcopy(raylist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); msgtimer("zidealstarlist"); } /* maintenant on suit discrayabslist */ if (DEBUGLEVEL>=2) { fprintferr("Starting discrayabs computations\n"); flusherr(); } if (allarch) nbarch = 1<<r1; else { nbarch = 1; clhrayall = cgetg(2,t_VEC); discall = cgetg(2,t_VEC); faall = cgetg(2,t_VEC); Id = idmat(degk); } idealrelinit=cgetg(3,t_MAT); idealrelinit[1]=lgetg(1,t_COL); idealrelinit[2]=lgetg(1,t_COL); av1=avma; lim=stack_lim(av1,1); if (square) bound = sqbou-1; disclist=bigcgetvec(bound); for (ii=1; ii<=bound; ii++) putcompobig(disclist,ii,cgetg(1,t_VEC)); for (ii2=1; ii2<=bound; ii2++) { ii = square? ii2*ii2: ii2; if (DEBUGLEVEL>=2 && ii%100==0) { fprintferr("%ld ",ii); flusherr(); } sous=getcompobig(raylist,ii); ly=lg(sous); sousdisc=cgetg(ly,t_VEC); putcompobig(disclist, square? ii2: ii,sousdisc); for (jj=1; jj<ly; jj++) { bidsimp=(GEN)sous[jj]; fa=(GEN)bidsimp[1]; fac=gcopy(fa); fa2=(GEN)fa[1]; ex=(GEN)fa[2]; lfa2=lg(fa2); if (allarch) { clhrayall = (GEN)bidsimp[2]; discall=cgetg(nbarch+1,t_VEC); } else clhray = itos((GEN)bidsimp[2]); for (karch=0; karch<nbarch; karch++) { if (!allarch) ideal = Id; else { kka=karch; nba=0; for (jjj=1; jjj<=r1; jjj++) { if (kka%2) nba++; kka>>=1; } clhray=itos((GEN)clhrayall[karch+1]); for (k2=1,k=1; k<=r1; k++,k2<<=1) { if (karch&k2 && clhray==itos((GEN)clhrayall[karch-k2+1])) { clhray=0; goto LDISCRAY; } } } idealrel = idealrelinit; for (k=1; k<lfa2; k++) { fauxpr=(GEN)fa2[k]; ep=itos((GEN)ex[k]); ffs=itos(fauxpr); /* Hack for NeXTgcc 2.5.8 -- splitting "resp=fs%degk+1" */ fs=ffs/degk; resp=fs%degk; resp++; gprime=stoi((long)(fs/degk)); if (!allarch && nba) { p1=(GEN)primedec(nf,gprime)[ffs%degk+1]; ideal = idealmul(nf,ideal,idealpow(nf,p1,(GEN)ex[k])); } som=0; clhss=0; normp=gpuigs(gprime,resp); normps=itos(normp); normi=ii; normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); no1[1]=(long)gprime; normp[1]=(long)no1; no2=cgetg(2,t_COL); no2[1]=lstoi(resp); normp[2]=(long)no2; for (j=1; j<=ep; j++) { if (clhss==1) som++; else { if (j<ep) { coeff(fac,k,2)=lstoi(ep-j); fad=fac; } else { fad=cgetg(3,t_MAT); fad1=cgetg(lfa2-1,t_COL); fad[1]=(long)fad1; fad2=cgetg(lfa2-1,t_COL); fad[2]=(long)fad2; for (i=1; i<k; i++) { fad1[i]=coeff(fac,i,1); fad2[i]=coeff(fac,i,2); } for ( ; i<lfa2-1; i++) { fad1[i]=coeff(fac,i+1,1); fad2[i]=coeff(fac,i+1,2); } } normi /= normps; /* Hack for NeXTgcc 2.5.8 -- using dlk as temporary variable */ dlk=rayclassnolistessimp(getcompobig(raylist,normi),fad); if (allarch) dlk = (GEN)dlk[karch+1]; clhss = itos(dlk); if (j==1 && clhss==clhray) { clhray=0; coeff(fac,k,2)=ex[k]; goto LDISCRAY; } som += clhss; } } coeff(fac,k,2)=ex[k]; idealrel=factormul(idealrel,factorpow(normp,som)); } dlk=factordivexact(factorpow(factor(stoi(ii)),clhray),idealrel); if (!allarch && nba) { module[1]=(long)ideal; arch2=gcopy(arch); module[2]=(long)arch2; nbdezero=0; for (k=1; k<=r1; k++) { if (signe(arch[k])) { arch2[k]=zero; clhss=itos(rayclassno(bnf,module)); arch2[k]=un; if (clhss==clhray) { clhray=0; goto LDISCRAY; } } else nbdezero++; } } else nbdezero = r1-nba;LDISCRAY: p1=cgetg(4,t_VEC); discall[karch+1]=(long)p1; if (!clhray) p1[1]=p1[2]=p1[3]=zero; else { p3=factorpow(fadkabs,clhray); n=clhray*degk; R1=nbdezero*clhray; if (((n-R1)&3)==2) { normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); normp[1]=(long)no1; no1[1]=lstoi(-1); no2=cgetg(2,t_COL); normp[2]=(long)no2; no2[1]=un; dlk=factormul(normp,dlk); } p1[1]=lstoi(n); p1[2]=lstoi(R1); p1[3]=(long)factormul(dlk,p3); } } if (allarch) { p1 = cgetg(3,t_VEC); p1[1]=(long)fa; p1[2]=(long)discall; } else { faall[1]=(long)fa; p1 = concatsp(faall, p1); } sousdisc[jj]=(long)p1; if (low_stack(lim, stack_lim(av1,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: discrayabslistarch"); if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(d) = %ld ",avma-bot,taille2(disclist)); tetpil=avma; disclist=gerepile(av1,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } } if (DEBUGLEVEL>2) msgtimer("discrayabs"); tdi=taille2(disclist); if (DEBUGLEVEL>2) { fprintferr("avma = %ld, t(d) = %ld ",avma-bot,tdi); flusherr(); } if (tdi<avma-bot) { tetpil=avma; disclist=gerepile(av0,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } return disclist;}
tdi=taille2(disclist); if (DEBUGLEVEL>2) { fprintferr("avma = %ld, t(d) = %ld ",avma-bot,tdi); flusherr(); } if (tdi<avma-bot) { tetpil=avma; disclist=gerepile(av0,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } return disclist;
tetpil=avma; return gerepile(av0,tetpil,gcopy(disclist));
discrayabslistarchintern(GEN bnf, GEN arch, long bound, long ramip){ byteptr ptdif=diffptr; long degk,lim,av0,av,av1,tetpil,i,j,k,p2s,lfa,lp1,sqbou,cex, allarch; long ffs,fs,resp,flbou,tdi,nba, k2,karch,kka,nbarch,jjj,jj,square; long ii2,ii,ly,clhray,lfa2,ep,som,clhss,normps,normi,nbdezero,r1,R1,n,c; ulong q; GEN nf,p,z,pol,p1,p2,p3,fa,pr,normp,ideal,bidp,z2,matarchunit; GEN bigres,funits,racunit,embunit,sous,clh,sousray,raylist; GEN clhrayall,discall,faall,Id,idealrel,idealrelinit; GEN sousdisc,module,fa2,ex,fac,no1,no2,fad,fad1,fad2,fadkabs,pz; GEN arch2,dlk,disclist,bidsimp,p4,faussefa,pex,fauxpr,gprime; GEN *gptr[2]; clhray = nbdezero = 0; /* gcc -Wall */ module = Id = dlk = ideal = clhrayall = discall = faall = NULL; /* ce qui suit recopie d'assez pres ideallistzstarall */ if (DEBUGLEVEL>2) timer2(); if (bound <= 0) err(talker,"non-positive bound in discrayabslist"); av0=avma; bnf = checkbnf(bnf); flbou=0; nf=(GEN)bnf[7]; bigres=(GEN)bnf[8]; pol=(GEN)nf[1]; degk=lgef(pol)-3; r1 = nf_get_r1(nf); fadkabs=factor(absi((GEN)nf[3])); clh=gmael(bigres,1,1); funits = check_units(bnf,"discrayabslistarchintern"); racunit=gmael(bigres,4,2); if (ramip >= 0) square = 0; else { square = 1; ramip = -ramip; if (ramip==1) ramip=0; } nba = 0; allarch = (arch==NULL); if (allarch) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=un; nba=r1; } else if (gcmp0(arch)) { arch=cgetg(r1+1,t_VEC); for (i=1; i<=r1; i++) arch[i]=zero; } else { if (lg(arch)!=r1+1) err(talker,"incorrect archimedean argument in discrayabslistlong"); for (i=1; i<=r1; i++) if (signe(arch[i])) nba++; if (nba) module=cgetg(3,t_VEC); } p1=cgetg(3,t_VEC); p1[1]=(long)idmat(degk); p1[2]=(long)arch; bidp=zidealstarinitall(nf,p1,0); matarchunit = allarch? logunitmatrix(nf,funits,racunit,bidp): (GEN)NULL; p=cgeti(3); p[1]=evalsigne(1)|evallgef(3); sqbou=itos(racine(stoi(bound)))+1; av=avma; lim=stack_lim(av,1); z=bigcgetvec(bound); for (i=2; i<=bound; i++) putcompobig(z,i,cgetg(1,t_VEC)); if (allarch) bidp=zidealstarinitall(nf,idmat(degk),0); embunit=logunitmatrix(nf,funits,racunit,bidp); p1=cgetg(2,t_VEC); putcompobig(z,1,p1); p1[1]=(long)zsimp(bidp,embunit); if (DEBUGLEVEL>=2) fprintferr("Starting zidealstarunits computations\n"); for (p[2]=0; p[2]<=bound; ) { if (!*ptdif) err(primer1); p[2] += *ptdif++; if (!flbou && p[2]>sqbou) { flbou=1; if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); /* maintenant on suit rayclassnolist */ for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } tetpil=avma; raylist=gerepile(av1,tetpil,gcopy(raylist)); z2=bigcgetvec(sqbou); for (i=1; i<=sqbou; i++) { p1=gcopy(getcompobig(z,i)); putcompobig(z2,i,p1); } z = z2; } fa=primedec(nf,p); lfa=lg(fa)-1; for (j=1; j<=lfa; j++) { pr=(GEN)fa[j]; normp=powgi(p,(GEN)pr[4]); cex=0; if (DEBUGLEVEL>=2) { fprintferr("%ld ",p[2]); flusherr(); } if (gcmpgs(normp,bound)<=0) { fauxpr=stoi(p[2]*degk*degk+(itos((GEN)pr[4])-1)*degk+j-1); q=p2s=itos(normp); ideal=pr; while (q <= (ulong)bound) { bidp=zidealstarinitall(nf,ideal,0); faussefa=cgetg(3,t_MAT); p1=cgetg(2,t_COL); faussefa[1]=(long)p1; p1[1]=(long)fauxpr; pex=cgetg(2,t_COL); faussefa[2]=(long)pex; cex++; pex[1]=lstoi(cex); embunit=logunitmatrix(nf,funits,racunit,bidp); for (i=q; i<=bound; i+=q) { p1=getcompobig(z,i/q); lp1=lg(p1); if (lp1>1) { p2=cgetg(lp1,t_VEC); c=0; for (k=1; k<lp1; k++) { p3=(GEN)p1[k]; if (i==q || ((p4=gmael(p3,1,1)) && !isinvector(p4,fauxpr,lg(p4)-1))) { c++; p2[c]=(long)zsimpjoin(p3,bidp,faussefa,embunit); } } setlg(p2,c+1); if (c) { if (p[2]<=sqbou) { pz=getcompobig(z,i); if (lg(pz)>1) putcompobig(z,i,concatsp(pz,p2)); else putcompobig(z,i,p2); } else { sousray=rayclassnointernarch(p2,clh,matarchunit); pz=getcompobig(raylist,i); if (lg(pz)>1) putcompobig(raylist,i,concatsp(pz,sousray)); else putcompobig(raylist,i,sousray); } } } } if (ramip && ramip % p[2]) q=bound+1; else { pz=mulss(q,p2s); q=(gcmpgs(pz,bound)>0)?bound+1:pz[2]; if (q <= (ulong)bound) ideal=idealmul(nf,ideal,pr); } } } } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: discrayabslistarch"); if (!flbou) { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(z) = %ld ",avma-bot,taille2(z)); tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); } else { if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); gptr[0]=&z; gptr[1]=&raylist; gerepilemany(av,gptr,2); } if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } if (!flbou) /* maintenant on suit rayclassnolist */ { if (DEBUGLEVEL>=2) { fprintferr("\nStarting rayclassno computations\n"); flusherr(); } tetpil=avma; z=gerepile(av,tetpil,gcopy(z)); av1=avma; raylist=bigcgetvec(bound); for (i=1; i<=bound; i++) { sous=getcompobig(z,i); sousray=rayclassnointernarch(sous,clh,matarchunit); putcompobig(raylist,i,sousray); } } if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(r) = %ld ",avma-bot,taille2(raylist)); tetpil=avma; raylist=gerepile(av,tetpil,gcopy(raylist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); msgtimer("zidealstarlist"); } /* maintenant on suit discrayabslist */ if (DEBUGLEVEL>=2) { fprintferr("Starting discrayabs computations\n"); flusherr(); } if (allarch) nbarch = 1<<r1; else { nbarch = 1; clhrayall = cgetg(2,t_VEC); discall = cgetg(2,t_VEC); faall = cgetg(2,t_VEC); Id = idmat(degk); } idealrelinit=cgetg(3,t_MAT); idealrelinit[1]=lgetg(1,t_COL); idealrelinit[2]=lgetg(1,t_COL); av1=avma; lim=stack_lim(av1,1); if (square) bound = sqbou-1; disclist=bigcgetvec(bound); for (ii=1; ii<=bound; ii++) putcompobig(disclist,ii,cgetg(1,t_VEC)); for (ii2=1; ii2<=bound; ii2++) { ii = square? ii2*ii2: ii2; if (DEBUGLEVEL>=2 && ii%100==0) { fprintferr("%ld ",ii); flusherr(); } sous=getcompobig(raylist,ii); ly=lg(sous); sousdisc=cgetg(ly,t_VEC); putcompobig(disclist, square? ii2: ii,sousdisc); for (jj=1; jj<ly; jj++) { bidsimp=(GEN)sous[jj]; fa=(GEN)bidsimp[1]; fac=gcopy(fa); fa2=(GEN)fa[1]; ex=(GEN)fa[2]; lfa2=lg(fa2); if (allarch) { clhrayall = (GEN)bidsimp[2]; discall=cgetg(nbarch+1,t_VEC); } else clhray = itos((GEN)bidsimp[2]); for (karch=0; karch<nbarch; karch++) { if (!allarch) ideal = Id; else { kka=karch; nba=0; for (jjj=1; jjj<=r1; jjj++) { if (kka%2) nba++; kka>>=1; } clhray=itos((GEN)clhrayall[karch+1]); for (k2=1,k=1; k<=r1; k++,k2<<=1) { if (karch&k2 && clhray==itos((GEN)clhrayall[karch-k2+1])) { clhray=0; goto LDISCRAY; } } } idealrel = idealrelinit; for (k=1; k<lfa2; k++) { fauxpr=(GEN)fa2[k]; ep=itos((GEN)ex[k]); ffs=itos(fauxpr); /* Hack for NeXTgcc 2.5.8 -- splitting "resp=fs%degk+1" */ fs=ffs/degk; resp=fs%degk; resp++; gprime=stoi((long)(fs/degk)); if (!allarch && nba) { p1=(GEN)primedec(nf,gprime)[ffs%degk+1]; ideal = idealmul(nf,ideal,idealpow(nf,p1,(GEN)ex[k])); } som=0; clhss=0; normp=gpuigs(gprime,resp); normps=itos(normp); normi=ii; normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); no1[1]=(long)gprime; normp[1]=(long)no1; no2=cgetg(2,t_COL); no2[1]=lstoi(resp); normp[2]=(long)no2; for (j=1; j<=ep; j++) { if (clhss==1) som++; else { if (j<ep) { coeff(fac,k,2)=lstoi(ep-j); fad=fac; } else { fad=cgetg(3,t_MAT); fad1=cgetg(lfa2-1,t_COL); fad[1]=(long)fad1; fad2=cgetg(lfa2-1,t_COL); fad[2]=(long)fad2; for (i=1; i<k; i++) { fad1[i]=coeff(fac,i,1); fad2[i]=coeff(fac,i,2); } for ( ; i<lfa2-1; i++) { fad1[i]=coeff(fac,i+1,1); fad2[i]=coeff(fac,i+1,2); } } normi /= normps; /* Hack for NeXTgcc 2.5.8 -- using dlk as temporary variable */ dlk=rayclassnolistessimp(getcompobig(raylist,normi),fad); if (allarch) dlk = (GEN)dlk[karch+1]; clhss = itos(dlk); if (j==1 && clhss==clhray) { clhray=0; coeff(fac,k,2)=ex[k]; goto LDISCRAY; } som += clhss; } } coeff(fac,k,2)=ex[k]; idealrel=factormul(idealrel,factorpow(normp,som)); } dlk=factordivexact(factorpow(factor(stoi(ii)),clhray),idealrel); if (!allarch && nba) { module[1]=(long)ideal; arch2=gcopy(arch); module[2]=(long)arch2; nbdezero=0; for (k=1; k<=r1; k++) { if (signe(arch[k])) { arch2[k]=zero; clhss=itos(rayclassno(bnf,module)); arch2[k]=un; if (clhss==clhray) { clhray=0; goto LDISCRAY; } } else nbdezero++; } } else nbdezero = r1-nba;LDISCRAY: p1=cgetg(4,t_VEC); discall[karch+1]=(long)p1; if (!clhray) p1[1]=p1[2]=p1[3]=zero; else { p3=factorpow(fadkabs,clhray); n=clhray*degk; R1=nbdezero*clhray; if (((n-R1)&3)==2) { normp=cgetg(3,t_MAT); no1=cgetg(2,t_COL); normp[1]=(long)no1; no1[1]=lstoi(-1); no2=cgetg(2,t_COL); normp[2]=(long)no2; no2[1]=un; dlk=factormul(normp,dlk); } p1[1]=lstoi(n); p1[2]=lstoi(R1); p1[3]=(long)factormul(dlk,p3); } } if (allarch) { p1 = cgetg(3,t_VEC); p1[1]=(long)fa; p1[2]=(long)discall; } else { faall[1]=(long)fa; p1 = concatsp(faall, p1); } sousdisc[jj]=(long)p1; if (low_stack(lim, stack_lim(av1,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: discrayabslistarch"); if (DEBUGLEVEL>2) fprintferr("avma = %ld, t(d) = %ld ",avma-bot,taille2(disclist)); tetpil=avma; disclist=gerepile(av1,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } } } if (DEBUGLEVEL>2) msgtimer("discrayabs"); tdi=taille2(disclist); if (DEBUGLEVEL>2) { fprintferr("avma = %ld, t(d) = %ld ",avma-bot,tdi); flusherr(); } if (tdi<avma-bot) { tetpil=avma; disclist=gerepile(av0,tetpil,gcopy(disclist)); if (DEBUGLEVEL>2) { fprintferr("avma = %ld ",avma-bot); flusherr(); } } return disclist;}
dhcp_hostname = NULL;
if (dhcp_hostname != NULL) { dhcp_hostname=bootp_strdup_realloc(dhcp_hostname,0); }
bootpc_init(int update_files){ struct bootp_packet call; struct bootp_packet reply; static u_int32_t xid = ~0xFF; struct ifreq ireq; struct ifnet *ifp; struct socket *so; int j; int error; struct sockaddr_in myaddr; struct ifaddr *ifa; struct sockaddr_dl *sdl = NULL; char *delim; struct proc *procp = NULL; /* * If already filled in, don't touch it here */ if (nfs_diskless_valid) return; /* * If we are to update the files create the root * file structure. */ if (update_files) if (rtems_create_root_fs () < 0) { printf("Error creating the root filesystem.\nFile not created.\n"); update_files = 0; } dhcp_hostname = NULL; /* * Find a network interface. */ for (ifp = ifnet; ifp != 0; ifp = ifp->if_next) if ((ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT)) == 0) break; if (ifp == NULL) panic("bootpc_init: no suitable interface"); bzero(&ireq,sizeof(ireq)); sprintf(ireq.ifr_name, "%s%d", ifp->if_name,ifp->if_unit); printf("bootpc_init: using network interface '%s'\n", ireq.ifr_name); if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp)) != 0) panic("nfs_boot: socreate, error=%d", error); bootpc_fakeup_interface(&ireq,so,procp); printf("Bootpc testing starting\n"); /* Get HW address */ for (ifa = ifp->if_addrlist;ifa; ifa = ifa->ifa_next) if (ifa->ifa_addr->sa_family == AF_LINK && (sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) && sdl->sdl_type == IFT_ETHER) break; if (!sdl) panic("bootpc: Unable to find HW address"); if (sdl->sdl_alen != EALEN ) panic("bootpc: HW address len is %d, expected value is %d", sdl->sdl_alen,EALEN); printf("bootpc hw address is "); delim=""; for (j=0;j<sdl->sdl_alen;j++) { printf("%s%x",delim,((unsigned char *)LLADDR(sdl))[j]); delim=":"; } printf("\n");#if 0 bootpboot_p_iflist(); bootpboot_p_rtlist();#endif bzero((caddr_t) &call, sizeof(call)); /* bootpc part */ call.op = 1; /* BOOTREQUEST */ call.htype= 1; /* 10mb ethernet */ call.hlen=sdl->sdl_alen; /* Hardware address length */ call.hops=0; xid++; call.xid = txdr_unsigned(xid); bcopy(LLADDR(sdl),&call.chaddr,sdl->sdl_alen); call.vend[0]=99; call.vend[1]=130; call.vend[2]=83; call.vend[3]=99; call.vend[4]=255; call.secs = 0; call.flags = htons(0x8000); /* We need an broadcast answer */ error = bootpc_call(&call,&reply,procp); if (error) panic("BOOTP call failed -- error %d", error); /* * Initialize network address structures */ bzero(&myaddr,sizeof(myaddr)); bzero(&dhcp_netmask,sizeof(dhcp_netmask)); bzero(&dhcp_gw,sizeof(dhcp_gw)); myaddr.sin_len = sizeof(myaddr); myaddr.sin_family = AF_INET; dhcp_netmask.sin_len = sizeof(dhcp_netmask); dhcp_netmask.sin_family = AF_INET; dhcp_gw.sin_len = sizeof(dhcp_gw); dhcp_gw.sin_family= AF_INET; /* * Set our address */ myaddr.sin_addr = reply.yiaddr; printip("My ip address",myaddr.sin_addr); /* * Process BOOTP/DHCP options */ if (reply.vend[0]==99 && reply.vend[1]==130 && reply.vend[2]==83 && reply.vend[3]==99) { processOptions (&reply.vend[4], sizeof(reply.vend) - 4); } if (dhcpOptionOverload & 1) { processOptions (reply.file, sizeof reply.file); } else { if (reply.file[0]) rtems_bsdnet_bootp_boot_file_name = bootp_strdup_realloc(rtems_bsdnet_bootp_boot_file_name,reply.file); } if (dhcpOptionOverload & 2) { processOptions (reply.sname, sizeof reply.sname); } else { if (reply.sname[0]) rtems_bsdnet_bootp_server_name = bootp_strdup_realloc(rtems_bsdnet_bootp_server_name,reply.sname); } if (rtems_bsdnet_bootp_server_name) printf ("Server name is %s\n", rtems_bsdnet_bootp_server_name); if (rtems_bsdnet_bootp_boot_file_name) printf ("Boot file is %s\n", rtems_bsdnet_bootp_boot_file_name); if (rtems_bsdnet_bootp_cmdline) printf ("Command line is %s\n", rtems_bsdnet_bootp_cmdline); /* * Use defaults if values were not supplied by BOOTP/DHCP options */ if (!dhcp_gotnetmask) { if (IN_CLASSA(ntohl(myaddr.sin_addr.s_addr))) dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET); else if (IN_CLASSB(ntohl(myaddr.sin_addr.s_addr))) dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET); else dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET); } printip ("Subnet mask", dhcp_netmask.sin_addr); if (!dhcp_gotserver) rtems_bsdnet_bootp_server_address = reply.siaddr; printip ("Server ip address" ,rtems_bsdnet_bootp_server_address); if (!dhcp_gotgw) dhcp_gw.sin_addr = reply.giaddr; printip ("Gateway ip address", dhcp_gw.sin_addr); if (!dhcp_gotlogserver) rtems_bsdnet_log_host_address = rtems_bsdnet_bootp_server_address; printip ("Log server ip address", rtems_bsdnet_log_host_address); /* * Update the files if we are asked too. */ if (update_files) { char *dn = rtems_bsdnet_domain_name; char *hn = dhcp_hostname; if (!dn) dn = "mydomain"; if (!hn) hn = "me"; rtems_rootfs_append_host_rec(*((unsigned long*) &myaddr.sin_addr), hn, dn); /* * Should the given domainname be used here ? */ if (dhcp_gotserver) { if (rtems_bsdnet_bootp_server_name) hn = rtems_bsdnet_bootp_server_name; else hn = "bootps"; rtems_rootfs_append_host_rec(*((unsigned long *) &rtems_bsdnet_bootp_server_address), hn, dn); } if (dhcp_gotlogserver) { rtems_rootfs_append_host_rec(*((unsigned long *) &rtems_bsdnet_log_host_address), "logs", dn); } /* * Setup the DNS configuration file /etc/resolv.conf. */ if (rtems_bsdnet_nameserver_count) { int i; char buf[64]; const char *bufl[1]; bufl[0] = buf; #define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH) if (rtems_bsdnet_domain_name && (strlen(rtems_bsdnet_domain_name) < (sizeof(buf) - 1))) { strcpy(buf, "search "); strcat(buf, rtems_bsdnet_domain_name); strcat(buf, "\n"); rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl); } for (i = 0; i < rtems_bsdnet_nameserver_count; i++) { strcpy(buf, "nameserver "); strcat(buf, inet_ntoa(rtems_bsdnet_ntpserver[i])); strcat(buf, "\n"); if (rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl)) break; } } } /* * Configure the interface with the new settings */ error = bootpc_adjust_interface(&ireq,so, &myaddr,&dhcp_netmask,&dhcp_gw,procp); soclose(so);}
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta)
embedding_of_potential_subfields(GEN g,GEN DATA,GEN rootsA,GEN delta)
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp;
GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind,maxp,p1;
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma;
T = (GEN)DATA[1]; p = (GEN)DATA[2]; maxp = (GEN)DATA[7]; ind = (GEN)DATA[9]; gp = derivpol(g); av = avma;
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
{ GEN p1;
{
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) &&
if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp) > 0) &&
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
struct sockaddr_in *sin,sa;
struct sockaddr_in *sin;
bootpc_call(call,reply,procp) struct bootp_packet *call; struct bootp_packet *reply; /* output */ struct proc *procp;{ struct socket *so; struct sockaddr_in *sin,sa; struct mbuf *m, *nam; struct uio auio; struct iovec aio; int error, rcvflg, timo, secs, len; u_int tport; /* Free at end if not null. */ nam = NULL; /* * Create socket and set its recieve timeout. */ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp))) goto out; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } else { struct timeval *tv; tv = mtod(m, struct timeval *); m->m_len = sizeof(*tv); tv->tv_sec = 1; tv->tv_usec = 0; if ((error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m))) goto out; } /* * Enable broadcast. */ { int *on; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } on = mtod(m, int *); m->m_len = sizeof(*on); *on = 1; if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m))) goto out; } /* * Bind the local endpoint to a bootp client port. */ m = m_getclr(M_WAIT, MT_SONAME); sin = mtod(m, struct sockaddr_in *); sin->sin_len = m->m_len = sizeof(*sin); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(IPPORT_BOOTPC); error = sobind(so, m); m_freem(m); if (error) { printf("bind failed\n"); goto out; } /* * Setup socket address for the server. */ nam = m_get(M_WAIT, MT_SONAME); if (nam == NULL) { error = ENOBUFS; goto out; } sin = mtod(nam, struct sockaddr_in *); sin-> sin_len = sizeof(*sin); sin-> sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_BROADCAST; sin->sin_port = htons(IPPORT_BOOTPS); nam->m_len = sizeof(*sin); /* * Send it, repeatedly, until a reply is received, * but delay each re-send by an increasing amount. * If the delay hits the maximum, start complaining. */ timo = 0; for (;;) { /* Send BOOTP request (or re-send). */ aio.iov_base = (caddr_t) call; aio.iov_len = sizeof(*call); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_offset = 0; auio.uio_resid = sizeof(*call); auio.uio_procp = procp; error = sosend(so, nam, &auio, NULL, NULL, 0); if (error) { printf("bootpc_call: sosend: %d\n", error); goto out; } /* Determine new timeout. */ if (timo < MAX_RESEND_DELAY) timo++; else printf("BOOTP timeout for server 0x%x\n", (int)ntohl(sin->sin_addr.s_addr)); /* * Wait for up to timo seconds for a reply. * The socket receive timeout was set to 1 second. */ secs = timo; while (secs > 0) { aio.iov_base = (caddr_t) reply; aio.iov_len = sizeof(*reply); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_READ; auio.uio_offset = 0; auio.uio_resid = sizeof(*reply); auio.uio_procp = procp; rcvflg = 0; error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg); if (error == EWOULDBLOCK) { secs--; call->secs=htons(ntohs(call->secs)+1); continue; } if (error) goto out; len = sizeof(*reply) - auio.uio_resid; /* Do we have the required number of bytes ? */ if (len < BOOTP_MIN_LEN) continue; /* Is it the right reply? */ if (reply->op != 2) continue; if (reply->xid != call->xid) continue; if (reply->hlen != call->hlen) continue; if (bcmp(reply->chaddr,call->chaddr,call->hlen)) continue; goto gotreply; /* break two levels */ } /* while secs */ } /* forever send/receive */ error = ETIMEDOUT; goto out; gotreply: out: if (nam) m_freem(nam); soclose(so); return error;}
u_int tport;
bootpc_call(call,reply,procp) struct bootp_packet *call; struct bootp_packet *reply; /* output */ struct proc *procp;{ struct socket *so; struct sockaddr_in *sin,sa; struct mbuf *m, *nam; struct uio auio; struct iovec aio; int error, rcvflg, timo, secs, len; u_int tport; /* Free at end if not null. */ nam = NULL; /* * Create socket and set its recieve timeout. */ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp))) goto out; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } else { struct timeval *tv; tv = mtod(m, struct timeval *); m->m_len = sizeof(*tv); tv->tv_sec = 1; tv->tv_usec = 0; if ((error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m))) goto out; } /* * Enable broadcast. */ { int *on; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } on = mtod(m, int *); m->m_len = sizeof(*on); *on = 1; if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m))) goto out; } /* * Bind the local endpoint to a bootp client port. */ m = m_getclr(M_WAIT, MT_SONAME); sin = mtod(m, struct sockaddr_in *); sin->sin_len = m->m_len = sizeof(*sin); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(IPPORT_BOOTPC); error = sobind(so, m); m_freem(m); if (error) { printf("bind failed\n"); goto out; } /* * Setup socket address for the server. */ nam = m_get(M_WAIT, MT_SONAME); if (nam == NULL) { error = ENOBUFS; goto out; } sin = mtod(nam, struct sockaddr_in *); sin-> sin_len = sizeof(*sin); sin-> sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_BROADCAST; sin->sin_port = htons(IPPORT_BOOTPS); nam->m_len = sizeof(*sin); /* * Send it, repeatedly, until a reply is received, * but delay each re-send by an increasing amount. * If the delay hits the maximum, start complaining. */ timo = 0; for (;;) { /* Send BOOTP request (or re-send). */ aio.iov_base = (caddr_t) call; aio.iov_len = sizeof(*call); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_offset = 0; auio.uio_resid = sizeof(*call); auio.uio_procp = procp; error = sosend(so, nam, &auio, NULL, NULL, 0); if (error) { printf("bootpc_call: sosend: %d\n", error); goto out; } /* Determine new timeout. */ if (timo < MAX_RESEND_DELAY) timo++; else printf("BOOTP timeout for server 0x%x\n", (int)ntohl(sin->sin_addr.s_addr)); /* * Wait for up to timo seconds for a reply. * The socket receive timeout was set to 1 second. */ secs = timo; while (secs > 0) { aio.iov_base = (caddr_t) reply; aio.iov_len = sizeof(*reply); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_READ; auio.uio_offset = 0; auio.uio_resid = sizeof(*reply); auio.uio_procp = procp; rcvflg = 0; error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg); if (error == EWOULDBLOCK) { secs--; call->secs=htons(ntohs(call->secs)+1); continue; } if (error) goto out; len = sizeof(*reply) - auio.uio_resid; /* Do we have the required number of bytes ? */ if (len < BOOTP_MIN_LEN) continue; /* Is it the right reply? */ if (reply->op != 2) continue; if (reply->xid != call->xid) continue; if (reply->hlen != call->hlen) continue; if (bcmp(reply->chaddr,call->chaddr,call->hlen)) continue; goto gotreply; /* break two levels */ } /* while secs */ } /* forever send/receive */ error = ETIMEDOUT; goto out; gotreply: out: if (nam) m_freem(nam); soclose(so); return error;}
rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2];
rtems_monitor_command_entry_t *command = table; int max_cmd_len = 0;
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; }
if (command_string && (*command_string != '\0')) { char *argv[2]; argv[0] = command_string; argv[1] = 0; command = rtems_monitor_command_lookup (table, 1, argv); if (command) rtems_monitor_show_help (command, strlen (command_string));
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
{ help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); }
printf ("Unrecognised command; try just 'help'\n"); return; } while (command) { int len = strlen (command->command);
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
if (help) printf("%s\n", help->usage);
if (len > max_cmd_len) max_cmd_len = len; command = command->next; } max_cmd_len++; command = table; while (command) { rtems_monitor_show_help (command, max_cmd_len); command = command->next; }
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
unsigned32 length = 0;
uint32_t length = 0;
rtems_monitor_config_dump( rtems_monitor_config_t *monitor_config, boolean verbose){ unsigned32 length = 0; length = 0; length += printf("WORKSPACE"); length += rtems_monitor_pad(DATACOL, length); length += printf("start: %p; size: 0x%x\n", monitor_config->work_space_start, monitor_config->work_space_size); length = 0; length += printf("TIME"); length += rtems_monitor_pad(DATACOL, length); length += printf("usec/tick: %d; tick/timeslice: %d; tick/sec: %d\n", monitor_config->microseconds_per_tick, monitor_config->ticks_per_timeslice, 1000000 / monitor_config->microseconds_per_tick); length = 0; length += printf("MAXIMUMS"); length += rtems_monitor_pad(DATACOL, length); length += printf("tasks: %d; timers: %d; sems: %d; que's: %d; ext's: %d\n", monitor_config->maximum_tasks, monitor_config->maximum_timers, monitor_config->maximum_semaphores, monitor_config->maximum_message_queues, monitor_config->maximum_extensions); length = 0; length += rtems_monitor_pad(CONTCOL, length); length += printf("partitions: %d; regions: %d; ports: %d; periods: %d\n", monitor_config->maximum_partitions, monitor_config->maximum_regions, monitor_config->maximum_ports, monitor_config->maximum_periods);}
n = negi(n); y = cgetg(3,t_VEC); y[2] = lnegi((GEN)z[2]); y[1] = z[1]; z = y;
z = negsell(z); n = negi(n);
powsell(GEN e, GEN z, GEN n, GEN p){ GEN y; long s=signe(n),i,j; ulong m; if (!s || !z) return NULL; if (s < 0) { n = negi(n); y = cgetg(3,t_VEC); y[2] = lnegi((GEN)z[2]); y[1] = z[1]; z = y; } if (is_pm1(n)) return z; y = NULL; for (i=lgefint(n)-1; i>2; i--) for (m=n[i],j=0; j<BITS_IN_LONG; j++,m>>=1) { if (m&1) y = addsell(e,y,z,p); z = addsell(e,z,z,p); } for (m=n[2]; m>1; m>>=1) { if (m&1) y = addsell(e,y,z,p); z = addsell(e,z,z,p); } return addsell(e,y,z,p);}
for (m = 2; m < gse+k; m++)
for (m = 2; m < (ulong)gse+k; m++)
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
for (m = 5; m <= gse; m++)
for (m = 5; m <= (ulong)gse; m++)
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
for (j = 0; j < m2-64; j+=64)
for (j = 0; (ulong)j < m2-64; j+=64)
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
(m<gse ? XB2 + m2 + j : NULL))
(m<(ulong)gse ? XB2 + m2 + j : NULL))
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
clr_exisr(mask);
ictrl_isr(rtems_vector_number vector,CPU_Interrupt_frame *cpu_frame){ unsigned32 istat, mask, global_vec; int exvec; rtems_isr_entry handler; istat = get_exisr() & get_exier() & PPC_EXI_MASK; /* FIXME: this may be speeded up using cntlzw instruction */ for (exvec = 0;exvec < PPC_IRQ_EXT_MAX;exvec++) { mask = VEC_TO_EXMSK(exvec); if (0 != (istat & mask)) { clr_exisr(mask); handler = ictrl_vector_table[exvec]; if (handler) { istat &= ~mask; global_vec = exvec + PPC_IRQ_EXT_BASE; (handler)(global_vec); } } } if (istat != 0) { /* anything left? then we have a spurious interrupt */ ictrl_spurious_handler(istat,cpu_frame); }}
clr_exisr(mask);
ictrl_isr(rtems_vector_number vector,CPU_Interrupt_frame *cpu_frame){ unsigned32 istat, mask, global_vec; int exvec; rtems_isr_entry handler; istat = get_exisr() & get_exier() & PPC_EXI_MASK; /* FIXME: this may be speeded up using cntlzw instruction */ for (exvec = 0;exvec < PPC_IRQ_EXT_MAX;exvec++) { mask = VEC_TO_EXMSK(exvec); if (0 != (istat & mask)) { clr_exisr(mask); handler = ictrl_vector_table[exvec]; if (handler) { istat &= ~mask; global_vec = exvec + PPC_IRQ_EXT_BASE; (handler)(global_vec); } } } if (istat != 0) { /* anything left? then we have a spurious interrupt */ ictrl_spurious_handler(istat,cpu_frame); }}
case '!': case '#': analyseur++; skiptruc(); return;
case '!': case '#': analyseur++; skipfacteur(); return;
skiptruc(void){ long i,m,n; char *old; switch(*analyseur) { case '"': skipstring(); return; case '!': case '#': analyseur++; skiptruc(); return; case '&': case '\'': analyseur++; check_var_name(); skipentry(); return; } if (isalpha((int)*analyseur)) { skipidentifier(); return; } if (isdigit((int)*analyseur) || *analyseur== '.') { skipconstante(); return; } switch(*analyseur++) { case '(': skipexpr(); match(')'); return; case '[': old = analyseur-1; if (*analyseur == ';' && analyseur[1] == ']') /* [;] */ { analyseur+=2; return; } n = 0; if (*analyseur != ']') { do { n++; skipexpr(); old=analyseur; } while (*analyseur++ == ','); analyseur--; } switch (*analyseur) { case ']': analyseur++; return; case ';': analyseur++; for (m=2; ; m++) { for (i=1; i<n; i++) { skipexpr(); match(','); } skipexpr(); if (*analyseur == ']') break; match(';'); } analyseur++; return; default: err(talker2,"; or ] expected",old,mark.start); } case '%': if (*analyseur == '`') { while (*++analyseur == '`') /*empty*/; return; } number(&n); return; } err(caracer1,analyseur-1,mark.start);}
rtems_unsigned8 umr1, umr2;
uint8_t umr1, umr2;
mcfuart_set_attributes(mcfuart *uart, const struct termios *t){ int level; speed_t baud; rtems_unsigned8 umr1, umr2; baud = cfgetospeed(t); umr1 = 0; umr2 = MCF5206E_UMR2_CM_NORMAL; /* Set flow control */ if ((t->c_cflag & CRTSCTS) != 0) { umr1 |= MCF5206E_UMR1_RXRTS; umr2 |= MCF5206E_UMR2_TXCTS; } /* Set character size */ switch (t->c_cflag & CSIZE) { case CS5: umr1 |= MCF5206E_UMR1_BC_5; break; case CS6: umr1 |= MCF5206E_UMR1_BC_6; break; case CS7: umr1 |= MCF5206E_UMR1_BC_7; break; case CS8: umr1 |= MCF5206E_UMR1_BC_8; break; } /* Set number of stop bits */ if ((t->c_cflag & CSTOPB) != 0) { if ((t->c_cflag & CSIZE) == CS5) { umr2 |= MCF5206E_UMR2_SB5_2; } else { umr2 |= MCF5206E_UMR2_SB_2; } } else { if ((t->c_cflag & CSIZE) == CS5) { umr2 |= MCF5206E_UMR2_SB5_1; } else { umr2 |= MCF5206E_UMR2_SB_1; } } /* Set parity mode */ if ((t->c_cflag & PARENB) != 0) { if ((t->c_cflag & PARODD) != 0) { umr1 |= MCF5206E_UMR1_PM_ODD; } else { umr1 |= MCF5206E_UMR1_PM_EVEN; } } else { umr1 |= MCF5206E_UMR1_PM_NO_PARITY; } rtems_interrupt_disable(level); *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_DISABLE | MCF5206E_UCR_RC_DISABLE; mcfuart_set_baudrate(uart, baud); *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_MISC_RESET_MR; *MCF5206E_UMR(MBAR,uart->chn) = umr1; *MCF5206E_UMR(MBAR,uart->chn) = umr2; if ((t->c_cflag & CREAD) != 0) { *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_ENABLE | MCF5206E_UCR_RC_ENABLE; } else { *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_ENABLE; } rtems_interrupt_enable(level); return RTEMS_SUCCESSFUL;}
int pk,i,j,LE=0;
int pk,pk2,i,j,LE=0;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
GEN tabt,taba,m,E=gzero,p1;
GEN tabt,taba,m,E=gzero,p1,a=gzero,a2=gzero;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
tabcyc[pk] = cyclo(pk,0);
ishack = isinstep5 && ((pk>=lg((GEN)tabcyc)) || ((!signe(tabcyc[pk])))); pk2 = pkfalse; tabcyc[pk2] = cyclo(pk,0);
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1);
for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk2]); tabeta[pk2] = lmul(gmodulcp(gun,N),p1);
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
tabE[pk] = (long)E;
tabE[pk2] = (long)E;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
tabTH[pk] = (long)p1;
tabTH[pk2] = (long)p1;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;
setlg(taba, e); tabaall[pk2] = taba; setlg(tabt, e); tabtall[pk2] = tabt;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
GEN x0 = x+2, z; z = (GEN)x0[0];
GEN x0 = x+2, z = (GEN)x0[0];
spec_FpXQ_pow(GEN x, GEN p, GEN S){ long i, dx = degpol(x); pari_sp av = avma, lim = stack_lim(av, 1); GEN x0 = x+2, z; z = (GEN)x0[0]; if (dx < 0) err(talker, "zero polynomial in FpXQ_pow. %Z not prime", p); for (i = 1; i <= dx; i++) { GEN d, c = (GEN)x0[i]; /* assume coeffs in [0, p-1] */ if (!signe(c)) continue; d = (GEN)S[i]; if (!gcmp1(c)) d = gmul(c,d); z = gadd(z, d); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"spec_FpXQ_pow"); z = gerepileupto(av, z); } } z = FpX_red(z, p); return gerepileupto(av, z);}
z = FpX_red(z, p); return gerepileupto(av, z);
return gerepileupto(av, FpX_red(z, p));
spec_FpXQ_pow(GEN x, GEN p, GEN S){ long i, dx = degpol(x); pari_sp av = avma, lim = stack_lim(av, 1); GEN x0 = x+2, z; z = (GEN)x0[0]; if (dx < 0) err(talker, "zero polynomial in FpXQ_pow. %Z not prime", p); for (i = 1; i <= dx; i++) { GEN d, c = (GEN)x0[i]; /* assume coeffs in [0, p-1] */ if (!signe(c)) continue; d = (GEN)S[i]; if (!gcmp1(c)) d = gmul(c,d); z = gadd(z, d); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"spec_FpXQ_pow"); z = gerepileupto(av, z); } } z = FpX_red(z, p); return gerepileupto(av, z);}
long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m;
long iscol, i, j, k, li, bco, aco = lg(a)-1; ulong piv, invpiv, m; const int OK_ulong = u_OK_ULONG(p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
piv = 0;
piv = invpiv = 0;
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv)
if (OK_ulong) for (k = 1; k < i; k++) coeff(a,k,i) %= p; for (k = i; k <= li; k++)
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL;
piv = ( coeff(a,k,i) %= p ); if (piv) break;
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
piv = coeff(a,i,i);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m)
m = ( coeff(a,k,i) %= p ); if (!m) continue; m = p - mulssmod(m, invpiv, p); if (m == 1)
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); }
for (j=i+1; j<=aco; j++) _u_Fp_add((ulong*)a[j],k,i, p); for (j=1; j<=bco; j++) _u_Fp_add((ulong*)b[j],k,i, p); } else if (OK_ulong) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((ulong*)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((ulong*)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((ulong*)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((ulong*)b[j],k,i,m, p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p);
if (OK_ulong) for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col_OK(a,(GEN)b[j], invpiv, aco, p); else for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j], invpiv, aco, p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
if (maxprime() < a) err(primer1);
if (maxprime() < (ulong)a) err(primer1);
sinitp(long a, long c, byteptr *ptr){ byteptr p = *ptr; if (a <= 0) a = 2; if (maxprime() < a) err(primer1); while (a > c) c += *p++; *ptr = p; return c;}
GEN piv,m,u;
GEN piv, invpiv, m, u;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
piv = NULL;
piv = invpiv = NULL;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv))
for (k = i; k <= li; k++)
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL;
piv = FpX_res(gcoeff(a,k,i), T,p); coeff(a,k,i) = (long)piv; if (signe(piv)) break;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p);
m = gneg( FpXQ_mul(m, invpiv, T,p) );
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
gerepilemany(av,gptr,2);
gerepileall(av, 2, &a,&b);
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p);
for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a, (GEN)b[j], invpiv, aco, T, p);
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
if (!T) return FpM_ker_i(x,p,deplin);
FqM_ker_i(GEN x, GEN T, GEN p, long deplin){ gpmem_t av0,av,lim,tetpil; GEN y,c,d,piv,mun; long i,j,k,r,t,n,m; if (typ(x)!=t_MAT) err(typeer,"FpM_ker"); n=lg(x)-1; if (!n) return cgetg(1,t_MAT); m=lg(x[1])-1; r=0; av0 = avma; x=dummycopy(x); mun=negi(gun); c=new_chunk(m+1); for (k=1; k<=m; k++) c[k]=0; d=new_chunk(n+1); av=avma; lim=stack_lim(av,1); for (k=1; k<=n; k++) { for (j=1; j<=m; j++) if (!c[j]) { coeff(x,j,k) = (long) Fq_res(gcoeff(x,j,k), T, p); if (signe(coeff(x,j,k))) break; } if (j>m) { if (deplin) { c = cgetg(n+1, t_COL); for (i=1; i<k; i++) c[i] = (long)Fq_res(gcoeff(x,d[i],k), T, p); c[k] = un; for (i=k+1; i<=n; i++) c[i] = zero; return gerepileupto(av0, c); } r++; d[k]=0; for(j=1; j<k; j++) if (d[j]) coeff(x,d[j],k) = lclone(gcoeff(x,d[j],k)); } else { c[j]=k; d[k]=j; piv = Fq_neg_inv(gcoeff(x,j,k), T, p); coeff(x,j,k) = (long)mun; for (i=k+1; i<=n; i++) coeff(x,j,i) = (long) Fq_mul(piv,gcoeff(x,j,i), T, p); for (t=1; t<=m; t++) if (t!=j) { piv = Fq_res(gcoeff(x,t,k), T, p); if (signe(piv)) { coeff(x,t,k)=zero; for (i=k+1; i<=n; i++) coeff(x,t,i) = (long)Fq_add(gcoeff(x,t,i),Fq_mul(piv,gcoeff(x,j,i), T, p), T, p); if (low_stack(lim, stack_lim(av,1))) Fq_gerepile_gauss_ker(x,T,p,k,t,av); } } } } if (deplin) { avma = av0; return NULL; } tetpil=avma; y=cgetg(r+1,t_MAT); for (j=k=1; j<=r; j++,k++) { GEN c = cgetg(n+1,t_COL); y[j]=(long)c; while (d[k]) k++; for (i=1; i<k; i++) if (d[i]) { GEN p1=gcoeff(x,d[i],k); c[i] = (long) Fq_res(p1, T, p); gunclone(p1); } else c[i] = zero; c[k]=un; for (i=k+1; i<=n; i++) c[i]=zero; } return gerepile(av0,tetpil,y);}
sqrtu2_1(ulong *a) { double beta = sqrt((double)a[0]); return (ulong)(beta * ((1UL << BITS_IN_HALFULONG) * 0.707106781186547524)); }
sqrtu2_1(ulong *a) { return dblmantissa( sqrt(2. * a[0]) ); }
sqrtu2_1(ulong *a){ double beta = sqrt((double)a[0]); /* 0.707... ~ 1/sqrt(2) */ return (ulong)(beta * ((1UL << BITS_IN_HALFULONG) * 0.707106781186547524));}
if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } }
filtre0(filtre_t *F){ const int downcase = F->downcase; char c, *s = F->s, *t; if (!F->t) F->t = gpmalloc(strlen(s)+1); t = F->t; if (F->more_input == 1) F->more_input = 0; if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } } while ((c = *s++)) { if (F->in_string) { *t++ = c; /* copy verbatim */ switch(c) { case '\\': /* in strings, \ is the escape character */ if (*s) *t++ = *s++; break; case '"': F->in_string = 0; } continue; } if (F->in_comment) { /* look for comment's end */ if (F->in_comment == MULTI_LINE_COMMENT) { while (c != '*' || *s != '/') { if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } c = *s++; } s++; } else while (c != '\n' && *s) c = *s++; F->in_comment = 0; continue; } /* weed out comments and spaces */ if (c=='\\' && *s=='\\') { F->in_comment = ONE_LINE_COMMENT; continue; } if (isspace((int)c)) continue; *t++ = downcase? tolower((int)c): c; switch(c) { case '/': if (*s == '*') { t--; F->in_comment = MULTI_LINE_COMMENT; } break; case '\\': if (!*s) { if (t[-2] == '?') break; /* '?\' */ t--; if (!F->more_input) F->more_input = 1; goto END; } if (*s == '\r') s++; /* DOS */ if (*s == '\n') { if (t[-2] == '?') break; /* '?\' */ t--; s++; if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } } /* skip \<CR> */ break; case ':': if (!compatible && isalpha((int)*s)) { t--; s++; while (is_keyword_char(*s)) { s++; } } break; case '"': F->in_string = 1; } } if (t != F->t) /* non empty input */ { c = t[-1]; /* = last input char */ if (c == '=') F->more_input = 2; else if (! F->wait_for_brace) F->more_input = 0; else if (c == RBRACE) { F->more_input = 0; t--; } }END: F->end = t; *t = 0; return F->t;}
break; case LBRACE: t--; if (F->wait_for_brace) err(impl,"embedded braces (in parser)"); F->more_input = 2; F->wait_for_brace = 1; break;
filtre0(filtre_t *F){ const int downcase = F->downcase; char c, *s = F->s, *t; if (!F->t) F->t = gpmalloc(strlen(s)+1); t = F->t; if (F->more_input == 1) F->more_input = 0; if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } } while ((c = *s++)) { if (F->in_string) { *t++ = c; /* copy verbatim */ switch(c) { case '\\': /* in strings, \ is the escape character */ if (*s) *t++ = *s++; break; case '"': F->in_string = 0; } continue; } if (F->in_comment) { /* look for comment's end */ if (F->in_comment == MULTI_LINE_COMMENT) { while (c != '*' || *s != '/') { if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } c = *s++; } s++; } else while (c != '\n' && *s) c = *s++; F->in_comment = 0; continue; } /* weed out comments and spaces */ if (c=='\\' && *s=='\\') { F->in_comment = ONE_LINE_COMMENT; continue; } if (isspace((int)c)) continue; *t++ = downcase? tolower((int)c): c; switch(c) { case '/': if (*s == '*') { t--; F->in_comment = MULTI_LINE_COMMENT; } break; case '\\': if (!*s) { if (t[-2] == '?') break; /* '?\' */ t--; if (!F->more_input) F->more_input = 1; goto END; } if (*s == '\r') s++; /* DOS */ if (*s == '\n') { if (t[-2] == '?') break; /* '?\' */ t--; s++; if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } } /* skip \<CR> */ break; case ':': if (!compatible && isalpha((int)*s)) { t--; s++; while (is_keyword_char(*s)) { s++; } } break; case '"': F->in_string = 1; } } if (t != F->t) /* non empty input */ { c = t[-1]; /* = last input char */ if (c == '=') F->more_input = 2; else if (! F->wait_for_brace) F->more_input = 0; else if (c == RBRACE) { F->more_input = 0; t--; } }END: F->end = t; *t = 0; return F->t;}
Objects_Name the_name,
unsigned32 the_name,
boolean _Objects_MP_Open ( Objects_Information *information, Objects_Name the_name, Objects_Id the_id, boolean is_fatal_error){ Objects_MP_Control *the_global_object; the_global_object = _Objects_MP_Allocate_global_object(); if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { if ( is_fatal_error == FALSE ) return FALSE; rtems_fatal_error_occurred( RTEMS_TOO_MANY ); } the_global_object->Object.id = the_id; the_global_object->name = the_name; _Chain_Prepend( &information->global_table[ rtems_get_node( the_id ) ], &the_global_object->Object.Node ); return TRUE;}
unsigned32 real_trap; unsigned32 source;
uint32_t real_trap; uint32_t source;
rtems_isr_entry set_vector( /* returns old vector */ rtems_isr_entry handler, /* isr routine */ rtems_vector_number vector, /* vector number */ int type /* RTEMS or RAW intr */){ rtems_isr_entry previous_isr; unsigned32 real_trap; unsigned32 source; if ( type ) rtems_interrupt_catch( handler, vector, &previous_isr ); else _CPU_ISR_install_raw_handler( vector, handler, (void *)&previous_isr ); real_trap = SPARC_REAL_TRAP_NUMBER( vector ); if ( ERC32_Is_MEC_Trap( real_trap ) ) { source = ERC32_TRAP_SOURCE( real_trap ); ERC32_Clear_interrupt( source ); ERC32_Unmask_interrupt( source ); } return previous_isr;}
unsigned32 regno, unsigned32 value
uint32_t regno, uint32_t value
void dmv177_sonic_write_register( void *base, unsigned32 regno, unsigned32 value){ volatile unsigned32 *p = base;#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Write 0x%04x to %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif p[regno] = value;}
volatile unsigned32 *p = base;
volatile uint32_t *p = base;
void dmv177_sonic_write_register( void *base, unsigned32 regno, unsigned32 value){ volatile unsigned32 *p = base;#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Write 0x%04x to %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif p[regno] = value;}
volatile unsigned16 *card_resource_reg; unsigned16 v;
volatile uint16_t *card_resource_reg; uint16_t v;
boolean dmv177_icm7170_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_RTC_INST_MASK; if ( v == DMV170_RTC_INSTALLED ) return TRUE; return FALSE;}
card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG;
card_resource_reg = (volatile uint16_t*) DMV170_CARD_RESORCE_REG;
boolean dmv177_icm7170_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_RTC_INST_MASK; if ( v == DMV170_RTC_INSTALLED ) return TRUE; return FALSE;}
if (DEBUGLEVEL) msgtimer("LLL basis");
initalgall0(GEN x, long flag, long prec){ const gpmem_t av=avma; GEN lead = NULL,nf,ro,bas,mat,rev,dK,dx,index,res; long n,i,r1,r2,ru,PRECREG; if (DEBUGLEVEL) (void)timer2(); if (typ(x)==t_POL) { n=degpol(x); if (n<=0) err(constpoler,"initalgall0"); check_pol_int(x,"initalg"); if (gisirreducible(x) == gzero) err(redpoler,"nfinit"); if (!gcmp1((GEN)x[n+2])) { x = pol_to_monic(x,&lead); if (!(flag & nf_SMALL)) { if (!(flag & nf_REDUCE)) err(warner,"non-monic polynomial. Result of the form [nf,c]"); flag = flag | nf_REDUCE | nf_ORIG; } } bas = allbase4(x,0,&dK,NULL); if (DEBUGLEVEL) msgtimer("round4"); dx = ZX_disc(x); r1 = sturm(x); } else { i = lg(x); if (typ(x) == t_VEC && i==3 && typ(x[1])==t_POL) { /* polynomial + integer basis */ bas=(GEN)x[2]; x=(GEN)x[1]; n=degpol(x); if (typ(bas) == t_MAT) { mat = bas; bas = mat_to_vecpol(mat,varn(x)); } else mat = vecpol_to_mat(bas,n); dx = ZX_disc(x); r1 = sturm(x); dK = gmul(dx, gsqr(det2(mat))); } else { nf=checknf(x); bas=(GEN)nf[7]; x=(GEN)nf[1]; n=degpol(x); dK=(GEN)nf[3]; dx=mulii(dK, sqri((GEN)nf[4])); r1 = nf_get_r1(nf); } bas[1]=lpolun[varn(x)]; /* it may be gun => SEGV later */ } r2=(n-r1)>>1; ru=r1+r2; PRECREG = prec + (expi(dK)>>(TWOPOTBITS_IN_LONG+1)) + (long)((sqrt((double)n)+3) / sizeof(long) * 4); rev = NULL; if (flag & nf_REDUCE) { nfinit_reduce(flag, &x, &dx, &rev, &bas, prec); if (DEBUGLEVEL) msgtimer("polred"); } if (!carrecomplet(divii(dx,dK),&index)) err(bugparier,"nfinit (incorrect discriminant)"); ro=get_roots(x,r1,PRECREG); if (DEBUGLEVEL) msgtimer("roots"); bas = gmul(bas, LLL_nfbasis(x,ro,bas,prec)); nf=cgetg(10,t_VEC); nf[1]=(long)x; nf[2]=lgetg(3,t_VEC); mael(nf,2,1)=lstoi(r1); mael(nf,2,2)=lstoi(r2); nf[3]=(long)dK; nf[4]=(long)index; nf[6]=(long)ro; nf[7]=(long)bas; get_nf_matrices(nf, flag & nf_SMALL); if (flag & nf_ORIG) { if (!rev) err(talker,"bad flag in initalgall0"); res = cgetg(3,t_VEC); res[1]=(long)nf; nf = res; res[2]=lead? ldiv(rev,lead): (long)rev; } return gerepilecopy(av, nf);}
unsigned32 dmv177_sonic_read_register(
uint32_t dmv177_sonic_read_register(
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
unsigned32 regno
uint32_t regno
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
volatile unsigned32 *p = base; unsigned32 value;
volatile uint32_t *p = base; uint32_t value;
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
volatile unsigned16 *card_resource_reg; unsigned16 v;
volatile uint16_t *card_resource_reg; uint16_t v;
boolean dmv177_mc68681_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_DUART_INST_MASK; if ( v == DMV170_DUART_INSTALLED ) return TRUE; return FALSE;}
card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG;
card_resource_reg = (volatile uint16_t*) DMV170_CARD_RESORCE_REG;
boolean dmv177_mc68681_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_DUART_INST_MASK; if ( v == DMV170_DUART_INSTALLED ) return TRUE; return FALSE;}
char token[ NAME_MAX + 1 ];
char token[ IMFS_NAME_MAX + 1 ];
int IMFS_evaluate_for_make( const char *path, /* IN */ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ const char **name /* OUT */){ int i = 0; int len; IMFS_token_types type; char token[ NAME_MAX + 1 ]; rtems_filesystem_location_info_t newloc; IMFS_jnode_t *node; int done = 0; int result; /* * This was filled in by the caller and is valid in the * mount table. */ node = pathloc->node_access; /* * Evaluate all tokens until we are done or an error occurs. */ while( !done ) { type = IMFS_get_token( &path[i], token, &len ); i += len; if ( !pathloc->node_access ) set_errno_and_return_minus_one( ENOENT ); /* * I cannot move out of this directory without execute permission. */ if ( type != IMFS_NO_MORE_PATH ) if ( node->type == IMFS_DIRECTORY ) if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) set_errno_and_return_minus_one( EACCES ); node = pathloc->node_access; switch( type ) { case IMFS_UP_DIR: /* * Am I at the root of this mounted filesystem? */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access){ /* * Am I at the root of all filesystems? */ if ( pathloc->node_access == rtems_filesystem_root.node_access ) { break; } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalformake)( &path[i-len], pathloc, name ); } } else { if ( !node->Parent ) set_errno_and_return_minus_one( ENOENT ); node = node->Parent; } pathloc->node_access = node; break; case IMFS_NAME: if ( node->type == IMFS_HARD_LINK ) { result = IMFS_evaluate_link( pathloc, 0 ); if ( result == -1 ) return -1; } else if ( node->type == IMFS_SYM_LINK ) { result = IMFS_evaluate_link( pathloc, 0 ); if ( result == -1 ) return -1; } node = pathloc->node_access; if ( !node ) set_errno_and_return_minus_one( ENOTDIR ); /* * Only a directory can be decended into. */ if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * If we are at a node that is a mount point. Set loc to the * new fs root node and let them finish evaluating the path. */ if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; return (*pathloc->ops->evalformake)( &path[i-len], pathloc, name ); } /* * Otherwise find the token name in the present location. */ node = IMFS_find_match_in_dir( node, token ); /* * If there is no node we have found the name of the node we * wish to create. */ if ( ! node ) done = TRUE; else pathloc->node_access = node; break; case IMFS_NO_MORE_PATH: set_errno_and_return_minus_one( EEXIST ); break; case IMFS_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; case IMFS_CURRENT_DIR: break; } } *name = &path[ i - len ]; /* * We have evaluated the path as far as we can. * Verify there is not any invalid stuff at the end of the name. */ for( ; path[i] != '\0'; i++) { if ( !IMFS_is_separator( path[ i ] ) ) set_errno_and_return_minus_one( ENOENT ); } /* * Verify we can execute and write to this directory. */ result = IMFS_Set_handlers( pathloc ); /* * The returned node must be a directory */ node = pathloc->node_access; if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * We must have Write and execute permission on the returned node. */ if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_WX ) ) set_errno_and_return_minus_one( EACCES ); return result;}
char token[ NAME_MAX + 1 ];
char token[ IMFS_NAME_MAX + 1 ];
int IMFS_eval_path( const char *pathname, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */){ int i = 0; int len; IMFS_token_types type = IMFS_CURRENT_DIR; char token[ NAME_MAX + 1 ]; rtems_filesystem_location_info_t newloc; IMFS_jnode_t *node; int result; if ( !rtems_libio_is_valid_perms( flags ) ) { assert( 0 ); set_errno_and_return_minus_one( EIO ); } /* * This was filled in by the caller and is valid in the * mount table. */ node = pathloc->node_access; /* * Evaluate all tokens until we are done or an error occurs. */ while( (type != IMFS_NO_MORE_PATH) && (type != IMFS_INVALID_TOKEN) ) { type = IMFS_get_token( &pathname[i], token, &len ); i += len; if ( !pathloc->node_access ) set_errno_and_return_minus_one( ENOENT ); /* * I cannot move out of this directory without execute permission. */ if ( type != IMFS_NO_MORE_PATH ) if ( node->type == IMFS_DIRECTORY ) if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) set_errno_and_return_minus_one( EACCES ); node = pathloc->node_access; switch( type ) { case IMFS_UP_DIR: /* * Am I at the root of this mounted filesystem? */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) { /* * Am I at the root of all filesystems? */ if ( pathloc->node_access == rtems_filesystem_root.node_access ) { break; /* Throw out the .. in this case */ } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalpath)(&(pathname[i-len]),flags,pathloc); } } else { if ( !node->Parent ) set_errno_and_return_minus_one( ENOENT ); node = node->Parent; pathloc->node_access = node; } pathloc->node_access = node; break; case IMFS_NAME: /* * If we are at a link follow it. */ if ( node->type == IMFS_HARD_LINK ) { IMFS_evaluate_hard_link( pathloc, 0 ); node = pathloc->node_access; if ( !node ) set_errno_and_return_minus_one( ENOTDIR ); } else if ( node->type == IMFS_SYM_LINK ) { result = IMFS_evaluate_sym_link( pathloc, 0 ); node = pathloc->node_access; if ( result == -1 ) return -1; } /* * Only a directory can be decended into. */ if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * If we are at a node that is a mount point. Set loc to the * new fs root node and let them finish evaluating the path. */ if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; return (*pathloc->ops->evalpath)( &pathname[i-len], flags, pathloc ); } /* * Otherwise find the token name in the present location. */ node = IMFS_find_match_in_dir( node, token ); if ( !node ) set_errno_and_return_minus_one( ENOENT ); /* * Set the node access to the point we have found. */ pathloc->node_access = node; break; case IMFS_NO_MORE_PATH: case IMFS_CURRENT_DIR: break; case IMFS_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; } } /* * Only return root node if this is the base file system. */ if ((pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) && (pathloc->node_access != rtems_filesystem_root.node_access) ) { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; } result = IMFS_Set_handlers( pathloc ); /* * Verify we have the correct permissions for this node. */ if ( !IMFS_evaluate_permission( pathloc, flags ) ) set_errno_and_return_minus_one( EACCES ); return result;}
GEN ishiftr_spec(GEN x, long lx, long n) {
ishiftr_spec(GEN x, long lx, long n) {
GEN ishiftr_spec(GEN x, long lx, long n){ /*This is a kludge since x is not an integer*/ return shifti_spec(x, lx, n);}
if (gcmp0(FpC_Fp_mul(gel(vecMsup,i), X, ell))) return 0;
if (gcmp0(FpM_FpC_mul(gel(vecMsup,i),X, ell))) return 0;
ok_congruence(GEN X, GEN ell, long lW, GEN vecMsup){ long i, l; if (gcmp0(X)) return 0; l = lg(X); for (i=lW; i<l; i++) if (gcmp0(gel(X,i))) return 0; l = lg(vecMsup); for (i=1; i<l; i++) if (gcmp0(FpC_Fp_mul(gel(vecMsup,i), X, ell))) return 0; return 1;}
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q)
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN modpr,GEN q)
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1];
GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)modpr[1];
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
x = lift_intern(nfreducemodpr(nf,x,prhall));
x = lift_intern(nfreducemodpr(nf,x,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
g0inv = lift_intern(element_invmodpr(nf,g0,prhall));
g0inv = lift_intern(element_invmodpr(nf,g0,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
giant=lift_intern(element_divmodpr(nf,x,p1,prhall));
giant=lift_intern(element_divmodpr(nf,x,p1,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
GEN pr, C0, C, dk, bad, polbase, pk, init_fa;
GEN pr, C0, C, dk, bad, polbase, pk, init_fa = NULL;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
GEN list, r = NULL;
GEN list, r = NULL, fa = NULL;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap);
anbf = fl? FqX_split_deg1(&fa, red, q, aT, ap) : FqX_split_by_degree(&fa, red, q, aT, ap);
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
L.Tp = aT;
L.Tp = aT; init_fa = fa;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
res[2] = (long)_vec(T->fact);
res[2] = (long)T->fact;
nfcmbf(nfcmbf_t *T, GEN p, long a, long maxK, long klim){ long Sbound; GEN pol = T->pol, nf = T->nf, famod = T->fact, dn = T->dn; GEN bound = T->bound; GEN nfpol = (GEN)nf[1]; long K = 1, cnt = 1, i,j,k, curdeg, lfamod = lg(famod)-1, dnf = degpol(nfpol); GEN res = cgetg(3, t_VEC); pari_sp av0 = avma; GEN pk = gpowgs(p,a), pks2 = shifti(pk,-1); GEN trace1 = cgetg(lfamod+1, t_MAT); GEN trace2 = cgetg(lfamod+1, t_MAT); GEN ind = cgetg(lfamod+1, t_VECSMALL); GEN degpol = cgetg(lfamod+1, t_VECSMALL); GEN degsofar = cgetg(lfamod+1, t_VECSMALL); GEN listmod = cgetg(lfamod+1, t_COL); GEN fa = cgetg(lfamod+1, t_COL); GEN q = ceil_safe(mpsqrt(T->BS_2)); GEN lc = absi(leading_term(pol)), lt = is_pm1(lc)? NULL: lc; GEN C2ltpol, C = T->L->topowden, Tpk = T->L->Tpk; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); const double Bhigh = get_Bhigh(lfamod, dnf); trace_data _T1, _T2, *T1, *T2; pari_timer ti; TIMERstart(&ti); if (maxK < 0) maxK = lfamod-1; C2ltpol = C2lt? gmul(C2lt,pol): pol; { GEN t1,t2, ltdn, lt2dn; ltdn = mul_content(lt, dn); lt2dn= mul_content(ltdn, lt); for (i=1; i <= lfamod; i++) { GEN P = (GEN)famod[i]; long d = degpol(P); degpol[i] = d; P += 2; t1 = (GEN)P[d-1];/* = - S_1 */ t2 = gsqr(t1); if (d > 1) t2 = gsub(t2, gmul2n((GEN)P[d-2], 1)); t2 = Tpk? FpX_rem(t2, Tpk, pk): modii(t2, pk); /* = S_2 Newton sum */ if (lt) { t1 = FpX_red(gmul(ltdn, t1), pk); t2 = FpX_red(gmul(lt2dn,t2), pk); } trace1[i] = (long)nf_bestlift(t1, NULL, T->L); trace2[i] = (long)nf_bestlift(t2, NULL, T->L); } T1 = init_trace(&_T1, trace1, T->L, q); T2 = init_trace(&_T2, trace2, T->L, q); } degsofar[0] = 0; /* sentinel */ /* ind runs through strictly increasing sequences of length K, * 1 <= ind[i] <= lfamod */nextK: if (K > maxK || 2*K > lfamod) goto END; if (DEBUGLEVEL > 3) fprintferr("\n### K = %d, %Z combinations\n", K,binome(stoi(lfamod), K)); setlg(ind, K+1); ind[1] = 1; Sbound = ((K+1)>>1); i = 1; curdeg = degpol[ind[1]]; for(;;) { /* try all combinations of K factors */ for (j = i; j < K; j++) { degsofar[j] = curdeg; ind[j+1] = ind[j]+1; curdeg += degpol[ind[j+1]]; } if (curdeg <= klim && curdeg % T->hint == 0) /* trial divide */ { GEN t, y, q, list; pari_sp av; av = avma; /* d - 1 test */ if (T1) { t = get_trace(ind, T1); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>6) fprintferr("."); avma = av; goto NEXT; } } /* d - 2 test */ if (T2) { t = get_trace(ind, T2); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>3) fprintferr("|"); avma = av; goto NEXT; } } avma = av; y = lt; /* full computation */ for (i=1; i<=K; i++) { GEN q = (GEN)famod[ind[i]]; if (y) q = gmul(y, q); y = FqX_centermod(q, Tpk, pk, pks2); } y = nf_pol_lift(y, bound, T); if (!y) { if (DEBUGLEVEL>3) fprintferr("@"); avma = av; goto NEXT; } /* try out the new combination: y is the candidate factor */ q = RXQX_divrem(C2ltpol, y, nfpol, ONLY_DIVIDES); if (!q) { if (DEBUGLEVEL>3) fprintferr("*"); avma = av; goto NEXT; } /* found a factor */ list = cgetg(K+1, t_VEC); listmod[cnt] = (long)list; for (i=1; i<=K; i++) list[i] = famod[ind[i]]; y = Q_primpart(y); fa[cnt++] = (long)QXQ_normalize(y, nfpol); /* fix up pol */ pol = q; for (i=j=k=1; i <= lfamod; i++) { /* remove used factors */ if (j <= K && i == ind[j]) j++; else { famod[k] = famod[i]; update_trace(T1, k, i); update_trace(T2, k, i); degpol[k] = degpol[i]; k++; } } lfamod -= K; if (lfamod < 2*K) goto END; i = 1; curdeg = degpol[ind[1]]; if (C2lt) pol = Q_primpart(pol); if (lt) lt = absi(leading_term(pol)); Clt = mul_content(C, lt); C2lt = mul_content(C,Clt); C2ltpol = C2lt? gmul(C2lt,pol): pol; if (DEBUGLEVEL > 2) { fprintferr("\n"); msgTIMER(&ti, "to find factor %Z",y); fprintferr("remaining modular factor(s): %ld\n", lfamod); } continue; }NEXT: for (i = K+1;;) { if (--i == 0) { K++; goto nextK; } if (++ind[i] <= lfamod - K + i) { curdeg = degsofar[i-1] + degpol[ind[i]]; if (curdeg <= klim) break; } } }END: if (degpol(pol) > 0) { /* leftover factor */ if (signe(leading_term(pol)) < 0) pol = gneg_i(pol); if (C2lt && lfamod < 2*K) pol = QXQ_normalize(Q_primpart(pol), nfpol); setlg(famod, lfamod+1); listmod[cnt] = (long)dummycopy(famod); fa[cnt++] = (long)pol; } if (DEBUGLEVEL>6) fprintferr("\n"); if (cnt == 2) { avma = av0; res[1] = (long)_vec(T->pol); res[2] = (long)_vec(T->fact); } else { setlg(listmod, cnt); setlg(fa, cnt); res[1] = (long)fa; res[2] = (long)listmod; gerepilecopy(av0, res); } return res;}
gerepilecopy(av0, res);
res = gerepilecopy(av0, res);
nfcmbf(nfcmbf_t *T, GEN p, long a, long maxK, long klim){ long Sbound; GEN pol = T->pol, nf = T->nf, famod = T->fact, dn = T->dn; GEN bound = T->bound; GEN nfpol = (GEN)nf[1]; long K = 1, cnt = 1, i,j,k, curdeg, lfamod = lg(famod)-1, dnf = degpol(nfpol); GEN res = cgetg(3, t_VEC); pari_sp av0 = avma; GEN pk = gpowgs(p,a), pks2 = shifti(pk,-1); GEN trace1 = cgetg(lfamod+1, t_MAT); GEN trace2 = cgetg(lfamod+1, t_MAT); GEN ind = cgetg(lfamod+1, t_VECSMALL); GEN degpol = cgetg(lfamod+1, t_VECSMALL); GEN degsofar = cgetg(lfamod+1, t_VECSMALL); GEN listmod = cgetg(lfamod+1, t_COL); GEN fa = cgetg(lfamod+1, t_COL); GEN q = ceil_safe(mpsqrt(T->BS_2)); GEN lc = absi(leading_term(pol)), lt = is_pm1(lc)? NULL: lc; GEN C2ltpol, C = T->L->topowden, Tpk = T->L->Tpk; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); const double Bhigh = get_Bhigh(lfamod, dnf); trace_data _T1, _T2, *T1, *T2; pari_timer ti; TIMERstart(&ti); if (maxK < 0) maxK = lfamod-1; C2ltpol = C2lt? gmul(C2lt,pol): pol; { GEN t1,t2, ltdn, lt2dn; ltdn = mul_content(lt, dn); lt2dn= mul_content(ltdn, lt); for (i=1; i <= lfamod; i++) { GEN P = (GEN)famod[i]; long d = degpol(P); degpol[i] = d; P += 2; t1 = (GEN)P[d-1];/* = - S_1 */ t2 = gsqr(t1); if (d > 1) t2 = gsub(t2, gmul2n((GEN)P[d-2], 1)); t2 = Tpk? FpX_rem(t2, Tpk, pk): modii(t2, pk); /* = S_2 Newton sum */ if (lt) { t1 = FpX_red(gmul(ltdn, t1), pk); t2 = FpX_red(gmul(lt2dn,t2), pk); } trace1[i] = (long)nf_bestlift(t1, NULL, T->L); trace2[i] = (long)nf_bestlift(t2, NULL, T->L); } T1 = init_trace(&_T1, trace1, T->L, q); T2 = init_trace(&_T2, trace2, T->L, q); } degsofar[0] = 0; /* sentinel */ /* ind runs through strictly increasing sequences of length K, * 1 <= ind[i] <= lfamod */nextK: if (K > maxK || 2*K > lfamod) goto END; if (DEBUGLEVEL > 3) fprintferr("\n### K = %d, %Z combinations\n", K,binome(stoi(lfamod), K)); setlg(ind, K+1); ind[1] = 1; Sbound = ((K+1)>>1); i = 1; curdeg = degpol[ind[1]]; for(;;) { /* try all combinations of K factors */ for (j = i; j < K; j++) { degsofar[j] = curdeg; ind[j+1] = ind[j]+1; curdeg += degpol[ind[j+1]]; } if (curdeg <= klim && curdeg % T->hint == 0) /* trial divide */ { GEN t, y, q, list; pari_sp av; av = avma; /* d - 1 test */ if (T1) { t = get_trace(ind, T1); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>6) fprintferr("."); avma = av; goto NEXT; } } /* d - 2 test */ if (T2) { t = get_trace(ind, T2); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>3) fprintferr("|"); avma = av; goto NEXT; } } avma = av; y = lt; /* full computation */ for (i=1; i<=K; i++) { GEN q = (GEN)famod[ind[i]]; if (y) q = gmul(y, q); y = FqX_centermod(q, Tpk, pk, pks2); } y = nf_pol_lift(y, bound, T); if (!y) { if (DEBUGLEVEL>3) fprintferr("@"); avma = av; goto NEXT; } /* try out the new combination: y is the candidate factor */ q = RXQX_divrem(C2ltpol, y, nfpol, ONLY_DIVIDES); if (!q) { if (DEBUGLEVEL>3) fprintferr("*"); avma = av; goto NEXT; } /* found a factor */ list = cgetg(K+1, t_VEC); listmod[cnt] = (long)list; for (i=1; i<=K; i++) list[i] = famod[ind[i]]; y = Q_primpart(y); fa[cnt++] = (long)QXQ_normalize(y, nfpol); /* fix up pol */ pol = q; for (i=j=k=1; i <= lfamod; i++) { /* remove used factors */ if (j <= K && i == ind[j]) j++; else { famod[k] = famod[i]; update_trace(T1, k, i); update_trace(T2, k, i); degpol[k] = degpol[i]; k++; } } lfamod -= K; if (lfamod < 2*K) goto END; i = 1; curdeg = degpol[ind[1]]; if (C2lt) pol = Q_primpart(pol); if (lt) lt = absi(leading_term(pol)); Clt = mul_content(C, lt); C2lt = mul_content(C,Clt); C2ltpol = C2lt? gmul(C2lt,pol): pol; if (DEBUGLEVEL > 2) { fprintferr("\n"); msgTIMER(&ti, "to find factor %Z",y); fprintferr("remaining modular factor(s): %ld\n", lfamod); } continue; }NEXT: for (i = K+1;;) { if (--i == 0) { K++; goto nextK; } if (++ind[i] <= lfamod - K + i) { curdeg = degsofar[i-1] + degpol[ind[i]]; if (curdeg <= klim) break; } } }END: if (degpol(pol) > 0) { /* leftover factor */ if (signe(leading_term(pol)) < 0) pol = gneg_i(pol); if (C2lt && lfamod < 2*K) pol = QXQ_normalize(Q_primpart(pol), nfpol); setlg(famod, lfamod+1); listmod[cnt] = (long)dummycopy(famod); fa[cnt++] = (long)pol; } if (DEBUGLEVEL>6) fprintferr("\n"); if (cnt == 2) { avma = av0; res[1] = (long)_vec(T->pol); res[2] = (long)_vec(T->fact); } else { setlg(listmod, cnt); setlg(fa, cnt); res[1] = (long)fa; res[2] = (long)listmod; gerepilecopy(av0, res); } return res;}
GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5;
GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst, Z; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 10;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
if (!B) B = N;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0));
fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(Z));
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0)));
fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, Z)));
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
if (cmpii(nsp, mulsi(bnd, N0)) < 0) break;
if (cmpii(nsp, mulsi(bnd, Z)) < 0) break;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
bnd = itos(divii(nsp, N0)) + 1;
bnd = itos(divii(nsp, Z)) + 1;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
if (i < bnd) R[2] = (long)addii((GEN)R[2], N0);
if (i < bnd) R[2] = (long)addii((GEN)R[2], Z);
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
return gerepileupto(av, gcopy(y));
return gerepilecopy(av, y);
zidealstarinitall(GEN nf, GEN ideal,long add_gen){ long av = avma,i,j,k,nba,nbp,R1,nbgen,cp; GEN p1,y,h,cyc,U,u1,fa,fa2,ep,x,arch,list,sarch,gen; nf = checknf(nf); R1=itos(gmael(nf,2,1)); if (typ(ideal)==t_VEC && lg(ideal)==3) { arch=(GEN)ideal[2]; ideal = (GEN)ideal[1]; i = typ(arch); if (!is_vec_t(i) || lg(arch) != R1+1) err(talker,"incorrect archimedean component in zidealstarinit"); for (nba=0,i=1; i<=R1; i++) if (signe(arch[i])) nba++; } else { arch=cgetg(R1+1,t_VEC); for (nba=0,i=1; i<=R1; i++) arch[i]=zero; } x = idealhermite(nf,ideal); if (!gcmp1(denom(x))) err(talker,"zidealstarinit needs an integral ideal: %Z",x); p1=cgetg(3,t_VEC); ideal=p1; p1[1]=(long)x; p1[2]=(long)arch; fa=idealfactor(nf,x); list=(GEN)fa[1]; ep=(GEN)fa[2]; nbp=lg(list)-1; fa2=cgetg(nbp+2,t_VEC); gen = cgetg(1,t_VEC); p1 = (nbp==1)? (GEN)NULL: x; for (i=1; i<=nbp; i++) { GEN L = zprimestar(nf,(GEN)list[i],(GEN)ep[i],p1,arch); fa2[i] = (long)L; for (j=1; j<lg(L); j++) gen = concatsp(gen,gmael(L,j,3)); } sarch = zarchstar(nf,x,arch,nba); fa2[i]=(long)sarch; gen = concatsp(gen,(GEN)sarch[2]); nbgen = lg(gen)-1; h=cgetg(nbgen+1,t_MAT); cp=0; for (i=1; i<=nbp; i++) { list = (GEN)fa2[i]; for (j=1; j<lg(list); j++) { GEN a, L = (GEN)list[j], e = (GEN)L[1], g = (GEN)L[3]; for (k=1; k<lg(g); k++) { a = element_powmodidele(nf,(GEN)g[k],(GEN)e[k],ideal,sarch); h[++cp] = lneg(zinternallog(nf,a,fa2,nbgen,arch,fa,i)); coeff(h,cp,cp) = e[k]; } } } for (j=1; j<=nba; j++) { h[++cp]=(long)zerocol(nbgen); coeff(h,cp,cp)=deux; } if (cp!=nbgen) err(talker,"bug in zidealstarinit"); h = hnfall_i(h,NULL,0); cyc = smithrel(h, &U, add_gen? &u1: NULL); p1 = cgetg(add_gen? 4: 3, t_VEC); p1[1] = (long)detcyc(cyc); p1[2] = (long)cyc; y = cgetg(6,t_VEC); y[1] = (long)ideal; y[2] = (long)p1; y[3] = (long)fa; y[4] = (long)fa2; y[5] = (long)U; if (add_gen) p1[3] = (long)compute_gen(nf,u1,gen, y); return gerepileupto(av, gcopy(y));}
if (*xl != ~uzero) {
if ((ulong)*xl != ~uzero) {
incdec(GEN x, long incdec){ long *xf = x + 2, *xl; long len = lgefint(x); const ulong uzero = 0; xl = x + len; if (incdec == 1) { while (--xl >= xf) { if (*xl != ~uzero) { (*xl)++; return 0; } *xl = 0; } return 1; } else { while (--xl >= xf) { if (*xl != 0) { (*xl)--; return 0; } *xl = (long)~uzero; } return 0; }}
if (gcmp0(x)) return ggamma(a,prec);
incgam(GEN a, GEN x, long prec){ GEN p1,z = cgetr(prec); long av = avma; if (typ(x)!=t_REAL) { gaffect(x,z); x=z; } if (gcmp(subrs(x,1),a) > 0 || gsigne(greal(a)) <= 0) p1 = incgam2(a,x,prec); else p1 = gsub(ggamma(a,prec), incgam3(a,x,prec)); affrr(p1,z); avma = av; return z;}