rem
stringlengths
0
274k
add
stringlengths
0
169k
context
stringlengths
9
471k
p=cgetr(prec); gaffect(ginv(a),p); a=p; p=cgetr(prec); gaffect(ginv(b),p); b=p;
a = fix(ginv(a), prec); b = fix(ginv(b), prec);
qromi(entree *ep, GEN a, GEN b, char *ch, long prec){ GEN ss,dss,s,h,q1,p1,p,qlint,del,ddel,x,sum; long av = avma, av1,tetpil,j,j1,j2,lim,it,sig; p=cgetr(prec); gaffect(ginv(a),p); a=p; p=cgetr(prec); gaffect(ginv(b),p); b=p; qlint=subrr(b,a); sig= -signe(qlint); if (!sig) { avma=av; return gzero; } if (sig>0) { setsigne(qlint,1); s=a; a=b; b=s; } s=new_chunk(JMAXP); h=new_chunk(JMAXP); h[0] = (long)realun(prec); x=divsr(2,addrr(a,b)); push_val(ep, x); p1=gmul(lisexpr(ch),mulrr(x,x)); s[0]=lmul(qlint,p1); for (it=1,j=1; j<JMAX; j++, it*=3) { h[j] = ldivrs((GEN)h[j-1],9); av1=avma; del=divrs(qlint,3*it); ddel=shiftr(del,1); x=addrr(a,shiftr(del,-1)); sum=gzero; for (j1=1; j1<=it; j1++) { q1 = ginv(x); ep->value = (void*)q1; p1=gmul(lisexpr(ch), gsqr(q1)); sum=gadd(sum,p1); x=addrr(x,ddel); q1 = ginv(x); ep->value = (void*)q1; p1=gmul(lisexpr(ch), gsqr(q1)); sum=gadd(sum,p1); x=addrr(x,del); } sum = gmul(sum,del); p1 = gdivgs((GEN)s[j-1],3); tetpil=avma; s[j]=lpile(av1,tetpil,gadd(p1,sum)); if (j>=KLOC) { tetpil=avma; ss=polint_i(h+j-KLOC,s+j-KLOC,gzero,KLOC+1,&dss); j1=gexpo(ss); j2=gexpo(dss); lim=bit_accuracy(prec)-(3*j/2)-6; if (j1-j2 > lim || j1 < -lim) { pop_val(ep); if (gcmp0(gimag(ss))) ss=greal(ss); tetpil=avma; return gerepile(av,tetpil,gmulsg(sig,ss)); } } } err(intger2); return NULL; /* not reached */}
for (i=1; i<lv; i++) tabE[i] = tabTH[i] = tabeta[i] = zero;
inittabs(int lv){ int i; tabaall = (GEN*)cgetg(lv,t_VECSMALL); tabtall = (GEN*)cgetg(lv,t_VECSMALL); tabcyc = (GEN*)cgetg(lv,t_VEC); tabE = cgetg(lv,t_VEC); tabTH= cgetg(lv,t_VEC); tabeta=cgetg(lv,t_VEC); sgt = cgetg(lv,t_VECSMALL); ctsgt= cgetg(lv,t_VECSMALL); for (i=1; i<lv; i++) sgt[i] = ctsgt[i] = 0;}
&IMFS_linearfile_handlers,
int IMFS_initialize( rtems_filesystem_mount_table_entry_t *temp_mt_entry){ IMFS_initialize_support( temp_mt_entry, &IMFS_ops, &IMFS_memfile_handlers, &IMFS_directory_handlers ); return 0;}
long i,lx,vx,av,tetpil, tx = typ(x);
ulong av,tetpil, tx = typ(x); long i,lx,vx;
chinois(GEN x, GEN y){ long i,lx,vx,av,tetpil, tx = typ(x); GEN z,p1,p2,d,u,v; if (gegal(x,y)) return gcopy(x); if (tx == typ(y)) switch(tx) { case t_POLMOD: if (gegal((GEN)x[1],(GEN)y[1])) /* same modulus */ { z=cgetg(3,tx); z[1]=lcopy((GEN)x[1]); z[2]=(long)chinois((GEN)x[2],(GEN)y[2]); return z; } /* fall through */ case t_INTMOD: z=cgetg(3,tx); av=avma; d=gbezout((GEN)x[1],(GEN)y[1],&u,&v); if (!gegal(gmod((GEN)x[2],d), gmod((GEN)y[2],d))) break; p1 = gdiv((GEN)x[1],d); p2 = gadd((GEN)x[2], gmul(gmul(u,p1), gadd((GEN)y[2],gneg((GEN)x[2])))); tetpil=avma; z[1]=lmul(p1,(GEN)y[1]); z[2]=lmod(p2,(GEN)z[1]); gerepilemanyvec(av,tetpil,z+1,2); return z; case t_POL: lx=lgef(x); vx=varn(x); z=cgetg(lx,tx); if (lx!=lgef(y) || vx!=varn(y)) break; z[1]=evalsigne(1)|evallgef(lx)|evalvarn(vx); for (i=2; i<lx; i++) z[i]=(long)chinois((GEN)x[i],(GEN)y[i]); return z; case t_VEC: case t_COL: case t_MAT: lx=lg(x); z=cgetg(lx,tx); if (lx!=lg(y)) break; for (i=1; i<lx; i++) z[i]=(long)chinois((GEN)x[i],(GEN)y[i]); return z; } err(talker,"incompatible arguments in chinois"); return NULL; /* not reached */}
case t_VECSMALL: lx=lg(x); y=cgetg(lx,tx); for (i=1; i<lx; i++) y[i] = -x[i]; break;
gneg_i(GEN x){ long tx=typ(x),lx,i; GEN y; if (gcmp0(x)) return x; switch(tx) { case t_INT: case t_REAL: return mpneg(x); case t_INTMOD: y=cgetg(3,t_INTMOD); y[1]=x[1]; y[2] = lsubii((GEN)y[1],(GEN)x[2]); break; case t_FRAC: case t_FRACN: case t_RFRAC: case t_RFRACN: y=cgetg(3,tx); y[2]=x[2]; y[1]=(long)gneg_i((GEN)x[1]); break; case t_PADIC: y = cgetg(5,t_PADIC); y[2]=x[2]; y[3]=x[3]; y[1] = evalprecp(precp(x)) | evalvalp(valp(x)); y[4]=lsubii((GEN)x[3],(GEN)x[4]); break; case t_POLMOD: y=cgetg(3,t_POLMOD); y[1]=x[1]; y[2]=(long)gneg_i((GEN)x[2]); break; case t_QUAD: y=cgetg(4,t_QUAD); y[1]=x[1]; y[2]=(long)gneg_i((GEN)x[2]); y[3]=(long)gneg_i((GEN)x[3]); break; case t_COMPLEX: case t_VEC: case t_COL: case t_MAT: lx=lg(x); y=cgetg(lx,tx); for (i=1; i<lx; i++) y[i]=(long)gneg_i((GEN)x[i]); break; case t_POL: case t_SER: lx=lg(x); y=cgetg(lx,tx); y[1]=x[1]; for (i=2; i<lx; i++) y[i]=(long)gneg_i((GEN)x[i]); break; default: err(typeer,"negation"); return NULL; /* not reached */ } return y;}
if (j < e) k /= u_pow(p, e - j);
if (j < e) k /= npownn(p, e - j);
gisanypower(GEN x, GEN *pty){ long tx = typ(x); ulong k, h; if (tx == t_FRAC) { pari_sp av = avma; GEN fa, P, E, a = (GEN)x[1], b = (GEN)x[2]; long i, j, p, e; int sw = (cmpii(a, b) > 0); if (sw) swap(a, b); k = isanypower(a, pty? &a: NULL); if (!k) { avma = av; return 0; } fa = factoru(k); P = (GEN)fa[1]; E = (GEN)fa[2]; h = k; for (i = lg(P) - 1; i > 0; i--) { p = P[i]; e = E[i]; for (j = 0; j < e; j++) if (!is_kth_power(b, p, &b, NULL)) break; if (j < e) k /= u_pow(p, e - j); } if (k == 1) { avma = av; return 0; } if (!pty) { avma = av; return k; } if (k != h) a = gpowgs(a, h/k); *pty = gerepilecopy(av, mkfrac(a, b)); return k; } if (tx == t_INT) return isanypower(x, pty); err(talker, "missing exponent"); return 0; /* not reached */}
long lx, av = avma; ulong k,l;
long lx,k,l, av = avma;
mpfact(long n){ long lx, av = avma; ulong k,l; GEN x; if (n<2) { if (n<0) err(facter); return gun; } if (n < 60) { x = gdeux; for (k=3; k<=n; k++) x = mulsi(k,x); return gerepileuptoint(av,x); } lx = 1; x = cgetg(1 + n/2, t_VEC); for (k=2;; k++) { l = n+2-k; if (l <= k) break; x[lx++] = (long)muluu(k,l); } if (l == k) x[lx++] = lstoi(k); setlg(x, lx); return gerepileuptoint(av, divide_conquer_prod(x, mulii));}
long av,tetpil,lx,i,tx=typ(x);
long lx,i,tx=typ(x); ulong av,tetpil;
content(GEN x){ long av,tetpil,lx,i,tx=typ(x); GEN p1,p2; if (is_scalar_t(tx)) return tx==t_POLMOD? content((GEN)x[2]): gcopy(x); av = avma; switch(tx) { case t_RFRAC: case t_RFRACN: p1=content((GEN)x[1]); p2=content((GEN)x[2]); tetpil=avma; return gerepile(av,tetpil,gdiv(p1,p2)); case t_VEC: case t_COL: case t_MAT: lx = lg(x); if (lx==1) return gun; p1=content((GEN)x[1]); for (i=2; i<lx; i++) p1 = ggcd(p1,content((GEN)x[i])); return gerepileupto(av,p1); case t_POL: if (!signe(x)) return gzero; lx = lgef(x); break; case t_SER: if (!signe(x)) return gzero; lx = lg(x); break; case t_QFR: case t_QFI: lx = 4; break; default: err(typeer,"content"); return NULL; /* not reached */ } for (i=lontyp[tx]; i<lx; i++) if (typ(x[i]) != t_INT) break; lx--; p1=(GEN)x[lx]; if (i > lx) { /* integer coeffs */ while (lx>lontyp[tx]) { lx--; p1=mppgcd(p1,(GEN)x[lx]); if (is_pm1(p1)) { avma=av; return gun; } } } else { while (lx>lontyp[tx]) { lx--; p1=ggcd(p1,(GEN)x[lx]); } if (isinexactreal(p1)) { avma=av; return gun; } } return av==avma? gcopy(p1): gerepileupto(av,p1);}
affrr(p2,y); avma = av; return y;
affr_fixlg(p2,y); avma = av; return y;
exp1r_abs(GEN x){ long l = lg(x), l2 = l+1, ex = expo(x), l1, i, n, m, s; GEN y = cgetr(l), p1, p2, p3, X, unr; pari_sp av2, av = avma; double a, b, beta, gama = 2.0 /* optimized for SUN3 */; /* KB: 3.0 is better for UltraSparc */ if (ex >= EXMAX) err(talker,"exponent too large in exp"); beta = 5. + bit_accuracy_mul(l, LOG2); a = sqrt(beta/(gama*LOG2)); b = (BITS_IN_LONG-1-ex) + log2(a * (gama/2.718281828459045) / (double)(ulong)x[2]); if (a >= b) { n = (long)(1+a*gama); m = (long)(1+a-b); l2 += m>>TWOPOTBITS_IN_LONG; } else { /* rare ! */ b = -1 - log((double)(ulong)x[2]) + (BITS_IN_LONG-1-ex)*LOG2; /*-1-log(x)*/ n = (long)(1 + beta/b); m = 0; } unr=realun(l2); p2 =realun(l2); setlg(p2,3); X = cgetr(l2); affrr(x, X); setsigne(X, 1); if (m) setexpo(X, ex-m); s = 0; l1 = 3; av2 = avma; for (i=n; i>=2; i--) { setlg(X,l1); p3 = divrs(X,i); s -= expo(p3); p1 = mulrr(p3,p2); setlg(p1,l1); l1 += s>>TWOPOTBITS_IN_LONG; if (l1>l2) l1=l2; s &= (BITS_IN_LONG-1); setlg(unr,l1); p1 = addrr_sign(unr,1, p1,1); setlg(p2,l1); affrr(p1,p2); avma = av2; } setlg(p2,l2); setlg(X,l2); p2 = mulrr(X,p2); for (i=1; i<=m; i++) { setlg(p2,l2); p2 = mulrr(p2, addsr(2,p2)); } affrr(p2,y); avma = av; return y;}
if (bl_num(x) < loc) return 0;
pop_val_if_newer(entree *ep, long loc){ var_cell *v = (var_cell*) ep->args; if (v == INITIAL) return 0; if (v->flag == COPY_VAL) { GEN x = (GEN)ep->value; if (DEBUGMEM>2) fprintferr("popping %s (bloc no %ld)\n", ep->name, bl_num(x)); if (bl_num(x) < loc) return 0; /* older */ killbloc((GEN)ep->value); } ep->value = v->value; ep->args = (void*) v->prev; free((void*)v); return 1;}
case 0: return kbessel(nu,gx,prec); case 1: return kbessel2(nu,gx,prec);
case 0: return kbesselnew(nu,gx,prec); case 1: return kbessel(nu,gx,prec); case 2: return kbessel2(nu,gx,prec); case 3: return kbesselnewalways(nu,gx,prec);
kbessel0(GEN nu, GEN gx, long flag, long prec){ switch(flag) { case 0: return kbessel(nu,gx,prec); case 1: return kbessel2(nu,gx,prec); default: err(flagerr,"besselk"); } return NULL; /* not reached */}
GEN x,y,p1,p2,zf,zz,s,t,q,r,u,v,e,f,c,d,ak,pitemp,nu2,w; long l, lbin, k, k2, l1, n2, n;
GEN x,y,yfin,p1,p2,zf,zz,s,t,q,r,u,v,e,f,c,d,ak,pitemp,nu2,w; long l, lnew, lbin, k, k2, l1, n2, n, ex, rab=0;
kbessel(GEN nu, GEN gx, long prec){ GEN x,y,p1,p2,zf,zz,s,t,q,r,u,v,e,f,c,d,ak,pitemp,nu2,w; long l, lbin, k, k2, l1, n2, n; gpmem_t av, av1; if (typ(nu)==t_COMPLEX) return kbessel2(nu,gx,prec); l = (typ(gx)==t_REAL)? lg(gx): prec; y=cgetr(l); l1=l+1; av=avma; x = fix(gx, l); u=cgetr(l1); v=cgetr(l1); c=cgetr(l1); d=cgetr(l1); e=cgetr(l1); f=cgetr(l1); nu2=gmulgs(gsqr(nu),-4); n = (long) (bit_accuracy(l)*LOG2 + PI*sqrt(gtodouble(gnorm(nu)))) / 2; n2=(n<<1); pitemp=mppi(l1); /* this 10 should really be a 5, but then kbessel(15.99) enters oo loop */ lbin = 10 - bit_accuracy(l); av1=avma; if (gcmpgs(x,n)<0) { zf=gsqrt(gdivgs(pitemp,n2),prec); zz=cgetr(l1); gaffect(ginv(stoi(n2<<2)), zz); s=gun; t=gzero; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1 = gadd(mulss(k2,k2),nu2); else p1 = gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),-k); s=gadd(gun,gmul(ak,s)); t=gaddsg(k2,gmul(ak,t)); } gmulz(s,zf,u); t=gmul2n(t,-1); gdivgsz(gadd(gmul(t,zf),gmul(u,nu)),-n2,v); avma=av1; affsr(n2,q=cgetr(l1)); r=gmul2n(x,1); av1=avma; for(;;) { p1=divsr(5,q); if (expo(p1) >= -1) p1=ghalf; p2=subsr(1,divrr(r,q)); if (gcmp(p1,p2)>0) p1=p2; gnegz(p1,c); gaffsg(1,d); affrr(u,e); affrr(v,f); for (k=1; ; k++) { w=gadd(gmul(gsubsg(k,ghalf),u), gmul(subrs(q,k),v)); w=gadd(w, gmul(nu,gsub(u,gmul2n(v,1)))); gdivgsz(gmul(q,v),k,u); gdivgsz(w,k,v); gmulz(d,c,d); gaddz(e,gmul(d,u),e); p1=gmul(d,v); gaddz(f,p1,f); if (gexpo(p1)-gexpo(f) <= lbin) break; avma=av1; } p1=u; u=e; e=p1; p1=v; v=f; f=p1; gmulz(q,gaddsg(1,c),q); if (expo(subrr(q,r)) <= lbin) break; } gmulz(u,gpui(gdivgs(x,n),nu,prec),y); } else { p2=gmul2n(x,1); zf=gsqrt(gdiv(pitemp,p2),prec); zz=ginv(gmul2n(p2,2)); s=gun; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1=gadd(mulss(k2,k2),nu2); else p1=gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),k); s=gsub(gun,gmul(ak,s)); } gmulz(s,zf,y); } gdivz(y,mpexp(x),y); avma=av; return y;}
y=cgetr(l); l1=l+1; av=avma; x = fix(gx, l);
ex = gexpo(gx); if (ex < 0) { rab = 1 + ((-ex)>>TWOPOTBITS_IN_LONG); lnew = l + rab; prec += rab; } else lnew = l; yfin=cgetr(l); l1=lnew+1; av=avma; x = fix(gx, lnew); y=cgetr(lnew);
kbessel(GEN nu, GEN gx, long prec){ GEN x,y,p1,p2,zf,zz,s,t,q,r,u,v,e,f,c,d,ak,pitemp,nu2,w; long l, lbin, k, k2, l1, n2, n; gpmem_t av, av1; if (typ(nu)==t_COMPLEX) return kbessel2(nu,gx,prec); l = (typ(gx)==t_REAL)? lg(gx): prec; y=cgetr(l); l1=l+1; av=avma; x = fix(gx, l); u=cgetr(l1); v=cgetr(l1); c=cgetr(l1); d=cgetr(l1); e=cgetr(l1); f=cgetr(l1); nu2=gmulgs(gsqr(nu),-4); n = (long) (bit_accuracy(l)*LOG2 + PI*sqrt(gtodouble(gnorm(nu)))) / 2; n2=(n<<1); pitemp=mppi(l1); /* this 10 should really be a 5, but then kbessel(15.99) enters oo loop */ lbin = 10 - bit_accuracy(l); av1=avma; if (gcmpgs(x,n)<0) { zf=gsqrt(gdivgs(pitemp,n2),prec); zz=cgetr(l1); gaffect(ginv(stoi(n2<<2)), zz); s=gun; t=gzero; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1 = gadd(mulss(k2,k2),nu2); else p1 = gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),-k); s=gadd(gun,gmul(ak,s)); t=gaddsg(k2,gmul(ak,t)); } gmulz(s,zf,u); t=gmul2n(t,-1); gdivgsz(gadd(gmul(t,zf),gmul(u,nu)),-n2,v); avma=av1; affsr(n2,q=cgetr(l1)); r=gmul2n(x,1); av1=avma; for(;;) { p1=divsr(5,q); if (expo(p1) >= -1) p1=ghalf; p2=subsr(1,divrr(r,q)); if (gcmp(p1,p2)>0) p1=p2; gnegz(p1,c); gaffsg(1,d); affrr(u,e); affrr(v,f); for (k=1; ; k++) { w=gadd(gmul(gsubsg(k,ghalf),u), gmul(subrs(q,k),v)); w=gadd(w, gmul(nu,gsub(u,gmul2n(v,1)))); gdivgsz(gmul(q,v),k,u); gdivgsz(w,k,v); gmulz(d,c,d); gaddz(e,gmul(d,u),e); p1=gmul(d,v); gaddz(f,p1,f); if (gexpo(p1)-gexpo(f) <= lbin) break; avma=av1; } p1=u; u=e; e=p1; p1=v; v=f; f=p1; gmulz(q,gaddsg(1,c),q); if (expo(subrr(q,r)) <= lbin) break; } gmulz(u,gpui(gdivgs(x,n),nu,prec),y); } else { p2=gmul2n(x,1); zf=gsqrt(gdiv(pitemp,p2),prec); zz=ginv(gmul2n(p2,2)); s=gun; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1=gadd(mulss(k2,k2),nu2); else p1=gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),k); s=gsub(gun,gmul(ak,s)); } gmulz(s,zf,y); } gdivz(y,mpexp(x),y); avma=av; return y;}
gdivz(y,mpexp(x),y); avma=av; return y;
gdivz(y,mpexp(x),yfin); avma=av; return yfin;
kbessel(GEN nu, GEN gx, long prec){ GEN x,y,p1,p2,zf,zz,s,t,q,r,u,v,e,f,c,d,ak,pitemp,nu2,w; long l, lbin, k, k2, l1, n2, n; gpmem_t av, av1; if (typ(nu)==t_COMPLEX) return kbessel2(nu,gx,prec); l = (typ(gx)==t_REAL)? lg(gx): prec; y=cgetr(l); l1=l+1; av=avma; x = fix(gx, l); u=cgetr(l1); v=cgetr(l1); c=cgetr(l1); d=cgetr(l1); e=cgetr(l1); f=cgetr(l1); nu2=gmulgs(gsqr(nu),-4); n = (long) (bit_accuracy(l)*LOG2 + PI*sqrt(gtodouble(gnorm(nu)))) / 2; n2=(n<<1); pitemp=mppi(l1); /* this 10 should really be a 5, but then kbessel(15.99) enters oo loop */ lbin = 10 - bit_accuracy(l); av1=avma; if (gcmpgs(x,n)<0) { zf=gsqrt(gdivgs(pitemp,n2),prec); zz=cgetr(l1); gaffect(ginv(stoi(n2<<2)), zz); s=gun; t=gzero; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1 = gadd(mulss(k2,k2),nu2); else p1 = gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),-k); s=gadd(gun,gmul(ak,s)); t=gaddsg(k2,gmul(ak,t)); } gmulz(s,zf,u); t=gmul2n(t,-1); gdivgsz(gadd(gmul(t,zf),gmul(u,nu)),-n2,v); avma=av1; affsr(n2,q=cgetr(l1)); r=gmul2n(x,1); av1=avma; for(;;) { p1=divsr(5,q); if (expo(p1) >= -1) p1=ghalf; p2=subsr(1,divrr(r,q)); if (gcmp(p1,p2)>0) p1=p2; gnegz(p1,c); gaffsg(1,d); affrr(u,e); affrr(v,f); for (k=1; ; k++) { w=gadd(gmul(gsubsg(k,ghalf),u), gmul(subrs(q,k),v)); w=gadd(w, gmul(nu,gsub(u,gmul2n(v,1)))); gdivgsz(gmul(q,v),k,u); gdivgsz(w,k,v); gmulz(d,c,d); gaddz(e,gmul(d,u),e); p1=gmul(d,v); gaddz(f,p1,f); if (gexpo(p1)-gexpo(f) <= lbin) break; avma=av1; } p1=u; u=e; e=p1; p1=v; v=f; f=p1; gmulz(q,gaddsg(1,c),q); if (expo(subrr(q,r)) <= lbin) break; } gmulz(u,gpui(gdivgs(x,n),nu,prec),y); } else { p2=gmul2n(x,1); zf=gsqrt(gdiv(pitemp,p2),prec); zz=ginv(gmul2n(p2,2)); s=gun; for (k=n2,k2=2*n2-1; k > 0; k--,k2-=2) { if (k2 & ~(MAXHALFULONG>>1)) p1=gadd(mulss(k2,k2),nu2); else p1=gaddsg(k2*k2,nu2); ak=gdivgs(gmul(p1,zz),k); s=gsub(gun,gmul(ak,s)); } gmulz(s,zf,y); } gdivz(y,mpexp(x),y); avma=av; return y;}
if (gegal(x, initial_value(ep))) return gcopy(z); #undef initial_value
geval(GEN x){ long av,tetpil,lx,i, tx = typ(x); GEN y,z; if (is_const_t(tx)) return gcopy(x); if (is_graphicvec_t(tx) || tx == t_RFRACN) { lx=lg(x); y=cgetg(lx, tx); for (i=1; i<lx; i++) y[i] = (long)geval((GEN)x[i]); return y; } switch(tx) { case t_STR: return flisexpr(GSTR(x)); case t_POLMOD: y=cgetg(3,tx); y[1]=(long)geval((GEN)x[1]); av=avma; z=geval((GEN)x[2]); tetpil=avma; y[2]=lpile(av,tetpil,gmod(z,(GEN)y[1])); return y; case t_POL: lx=lgef(x); if (lx==2) return gzero; { entree *ep = varentries[varn(x)]; if (!ep) return gcopy(x); z = (GEN)ep->value; } y=gzero; av=avma; for (i=lx-1; i>1; i--) { tetpil=avma; y = gadd(geval((GEN)x[i]), gmul(z,y)); } return gerepile(av,tetpil,y); case t_SER: err(impl, "evaluation of a power series"); case t_RFRAC: return gdiv(geval((GEN)x[1]),geval((GEN)x[2])); } err(typeer,"geval"); return NULL; /* not reached */}
p1=cgetr(3); *s=p1; p1[1]=x[1]; p1[2]=0; *c=addsr(1,x); return;
*s=realzero_bit(expo(x)); *c=addsr(1,x); return;
mpsincos(GEN x, GEN *s, GEN *c){ long av,tetpil,mod8; GEN p1, *gptr[2]; if (typ(x)!=t_REAL) err(typeer,"mpsincos"); if (!signe(x)) { p1=cgetr(3); *s=p1; p1[1]=x[1]; p1[2]=0; *c=addsr(1,x); return; } av=avma; p1=mpsc1(x,&mod8); tetpil=avma; switch(mod8) { case 0: *c=addsr( 1,p1); *s=mpaut(p1); break; case 1: *s=addsr( 1,p1); *c=mpaut(p1); setsigne(*c,-signe(*c)); break; case 2: *c=subsr(-1,p1); *s=mpaut(p1); setsigne(*s,-signe(*s)); break; case 3: *s=subsr(-1,p1); *c=mpaut(p1); break; case 4: *c=addsr( 1,p1); *s=mpaut(p1); setsigne(*s,-signe(*s)); break; case 5: *s=addsr( 1,p1); *c=mpaut(p1); break; case 6: *c=subsr(-1,p1); *s=mpaut(p1); break; case 7: *s=subsr(-1,p1); *c=mpaut(p1); setsigne(*c,-signe(*c)); break; } gptr[0]=s; gptr[1]=c; gerepilemanysp(av,tetpil,gptr,2);}
cacr = 0x80008000;
cacr = 0x00000000;
void page_table_init( rtems_configuration_table *config_table){ unsigned char j1; /* State of J1 jumpers */ register unsigned long dtt0; /* Content of dtt0 */ register unsigned long cacr; /* Content of cacr */ /* * Logical base addr = 0x00 map starting at 0x00000000 * Logical address mask = 0x7F map up to 0x7FFFFFFF * E = 0b1 enable address translation * S-Field = 0b1X ignore FC2 when matching * U1, U0 = 0b00 user page attributes not used * CM = 0b01 cachable, copyback * W = 0b0 read/write access allowed */ dtt0 = 0x007FC020; cacr = 0x80008000; /* Data and instruction cache on */ /* Read the J1 header */ j1 = (unsigned char)(lcsr->vector_base & 0xFF); if ( j1 & 0x80 ) /* Jumper J1-7 if off, disable data caching */ cacr &= 0x7FFFFFFF; if ( j1 & 0x40 ) /* Jumper J1-6 if off, disable instruction caching */ cacr &= 0xFFFF7FFF; if ( j1 & 0x20 ) /* Jumper J1-5 is off, enable writethrough caching */ dtt0 &= 0xFFFFFF9F; /* do it ! */ asm volatile("movec %0, %%tc /* turn off paged address translation */ movec %0, %%cacr /* disable both caches */ cinva %%bc /* clear both caches */ movec %1,%%dtt0 /* block address translation on */ movec %1,%%itt0 movec %2,%%dtt1 movec %2,%%itt1 movec %3,%%cacr" /* data cache on */ :: "d" (0), "d" (dtt0), "d" (0xFF00C040), "d" (cacr));}
if ( j1 & 0x20 ) dtt0 &= 0xFFFFFF9F;
if ( j1 & 0x20 ) dtt0 &= 0xFFFFFF9F; }
void page_table_init( rtems_configuration_table *config_table){ unsigned char j1; /* State of J1 jumpers */ register unsigned long dtt0; /* Content of dtt0 */ register unsigned long cacr; /* Content of cacr */ /* * Logical base addr = 0x00 map starting at 0x00000000 * Logical address mask = 0x7F map up to 0x7FFFFFFF * E = 0b1 enable address translation * S-Field = 0b1X ignore FC2 when matching * U1, U0 = 0b00 user page attributes not used * CM = 0b01 cachable, copyback * W = 0b0 read/write access allowed */ dtt0 = 0x007FC020; cacr = 0x80008000; /* Data and instruction cache on */ /* Read the J1 header */ j1 = (unsigned char)(lcsr->vector_base & 0xFF); if ( j1 & 0x80 ) /* Jumper J1-7 if off, disable data caching */ cacr &= 0x7FFFFFFF; if ( j1 & 0x40 ) /* Jumper J1-6 if off, disable instruction caching */ cacr &= 0xFFFF7FFF; if ( j1 & 0x20 ) /* Jumper J1-5 is off, enable writethrough caching */ dtt0 &= 0xFFFFFF9F; /* do it ! */ asm volatile("movec %0, %%tc /* turn off paged address translation */ movec %0, %%cacr /* disable both caches */ cinva %%bc /* clear both caches */ movec %1,%%dtt0 /* block address translation on */ movec %1,%%itt0 movec %2,%%dtt1 movec %2,%%itt1 movec %3,%%cacr" /* data cache on */ :: "d" (0), "d" (dtt0), "d" (0xFF00C040), "d" (cacr));}
affrr(mptan(x), y); avma = av; return y;
affr_fixlg(mptan(x), y); avma = av; return y;
gtan(GEN x, long prec){ pari_sp av; GEN y, s, c; switch(typ(x)) { case t_REAL: return mptan(x); case t_COMPLEX: av = avma; gsincos(x,&s,&c,prec); return gerepileupto(av, gdiv(s,c)); case t_INT: case t_FRAC: y = cgetr(prec); av = avma; /* _not_ afrr: we want to be able to reduce mod Pi */ x = gadd(x, realzero(prec)); affrr(mptan(x), y); avma = av; return y; case t_INTMOD: case t_PADIC: err(typeer,"gtan"); default: av = avma; if (!(y = _toser(x))) break; if (gcmp0(y)) return gcopy(y); if (valp(y) < 0) err(negexper,"gtan"); gsincos(y,&s,&c,prec); return gerepileupto(av, gdiv(s,c)); } return transc(gtan,x,prec);}
rtems_unsigned32 n = rtems_get_index(*next_id);
uint32_t n = rtems_get_index(*next_id);
rtems_monitor_init_task_next( void *object_info, rtems_monitor_init_task_t *canonical_init_task, rtems_id *next_id){ rtems_configuration_table *c = _Configuration_Table; rtems_initialization_tasks_table *itask; rtems_unsigned32 n = rtems_get_index(*next_id); if (n >= c->RTEMS_api_configuration->number_of_initialization_tasks) goto failed; _Thread_Disable_dispatch(); itask = c->RTEMS_api_configuration->User_initialization_tasks_table + n; /* * dummy up a fake id and name for this item */ canonical_init_task->id = n; canonical_init_task->name = itask->name; *next_id += 1; return (void *) itask;failed: *next_id = RTEMS_OBJECT_ID_FINAL; return 0;}
request.argument0 = (unsigned32) type; request.argument1 = (unsigned32) id;
request.argument0 = (uint32_t ) type; request.argument1 = (uint32_t ) id;
rtems_monitor_object_canonical_next_remote( rtems_monitor_object_type_t type, rtems_id id, void *canonical){ rtems_id next_id; rtems_status_code status; rtems_monitor_server_request_t request; rtems_monitor_server_response_t response; /* * Send request */ request.command = RTEMS_MONITOR_SERVER_CANONICAL; request.argument0 = (unsigned32) type; request.argument1 = (unsigned32) id; status = rtems_monitor_server_request(rtems_get_node(id), &request, &response); if (status != RTEMS_SUCCESSFUL) goto failed; /* * process response */ next_id = (rtems_id) response.result0; if (next_id != RTEMS_OBJECT_ID_FINAL) (void) memcpy(canonical, &response.payload, response.result1); return next_id;failed: return RTEMS_OBJECT_ID_FINAL;}
unsigned32 length = 0;
uint32_t length = 0;
rtems_monitor_extension_dump( rtems_monitor_extension_t *monitor_extension, boolean verbose){ unsigned32 length = 0; length += rtems_monitor_dump_id(monitor_extension->id); length += rtems_monitor_pad(11, length); length += rtems_monitor_dump_name(monitor_extension->name); length += rtems_monitor_pad(18, length); length += printf("create: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_create, verbose); length += printf("; start: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_start, verbose); length += printf("; restart: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_restart, verbose); length += printf("\n"); length = 0; length += rtems_monitor_pad(18, length); length += printf("delete: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_delete, verbose); length += printf("; switch: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_tswitch, verbose); length += printf("; begin: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_begin, verbose); length += printf("\n"); length = 0; length += rtems_monitor_pad(18, length); length += printf("exitted: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_exitted, verbose); length += printf("; fatal: "); length += rtems_monitor_symbol_dump(&monitor_extension->e_fatal, verbose); length += printf("\n"); length = 0; printf("\n");}
unsigned32 length = 0;
uint32_t length = 0;
rtems_monitor_dname_dump( rtems_monitor_dname_t *monitor_dname, boolean verbose){ unsigned32 length = 0; length += rtems_monitor_pad(6, length); length += rtems_monitor_dump_hex(monitor_dname->major); length += printf(":"); length += rtems_monitor_dump_hex(monitor_dname->minor); length += rtems_monitor_pad(16, length); length += printf("%.*s", (int) sizeof(monitor_dname->name_string), (char *) monitor_dname->name_string); length += printf("\n"); length = 0;}
xmpn_mirror(x,nx); if (x!=y) xmpn_mirror(y,ny);
xmpn_mirror((mp_limb_t *)x,nx); if (x!=y) xmpn_mirror((mp_limb_t *)y,ny);
quickmulii(GEN x, GEN y, long nx, long ny){ GEN z; xmpn_mirror(x,nx); if (x!=y) xmpn_mirror(y,ny); z=muliispec(x, y, nx, ny); xmpn_mirror(LIMBS(z),NLIMBS(z)); xmpn_mirror(x,nx); if (x!=y) xmpn_mirror(y,ny); return z;}
rtems_unsigned32 source,
uint32_t source,
rtems_extension Fatal_extension( rtems_unsigned32 source, boolean is_internal, rtems_unsigned32 error){ int index; Error_Happened[ Case_in_switch ] = error; if ( First_Time_Through == 0 ) { Case_in_switch = FATAL_WORKSPACE_OF_ZERO; First_Time_Through = 1; setjmp( Restart_Context ); } else if ( Case_in_switch == FATAL_LAST ) { /* * Depending on the C library we use, we cannot get the * task exitted error so do not check for it. */ puts( "*** TEST FATAL ***" ); for ( index=0 ; index< FATAL_LAST ; index++ ) put_error( Error_Happened[ index ], Expected_Errors[ index ] ); puts( "NOT TESTING FATAL ERROR WHEN TASK EXITS -- C LIBRARY CATCHES THIS" ); puts( "*** END OF TEST FATAL ***" ); /* * returns to the default fatal error handler instead of * calling rtems_shutdown_executive */ return; } else { longjmp( Restart_Context, 1 ); } Process_case();}
rtems_unsigned32 error
uint32_t error
rtems_extension Fatal_extension( rtems_unsigned32 source, boolean is_internal, rtems_unsigned32 error){ int index; Error_Happened[ Case_in_switch ] = error; if ( First_Time_Through == 0 ) { Case_in_switch = FATAL_WORKSPACE_OF_ZERO; First_Time_Through = 1; setjmp( Restart_Context ); } else if ( Case_in_switch == FATAL_LAST ) { /* * Depending on the C library we use, we cannot get the * task exitted error so do not check for it. */ puts( "*** TEST FATAL ***" ); for ( index=0 ; index< FATAL_LAST ; index++ ) put_error( Error_Happened[ index ], Expected_Errors[ index ] ); puts( "NOT TESTING FATAL ERROR WHEN TASK EXITS -- C LIBRARY CATCHES THIS" ); puts( "*** END OF TEST FATAL ***" ); /* * returns to the default fatal error handler instead of * calling rtems_shutdown_executive */ return; } else { longjmp( Restart_Context, 1 ); } Process_case();}
case PPC_601 : case PPC_603 : case PPC_604 : case PPC_603e : case PPC_603ev: case PPC_750 : case PPC_604e : case PPC_604r : case PPC_620 : case PPC_860 : current_ppc_cpu = (ppc_cpu_id_t) pvr; return current_ppc_cpu; default : printk("Unknown PVR value. Please add it to <libcpu/powerpc/shared/cpu.h> \n");
case PPC_601: case PPC_603: case PPC_604: case PPC_603: case PPC_603ev: case PPC_750: case PPC_604e: case PPC_604r: case PPC_620: case PPC_860: current_ppc_cpu = (ppc_cpu_id_t) pvr; return current_ppc_cpu; default: printk("Unknown PVR value of 0x%x. Please add it to <libcpu/powerpc/shared/cpu.h>\n", pvr );
SPR_RO(PVR)ppc_cpu_id_t current_ppc_cpu = PPC_UNKNOWN;ppc_cpu_revision_t current_ppc_revision = 0xff;ppc_cpu_id_t get_ppc_cpu_type(){ unsigned int pvr = (_read_PVR() >> 16) ; current_ppc_cpu = (ppc_cpu_id_t) pvr; switch (pvr) { case PPC_601 : case PPC_603 : case PPC_604 : case PPC_603e : case PPC_603ev: case PPC_750 : case PPC_604e : case PPC_604r : case PPC_620 : case PPC_860 : current_ppc_cpu = (ppc_cpu_id_t) pvr; return current_ppc_cpu; default : printk("Unknown PVR value. Please add it to <libcpu/powerpc/shared/cpu.h> \n"); return PPC_UNKNOWN; } }
unsigned32 start, unsigned32 offset, unsigned32 count,
uint32_t start, uint32_t offset, uint32_t count,
_fat_block_write( rtems_filesystem_mount_table_entry_t *mt_entry, unsigned32 start, unsigned32 offset, unsigned32 count, const void *buff){ int rc = RC_OK; fat_fs_info_t *fs_info = mt_entry->fs_info; ssize_t cmpltd = 0; unsigned32 blk = start; unsigned32 ofs = offset; bdbuf_buffer *block = NULL; unsigned32 c = 0; while(count > 0) { c = MIN(count, (fs_info->vol.bps - ofs)); if (c == fs_info->vol.bps) rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block); else rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); if (rc != RC_OK) return -1; memcpy((block->buffer + ofs), (buff + cmpltd), c); fat_buf_mark_modified(fs_info); count -= c; cmpltd +=c; blk++; ofs = 0; } return cmpltd;}
unsigned32 blk = start; unsigned32 ofs = offset;
uint32_t blk = start; uint32_t ofs = offset;
_fat_block_write( rtems_filesystem_mount_table_entry_t *mt_entry, unsigned32 start, unsigned32 offset, unsigned32 count, const void *buff){ int rc = RC_OK; fat_fs_info_t *fs_info = mt_entry->fs_info; ssize_t cmpltd = 0; unsigned32 blk = start; unsigned32 ofs = offset; bdbuf_buffer *block = NULL; unsigned32 c = 0; while(count > 0) { c = MIN(count, (fs_info->vol.bps - ofs)); if (c == fs_info->vol.bps) rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block); else rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); if (rc != RC_OK) return -1; memcpy((block->buffer + ofs), (buff + cmpltd), c); fat_buf_mark_modified(fs_info); count -= c; cmpltd +=c; blk++; ofs = 0; } return cmpltd;}
unsigned32 c = 0;
uint32_t c = 0;
_fat_block_write( rtems_filesystem_mount_table_entry_t *mt_entry, unsigned32 start, unsigned32 offset, unsigned32 count, const void *buff){ int rc = RC_OK; fat_fs_info_t *fs_info = mt_entry->fs_info; ssize_t cmpltd = 0; unsigned32 blk = start; unsigned32 ofs = offset; bdbuf_buffer *block = NULL; unsigned32 c = 0; while(count > 0) { c = MIN(count, (fs_info->vol.bps - ofs)); if (c == fs_info->vol.bps) rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block); else rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); if (rc != RC_OK) return -1; memcpy((block->buffer + ofs), (buff + cmpltd), c); fat_buf_mark_modified(fs_info); count -= c; cmpltd +=c; blk++; ofs = 0; } return cmpltd;}
fast_idle_extension.task_switch = fast_idle_switch_hook;
fast_idle_extension.thread_switch = fast_idle_switch_hook;
bsp_pretasking_hook(void){ bsp_libc_init();#if SIMHPPA_FAST_IDLE /* * Install the fast idle task switch extension * * on MP systems, might now want to do this; it confuses at least * one test (mp06) */#if 0 if (BSP_Configuration.User_multiprocessing_table == 0)#endif { rtems_extensions_table fast_idle_extension; rtems_id extension_id; rtems_status_code rc; memset(&fast_idle_extension, 0, sizeof(fast_idle_extension)); fast_idle_extension.task_switch = fast_idle_switch_hook; rc = rtems_extension_create(rtems_build_name('F', 'D', 'L', 'E'), &fast_idle_extension, &extension_id); if (rc != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred(rc); }#endif#ifdef STACK_CHECKER_ON /* * Initialize the stack bounds checker * We can either turn it on here or from the app. */ Stack_check_Initialize();#endif}
case PPC_603le: return "MPC603le";
SPR_RO(PVR)ppc_cpu_id_t current_ppc_cpu = PPC_UNKNOWN;ppc_cpu_revision_t current_ppc_revision = 0xff;char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu){ switch (cpu) { case PPC_601: return "MPC601"; case PPC_5XX: return "MPC5XX"; case PPC_603: return "MPC603"; case PPC_603ev: return "MPC603ev"; case PPC_604: return "MPC604"; case PPC_750: return "MPC750"; case PPC_7400: return "MPC7400"; case PPC_7455: return "MPC7455"; case PPC_604e: return "MPC604e"; case PPC_604r: return "MPC604r"; case PPC_620: return "MPC620"; case PPC_860: return "MPC860"; case PPC_8260: return "MPC8260"; case PPC_8245: return "MPC8245"; default: printk("Unknown CPU value of 0x%x. Please add it to " "<libcpu/powerpc/shared/include/cpuIdent.c>\n", cpu ); } return "UNKNOWN";}
(unsigned long *)&make_private_module_public);
(void*)&make_private_module_public);
void *dlopen(const char *path, int mode){ void *module = 0; NSObjectFileImage ofi = 0; NSObjectFileImageReturnCode ofirc; static int (*make_private_module_public) (NSModule module) = 0; unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE; /* If we got no path, the app wants the global namespace, use -1 as the marker in this case */ if (!path) return (void *)-1; /* Create the object file image, works for things linked with the -bundle arg to ld */ ofirc = NSCreateObjectFileImageFromFile(path, &ofi); switch (ofirc) { case NSObjectFileImageSuccess: /* It was okay, so use NSLinkModule to link in the image */ if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW; module = NSLinkModule(ofi, path,flags); /* Don't forget to destroy the object file image, unless you like leaks */ NSDestroyObjectFileImage(ofi); /* If the mode was global, then change the module, this avoids multiply defined symbol errors to first load private then make global. Silly, isn't it. */ if ((mode & RTLD_GLOBAL)) { if (!make_private_module_public) { _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&make_private_module_public); } make_private_module_public(module); } break; case NSObjectFileImageInappropriateFile: /* It may have been a dynamic library rather than a bundle, try to load it */ module = (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); break; case NSObjectFileImageFailure: error(0,"Object file setup failure : \"%s\"", path); return 0; case NSObjectFileImageArch: error(0,"No object for this architecture : \"%s\"", path); return 0; case NSObjectFileImageFormat: error(0,"Bad object file format : \"%s\"", path); return 0; case NSObjectFileImageAccess: error(0,"Can't read object file : \"%s\"", path); return 0; } if (!module) error(0, "Can not open \"%s\"", path); return module;}
make_private_module_public(module);
make_private_module_public((NSModule)module);
void *dlopen(const char *path, int mode){ void *module = 0; NSObjectFileImage ofi = 0; NSObjectFileImageReturnCode ofirc; static int (*make_private_module_public) (NSModule module) = 0; unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE; /* If we got no path, the app wants the global namespace, use -1 as the marker in this case */ if (!path) return (void *)-1; /* Create the object file image, works for things linked with the -bundle arg to ld */ ofirc = NSCreateObjectFileImageFromFile(path, &ofi); switch (ofirc) { case NSObjectFileImageSuccess: /* It was okay, so use NSLinkModule to link in the image */ if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW; module = NSLinkModule(ofi, path,flags); /* Don't forget to destroy the object file image, unless you like leaks */ NSDestroyObjectFileImage(ofi); /* If the mode was global, then change the module, this avoids multiply defined symbol errors to first load private then make global. Silly, isn't it. */ if ((mode & RTLD_GLOBAL)) { if (!make_private_module_public) { _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&make_private_module_public); } make_private_module_public(module); } break; case NSObjectFileImageInappropriateFile: /* It may have been a dynamic library rather than a bundle, try to load it */ module = (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); break; case NSObjectFileImageFailure: error(0,"Object file setup failure : \"%s\"", path); return 0; case NSObjectFileImageArch: error(0,"No object for this architecture : \"%s\"", path); return 0; case NSObjectFileImageFormat: error(0,"Bad object file format : \"%s\"", path); return 0; case NSObjectFileImageAccess: error(0,"Can't read object file : \"%s\"", path); return 0; } if (!module) error(0, "Can not open \"%s\"", path); return module;}
long lx,ly,lz,dx,dy,av,tetpil,i,j;
ulong av = avma; long lx,ly,lz,dx,dy,i,j;
dirdiv(GEN x, GEN y){ long lx,ly,lz,dx,dy,av,tetpil,i,j; GEN z,p1; if (typ(x)!=t_VEC || typ(y)!=t_VEC) err(talker,"not a dirseries in dirmul"); av=avma; dx=dirval(x); dy=dirval(y); lx=lg(x); ly=lg(y); if (dy!=1) err(talker,"not an invertible dirseries in dirdiv"); lz=min(lx,ly*dx); p1=(GEN)y[1]; if (!gcmp1(p1)) { y=gdiv(y,p1); x=gdiv(x,p1); } else x=gcopy(x); z=cgetg(lz,t_VEC); for (i=1; i<dx; i++) z[i]=zero; for (j=dx; j<lz; j++) { p1=(GEN)x[j]; z[j]=(long)p1; if (!gcmp0(p1)) { if (gcmp1(p1)) for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],(GEN)y[i/j]); else { if (gcmp_1(p1)) for (i=j+j; i<lz; i+=j) x[i]=ladd((GEN)x[i],(GEN)y[i/j]); else for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],gmul(p1,(GEN)y[i/j])); } } } tetpil=avma; return gerepile(av,tetpil,gcopy(z));}
av=avma; dx=dirval(x); dy=dirval(y); lx=lg(x); ly=lg(y);
dx=dirval(x); dy=dirval(y); lx=lg(x); ly=lg(y);
dirdiv(GEN x, GEN y){ long lx,ly,lz,dx,dy,av,tetpil,i,j; GEN z,p1; if (typ(x)!=t_VEC || typ(y)!=t_VEC) err(talker,"not a dirseries in dirmul"); av=avma; dx=dirval(x); dy=dirval(y); lx=lg(x); ly=lg(y); if (dy!=1) err(talker,"not an invertible dirseries in dirdiv"); lz=min(lx,ly*dx); p1=(GEN)y[1]; if (!gcmp1(p1)) { y=gdiv(y,p1); x=gdiv(x,p1); } else x=gcopy(x); z=cgetg(lz,t_VEC); for (i=1; i<dx; i++) z[i]=zero; for (j=dx; j<lz; j++) { p1=(GEN)x[j]; z[j]=(long)p1; if (!gcmp0(p1)) { if (gcmp1(p1)) for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],(GEN)y[i/j]); else { if (gcmp_1(p1)) for (i=j+j; i<lz; i+=j) x[i]=ladd((GEN)x[i],(GEN)y[i/j]); else for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],gmul(p1,(GEN)y[i/j])); } } } tetpil=avma; return gerepile(av,tetpil,gcopy(z));}
tetpil=avma; return gerepile(av,tetpil,gcopy(z));
return gerepilecopy(av,z);
dirdiv(GEN x, GEN y){ long lx,ly,lz,dx,dy,av,tetpil,i,j; GEN z,p1; if (typ(x)!=t_VEC || typ(y)!=t_VEC) err(talker,"not a dirseries in dirmul"); av=avma; dx=dirval(x); dy=dirval(y); lx=lg(x); ly=lg(y); if (dy!=1) err(talker,"not an invertible dirseries in dirdiv"); lz=min(lx,ly*dx); p1=(GEN)y[1]; if (!gcmp1(p1)) { y=gdiv(y,p1); x=gdiv(x,p1); } else x=gcopy(x); z=cgetg(lz,t_VEC); for (i=1; i<dx; i++) z[i]=zero; for (j=dx; j<lz; j++) { p1=(GEN)x[j]; z[j]=(long)p1; if (!gcmp0(p1)) { if (gcmp1(p1)) for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],(GEN)y[i/j]); else { if (gcmp_1(p1)) for (i=j+j; i<lz; i+=j) x[i]=ladd((GEN)x[i],(GEN)y[i/j]); else for (i=j+j; i<lz; i+=j) x[i]=lsub((GEN)x[i],gmul(p1,(GEN)y[i/j])); } } } tetpil=avma; return gerepile(av,tetpil,gcopy(z));}
if (typ(nmax)!=t_INT || signe(nmax) < 0) err(talker,"bad number of components in vector");
if (typ(nmax) != t_INT) err(typeer,"vector");
vecteur(GEN nmax, entree *ep, char *ch){ GEN y,p1; long i,m; long c[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 0}; if (typ(nmax)!=t_INT || signe(nmax) < 0) err(talker,"bad number of components in vector"); m = itos(nmax); if (!ep || !ch) return zerovec(m); y = cgetg(m+1,t_VEC); push_val(ep, c); for (i=1; i<=m; i++) { c[2] = i; p1 = lisseq_nobreak(ch); y[i] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } pop_val(ep); return y;}
if (m < 0) err(talker,"negative number of components in vector");
vecteur(GEN nmax, entree *ep, char *ch){ GEN y,p1; long i,m; long c[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 0}; if (typ(nmax)!=t_INT || signe(nmax) < 0) err(talker,"bad number of components in vector"); m = itos(nmax); if (!ep || !ch) return zerovec(m); y = cgetg(m+1,t_VEC); push_val(ep, c); for (i=1; i<=m; i++) { c[2] = i; p1 = lisseq_nobreak(ch); y[i] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } pop_val(ep); return y;}
fs_info->ino_count = 1; fs_info->memfile_handlers = memfile_handlers; fs_info->directory_handlers = directory_handlers;
fs_info->ino_count = 1; fs_info->linearfile_handlers = linearfile_handlers; fs_info->memfile_handlers = memfile_handlers; fs_info->directory_handlers = directory_handlers;
int IMFS_initialize_support( rtems_filesystem_mount_table_entry_t *temp_mt_entry, rtems_filesystem_operations_table *op_table, rtems_filesystem_file_handlers_r *memfile_handlers, rtems_filesystem_file_handlers_r *directory_handlers){ IMFS_fs_info_t *fs_info; IMFS_jnode_t *jnode; /* * Create the root node */ temp_mt_entry->mt_fs_root.node_access = IMFS_create_node( NULL, IMFS_DIRECTORY, "", ( S_IFDIR | S_IRWXO | S_IRWXG| S_IRWXU ), NULL ); temp_mt_entry->mt_fs_root.handlers = directory_handlers; temp_mt_entry->mt_fs_root.ops = op_table; temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS; /* * Create custom file system data. */ fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) ); if ( !fs_info ){ free(temp_mt_entry->mt_fs_root.node_access); return 1; } temp_mt_entry->fs_info = fs_info; /* * Set st_ino for the root to 1. */ fs_info->ino_count = 1; fs_info->memfile_handlers = memfile_handlers; fs_info->directory_handlers = directory_handlers; jnode = temp_mt_entry->mt_fs_root.node_access; jnode->st_ino = fs_info->ino_count; return 0;}
_CPU_ISR_Disable(level);
int BSP_install_rtems_shared_irq_handler (const rtems_irq_connect_data* irq){ unsigned int level; rtems_irq_connect_data* vchain; if (!isValidInterrupt(irq->name)) { printk("Invalid interrupt vector %d\n",irq->name); return 0; } if ( (int)rtems_hdl_tbl[irq->name].next_handler == -1 ) { printk("IRQ vector %d already connected to an unshared handler\n",irq->name); return 0; } _CPU_ISR_Disable(level); vchain = (rtems_irq_connect_data*)malloc(sizeof(rtems_irq_connect_data)); /* save off topmost handler */ vchain[0]= rtems_hdl_tbl[irq->name]; /* * store the data provided by user */ rtems_hdl_tbl[irq->name] = *irq; /* link chain to new topmost handler */ rtems_hdl_tbl[irq->name].next_handler = (void *)vchain; if (is_isa_irq(irq->name)) { /* * Enable interrupt at PIC level */ BSP_irq_enable_at_i8259s (irq->name); } if (is_pci_irq(irq->name)) { /* * Enable interrupt at OPENPIC level */ openpic_enable_irq ((int) irq->name - BSP_PCI_IRQ_LOWEST_OFFSET); } if (is_processor_irq(irq->name)) { /* * Enable exception at processor level */ } /* * Enable interrupt on device */ irq->on(irq); _CPU_ISR_Enable(level); return 1;}
y=cgetg(3,t_COMPLEX); y[2]=larg(x,prec); av=avma; p1=glog(gnorm(x),prec); tetpil=avma; y[1]=lpile(av,tetpil,gmul2n(p1,-1)); return y;
if (gcmp0((GEN)x[2])) return glog((GEN)x[1], prec); if (prec > LOGAGMCX_LIMIT) return logagmcx(x, prec); y = cgetg(3,t_COMPLEX); y[2] = larg(x,prec); av = avma; p1 = glog(cxnorm(x),prec); tetpil = avma; y[1] = lpile(av,tetpil,gmul2n(p1,-1)); return y;
glog(GEN x, long prec){ pari_sp av, tetpil; GEN y, p1; switch(typ(x)) { case t_REAL: if (signe(x) >= 0) { if (!signe(x)) err(talker,"zero argument in mplog"); return logr_abs(x); } y = cgetg(3,t_COMPLEX); y[1] = (long)logr_abs(x); y[2] = lmppi(lg(x)); return y; case t_COMPLEX: y=cgetg(3,t_COMPLEX); y[2]=larg(x,prec); av=avma; p1=glog(gnorm(x),prec); tetpil=avma; y[1]=lpile(av,tetpil,gmul2n(p1,-1)); return y; case t_PADIC: return palog(x); case t_INTMOD: err(typeer,"glog"); default: av = avma; if (!(y = _toser(x))) break; if (valp(y) || gcmp0(y)) err(talker,"log is not meromorphic at 0"); p1 = integ(gdiv(derivser(y), y), varn(y)); /* log(y)' = y'/y */ if (!gcmp1((GEN)y[2])) p1 = gadd(p1, glog((GEN)y[2],prec)); return gerepileupto(av, p1); } return transc(glog,x,prec);}
GEN z, y = cgetr(lg(x)); pari_sp av = avma; z = (s<0)? negr(x): x; z = mplog( addrr(z, sqrtr( addrs(mulrr(z,z), 1) )) );
GEN z = (s<0)? negr(x): x; z = logr_abs( addrr(z, sqrtr( addrs(mulrr(z,z), 1) )) );
mpash(GEN x){ long s = signe(x); GEN z, y = cgetr(lg(x)); pari_sp av = avma; z = (s<0)? negr(x): x; z = mplog( addrr(z, sqrtr( addrs(mulrr(z,z), 1) )) ); if (s<0) setsigne(z, -signe(z)); affrr(z,y); avma = av; return y;}
affrr(z,y); avma = av; return y;
return gerepileuptoleaf(av, z);
mpash(GEN x){ long s = signe(x); GEN z, y = cgetr(lg(x)); pari_sp av = avma; z = (s<0)? negr(x): x; z = mplog( addrr(z, sqrtr( addrs(mulrr(z,z), 1) )) ); if (s<0) setsigne(z, -signe(z)); affrr(z,y); avma = av; return y;}
if (expo(x) < 0) { y = cgetr(lg(x)); av = avma; affrr(mpasin(x), y); avma = av; return y; }
if (expo(x) < 0) { av = avma; return gerepileuptoleaf(av, mpasin(x)); }
gasin(GEN x, long prec){ long sx; pari_sp av; GEN a, y, p1; switch(typ(x)) { case t_REAL: sx = signe(x); if (!sx) return realzero_bit(expo(x)); if (absrnz_egal1(x)) { /* |x| = 1 */ if (sx > 0) return Pi2n(-1, lg(x)); /* 1 */ y = Pi2n(-1, lg(x)); setsigne(y, -1); return y; /* -1 */ } if (expo(x) < 0) { y = cgetr(lg(x)); av = avma; affrr(mpasin(x), y); avma = av; return y; } y = cgetg(3,t_COMPLEX); y[1] = (long)Pi2n(-1, lg(x)); y[2] = (long)mpach(x, 1); if (sx < 0) { setsigne(y[1],-signe(y[1])); setsigne(y[2],-signe(y[2])); } return y; case t_COMPLEX: av = avma; p1 = cgetg(3,t_COMPLEX); p1[1] = (long)gneg_i((GEN)x[2]); p1[2] = x[1]; y=gerepileupto(av, gash(p1,prec)); p1 = (GEN)y[1]; y[1] = y[2]; y[2] = (long)p1; setsigne(p1, -signe(p1)); return y; case t_INTMOD: case t_PADIC: err(typeer,"gasin"); default: av = avma; if (!(y = _toser(x))) break; if (gcmp0(y)) return gcopy(y); /* lg(y) > 2*/ if (valp(y) < 0) err(negexper,"gasin"); p1 = gdiv(derivser(y), gsqrt(gsubsg(1,gsqr(y)),prec)); a = integ(p1,varn(y)); if (!valp(y)) a = gadd(a, gasin((GEN)y[2],prec)); return gerepileupto(av, a); } return transc(gasin,x,prec);}
long l = lg(x); GEN z, y = cgetr(l);
mpach(GEN x, long s){ long l = lg(x); GEN z, y = cgetr(l); pari_sp av = avma; if (s != signe(x)) { x = rcopy(x); setsigne(x, s); } z = mplog( addrr(x, sqrtr( subrs(mulrr(x,x), 1) )) ); affrr(z,y); avma = av; return y;}
if (s != signe(x)) { x = rcopy(x); setsigne(x, s); } z = mplog( addrr(x, sqrtr( subrs(mulrr(x,x), 1) )) ); affrr(z,y); avma = av; return y;
GEN z = logr_abs( addrr_sign(x, s, sqrtr( subrs(mulrr(x,x), 1) ), 1) ); return gerepileuptoleaf(av, z);
mpach(GEN x, long s){ long l = lg(x); GEN z, y = cgetr(l); pari_sp av = avma; if (s != signe(x)) { x = rcopy(x); setsigne(x, s); } z = mplog( addrr(x, sqrtr( subrs(mulrr(x,x), 1) )) ); affrr(z,y); avma = av; return y;}
long l = lg(x); GEN y = cgetr(l);
mpacos(GEN x){ long l = lg(x); GEN y = cgetr(l); pari_sp av = avma; affrr( subrr(Pi2n(-1,l), mpasin(x)), y ); avma = av; return y;}
affrr( subrr(Pi2n(-1,l), mpasin(x)), y ); avma = av; return y;
return gerepileuptoleaf(av, subrr(Pi2n(-1,lg(x)), mpasin(x)));
mpacos(GEN x){ long l = lg(x); GEN y = cgetr(l); pari_sp av = avma; affrr( subrr(Pi2n(-1,l), mpasin(x)), y ); avma = av; return y;}
errno = ENOSYS; return -1;
off_t status; status = lseek( dirp->dd_fd, 0, SEEK_SET ); if( status == -1 ) return; dirp->dd_loc = 0;
void rewinddir( DIR *dirp){ errno = ENOSYS; return -1;}
if (!signe(x)) { y=cgetr(3); y[1] = evalexpo((expo(x)<<1) - 1); y[2] = 0; *ptmod8=0; return y; }
if (!signe(x)) { *ptmod8=0; return realzero_bit((expo(x)<<1) - 1); }
mpsc1(GEN x, long *ptmod8){ const long mmax = 23169; /* on a 64-bit machine with true 128 bit/64 bit division, one could * take mmax=1518500248; on the alpha it does not seem worthwhile */ long l,l0,l1,l2,l4,ee,i,n,m,s,t,av; double alpha,beta,a,b,c,d; GEN y,p1,p2,p3,p4,pitemp; if (typ(x)!=t_REAL) err(typeer,"mpsc1"); if (!signe(x)) { y=cgetr(3); y[1] = evalexpo((expo(x)<<1) - 1); y[2] = 0; *ptmod8=0; return y; } l=lg(x); y=cgetr(l); av=avma; l++; pitemp = mppi(l+1); setexpo(pitemp,-1); p1 = addrr(x,pitemp); setexpo(pitemp,0); if (expo(p1) >= bit_accuracy(min(l,lg(p1))) + 3) err(precer,"mpsc1"); p3 = divrr(p1,pitemp); p2 = mpent(p3); if (signe(p2)) x = subrr(x, mulir(p2,pitemp)); p1 = cgetr(l+1); affrr(x, p1); *ptmod8 = (signe(p1) < 0)? 4: 0; if (signe(p2)) { long mod4 = mod4(p2); if (signe(p2) < 0 && mod4) mod4 = 4-mod4; *ptmod8 += mod4; } if (gcmp0(p1)) alpha=1000000.0; else { m=expo(p1); alpha=(m<-1022)? -1-m*LOG2: -1-log(fabs(rtodbl(p1))); } beta = 5 + bit_accuracy(l)*LOG2; a=0.5/LOG2; b=0.5*a; c = a+sqrt((beta+b)/LOG2); d = ((beta/c)-alpha-log(c))/LOG2; if (d>=0) { m=(long)(1+d); n=(long)((1+c)/2.0); setexpo(p1,expo(p1)-m); } else { m=0; n=(long)((1+beta/alpha)/2.0); } l2=l+1+(m>>TWOPOTBITS_IN_LONG); p2=realun(l2); setlg(p2,4); p4=cgetr(l2); av = avma; affrr(gsqr(p1),p4); setlg(p4,4); if (n>mmax) p3 = divrs(divrs(p4,2*n+2),2*n+1); else p3 = divrs(p4, (2*n+2)*(2*n+1)); ee = -expo(p3); s=0; l4 = l1 = 3 + (ee>>TWOPOTBITS_IN_LONG); if (l4<=l2) { setlg(p2,l4); setlg(p4,l4); } for (i=n; i>mmax; i--) { p3 = divrs(divrs(p4,2*i),2*i-1); s -= expo(p3); t=s&(BITS_IN_LONG-1); l0=(s>>TWOPOTBITS_IN_LONG); if (t) l0++; l1 += l0; if (l1>l2) { l0 += l2-l1; l1=l2; } l4 += l0; p3 = mulrr(p3,p2); if (l4<=l2) { setlg(p2,l4); setlg(p4,l4); } subsrz(1,p3,p2); avma=av; } for ( ; i>=2; i--) { p3 = divrs(p4, 2*i*(2*i-1)); s -= expo(p3); t=s&(BITS_IN_LONG-1); l0=(s>>TWOPOTBITS_IN_LONG); if (t) l0++; l1 += l0; if (l1>l2) { l0 += l2-l1; l1=l2; } l4 += l0; p3 = mulrr(p3,p2); if (l4<=l2) { setlg(p2,l4); setlg(p4,l4); } subsrz(1,p3,p2); avma=av; } if (l4<=l2) { setlg(p2,l4); setlg(p4,l4); } setexpo(p4,expo(p4)-1); setsigne(p4, -signe(p4)); p2 = mulrr(p4,p2); for (i=1; i<=m; i++) { p2 = mulrr(p2,addsr(2,p2)); setexpo(p2,expo(p2)+1); } affrr(p2,y); avma=av; return y;}
affrr(p4,y); avma = av0; return y;
affr_fixlg(p4,y); avma = av0; return y;
mpatan(GEN x){ long l, l1, l2, n, m, i, lp, e, s, sx = signe(x); pari_sp av0, av; double alpha, beta, delta; GEN y, p1, p2, p3, p4, p5, unr; int inv; if (!sx) return realzero_bit(expo(x)); l = lp = lg(x); if (absrnz_egal1(x)) { /* |x| = 1 */ y = Pi2n(-2, l+1); if (sx < 0) setsigne(y,-1); return y; } e = expo(x); inv = (e >= 0); /* = (|x| > 1 ) */ if (e > 0) lp += (e>>TWOPOTBITS_IN_LONG); y = cgetr(lp); av0 = avma; p1 = cgetr(l+1); affrr(x,p1); setsigne(p1, 1); /* p1 = |x| */ if (inv) p1 = divsr(1, p1); e = expo(p1); if (e < -100) alpha = 1.65149612947 - e; /* log_2(Pi) - e */ else alpha = log2(PI / atan(rtodbl(p1))); beta = (double)(bit_accuracy(l)>>1); delta = 1 + beta - alpha/2; if (delta <= 0) { n = 1; m = 0; } else { double fi = alpha-2;#if 0 const double gama = 1.; /* optimize this */ if (delta >= gama*fi*fi) { n = (long)(1+sqrt(gama*delta)); m = (long)(1+sqrt(delta/gama) - fi); }#else if (delta >= fi*fi) { double t = 1 + sqrt(delta); n = (long)t; m = (long)(t - fi); }#endif else { n = (long)(1+beta/fi); m = 0; } } l2 = l+1+(m>>TWOPOTBITS_IN_LONG); p2 = cgetr(l2); affrr(p1,p2); av = avma; for (i=1; i<=m; i++) { p5 = addsr(1, mulrr(p2,p2)); setlg(p5,l2); p5 = addsr(1, sqrtr_abs(p5)); setlg(p5,l2); affrr(divrr(p2,p5), p2); avma = av; } p3 = mulrr(p2,p2); l1 = 4; unr = realun(l2); setlg(unr,4); p4 = cgetr(l2); setlg(p4,4); affrr(divrs(unr,2*n+1), p4); s = 0; e = expo(p3); av = avma; for (i = n; i > 1; i--) /* n >= 1. i = 1 done outside for efficiency */ { setlg(p3,l1); p5 = mulrr(p4,p3); s -= e; l1 += (s>>TWOPOTBITS_IN_LONG); s %= BITS_IN_LONG; if (l1 > l2) l1 = l2; setlg(unr,l1); p5 = subrr(divrs(unr,2*i-1), p5); setlg(p4,l1); affrr(p5,p4); avma = av; } setlg(p3, l2); p5 = mulrr(p4,p3); /* i = 1 */ setlg(unr,l2); p4 = subrr(unr, p5); p4 = mulrr(p2,p4); setexpo(p4, expo(p4)+m); if (inv) p4 = subrr(Pi2n(-1, lp), p4); if (sx < 0) setsigne(p4,-signe(p4)); affrr(p4,y); avma = av0; return y;}
p1 = mplog( addrs(divsr(2,addsr(-1,x)),1) );
p1 = logr_abs( addrs(divsr(2,addsr(-1,x)),1) );
gath(GEN x, long prec){ pari_sp av; GEN a, y, p1; switch(typ(x)) { case t_REAL: if (!signe(x)) return realzero_bit(expo(x)); if (expo(x) < 0) return mpath(x); y = cgetg(3,t_COMPLEX); av = avma; p1 = mplog( addrs(divsr(2,addsr(-1,x)),1) ); setexpo(p1, expo(p1)-1); y[1]=(long)gerepileuptoleaf(av, p1); y[2]=(long)Pi2n(-1, lg(x)); return y; case t_COMPLEX: av = avma; p1 = glog( gaddgs(gdivsg(2,gsubsg(1,x)),-1), prec ); return gerepileupto(av, gmul2n(p1,-1)); case t_INTMOD: case t_PADIC: err(typeer,"gath"); default: av = avma; if (!(y = _toser(x))) break; if (valp(y) < 0) err(negexper,"gath"); p1 = gdiv(derivser(y), gsubsg(1,gsqr(y))); a = integ(p1, varn(y)); if (!valp(y)) a = gadd(a, gath((GEN)y[2],prec)); return gerepileupto(av, a); } return transc(gath,x,prec);}
if (ma > 962353) err(talker, "argument too large in ggamma");
gammahs(long m, long prec){ GEN y = cgetr(prec), z; pari_sp av = avma; long ma = labs(m); if (ma > 962353) err(talker, "argument too large in ggamma"); if (ma > 200 + 50*(prec-2)) /* heuristic */ { z = stor(m + 1, prec); setexpo(z, expo(z)-1); affrr(cxgamma(z,0,prec), y); avma = av; return y; } z = sqrtr( mppi(prec) ); if (m) { GEN p1 = seq_umul(ma/2 + 1, ma); long v = vali(p1); p1 = shifti(p1, -v); v -= ma; if (m >= 0) z = mulri(z,p1); else { z = divri(z,p1); v = -v; if ((m&3) == 2) setsigne(z,-1); } setexpo(z, expo(z) + v); } affrr(z, y); avma = av; return y;}
y = cgetr(prec); av = avma; p1 = mplog( itor(mpfact(itos(x) - 1), prec) ); affrr(p1, y); avma = av; return y;
av = avma; return gerepileuptoleaf(av, logr_abs( itor(mpfact(itos(x) - 1), prec) ));
glngamma(GEN x, long prec){ long i, n; pari_sp av; GEN a, y, p1; switch(typ(x)) { case t_INT: if (signe(x) <= 0) err(talker,"non-positive integer in glngamma"); if (cmpis(x,200 + 50*(prec-2)) > 0) /* heuristic */ return cxgamma(x, 1, prec); y = cgetr(prec); av = avma; p1 = mplog( itor(mpfact(itos(x) - 1), prec) ); affrr(p1, y); avma = av; return y; case t_REAL: case t_COMPLEX: return cxgamma(x, 1, prec); default: av = avma; if (!(y = _toser(x))) break; if (valp(y)) err(negexper,"glngamma"); p1 = gsubsg(1,y); if (!valp(p1)) err(impl,"lngamma around a!=1"); n = (lg(y)-3) / valp(p1); a = zeroser(varn(y), lg(y)-2); for (i=n; i>=2; i--) a = gmul(p1, gadd(a, gdivgs(szeta(i, prec),i))); a = gadd(a, mpeuler(prec)); return gerepileupto(av, gmul(a, p1)); case t_PADIC: err(impl,"p-adic lngamma function"); case t_INTMOD: err(typeer,"glngamma"); } return transc(glngamma,x,prec);}
return mpgamd(itos(x),prec);
{ long k = itos(x); if (labs(k) > 962353) err(talker, "argument too large in ggamd"); return gammahs(k<<1, prec); }
ggamd(GEN x, long prec){ pari_sp av, tetpil; switch(typ(x)) { case t_INT: return mpgamd(itos(x),prec); case t_REAL: case t_FRAC: case t_COMPLEX: case t_QUAD: av=avma; x = gadd(x,ghalf); tetpil=avma; return gerepile(av,tetpil,ggamma(x,prec)); case t_INTMOD: case t_PADIC: err(typeer,"ggamd"); case t_SER: err(impl,"gamd of a power series"); } return transc(ggamd,x,prec);}
if (signe(sig) <= 0) { GEN pi = mppi(prec); z = gsub(cxpsi(gsub(gun,s), prec), gmul(pi, gcotan(gmul(pi,s), prec))); gaffect(z, res); avma = av; return res; }
if (signe(sig) <= 0) { funeq = 1; s = gsub(gun, s); sig = real_i(s); } if (typ(s0) == t_INT && signe(s0) <= 0) err(talker,"non-positive integer argument in cxpsi");
cxpsi(GEN s0, long prec){ pari_sp av, av2; GEN sum,z,a,res,tes,in2,sig,s,unr; long lim,nn,k; const long la = 3; if (DEBUGLEVEL>2) (void)timer2(); s = trans_fix_arg(&prec,&s0,&sig,&av,&res); if (signe(sig) <= 0) { GEN pi = mppi(prec); z = gsub(cxpsi(gsub(gun,s), prec), gmul(pi, gcotan(gmul(pi,s), prec))); gaffect(z, res); avma = av; return res; } { double ssig = rtodbl(sig); double st = rtodbl(imag_i(s)); double l; { double rlog, ilog; /* log (s - Euler) */ dcxlog(ssig - 0.57721566, st, &rlog,&ilog); l = dnorm(rlog,ilog); } if (l < 0.000001) l = 0.000001; l = log(l) / 2.; lim = 2 + (long)ceil((bit_accuracy_mul(prec, LOG2) - l) / (2*(1+log((double)la)))); if (lim < 2) lim = 2; l = (2*lim-1)*la / (2.*PI); l = l*l - st*st; if (l < 0.) l = 0.; nn = (long)ceil( sqrt(l) - ssig ); if (nn < 1) nn = 1; if (DEBUGLEVEL>2) fprintferr("lim, nn: [%ld, %ld]\n",lim,nn); } prec++; unr = realun(prec); /* one extra word of precision */ a = gdiv(unr, gaddgs(s, nn)); /* 1 / (s+n) */ av2 = avma; sum = gmul2n(a,-1); for (k = 0; k < nn; k++) { sum = gadd(sum, gdiv(unr, gaddgs(s, k))); if ((k & 127) == 0) sum = gerepileupto(av2, sum); } z = gsub(glog(gaddgs(s, nn), prec), sum); if (DEBUGLEVEL>2) msgtimer("sum from 0 to N-1"); in2 = gsqr(a); av2 = avma; tes = divrs(bernreal(2*lim, prec), 2*lim); for (k=2*lim-2; k>=2; k-=2) { tes = gadd(gmul(in2,tes), divrs(bernreal(k, prec), k)); if ((k & 255) == 0) tes = gerepileupto(av2, tes); } if (DEBUGLEVEL>2) msgtimer("Bernoulli sum"); z = gsub(z, gmul(in2,tes)); gaffect(z, res); avma = av; return res;}
gaffect(z, res); avma = av; return res;
if (funeq) { GEN pi = mppi(prec); z = gadd(z, gmul(pi, gcotan(gmul(pi,s), prec))); } if (typ(z) == t_REAL) affr_fixlg(z, res); else { affr_fixlg((GEN)z[1], (GEN)res[1]); affr_fixlg((GEN)z[2], (GEN)res[2]); } avma = av; return res;
cxpsi(GEN s0, long prec){ pari_sp av, av2; GEN sum,z,a,res,tes,in2,sig,s,unr; long lim,nn,k; const long la = 3; if (DEBUGLEVEL>2) (void)timer2(); s = trans_fix_arg(&prec,&s0,&sig,&av,&res); if (signe(sig) <= 0) { GEN pi = mppi(prec); z = gsub(cxpsi(gsub(gun,s), prec), gmul(pi, gcotan(gmul(pi,s), prec))); gaffect(z, res); avma = av; return res; } { double ssig = rtodbl(sig); double st = rtodbl(imag_i(s)); double l; { double rlog, ilog; /* log (s - Euler) */ dcxlog(ssig - 0.57721566, st, &rlog,&ilog); l = dnorm(rlog,ilog); } if (l < 0.000001) l = 0.000001; l = log(l) / 2.; lim = 2 + (long)ceil((bit_accuracy_mul(prec, LOG2) - l) / (2*(1+log((double)la)))); if (lim < 2) lim = 2; l = (2*lim-1)*la / (2.*PI); l = l*l - st*st; if (l < 0.) l = 0.; nn = (long)ceil( sqrt(l) - ssig ); if (nn < 1) nn = 1; if (DEBUGLEVEL>2) fprintferr("lim, nn: [%ld, %ld]\n",lim,nn); } prec++; unr = realun(prec); /* one extra word of precision */ a = gdiv(unr, gaddgs(s, nn)); /* 1 / (s+n) */ av2 = avma; sum = gmul2n(a,-1); for (k = 0; k < nn; k++) { sum = gadd(sum, gdiv(unr, gaddgs(s, k))); if ((k & 127) == 0) sum = gerepileupto(av2, sum); } z = gsub(glog(gaddgs(s, nn), prec), sum); if (DEBUGLEVEL>2) msgtimer("sum from 0 to N-1"); in2 = gsqr(a); av2 = avma; tes = divrs(bernreal(2*lim, prec), 2*lim); for (k=2*lim-2; k>=2; k-=2) { tes = gadd(gmul(in2,tes), divrs(bernreal(k, prec), k)); if ((k & 255) == 0) tes = gerepileupto(av2, tes); } if (DEBUGLEVEL>2) msgtimer("Bernoulli sum"); z = gsub(z, gmul(in2,tes)); gaffect(z, res); avma = av; return res;}
mips_set_sr(sr & ~SR_IE);
mips_set_sr( (sr & ~SR_IE) );
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr, srbits; /* ** mask off the int level bits only so we can ** preserve software int settings and FP enable ** for this thread. Note we don't force software ints ** enabled when changing level, they were turned on ** when this task was created, but may have been turned ** off since, so we'll just leave them alone. */ mips_get_sr(sr);#if __mips == 3 mips_set_sr(sr & ~SR_IE); /* first disable ie bit (recommended) */ srbits = sr & ~(0xfc00 | SR_EXL | SR_IE); sr = srbits | ((new_level==0)? (0xfc00 | SR_EXL | SR_IE): \ (((new_level<<9) & 0xfc000) | \ (new_level & 1)?(SR_EXL | SR_IE):0));/* if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; * clear the EXL bit * mips_set_sr(sr); } else { sr |= SR_EXL|SR_IE; * enable exception level * mips_set_sr(sr); * first disable ie bit (recommended) * }*/ #elif __mips == 1 mips_set_sr( (sr & ~SR_IEC) ); srbits = sr & ~(0xfc00 | SR_IEC); sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc000) | (new_level & 1)));#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif mips_set_sr( sr );}
(((new_level<<9) & 0xfc000) | \
(((new_level<<9) & 0xfc00) | \
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr, srbits; /* ** mask off the int level bits only so we can ** preserve software int settings and FP enable ** for this thread. Note we don't force software ints ** enabled when changing level, they were turned on ** when this task was created, but may have been turned ** off since, so we'll just leave them alone. */ mips_get_sr(sr);#if __mips == 3 mips_set_sr(sr & ~SR_IE); /* first disable ie bit (recommended) */ srbits = sr & ~(0xfc00 | SR_EXL | SR_IE); sr = srbits | ((new_level==0)? (0xfc00 | SR_EXL | SR_IE): \ (((new_level<<9) & 0xfc000) | \ (new_level & 1)?(SR_EXL | SR_IE):0));/* if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; * clear the EXL bit * mips_set_sr(sr); } else { sr |= SR_EXL|SR_IE; * enable exception level * mips_set_sr(sr); * first disable ie bit (recommended) * }*/ #elif __mips == 1 mips_set_sr( (sr & ~SR_IEC) ); srbits = sr & ~(0xfc00 | SR_IEC); sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc000) | (new_level & 1)));#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif mips_set_sr( sr );}
sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc000) | (new_level & 1)));
sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc00) | \ (new_level & SR_IEC)));
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr, srbits; /* ** mask off the int level bits only so we can ** preserve software int settings and FP enable ** for this thread. Note we don't force software ints ** enabled when changing level, they were turned on ** when this task was created, but may have been turned ** off since, so we'll just leave them alone. */ mips_get_sr(sr);#if __mips == 3 mips_set_sr(sr & ~SR_IE); /* first disable ie bit (recommended) */ srbits = sr & ~(0xfc00 | SR_EXL | SR_IE); sr = srbits | ((new_level==0)? (0xfc00 | SR_EXL | SR_IE): \ (((new_level<<9) & 0xfc000) | \ (new_level & 1)?(SR_EXL | SR_IE):0));/* if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; * clear the EXL bit * mips_set_sr(sr); } else { sr |= SR_EXL|SR_IE; * enable exception level * mips_set_sr(sr); * first disable ie bit (recommended) * }*/ #elif __mips == 1 mips_set_sr( (sr & ~SR_IEC) ); srbits = sr & ~(0xfc00 | SR_IEC); sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc000) | (new_level & 1)));#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif mips_set_sr( sr );}
unsigned32 vector,
uint32_t vector,
void _CPU_ISR_install_raw_handler( unsigned32 vector, proc_ptr new_handler, proc_ptr *old_handler){ proc_ptr *interrupt_table = NULL;#if (M68K_HAS_FPSP_PACKAGE == 1) /* * If this vector being installed is one related to FP, then the * FPSP will install the handler itself and handle it completely * with no intervention from RTEMS. */ if (*_FPSP_install_raw_handler && (*_FPSP_install_raw_handler)(vector, new_handler, *old_handler)) return;#endif /* * On CPU models without a VBR, it is necessary for there to be some * header code for each ISR which saves a register, loads the vector * number, and jumps to _ISR_Handler. */ m68k_get_vbr( interrupt_table );#if ( M68K_HAS_VBR == 1 ) *old_handler = interrupt_table[ vector ]; interrupt_table[ vector ] = new_handler;#else /* * Install handler into RTEMS jump table and if VBR table is in * RAM, install the pointer to the appropriate jump table slot. * If the VBR table is in ROM, it is the BSP's responsibility to * load it appropriately to vector to the RTEMS jump table. */ *old_handler = (proc_ptr) _CPU_ISR_jump_table[vector].isr_handler; _CPU_ISR_jump_table[vector].isr_handler = (unsigned32) new_handler; if ( (unsigned32) interrupt_table != 0xFFFFFFFF ) interrupt_table[ vector ] = (proc_ptr) &_CPU_ISR_jump_table[vector];#endif /* M68K_HAS_VBR */}
_CPU_ISR_jump_table[vector].isr_handler = (unsigned32) new_handler; if ( (unsigned32) interrupt_table != 0xFFFFFFFF )
_CPU_ISR_jump_table[vector].isr_handler = (uint32_t ) new_handler; if ( (uint32_t ) interrupt_table != 0xFFFFFFFF )
void _CPU_ISR_install_raw_handler( unsigned32 vector, proc_ptr new_handler, proc_ptr *old_handler){ proc_ptr *interrupt_table = NULL;#if (M68K_HAS_FPSP_PACKAGE == 1) /* * If this vector being installed is one related to FP, then the * FPSP will install the handler itself and handle it completely * with no intervention from RTEMS. */ if (*_FPSP_install_raw_handler && (*_FPSP_install_raw_handler)(vector, new_handler, *old_handler)) return;#endif /* * On CPU models without a VBR, it is necessary for there to be some * header code for each ISR which saves a register, loads the vector * number, and jumps to _ISR_Handler. */ m68k_get_vbr( interrupt_table );#if ( M68K_HAS_VBR == 1 ) *old_handler = interrupt_table[ vector ]; interrupt_table[ vector ] = new_handler;#else /* * Install handler into RTEMS jump table and if VBR table is in * RAM, install the pointer to the appropriate jump table slot. * If the VBR table is in ROM, it is the BSP's responsibility to * load it appropriately to vector to the RTEMS jump table. */ *old_handler = (proc_ptr) _CPU_ISR_jump_table[vector].isr_handler; _CPU_ISR_jump_table[vector].isr_handler = (unsigned32) new_handler; if ( (unsigned32) interrupt_table != 0xFFFFFFFF ) interrupt_table[ vector ] = (proc_ptr) &_CPU_ISR_jump_table[vector];#endif /* M68K_HAS_VBR */}
Objects_Name name,
rtems_name name,
rtems_status_code rtems_message_queue_create( Objects_Name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !_Objects_Is_name_valid( name ) ) return ( RTEMS_INVALID_NAME ); if ( _Attributes_Is_global( attribute_set ) && !_Configuration_Is_multiprocessing() ) return( RTEMS_MP_NOT_CONFIGURED ); if (count == 0) return RTEMS_INVALID_NUMBER; if (max_message_size == 0) return RTEMS_INVALID_SIZE;#if 1 /* * I am not 100% sure this should be an error. * It seems reasonable to create a que with a large max size, * and then just send smaller msgs from remote (or all) nodes. */ if ( _Attributes_Is_global( attribute_set ) && _Configuration_MPCI_table && (_Configuration_MPCI_table->maximum_packet_size < max_message_size)) { return RTEMS_INVALID_SIZE; }#endif _Thread_Disable_dispatch(); /* protects object pointer */ the_message_queue = _Message_queue_Allocate(count, max_message_size); if ( !the_message_queue ) { _Thread_Enable_dispatch(); return( RTEMS_TOO_MANY ); } if ( _Attributes_Is_global( attribute_set ) && !( _Objects_MP_Open( &_Message_queue_Information, name, the_message_queue->Object.id, FALSE ) ) ) { _Message_queue_Free( the_message_queue ); _Thread_Enable_dispatch(); return RTEMS_TOO_MANY; } the_message_queue->maximum_pending_messages = count; the_message_queue->attribute_set = attribute_set; the_message_queue->number_of_pending_messages = 0; _Chain_Initialize_empty( &the_message_queue->Pending_messages ); _Thread_queue_Initialize( &the_message_queue->Wait_queue, attribute_set, STATES_WAITING_FOR_MESSAGE ); _Objects_Open( &_Message_queue_Information, &the_message_queue->Object, name ); *id = the_message_queue->Object.id; if ( _Attributes_Is_global( attribute_set ) ) _Message_queue_MP_Send_process_packet( MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, the_message_queue->Object.id, name, 0 ); _Thread_Enable_dispatch(); return( RTEMS_SUCCESSFUL );}
if ( !_Objects_Is_name_valid( name ) )
if ( !rtems_is_name_valid( name ) )
rtems_status_code rtems_message_queue_create( Objects_Name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !_Objects_Is_name_valid( name ) ) return ( RTEMS_INVALID_NAME ); if ( _Attributes_Is_global( attribute_set ) && !_Configuration_Is_multiprocessing() ) return( RTEMS_MP_NOT_CONFIGURED ); if (count == 0) return RTEMS_INVALID_NUMBER; if (max_message_size == 0) return RTEMS_INVALID_SIZE;#if 1 /* * I am not 100% sure this should be an error. * It seems reasonable to create a que with a large max size, * and then just send smaller msgs from remote (or all) nodes. */ if ( _Attributes_Is_global( attribute_set ) && _Configuration_MPCI_table && (_Configuration_MPCI_table->maximum_packet_size < max_message_size)) { return RTEMS_INVALID_SIZE; }#endif _Thread_Disable_dispatch(); /* protects object pointer */ the_message_queue = _Message_queue_Allocate(count, max_message_size); if ( !the_message_queue ) { _Thread_Enable_dispatch(); return( RTEMS_TOO_MANY ); } if ( _Attributes_Is_global( attribute_set ) && !( _Objects_MP_Open( &_Message_queue_Information, name, the_message_queue->Object.id, FALSE ) ) ) { _Message_queue_Free( the_message_queue ); _Thread_Enable_dispatch(); return RTEMS_TOO_MANY; } the_message_queue->maximum_pending_messages = count; the_message_queue->attribute_set = attribute_set; the_message_queue->number_of_pending_messages = 0; _Chain_Initialize_empty( &the_message_queue->Pending_messages ); _Thread_queue_Initialize( &the_message_queue->Wait_queue, attribute_set, STATES_WAITING_FOR_MESSAGE ); _Objects_Open( &_Message_queue_Information, &the_message_queue->Object, name ); *id = the_message_queue->Object.id; if ( _Attributes_Is_global( attribute_set ) ) _Message_queue_MP_Send_process_packet( MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, the_message_queue->Object.id, name, 0 ); _Thread_Enable_dispatch(); return( RTEMS_SUCCESSFUL );}
_Objects_Open( &_Message_queue_Information, &the_message_queue->Object, name );
_Objects_Open( &_Message_queue_Information, &the_message_queue->Object, &name );
rtems_status_code rtems_message_queue_create( Objects_Name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !_Objects_Is_name_valid( name ) ) return ( RTEMS_INVALID_NAME ); if ( _Attributes_Is_global( attribute_set ) && !_Configuration_Is_multiprocessing() ) return( RTEMS_MP_NOT_CONFIGURED ); if (count == 0) return RTEMS_INVALID_NUMBER; if (max_message_size == 0) return RTEMS_INVALID_SIZE;#if 1 /* * I am not 100% sure this should be an error. * It seems reasonable to create a que with a large max size, * and then just send smaller msgs from remote (or all) nodes. */ if ( _Attributes_Is_global( attribute_set ) && _Configuration_MPCI_table && (_Configuration_MPCI_table->maximum_packet_size < max_message_size)) { return RTEMS_INVALID_SIZE; }#endif _Thread_Disable_dispatch(); /* protects object pointer */ the_message_queue = _Message_queue_Allocate(count, max_message_size); if ( !the_message_queue ) { _Thread_Enable_dispatch(); return( RTEMS_TOO_MANY ); } if ( _Attributes_Is_global( attribute_set ) && !( _Objects_MP_Open( &_Message_queue_Information, name, the_message_queue->Object.id, FALSE ) ) ) { _Message_queue_Free( the_message_queue ); _Thread_Enable_dispatch(); return RTEMS_TOO_MANY; } the_message_queue->maximum_pending_messages = count; the_message_queue->attribute_set = attribute_set; the_message_queue->number_of_pending_messages = 0; _Chain_Initialize_empty( &the_message_queue->Pending_messages ); _Thread_queue_Initialize( &the_message_queue->Wait_queue, attribute_set, STATES_WAITING_FOR_MESSAGE ); _Objects_Open( &_Message_queue_Information, &the_message_queue->Object, name ); *id = the_message_queue->Object.id; if ( _Attributes_Is_global( attribute_set ) ) _Message_queue_MP_Send_process_packet( MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, the_message_queue->Object.id, name, 0 ); _Thread_Enable_dispatch(); return( RTEMS_SUCCESSFUL );}
Objects_Name name,
rtems_name name,
rtems_status_code rtems_message_queue_ident( Objects_Name name, unsigned32 node, Objects_Id *id){ return( _Objects_Name_to_id( &_Message_queue_Information, name, node, id ) );}
return( _Objects_Name_to_id( &_Message_queue_Information, name, node, id ) );
return _Objects_Name_to_id( &_Message_queue_Information, &name, node, id );
rtems_status_code rtems_message_queue_ident( Objects_Name name, unsigned32 node, Objects_Id *id){ return( _Objects_Name_to_id( &_Message_queue_Information, name, node, id ) );}
fs_info->ino_count = 1; fs_info->memfile_handlers = memfile_handlers; fs_info->memfile_handlers = directory_handlers;
fs_info->ino_count = 1; fs_info->memfile_handlers = memfile_handlers; fs_info->directory_handlers = directory_handlers;
int IMFS_initialize_support( rtems_filesystem_mount_table_entry_t *temp_mt_entry, rtems_filesystem_operations_table *op_table, rtems_filesystem_file_handlers_r *memfile_handlers, rtems_filesystem_file_handlers_r *directory_handlers){ IMFS_fs_info_t *fs_info; IMFS_jnode_t *jnode; /* * Create the root node */ temp_mt_entry->mt_fs_root.node_access = IMFS_create_node( NULL, IMFS_DIRECTORY, "", ( S_IRWXO | S_IRWXG| S_IRWXU ), NULL ); temp_mt_entry->mt_fs_root.handlers = directory_handlers; temp_mt_entry->mt_fs_root.ops = op_table; temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS; /* * Create custom file system data. */ fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) ); if ( !fs_info ){ free(temp_mt_entry->mt_fs_root.node_access); return 1; } temp_mt_entry->fs_info = fs_info; /* * Set st_ino for the root to 1. */ fs_info->ino_count = 1; fs_info->memfile_handlers = memfile_handlers; fs_info->memfile_handlers = directory_handlers; jnode = temp_mt_entry->mt_fs_root.node_access; jnode->st_ino = fs_info->ino_count; return 0;}
unsigned32 baudrate
uint32_t baudrate
int termios_printk_open/*-------------------------------------------------------------------------*\| Purpose: || try to open given serial debug port |+---------------------------------------------------------------------------+| Input Parameters: |\*-------------------------------------------------------------------------*/( const char *dev_name, /* name of device to open */ unsigned32 baudrate /* baud rate to use */)/*-------------------------------------------------------------------------*\| Return Value: || 0 on success, -1 and errno otherwise |\*=========================================================================*/{ boolean err_occurred = FALSE; rtems_libio_t *iop = NULL; struct termios act_termios; tcflag_t baudcode = B0; if (termios_printk_fd >= 0) { /* * already initialized */ return 0; } /* * translate baudrate into baud code */ switch(baudrate) { case 50: baudcode = B50; break; case 75: baudcode = B75; break; case 110: baudcode = B110; break; case 134: baudcode = B134; break; case 150: baudcode = B150; break; case 200: baudcode = B200; break; case 300: baudcode = B300; break; case 600: baudcode = B600; break; case 1200: baudcode = B1200; break; case 1800: baudcode = B1800; break; case 2400: baudcode = B2400; break; case 4800: baudcode = B4800; break; case 9600: baudcode = B9600; break; case 19200: baudcode = B19200; break; case 38400: baudcode = B38400; break; case 57600: baudcode = B57600; break; case 115200: baudcode = B115200; break; case 230400: baudcode = B230400; break; case 460800: baudcode = B460800; break; default : err_occurred = TRUE; errno = EINVAL; break; } /* * open device for serdbg operation */ if (!err_occurred && (dev_name != NULL) && (dev_name[0] != '\0')) { termios_printk_fd = open(dev_name,O_RDWR); if (termios_printk_fd < 0) { err_occurred = TRUE; } } /* * capture tty structure */ if (!err_occurred) { iop = &rtems_libio_iops[termios_printk_fd]; termios_printk_tty = iop->data1; } /* * set device baudrate * (and transp mode, this is not really needed) * ... */ /* * ... get fd settings */ if (!err_occurred && (0 != tcgetattr(termios_printk_fd,&act_termios))) { err_occurred = TRUE; } if (!err_occurred) { cfsetospeed(&act_termios,baudcode); cfsetispeed(&act_termios,baudcode); if (0 != tcsetattr(termios_printk_fd,TCSANOW,&act_termios)) { err_occurred = TRUE; } } if (!err_occurred) { BSP_output_char = termios_printk_outputchar; BSP_poll_char = termios_printk_inputchar; } return (err_occurred ? -1 : 0);}
short val;
unsigned long val;
sosetopt(so, level, optname, m0) register struct socket *so; int level, optname; struct mbuf *m0;{ int error = 0; register struct mbuf *m = m0; if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) return ((*so->so_proto->pr_ctloutput) (PRCO_SETOPT, so, level, optname, &m0)); error = ENOPROTOOPT; } else { switch (optname) { case SO_LINGER: if (m == NULL || m->m_len != sizeof (struct linger)) { error = EINVAL; goto bad; } so->so_linger = mtod(m, struct linger *)->l_linger; /* fall thru... */ case SO_DEBUG: case SO_KEEPALIVE: case SO_DONTROUTE: case SO_USELOOPBACK: case SO_BROADCAST: case SO_REUSEADDR: case SO_REUSEPORT: case SO_OOBINLINE: case SO_TIMESTAMP: if (m == NULL || m->m_len < sizeof (int)) { error = EINVAL; goto bad; } if (*mtod(m, int *)) so->so_options |= optname; else so->so_options &= ~optname; break; case SO_SNDBUF: case SO_RCVBUF: case SO_SNDLOWAT: case SO_RCVLOWAT: { int optval; if (m == NULL || m->m_len < sizeof (int)) { error = EINVAL; goto bad; } /* * Values < 1 make no sense for any of these * options, so disallow them. */ optval = *mtod(m, int *); if (optval < 1) { error = EINVAL; goto bad; } switch (optname) { case SO_SNDBUF: case SO_RCVBUF: if (sbreserve(optname == SO_SNDBUF ? &so->so_snd : &so->so_rcv, (u_long) optval) == 0) { error = ENOBUFS; goto bad; } break; /* * Make sure the low-water is never greater than * the high-water. */ case SO_SNDLOWAT: so->so_snd.sb_lowat = (optval > so->so_snd.sb_hiwat) ? so->so_snd.sb_hiwat : optval; break; case SO_RCVLOWAT: so->so_rcv.sb_lowat = (optval > so->so_rcv.sb_hiwat) ? so->so_rcv.sb_hiwat : optval; break; } break; } case SO_SNDTIMEO: case SO_RCVTIMEO: { struct timeval *tv; short val; if (m == NULL || m->m_len < sizeof (*tv)) { error = EINVAL; goto bad; } tv = mtod(m, struct timeval *); if (tv->tv_sec > SHRT_MAX / hz - hz) { error = EDOM; goto bad; } val = tv->tv_sec * hz + tv->tv_usec / tick; switch (optname) { case SO_SNDTIMEO: so->so_snd.sb_timeo = val; break; case SO_RCVTIMEO: so->so_rcv.sb_timeo = val; break; } break; } case SO_PRIVSTATE: /* we don't care what the parameter is... */ so->so_state &= ~SS_PRIV; break; default: error = ENOPROTOOPT; break; } if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { (void) ((*so->so_proto->pr_ctloutput) (PRCO_SETOPT, so, level, optname, &m0)); m = NULL; /* freed by protocol */ } }bad: if (m) (void) m_free(m); return (error);}
if (tv->tv_sec > SHRT_MAX / hz - hz) {
if (tv->tv_sec >= (ULONG_MAX - hz) / hz) {
sosetopt(so, level, optname, m0) register struct socket *so; int level, optname; struct mbuf *m0;{ int error = 0; register struct mbuf *m = m0; if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) return ((*so->so_proto->pr_ctloutput) (PRCO_SETOPT, so, level, optname, &m0)); error = ENOPROTOOPT; } else { switch (optname) { case SO_LINGER: if (m == NULL || m->m_len != sizeof (struct linger)) { error = EINVAL; goto bad; } so->so_linger = mtod(m, struct linger *)->l_linger; /* fall thru... */ case SO_DEBUG: case SO_KEEPALIVE: case SO_DONTROUTE: case SO_USELOOPBACK: case SO_BROADCAST: case SO_REUSEADDR: case SO_REUSEPORT: case SO_OOBINLINE: case SO_TIMESTAMP: if (m == NULL || m->m_len < sizeof (int)) { error = EINVAL; goto bad; } if (*mtod(m, int *)) so->so_options |= optname; else so->so_options &= ~optname; break; case SO_SNDBUF: case SO_RCVBUF: case SO_SNDLOWAT: case SO_RCVLOWAT: { int optval; if (m == NULL || m->m_len < sizeof (int)) { error = EINVAL; goto bad; } /* * Values < 1 make no sense for any of these * options, so disallow them. */ optval = *mtod(m, int *); if (optval < 1) { error = EINVAL; goto bad; } switch (optname) { case SO_SNDBUF: case SO_RCVBUF: if (sbreserve(optname == SO_SNDBUF ? &so->so_snd : &so->so_rcv, (u_long) optval) == 0) { error = ENOBUFS; goto bad; } break; /* * Make sure the low-water is never greater than * the high-water. */ case SO_SNDLOWAT: so->so_snd.sb_lowat = (optval > so->so_snd.sb_hiwat) ? so->so_snd.sb_hiwat : optval; break; case SO_RCVLOWAT: so->so_rcv.sb_lowat = (optval > so->so_rcv.sb_hiwat) ? so->so_rcv.sb_hiwat : optval; break; } break; } case SO_SNDTIMEO: case SO_RCVTIMEO: { struct timeval *tv; short val; if (m == NULL || m->m_len < sizeof (*tv)) { error = EINVAL; goto bad; } tv = mtod(m, struct timeval *); if (tv->tv_sec > SHRT_MAX / hz - hz) { error = EDOM; goto bad; } val = tv->tv_sec * hz + tv->tv_usec / tick; switch (optname) { case SO_SNDTIMEO: so->so_snd.sb_timeo = val; break; case SO_RCVTIMEO: so->so_rcv.sb_timeo = val; break; } break; } case SO_PRIVSTATE: /* we don't care what the parameter is... */ so->so_state &= ~SS_PRIV; break; default: error = ENOPROTOOPT; break; } if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { (void) ((*so->so_proto->pr_ctloutput) (PRCO_SETOPT, so, level, optname, &m0)); m = NULL; /* freed by protocol */ } }bad: if (m) (void) m_free(m); return (error);}
int val = (optname == SO_SNDTIMEO ?
unsigned long val = (optname == SO_SNDTIMEO ?
sogetopt(so, level, optname, mp) register struct socket *so; int level, optname; struct mbuf **mp;{ register struct mbuf *m; if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { return ((*so->so_proto->pr_ctloutput) (PRCO_GETOPT, so, level, optname, mp)); } else return (ENOPROTOOPT); } else { m = m_get(M_WAIT, MT_SOOPTS); m->m_len = sizeof (int); switch (optname) { case SO_LINGER: m->m_len = sizeof (struct linger); mtod(m, struct linger *)->l_onoff = so->so_options & SO_LINGER; mtod(m, struct linger *)->l_linger = so->so_linger; break; case SO_USELOOPBACK: case SO_DONTROUTE: case SO_DEBUG: case SO_KEEPALIVE: case SO_REUSEADDR: case SO_REUSEPORT: case SO_BROADCAST: case SO_OOBINLINE: case SO_TIMESTAMP: *mtod(m, int *) = so->so_options & optname; break; case SO_PRIVSTATE: *mtod(m, int *) = so->so_state & SS_PRIV; break; case SO_TYPE: *mtod(m, int *) = so->so_type; break; case SO_ERROR: *mtod(m, int *) = so->so_error; so->so_error = 0; break; case SO_SNDBUF: *mtod(m, int *) = so->so_snd.sb_hiwat; break; case SO_RCVBUF: *mtod(m, int *) = so->so_rcv.sb_hiwat; break; case SO_SNDLOWAT: *mtod(m, int *) = so->so_snd.sb_lowat; break; case SO_RCVLOWAT: *mtod(m, int *) = so->so_rcv.sb_lowat; break; case SO_SNDTIMEO: case SO_RCVTIMEO: { int val = (optname == SO_SNDTIMEO ? so->so_snd.sb_timeo : so->so_rcv.sb_timeo); m->m_len = sizeof(struct timeval); mtod(m, struct timeval *)->tv_sec = val / hz; mtod(m, struct timeval *)->tv_usec = (val % hz) * tick; break; } default: (void)m_free(m); return (ENOPROTOOPT); } *mp = m; return (0); }}
M = matrixbase2(L, T, disc);
for(i=1; i<=n; i++) { z = (GEN)L[i]; if (signe(z[2])) break; L[i] = z[1]; } M = matrixbase2(L, gmul(T, dbltor(1.)), disc);
initborne(GEN T, GEN disc, struct galois_borne * gb, long ppp){ ulong ltop = avma, lbot, av2; GEN borne, borneroots, borneabs; int i, j; int n; GEN L, M, z; L = roots(T, DEFAULTPREC); n = lg(L) - 1; M = matrixbase2(L, T, disc); borne = gzero; for (i = 1; i <= n; i++) { z = gzero; for (j = 1; j <= n; j++) z = gadd(z, gabs(((GEN **) M)[j][i], DEFAULTPREC)); if (gcmp(z, borne) > 0) borne = z; } borneroots = gzero; for (i = 1; i <= n; i++) { z = gabs((GEN) L[i], DEFAULTPREC); if (gcmp(z, borneroots) > 0) borneroots = z; } borneabs = addsr(1, gpowgs(addsr(n, borneroots), n / ppp)); lbot = avma; borneroots = addsr(1, gmul(borne, borneroots)); av2 = avma; borneabs = gmul2n(gmul(borne, borneabs), 4); gb->valsol = itos(gceil(gdiv(glog(gmul2n(borneroots, 4 + (n >> 1)), DEFAULTPREC), glog(gb->l, DEFAULTPREC)))); if (DEBUGLEVEL >= 4) fprintferr("GaloisConj:val1=%d\n", gb->valsol); gb->valabs = max(gb->valsol, itos(gceil(gdiv(glog(borneabs, DEFAULTPREC), glog(gb->l, DEFAULTPREC))))); if (DEBUGLEVEL >= 4) fprintferr("GaloisConj:val2=%d\n", gb->valabs); avma = av2; gb->bornesol = gerepile(ltop, lbot, borneroots); gb->ladicsol = gpowgs(gb->l, gb->valsol); gb->ladicabs = gpowgs(gb->l, gb->valabs);}
long nb,v, lim1;
long p,nb,v, lim1;
omega(GEN n){ byteptr d=diffptr+1; gpmem_t av = avma; long nb,v, lim1; if (typ(n) != t_INT) err(arither1); if (!signe(n)) err(arither2); if (is_pm1(n)) return 0; v=vali(n); nb = v ? 1 : 0; n = absi(shifti(n,-v)); p = 2; if (is_pm1(n)) return nb; lim1 = tridiv_bound(n,1); while (*d && p < lim1) { p += *d++; if (mpdivisis(n,p,n)) { nb++; while (mpdivisis(n,p,n)); /* empty */ if (is_pm1(n)) { avma = av; return nb; } } } if (cmpii(sqru(p),n) >= 0 || pseudoprime(n)) { avma = av; return nb+1; } /* large composite without small factors */ nb += ifac_omega(n, decomp_default_hint); avma=av; return nb;}
a = 1 + (nbcmax<<7);
a = 1 + (nbcmax<<7)*(size&0xffff);
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. * Start a little below the optimal B1 for finding factors which would just * have been missed by pollardbrent(), and escalate gradually, changing * curves sufficiently frequently to give good coverage of the small factor * ranges. Entries grow a bit faster than what Paul says would be optimal * but a 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, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,dp; GEN *X,*XAUX,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb; GEN res = cgeti(tf); pari_sp av1, avtmp, av = avma; int rflag, use_clones = 0; byteptr d, d0; 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"); 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(); 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(). */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4;{ const long tw = evallg(tf) | evaltyp(t_INT); GEN w; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) fprintferr("ECM: stack tight, using heap space\n"); use_clones = 1; X = (GEN*)newbloc(spc + 385); w = newbloc(spc*tf); } else { X = (GEN*)new_chunk(spc + 385); w = new_chunk(spc*tf); } /* hack for X[i] = cgeti(tf). X = current point in B1 phase */ for (i = spc; i--; ) { X[i] = w; *w = tw; w += tf; }} 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 + 10*nbc2; /* 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 + 48*nbc2; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set inside the main loop, since it depends on B2 */ /* 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. */ /* 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); } p = 0; NEXT_PRIME_VIADIFF(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) { pari_sp av = avma; 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, XAUX)) > 1) goto fin; else if (rflag) break; avma = av; } avma = av; } /* primes p larger than sqrt(B2) appear only to the 1st power */ while (p < B1) { pari_sp av = avma; p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X, XAUX) > 1) goto fin; /* p^2 > B2: no loop */ avma = av; } 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, XAUX) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = prc210_rp[%ld] mod 210)\n", p, 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, XAUX) > 1) goto fin; if (ellmult(nbc, 7, X, X, XAUX) > 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++) 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, ..., four * for 209 mod 210, 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. * Multiples which we already have (by 1,2,3,4,8,16,...,2^gse) are * entered simply by copying the pointers, ignoring the few 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; /* points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < (ulong)gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points 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 <= (ulong)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; (ulong)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<(ulong)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<(ulong)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 = gen_1; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (pari_sp)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) { ulong p2 = p; /* save current p for diagnostics */ /* 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 = gcdii(gl, n); if (!is_pm1(gl) && !equalii(gl, n)) { p = p2; goto fin; } gl = gen_1; 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); k = bstp - (rcn < rcn0 ? 1 : 0); /* recompute multiplier */ } } 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(); } res = NULL; goto ret; } } /* 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(); }ret: if (use_clones) { gunclone(X[spc]); gunclone((GEN)X); } avma = av; return res;}
* and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves.
* and insist phases; moreover, repeated calls acting on factors of the * same original number should try to use fresh curves.
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. * Start a little below the optimal B1 for finding factors which would just * have been missed by pollardbrent(), and escalate gradually, changing * curves sufficiently frequently to give good coverage of the small factor * ranges. Entries grow a bit faster than what Paul says would be optimal * but a 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, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,dp; GEN *X,*XAUX,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb; GEN res = cgeti(tf); pari_sp av1, avtmp, av = avma; int rflag, use_clones = 0; byteptr d, d0; 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"); 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(); 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(). */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4;{ const long tw = evallg(tf) | evaltyp(t_INT); GEN w; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) fprintferr("ECM: stack tight, using heap space\n"); use_clones = 1; X = (GEN*)newbloc(spc + 385); w = newbloc(spc*tf); } else { X = (GEN*)new_chunk(spc + 385); w = new_chunk(spc*tf); } /* hack for X[i] = cgeti(tf). X = current point in B1 phase */ for (i = spc; i--; ) { X[i] = w; *w = tw; w += tf; }} 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 + 10*nbc2; /* 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 + 48*nbc2; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set inside the main loop, since it depends on B2 */ /* 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. */ /* 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); } p = 0; NEXT_PRIME_VIADIFF(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) { pari_sp av = avma; 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, XAUX)) > 1) goto fin; else if (rflag) break; avma = av; } avma = av; } /* primes p larger than sqrt(B2) appear only to the 1st power */ while (p < B1) { pari_sp av = avma; p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X, XAUX) > 1) goto fin; /* p^2 > B2: no loop */ avma = av; } 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, XAUX) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = prc210_rp[%ld] mod 210)\n", p, 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, XAUX) > 1) goto fin; if (ellmult(nbc, 7, X, X, XAUX) > 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++) 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, ..., four * for 209 mod 210, 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. * Multiples which we already have (by 1,2,3,4,8,16,...,2^gse) are * entered simply by copying the pointers, ignoring the few 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; /* points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < (ulong)gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points 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 <= (ulong)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; (ulong)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<(ulong)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<(ulong)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 = gen_1; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (pari_sp)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) { ulong p2 = p; /* save current p for diagnostics */ /* 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 = gcdii(gl, n); if (!is_pm1(gl) && !equalii(gl, n)) { p = p2; goto fin; } gl = gen_1; 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); k = bstp - (rcn < rcn0 ? 1 : 0); /* recompute multiplier */ } } 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(); } res = NULL; goto ret; } } /* 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(); }ret: if (use_clones) { gunclone(X[spc]); gunclone((GEN)X); } avma = av; return res;}
k = 1+bfffo(m); m<<=k; k = BITS_IN_LONG-k;
k = 1+bfffo((ulong)m); m<<=k; k = BITS_IN_LONG-k;
puissii(GEN a, GEN n, long s){ long av,*p,m,k,i,lim; GEN y; if (!signe(a)) return gzero; /* a==0 */ if (lgefint(a)==3) { /* easy if |a| < 3 */ if (a[2] == 1) return (s>0)? gun: negi(gun); if (a[2] == 2) { a = shifti(gun, labs(itos(n))); setsigne(a,s); return a; } } if (lgefint(n)==3) { /* or if |n| < 3 */ if (n[2] == 1) { a = icopy(a); setsigne(a,s); return a; } if (n[2] == 2) return sqri(a); } /* be paranoid about memory consumption */ av=avma; lim=stack_lim(av,1); y = a; p = n+2; m = *p; /* normalize, i.e set highest bit to 1 (we know m != 0) */ k = 1+bfffo(m); m<<=k; k = BITS_IN_LONG-k; /* first bit is now implicit */ for (i=lgefint(n)-2;;) { for (; k; m<<=1,k--) { y = sqri(y); if (m < 0) y = mulii(y,a); /* first bit is set: multiply by base */ if (low_stack(lim, stack_lim(av,1))) { if (DEBUGMEM>1) err(warnmem,"puissii"); y = gerepileuptoint(av,y); } } if (--i == 0) break; m = *++p; k = BITS_IN_LONG; } setsigne(y,s); return gerepileuptoint(av,y);}
case t_REAL: av = avma; affrr(rdivii((GEN)x[1],(GEN)x[2], lg(y)), y); avma = av; break;
case t_REAL: rdiviiz((GEN)x[1],(GEN)x[2], y); break;
gaffect(GEN x, GEN y){ long i, j, k, vx, vy, lx, ly, tx = typ(x), ty = typ(y); pari_sp av; GEN p1,num,den; if (tx == ty) switch(tx) { case t_INT: if (!is_universal_constant(y)) { affii(x,y); return; } /* y = gzero, gnil, gun or gdeux */ if (y==gzero) err(overwriter,"gaffect (gzero)"); if (y==gun) err(overwriter,"gaffect (gun)"); if (y==gdeux) err(overwriter,"gaffect (gdeux)"); err(overwriter,"gaffect (gnil)"); case t_REAL: affrr(x,y); return; case t_INTMOD: if (!dvdii((GEN)x[1],(GEN)y[1])) err(operi,"",x,y); modiiz((GEN)x[2],(GEN)y[1],(GEN)y[2]); return; case t_FRAC: affii((GEN)x[1],(GEN)y[1]); affii((GEN)x[2],(GEN)y[2]); return; case t_COMPLEX: gaffect((GEN)x[1],(GEN)y[1]); gaffect((GEN)x[2],(GEN)y[2]); return; case t_PADIC: if (!egalii((GEN)x[2],(GEN)y[2])) err(operi,"",x,y); modiiz((GEN)x[4],(GEN)y[3],(GEN)y[4]); setvalp(y,valp(x)); return; case t_QUAD: if (! gegal((GEN)x[1],(GEN)y[1])) err(operi,"",x,y); affii((GEN)x[2],(GEN)y[2]); affii((GEN)x[3],(GEN)y[3]); return; case t_POLMOD: if (! gdvd((GEN)x[1],(GEN)y[1])) err(operi,"",x,y); gmodz((GEN)x[2],(GEN)y[1],(GEN)y[2]); return; case t_POL: vx = varn(x); vy = varn(y); ly = lg(y); if (vx != vy) { if (varncmp(vy, vx) > 0) err(operf,"",x,y); gaffect(x,(GEN)y[2]); for (i=3; i<ly; i++) gaffsg(0,(GEN)y[i]); y[1] = signe(x)? evalsigne(1)|evalvarn(vy): evalvarn(vy); return; } lx = lg(x); if (lx > ly) err(operi,"",x,y); y[1] = x[1]; for (i=2; i<lx; i++) gaffect((GEN)x[i],(GEN)y[i]); return; case t_SER: vx = varn(x); vy = varn(y); ly = lg(y); if (vx != vy) { if (varncmp(vy, vx) > 0) err(operf,"",x,y); gaffect(x,(GEN)y[2]); if (!signe(x)) y[1] = evalvalp(ly-2) | evalvarn(vy); else y[1] = evalsigne(1) | evalvalp(0) | evalvarn(vy); for (i=3; i<ly; i++) gaffsg(0,(GEN)y[i]); return; } lx = lg(x); if (lx > ly) lx = ly; y[1] = x[1]; for (i=2; i<lx; i++) gaffect((GEN)x[i],(GEN)y[i]); for ( ; i<ly; i++) gaffsg(0,(GEN)y[i]); return; case t_RFRAC: gaffect((GEN)x[1],(GEN)y[1]); gaffect((GEN)x[2],(GEN)y[2]); return; case t_QFR: case t_QFI: case t_VEC: case t_COL: case t_MAT: lx = lg(x); if (lx != lg(y)) err(operi,"",x,y); for (i=1; i<lx; i++) gaffect((GEN)x[i],(GEN)y[i]); return; } if (is_scalar_t(tx)) { if (is_scalar_t(ty)) { switch(tx) { case t_INT: switch(ty) { case t_REAL: if (y == gpi) err(overwriter,"gaffect (gpi)"); if (y==geuler) err(overwriter,"gaffect (geuler)"); affir(x,y); break; case t_INTMOD: modiiz(x,(GEN)y[1],(GEN)y[2]); break; case t_FRAC: if (y == ghalf) err(overwriter,"gaffect (ghalf)"); affii(x,(GEN)y[1]); affsi(1,(GEN)y[2]); break; case t_COMPLEX: if (y == gi) err(overwriter,"gaffect (gi)"); gaffect(x,(GEN)y[1]); gaffsg(0,(GEN)y[2]); break; case t_PADIC: if (!signe(x)) { padicaff0(y); break; } av=avma; setvalp(y, Z_pvalrem(x,(GEN)y[2],&p1)); modiiz(p1,(GEN)y[3],(GEN)y[4]); avma=av; break; case t_QUAD: gaffect(x,(GEN)y[2]); gaffsg(0,(GEN)y[3]); break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_REAL: switch(ty) { case t_COMPLEX: gaffect(x,(GEN)y[1]); gaffsg(0,(GEN)y[2]); break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_INTMOD: switch(ty) { case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_FRAC: switch(ty) { case t_REAL: av = avma; affrr(rdivii((GEN)x[1],(GEN)x[2], lg(y)), y); avma = av; break; case t_INTMOD: av = avma; p1 = Fp_inv((GEN)x[2],(GEN)y[1]); modiiz(mulii((GEN)x[1],p1),(GEN)y[1],(GEN)y[2]); avma = av; break; case t_COMPLEX: gaffect(x,(GEN)y[1]); gaffsg(0,(GEN)y[2]); break; case t_PADIC: if (!signe(x[1])) { padicaff0(y); break; } num = (GEN)x[1]; den = (GEN)x[2]; av = avma; vx = Z_pvalrem(num, (GEN) y[2], &num); if (!vx) vx = -Z_pvalrem(den,(GEN)y[2],&den); setvalp(y,vx); p1 = mulii(num,Fp_inv(den,(GEN)y[3])); modiiz(p1,(GEN)y[3],(GEN)y[4]); avma = av; break; case t_QUAD: gaffect(x,(GEN)y[2]); gaffsg(0,(GEN)y[3]); break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_COMPLEX: switch(ty) { case t_INT: case t_REAL: case t_INTMOD: case t_FRAC: case t_PADIC: case t_QUAD: if (!gcmp0((GEN)x[2])) err(operi,"",x,y); gaffect((GEN)x[1],y); break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_PADIC: switch(ty) { case t_INTMOD: av = avma; affii(ptolift(x, (GEN)y[1]), (GEN)y[2]); avma = av; break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_QUAD: switch(ty) { case t_INT: case t_INTMOD: case t_FRAC: case t_PADIC: if (!gcmp0((GEN)x[3])) err(operi,"",x,y); gaffect((GEN)x[2],y); break; case t_REAL: av = avma; gaffect(quadtoc(x,lg(y)), y); avma = av; break; case t_COMPLEX: ly = precision(y); if (ly) { av = avma; gaffect(quadtoc(x,ly), y); avma = av; } else { if (!gcmp0((GEN)x[3])) err(operi,"",x,y); gaffect((GEN)x[2],y); } break; case t_POLMOD: gaffect(x,(GEN)y[2]); break; default: err(operf,"",x,y); } break; default: err(operf,"",x,y); } return; } /* here y is not scalar */ switch(ty) { case t_POL: vx = varn(y); ly = lg(y); if (y==polun[vx] || y==polx[vx]) err(overwriter,"gaffect (polun/polx)"); gaffect(x,(GEN)y[2]); for (i=3; i<ly; i++) gaffsg(0,(GEN)y[i]); y[1] = gcmp0(x)? evalvarn(vx): evalsigne(1) | evalvarn(vx); break; case t_SER: vx = varn(y); ly = lg(y); if (gcmp0(x)) y[1] = evalvalp(ly-2) | evalvarn(vx); else y[1] = evalsigne(1) | evalvalp(0) | evalvarn(vx); gaffect(x,(GEN)y[2]); for (i=3; i<ly; i++) gaffsg(0,(GEN)y[i]); break; case t_RFRAC: gaffect(x,(GEN)y[1]); gaffsg(1,(GEN)y[2]); break; default: err(operf,"",x,y); } return; } if (is_const_t(ty)) { entree *varnum, *varden; long vnum, vden; GEN num, den; if (tx == t_POL) { vnum = varn(x); varnum = varentries[ordvar[vnum]]; if (varnum) { x = geval(x); tx = typ(x); if (tx != t_POL || varn(x) != vnum) { gaffect(x, y); return; } } } else if (tx == t_RFRAC) { num = (GEN)x[1]; vnum = gvar(num); varnum = varentries[ordvar[vnum]]; den = (GEN)x[2]; vden = gvar(den); varden = varentries[ordvar[vden]]; if (varnum && varden) { vnum = min(vnum, vden); x = geval(x); tx = typ(x); if (tx != t_RFRAC || gvar(x) != vnum) { gaffect(x, y); return; } } } err(operf,"",x,y); } lx = lg(x); ly = lg(y); switch(tx) { case t_POL: vx = varn(x); switch(ty) { case t_POLMOD: gmodz(x,(GEN)y[1],(GEN)y[2]); break; case t_SER: vy=varn(y); if (varncmp(vy, vx) > 0) err(operf,"",x,y); if (!signe(x)) { gaffsg(0,y); return; } if (vy==vx) { i = gval(x,vx); y[1] = evalvarn(vx) | evalvalp(i) | evalsigne(1); k = lx-i; if (k > ly) k = ly; for (j=2; j<k; j++) gaffect((GEN)x[i+j],(GEN)y[j]); for ( ; j<ly; j++) gaffsg(0,(GEN)y[j]); } else { gaffect(x,(GEN)y[2]); if (!signe(x)) y[1] = evalvalp(ly-2) | evalvarn(vy); else y[1] = evalsigne(1) | evalvalp(0) | evalvarn(vy); for (i=3; i<ly; i++) gaffsg(0,(GEN)y[i]); } break; case t_RFRAC: gaffect(x,(GEN)y[1]); gaffsg(1,(GEN)y[2]); break; default: err(operf,"",x,y); } break; case t_RFRAC: switch(ty) { case t_POLMOD: av=avma; p1=ginvmod((GEN)x[2],(GEN)y[1]); gmodz(gmul((GEN)x[1],p1),(GEN)y[1],(GEN)y[2]); avma=av; break; case t_SER: gdivz((GEN)x[1],(GEN)x[2],y); break; default: err(operf,"",x,y); } break; default: err(operf,"",x,y); }}
while( final_address > d_addr ) {
while( final_address >= d_addr ) {
rtems_cache_invalidate_multiple_data_lines( const void * d_addr, size_t n_bytes ){#if defined(CPU_DATA_CACHE_ALIGNMENT) const void * final_address; /* * Set d_addr to the beginning of the cache line; final_address indicates * the last address_t which needs to be invalidated. Increment d_addr and * invalidate the resulting line until final_address is passed. */ if( n_bytes == 0 ) /* Do nothing if number of bytes to invalidate is zero */ return; final_address = (void *)((size_t)d_addr + n_bytes - 1); d_addr = (void *)((size_t)d_addr & ~(CPU_DATA_CACHE_ALIGNMENT - 1)); while( final_address > d_addr ) { _CPU_cache_invalidate_1_data_line( d_addr ); d_addr = (void *)((size_t)d_addr + CPU_DATA_CACHE_ALIGNMENT); }#endif}
s = a; a = b; b = s;
cbezout(long a,long b,long *uu,long *vv){ long s,*t; ulong d = labs(a), d1 = labs(b); ulong r,u,u1,v,v1;#ifdef DEBUG_CBEZOUT fprintferr("> cbezout(%ld,%ld,%p,%p)\n", a, b, (void *)uu, (void *)vv);#endif if (!b) { *vv=0L; if (!a) { *uu=1L;#ifdef DEBUG_CBEZOUT fprintferr("< %ld (%ld, %ld)\n", 1L, *uu, *vv);#endif return 0L; } *uu = a < 0 ? -1L : 1L;#ifdef DEBUG_CBEZOUT fprintferr("< %ld (%ld, %ld)\n", (long)d, *uu, *vv);#endif return (long)d; } else if (!a || (d == d1)) { *uu = 0L; *vv = b < 0 ? -1L : 1L;#ifdef DEBUG_CBEZOUT fprintferr("< %ld (%ld, %ld)\n", (long)d1, *uu, *vv);#endif return (long)d1; } else if (d == 1) /* frequently used by nfinit */ { *uu = a; *vv = 0L;#ifdef DEBUG_CBEZOUT fprintferr("< %ld (%ld, %ld)\n", 1L, *uu, *vv);#endif return 1L; } else if (d < d1) { r = d; d = d1; d1 = r; s = a; a = b; b = s; /* in order to keep the right signs */ t = uu; uu = vv; vv = t;#ifdef DEBUG_CBEZOUT fprintferr(" swapping\n");#endif } /* d > d1 > 0 */ r = xxgcduu(d, d1, 0, &u, &u1, &v, &v1, &s); if (s < 0) { *uu = a < 0 ? u : -(long)u; *vv = b < 0 ? -(long)v : v; } else { *uu = a < 0 ? -(long)u : u; *vv = b < 0 ? v : -(long)v; }#ifdef DEBUG_CBEZOUT fprintferr("< %ld (%ld, %ld)\n", (long)r, *uu, *vv);#endif return (long)r;}
prec = gprecision(x);
prec = gprecision(x) - 1;
init_pslq(pslq_M *M, GEN x, long *PREC){ long tx = typ(x), lx = lg(x), n = lx-1, i, j, k, prec; GEN s1, s, sinv; if (! is_vec_t(tx)) err(typeer,"pslq"); /* check trivial cases */ for (k = 1; k <= n; k++) if (gcmp0((GEN)x[k])) return vec_ei(n, k); if (n <= 1) return cgetg(1, t_COL); prec = gprecision(x); if (prec < 0) { /* exact components */ pari_sp av = avma; GEN im, U = NULL; x = Q_primpart(x); im = gimag(x); x = greal(x); settyp(x, t_VEC); if (!gcmp0(im)) { U = (GEN)extendedgcd(im)[2]; setlg(U, lg(U)-1); /* remove last column */ x = gmul(x, U); if (n == 2) /* x has a single component */ return gcmp0((GEN)x[1])? (GEN)U[1]: cgetg(1, t_COL); } x = (GEN)extendedgcd(x)[2]; x = (GEN)x[1]; if (U) x = gmul(U, x); return gerepilecopy(av, x); } if (prec < DEFAULTPREC) prec = DEFAULTPREC; *PREC = prec; M->EXP = - bit_accuracy(prec) + max(2*n, 32); M->flreal = is_zero(gimag(x), M->EXP, prec); if (!M->flreal) return lindep(x,prec); /* FIXME */ else x = greal(x); if (DEBUGLEVEL>=3) { (void)timer(); init_timer(M->T); } x = col_to_MP(x, prec); settyp(x,t_VEC); M->n = n; M->A = idmat(n); M->B = idmat(n); s1 = cgetg(lx,t_VEC); s1[n] = lnorm((GEN)x[n]); s = cgetg(lx,t_VEC); s[n] = (long)gabs((GEN)x[n],prec); for (k=n-1; k>=1; k--) { s1[k] = ladd((GEN)s1[k+1], gnorm((GEN)x[k])); s[k] = (long)gsqrt((GEN)s1[k], prec); } sinv = ginv((GEN)s[1]); s = gmul(sinv,s); M->y = gmul(sinv, x); M->H = cgetg(n,t_MAT); for (j=1; j<n; j++) { GEN d, c = cgetg(lx,t_COL); M->H[j] = (long)c; for (i=1; i<j; i++) c[i] = zero; c[j] = ldiv((GEN)s[j+1],(GEN)s[j]); d = gneg( gdiv((GEN)M->y[j], gmul((GEN)s[j],(GEN)s[j+1]) )); for (i=j+1; i<=n; i++) c[i] = lmul(gconj((GEN)M->y[i]), d); } for (i=2; i<=n; i++) redall(M, i, i-1); return NULL;}
M->EXP = - bit_accuracy(prec) + max(2*n, 32);
M->EXP = - bit_accuracy(prec) + max(n, 8);
init_pslq(pslq_M *M, GEN x, long *PREC){ long tx = typ(x), lx = lg(x), n = lx-1, i, j, k, prec; GEN s1, s, sinv; if (! is_vec_t(tx)) err(typeer,"pslq"); /* check trivial cases */ for (k = 1; k <= n; k++) if (gcmp0((GEN)x[k])) return vec_ei(n, k); if (n <= 1) return cgetg(1, t_COL); prec = gprecision(x); if (prec < 0) { /* exact components */ pari_sp av = avma; GEN im, U = NULL; x = Q_primpart(x); im = gimag(x); x = greal(x); settyp(x, t_VEC); if (!gcmp0(im)) { U = (GEN)extendedgcd(im)[2]; setlg(U, lg(U)-1); /* remove last column */ x = gmul(x, U); if (n == 2) /* x has a single component */ return gcmp0((GEN)x[1])? (GEN)U[1]: cgetg(1, t_COL); } x = (GEN)extendedgcd(x)[2]; x = (GEN)x[1]; if (U) x = gmul(U, x); return gerepilecopy(av, x); } if (prec < DEFAULTPREC) prec = DEFAULTPREC; *PREC = prec; M->EXP = - bit_accuracy(prec) + max(2*n, 32); M->flreal = is_zero(gimag(x), M->EXP, prec); if (!M->flreal) return lindep(x,prec); /* FIXME */ else x = greal(x); if (DEBUGLEVEL>=3) { (void)timer(); init_timer(M->T); } x = col_to_MP(x, prec); settyp(x,t_VEC); M->n = n; M->A = idmat(n); M->B = idmat(n); s1 = cgetg(lx,t_VEC); s1[n] = lnorm((GEN)x[n]); s = cgetg(lx,t_VEC); s[n] = (long)gabs((GEN)x[n],prec); for (k=n-1; k>=1; k--) { s1[k] = ladd((GEN)s1[k+1], gnorm((GEN)x[k])); s[k] = (long)gsqrt((GEN)s1[k], prec); } sinv = ginv((GEN)s[1]); s = gmul(sinv,s); M->y = gmul(sinv, x); M->H = cgetg(n,t_MAT); for (j=1; j<n; j++) { GEN d, c = cgetg(lx,t_COL); M->H[j] = (long)c; for (i=1; i<j; i++) c[i] = zero; c[j] = ldiv((GEN)s[j+1],(GEN)s[j]); d = gneg( gdiv((GEN)M->y[j], gmul((GEN)s[j],(GEN)s[j+1]) )); for (i=j+1; i<=n; i++) c[i] = lmul(gconj((GEN)M->y[i]), d); } for (i=2; i<=n; i++) redall(M, i, i-1); return NULL;}
if (rn_inithead((void **)&mask_rnhead, 0) == 0)
if (rn_inithead((void *)&mask_rnhead, 0) == 0)
rn_init(){ char *cp, *cplim;#ifdef KERNEL struct domain *dom; for (dom = domains; dom; dom = dom->dom_next) if (dom->dom_maxrtkey > max_keylen) max_keylen = dom->dom_maxrtkey;#endif if (max_keylen == 0) { log(LOG_ERR, "rn_init: radix functions require max_keylen be set\n"); return; } R_Malloc(rn_zeros, char *, 3 * max_keylen); if (rn_zeros == NULL) panic("rn_init"); Bzero(rn_zeros, 3 * max_keylen); rn_ones = cp = rn_zeros + max_keylen; addmask_key = cplim = rn_ones + max_keylen; while (cp < cplim) *cp++ = -1; if (rn_inithead((void **)&mask_rnhead, 0) == 0) panic("rn_init 2");}
GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F;
GEN f, fZ, basecl, module, fa, fa2, pr, t, EX, sarch, cyc, F; GEN *listpr, *listep, *vecpi, *vecpinvpi, *vectau;
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
vecinvpi = (GEN*)cgetg(lp, t_VEC);
vecpinvpi = (GEN*)cgetg(lp, t_VEC); vecpi = (GEN*)cgetg(lp, t_VEC);
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
vecinvpi[i] = NULL;
vecpi[i] = NULL; vecpinvpi[i] = NULL;
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
GEN invpi, dmulI, mulI, G, I, A, e, L, newL;
GEN p, pi, pinvpi, dmulI, mulI, G, I, A, e, L, newL;
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v));
p = (GEN)pr[1]; pi = get_pi(F, pr, &vecpi[j]); pinvpi = get_pinvpi(nf, fZ, p, pi, &vecpinvpi[j]); t = element_pow(nf, pinvpi, stoi(v));
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v));
p = (GEN)pr[1]; pi = get_pi(F, pr, &vecpi[j]); if (v > 0) { pinvpi = get_pinvpi(nf, fZ, p, pi, &vecpinvpi[j]); t = element_pow(nf,pinvpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdiv(LL, gpowgs(p, v)); } else { t = element_pow(nf,pi,stoi(-v)); LL = element_mul(nf, LL, t); }
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ);
newL[k] = (long)FpV_red(make_integral(nf,LL,f,listpr), fZ);
compute_raygen(GEN nf, GEN u1, GEN gen, GEN bid){ GEN f, fZ, basecl, module, fa, fa2, *listpr, *listep, *vecinvpi, *vectau; GEN pr, t, EX, sarch, cyc, F; long i,j,l,lp; /* basecl = generators in factored form */ basecl = compute_fact(nf,u1,gen); module = (GEN)bid[1]; cyc = gmael(bid,2,2); EX = (GEN)cyc[1]; /* exponent of (O/f)^* */ f = (GEN)module[1]; fZ = gcoeff(f,1,1); fa = (GEN)bid[3]; fa2 = (GEN)bid[4]; sarch = (GEN)fa2[lg(fa2)-1]; listpr = (GEN*)fa[1]; F = init_unif_mod_fZ((GEN)listpr); listep = (GEN*)fa[2]; lp = lg(listpr); vecinvpi = (GEN*)cgetg(lp, t_VEC); vectau = (GEN*)cgetg(lp, t_VEC); for (i=1; i<lp; i++) { pr = listpr[i]; vecinvpi[i] = NULL; /* to be computed if needed */ vectau[i] = eltmul_get_table(nf, (GEN)pr[5]); } l = lg(basecl); for (i=1; i<l; i++) { GEN invpi, dmulI, mulI, G, I, A, e, L, newL; long la, v, k; /* G = [I, A=famat(L,e)] is a generator, I integral */ G = (GEN)basecl[i]; I = (GEN)G[1]; A = (GEN)G[2]; L = (GEN)A[1]; e = (GEN)A[2]; /* if no reduction took place in compute_fact, everybody is still coprime * to f + no denominators */ if (!I) { basecl[i] = (long)famat_to_nf_modidele(nf, L, e, bid); continue; } if (lg(A) == 1) { basecl[i] = (long)I; continue; } /* compute mulI so that mulI * I coprime to f * FIXME: use idealcoprime ??? (Less efficient. Fix idealcoprime!) */ dmulI = mulI = NULL; for (j=1; j<lp; j++) { pr = listpr[j]; v = idealval(nf, I, pr); if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf, invpi, stoi(v)); mulI = mulI? element_mul(nf, mulI, t): t; t = gpowgs((GEN)pr[1], v); dmulI = dmulI? mulii(dmulI, t): t; } /* make all components of L coprime to f. * Assuming (L^e * I, f) = 1, then newL^e * mulI = L^e */ la = lg(e); newL = cgetg(la, t_VEC); for (k=1; k<la; k++) { GEN L0, cx, LL = _algtobasis(nf, (GEN)L[k]); L0 = Q_primitive_part(LL, &cx); /* LL = L0*cx (faster element_val) */ for (j=1; j<lp; j++) { pr = listpr[j]; v = fast_val(nf, L0,cx, pr,vectau[j]); /* = val_pr(LL) */ if (!v) continue; invpi = get_invpi(nf, fZ, pr, F, &vecinvpi[j]); t = element_pow(nf,invpi,stoi(v)); LL = element_mul(nf, LL, t); LL = gdivexact(LL, gpowgs((GEN)pr[1], v)); } newL[k] = (long)FpV_red(make_integral(LL,fZ), fZ); } /* G in nf, = L^e mod f */ G = famat_to_nf_modideal_coprime(nf, newL, gmod(e,EX), f); if (mulI) { G = element_muli(nf, G, mulI); G = colreducemodHNF(G, gmul(f, dmulI), NULL); } G = set_sign_mod_idele(nf,A,G,module,sarch); I = idealmul(nf,I,G); if (dmulI) I = gdivexact(I, dmulI); /* more or less useless, but cheap at this point */ I = _idealmodidele(nf,I,module,sarch); basecl[i] = (long)I; } return basecl;}
unsigned int sr;
unsigned int sr, srbits;
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
sr &= ~SR_EXL;
sr &= ~SR_EXL; * clear the EXL bit *
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
sr &= ~SR_IE; mips_set_sr(sr);
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
sr |= SR_EXL|SR_IE; mips_set_sr(sr);
sr |= SR_EXL|SR_IE; * enable exception level * mips_set_sr(sr); * first disable ie bit (recommended) *
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return;
mips_set_sr( (sr & ~SR_IEC) );
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
sr &= ~SR_IEC; if ( !new_level ) sr |= SR_IEC; mips_set_sr(sr);
srbits = sr & ~(0xfc00 | SR_IEC); sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc000) | (new_level & 1)));
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
mips_set_sr( sr );
void _CPU_ISR_Set_level( unsigned32 new_level ){ unsigned int sr; mips_get_sr(sr);#if __mips == 3 if ( (new_level & SR_EXL) == (sr & SR_EXL) ) return; if ( (new_level & SR_EXL) == 0 ) { sr &= ~SR_EXL; /* clear the EXL bit */ mips_set_sr(sr); } else { sr &= ~SR_IE; mips_set_sr(sr); /* first disable ie bit (recommended) */ sr |= SR_EXL|SR_IE; /* enable exception level */ mips_set_sr(sr); /* first disable ie bit (recommended) */ } #elif __mips == 1 if ( (new_level & SR_IEC) == (sr & SR_IEC) ) return; sr &= ~SR_IEC; /* clear the IEC bit */ if ( !new_level ) sr |= SR_IEC; /* enable interrupts */ mips_set_sr(sr);#else#error "CPU ISR level: unknown MIPS level for SR handling"#endif}
mulred(GEN nf,GEN x, GEN I, long prec,long precint)
mulred(GEN nf,GEN x, GEN I, long prec)
mulred(GEN nf,GEN x, GEN I, long prec,long precint){ long av = avma; GEN y = cgetg(3,t_VEC); y[1] = (long)idealmulh(nf,I,(GEN)x[1]); y[2] = x[2]; y = ideallllredall(nf,y,NULL,prec,precint); y[1] = (long)ideal_two_elt(nf,(GEN)y[1]); return gerepileupto(av,gcopy(y));}
y = ideallllredall(nf,y,NULL,prec,precint);
y = ideallllred(nf,y,NULL,prec);
mulred(GEN nf,GEN x, GEN I, long prec,long precint){ long av = avma; GEN y = cgetg(3,t_VEC); y[1] = (long)idealmulh(nf,I,(GEN)x[1]); y[2] = x[2]; y = ideallllredall(nf,y,NULL,prec,precint); y[1] = (long)ideal_two_elt(nf,(GEN)y[1]); return gerepileupto(av,gcopy(y));}