rem
stringlengths 0
274k
| add
stringlengths 0
169k
| context
stringlengths 9
471k
|
---|---|---|
if ((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR) == 0)) | if (((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR)) == 0)) | udp_input(m, iphlen) register struct mbuf *m; int iphlen;{ register struct ip *ip; register struct udphdr *uh; register struct inpcb *inp; struct mbuf *opts = 0; int len; struct ip save_ip; udpstat.udps_ipackets++; /* * Strip IP options, if any; should skip this, * make available to user, and use on returned packets, * but we don't yet have a way to check the checksum * with options still present. */ if (iphlen > sizeof (struct ip)) { ip_stripoptions(m, (struct mbuf *)0); iphlen = sizeof(struct ip); } /* * Get IP and UDP header together in first mbuf. */ ip = mtod(m, struct ip *); if (m->m_len < iphlen + sizeof(struct udphdr)) { if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) { udpstat.udps_hdrops++; return; } ip = mtod(m, struct ip *); } uh = (struct udphdr *)((caddr_t)ip + iphlen); /* * Make mbuf data length reflect UDP length. * If not enough data to reflect UDP length, drop. */ len = ntohs((u_short)uh->uh_ulen); if (ip->ip_len != len) { if (len > ip->ip_len || len < sizeof(struct udphdr)) { udpstat.udps_badlen++; goto bad; } m_adj(m, len - ip->ip_len); /* ip->ip_len = len; */ } /* * Save a copy of the IP header in case we want restore it * for sending an ICMP error message in response. */ save_ip = *ip; /* * Checksum extended UDP header and data. */ if (uh->uh_sum) { ((struct ipovly *)ip)->ih_next = 0; ((struct ipovly *)ip)->ih_prev = 0; ((struct ipovly *)ip)->ih_x1 = 0; ((struct ipovly *)ip)->ih_len = uh->uh_ulen; uh->uh_sum = in_cksum(m, len + sizeof (struct ip)); if (uh->uh_sum) { udpstat.udps_badsum++; m_freem(m); return; } } if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) { struct inpcb *last; /* * Deliver a multicast or broadcast datagram to *all* sockets * for which the local and remote addresses and ports match * those of the incoming datagram. This allows more than * one process to receive multi/broadcasts on the same port. * (This really ought to be done for unicast datagrams as * well, but that would cause problems with existing * applications that open both address-specific sockets and * a wildcard socket listening to the same port -- they would * end up receiving duplicates of every unicast datagram. * Those applications open the multiple sockets to overcome an * inadequacy of the UDP socket interface, but for backwards * compatibility we avoid the problem here rather than * fixing the interface. Maybe 4.5BSD will remedy this?) */ /* * Construct sockaddr format source address. */ udp_in.sin_port = uh->uh_sport; udp_in.sin_addr = ip->ip_src; m->m_len -= sizeof (struct udpiphdr); m->m_data += sizeof (struct udpiphdr); /* * Locate pcb(s) for datagram. * (Algorithm copied from raw_intr().) */ last = NULL; for (inp = udb.lh_first; inp != NULL; inp = inp->inp_list.le_next) { if (inp->inp_lport != uh->uh_dport) continue; if (inp->inp_laddr.s_addr != INADDR_ANY) { if (inp->inp_laddr.s_addr != ip->ip_dst.s_addr) continue; } if (inp->inp_faddr.s_addr != INADDR_ANY) { if (inp->inp_faddr.s_addr != ip->ip_src.s_addr || inp->inp_fport != uh->uh_sport) continue; } if (last != NULL) { struct mbuf *n; if ((n = m_copy(m, 0, M_COPYALL)) != NULL) { if (last->inp_flags & INP_CONTROLOPTS || last->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(last, &opts, ip, n); if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&udp_in, n, opts) == 0) { m_freem(n); if (opts) m_freem(opts); udpstat.udps_fullsock++; } else sorwakeup(last->inp_socket); opts = 0; } } last = inp; /* * Don't look for additional matches if this one does * not have either the SO_REUSEPORT or SO_REUSEADDR * socket options set. This heuristic avoids searching * through all pcbs in the common case of a non-shared * port. It * assumes that an application will never * clear these options after setting them. */ if ((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR) == 0)) break; } if (last == NULL) { /* * No matching pcb found; discard datagram. * (No need to send an ICMP Port Unreachable * for a broadcast or multicast datgram.) */ udpstat.udps_noportbcast++; goto bad; } if (last->inp_flags & INP_CONTROLOPTS || last->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(last, &opts, ip, m); if (sbappendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&udp_in, m, opts) == 0) { udpstat.udps_fullsock++; goto bad; } sorwakeup(last->inp_socket); return; } /* * Locate pcb for datagram. */ inp = in_pcblookuphash(&udbinfo, ip->ip_src, uh->uh_sport, ip->ip_dst, uh->uh_dport, 1); if (inp == NULL) { if (log_in_vain) { char buf[4*sizeof "123"]; strcpy(buf, inet_ntoa(ip->ip_dst)); log(LOG_INFO, "Connection attempt to UDP %s:%d" " from %s:%d\n", buf, ntohs(uh->uh_dport), inet_ntoa(ip->ip_src), ntohs(uh->uh_sport)); } udpstat.udps_noport++; if (m->m_flags & (M_BCAST | M_MCAST)) { udpstat.udps_noportbcast++; goto bad; } *ip = save_ip; icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); return; } /* * Construct sockaddr format source address. * Stuff source address and datagram in user buffer. */ udp_in.sin_port = uh->uh_sport; udp_in.sin_addr = ip->ip_src; if (inp->inp_flags & INP_CONTROLOPTS || inp->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(inp, &opts, ip, m); iphlen += sizeof(struct udphdr); m->m_len -= iphlen; m->m_pkthdr.len -= iphlen; m->m_data += iphlen; if (sbappendaddr(&inp->inp_socket->so_rcv, (struct sockaddr *)&udp_in, m, opts) == 0) { udpstat.udps_fullsock++; goto bad; } sorwakeup(inp->inp_socket); return;bad: m_freem(m); if (opts) m_freem(opts);} |
if (err_catch_stack) { | if (err_catch_stack && numerr != memer) { | err(long numerr, ...){ char s[128], *ch1; int ret = 0, trap = 0; PariOUT *out = pariOut; va_list ap; va_start(ap,numerr); if (err_catch_stack) { if (err_catch_stack[numerr]) trap = numerr; else if (err_catch_stack[noer] && numerr >= talker) trap = noer; } if (trap) { /* all non-syntax errors (noer), or numerr individually trapped */ cell *a = (cell*) err_catch_stack[trap]->value; global_err_data = a->data; if (a->env) longjmp(a->env, numerr); } else global_err_data = NULL; if (!added_newline) { pariputc('\n'); added_newline=1; } pariflush(); pariOut = pariErr; pariflush(); term_color(c_ERR); if (numerr < talker) { strcpy(s, errmessage[numerr]); switch (numerr) { case obsoler: ch1 = va_arg(ap,char *); errcontext(s,ch1,va_arg(ap,char *)); if (whatnow_fun) { term_color(c_NONE); print_text("For full compatibility with GP 1.39, type \"default(compatible,3)\" (you can also set \"compatible = 3\" in your GPRC file)"); pariputc('\n'); ch1 = va_arg(ap,char *); whatnow_fun(ch1, - va_arg(ap,int)); } break; case openfiler: sprintf(s+strlen(s), "%s file", va_arg(ap,char*)); ch1 = va_arg(ap,char *); errcontext(s,ch1,ch1); break; case talker2: case member: strcat(s,va_arg(ap, char*)); /* fall through */ default: ch1 = va_arg(ap,char *); errcontext(s,ch1,va_arg(ap,char *)); } } else { pariputsf(" *** %s", errmessage[numerr]); switch (numerr) { case talker: case siginter: ch1=va_arg(ap, char*); vpariputs(ch1,ap); pariputc('.'); break; case impl: ch1=va_arg(ap, char*); pariputsf(" %s is not yet implemented.",ch1); break; case breaker: case typeer: case mattype1: case overwriter: case accurer: case infprecer: case negexper: case polrationer: case funder2: case constpoler: case notpoler: case redpoler: case zeropoler: case consister: case flagerr: pariputsf(" in %s.",va_arg(ap, char*)); break; case bugparier: pariputsf(" %s, please report",va_arg(ap, char*)); break; case operi: case operf: { char *f, *op = va_arg(ap, char*); long x = va_arg(ap, long); long y = va_arg(ap, long); if (*op == '+') f = "addition"; else if (*op == '*') f = "multiplication"; else if (*op == '/' || *op == '%') f = "division"; else if (*op == 'g') { op = ","; f = "gcd"; } else { op = "-->"; f = "assignment"; } pariputsf(" %s %s %s %s.",f,type_name(x),op,type_name(y)); break; } /* the following 4 are only warnings (they return) */ case warnmem: case warner: pariputc(' '); ch1=va_arg(ap, char*); vpariputs(ch1,ap); pariputs(".\n"); ret = 1; break; case warnprec: vpariputs(" in %s; new prec = %ld\n",ap); ret = 1; break; case warnfile: ch1=va_arg(ap, char*); pariputsf(" %s: %s", ch1, va_arg(ap, char*)); ret = 1; break; } } term_color(c_NONE); va_end(ap); if (numerr==errpile) { fprintferr("\n current stack size: %.1f Mbytes\n", (double)(top-bot)/1E6); fprintferr(" [hint] you can increase GP stack with allocatemem()\n"); } pariOut = out; if (ret || (trap && default_exception_handler && default_exception_handler(numerr))) { flusherr(); return; } err_recover(numerr); exit(1); /* not reached */} |
red_cyclo2n_ip(GEN x, int n) | red_cyclo2n_ip(GEN x, long n) | red_cyclo2n_ip(GEN x, int n){ long i, pow2 = 1<<(n-1); for (i = lg(x)-1; i>pow2+1; i--) if (signe(x[i])) x[i-pow2] = lsubii((GEN)x[i-pow2], (GEN)x[i]); return normalizepol_i(x, i+1);} |
red_cyclo2n(GEN x, int n) { return red_cyclo2n_ip(dummycopy(x), n); } | red_cyclo2n(GEN x, long n) { return red_cyclo2n_ip(dummycopy(x), n); } | red_cyclo2n(GEN x, int n) { return red_cyclo2n_ip(dummycopy(x), n); } |
autvec_AL(int pk, GEN z, GEN v, Red *R) | autvec_AL(long pk, GEN z, GEN v, Red *R) | autvec_AL(int pk, GEN z, GEN v, Red *R){ const int r = umodiu(R->N, pk); GEN s = polun[varn(R->C)]; int i, lv = lg(v); for (i=1; i<lv; i++) { long y = (r*v[i]) / pk; if (y) s = RgXQ_mul(s, RgXQ_u_pow(aut(pk,z, v[i]), y, R->C), R->C); } return s;} |
const int r = umodiu(R->N, pk); | const long r = umodiu(R->N, pk); | autvec_AL(int pk, GEN z, GEN v, Red *R){ const int r = umodiu(R->N, pk); GEN s = polun[varn(R->C)]; int i, lv = lg(v); for (i=1; i<lv; i++) { long y = (r*v[i]) / pk; if (y) s = RgXQ_mul(s, RgXQ_u_pow(aut(pk,z, v[i]), y, R->C), R->C); } return s;} |
int i, lv = lg(v); | long i, lv = lg(v); | autvec_AL(int pk, GEN z, GEN v, Red *R){ const int r = umodiu(R->N, pk); GEN s = polun[varn(R->C)]; int i, lv = lg(v); for (i=1; i<lv; i++) { long y = (r*v[i]) / pk; if (y) s = RgXQ_mul(s, RgXQ_u_pow(aut(pk,z, v[i]), y, R->C), R->C); } return s;} |
printf ("Can't create syslog seamphore: %d\n", sc); | printf ("Can't create syslog semaphore: %d\n", sc); | openlog (const char *ident, int logstat, int logfac){ rtems_status_code sc; struct sockaddr_in myAddress; if (ident != NULL) LogTag = ident; LogStatus = logstat; if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0) LogFacility = logfac; /* * Create the socket */ if ((LogFd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { printf ("Can't create syslog socket: %d\n", errno); return; } /* * Bind socket to name */ myAddress.sin_family = AF_INET; myAddress.sin_addr.s_addr = INADDR_ANY; myAddress.sin_port = 0; memset (myAddress.sin_zero, '\0', sizeof myAddress.sin_zero); if (bind (LogFd, (struct sockaddr *)&myAddress, sizeof (myAddress)) < 0) { close (LogFd); LogFd = -1; printf ("Can't bind syslog socket: %d\n", errno); return; } /* * Create the mutex */ sc = rtems_semaphore_create (rtems_build_name('s', 'L', 'o', 'g'), 1, RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0, &LogSemaphore); if (sc != RTEMS_SUCCESSFUL) { printf ("Can't create syslog seamphore: %d\n", sc); close (LogFd); LogFd = -1; }} |
if (l[i+1].nb) { xsml = xbig = l[i ].d[0]; ysml = ybig = l[i+1].d[0]; break; } | if (l[i+1].nb) break; | gtodblList(GEN data, long flags){ dblPointList *l; double xsml,xbig,ysml,ybig; long tx=typ(data), ty, nl=lg(data)-1, lx1,lx; register long i,j,u,v; long param=(flags & PLOT_PARAMETRIC); GEN x,y; if (! is_vec_t(tx)) err(talker,"not a vector in gtodblList"); if (!nl) return NULL; lx1 = lg(data[1]); if (nl == 1) err(talker,"single vector in gtodblList"); /* Allocate memory, then convert coord. to double */ l = (dblPointList*) gpmalloc(nl*sizeof(dblPointList)); for (i=0; i<nl-1; i+=2) { u = i+1; x = (GEN)data[u]; tx = typ(x); y = (GEN)data[u+1]; ty = typ(y); if (!is_vec_t(tx) || !is_vec_t(ty)) err(ploter4); lx = lg(x); if (lg(y) != lx) err(ploter5); if (!param && lx != lx1) err(ploter5); lx--; l[i].d = (double*) gpmalloc(lx*sizeof(double)); l[u].d = (double*) gpmalloc(lx*sizeof(double)); for (j=0; j<lx; j=v) { v = j+1; l[i].d[j] = gtodouble((GEN)x[v]); l[u].d[j] = gtodouble((GEN)y[v]); } l[i].nb = l[u].nb = lx; } /* Now compute extremas */ if (param) { l[0].nb = nl/2; for (i=0; i < l[0].nb; i+=2) if (l[i+1].nb) { xsml = xbig = l[i ].d[0]; ysml = ybig = l[i+1].d[0]; break; } if (i >= l[0].nb) { free(l); return NULL; } for (i=0; i < l[0].nb; i+=2) { u = i+1; for (j=0; j < l[u].nb; j++) { if (l[i].d[j] < xsml) xsml = l[i].d[j]; else if (l[i].d[j] > xbig) xbig = l[i].d[j]; if (l[u].d[j] < ysml) ysml = l[u].d[j]; else if (l[u].d[j] > ybig) ybig = l[u].d[j]; } } } else { if (!l[0].nb) { free(l); return NULL; } l[0].nb = nl-1; xsml = xbig = l[0].d[0]; ysml = ybig = l[1].d[0]; for (j=0; j < l[1].nb; j++) { if (l[0].d[j] < xsml) xsml = l[0].d[j]; else if (l[0].d[j] > xbig) xbig = l[0].d[j]; } for (i=1; i <= l[0].nb; i++) for (j=0; j < l[i].nb; j++) { if (l[i].d[j] < ysml) ysml = l[i].d[j]; else if (l[i].d[j] > ybig) ybig = l[i].d[j]; } } l[0].xsml = xsml; l[0].xbig = xbig; l[0].ysml = ysml; l[0].ybig = ybig; return l;} |
xsml = xbig = l[i ].d[0]; ysml = ybig = l[i+1].d[0]; | gtodblList(GEN data, long flags){ dblPointList *l; double xsml,xbig,ysml,ybig; long tx=typ(data), ty, nl=lg(data)-1, lx1,lx; register long i,j,u,v; long param=(flags & PLOT_PARAMETRIC); GEN x,y; if (! is_vec_t(tx)) err(talker,"not a vector in gtodblList"); if (!nl) return NULL; lx1 = lg(data[1]); if (nl == 1) err(talker,"single vector in gtodblList"); /* Allocate memory, then convert coord. to double */ l = (dblPointList*) gpmalloc(nl*sizeof(dblPointList)); for (i=0; i<nl-1; i+=2) { u = i+1; x = (GEN)data[u]; tx = typ(x); y = (GEN)data[u+1]; ty = typ(y); if (!is_vec_t(tx) || !is_vec_t(ty)) err(ploter4); lx = lg(x); if (lg(y) != lx) err(ploter5); if (!param && lx != lx1) err(ploter5); lx--; l[i].d = (double*) gpmalloc(lx*sizeof(double)); l[u].d = (double*) gpmalloc(lx*sizeof(double)); for (j=0; j<lx; j=v) { v = j+1; l[i].d[j] = gtodouble((GEN)x[v]); l[u].d[j] = gtodouble((GEN)y[v]); } l[i].nb = l[u].nb = lx; } /* Now compute extremas */ if (param) { l[0].nb = nl/2; for (i=0; i < l[0].nb; i+=2) if (l[i+1].nb) { xsml = xbig = l[i ].d[0]; ysml = ybig = l[i+1].d[0]; break; } if (i >= l[0].nb) { free(l); return NULL; } for (i=0; i < l[0].nb; i+=2) { u = i+1; for (j=0; j < l[u].nb; j++) { if (l[i].d[j] < xsml) xsml = l[i].d[j]; else if (l[i].d[j] > xbig) xbig = l[i].d[j]; if (l[u].d[j] < ysml) ysml = l[u].d[j]; else if (l[u].d[j] > ybig) ybig = l[u].d[j]; } } } else { if (!l[0].nb) { free(l); return NULL; } l[0].nb = nl-1; xsml = xbig = l[0].d[0]; ysml = ybig = l[1].d[0]; for (j=0; j < l[1].nb; j++) { if (l[0].d[j] < xsml) xsml = l[0].d[j]; else if (l[0].d[j] > xbig) xbig = l[0].d[j]; } for (i=1; i <= l[0].nb; i++) for (j=0; j < l[i].nb; j++) { if (l[i].d[j] < ysml) ysml = l[i].d[j]; else if (l[i].d[j] > ybig) ybig = l[i].d[j]; } } l[0].xsml = xsml; l[0].xbig = xbig; l[0].ysml = ysml; l[0].ybig = ybig; return l;} |
|
GEN d = mppgcd(a,q); | GEN d = gcdii(a,q); | gcarreparfait(GEN x){ pari_sp av; GEN p1,a,p; long tx=typ(x),l,i,v; switch(tx) { case t_INT: return carreparfait(x)? gun: gzero; case t_REAL: return (signe(x)>=0)? gun: gzero; case t_INTMOD: { GEN b, q; long w; a = (GEN)x[2]; if (!signe(a)) return gun; av = avma; q = absi((GEN)x[1]); v = vali(q); if (v) /* > 0 */ { long dv; w = vali(a); dv = v - w; if (dv > 0) { if (w & 1) { avma = av; return gzero; } if (dv >= 2) { b = w? shifti(a,-w): a; if ((dv>=3 && mod8(b) != 1) || (dv==2 && mod4(b) != 1)) { avma = av; return gzero; } } } q = shifti(q, -v); } /* q is now odd */ i = kronecker(a,q); if (i < 0) { avma = av; return gzero; } if (i==0) { GEN d = mppgcd(a,q); p = (GEN)factor(d)[1]; l = lg(p); for (i=1; i<l; i++) { v = pvaluation(a,(GEN)p[i],&p1); w = pvaluation(q,(GEN)p[i], &q); if (v < w && (v&1 || kronecker(p1,(GEN)p[i]) == -1)) { avma = av; return gzero; } } if (kronecker(a,q) == -1) { avma = av; return gzero; } } /* kro(a,q) = 1, q odd: need to factor q */ p = (GEN)factor(q)[1]; l = lg(p) - 1; /* kro(a,q) = 1, check all p|q but the last (product formula) */ for (i=1; i<l; i++) if (kronecker(a,(GEN)p[i]) == -1) { avma = av; return gzero; } return gun; } case t_FRAC: av=avma; l=carreparfait(mulii((GEN)x[1],(GEN)x[2])); avma=av; return l? gun: gzero; case t_COMPLEX: return gun; case t_PADIC: a = (GEN)x[4]; if (!signe(a)) return gun; if (valp(x)&1) return gzero; p = (GEN)x[2]; if (!egalii(p, gdeux)) return (kronecker(a,p)== -1)? gzero: gun; v = precp(x); /* here p=2, a is odd */ if ((v>=3 && mod8(a) != 1 ) || (v==2 && mod4(a) != 1)) return gzero; return gun; case t_POL: return stoi( polcarrecomplet(x,NULL) ); case t_SER: if (!signe(x)) return gun; if (valp(x)&1) return gzero; return gcarreparfait((GEN)x[2]); case t_RFRAC: av=avma; l=itos(gcarreparfait(gmul((GEN)x[1],(GEN)x[2]))); avma=av; return stoi(l); case t_QFR: case t_QFI: return gcarreparfait((GEN)x[1]); case t_VEC: case t_COL: case t_MAT: l=lg(x); p1=cgetg(l,tx); for (i=1; i<l; i++) p1[i]=(long)gcarreparfait((GEN)x[i]); return p1; } err(typeer,"issquare"); return NULL; /* not reached */} |
long i, n; | long i, G; | constpi(long prec){ GEN A, B, C, tmppi; long i, n; pari_sp av, av2; if (gpi && lg(gpi) >= prec) return; av = avma; tmppi = newbloc(prec); *tmppi = evaltyp(t_REAL) | evallg(prec); /* 0.10... ~ log(2) / log( (2*Pi^4) / (Pi - (1+1/sqrt(2))^2) ) */ n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; prec++; A = real_1(prec); B = sqrtr_abs(real2n(1,prec)); setexpo(B, -1); /* = 1/sqrt(2) */ C = real2n(-2, prec); av2 = avma; for (i = 0; i < n; i++) { GEN y = A, a,b; a = addrr(A,B); setexpo(a, expo(a)-1); b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); affrr(subrr(C, y), C); affrr(a, A); affrr(b, B); avma = av2; } setexpo(C, expo(C)+2); affrr(divrr(gsqr(addrr(A,B)), C), tmppi); if (gpi) gunclone(gpi); avma = av; gpi = tmppi;} |
n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; | G = - bit_accuracy(prec); | constpi(long prec){ GEN A, B, C, tmppi; long i, n; pari_sp av, av2; if (gpi && lg(gpi) >= prec) return; av = avma; tmppi = newbloc(prec); *tmppi = evaltyp(t_REAL) | evallg(prec); /* 0.10... ~ log(2) / log( (2*Pi^4) / (Pi - (1+1/sqrt(2))^2) ) */ n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; prec++; A = real_1(prec); B = sqrtr_abs(real2n(1,prec)); setexpo(B, -1); /* = 1/sqrt(2) */ C = real2n(-2, prec); av2 = avma; for (i = 0; i < n; i++) { GEN y = A, a,b; a = addrr(A,B); setexpo(a, expo(a)-1); b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); affrr(subrr(C, y), C); affrr(a, A); affrr(b, B); avma = av2; } setexpo(C, expo(C)+2); affrr(divrr(gsqr(addrr(A,B)), C), tmppi); if (gpi) gunclone(gpi); avma = av; gpi = tmppi;} |
for (i = 0; i < n; i++) | for (i = 0;; i++) | constpi(long prec){ GEN A, B, C, tmppi; long i, n; pari_sp av, av2; if (gpi && lg(gpi) >= prec) return; av = avma; tmppi = newbloc(prec); *tmppi = evaltyp(t_REAL) | evallg(prec); /* 0.10... ~ log(2) / log( (2*Pi^4) / (Pi - (1+1/sqrt(2))^2) ) */ n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; prec++; A = real_1(prec); B = sqrtr_abs(real2n(1,prec)); setexpo(B, -1); /* = 1/sqrt(2) */ C = real2n(-2, prec); av2 = avma; for (i = 0; i < n; i++) { GEN y = A, a,b; a = addrr(A,B); setexpo(a, expo(a)-1); b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); affrr(subrr(C, y), C); affrr(a, A); affrr(b, B); avma = av2; } setexpo(C, expo(C)+2); affrr(divrr(gsqr(addrr(A,B)), C), tmppi); if (gpi) gunclone(gpi); avma = av; gpi = tmppi;} |
GEN y = A, a,b; | GEN y, a, b, B_A = subrr(B, A); if (expo(B_A) < G) break; | constpi(long prec){ GEN A, B, C, tmppi; long i, n; pari_sp av, av2; if (gpi && lg(gpi) >= prec) return; av = avma; tmppi = newbloc(prec); *tmppi = evaltyp(t_REAL) | evallg(prec); /* 0.10... ~ log(2) / log( (2*Pi^4) / (Pi - (1+1/sqrt(2))^2) ) */ n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; prec++; A = real_1(prec); B = sqrtr_abs(real2n(1,prec)); setexpo(B, -1); /* = 1/sqrt(2) */ C = real2n(-2, prec); av2 = avma; for (i = 0; i < n; i++) { GEN y = A, a,b; a = addrr(A,B); setexpo(a, expo(a)-1); b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); affrr(subrr(C, y), C); affrr(a, A); affrr(b, B); avma = av2; } setexpo(C, expo(C)+2); affrr(divrr(gsqr(addrr(A,B)), C), tmppi); if (gpi) gunclone(gpi); avma = av; gpi = tmppi;} |
b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); | b = sqrtr_abs( mulrr(A, B) ); y = gsqr(B_A); setexpo(y, expo(y) + i - 2); | constpi(long prec){ GEN A, B, C, tmppi; long i, n; pari_sp av, av2; if (gpi && lg(gpi) >= prec) return; av = avma; tmppi = newbloc(prec); *tmppi = evaltyp(t_REAL) | evallg(prec); /* 0.10... ~ log(2) / log( (2*Pi^4) / (Pi - (1+1/sqrt(2))^2) ) */ n = (long)ceil( log2( bit_accuracy_mul(prec, 0.10263977) ) ); if (n < 1) n = 1; prec++; A = real_1(prec); B = sqrtr_abs(real2n(1,prec)); setexpo(B, -1); /* = 1/sqrt(2) */ C = real2n(-2, prec); av2 = avma; for (i = 0; i < n; i++) { GEN y = A, a,b; a = addrr(A,B); setexpo(a, expo(a)-1); b = sqrtr_abs( mulrr(y, B) ); y = gsqr(subrr(a,y)); setexpo(y, expo(y) + i); affrr(subrr(C, y), C); affrr(a, A); affrr(b, B); avma = av2; } setexpo(C, expo(C)+2); affrr(divrr(gsqr(addrr(A,B)), C), tmppi); if (gpi) gunclone(gpi); avma = av; gpi = tmppi;} |
case FIONREAD: *(int *)args->buffer = tty->ccount - tty->cindex; break; | rtems_termios_ioctl (void *arg){ rtems_libio_ioctl_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; rtems_status_code sc; args->ioctl_return = 0; sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) { args->ioctl_return = sc; return sc; } switch (args->command) { default: sc = RTEMS_INVALID_NUMBER; break; case RTEMS_IO_GET_ATTRIBUTES: *(struct termios *)args->buffer = tty->termios; break; case RTEMS_IO_SET_ATTRIBUTES: tty->termios = *(struct termios *)args->buffer; /* check for and process change in flow control options */ termios_set_flowctrl(tty); if (tty->termios.c_lflag & ICANON) { tty->rawInBufSemaphoreOptions = RTEMS_WAIT; tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT; tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; } else { rtems_interval ticksPerSecond; rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond); tty->vtimeTicks = tty->termios.c_cc[VTIME] * ticksPerSecond / 10; if (tty->termios.c_cc[VTIME]) { tty->rawInBufSemaphoreOptions = RTEMS_WAIT; tty->rawInBufSemaphoreTimeout = tty->vtimeTicks; if (tty->termios.c_cc[VMIN]) tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; else tty->rawInBufSemaphoreFirstTimeout = tty->vtimeTicks; } else { if (tty->termios.c_cc[VMIN]) { tty->rawInBufSemaphoreOptions = RTEMS_WAIT; tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT; tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; } else { tty->rawInBufSemaphoreOptions = RTEMS_NO_WAIT; } } } if (tty->device.setAttributes) (*tty->device.setAttributes)(tty->minor, &tty->termios); break; case RTEMS_IO_TCDRAIN: drainOutput (tty); break; } rtems_semaphore_release (tty->osem); args->ioctl_return = sc; return sc;} |
|
size = BITS_IN_LONG - bfffo(n[2]); | size = BITS_IN_LONG - bfffo((ulong)n[2]); | pollardbrent(GEN n){ long tf = lgefint(n), size = 0, delta, retries = 0, msg_mask; long c0, c, k, k1, l, avP, avx, GGG, av = avma; GEN x, x1, y, P, g, g1, res; if (DEBUGLEVEL >= 4) (void)timer2(); /* clear timer */ if (tf >= 4) size = expi(n) + 1; else if (tf == 3) /* try to keep purify happy... */ size = BITS_IN_LONG - bfffo(n[2]); if (size <= 28) c0 = 32; /* amounts very nearly to `insist'. * Now that we have squfof(), we don't insist * any more when input is 2^29 ... 2^32 */ else if (size <= 42) c0 = tune_pb_min; else if (size <= 59) /* match squfof() cutoff point */ c0 = tune_pb_min + ((size - 42)<<1); else if (size <= 72) c0 = tune_pb_min + size - 24; else if (size <= 301) /* nonlinear increase in effort, kicking in around 80 bits */ /* 301 gives 48121 + tune_pb_min */ c0 = tune_pb_min + size - 60 + ((size-73)>>1)*((size-70)>>3)*((size-56)>>4); else c0 = 49152; /* ECM is faster when it'd take longer */ c = c0 << 5; /* 32 iterations per round */ msg_mask = (size >= 448? 0x1fff: (size >= 192? (256L<<((size-128)>>6))-1: 0xff));PB_RETRY: /* trick to make a `random' choice determined by n. Don't use x^2+0 or * x^2-2, ever. Don't use x^2-3 or x^2-7 with a starting value of 2. * x^2+4, x^2+9 are affine conjugate to x^2+1, so don't use them either. * * (the point being that when we get called again on a composite cofactor * of something we've already seen, we had better avoid the same delta) */ switch ((size + retries) & 7) { case 0: delta= 1; break; case 1: delta= -1; break; case 2: delta= 3; break; case 3: delta= 5; break; case 4: delta= -5; break; case 5: delta= 7; break; case 6: delta= 11; break; /* case 7: */ default: delta=-11; break; } if (DEBUGLEVEL >= 4) { if (!retries) { if (size < 1536) fprintferr("Rho: searching small factor of %ld-bit integer\n", size); else fprintferr("Rho: searching small factor of %ld-word integer\n", tf-2); } else fprintferr("Rho: restarting for remaining rounds...\n"); fprintferr("Rho: using X^2%+1ld for up to %ld rounds of 32 iterations\n", delta, c >> 5); flusherr(); } x=gdeux; P=gun; g1 = NULL; k = 1; l = 1; (void)new_chunk(10 + 6 * tf); /* enough for cgetg(10) + 3 divii */ y = cgeti(tf); affsi(2, y); x1= cgeti(tf); affsi(2, x1); avx = avma; avP = (long)new_chunk(2 * tf); /* enough for x = addsi(tf+1) */ GGG = (long)new_chunk(4 * tf); /* enough for P = modii(2tf+1, tf) */ for (;;) /* terminated under the control of c */ { /* use the polynomial x^2 + delta */#define one_iter() {\ avma = GGG; x = resii(sqri(x), n); /* to garbage zone */\ avma = avx; x = addsi(delta,x); /* erase garbage */\ avma = GGG; P = mulii(P, subii(x1, x));\ avma = avP; P = modii(P,n); } one_iter(); if ((--c & 0x1f)==0) /* one round complete */ { g = mppgcd(n, P); if (!is_pm1(g)) goto fin; /* caught something */ if (c <= 0) { /* getting bored */ if (DEBUGLEVEL >= 4) { fprintferr("Rho: time = %6ld ms,\tPollard-Brent giving up.\n", timer2()); flusherr(); } avma=av; return NULL; } P = gun; /* not necessary, but saves 1 mulii/round */ if (DEBUGLEVEL >= 4) rho_dbg(c0-(c>>5), msg_mask); affii(x,y); } if (--k) continue; /* normal end of loop body */ if (c & 0x1f) /* otherwise, we already checked */ { g = mppgcd(n, P); if (!is_pm1(g)) goto fin; P = gun; } /* Fast forward phase, doing l inner iterations without computing gcds. * Check first whether it would take us beyond the alloted time. * Fast forward rounds count only half (although they're taking * more like 2/3 the time of normal rounds). This to counteract the * nuisance that all c0 between 4096 and 6144 would act exactly as * 4096; with the halving trick only the range 4096..5120 collapses * (similarly for all other powers of two) */ if ((c-=(l>>1)) <= 0) { /* got bored */ if (DEBUGLEVEL >= 4) { fprintferr("Rho: time = %6ld ms,\tPollard-Brent giving up.\n", timer2()); flusherr(); } avma=av; return NULL; } c &= ~0x1f; /* keep it on multiples of 32 */ /* Fast forward loop */ affii(x, x1); k = l; l <<= 1; /* don't show this for the first several (short) fast forward phases. */ if (DEBUGLEVEL >= 4 && (l>>7) > msg_mask) { fprintferr("Rho: fast forward phase (%ld rounds of 64)...\n", l>>7); flusherr(); } for (k1=k; k1; k1--) one_iter(); if (DEBUGLEVEL >= 4 && (l>>7) > msg_mask) { fprintferr("Rho: time = %6ld ms,\t%3ld rounds, back to normal mode\n", timer2(), c0-(c>>5)); flusherr(); } affii(x,y); } /* forever */fin: /* An accumulated gcd was > 1 */ /* if it isn't n, and looks prime, return it */ if (!egalii(g,n)) { if (miller(g,17)) { if (DEBUGLEVEL >= 4) { rho_dbg(c0-(c>>5), 0); fprintferr("\tfound factor = %Z\n",g); flusherr(); } avma=av; return icopy(g); } avma = avx; g1 = icopy(g); /* known composite, keep it safe */ avx = avma; } else g1 = n; /* and work modulo g1 for backtracking */ /* Here g1 is known composite */ if (DEBUGLEVEL >= 4 && size > 192) { fprintferr("Rho: hang on a second, we got something here...\n"); flusherr(); } for(;;) /* backtrack until period recovered. Must terminate */ { avma = GGG; y = resii(sqri(y), g1); avma = avx; y = addsi(delta,y); g = mppgcd(subii(x1, y), g1); if (!is_pm1(g)) break; if (DEBUGLEVEL >= 4 && (--c & 0x1f) == 0) rho_dbg(c0-(c>>5), msg_mask); } avma = av; /* safe */ if (g1 == n || egalii(g,g1)) { if (g1 == n && egalii(g,g1)) { /* out of luck */ if (DEBUGLEVEL >= 4) { rho_dbg(c0-(c>>5), 0); fprintferr("\tPollard-Brent failed.\n"); flusherr(); } if (++retries >= 4) return NULL; goto PB_RETRY; } /* half lucky: we've split n, but g1 equals either g or n */ if (DEBUGLEVEL >= 4) { rho_dbg(c0-(c>>5), 0); fprintferr("\tfound %sfactor = %Z\n", (g1!=n ? "composite " : ""), g); flusherr(); } res = cgetg(7, t_VEC); res[1] = licopy(g); /* factor */ res[2] = un; /* exponent 1 */ res[3] = (g1!=n? zero: (long)NULL); /* known composite when g1!=n */ res[4] = ldivii(n,g); /* cofactor */ res[5] = un; /* exponent 1 */ res[6] = (long)NULL; /* unknown */ return res; } /* g < g1 < n : our lucky day -- we've split g1, too */ res = cgetg(10, t_VEC); /* unknown status for all three factors */ res[1] = licopy(g); res[2] = un; res[3] = (long)NULL; res[4] = ldivii(g1,g); res[5] = un; res[6] = (long)NULL; res[7] = ldivii(n,g1); res[8] = un; res[9] = (long)NULL; if (DEBUGLEVEL >= 4) { rho_dbg(c0-(c>>5), 0); fprintferr("\tfound factors = %Z, %Z,\n\tand %Z\n", res[1], res[4], res[7]); flusherr(); } return res;} |
case t_COMPLEX: case t_POL: case t_SER: case t_RFRAC: case t_RFRACN: | case t_COMPLEX: av = avma; y = cgetg(3, t_COMPLEX); y[2] = lrndtoi((GEN)x[2], e); if (!signe(y[2])) { avma = av; y = grndtoi((GEN)x[1], &e1); } else y[1] = lrndtoi((GEN)x[1], &e1); if (e1 > *e) *e = e1; return y; case t_POL: case t_SER: case t_RFRAC: case t_RFRACN: | grndtoi(GEN x, long *e){ GEN y,p1; long i, tx=typ(x), lx, ex, e1; pari_sp av; *e = -(long)HIGHEXPOBIT; switch(tx) { case t_INT: case t_INTMOD: case t_QUAD: case t_FRAC: case t_FRACN: return ground(x); case t_REAL: av=avma; p1=gadd(ghalf,x); ex=expo(p1); if (ex<0) { if (signe(p1)>=0) { *e=expo(x); avma=av; return gzero; } *e=expo(addsr(1,x)); avma=av; return negi(gun); } lx=lg(x); e1 = ex - bit_accuracy(lx) + 1; y = ishiftr_spec(p1, lx, e1); if (signe(x)<0) y=addsi(-1,y); y = gerepileuptoint(av,y); if (e1<=0) { av=avma; e1=expo(subri(x,y)); avma=av; } *e=e1; return y; case t_POLMOD: y=cgetg(3,t_POLMOD); copyifstack(x[1],y[1]); y[2]=lrndtoi((GEN)x[2],e); return y; case t_COMPLEX: case t_POL: case t_SER: case t_RFRAC: case t_RFRACN: case t_VEC: case t_COL: case t_MAT: lx=(tx==t_POL)? lgef(x): lg(x); y=cgetg(lx,tx); for (i=1; i<lontyp[tx]; i++) y[i]=x[i]; for ( ; i<lx; i++) { y[i]=lrndtoi((GEN)x[i],&e1); if (e1>*e) *e=e1; } return y; } err(typeer,"grndtoi"); return NULL; /* not reached */} |
stackdummy(z + ly, lz - ly - 1); | stackdummy(z + ly, lz - ly); | rfixlg(GEN z, GEN y) { long ly = lg(y), lz = lg(z); if (ly < lz) { setlg(z, ly); stackdummy(z + ly, lz - ly - 1); }} |
printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); rtems_task_delete(_Thread_Executing->Object.id); | if (_ISR_Nest_level > 0) { printk("Exception while executing ISR!!!. System locked\n"); while(1); } else { printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); rtems_task_delete(_Thread_Executing->Object.id); } | void _defaultExcHandler (CPU_Exception_frame *ctx){ printk("----------------------------------------------------------\n"); printk("Exception %d caught at PC %x by thread %d\n", ctx->idtIndex, ctx->eip, _Thread_Executing->Object.id); printk("----------------------------------------------------------\n"); printk("Processor execution context at time of the fault was :\n"); printk("----------------------------------------------------------\n"); printk(" EAX = %x EBX = %x ECX = %x EDX = %x\n", ctx->eax, ctx->ebx, ctx->ecx, ctx->edx); printk(" ESI = %x EDI = %x EBP = %x ESP = %x\n", ctx->esi, ctx->edi, ctx->ebp, ctx->esp0); printk("----------------------------------------------------------\n"); printk("Error code pushed by processor itself (if not 0) = %x\n", ctx->faultCode); printk("----------------------------------------------------------\n\n"); printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); /* * OK I could probably use a simplified version but at least this * should work. */ rtems_task_delete(_Thread_Executing->Object.id);} |
dbg_outrel(long iz,long jideal,long bouext,long bou,long phase,long cmptglob, GEN vperm,long **ma,GEN maarch) | dbg_outrel(long phase,long cmptglob, GEN vperm,long **ma,GEN maarch) | dbg_outrel(long iz,long jideal,long bouext,long bou,long phase,long cmptglob, GEN vperm,long **ma,GEN maarch){ long av,i,j; GEN p1,p2; if (phase == 0) { fprintferr("Upon exit: iz=%ld,jideal=%ld,bouext=%ld,bou=%ld,phase=%ld\n", iz,jideal,bouext,bou,phase); av=avma; p2=cgetg(cmptglob+1,t_MAT); for (j=1; j<=cmptglob; j++) { p1=cgetg(KC+1,t_COL); p2[j]=(long)p1; for (i=1; i<=KC; i++) p1[i]=lstoi(ma[j][i]); } fprintferr("\nRank = %ld, time = %ld\n",rank(p2),timer2()); if (DEBUGLEVEL>3) { fprintferr("relations = \n"); for (j=1; j <= cmptglob; j++) wr_rel(ma[j]); fprintferr("\nmatarch = %Z\n",maarch); } avma=av; } else if (DEBUGLEVEL>6) { fprintferr("before hnfadd:\nvectbase[vperm[]] = \n"); fprintferr("["); for (i=1; i<=KC; i++) { bruterr((GEN)vectbase[vperm[i]],'g',-1); if (i<KC) fprintferr(","); } fprintferr("]~\n"); } flusherr();} |
fprintferr("Upon exit: iz=%ld,jideal=%ld,bouext=%ld,bou=%ld,phase=%ld\n", iz,jideal,bouext,bou,phase); | dbg_outrel(long iz,long jideal,long bouext,long bou,long phase,long cmptglob, GEN vperm,long **ma,GEN maarch){ long av,i,j; GEN p1,p2; if (phase == 0) { fprintferr("Upon exit: iz=%ld,jideal=%ld,bouext=%ld,bou=%ld,phase=%ld\n", iz,jideal,bouext,bou,phase); av=avma; p2=cgetg(cmptglob+1,t_MAT); for (j=1; j<=cmptglob; j++) { p1=cgetg(KC+1,t_COL); p2[j]=(long)p1; for (i=1; i<=KC; i++) p1[i]=lstoi(ma[j][i]); } fprintferr("\nRank = %ld, time = %ld\n",rank(p2),timer2()); if (DEBUGLEVEL>3) { fprintferr("relations = \n"); for (j=1; j <= cmptglob; j++) wr_rel(ma[j]); fprintferr("\nmatarch = %Z\n",maarch); } avma=av; } else if (DEBUGLEVEL>6) { fprintferr("before hnfadd:\nvectbase[vperm[]] = \n"); fprintferr("["); for (i=1; i<=KC; i++) { bruterr((GEN)vectbase[vperm[i]],'g',-1); if (i<KC) fprintferr(","); } fprintferr("]~\n"); } flusherr();} |
|
rtems_unsigned32 isrlevel; | uint32_t isrlevel; | rtems_device_driver Clock_control( rtems_device_major_number major, rtems_device_minor_number minor, void *pargp){ rtems_unsigned32 isrlevel; rtems_libio_ioctl_args_t *args = pargp; if (args == 0) goto done; /* * This is hokey, but until we get a defined interface * to do this, it will just be this simple... */ if (args->command == rtems_build_name('I', 'S', 'R', ' ')) { Clock_isr(CLOCK_VECTOR); } else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) { rtems_interrupt_disable( isrlevel ); (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); rtems_interrupt_enable( isrlevel ); } done: return RTEMS_SUCCESSFUL;} |
if (avma - bot < need>>1) { | if (avma - bot < (ulong)need>>1) { | initprimes0(ulong maxnum, long *lenp, long *lastp){ long k, size, alloced, asize, psize, rootnum, curlow, last, remains, need; byteptr q,r,s,fin, p, p1, fin1, plast, curdiff;#if 0 fprintferr("initprimes0: called for maxnum = %lu\n", maxnum);#endif if (maxnum <= 1ul<<17) /* Arbitrary. */ return initprimes1(maxnum>>1, lenp, lastp); maxnum |= 1; /* make it odd. */ /* Checked to be enough up to 40e6, attained at 155893 */ size = (long) (1.09 * maxnum/log((double)maxnum)) + 145; p1 = (byteptr) gpmalloc(size); rootnum = (long) sqrt((double)maxnum); /* cast it back to a long */ rootnum |= 1;#if 0 fprintferr("initprimes0: rootnum = %ld\n", rootnum);#endif { byteptr p2 = initprimes0(rootnum, &psize, &last); /* recursive call */ memcpy(p1, p2, psize); free(p2); } fin1 = p1 + psize - 1; remains = (maxnum - rootnum) >> 1; /* number of odd numbers to check */ need = 100 * rootnum; /* Make % overhead negligeable. */ if (need < PRIME_ARENA) need = PRIME_ARENA; if (avma - bot < need>>1) { /* need to do our own allocation */ alloced = 1; asize = need; } else { /* scratch area is free part of PARI stack */ alloced = 0; asize = avma - bot; } if (asize > remains) asize = remains + 1;/* + room for a sentinel byte */ if (alloced) p = (byteptr) gpmalloc(asize); else p = (byteptr) bot; fin = p + asize - 1; /* the 0 sentinel goes at fin. */ curlow = rootnum + 2; /* We know all primes up to rootnum (odd). */ curdiff = fin1; /* During each iteration p..fin-1 represents a range of odd numbers. plast is a pointer which represents the last prime seen, it may point before p..fin-1. */ plast = p - ((rootnum - last) >> 1) - 1; while (remains) { if (asize > remains) { asize = remains + 1; fin = p + asize - 1; } memset(p, 0, asize); /* p corresponds to curlow. q runs over primediffs. */ for (q = p1+2, k = 3; q <= fin1; k += *q++) { /* The first odd number which is >= curlow and divisible by p equals (if curlow > p) the last odd number which is <= curlow + 2p - 1 and 0 (mod p) which equals p + the last even number which is <= curlow + p - 1 and 0 (mod p) which equals p + the last even number which is <= curlow + p - 2 and 0 (mod p) which equals p + curlow + p - 2 - (curlow + p - 2)) % 2p. */ long k2 = k*k - curlow; if (k2 > 0) { r = p + (k2 >>= 1); if (k2 > remains) break; /* Guard against an address wrap. */ } else r = p - (((curlow+k-2) % (2*k)) >> 1) + k - 1; for (s = r; s < fin; s += k) *s = 1; } /* now q runs over addresses corresponding to primes */ for (q = p; ; plast = q++) { while (*q) q++; /* use 0-sentinel at end */ if (q >= fin) break; *curdiff++ = (q - plast) << 1; } plast -= asize - 1; remains -= asize - 1; curlow += ((asize - 1)<<1); } /* while (remains) */ last = curlow - ((p - plast) << 1); *curdiff++ = 0; /* sentinel */ *lenp = curdiff - p1; *lastp = last; if (alloced) free(p); return (byteptr) gprealloc(p1, *lenp, size);} |
long tx = typ(x), av = avma, tetpil; | ulong tx = typ(x), av = avma, tetpil; | compimag0(GEN x, GEN y, int raw){ long tx = typ(x), av = avma, tetpil; GEN z; if (typ(y) != tx || tx!=t_QFI) err(typeer,"composition"); if (cmpii((GEN)x[1],(GEN)y[1]) > 0) { z=x; x=y; y=z; } z=cgetg(4,t_QFI); comp_gen(z,x,y); tetpil=avma; return gerepile(av,tetpil,raw? gcopy(z): redimag(z));} |
x = gerepileupto(av, gcopy(x)); | x = gerepilecopy(av, x); | rhoreal_pow(GEN x, long n){ long i, av = avma, lim = stack_lim(av,1); for (i=1; i<=n; i++) { x = rhorealform(x); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"rhoreal_pow"); x = gerepileupto(av, gcopy(x)); } } return gerepileupto(av, gcopy(x));} |
return gerepileupto(av, gcopy(x)); | return gerepilecopy(av, x); | rhoreal_pow(GEN x, long n){ long i, av = avma, lim = stack_lim(av,1); for (i=1; i<=n; i++) { x = rhorealform(x); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"rhoreal_pow"); x = gerepileupto(av, gcopy(x)); } } return gerepileupto(av, gcopy(x));} |
if ( ! equalii(gel(a,1),gel(b,1)) || !absi_equal(gel(a,2),gel(b,2)) || ! equalii(gel(a,3),gel(b,3))) return gen_0; x = SL2_div_mul_e1(N,M); if (signe(gel(a,2)) != signe(gel(b,2))) gel(x,2) = negi(gel(x,2)); | if (!GL2_qfb_equal(a,b)) return gen_0; if (signe(gel(a,2))==signe(gel(b,2))) x = SL2_div_mul_e1(N,M); else x = SL2_swap_div_mul_e1(N,M); | qfbimagsolvep(GEN Q, GEN p){ GEN M, N, x,y, a,b,c, d; pari_sp av = avma; if (!signe(gel(Q,2))) { a = gel(Q,1); c = gel(Q,3); /* if principal form, use faster cornacchia */ if (gcmp1(a)) return qfbsolve_cornacchia(c, p, 0); if (gcmp1(c)) return qfbsolve_cornacchia(a, p, 1); } d = qf_disc(Q); if (kronecker(d,p) < 0) return gen_0; a = redimagsl2(Q, &N); if (is_pm1(gel(a,1))) /* principal form */ { long r; if (!signe(gel(a,2))) { a = qfbsolve_cornacchia(gel(a,3), p, 0); return gerepileupto(av, gmul(a, shallowtrans(N))); } /* x^2 + xy + ((1-d)/4)y^2 = p <==> (2x + y)^2 - d y^2 = 4p */ if (!cornacchia2(negi(d), p, &x, &y)) { avma = av; return gen_0; } x = divis_rem(subii(x,y), 2, &r); if (r) { avma = av; return gen_0; } return gerepileupto(av, gmul(mkvec2(x,y), shallowtrans(N))); } b = redimagsl2(primeform(d, p, 0), &M); if ( ! equalii(gel(a,1),gel(b,1)) || !absi_equal(gel(a,2),gel(b,2)) || ! equalii(gel(a,3),gel(b,3))) return gen_0; x = SL2_div_mul_e1(N,M); if (signe(gel(a,2)) != signe(gel(b,2))) gel(x,2) = negi(gel(x,2)); return gerepilecopy(av, x);} |
sd_rl(char *v, int flag) | sd_rl(const char *v, int flag) | sd_rl(char *v, int flag){ static const char * const msg[] = {NULL, "(bits 0x2/0x4 control matched-insert/arg-complete)"}; ulong o_readline_state = readline_state; GEN res; res = sd_ulong(v,flag,"readline", &readline_state, 0, 7, (char**)msg);#ifdef READLINE if (!readline_init && *v && *v != '0') { init_readline(); readline_init = 1; } if (o_readline_state != readline_state) sd_gptoggle(readline_state ? "1" : "0", d_SILENT, "readline", USE_READLINE);#endif return res;} |
unsigned32 count | uint32_t count | ssize_t memfile_write( rtems_libio_t *iop, const void *buffer, unsigned32 count){ IMFS_jnode_t *the_jnode; ssize_t status; the_jnode = iop->file_info; status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count ); iop->size = the_jnode->info.file.size; return status;} |
rtems_unsigned8 usr; | uint8_t usr; | mcfuart_poll_read(mcfuart *uart){ rtems_unsigned8 usr; int ch; if (uart->parerr_mark_flag == 1) { uart->parerr_mark_flag = 0; return 0; } usr = *MCF5206E_USR(MBAR,uart->chn); if ((usr & MCF5206E_USR_RXRDY) != 0) { if (((usr & (MCF5206E_USR_FE | MCF5206E_USR_PE)) != 0) && !(uart->c_iflag & IGNPAR)) { ch = *MCF5206E_URB(MBAR,uart->chn); /* Clear error bits */ if (uart->c_iflag & PARMRK) { uart->parerr_mark_flag = 1; ch = 0xff; } else { ch = 0; } } else { ch = *MCF5206E_URB(MBAR,uart->chn); } } else ch = -1; return ch;} |
p2 = cgetg(ph+1,t_COL); p1[ph] = (long)p2; | p2 = cgetg(ph+1,t_COL); p1[1] = (long)p2; | filltabs(GEN N, int p, int k, ulong ltab, int step5){ const ulong mask = (1<<kglob)-1; pari_sp av; int pk, pk2, i, j, LE = 0; long e; GEN tabt, taba, m, E, p1; pk = u_pow(p,k); ishack = step5 && (pk >= lg((GEN)tabcyc) || !signe(tabcyc[pk])); pk2 = pkfalse; tabcyc[pk2] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = (long)FpX_res(gpowgs(polx[0],i-1), tabcyc[pk2], N); tabeta[pk2] = (long)p1; E = NULL; if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE, t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE, t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (E) { tabE[pk2] = (long)E; p1 = cgetg(LE, t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3, t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk2] = (long)p1; } if (pk > 2 && smodis(N,pk) == 1) { GEN vpa, p1, p2, p3, a2 = NULL, a = finda(N, pk, p, step5); int ph, jj; if (!a) return; ph = pk - pk/p; vpa = cgetg(ph+1,t_COL); vpa[1] = (long)a; if (k > 1) a2 = modii(sqri(a), N); jj = 1; for (i=2; i<pk; i++) /* vpa = { a^i, (i,p) = 1 } */ if (i%p) { jj++; vpa[jj] = lmodii( mulii((i%p==1) ? a2 : a, (GEN)vpa[jj-1]), N ); } if (!gcmp1( modii( mulii(a, (GEN)vpa[ph]), N) )) { if (signe(errfill) <= 0) errfill = stoi(-1); return; } p1 = cgetg(ph+1,t_MAT); p2 = cgetg(ph+1,t_COL); p1[ph] = (long)p2; for (i=1; i<=ph; i++) p2[i] = un; j = ph-1; p1[j] = (long)vpa; p3 = vpa; for (j--; j > 0; j--) { p2 = cgetg(ph+1,t_COL); p1[j] = (long)p2; for (i=1; i<=ph; i++) p2[i] = lmodii(mulii((GEN)vpa[i],(GEN)p3[i]), N); p3 = p2; } tabmatvite[pk2] = p1; tabmatinvvite[pk2] = FpM_inv(p1, N); } tabt = cgetg(ltab+1, t_VECSMALL); taba = cgetg(ltab+1, t_VECSMALL); av = avma; m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { long s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } avma = av; if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk2] = taba; setlg(tabt, e); tabtall[pk2] = tabt;} |
j = ph-1; p1[j] = (long)vpa; p3 = vpa; for (j--; j > 0; j--) | j = 2; p1[j] = (long)vpa; p3 = vpa; for (j++; j <= ph; j++) | filltabs(GEN N, int p, int k, ulong ltab, int step5){ const ulong mask = (1<<kglob)-1; pari_sp av; int pk, pk2, i, j, LE = 0; long e; GEN tabt, taba, m, E, p1; pk = u_pow(p,k); ishack = step5 && (pk >= lg((GEN)tabcyc) || !signe(tabcyc[pk])); pk2 = pkfalse; tabcyc[pk2] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = (long)FpX_res(gpowgs(polx[0],i-1), tabcyc[pk2], N); tabeta[pk2] = (long)p1; E = NULL; if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE, t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE, t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (E) { tabE[pk2] = (long)E; p1 = cgetg(LE, t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3, t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk2] = (long)p1; } if (pk > 2 && smodis(N,pk) == 1) { GEN vpa, p1, p2, p3, a2 = NULL, a = finda(N, pk, p, step5); int ph, jj; if (!a) return; ph = pk - pk/p; vpa = cgetg(ph+1,t_COL); vpa[1] = (long)a; if (k > 1) a2 = modii(sqri(a), N); jj = 1; for (i=2; i<pk; i++) /* vpa = { a^i, (i,p) = 1 } */ if (i%p) { jj++; vpa[jj] = lmodii( mulii((i%p==1) ? a2 : a, (GEN)vpa[jj-1]), N ); } if (!gcmp1( modii( mulii(a, (GEN)vpa[ph]), N) )) { if (signe(errfill) <= 0) errfill = stoi(-1); return; } p1 = cgetg(ph+1,t_MAT); p2 = cgetg(ph+1,t_COL); p1[ph] = (long)p2; for (i=1; i<=ph; i++) p2[i] = un; j = ph-1; p1[j] = (long)vpa; p3 = vpa; for (j--; j > 0; j--) { p2 = cgetg(ph+1,t_COL); p1[j] = (long)p2; for (i=1; i<=ph; i++) p2[i] = lmodii(mulii((GEN)vpa[i],(GEN)p3[i]), N); p3 = p2; } tabmatvite[pk2] = p1; tabmatinvvite[pk2] = FpM_inv(p1, N); } tabt = cgetg(ltab+1, t_VECSMALL); taba = cgetg(ltab+1, t_VECSMALL); av = avma; m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { long s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } avma = av; if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk2] = taba; setlg(tabt, e); tabtall[pk2] = tabt;} |
if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE ) heir->cpu_time_budget = _Thread_Ticks_per_timeslice; | void _Thread_Dispatch( void ){ Thread_Control *executing; Thread_Control *heir; ISR_Level level; executing = _Thread_Executing; _ISR_Disable( level ); while ( _Context_Switch_necessary == TRUE ) { heir = _Thread_Heir; _Thread_Dispatch_disable_level = 1; _Context_Switch_necessary = FALSE; _Thread_Executing = heir; executing->rtems_ada_self = rtems_ada_self; rtems_ada_self = heir->rtems_ada_self; _ISR_Enable( level ); heir->ticks_executed++; /* * Switch libc's task specific data. */ if ( _Thread_libc_reent ) { executing->libc_reent = *_Thread_libc_reent; *_Thread_libc_reent = heir->libc_reent; } _User_extensions_Thread_switch( executing, heir ); if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE ) heir->cpu_time_budget = _Thread_Ticks_per_timeslice; /* * If the CPU has hardware floating point, then we must address saving * and restoring it as part of the context switch. * * The second conditional compilation section selects the algorithm used * to context switch between floating point tasks. The deferred algorithm * can be significantly better in a system with few floating point tasks * because it reduces the total number of save and restore FP context * operations. However, this algorithm can not be used on all CPUs due * to unpredictable use of FP registers by some compilers for integer * operations. */#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE ) if ( executing->fp_context != NULL ) _Context_Save_fp( &executing->fp_context );#endif#endif _Context_Switch( &executing->Registers, &heir->Registers );#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) { if ( _Thread_Allocated_fp != NULL ) _Context_Save_fp( &_Thread_Allocated_fp->fp_context ); _Context_Restore_fp( &executing->fp_context ); _Thread_Allocated_fp = executing; }#else if ( executing->fp_context != NULL ) _Context_Restore_fp( &executing->fp_context );#endif#endif executing = _Thread_Executing; _ISR_Disable( level ); } _Thread_Dispatch_disable_level = 0; _ISR_Enable( level ); if ( _Thread_Do_post_task_switch_extension || executing->do_post_task_switch_extension ) { executing->do_post_task_switch_extension = FALSE; _API_extensions_Run_postswitch(); }} |
|
if (powsubfactorbase) { for (i=lg(powsubfactorbase)-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } | desallocate(long **matcopy){ long i; free(numfactorbase); free(factorbase); free(numideal); free(idealbase); if (powsubfactorbase) { for (i=lg(powsubfactorbase)-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } if (matcopy) { for (i=lg(matcopy)-1; i; i--) free(matcopy[i]); free(matcopy); matcopy = NULL; }} |
|
powsubfb = NULL; | desallocate(long **matcopy){ long i; free(numfactorbase); free(factorbase); free(numideal); free(idealbase); if (powsubfactorbase) { for (i=lg(powsubfactorbase)-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } if (matcopy) { for (i=lg(matcopy)-1; i; i--) free(matcopy[i]); free(matcopy); matcopy = NULL; }} |
|
(void) _Workspace_Free( the_thread->Start.fp_context ); | (void) _Workspace_Free( the_thread->Start.fp_context ); #endif | void _Thread_Close( Objects_Information *information, Thread_Control *the_thread){ _Objects_Close( information, &the_thread->Object ); _Thread_Set_state( the_thread, STATES_TRANSIENT ); if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) { if ( _Watchdog_Is_active( &the_thread->Timer ) ) (void) _Watchdog_Remove( &the_thread->Timer ); } _User_extensions_Thread_delete( the_thread ); #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) if ( _Thread_Is_allocated_fp( the_thread ) ) _Thread_Deallocate_fp();#endif the_thread->fp_context = NULL; if ( the_thread->Start.fp_context ) (void) _Workspace_Free( the_thread->Start.fp_context ); _Thread_Stack_Free( the_thread ); if ( the_thread->extensions ) (void) _Workspace_Free( the_thread->extensions ); the_thread->Start.stack = NULL; the_thread->extensions = NULL;} |
rtems_unsigned32 offset; rtems_unsigned32 good_front_flag; rtems_unsigned32 good_back_flag; | uint32_t offset; uint32_t good_front_flag; uint32_t good_back_flag; | void Screen12(){ void *segment_address_1; void *segment_address_2; void *segment_address_3; rtems_unsigned32 offset; rtems_unsigned32 good_front_flag; rtems_unsigned32 good_back_flag; rtems_status_code status; status = rtems_region_create( 0, Region_good_area, 0x40, 32, RTEMS_DEFAULT_ATTRIBUTES, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NAME, "rtems_region_create with illegal name" ); puts( "TA1 - rtems_region_create - RTEMS_INVALID_NAME" );#if defined(_C3x) || defined(_C4x) puts( "TA1 - rtems_region_create - RTEMS_INVALID_ADDRESS - SKIPPED" );#else status = rtems_region_create( Region_name[ 1 ], Region_bad_area, 0x40, 32, RTEMS_DEFAULT_ATTRIBUTES, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_region_create with illegal address" ); puts( "TA1 - rtems_region_create - RTEMS_INVALID_ADDRESS" );#endif#if defined(_C3x) || defined(_C4x) puts( "TA1 - rtems_region_create - RTEMS_INVALID_SIZE - SKIPPED" );#else status = rtems_region_create( Region_name[ 1 ], Region_good_area, 0x40, 34, RTEMS_DEFAULT_ATTRIBUTES, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_SIZE, "rtems_region_create with illegal size" ); puts( "TA1 - rtems_region_create - RTEMS_INVALID_SIZE" );#endif status = rtems_region_create( Region_name[ 1 ], &Region_good_area[ REGION_START_OFFSET ], REGION_LENGTH, 0x40, RTEMS_DEFAULT_ATTRIBUTES, &Region_id[ 1 ] ); directive_failed( status, "rtems_region_create" ); puts( "TA1 - rtems_region_create - RTEMS_SUCCESSFUL" ); status = rtems_region_create( Region_name[ 1 ], Region_good_area, REGION_LENGTH, 0x40, RTEMS_DEFAULT_ATTRIBUTES, &Junk_id ); fatal_directive_status( status, RTEMS_TOO_MANY, "rtems_region_create of too many" ); puts( "TA1 - rtems_region_create - RTEMS_TOO_MANY" ); status = rtems_region_delete( 100 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_region_delete with illegal id" ); puts( "TA1 - rtems_region_delete - unknown RTEMS_INVALID_ID" ); status = rtems_region_delete( 0x10100 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_region_delete with illegal id" ); puts( "TA1 - rtems_region_delete - local RTEMS_INVALID_ID" ); status = rtems_region_ident( 0, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NAME, "rtems_region_ident with illegal name" ); puts( "TA1 - rtems_region_ident - RTEMS_INVALID_NAME" ); status = rtems_region_get_segment( 100, 0x40, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &segment_address_1 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_region_get_segment with illegal id" ); puts( "TA1 - rtems_region_get_segment - RTEMS_INVALID_ID" ); status = rtems_region_get_segment( Region_id[ 1 ], sizeof( Region_good_area ) * 2, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &segment_address_1 ); fatal_directive_status( status, RTEMS_INVALID_SIZE, "rtems_region_get_segment with illegal size" ); puts( "TA1 - rtems_region_get_segment - RTEMS_INVALID_SIZE" ); status = rtems_region_get_segment( Region_id[ 1 ], 384, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT, &segment_address_1 ); directive_failed( status, "rtems_region_get_segment" ); puts( "TA1 - rtems_region_get_segment - RTEMS_SUCCESSFUL" ); status = rtems_region_get_segment( Region_id[ 1 ], REGION_LENGTH / 2, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &segment_address_2 ); fatal_directive_status( status, RTEMS_UNSATISFIED, "rtems_region_get_segment unsatisfied" ); puts( "TA1 - rtems_region_get_segment - RTEMS_UNSATISFIED" ); puts( "TA1 - rtems_region_get_segment - timeout in 3 seconds" ); status = rtems_region_get_segment( Region_id[ 1 ], 128, RTEMS_DEFAULT_OPTIONS, 3 * TICKS_PER_SECOND, &segment_address_3 ); fatal_directive_status( status, RTEMS_TIMEOUT, "rtems_region_get_segment timeout" ); puts( "TA1 - rtems_region_get_segment - woke up with RTEMS_TIMEOUT" ); status = rtems_region_delete( Region_id[ 1 ] ); fatal_directive_status( status, RTEMS_RESOURCE_IN_USE, "rtems_region_delete with buffers in use" ); puts( "TA1 - rtems_region_delete - RTEMS_RESOURCE_IN_USE" ); status = rtems_region_return_segment( 100, segment_address_1 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_region_return_segment with illegal id" ); puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ID" ); status = rtems_region_return_segment( Region_id[ 1 ], Region_good_area ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_region_return_segment with illegal segment" ); puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS" );/* * The following generate internal heap errors. Thus this code * is subject to change if the heap code changes. */ puts( "TA1 - rtems_debug_disable - RTEMS_DEBUG_REGION" ); rtems_debug_disable( RTEMS_DEBUG_REGION );#if 0 offset = (segment_address_1 - (void *)Region_good_area) / 4;/* bad FRONT_FLAG error */ good_front_flag = Region_good_area[ offset - 1 ]; Region_good_area[ offset - 1 ] = good_front_flag + 2; status = rtems_region_return_segment( Region_id[ 1 ], segment_address_1 ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_region_return_segment with back_flag != front_flag" ); puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS" ); Region_good_area[ offset - 1 ] = good_front_flag;/* bad FRONT_FLAG error */ good_back_flag = Region_good_area[ offset - 2 ]; Region_good_area[ offset - 2 ] = 1024; status = rtems_region_return_segment( Region_id[ 1 ], segment_address_1 ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_region_return_segment with back_flag != front_flag" ); puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS" ); Region_good_area[ offset - 2 ] = good_back_flag;#else offset = 0; good_front_flag = 0; good_back_flag = 0; puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS - SKIPPED" ); puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS - SKIPPED" );#endif puts( "TA1 - rtems_debug_enable - RTEMS_DEBUG_REGION" ); rtems_debug_enable( RTEMS_DEBUG_REGION ); status = rtems_region_extend( 100, Region_good_area, 128 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_region_extend with illegal id" ); puts( "TA1 - rtems_region_extend - RTEMS_INVALID_ID" ); status = rtems_region_extend( Region_id[ 1 ], &Region_good_area[ REGION_START_OFFSET + 16 ], 128 ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_region_extend with illegal starting address" ); puts( "TA1 - rtems_region_extend - within heap - RTEMS_INVALID_ADDRESS" ); status = rtems_region_extend( Region_id[ 1 ], Region_bad_area, 128 ); fatal_directive_status( status, RTEMS_NOT_IMPLEMENTED, "rtems_region_extend with unsupported starting address" ); puts( "TA1 - rtems_region_extend - non-contiguous lower - RTEMS_NOT_IMPLEMENTED" ); status = rtems_region_extend( Region_id[ 1 ], &Region_good_area[ REGION_START_OFFSET - REGION_LENGTH ], 128 ); fatal_directive_status( status, RTEMS_NOT_IMPLEMENTED, "rtems_region_extend with unsupported starting address" ); puts( "TA1 - rtems_region_extend - contiguous lower - RTEMS_NOT_IMPLEMENTED" ); status = rtems_region_extend( Region_id[ 1 ], &Region_good_area[ REGION_START_OFFSET + REGION_LENGTH + 16 ], 128 ); fatal_directive_status( status, RTEMS_NOT_IMPLEMENTED, "rtems_region_extend with unsupported starting address" ); puts( "TA1 - rtems_region_extend - non-contiguous higher - RTEMS_NOT_IMPLEMENTED" );} |
sd_toggle(char *v, int flag, char *s, int *ptn) | sd_toggle(const char *v, int flag, char *s, int *ptn) | sd_toggle(char *v, int flag, char *s, int *ptn){ int state = *ptn; if (*v) { int n = (int)get_int(v,0); if (n == state) return gnil; if (n != !state) { char s[128]; sprintf(s, "default: incorrect value for %s [0:off / 1:on]", s); err(talker2, s, v,v); } state = *ptn = n; } switch(flag) { case d_RETURN: return utoi(state); case d_ACKNOWLEDGE: if (state) pariputsf(" %s = 1 (on)\n", s); else pariputsf(" %s = 0 (off)\n", s); break; } return gnil;} |
char s[SIZE], *t = s; | char s[128], *t = s; | sd_colors(char *v, int flag){ long c,l; if (*v && !(GP_DATA->flags & (EMACS|TEXMACS))) { char *v0; disable_color=1; l = strlen(v); if (l <= 2 && strncmp(v, "no", l) == 0) v = ""; if (l <= 6 && strncmp(v, "darkbg", l) == 0) v = "1, 5, 3, 7, 6, 2, 3"; /* Assume recent ReadLine. */ if (l <= 7 && strncmp(v, "lightbg", l) == 0) v = "1, 6, 3, 4, 5, 2, 3"; /* Assume recent ReadLine. */ if (l <= 6 && strncmp(v, "boldfg", l) == 0) /* Good for darkbg consoles */ v = "[1,,1], [5,,1], [3,,1], [7,,1], [6,,1], [2,,1], [3,,1]"; v0 = v = filtre(v, 0); for (c=c_ERR; c < c_LAST; c++) gp_colors[c] = gp_get_color(&v); free(v0); } if (flag == d_ACKNOWLEDGE || flag == d_RETURN) { char s[SIZE], *t = s; int col[3], n; for (*t=0,c=c_ERR; c < c_LAST; c++) { n = gp_colors[c]; if (n == c_NONE) sprintf(t,"no"); else { decode_color(n,col); if (n & (1<<12)) { if (col[0]) sprintf(t,"[%d,,%d]",col[1],col[0]); else sprintf(t,"%d",col[1]); } else sprintf(t,"[%d,%d,%d]",col[1],col[2],col[0]); } t += strlen(t); if (c < c_LAST - 1) { *t++=','; *t++=' '; } } if (flag==d_RETURN) return STRtoGENstr(s); pariputsf(" colors = \"%s\"\n",s); } return gnil;} |
y[1] = lpileupto(av,gcopy(cx)); | y[1] = lpilecopy(av,cx); | mat_ideal_two_elt(GEN nf, GEN x){ GEN y,a,beta,cx,xZ,mul, pol = (GEN)nf[1]; long i,j,lm, N = degpol(pol); ulong av,tetpil; y=cgetg(3,t_VEC); av=avma; if (lg(x[1])!=N+1) err(typeer,"ideal_two_elt"); if (N == 2) { y[1] = lcopy(gcoeff(x,1,1)); y[2] = lcopy((GEN)x[2]); return y; } cx = content(x); if (!gcmp1(cx)) x = gdiv(x,cx); if (lg(x) != N+1) x = idealhermite_aux(nf,x); xZ = gcoeff(x,1,1); if (gcmp1(xZ)) { y[1] = lpileupto(av,gcopy(cx)); y[2] = (long)gscalcol(cx,N); return y; } a = NULL; /* gcc -Wall */ beta= cgetg(N+1, t_VEC); mul = cgetg(N+1, t_VEC); lm = 1; /* = lg(mul) */ /* look for a in x such that a O/xZ = x O/xZ */ for (i=2; i<=N; i++) { GEN t, y = cgetg(N+1,t_MAT); a = (GEN)x[i]; for (j=1; j<=N; j++) y[j] = (long)element_mulid(nf,a,j); /* columns of mul[i] = canonical generators for x[i] O/xZ as Z-module */ t = gmod(y, xZ); if (gcmp0(t)) continue; if (ok_elt(x,xZ, t)) break; beta[lm]= x[i]; mul[lm] = (long)t; lm++; } if (i>N) { GEN z = cgetg(lm, t_VECSMALL); ulong av1, c = 0; setlg(mul, lm); setlg(beta,lm); if (DEBUGLEVEL>3) fprintferr("ideal_two_elt, hard case: "); for(av1=avma;;avma=av1) { if (DEBUGLEVEL>3) fprintferr("%ld ", ++c); for (a=NULL,i=1; i<lm; i++) { long t = (mymyrand() >> (BITS_IN_RANDOM-5)) - 7; /* in [-7,8] */ z[i] = t; a = addmul_mat(a, t, (GEN)mul[i]); } /* a = matrix (NOT HNF) of ideal generated by beta.z in O/xZ */ if (a && ok_elt(x,xZ, a)) break; } for (a=NULL,i=1; i<lm; i++) a = addmul_col(a, z[i], (GEN)beta[i]); if (DEBUGLEVEL>3) fprintferr("\n"); } a = centermod(a, xZ); tetpil=avma; y[1] = lmul(xZ,cx); y[2] = lmul(a, cx); gerepilemanyvec(av,tetpil,y+1,2); return y;} |
if (DEBUGLEVEL) err(warnprec,"lllfp",prec); | lllfp_marked(long *pMARKED, GEN x, long D, long flag, long prec, int gram){ GEN xinit,L,h,B,L1,delta, Q, H = NULL; long retry = 2, lx = lg(x), hx, l, i, j, k, k1, n, kmax, KMAX, MARKED; pari_sp av0 = avma, av, lim; int isexact, exact_can_leave, count, count_max = 8; const int in_place = (flag == 3); if (typ(x) != t_MAT) err(typeer,"lllfp"); n = lx-1; if (n <= 1) return idmat(n);#if 0 /* doesn't work yet */ return lll_scaled(MARKED, x, D);#endif hx = lg(x[1]); if (hx != lx) { if (gram) err(mattype1,"lllfp"); if (lx > hx) err(talker,"dependent vectors in lllfp"); } delta = divrs(stor(D-1, DEFAULTPREC), D); xinit = x; av = avma; lim = stack_lim(av,1); if (gram) { for (k=2,j=1; j<lx; j++) { GEN p1=(GEN)x[j]; for (i=1; i<=j; i++) if (typ(p1[i]) == t_REAL) { l = lg(p1[i]); if (l>k) k=l; } } } else { for (k=2,j=1; j<lx; j++) { GEN p1=(GEN)x[j]; for (i=1; i<hx; i++) if (typ(p1[i]) == t_REAL) { l = lg(p1[i]); if (l>k) k=l; } } } if (k == 2) { if (!prec) return lllint_marked(pMARKED, x, D, gram, &h, NULL, NULL); x = mat_to_MP(x, prec); isexact = 1; } else { if (prec < k) prec = k; x = mat_to_mp(x, prec+1); isexact = 0; } /* kmax = maximum column index attained during this run * KMAX = same over all runs (after PRECPB) */ MARKED = pMARKED? *pMARKED: 0; kmax = KMAX = 1; h = idmat(n);#ifdef LONG_IS_64BIT# define PREC_THRESHOLD 32# define PREC_DEC_THRESHOLD 7#else# define PREC_THRESHOLD 62# define PREC_DEC_THRESHOLD 12#endifPRECPB: switch(retry--) { case 2: break; /* entry */ case 1: if (DEBUGLEVEL>3) fprintferr("\n"); if (flag == 2) return _vec(h); if (isexact || (gram && kmax > 2)) { /* some progress but precision loss, try again */ if (prec < PREC_THRESHOLD) prec = (prec<<1)-2; else prec = (long)((prec-2) * 1.25 + 2); if (DEBUGLEVEL) err(warnprec,"lllfp",prec); if (isexact) { if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); gerepileall(av, in_place? 1: 2, &xinit, &H); x = mat_to_MP(xinit, prec); h = idmat(n); retry = 1; /* never abort if x is exact */ count_max = min(count_max << 1, 512); if (DEBUGLEVEL>3) fprintferr("count_max = %ld\n", count_max); } else { x = gprec_w(xinit,prec); x = gram? qf_base_change(x, h, 1): gmul(x, h); gerepileall(av, 2, &h, &x); } kmax = 1; break; } /* fall through */ case 0: /* give up */ if (DEBUGLEVEL>3) fprintferr("\n"); if (DEBUGLEVEL) err(warner,"lllfp giving up"); if (flag) { avma=av; return NULL; } err(lllger3); } exact_can_leave = 1; count = 0; Q = zerovec(n); L = cgetg(lx,t_MAT); B = cgetg(lx,t_COL); for (j=1; j<lx; j++) { L[j] = (long)zerocol(n); B[j] = zero; } if (gram && !incrementalGS(x, L, B, 1)) { if (flag) return NULL; err(lllger3); } if (DEBUGLEVEL>5) fprintferr("k ="); for(k=2;;) { if (k > kmax) { kmax = k; if (KMAX < kmax) { KMAX = kmax; count_max = 8; } if (DEBUGLEVEL>3) {fprintferr("K%ld ",k);flusherr();} if (gram) j = incrementalGS(x, L, B, k); else j = Householder_get_mu(x, L, B, k, Q, prec); if (!j) goto PRECPB; count = 0; } else if (isexact && prec > PREC_DEC_THRESHOLD && k == kmax-1 && ++count > count_max) { /* try to reduce precision */ count = 0; prec = (prec+2) >> 1; if (DEBUGLEVEL>3) fprintferr("\n...LLL reducing precision to %ld\n",prec); if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); gerepileall(av, in_place? 4: 5,&B,&L,&Q,&xinit, &H); x = mat_to_MP(xinit, prec); h = idmat(n); } else if (DEBUGLEVEL>5) fprintferr(" %ld",k); L1 = gcoeff(L,k,k-1); if (typ(L1) == t_REAL && expo(L1) + 20 > bit_accuracy(lg(L1))) { if (!gram) goto PRECPB; if (DEBUGLEVEL>3) fprintferr("\nRecomputing Gram-Schmidt, kmax = %ld\n", kmax); for (k1=1; k1<=kmax; k1++) if (!incrementalGS(x, L, B, k1)) goto PRECPB; } if (k != MARKED) { if (!gram) j = RED(k,k-1, x,h,L,KMAX); else j = RED_gram(k,k-1, x,h,L,KMAX); if (!j) goto PRECPB; } if (do_SWAP(x,h,L,B,kmax,k,delta,gram)) { if (MARKED == k) MARKED = k-1; else if (MARKED == k-1) MARKED = k; if (!B[k]) goto PRECPB; Q[k] = Q[k-1] = zero; exact_can_leave = 0; if (k>2) k--; } else { if (k != MARKED) for (l=k-2; l; l--) { if (!gram) j = RED(k,l, x,h,L,KMAX); else j = RED_gram(k,l, x,h,L,KMAX); if (!j) goto PRECPB; if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"lllfp[1], kmax = %ld", kmax); gerepileall(av, H? 7: 6, &B,&L,&h,&x,&Q,&xinit, &H); } } if (++k > n) { if (isexact) { if (exact_can_leave) { if (H) h = H; break; } if (DEBUGLEVEL>3) fprintferr("\nChecking LLL basis..."); if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); prec = good_prec(xinit, kmax); if (DEBUGLEVEL>3) fprintferr("in precision %ld\n", prec); x = mat_to_MP(xinit, prec); h = idmat(n); exact_can_leave = 1; k = 2; kmax = 1; continue; } else if (!gram && Q[n-1] == zero) { if (DEBUGLEVEL>3) fprintferr("\nChecking LLL basis\n"); j = Householder_get_mu(gmul(xinit,h), L, B, n, Q, prec); if (!j) goto PRECPB; k = 2; continue; } break; } } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"lllfp[2], kmax = %ld", kmax); gerepileall(av, H? 7: 6, &B,&L,&h,&x,&Q,&xinit, &H); } } if (in_place) h = gmul(xinit, h); if (DEBUGLEVEL>3) fprintferr("\n"); if (pMARKED) *pMARKED = MARKED; return gerepilecopy(av0, h);} |
|
if (DEBUGLEVEL) err(warnprec,"lllfp",prec); | lllfp_marked(long *pMARKED, GEN x, long D, long flag, long prec, int gram){ GEN xinit,L,h,B,L1,delta, Q, H = NULL; long retry = 2, lx = lg(x), hx, l, i, j, k, k1, n, kmax, KMAX, MARKED; pari_sp av0 = avma, av, lim; int isexact, exact_can_leave, count, count_max = 8; const int in_place = (flag == 3); if (typ(x) != t_MAT) err(typeer,"lllfp"); n = lx-1; if (n <= 1) return idmat(n);#if 0 /* doesn't work yet */ return lll_scaled(MARKED, x, D);#endif hx = lg(x[1]); if (hx != lx) { if (gram) err(mattype1,"lllfp"); if (lx > hx) err(talker,"dependent vectors in lllfp"); } delta = divrs(stor(D-1, DEFAULTPREC), D); xinit = x; av = avma; lim = stack_lim(av,1); if (gram) { for (k=2,j=1; j<lx; j++) { GEN p1=(GEN)x[j]; for (i=1; i<=j; i++) if (typ(p1[i]) == t_REAL) { l = lg(p1[i]); if (l>k) k=l; } } } else { for (k=2,j=1; j<lx; j++) { GEN p1=(GEN)x[j]; for (i=1; i<hx; i++) if (typ(p1[i]) == t_REAL) { l = lg(p1[i]); if (l>k) k=l; } } } if (k == 2) { if (!prec) return lllint_marked(pMARKED, x, D, gram, &h, NULL, NULL); x = mat_to_MP(x, prec); isexact = 1; } else { if (prec < k) prec = k; x = mat_to_mp(x, prec+1); isexact = 0; } /* kmax = maximum column index attained during this run * KMAX = same over all runs (after PRECPB) */ MARKED = pMARKED? *pMARKED: 0; kmax = KMAX = 1; h = idmat(n);#ifdef LONG_IS_64BIT# define PREC_THRESHOLD 32# define PREC_DEC_THRESHOLD 7#else# define PREC_THRESHOLD 62# define PREC_DEC_THRESHOLD 12#endifPRECPB: switch(retry--) { case 2: break; /* entry */ case 1: if (DEBUGLEVEL>3) fprintferr("\n"); if (flag == 2) return _vec(h); if (isexact || (gram && kmax > 2)) { /* some progress but precision loss, try again */ if (prec < PREC_THRESHOLD) prec = (prec<<1)-2; else prec = (long)((prec-2) * 1.25 + 2); if (DEBUGLEVEL) err(warnprec,"lllfp",prec); if (isexact) { if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); gerepileall(av, in_place? 1: 2, &xinit, &H); x = mat_to_MP(xinit, prec); h = idmat(n); retry = 1; /* never abort if x is exact */ count_max = min(count_max << 1, 512); if (DEBUGLEVEL>3) fprintferr("count_max = %ld\n", count_max); } else { x = gprec_w(xinit,prec); x = gram? qf_base_change(x, h, 1): gmul(x, h); gerepileall(av, 2, &h, &x); } kmax = 1; break; } /* fall through */ case 0: /* give up */ if (DEBUGLEVEL>3) fprintferr("\n"); if (DEBUGLEVEL) err(warner,"lllfp giving up"); if (flag) { avma=av; return NULL; } err(lllger3); } exact_can_leave = 1; count = 0; Q = zerovec(n); L = cgetg(lx,t_MAT); B = cgetg(lx,t_COL); for (j=1; j<lx; j++) { L[j] = (long)zerocol(n); B[j] = zero; } if (gram && !incrementalGS(x, L, B, 1)) { if (flag) return NULL; err(lllger3); } if (DEBUGLEVEL>5) fprintferr("k ="); for(k=2;;) { if (k > kmax) { kmax = k; if (KMAX < kmax) { KMAX = kmax; count_max = 8; } if (DEBUGLEVEL>3) {fprintferr("K%ld ",k);flusherr();} if (gram) j = incrementalGS(x, L, B, k); else j = Householder_get_mu(x, L, B, k, Q, prec); if (!j) goto PRECPB; count = 0; } else if (isexact && prec > PREC_DEC_THRESHOLD && k == kmax-1 && ++count > count_max) { /* try to reduce precision */ count = 0; prec = (prec+2) >> 1; if (DEBUGLEVEL>3) fprintferr("\n...LLL reducing precision to %ld\n",prec); if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); gerepileall(av, in_place? 4: 5,&B,&L,&Q,&xinit, &H); x = mat_to_MP(xinit, prec); h = idmat(n); } else if (DEBUGLEVEL>5) fprintferr(" %ld",k); L1 = gcoeff(L,k,k-1); if (typ(L1) == t_REAL && expo(L1) + 20 > bit_accuracy(lg(L1))) { if (!gram) goto PRECPB; if (DEBUGLEVEL>3) fprintferr("\nRecomputing Gram-Schmidt, kmax = %ld\n", kmax); for (k1=1; k1<=kmax; k1++) if (!incrementalGS(x, L, B, k1)) goto PRECPB; } if (k != MARKED) { if (!gram) j = RED(k,k-1, x,h,L,KMAX); else j = RED_gram(k,k-1, x,h,L,KMAX); if (!j) goto PRECPB; } if (do_SWAP(x,h,L,B,kmax,k,delta,gram)) { if (MARKED == k) MARKED = k-1; else if (MARKED == k-1) MARKED = k; if (!B[k]) goto PRECPB; Q[k] = Q[k-1] = zero; exact_can_leave = 0; if (k>2) k--; } else { if (k != MARKED) for (l=k-2; l; l--) { if (!gram) j = RED(k,l, x,h,L,KMAX); else j = RED_gram(k,l, x,h,L,KMAX); if (!j) goto PRECPB; if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"lllfp[1], kmax = %ld", kmax); gerepileall(av, H? 7: 6, &B,&L,&h,&x,&Q,&xinit, &H); } } if (++k > n) { if (isexact) { if (exact_can_leave) { if (H) h = H; break; } if (DEBUGLEVEL>3) fprintferr("\nChecking LLL basis..."); if (!in_place) H = H? gmul(H, h): h; xinit = gram? qf_base_change(xinit, h, 1): gmul(xinit, h); prec = good_prec(xinit, kmax); if (DEBUGLEVEL>3) fprintferr("in precision %ld\n", prec); x = mat_to_MP(xinit, prec); h = idmat(n); exact_can_leave = 1; k = 2; kmax = 1; continue; } else if (!gram && Q[n-1] == zero) { if (DEBUGLEVEL>3) fprintferr("\nChecking LLL basis\n"); j = Householder_get_mu(gmul(xinit,h), L, B, n, Q, prec); if (!j) goto PRECPB; k = 2; continue; } break; } } if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"lllfp[2], kmax = %ld", kmax); gerepileall(av, H? 7: 6, &B,&L,&h,&x,&Q,&xinit, &H); } } if (in_place) h = gmul(xinit, h); if (DEBUGLEVEL>3) fprintferr("\n"); if (pMARKED) *pMARKED = MARKED; return gerepilecopy(av0, h);} |
|
if (!compatible && is_keyword_char(*s)) { t--; while (is_keyword_char(*s)) { s++; } | if (!compatible && isalpha((int)*s)) { t--; s++; while (is_keyword_char(*s)) { s++; } | filtre0(filtre_t *F){ const int downcase = F->downcase; char c, *s = F->s, *t; if (!F->t) F->t = gpmalloc(strlen(s)+1); t = F->t; if (F->more_input == 1) F->more_input = 0; if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } } while ((c = *s++)) { if (F->in_string) { *t++ = c; /* copy verbatim */ switch(c) { case '\\': /* in strings, \ is the escape character */ if (*s) *t++ = *s++; break; case '"': F->in_string = 0; } continue; } if (F->in_comment) { /* look for comment's end */ if (F->in_comment == MULTI_LINE_COMMENT) { while (c != '*' || *s != '/') { if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } c = *s++; } s++; } else while (c != '\n' && *s) c = *s++; F->in_comment = 0; continue; } /* weed out comments and spaces */ if (c=='\\' && *s=='\\') { F->in_comment = ONE_LINE_COMMENT; continue; } if (isspace((int)c)) continue; *t++ = downcase? tolower((int)c): c; switch(c) { case '/': if (*s == '*') { t--; F->in_comment = MULTI_LINE_COMMENT; } break; case '\\': if (!*s) { if (t[-2] == '?') break; /* '?\' */ t--; if (!F->more_input) F->more_input = 1; goto END; } if (*s == '\r') s++; /* DOS */ if (*s == '\n') { if (t[-2] == '?') break; /* '?\' */ t--; s++; if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } } /* skip \<CR> */ break; case ':': if (!compatible && is_keyword_char(*s)) { t--; while (is_keyword_char(*s)) { s++; } } break; case '"': F->in_string = 1; } } if (t != F->t) /* non empty input */ { c = t[-1]; /* = last input char */ if (c == '=') F->more_input = 2; else if (! F->wait_for_brace) F->more_input = 0; else if (c == RBRACE) { F->more_input = 0; t--; } }END: F->end = t; *t = 0; return F->t;} |
rtems_unsigned32 node | uint32_t node | void Shm_Cause_interrupt_unix( rtems_unsigned32 node){ Shm_Interrupt_information *intr; intr = &Shm_Interrupt_table[node]; _CPU_SHM_Send_interrupt( (pid_t) intr->address, intr->value );} |
rtems_unsigned32 task_index; | uint32_t task_index; | rtems_task First_FP_task( rtems_task_argument argument){ rtems_status_code status; rtems_id tid; rtems_time_of_day time; rtems_unsigned32 task_index; INTEGER_DECLARE; FP_DECLARE; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident" ); task_index = task_number( tid ); INTEGER_LOAD( INTEGER_factors[ task_index ] ); FP_LOAD( FP_factors[ task_index ] ); put_name( Task_name[ task_index ], FALSE ); printf( " - integer base = (0x%x)\n", INTEGER_factors[ task_index ] ); put_name( Task_name[ task_index ], FALSE );#if ( RTEMS_HAS_HARDWARE_FP == 1 ) printf( " - float base = (%g)\n", FP_factors[ task_index ] );#else printf( " - float base = (NA)\n" );#endif if ( argument == 0 ) { status = rtems_task_restart( RTEMS_SELF, 1 ); directive_failed( status, "rtems_task_restart of RTEMS_SELF" ); } else { build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); status = rtems_clock_set( &time ); directive_failed( status, "rtems_clock_set" ); status = rtems_task_delete( RTEMS_SELF ); directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); }} |
if (prec == 0) return p; | number_of_terms(ulong p, long prec){ long N, f; N = (long)((p-1)*prec + (p>>1)*(log2(prec)/log2(p))); N = p*(N/p); f = valfact(N, p); while (f > prec) { N = p*(N/p) - 1; f -= u_lval(N+1, p); } while (f < prec) { N = p*(N/p+1); f += u_lval(N, p); } return N;} |
|
if (phase != PHASE_INITIALIZE) { | if (pppd_phase != PHASE_INITIALIZE) { | setdevname(cp) char *cp;{ struct stat statbuf; char dev[MAXPATHLEN]; if (*cp == 0) return 0; if (strncmp("/dev/", cp, 5) != 0) { strlcpy(dev, "/dev/", sizeof(dev)); strlcat(dev, cp, sizeof(dev)); cp = dev; } /* * Check if there is a character device by this name. */ if (stat(cp, &statbuf) < 0) { if (errno == ENOENT) return 0; option_error("Couldn't stat %s: %m", cp); return -1; } if (!S_ISCHR(statbuf.st_mode)) { option_error("%s is not a character device", cp); return -1; } if (phase != PHASE_INITIALIZE) { option_error("device name cannot be changed after initialization"); return -1; } else if (devnam_fixed) { option_error("per-tty options file may not specify device name"); return -1; } if (devnam_info.priv && !privileged_option) { option_error("device name cannot be overridden"); return -1; } strlcpy(devnam, cp, sizeof(devnam)); devstat = statbuf; default_device = 0; devnam_info.priv = privileged_option; devnam_info.source = option_source; return 1;} |
GEN A, M, nB, cand, p1, B2, C2, tB, beta2, eps, nf2, Bd; | GEN A, M, nB, cand, p1, B2, C2, tB, beta2, BIG, nf2, Bd; | RecCoeff3(GEN nf, RC_data *d, long prec){ GEN A, M, nB, cand, p1, B2, C2, tB, beta2, eps, nf2, Bd; GEN beta = d->beta, B = d->B; long N = d->N, v = d->v; long i, j, k, l, ct = 0, prec2; pari_sp av = avma; FP_chk_fun chk = { &chk_reccoeff, &chk_reccoeff_init, NULL, 0 }; chk.data = (void*)d; d->G = min(-10, -bit_accuracy(prec) >> 4); eps = powuu(10, min(-8, (d->G >> 1))); tB = gpow(gmul2n(eps, N), gdivgs(gen_1, 1-N), DEFAULTPREC); Bd = gceil(gmin(B, tB)); prec2 = BIGDEFAULTPREC + (expi(Bd)>>TWOPOTBITS_IN_LONG); prec2 = max((prec << 1) - 2, prec2); nf2 = nfnewprec(nf, prec2); beta2 = gprec_w(beta, prec2);LABrcf: ct++; B2 = sqri(Bd); C2 = gdiv(B2, gsqr(eps)); M = gmael(nf2, 5, 1); d->M = M; A = cgetg(N+2, t_MAT); for (i = 1; i <= N+1; i++) A[i] = lgetg(N+2, t_COL); coeff(A, 1, 1) = ladd(gmul(C2, gsqr(beta2)), B2); for (j = 2; j <= N+1; j++) { p1 = gmul(C2, gmul(gneg_i(beta2), gcoeff(M, v, j-1))); coeff(A, 1, j) = coeff(A, j, 1) = (long)p1; } for (i = 2; i <= N+1; i++) for (j = 2; j <= N+1; j++) { p1 = gen_0; for (k = 1; k <= N; k++) { GEN p2 = gmul(gcoeff(M, k, j-1), gcoeff(M, k, i-1)); if (k == v) p2 = gmul(C2, p2); p1 = gadd(p1,p2); } coeff(A, i, j) = coeff(A, j, i) = (long)p1; } nB = mulsi(N+1, B2); d->nB = nB; cand = fincke_pohst(A, nB, -1, prec2, &chk); if (!cand) { if (ct > 3) { avma = av; return NULL; } prec2 = (prec2 << 1) - 2; if (DEBUGLEVEL>1) err(warnprec,"RecCoeff", prec2); nf2 = nfnewprec(nf2, prec2); beta2 = gprec_w(beta2, prec2); goto LABrcf; } cand = (GEN)cand[1]; l = lg(cand) - 1; if (l == 1) return gerepileupto(av, basistoalg(nf, (GEN)cand[1])); if (DEBUGLEVEL>1) fprintferr("RecCoeff3: no solution found!\n"); avma = av; return NULL;} |
eps = powuu(10, min(-8, (d->G >> 1))); tB = gpow(gmul2n(eps, N), gdivgs(gen_1, 1-N), DEFAULTPREC); | BIG = powuu(10, max(8, -(d->G >> 1))); tB = gpow(gmul2n(BIG, -N), gdivgs(gen_1, 1-N), DEFAULTPREC); | RecCoeff3(GEN nf, RC_data *d, long prec){ GEN A, M, nB, cand, p1, B2, C2, tB, beta2, eps, nf2, Bd; GEN beta = d->beta, B = d->B; long N = d->N, v = d->v; long i, j, k, l, ct = 0, prec2; pari_sp av = avma; FP_chk_fun chk = { &chk_reccoeff, &chk_reccoeff_init, NULL, 0 }; chk.data = (void*)d; d->G = min(-10, -bit_accuracy(prec) >> 4); eps = powuu(10, min(-8, (d->G >> 1))); tB = gpow(gmul2n(eps, N), gdivgs(gen_1, 1-N), DEFAULTPREC); Bd = gceil(gmin(B, tB)); prec2 = BIGDEFAULTPREC + (expi(Bd)>>TWOPOTBITS_IN_LONG); prec2 = max((prec << 1) - 2, prec2); nf2 = nfnewprec(nf, prec2); beta2 = gprec_w(beta, prec2);LABrcf: ct++; B2 = sqri(Bd); C2 = gdiv(B2, gsqr(eps)); M = gmael(nf2, 5, 1); d->M = M; A = cgetg(N+2, t_MAT); for (i = 1; i <= N+1; i++) A[i] = lgetg(N+2, t_COL); coeff(A, 1, 1) = ladd(gmul(C2, gsqr(beta2)), B2); for (j = 2; j <= N+1; j++) { p1 = gmul(C2, gmul(gneg_i(beta2), gcoeff(M, v, j-1))); coeff(A, 1, j) = coeff(A, j, 1) = (long)p1; } for (i = 2; i <= N+1; i++) for (j = 2; j <= N+1; j++) { p1 = gen_0; for (k = 1; k <= N; k++) { GEN p2 = gmul(gcoeff(M, k, j-1), gcoeff(M, k, i-1)); if (k == v) p2 = gmul(C2, p2); p1 = gadd(p1,p2); } coeff(A, i, j) = coeff(A, j, i) = (long)p1; } nB = mulsi(N+1, B2); d->nB = nB; cand = fincke_pohst(A, nB, -1, prec2, &chk); if (!cand) { if (ct > 3) { avma = av; return NULL; } prec2 = (prec2 << 1) - 2; if (DEBUGLEVEL>1) err(warnprec,"RecCoeff", prec2); nf2 = nfnewprec(nf2, prec2); beta2 = gprec_w(beta2, prec2); goto LABrcf; } cand = (GEN)cand[1]; l = lg(cand) - 1; if (l == 1) return gerepileupto(av, basistoalg(nf, (GEN)cand[1])); if (DEBUGLEVEL>1) fprintferr("RecCoeff3: no solution found!\n"); avma = av; return NULL;} |
C2 = gdiv(B2, gsqr(eps)); | C2 = mulii(B2, sqri(BIG)); | RecCoeff3(GEN nf, RC_data *d, long prec){ GEN A, M, nB, cand, p1, B2, C2, tB, beta2, eps, nf2, Bd; GEN beta = d->beta, B = d->B; long N = d->N, v = d->v; long i, j, k, l, ct = 0, prec2; pari_sp av = avma; FP_chk_fun chk = { &chk_reccoeff, &chk_reccoeff_init, NULL, 0 }; chk.data = (void*)d; d->G = min(-10, -bit_accuracy(prec) >> 4); eps = powuu(10, min(-8, (d->G >> 1))); tB = gpow(gmul2n(eps, N), gdivgs(gen_1, 1-N), DEFAULTPREC); Bd = gceil(gmin(B, tB)); prec2 = BIGDEFAULTPREC + (expi(Bd)>>TWOPOTBITS_IN_LONG); prec2 = max((prec << 1) - 2, prec2); nf2 = nfnewprec(nf, prec2); beta2 = gprec_w(beta, prec2);LABrcf: ct++; B2 = sqri(Bd); C2 = gdiv(B2, gsqr(eps)); M = gmael(nf2, 5, 1); d->M = M; A = cgetg(N+2, t_MAT); for (i = 1; i <= N+1; i++) A[i] = lgetg(N+2, t_COL); coeff(A, 1, 1) = ladd(gmul(C2, gsqr(beta2)), B2); for (j = 2; j <= N+1; j++) { p1 = gmul(C2, gmul(gneg_i(beta2), gcoeff(M, v, j-1))); coeff(A, 1, j) = coeff(A, j, 1) = (long)p1; } for (i = 2; i <= N+1; i++) for (j = 2; j <= N+1; j++) { p1 = gen_0; for (k = 1; k <= N; k++) { GEN p2 = gmul(gcoeff(M, k, j-1), gcoeff(M, k, i-1)); if (k == v) p2 = gmul(C2, p2); p1 = gadd(p1,p2); } coeff(A, i, j) = coeff(A, j, i) = (long)p1; } nB = mulsi(N+1, B2); d->nB = nB; cand = fincke_pohst(A, nB, -1, prec2, &chk); if (!cand) { if (ct > 3) { avma = av; return NULL; } prec2 = (prec2 << 1) - 2; if (DEBUGLEVEL>1) err(warnprec,"RecCoeff", prec2); nf2 = nfnewprec(nf2, prec2); beta2 = gprec_w(beta2, prec2); goto LABrcf; } cand = (GEN)cand[1]; l = lg(cand) - 1; if (l == 1) return gerepileupto(av, basistoalg(nf, (GEN)cand[1])); if (DEBUGLEVEL>1) fprintferr("RecCoeff3: no solution found!\n"); avma = av; return NULL;} |
*((rtems_unsigned16 *)0xfffb0016) = 0x0000; | *((uint16_t*)0xfffb0016) = 0x0000; | void Timer_initialize(){ (void) set_vector( timerisr, 66, 0 ); /* install ISR */ Ttimer_val = 0; /* clear timer ISR count */ Z8x36_WRITE( TIMER, MASTER_INTR, 0x01 ); /* reset */ Z8x36_WRITE( TIMER, MASTER_INTR, 0x00 ); /* clear reset */ Z8x36_WRITE( TIMER, MASTER_INTR, 0xe2 ); /* disable lower chain, no vec */ /* set right justified addr */ /* and master int enable */ Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x80 ); /* T1 continuous, and */ /* cycle/pulse output */ *((rtems_unsigned16 *)0xfffb0016) = 0x0000; /* write countdown value *//* Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 ); Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );*/ Z8x36_WRITE( TIMER, MASTER_CFG, 0xc4 ); /* enable timer1 */ Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xc6 ); /* set INTR enable (IE), */ /* trigger command */ /* (TCB) and gate */ /* command (GCB) bits */ *((rtems_unsigned8 *)0xfffb0038) &= 0xfd; /* enable timer INTR on */ /* VME controller */} |
*((rtems_unsigned8 *)0xfffb0038) &= 0xfd; | *((uint8_t*)0xfffb0038) &= 0xfd; | void Timer_initialize(){ (void) set_vector( timerisr, 66, 0 ); /* install ISR */ Ttimer_val = 0; /* clear timer ISR count */ Z8x36_WRITE( TIMER, MASTER_INTR, 0x01 ); /* reset */ Z8x36_WRITE( TIMER, MASTER_INTR, 0x00 ); /* clear reset */ Z8x36_WRITE( TIMER, MASTER_INTR, 0xe2 ); /* disable lower chain, no vec */ /* set right justified addr */ /* and master int enable */ Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x80 ); /* T1 continuous, and */ /* cycle/pulse output */ *((rtems_unsigned16 *)0xfffb0016) = 0x0000; /* write countdown value *//* Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 ); Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );*/ Z8x36_WRITE( TIMER, MASTER_CFG, 0xc4 ); /* enable timer1 */ Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xc6 ); /* set INTR enable (IE), */ /* trigger command */ /* (TCB) and gate */ /* command (GCB) bits */ *((rtems_unsigned8 *)0xfffb0038) &= 0xfd; /* enable timer INTR on */ /* VME controller */} |
long i,j,C,r,tmax,n0,n,dP = lgef(P)-3; | long i,j,C,r,S,tmax,n0,n,dP = lgef(P)-3; | LLL_cmbf(GEN P, GEN famod, GEN p, GEN pa, GEN bound, long a, long rec){ const long s = 2; /* # of traces added at each step */ long i,j,C,r,tmax,n0,n,dP = lgef(P)-3; double logp = log(gtodouble(p)); double b0 = log((double)dP*2) / logp; double k = gtodouble(glog(root_bound(P), DEFAULTPREC)) / logp; GEN y, T, T2, TT, BL, m, mGram, u, norm, target, M, piv, list; n0 = n = r = lg(famod) - 1; BL = idmat(n0); list = cgetg(n0+1, t_COL); TT = cgetg(n0+1, t_VEC); T = cgetg(n0+1, t_MAT); for (i=1; i<=n; i++) { TT[i] = 0; T [i] = lgetg(s+1, t_COL); } for(tmax = 0;; tmax += s) { /* tmax = number of traces added so far */ long b = (long)ceil(b0 + (tmax+s)*k), goodb; GEN pas2, pa_b, pb_as2, pbs2, pb, BE; if (a <= b) { a = ceil(b + 3*s*k) + 1; pa = gpowgs(p,a); famod = hensel_lift_fact(P,famod,p,pa,a); /* recompute old Newton sums to new precision */ for (i=1; i<=n0; i++) TT[i] = (long)polsym_gen((GEN)famod[i], NULL, tmax, pa); } goodb = (long) a - 0.12 * n0 * n0 / logp; if ((a - goodb)*logp < 64*LOG2) goodb = (long) a - 64*LOG2/logp; if (goodb > b) b = goodb; pa_b = gpowgs(p, a-b); pb_as2 = shifti(pa_b,-1); pb = gpowgs(p, b); pbs2 = shifti(pb,-1); C = (long)(sqrt((double)s*n)/ 2.); M = dbltor((C*C*n + (tmax+s)*n*n/4.) * 1.00001); if (DEBUGLEVEL>3) fprintferr("LLL_cmbf: %ld potential factors (tmax = %ld)\n", r, tmax); for (i=1; i<=n0; i++) { GEN p1 = (GEN)T[i]; GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tmax+s, pa); TT[i] = (long)p2; p2 += 1+tmax; /* ignore traces number 0...tmax */ for (j=1; j<=s; j++) p1[j] = p2[j]; } T2 = gmul(T, BL); for (i=1; i<=r; i++) { GEN p1 = (GEN)T2[i]; for (j=1; j<=s; j++) { GEN r3, p3 = dvmdii(modii((GEN)p1[j], pa), pb, &r3); if (cmpii(r3, pbs2) > 0) p3 = addis(p3,1); if (cmpii(p3,pb_as2) > 0) p3 = subii(p3,pa_b); p1[j] = (long)p3; } } if (gcmp0(T2)) continue; BE = cgetg(s+1, t_MAT); for (i=1; i<=s; i++) { GEN p1 = cgetg(r+s+1,t_COL); for (j=1; j<=r+s; j++) p1[j] = zero; p1[i+r] = (long)pa_b; BE[i] = (long)p1; } m = gscalmat(stoi(C), r); for (i=1; i<=r; i++) m[i] = (long)concatsp((GEN)m[i], (GEN)T2[i]); m = concatsp(m, BE); mGram = gram_matrix(m); u = lllgramintern(mGram, 4, 0, 0); m = gmul(m,u); (void)gram_schmidt(gmul(m, realun(DEFAULTPREC)), &norm); for (i=r+s; i>0; i--) if (cmprr((GEN)norm[i], M) < 0) break; if (i > r) continue; n = r; r = i; if (r <= 1) { if (r == 0) err(bugparier,"LLL_cmbf [no factor]"); list[1] = (long)P; setlg(list,2); return list; } setlg(u, r+1); for (i=1; i<=r; i++) setlg(u[i], n+1); BL = gmul(BL, u); if (r*rec >= n0) continue; { long av = avma; piv = special_pivot(BL); if (!piv) { avma = av; continue; } } pas2 = shifti(pa,-1); target = P; for (i=1; i<=r; i++) { GEN q, p1 = (GEN)piv[i]; y = gun; for (j=1; j<=n0; j++) if (signe(p1[j])) y = centermod_i(gmul(y, (GEN)famod[j]), pa, pas2); /* y is the candidate factor */ if (! (q = polidivis(target,y,bound)) ) break; if (signe(leading_term(y)) < 0) y = gneg(y); target = gdiv(q, leading_term(y)); list[i] = (long)y; } if (i > r) { setlg(list,r+1); return list; } }} |
for(tmax = 0;; tmax += s) { long b = (long)ceil(b0 + (tmax+s)*k), goodb; | for(tmax = 0;; tmax = S) { | LLL_cmbf(GEN P, GEN famod, GEN p, GEN pa, GEN bound, long a, long rec){ const long s = 2; /* # of traces added at each step */ long i,j,C,r,tmax,n0,n,dP = lgef(P)-3; double logp = log(gtodouble(p)); double b0 = log((double)dP*2) / logp; double k = gtodouble(glog(root_bound(P), DEFAULTPREC)) / logp; GEN y, T, T2, TT, BL, m, mGram, u, norm, target, M, piv, list; n0 = n = r = lg(famod) - 1; BL = idmat(n0); list = cgetg(n0+1, t_COL); TT = cgetg(n0+1, t_VEC); T = cgetg(n0+1, t_MAT); for (i=1; i<=n; i++) { TT[i] = 0; T [i] = lgetg(s+1, t_COL); } for(tmax = 0;; tmax += s) { /* tmax = number of traces added so far */ long b = (long)ceil(b0 + (tmax+s)*k), goodb; GEN pas2, pa_b, pb_as2, pbs2, pb, BE; if (a <= b) { a = ceil(b + 3*s*k) + 1; pa = gpowgs(p,a); famod = hensel_lift_fact(P,famod,p,pa,a); /* recompute old Newton sums to new precision */ for (i=1; i<=n0; i++) TT[i] = (long)polsym_gen((GEN)famod[i], NULL, tmax, pa); } goodb = (long) a - 0.12 * n0 * n0 / logp; if ((a - goodb)*logp < 64*LOG2) goodb = (long) a - 64*LOG2/logp; if (goodb > b) b = goodb; pa_b = gpowgs(p, a-b); pb_as2 = shifti(pa_b,-1); pb = gpowgs(p, b); pbs2 = shifti(pb,-1); C = (long)(sqrt((double)s*n)/ 2.); M = dbltor((C*C*n + (tmax+s)*n*n/4.) * 1.00001); if (DEBUGLEVEL>3) fprintferr("LLL_cmbf: %ld potential factors (tmax = %ld)\n", r, tmax); for (i=1; i<=n0; i++) { GEN p1 = (GEN)T[i]; GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tmax+s, pa); TT[i] = (long)p2; p2 += 1+tmax; /* ignore traces number 0...tmax */ for (j=1; j<=s; j++) p1[j] = p2[j]; } T2 = gmul(T, BL); for (i=1; i<=r; i++) { GEN p1 = (GEN)T2[i]; for (j=1; j<=s; j++) { GEN r3, p3 = dvmdii(modii((GEN)p1[j], pa), pb, &r3); if (cmpii(r3, pbs2) > 0) p3 = addis(p3,1); if (cmpii(p3,pb_as2) > 0) p3 = subii(p3,pa_b); p1[j] = (long)p3; } } if (gcmp0(T2)) continue; BE = cgetg(s+1, t_MAT); for (i=1; i<=s; i++) { GEN p1 = cgetg(r+s+1,t_COL); for (j=1; j<=r+s; j++) p1[j] = zero; p1[i+r] = (long)pa_b; BE[i] = (long)p1; } m = gscalmat(stoi(C), r); for (i=1; i<=r; i++) m[i] = (long)concatsp((GEN)m[i], (GEN)T2[i]); m = concatsp(m, BE); mGram = gram_matrix(m); u = lllgramintern(mGram, 4, 0, 0); m = gmul(m,u); (void)gram_schmidt(gmul(m, realun(DEFAULTPREC)), &norm); for (i=r+s; i>0; i--) if (cmprr((GEN)norm[i], M) < 0) break; if (i > r) continue; n = r; r = i; if (r <= 1) { if (r == 0) err(bugparier,"LLL_cmbf [no factor]"); list[1] = (long)P; setlg(list,2); return list; } setlg(u, r+1); for (i=1; i<=r; i++) setlg(u[i], n+1); BL = gmul(BL, u); if (r*rec >= n0) continue; { long av = avma; piv = special_pivot(BL); if (!piv) { avma = av; continue; } } pas2 = shifti(pa,-1); target = P; for (i=1; i<=r; i++) { GEN q, p1 = (GEN)piv[i]; y = gun; for (j=1; j<=n0; j++) if (signe(p1[j])) y = centermod_i(gmul(y, (GEN)famod[j]), pa, pas2); /* y is the candidate factor */ if (! (q = polidivis(target,y,bound)) ) break; if (signe(leading_term(y)) < 0) y = gneg(y); target = gdiv(q, leading_term(y)); list[i] = (long)y; } if (i > r) { setlg(list,r+1); return list; } }} |
C = (long)(sqrt((double)s*n)/ 2.); M = dbltor((C*C*n + (tmax+s)*n*n/4.) * 1.00001); | C = (long)sqrt(s*n0/4.); M = dbltor(n0 * (C*C + s*n0/4.) * 1.00001); | LLL_cmbf(GEN P, GEN famod, GEN p, GEN pa, GEN bound, long a, long rec){ const long s = 2; /* # of traces added at each step */ long i,j,C,r,tmax,n0,n,dP = lgef(P)-3; double logp = log(gtodouble(p)); double b0 = log((double)dP*2) / logp; double k = gtodouble(glog(root_bound(P), DEFAULTPREC)) / logp; GEN y, T, T2, TT, BL, m, mGram, u, norm, target, M, piv, list; n0 = n = r = lg(famod) - 1; BL = idmat(n0); list = cgetg(n0+1, t_COL); TT = cgetg(n0+1, t_VEC); T = cgetg(n0+1, t_MAT); for (i=1; i<=n; i++) { TT[i] = 0; T [i] = lgetg(s+1, t_COL); } for(tmax = 0;; tmax += s) { /* tmax = number of traces added so far */ long b = (long)ceil(b0 + (tmax+s)*k), goodb; GEN pas2, pa_b, pb_as2, pbs2, pb, BE; if (a <= b) { a = ceil(b + 3*s*k) + 1; pa = gpowgs(p,a); famod = hensel_lift_fact(P,famod,p,pa,a); /* recompute old Newton sums to new precision */ for (i=1; i<=n0; i++) TT[i] = (long)polsym_gen((GEN)famod[i], NULL, tmax, pa); } goodb = (long) a - 0.12 * n0 * n0 / logp; if ((a - goodb)*logp < 64*LOG2) goodb = (long) a - 64*LOG2/logp; if (goodb > b) b = goodb; pa_b = gpowgs(p, a-b); pb_as2 = shifti(pa_b,-1); pb = gpowgs(p, b); pbs2 = shifti(pb,-1); C = (long)(sqrt((double)s*n)/ 2.); M = dbltor((C*C*n + (tmax+s)*n*n/4.) * 1.00001); if (DEBUGLEVEL>3) fprintferr("LLL_cmbf: %ld potential factors (tmax = %ld)\n", r, tmax); for (i=1; i<=n0; i++) { GEN p1 = (GEN)T[i]; GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tmax+s, pa); TT[i] = (long)p2; p2 += 1+tmax; /* ignore traces number 0...tmax */ for (j=1; j<=s; j++) p1[j] = p2[j]; } T2 = gmul(T, BL); for (i=1; i<=r; i++) { GEN p1 = (GEN)T2[i]; for (j=1; j<=s; j++) { GEN r3, p3 = dvmdii(modii((GEN)p1[j], pa), pb, &r3); if (cmpii(r3, pbs2) > 0) p3 = addis(p3,1); if (cmpii(p3,pb_as2) > 0) p3 = subii(p3,pa_b); p1[j] = (long)p3; } } if (gcmp0(T2)) continue; BE = cgetg(s+1, t_MAT); for (i=1; i<=s; i++) { GEN p1 = cgetg(r+s+1,t_COL); for (j=1; j<=r+s; j++) p1[j] = zero; p1[i+r] = (long)pa_b; BE[i] = (long)p1; } m = gscalmat(stoi(C), r); for (i=1; i<=r; i++) m[i] = (long)concatsp((GEN)m[i], (GEN)T2[i]); m = concatsp(m, BE); mGram = gram_matrix(m); u = lllgramintern(mGram, 4, 0, 0); m = gmul(m,u); (void)gram_schmidt(gmul(m, realun(DEFAULTPREC)), &norm); for (i=r+s; i>0; i--) if (cmprr((GEN)norm[i], M) < 0) break; if (i > r) continue; n = r; r = i; if (r <= 1) { if (r == 0) err(bugparier,"LLL_cmbf [no factor]"); list[1] = (long)P; setlg(list,2); return list; } setlg(u, r+1); for (i=1; i<=r; i++) setlg(u[i], n+1); BL = gmul(BL, u); if (r*rec >= n0) continue; { long av = avma; piv = special_pivot(BL); if (!piv) { avma = av; continue; } } pas2 = shifti(pa,-1); target = P; for (i=1; i<=r; i++) { GEN q, p1 = (GEN)piv[i]; y = gun; for (j=1; j<=n0; j++) if (signe(p1[j])) y = centermod_i(gmul(y, (GEN)famod[j]), pa, pas2); /* y is the candidate factor */ if (! (q = polidivis(target,y,bound)) ) break; if (signe(leading_term(y)) < 0) y = gneg(y); target = gdiv(q, leading_term(y)); list[i] = (long)y; } if (i > r) { setlg(list,r+1); return list; } }} |
GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tmax+s, pa); | GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], S, pa); | LLL_cmbf(GEN P, GEN famod, GEN p, GEN pa, GEN bound, long a, long rec){ const long s = 2; /* # of traces added at each step */ long i,j,C,r,tmax,n0,n,dP = lgef(P)-3; double logp = log(gtodouble(p)); double b0 = log((double)dP*2) / logp; double k = gtodouble(glog(root_bound(P), DEFAULTPREC)) / logp; GEN y, T, T2, TT, BL, m, mGram, u, norm, target, M, piv, list; n0 = n = r = lg(famod) - 1; BL = idmat(n0); list = cgetg(n0+1, t_COL); TT = cgetg(n0+1, t_VEC); T = cgetg(n0+1, t_MAT); for (i=1; i<=n; i++) { TT[i] = 0; T [i] = lgetg(s+1, t_COL); } for(tmax = 0;; tmax += s) { /* tmax = number of traces added so far */ long b = (long)ceil(b0 + (tmax+s)*k), goodb; GEN pas2, pa_b, pb_as2, pbs2, pb, BE; if (a <= b) { a = ceil(b + 3*s*k) + 1; pa = gpowgs(p,a); famod = hensel_lift_fact(P,famod,p,pa,a); /* recompute old Newton sums to new precision */ for (i=1; i<=n0; i++) TT[i] = (long)polsym_gen((GEN)famod[i], NULL, tmax, pa); } goodb = (long) a - 0.12 * n0 * n0 / logp; if ((a - goodb)*logp < 64*LOG2) goodb = (long) a - 64*LOG2/logp; if (goodb > b) b = goodb; pa_b = gpowgs(p, a-b); pb_as2 = shifti(pa_b,-1); pb = gpowgs(p, b); pbs2 = shifti(pb,-1); C = (long)(sqrt((double)s*n)/ 2.); M = dbltor((C*C*n + (tmax+s)*n*n/4.) * 1.00001); if (DEBUGLEVEL>3) fprintferr("LLL_cmbf: %ld potential factors (tmax = %ld)\n", r, tmax); for (i=1; i<=n0; i++) { GEN p1 = (GEN)T[i]; GEN p2 = polsym_gen((GEN)famod[i], (GEN)TT[i], tmax+s, pa); TT[i] = (long)p2; p2 += 1+tmax; /* ignore traces number 0...tmax */ for (j=1; j<=s; j++) p1[j] = p2[j]; } T2 = gmul(T, BL); for (i=1; i<=r; i++) { GEN p1 = (GEN)T2[i]; for (j=1; j<=s; j++) { GEN r3, p3 = dvmdii(modii((GEN)p1[j], pa), pb, &r3); if (cmpii(r3, pbs2) > 0) p3 = addis(p3,1); if (cmpii(p3,pb_as2) > 0) p3 = subii(p3,pa_b); p1[j] = (long)p3; } } if (gcmp0(T2)) continue; BE = cgetg(s+1, t_MAT); for (i=1; i<=s; i++) { GEN p1 = cgetg(r+s+1,t_COL); for (j=1; j<=r+s; j++) p1[j] = zero; p1[i+r] = (long)pa_b; BE[i] = (long)p1; } m = gscalmat(stoi(C), r); for (i=1; i<=r; i++) m[i] = (long)concatsp((GEN)m[i], (GEN)T2[i]); m = concatsp(m, BE); mGram = gram_matrix(m); u = lllgramintern(mGram, 4, 0, 0); m = gmul(m,u); (void)gram_schmidt(gmul(m, realun(DEFAULTPREC)), &norm); for (i=r+s; i>0; i--) if (cmprr((GEN)norm[i], M) < 0) break; if (i > r) continue; n = r; r = i; if (r <= 1) { if (r == 0) err(bugparier,"LLL_cmbf [no factor]"); list[1] = (long)P; setlg(list,2); return list; } setlg(u, r+1); for (i=1; i<=r; i++) setlg(u[i], n+1); BL = gmul(BL, u); if (r*rec >= n0) continue; { long av = avma; piv = special_pivot(BL); if (!piv) { avma = av; continue; } } pas2 = shifti(pa,-1); target = P; for (i=1; i<=r; i++) { GEN q, p1 = (GEN)piv[i]; y = gun; for (j=1; j<=n0; j++) if (signe(p1[j])) y = centermod_i(gmul(y, (GEN)famod[j]), pa, pas2); /* y is the candidate factor */ if (! (q = polidivis(target,y,bound)) ) break; if (signe(leading_term(y)) < 0) y = gneg(y); target = gdiv(q, leading_term(y)); list[i] = (long)y; } if (i > r) { setlg(list,r+1); return list; } }} |
mpn_sub_1 (LIMBS(zd), x, nx, s); | mpn_sub_1 (LIMBS(zd), (mp_limb_t *)x, nx, s); | subisspec(GEN x, long s, long nx){ GEN zd; long lz; lz = nx + 2; zd = cgeti(lz); mpn_sub_1 (LIMBS(zd), x, nx, s); if (! zd[lz - 1]) { --lz; } zd[1] = evalsigne(1) | evallgefint(lz); return zd;} |
D1 = mppgcd(addii(X,Y_prod),N); | D1 = gcdii(addii(X,Y_prod),N); | mpqs_solve_linear_system(GEN kN, GEN N, long rel, long *FB, long size_of_FB){ pariFILE *pFREL; FILE *FREL; GEN X, Y_prod, N_or_kN, D1, base, res, new_res; pari_sp av=avma, av2, av3, lim, lim3, tetpil; long *fpos, *ei; long i, j, H_cols, H_rows; long res_last, res_next, res_size, res_max; mpqs_gauss_matrix m, ker_m; long done, flag, mask, rank;#ifdef MPQS_DEBUG N_or_kN = kN;#else N_or_kN = (DEBUGLEVEL >= 4 ? kN : N);#endif /* --GN */ pFREL = pari_fopen(FREL_str, READ); FREL = pFREL->file; fpos = (long *) gpmalloc(rel * sizeof(long)); m = mpqs_gauss_read_matrix(FREL, size_of_FB+1, rel, fpos); if (DEBUGLEVEL >= 7) { fprintferr("\\\\ MATRIX READ BY MPQS\nFREL="); mpqs_gauss_print_matrix(m, size_of_FB+1, rel); fprintferr("\n"); } ker_m = mpqs_kernel(m, size_of_FB+1, rel, &rank); if (DEBUGLEVEL >= 4) { if (DEBUGLEVEL >= 7) { fprintferr("\\\\ KERNEL COMPUTED BY MPQS\nKERNEL="); mpqs_gauss_print_matrix(ker_m, rel, rank); fprintferr("\n"); } /* put this here where the poor user has a chance of seeing it: */ fprintferr("MPQS: Gauss done: kernel has rank %ld, taking gcds...\n", rank); } H_rows = rel; H_cols = rank; /* If the computed kernel turns out to be trivial, fail gracefully; main loop may try to find some more relations --GN */ if (H_cols == 0) { if (DEBUGLEVEL >= 3) err(warner, "MPQS: no solutions found from linear system solver"); /* ei has not yet been allocated */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(fpos); pari_fclose(pFREL); avma = av; return NULL; /* no factors found */ } /* If the rank is r, we can expect up to 2^r pairwise coprime factors, but it may well happen that a kernel basis vector contributes nothing new to the decomposition. We will allocate room for up to eight factors initially (certainly adequate when one or two basis vectors work), adjusting this down at the end to what we actually found, or up if we are very lucky and find more factors. In the upper half of our vector, we store information about which factors we know to be composite (zero) or believe to be composite ((long)NULL which is just 0) or suspect to be prime (un), or an exponent (deux or some t_INT) if it is a proper power */ av2 = avma; lim = stack_lim(av2,1); if (rank > (long)BITS_IN_LONG - 2) res_max = VERYBIGINT; /* this, unfortunately, is the common case */ else res_max = 1L<<rank; /* max number of factors we can hope for */ res_size = 8; /* no. of factors we can store in this res */ res = cgetg(2*res_size+1, t_VEC); for (i=2*res_size; i; i--) res[i] = 0; res_next = res_last = 1; ei = (long *) gpmalloc((size_of_FB + 2) * sizeof(long)); for (i = 0; i < H_cols; i++) /* loop over basis of kernel */ { X = Y_prod = gun; memset(ei, 0, (size_of_FB + 2) * sizeof(long)); av3 = avma; lim3 = stack_lim(av3,1); for (j = 0; j < H_rows; j++) { if (mpqs_gauss_get_bit(ker_m, j, i)) Y_prod = mpqs_add_relation(Y_prod, N_or_kN, ei, mpqs_get_relation(fpos[j], FREL)); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: mpqs_solve_linear_system"); Y_prod = gerepileupto(av3, Y_prod); } } Y_prod = gerepileupto(av3, Y_prod); /* unconditionally */ av3 = avma; lim3 = stack_lim(av3,1); for (j = 2; j <= (size_of_FB + 1); j++) { if (ei[j] & 1) { /* this cannot happen --GN */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); fprintferr("MPQS: the combination of the relations is a nonsquare\n"); err(bugparier, "factoring (MPQS)"); } if (ei[j]) { X = modii(mulii(X, powmodulo(stoi(FB[j]), stoi(ei[j]>>1), N_or_kN)), N_or_kN); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: mpqs_solve_linear_system"); X = gerepileupto(av3, X); } } } X = gerepileupto(av3, X); /* unconditionally */ if (MPQS_DEBUGLEVEL >= 1) { /* this shouldn't happen either --GN */ if (signe(modii(subii(sqri(X), sqri(Y_prod)), N_or_kN))) { fprintferr("MPQS: X^2 - Y^2 != 0 mod %s\n", (N_or_kN == kN ? "kN" : "N")); fprintferr("\tindex i = %ld\n", i); err(warner, "MPQS: wrong relation found after Gauss"); } } /* if res_next < 3, we still haven't decomposed the original N, and will want both a gcd and its cofactor, overwriting N. Note that gcd(X+Y_prod,N)==1 forces gcd(X-Y_prod,N)==N, so we can skip X-Y_prod in such cases */ done = 0; /* (re-)counts probably-prime factors (or powers whose bases we don't want to handle any further) */ if (res_next < 3) { D1 = mppgcd(addii(X,Y_prod),N); if (!is_pm1(D1)) { if ((flag = egalii(D1, N))) /* assignment */ /* this one's useless, try the other one */ D1 = mppgcd(subii(X,Y_prod),N); if (!flag || (!is_pm1(D1) && !egalii(D1,N))) { /* got something that works */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: splitting N after %ld kernel vector%s\n", i+1, (i? "s" : "")); (void)mpdivis(N, D1, N); /* divide N in place */ res[1] = (long)N; /* we'll gcopy this anyway before exiting */ res[2] = (long)D1; res_last = res_next = 3; if (res_max == 2) break; /* two out of two possible factors seen */ mask = 7; /* (actually, 5th/7th powers aren't really worth the trouble. OTOH once we have the hooks for dealing with cubes, higher powers can be handled essentially for free) */ if (isprobableprime(N)) { done++; res[res_size+1] = un; } else if (carrecomplet(N, &base)) { /* squares could cost us a lot of time */ affii(base, N); done++; res[res_size+1] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(N, &base, &mask))) /* assignment */ { affii(base, N); done++; res[res_size+1] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+1] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+2] = un; } else if (carrecomplet(D1, &base)) { res[2] = (long)base; done++; res[res_size+2] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[2] = (long)base; done++; res[res_size+2] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+2] = zero; /* known composite */ if (done == 2) break; /* both factors look prime or were powers */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: got two factors, looking for more...\n"); /* and loop (after collecting garbage if necessary) */ } /* else loop to next kernel basis vector */ } /* D1!=1, nothing to be done when ==1 */ } else /* we already have factors */ { GEN X_plus_Y = addii(X, Y_prod); GEN X_minus_Y = NULL; /* will only be computed when needed */ for (j=1; j < res_next; j++) { /* loop over known-composite factors */ if (res[res_size+j] && res[res_size+j] != zero) { done++; continue; /* skip probable primes etc */ } /* (actually, also skip square roots of squares etc. They are necessarily a lot smaller than the original N, and should be easy to deal with later) */ av3 = avma; D1 = mppgcd(X_plus_Y, (GEN)(res[j])); if (is_pm1(D1)) continue; /* this one doesn't help us */ if ((flag = egalii(D1, (GEN)(res[j])))) { /* bad one, try the other */ avma = av3; if (!X_minus_Y) X_minus_Y = subii(X, Y_prod); av3 = avma; D1 = mppgcd(X_minus_Y, (GEN)(res[j])); } if (!flag || (!is_pm1(D1) && !egalii(D1, (GEN)(res[j])))) { /* got one which splits this factor */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: resplitting a factor after %ld kernel vectors\n", i+1); /* always plural */ /* first make sure there's room for another factor */ if (res_next > res_size) { /* need to reallocate (_very_ rare case) */ long i1, new_size = 2*res_size; GEN new_res; if (new_size > res_max) new_size = res_max; new_res = cgetg(2*new_size+1, t_VEC); for (i1=2*new_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = res[i1]; /* factors */ new_res[new_size+i1] = res[res_size+i1]; /* primality tags */ } res = new_res; res_size = new_size; /* res_next unchanged */ } /* now there is room; divide into existing factor and store the new gcd. Remove the known-composite flag from the old entry */ (void)mpdivis((GEN)(res[j]), D1, (GEN)(res[j])); res[res_next] = (long)D1; res[res_size+j] = 0; if (++res_next > res_max) break; /* all possible factors seen */ mask = 7; /* check for 3rd and 5th powers */ if (isprobableprime((GEN)(res[j]))) { done++; res[res_size+j] = un; } else if (carrecomplet((GEN)(res[j]), &base)) { /* we no longer bother preserving the cloned N or what is left of it when we hit it here */ res[j] = (long)base; done++; res[res_size+j] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power((GEN)(res[j]), &base, &mask))) /* = */ { res[j] = (long)base; done++; res[res_size+j] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+j] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+res_last] = un; } else if (carrecomplet(D1, &base)) { res[res_last] = (long)base; done++; res[res_size+res_last] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[res_last] = (long)base; done++; res[res_size+res_last] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+res_last] = zero; /* known composite */ } /* else it didn't help on this factor, try the next one... */ else avma = av3; /* ...after destroying the gcds */ } /* loop over known composite factors */ if (res_next > res_last) { if (DEBUGLEVEL >= 5 && done < res_last) fprintferr("MPQS: got %ld factors%s\n", res_last, (done < res_last ? ", looking for more..." : "")); res_last = res_next; } /* we should break out of the outer loop when we have seen res_max factors, and also when all current factors are probable primes */ if (res_next > res_max || done == res_next - 1) break; /* else continue loop over kernel basis */ } /* end case of further splitting of existing factors */ /* garbage collection */ if (low_stack(lim, stack_lim(av2,1))) { long i1; if(DEBUGMEM>1) err(warnmem,"[3]: mpqs_solve_linear_system"); tetpil=avma; /* gcopy would have a problem with our NULL pointers... */ new_res = cgetg(lg(res), t_VEC); for (i1=2*res_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = (isonstack((GEN)(res[i1])) ? licopy((GEN)(res[i1])) : res[i1]); new_res[res_size+i1] = res[res_size+i1]; } res = gerepile(av2, tetpil, new_res); /* discard X and Y_prod */ } } /* for (loop over kernel basis) */ if (res_next < 3) /* still no factors seen */ { pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); avma = av; return NULL; /* no factors found */ } /* normal case: convert internal format to ifac format as described in src/basemath/ifactor1.c (triples of components: value, exponent, class [unknown, known composite, known prime]), clean up and return result */ pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); res_last = res_next - 1; /* number of distinct factors found */ new_res = cgetg(3*res_last + 1, t_VEC); if (DEBUGLEVEL >= 6) fprintferr("MPQS: wrapping up vector of %ld factors\n", res_last); for (i=1,j=1; i <= res_last; i++) { new_res[j++] = /* value of factor */ isonstack((GEN)(res[i])) ? licopy((GEN)(res[i])) : res[i]; flag = res[res_size+i]; new_res[j++] = /* exponent */ flag ? /* flag was zero or un or ... */ (flag == zero ? un : (isonstack((GEN)flag) ? licopy((GEN)flag) : flag) ) : un; /* flag was (long)NULL */ new_res[j++] = /* class */ flag == zero ? zero : /* known composite */ (long)NULL; /* base of power or suspected prime -- mark as `unknown' */ if (DEBUGLEVEL >= 6) fprintferr("\tpackaging %ld: %Z ^%ld (%s)\n", i, res[i], itos((GEN)(new_res[j-2])), (flag == zero ? "comp." : "unknown")); } return gerepileupto(av, new_res);} |
D1 = mppgcd(subii(X,Y_prod),N); | D1 = gcdii(subii(X,Y_prod),N); | mpqs_solve_linear_system(GEN kN, GEN N, long rel, long *FB, long size_of_FB){ pariFILE *pFREL; FILE *FREL; GEN X, Y_prod, N_or_kN, D1, base, res, new_res; pari_sp av=avma, av2, av3, lim, lim3, tetpil; long *fpos, *ei; long i, j, H_cols, H_rows; long res_last, res_next, res_size, res_max; mpqs_gauss_matrix m, ker_m; long done, flag, mask, rank;#ifdef MPQS_DEBUG N_or_kN = kN;#else N_or_kN = (DEBUGLEVEL >= 4 ? kN : N);#endif /* --GN */ pFREL = pari_fopen(FREL_str, READ); FREL = pFREL->file; fpos = (long *) gpmalloc(rel * sizeof(long)); m = mpqs_gauss_read_matrix(FREL, size_of_FB+1, rel, fpos); if (DEBUGLEVEL >= 7) { fprintferr("\\\\ MATRIX READ BY MPQS\nFREL="); mpqs_gauss_print_matrix(m, size_of_FB+1, rel); fprintferr("\n"); } ker_m = mpqs_kernel(m, size_of_FB+1, rel, &rank); if (DEBUGLEVEL >= 4) { if (DEBUGLEVEL >= 7) { fprintferr("\\\\ KERNEL COMPUTED BY MPQS\nKERNEL="); mpqs_gauss_print_matrix(ker_m, rel, rank); fprintferr("\n"); } /* put this here where the poor user has a chance of seeing it: */ fprintferr("MPQS: Gauss done: kernel has rank %ld, taking gcds...\n", rank); } H_rows = rel; H_cols = rank; /* If the computed kernel turns out to be trivial, fail gracefully; main loop may try to find some more relations --GN */ if (H_cols == 0) { if (DEBUGLEVEL >= 3) err(warner, "MPQS: no solutions found from linear system solver"); /* ei has not yet been allocated */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(fpos); pari_fclose(pFREL); avma = av; return NULL; /* no factors found */ } /* If the rank is r, we can expect up to 2^r pairwise coprime factors, but it may well happen that a kernel basis vector contributes nothing new to the decomposition. We will allocate room for up to eight factors initially (certainly adequate when one or two basis vectors work), adjusting this down at the end to what we actually found, or up if we are very lucky and find more factors. In the upper half of our vector, we store information about which factors we know to be composite (zero) or believe to be composite ((long)NULL which is just 0) or suspect to be prime (un), or an exponent (deux or some t_INT) if it is a proper power */ av2 = avma; lim = stack_lim(av2,1); if (rank > (long)BITS_IN_LONG - 2) res_max = VERYBIGINT; /* this, unfortunately, is the common case */ else res_max = 1L<<rank; /* max number of factors we can hope for */ res_size = 8; /* no. of factors we can store in this res */ res = cgetg(2*res_size+1, t_VEC); for (i=2*res_size; i; i--) res[i] = 0; res_next = res_last = 1; ei = (long *) gpmalloc((size_of_FB + 2) * sizeof(long)); for (i = 0; i < H_cols; i++) /* loop over basis of kernel */ { X = Y_prod = gun; memset(ei, 0, (size_of_FB + 2) * sizeof(long)); av3 = avma; lim3 = stack_lim(av3,1); for (j = 0; j < H_rows; j++) { if (mpqs_gauss_get_bit(ker_m, j, i)) Y_prod = mpqs_add_relation(Y_prod, N_or_kN, ei, mpqs_get_relation(fpos[j], FREL)); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: mpqs_solve_linear_system"); Y_prod = gerepileupto(av3, Y_prod); } } Y_prod = gerepileupto(av3, Y_prod); /* unconditionally */ av3 = avma; lim3 = stack_lim(av3,1); for (j = 2; j <= (size_of_FB + 1); j++) { if (ei[j] & 1) { /* this cannot happen --GN */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); fprintferr("MPQS: the combination of the relations is a nonsquare\n"); err(bugparier, "factoring (MPQS)"); } if (ei[j]) { X = modii(mulii(X, powmodulo(stoi(FB[j]), stoi(ei[j]>>1), N_or_kN)), N_or_kN); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: mpqs_solve_linear_system"); X = gerepileupto(av3, X); } } } X = gerepileupto(av3, X); /* unconditionally */ if (MPQS_DEBUGLEVEL >= 1) { /* this shouldn't happen either --GN */ if (signe(modii(subii(sqri(X), sqri(Y_prod)), N_or_kN))) { fprintferr("MPQS: X^2 - Y^2 != 0 mod %s\n", (N_or_kN == kN ? "kN" : "N")); fprintferr("\tindex i = %ld\n", i); err(warner, "MPQS: wrong relation found after Gauss"); } } /* if res_next < 3, we still haven't decomposed the original N, and will want both a gcd and its cofactor, overwriting N. Note that gcd(X+Y_prod,N)==1 forces gcd(X-Y_prod,N)==N, so we can skip X-Y_prod in such cases */ done = 0; /* (re-)counts probably-prime factors (or powers whose bases we don't want to handle any further) */ if (res_next < 3) { D1 = mppgcd(addii(X,Y_prod),N); if (!is_pm1(D1)) { if ((flag = egalii(D1, N))) /* assignment */ /* this one's useless, try the other one */ D1 = mppgcd(subii(X,Y_prod),N); if (!flag || (!is_pm1(D1) && !egalii(D1,N))) { /* got something that works */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: splitting N after %ld kernel vector%s\n", i+1, (i? "s" : "")); (void)mpdivis(N, D1, N); /* divide N in place */ res[1] = (long)N; /* we'll gcopy this anyway before exiting */ res[2] = (long)D1; res_last = res_next = 3; if (res_max == 2) break; /* two out of two possible factors seen */ mask = 7; /* (actually, 5th/7th powers aren't really worth the trouble. OTOH once we have the hooks for dealing with cubes, higher powers can be handled essentially for free) */ if (isprobableprime(N)) { done++; res[res_size+1] = un; } else if (carrecomplet(N, &base)) { /* squares could cost us a lot of time */ affii(base, N); done++; res[res_size+1] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(N, &base, &mask))) /* assignment */ { affii(base, N); done++; res[res_size+1] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+1] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+2] = un; } else if (carrecomplet(D1, &base)) { res[2] = (long)base; done++; res[res_size+2] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[2] = (long)base; done++; res[res_size+2] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+2] = zero; /* known composite */ if (done == 2) break; /* both factors look prime or were powers */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: got two factors, looking for more...\n"); /* and loop (after collecting garbage if necessary) */ } /* else loop to next kernel basis vector */ } /* D1!=1, nothing to be done when ==1 */ } else /* we already have factors */ { GEN X_plus_Y = addii(X, Y_prod); GEN X_minus_Y = NULL; /* will only be computed when needed */ for (j=1; j < res_next; j++) { /* loop over known-composite factors */ if (res[res_size+j] && res[res_size+j] != zero) { done++; continue; /* skip probable primes etc */ } /* (actually, also skip square roots of squares etc. They are necessarily a lot smaller than the original N, and should be easy to deal with later) */ av3 = avma; D1 = mppgcd(X_plus_Y, (GEN)(res[j])); if (is_pm1(D1)) continue; /* this one doesn't help us */ if ((flag = egalii(D1, (GEN)(res[j])))) { /* bad one, try the other */ avma = av3; if (!X_minus_Y) X_minus_Y = subii(X, Y_prod); av3 = avma; D1 = mppgcd(X_minus_Y, (GEN)(res[j])); } if (!flag || (!is_pm1(D1) && !egalii(D1, (GEN)(res[j])))) { /* got one which splits this factor */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: resplitting a factor after %ld kernel vectors\n", i+1); /* always plural */ /* first make sure there's room for another factor */ if (res_next > res_size) { /* need to reallocate (_very_ rare case) */ long i1, new_size = 2*res_size; GEN new_res; if (new_size > res_max) new_size = res_max; new_res = cgetg(2*new_size+1, t_VEC); for (i1=2*new_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = res[i1]; /* factors */ new_res[new_size+i1] = res[res_size+i1]; /* primality tags */ } res = new_res; res_size = new_size; /* res_next unchanged */ } /* now there is room; divide into existing factor and store the new gcd. Remove the known-composite flag from the old entry */ (void)mpdivis((GEN)(res[j]), D1, (GEN)(res[j])); res[res_next] = (long)D1; res[res_size+j] = 0; if (++res_next > res_max) break; /* all possible factors seen */ mask = 7; /* check for 3rd and 5th powers */ if (isprobableprime((GEN)(res[j]))) { done++; res[res_size+j] = un; } else if (carrecomplet((GEN)(res[j]), &base)) { /* we no longer bother preserving the cloned N or what is left of it when we hit it here */ res[j] = (long)base; done++; res[res_size+j] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power((GEN)(res[j]), &base, &mask))) /* = */ { res[j] = (long)base; done++; res[res_size+j] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+j] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+res_last] = un; } else if (carrecomplet(D1, &base)) { res[res_last] = (long)base; done++; res[res_size+res_last] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[res_last] = (long)base; done++; res[res_size+res_last] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+res_last] = zero; /* known composite */ } /* else it didn't help on this factor, try the next one... */ else avma = av3; /* ...after destroying the gcds */ } /* loop over known composite factors */ if (res_next > res_last) { if (DEBUGLEVEL >= 5 && done < res_last) fprintferr("MPQS: got %ld factors%s\n", res_last, (done < res_last ? ", looking for more..." : "")); res_last = res_next; } /* we should break out of the outer loop when we have seen res_max factors, and also when all current factors are probable primes */ if (res_next > res_max || done == res_next - 1) break; /* else continue loop over kernel basis */ } /* end case of further splitting of existing factors */ /* garbage collection */ if (low_stack(lim, stack_lim(av2,1))) { long i1; if(DEBUGMEM>1) err(warnmem,"[3]: mpqs_solve_linear_system"); tetpil=avma; /* gcopy would have a problem with our NULL pointers... */ new_res = cgetg(lg(res), t_VEC); for (i1=2*res_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = (isonstack((GEN)(res[i1])) ? licopy((GEN)(res[i1])) : res[i1]); new_res[res_size+i1] = res[res_size+i1]; } res = gerepile(av2, tetpil, new_res); /* discard X and Y_prod */ } } /* for (loop over kernel basis) */ if (res_next < 3) /* still no factors seen */ { pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); avma = av; return NULL; /* no factors found */ } /* normal case: convert internal format to ifac format as described in src/basemath/ifactor1.c (triples of components: value, exponent, class [unknown, known composite, known prime]), clean up and return result */ pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); res_last = res_next - 1; /* number of distinct factors found */ new_res = cgetg(3*res_last + 1, t_VEC); if (DEBUGLEVEL >= 6) fprintferr("MPQS: wrapping up vector of %ld factors\n", res_last); for (i=1,j=1; i <= res_last; i++) { new_res[j++] = /* value of factor */ isonstack((GEN)(res[i])) ? licopy((GEN)(res[i])) : res[i]; flag = res[res_size+i]; new_res[j++] = /* exponent */ flag ? /* flag was zero or un or ... */ (flag == zero ? un : (isonstack((GEN)flag) ? licopy((GEN)flag) : flag) ) : un; /* flag was (long)NULL */ new_res[j++] = /* class */ flag == zero ? zero : /* known composite */ (long)NULL; /* base of power or suspected prime -- mark as `unknown' */ if (DEBUGLEVEL >= 6) fprintferr("\tpackaging %ld: %Z ^%ld (%s)\n", i, res[i], itos((GEN)(new_res[j-2])), (flag == zero ? "comp." : "unknown")); } return gerepileupto(av, new_res);} |
D1 = mppgcd(X_plus_Y, (GEN)(res[j])); | D1 = gcdii(X_plus_Y, (GEN)(res[j])); | mpqs_solve_linear_system(GEN kN, GEN N, long rel, long *FB, long size_of_FB){ pariFILE *pFREL; FILE *FREL; GEN X, Y_prod, N_or_kN, D1, base, res, new_res; pari_sp av=avma, av2, av3, lim, lim3, tetpil; long *fpos, *ei; long i, j, H_cols, H_rows; long res_last, res_next, res_size, res_max; mpqs_gauss_matrix m, ker_m; long done, flag, mask, rank;#ifdef MPQS_DEBUG N_or_kN = kN;#else N_or_kN = (DEBUGLEVEL >= 4 ? kN : N);#endif /* --GN */ pFREL = pari_fopen(FREL_str, READ); FREL = pFREL->file; fpos = (long *) gpmalloc(rel * sizeof(long)); m = mpqs_gauss_read_matrix(FREL, size_of_FB+1, rel, fpos); if (DEBUGLEVEL >= 7) { fprintferr("\\\\ MATRIX READ BY MPQS\nFREL="); mpqs_gauss_print_matrix(m, size_of_FB+1, rel); fprintferr("\n"); } ker_m = mpqs_kernel(m, size_of_FB+1, rel, &rank); if (DEBUGLEVEL >= 4) { if (DEBUGLEVEL >= 7) { fprintferr("\\\\ KERNEL COMPUTED BY MPQS\nKERNEL="); mpqs_gauss_print_matrix(ker_m, rel, rank); fprintferr("\n"); } /* put this here where the poor user has a chance of seeing it: */ fprintferr("MPQS: Gauss done: kernel has rank %ld, taking gcds...\n", rank); } H_rows = rel; H_cols = rank; /* If the computed kernel turns out to be trivial, fail gracefully; main loop may try to find some more relations --GN */ if (H_cols == 0) { if (DEBUGLEVEL >= 3) err(warner, "MPQS: no solutions found from linear system solver"); /* ei has not yet been allocated */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(fpos); pari_fclose(pFREL); avma = av; return NULL; /* no factors found */ } /* If the rank is r, we can expect up to 2^r pairwise coprime factors, but it may well happen that a kernel basis vector contributes nothing new to the decomposition. We will allocate room for up to eight factors initially (certainly adequate when one or two basis vectors work), adjusting this down at the end to what we actually found, or up if we are very lucky and find more factors. In the upper half of our vector, we store information about which factors we know to be composite (zero) or believe to be composite ((long)NULL which is just 0) or suspect to be prime (un), or an exponent (deux or some t_INT) if it is a proper power */ av2 = avma; lim = stack_lim(av2,1); if (rank > (long)BITS_IN_LONG - 2) res_max = VERYBIGINT; /* this, unfortunately, is the common case */ else res_max = 1L<<rank; /* max number of factors we can hope for */ res_size = 8; /* no. of factors we can store in this res */ res = cgetg(2*res_size+1, t_VEC); for (i=2*res_size; i; i--) res[i] = 0; res_next = res_last = 1; ei = (long *) gpmalloc((size_of_FB + 2) * sizeof(long)); for (i = 0; i < H_cols; i++) /* loop over basis of kernel */ { X = Y_prod = gun; memset(ei, 0, (size_of_FB + 2) * sizeof(long)); av3 = avma; lim3 = stack_lim(av3,1); for (j = 0; j < H_rows; j++) { if (mpqs_gauss_get_bit(ker_m, j, i)) Y_prod = mpqs_add_relation(Y_prod, N_or_kN, ei, mpqs_get_relation(fpos[j], FREL)); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: mpqs_solve_linear_system"); Y_prod = gerepileupto(av3, Y_prod); } } Y_prod = gerepileupto(av3, Y_prod); /* unconditionally */ av3 = avma; lim3 = stack_lim(av3,1); for (j = 2; j <= (size_of_FB + 1); j++) { if (ei[j] & 1) { /* this cannot happen --GN */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); fprintferr("MPQS: the combination of the relations is a nonsquare\n"); err(bugparier, "factoring (MPQS)"); } if (ei[j]) { X = modii(mulii(X, powmodulo(stoi(FB[j]), stoi(ei[j]>>1), N_or_kN)), N_or_kN); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: mpqs_solve_linear_system"); X = gerepileupto(av3, X); } } } X = gerepileupto(av3, X); /* unconditionally */ if (MPQS_DEBUGLEVEL >= 1) { /* this shouldn't happen either --GN */ if (signe(modii(subii(sqri(X), sqri(Y_prod)), N_or_kN))) { fprintferr("MPQS: X^2 - Y^2 != 0 mod %s\n", (N_or_kN == kN ? "kN" : "N")); fprintferr("\tindex i = %ld\n", i); err(warner, "MPQS: wrong relation found after Gauss"); } } /* if res_next < 3, we still haven't decomposed the original N, and will want both a gcd and its cofactor, overwriting N. Note that gcd(X+Y_prod,N)==1 forces gcd(X-Y_prod,N)==N, so we can skip X-Y_prod in such cases */ done = 0; /* (re-)counts probably-prime factors (or powers whose bases we don't want to handle any further) */ if (res_next < 3) { D1 = mppgcd(addii(X,Y_prod),N); if (!is_pm1(D1)) { if ((flag = egalii(D1, N))) /* assignment */ /* this one's useless, try the other one */ D1 = mppgcd(subii(X,Y_prod),N); if (!flag || (!is_pm1(D1) && !egalii(D1,N))) { /* got something that works */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: splitting N after %ld kernel vector%s\n", i+1, (i? "s" : "")); (void)mpdivis(N, D1, N); /* divide N in place */ res[1] = (long)N; /* we'll gcopy this anyway before exiting */ res[2] = (long)D1; res_last = res_next = 3; if (res_max == 2) break; /* two out of two possible factors seen */ mask = 7; /* (actually, 5th/7th powers aren't really worth the trouble. OTOH once we have the hooks for dealing with cubes, higher powers can be handled essentially for free) */ if (isprobableprime(N)) { done++; res[res_size+1] = un; } else if (carrecomplet(N, &base)) { /* squares could cost us a lot of time */ affii(base, N); done++; res[res_size+1] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(N, &base, &mask))) /* assignment */ { affii(base, N); done++; res[res_size+1] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+1] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+2] = un; } else if (carrecomplet(D1, &base)) { res[2] = (long)base; done++; res[res_size+2] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[2] = (long)base; done++; res[res_size+2] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+2] = zero; /* known composite */ if (done == 2) break; /* both factors look prime or were powers */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: got two factors, looking for more...\n"); /* and loop (after collecting garbage if necessary) */ } /* else loop to next kernel basis vector */ } /* D1!=1, nothing to be done when ==1 */ } else /* we already have factors */ { GEN X_plus_Y = addii(X, Y_prod); GEN X_minus_Y = NULL; /* will only be computed when needed */ for (j=1; j < res_next; j++) { /* loop over known-composite factors */ if (res[res_size+j] && res[res_size+j] != zero) { done++; continue; /* skip probable primes etc */ } /* (actually, also skip square roots of squares etc. They are necessarily a lot smaller than the original N, and should be easy to deal with later) */ av3 = avma; D1 = mppgcd(X_plus_Y, (GEN)(res[j])); if (is_pm1(D1)) continue; /* this one doesn't help us */ if ((flag = egalii(D1, (GEN)(res[j])))) { /* bad one, try the other */ avma = av3; if (!X_minus_Y) X_minus_Y = subii(X, Y_prod); av3 = avma; D1 = mppgcd(X_minus_Y, (GEN)(res[j])); } if (!flag || (!is_pm1(D1) && !egalii(D1, (GEN)(res[j])))) { /* got one which splits this factor */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: resplitting a factor after %ld kernel vectors\n", i+1); /* always plural */ /* first make sure there's room for another factor */ if (res_next > res_size) { /* need to reallocate (_very_ rare case) */ long i1, new_size = 2*res_size; GEN new_res; if (new_size > res_max) new_size = res_max; new_res = cgetg(2*new_size+1, t_VEC); for (i1=2*new_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = res[i1]; /* factors */ new_res[new_size+i1] = res[res_size+i1]; /* primality tags */ } res = new_res; res_size = new_size; /* res_next unchanged */ } /* now there is room; divide into existing factor and store the new gcd. Remove the known-composite flag from the old entry */ (void)mpdivis((GEN)(res[j]), D1, (GEN)(res[j])); res[res_next] = (long)D1; res[res_size+j] = 0; if (++res_next > res_max) break; /* all possible factors seen */ mask = 7; /* check for 3rd and 5th powers */ if (isprobableprime((GEN)(res[j]))) { done++; res[res_size+j] = un; } else if (carrecomplet((GEN)(res[j]), &base)) { /* we no longer bother preserving the cloned N or what is left of it when we hit it here */ res[j] = (long)base; done++; res[res_size+j] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power((GEN)(res[j]), &base, &mask))) /* = */ { res[j] = (long)base; done++; res[res_size+j] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+j] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+res_last] = un; } else if (carrecomplet(D1, &base)) { res[res_last] = (long)base; done++; res[res_size+res_last] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[res_last] = (long)base; done++; res[res_size+res_last] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+res_last] = zero; /* known composite */ } /* else it didn't help on this factor, try the next one... */ else avma = av3; /* ...after destroying the gcds */ } /* loop over known composite factors */ if (res_next > res_last) { if (DEBUGLEVEL >= 5 && done < res_last) fprintferr("MPQS: got %ld factors%s\n", res_last, (done < res_last ? ", looking for more..." : "")); res_last = res_next; } /* we should break out of the outer loop when we have seen res_max factors, and also when all current factors are probable primes */ if (res_next > res_max || done == res_next - 1) break; /* else continue loop over kernel basis */ } /* end case of further splitting of existing factors */ /* garbage collection */ if (low_stack(lim, stack_lim(av2,1))) { long i1; if(DEBUGMEM>1) err(warnmem,"[3]: mpqs_solve_linear_system"); tetpil=avma; /* gcopy would have a problem with our NULL pointers... */ new_res = cgetg(lg(res), t_VEC); for (i1=2*res_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = (isonstack((GEN)(res[i1])) ? licopy((GEN)(res[i1])) : res[i1]); new_res[res_size+i1] = res[res_size+i1]; } res = gerepile(av2, tetpil, new_res); /* discard X and Y_prod */ } } /* for (loop over kernel basis) */ if (res_next < 3) /* still no factors seen */ { pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); avma = av; return NULL; /* no factors found */ } /* normal case: convert internal format to ifac format as described in src/basemath/ifactor1.c (triples of components: value, exponent, class [unknown, known composite, known prime]), clean up and return result */ pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); res_last = res_next - 1; /* number of distinct factors found */ new_res = cgetg(3*res_last + 1, t_VEC); if (DEBUGLEVEL >= 6) fprintferr("MPQS: wrapping up vector of %ld factors\n", res_last); for (i=1,j=1; i <= res_last; i++) { new_res[j++] = /* value of factor */ isonstack((GEN)(res[i])) ? licopy((GEN)(res[i])) : res[i]; flag = res[res_size+i]; new_res[j++] = /* exponent */ flag ? /* flag was zero or un or ... */ (flag == zero ? un : (isonstack((GEN)flag) ? licopy((GEN)flag) : flag) ) : un; /* flag was (long)NULL */ new_res[j++] = /* class */ flag == zero ? zero : /* known composite */ (long)NULL; /* base of power or suspected prime -- mark as `unknown' */ if (DEBUGLEVEL >= 6) fprintferr("\tpackaging %ld: %Z ^%ld (%s)\n", i, res[i], itos((GEN)(new_res[j-2])), (flag == zero ? "comp." : "unknown")); } return gerepileupto(av, new_res);} |
D1 = mppgcd(X_minus_Y, (GEN)(res[j])); | D1 = gcdii(X_minus_Y, (GEN)(res[j])); | mpqs_solve_linear_system(GEN kN, GEN N, long rel, long *FB, long size_of_FB){ pariFILE *pFREL; FILE *FREL; GEN X, Y_prod, N_or_kN, D1, base, res, new_res; pari_sp av=avma, av2, av3, lim, lim3, tetpil; long *fpos, *ei; long i, j, H_cols, H_rows; long res_last, res_next, res_size, res_max; mpqs_gauss_matrix m, ker_m; long done, flag, mask, rank;#ifdef MPQS_DEBUG N_or_kN = kN;#else N_or_kN = (DEBUGLEVEL >= 4 ? kN : N);#endif /* --GN */ pFREL = pari_fopen(FREL_str, READ); FREL = pFREL->file; fpos = (long *) gpmalloc(rel * sizeof(long)); m = mpqs_gauss_read_matrix(FREL, size_of_FB+1, rel, fpos); if (DEBUGLEVEL >= 7) { fprintferr("\\\\ MATRIX READ BY MPQS\nFREL="); mpqs_gauss_print_matrix(m, size_of_FB+1, rel); fprintferr("\n"); } ker_m = mpqs_kernel(m, size_of_FB+1, rel, &rank); if (DEBUGLEVEL >= 4) { if (DEBUGLEVEL >= 7) { fprintferr("\\\\ KERNEL COMPUTED BY MPQS\nKERNEL="); mpqs_gauss_print_matrix(ker_m, rel, rank); fprintferr("\n"); } /* put this here where the poor user has a chance of seeing it: */ fprintferr("MPQS: Gauss done: kernel has rank %ld, taking gcds...\n", rank); } H_rows = rel; H_cols = rank; /* If the computed kernel turns out to be trivial, fail gracefully; main loop may try to find some more relations --GN */ if (H_cols == 0) { if (DEBUGLEVEL >= 3) err(warner, "MPQS: no solutions found from linear system solver"); /* ei has not yet been allocated */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(fpos); pari_fclose(pFREL); avma = av; return NULL; /* no factors found */ } /* If the rank is r, we can expect up to 2^r pairwise coprime factors, but it may well happen that a kernel basis vector contributes nothing new to the decomposition. We will allocate room for up to eight factors initially (certainly adequate when one or two basis vectors work), adjusting this down at the end to what we actually found, or up if we are very lucky and find more factors. In the upper half of our vector, we store information about which factors we know to be composite (zero) or believe to be composite ((long)NULL which is just 0) or suspect to be prime (un), or an exponent (deux or some t_INT) if it is a proper power */ av2 = avma; lim = stack_lim(av2,1); if (rank > (long)BITS_IN_LONG - 2) res_max = VERYBIGINT; /* this, unfortunately, is the common case */ else res_max = 1L<<rank; /* max number of factors we can hope for */ res_size = 8; /* no. of factors we can store in this res */ res = cgetg(2*res_size+1, t_VEC); for (i=2*res_size; i; i--) res[i] = 0; res_next = res_last = 1; ei = (long *) gpmalloc((size_of_FB + 2) * sizeof(long)); for (i = 0; i < H_cols; i++) /* loop over basis of kernel */ { X = Y_prod = gun; memset(ei, 0, (size_of_FB + 2) * sizeof(long)); av3 = avma; lim3 = stack_lim(av3,1); for (j = 0; j < H_rows; j++) { if (mpqs_gauss_get_bit(ker_m, j, i)) Y_prod = mpqs_add_relation(Y_prod, N_or_kN, ei, mpqs_get_relation(fpos[j], FREL)); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[1]: mpqs_solve_linear_system"); Y_prod = gerepileupto(av3, Y_prod); } } Y_prod = gerepileupto(av3, Y_prod); /* unconditionally */ av3 = avma; lim3 = stack_lim(av3,1); for (j = 2; j <= (size_of_FB + 1); j++) { if (ei[j] & 1) { /* this cannot happen --GN */ mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); fprintferr("MPQS: the combination of the relations is a nonsquare\n"); err(bugparier, "factoring (MPQS)"); } if (ei[j]) { X = modii(mulii(X, powmodulo(stoi(FB[j]), stoi(ei[j]>>1), N_or_kN)), N_or_kN); if (low_stack(lim3, stack_lim(av3,1))) { if(DEBUGMEM>1) err(warnmem,"[2]: mpqs_solve_linear_system"); X = gerepileupto(av3, X); } } } X = gerepileupto(av3, X); /* unconditionally */ if (MPQS_DEBUGLEVEL >= 1) { /* this shouldn't happen either --GN */ if (signe(modii(subii(sqri(X), sqri(Y_prod)), N_or_kN))) { fprintferr("MPQS: X^2 - Y^2 != 0 mod %s\n", (N_or_kN == kN ? "kN" : "N")); fprintferr("\tindex i = %ld\n", i); err(warner, "MPQS: wrong relation found after Gauss"); } } /* if res_next < 3, we still haven't decomposed the original N, and will want both a gcd and its cofactor, overwriting N. Note that gcd(X+Y_prod,N)==1 forces gcd(X-Y_prod,N)==N, so we can skip X-Y_prod in such cases */ done = 0; /* (re-)counts probably-prime factors (or powers whose bases we don't want to handle any further) */ if (res_next < 3) { D1 = mppgcd(addii(X,Y_prod),N); if (!is_pm1(D1)) { if ((flag = egalii(D1, N))) /* assignment */ /* this one's useless, try the other one */ D1 = mppgcd(subii(X,Y_prod),N); if (!flag || (!is_pm1(D1) && !egalii(D1,N))) { /* got something that works */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: splitting N after %ld kernel vector%s\n", i+1, (i? "s" : "")); (void)mpdivis(N, D1, N); /* divide N in place */ res[1] = (long)N; /* we'll gcopy this anyway before exiting */ res[2] = (long)D1; res_last = res_next = 3; if (res_max == 2) break; /* two out of two possible factors seen */ mask = 7; /* (actually, 5th/7th powers aren't really worth the trouble. OTOH once we have the hooks for dealing with cubes, higher powers can be handled essentially for free) */ if (isprobableprime(N)) { done++; res[res_size+1] = un; } else if (carrecomplet(N, &base)) { /* squares could cost us a lot of time */ affii(base, N); done++; res[res_size+1] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(N, &base, &mask))) /* assignment */ { affii(base, N); done++; res[res_size+1] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+1] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+2] = un; } else if (carrecomplet(D1, &base)) { res[2] = (long)base; done++; res[res_size+2] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[2] = (long)base; done++; res[res_size+2] = (long)(stoi(flag)); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+2] = zero; /* known composite */ if (done == 2) break; /* both factors look prime or were powers */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: got two factors, looking for more...\n"); /* and loop (after collecting garbage if necessary) */ } /* else loop to next kernel basis vector */ } /* D1!=1, nothing to be done when ==1 */ } else /* we already have factors */ { GEN X_plus_Y = addii(X, Y_prod); GEN X_minus_Y = NULL; /* will only be computed when needed */ for (j=1; j < res_next; j++) { /* loop over known-composite factors */ if (res[res_size+j] && res[res_size+j] != zero) { done++; continue; /* skip probable primes etc */ } /* (actually, also skip square roots of squares etc. They are necessarily a lot smaller than the original N, and should be easy to deal with later) */ av3 = avma; D1 = mppgcd(X_plus_Y, (GEN)(res[j])); if (is_pm1(D1)) continue; /* this one doesn't help us */ if ((flag = egalii(D1, (GEN)(res[j])))) { /* bad one, try the other */ avma = av3; if (!X_minus_Y) X_minus_Y = subii(X, Y_prod); av3 = avma; D1 = mppgcd(X_minus_Y, (GEN)(res[j])); } if (!flag || (!is_pm1(D1) && !egalii(D1, (GEN)(res[j])))) { /* got one which splits this factor */ if (DEBUGLEVEL >= 5) fprintferr("MPQS: resplitting a factor after %ld kernel vectors\n", i+1); /* always plural */ /* first make sure there's room for another factor */ if (res_next > res_size) { /* need to reallocate (_very_ rare case) */ long i1, new_size = 2*res_size; GEN new_res; if (new_size > res_max) new_size = res_max; new_res = cgetg(2*new_size+1, t_VEC); for (i1=2*new_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = res[i1]; /* factors */ new_res[new_size+i1] = res[res_size+i1]; /* primality tags */ } res = new_res; res_size = new_size; /* res_next unchanged */ } /* now there is room; divide into existing factor and store the new gcd. Remove the known-composite flag from the old entry */ (void)mpdivis((GEN)(res[j]), D1, (GEN)(res[j])); res[res_next] = (long)D1; res[res_size+j] = 0; if (++res_next > res_max) break; /* all possible factors seen */ mask = 7; /* check for 3rd and 5th powers */ if (isprobableprime((GEN)(res[j]))) { done++; res[res_size+j] = un; } else if (carrecomplet((GEN)(res[j]), &base)) { /* we no longer bother preserving the cloned N or what is left of it when we hit it here */ res[j] = (long)base; done++; res[res_size+j] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power((GEN)(res[j]), &base, &mask))) /* = */ { res[j] = (long)base; done++; res[res_size+j] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+j] = zero; /* known composite */ mask = 7; if (isprobableprime(D1)) { done++; res[res_size+res_last] = un; } else if (carrecomplet(D1, &base)) { res[res_last] = (long)base; done++; res[res_size+res_last] = deux; if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a square\n"); } else if ((flag = is_odd_power(D1, &base, &mask))) /* assignment */ { res[res_last] = (long)base; done++; res[res_size+res_last] = (long)stoi(flag); if (DEBUGLEVEL >= 5) fprintferr("MPQS: decomposed a %s\n", (flag == 3 ? "cube" : (flag == 5 ? "5th power" : "7th power"))); } else res[res_size+res_last] = zero; /* known composite */ } /* else it didn't help on this factor, try the next one... */ else avma = av3; /* ...after destroying the gcds */ } /* loop over known composite factors */ if (res_next > res_last) { if (DEBUGLEVEL >= 5 && done < res_last) fprintferr("MPQS: got %ld factors%s\n", res_last, (done < res_last ? ", looking for more..." : "")); res_last = res_next; } /* we should break out of the outer loop when we have seen res_max factors, and also when all current factors are probable primes */ if (res_next > res_max || done == res_next - 1) break; /* else continue loop over kernel basis */ } /* end case of further splitting of existing factors */ /* garbage collection */ if (low_stack(lim, stack_lim(av2,1))) { long i1; if(DEBUGMEM>1) err(warnmem,"[3]: mpqs_solve_linear_system"); tetpil=avma; /* gcopy would have a problem with our NULL pointers... */ new_res = cgetg(lg(res), t_VEC); for (i1=2*res_size; i1>=res_next; i1--) new_res[i1] = 0; for (i1=1; i1<res_next; i1++) { new_res[i1] = (isonstack((GEN)(res[i1])) ? licopy((GEN)(res[i1])) : res[i1]); new_res[res_size+i1] = res[res_size+i1]; } res = gerepile(av2, tetpil, new_res); /* discard X and Y_prod */ } } /* for (loop over kernel basis) */ if (res_next < 3) /* still no factors seen */ { pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); avma = av; return NULL; /* no factors found */ } /* normal case: convert internal format to ifac format as described in src/basemath/ifactor1.c (triples of components: value, exponent, class [unknown, known composite, known prime]), clean up and return result */ pari_fclose(pFREL); mpqs_gauss_destroy_matrix(m, size_of_FB+1, rel); mpqs_gauss_destroy_matrix(ker_m, rel, rank); free(ei); free(fpos); res_last = res_next - 1; /* number of distinct factors found */ new_res = cgetg(3*res_last + 1, t_VEC); if (DEBUGLEVEL >= 6) fprintferr("MPQS: wrapping up vector of %ld factors\n", res_last); for (i=1,j=1; i <= res_last; i++) { new_res[j++] = /* value of factor */ isonstack((GEN)(res[i])) ? licopy((GEN)(res[i])) : res[i]; flag = res[res_size+i]; new_res[j++] = /* exponent */ flag ? /* flag was zero or un or ... */ (flag == zero ? un : (isonstack((GEN)flag) ? licopy((GEN)flag) : flag) ) : un; /* flag was (long)NULL */ new_res[j++] = /* class */ flag == zero ? zero : /* known composite */ (long)NULL; /* base of power or suspected prime -- mark as `unknown' */ if (DEBUGLEVEL >= 6) fprintferr("\tpackaging %ld: %Z ^%ld (%s)\n", i, res[i], itos((GEN)(new_res[j-2])), (flag == zero ? "comp." : "unknown")); } return gerepileupto(av, new_res);} |
inv_q = mppgcd(inv_q, N); | inv_q = gcdii(inv_q, N); | mpqs_combine_large_primes(FILE *COMB, FILE *FNEW, long size_of_FB, GEN N, GEN kN, GEN *f#ifdef MPQS_DEBUG , long *FB#endif){ char buf [MPQS_STRING_LENGTH], *s1, *s2; char new_relation [MPQS_STRING_LENGTH]; mpqs_lp_entry e[2]; /* we'll use the two alternatingly */ long *ei, ei_size = size_of_FB + 2; long old_q; GEN inv_q, Y1, Y2, new_Y, new_Y1; long i, l, c = 0; pari_sp av = avma, av2; *f = NULL; if (fgets(buf, MPQS_STRING_LENGTH, COMB) == NULL) return 0; /* nothing there -- should not happen */ /* put first lp relation in row 0 of e */ s1 = buf; s2 = strchr(s1, ' '); *s2 = '\0'; e[0].q = atol(s1); s1 = s2 + 3; s2 = strchr(s1, ' '); *s2 = '\0'; strcpy(e[0].Y, s1); s1 = s2 + 3; s2 = strchr(s1, '\n'); *s2 = '\0'; strcpy(e[0].ep, s1); i = 1; /* second relation will go into row 1 */ old_q = e[0].q; while (!invmod(stoi(old_q), kN, &inv_q)) /* can happen --GN */ { inv_q = mppgcd(inv_q, N); if (is_pm1(inv_q) || egalii(inv_q, N)) /* pity */ {#ifdef MPQS_DEBUG fprintferr("MPQS: skipping relation with non-invertible q\n");#endif avma = av; if (fgets(buf, MPQS_STRING_LENGTH, COMB) == NULL) return 0; s1 = buf; s2 = strchr(s1, ' '); *s2 = '\0'; e[0].q = atol(s1); s1 = s2 + 3; s2 = strchr(s1, ' '); *s2 = '\0'; strcpy(e[0].Y, s1); s1 = s2 + 3; s2 = strchr(s1, '\n'); *s2 = '\0'; strcpy(e[0].ep, s1); old_q = e[0].q; continue; } *f = gerepileupto(av, inv_q); return c; } Y1 = lisexpr(e[0].Y); av2 = avma; /* preserve inv_q and Y1 */ ei = (long *) gpmalloc(ei_size * sizeof(long)); while (fgets(buf, MPQS_STRING_LENGTH, COMB) != NULL) { s1 = buf; s2 = strchr(s1, ' '); *s2 = '\0'; e[i].q = atol(s1); s1 = s2 + 3; s2 = strchr(s1, ' '); *s2 = '\0'; strcpy(e[i].Y, s1); s1 = s2 + 3; s2 = strchr(s1, '\n'); *s2 = '\0'; strcpy(e[i].ep, s1); if (e[i].q != old_q) { /* switch to combining a new bunch, swapping the rows */ old_q = e[i].q; avma = av; /* discard old inv_q and Y1 */ if (!invmod(stoi(old_q), kN, &inv_q)) /* can happen --GN */ { inv_q = mppgcd(inv_q, N); if (is_pm1(inv_q) || egalii(inv_q, N)) /* pity */ {#ifdef MPQS_DEBUG fprintferr("MPQS: skipping relation with non-invertible q\n");#endif avma = av; old_q = -1; /* sentinel */ av2 = avma; continue; /* discard this combination */ } *f = gerepileupto(av, inv_q); free (ei); return c; } Y1 = lisexpr(e[i].Y); i = 1 - i; /* subsequent relations go to other row */ av2 = avma; /* preserve inv_q and Y1 */ continue; } /* count and combine the two we've got, and continue in the same row */ c++; mpqs_combine_exponents(ei, ei_size, e[1-i].ep, e[i].ep); if (DEBUGLEVEL >= 6) { fprintferr("MPQS: combining\n"); fprintferr(" {%ld @ %s : %s}\n", old_q, e[1-i].Y, e[1-i].ep); fprintferr(" * {%ld @ %s : %s}\n", e[i].q, e[i].Y, e[i].ep); } Y2 = lisexpr(e[i].Y); new_Y = modii(mulii(mulii(Y1, Y2), inv_q), kN); new_Y1 = subii(kN, new_Y); if (absi_cmp(new_Y1, new_Y) < 0) new_Y = new_Y1; s1 = GENtostr(new_Y); strcpy(new_relation, s1); free(s1); strcat(new_relation, " :"); if (ei[1] % 2) strcat(new_relation, " 1 1"); for (l = 2; l < ei_size; l++) { if (ei[l]) { sprintf(buf, " %ld %ld", ei[l], l); strcat(new_relation, buf); } } strcat(new_relation, " 0"); if (DEBUGLEVEL >= 6) fprintferr(" == {%s}\n", new_relation); strcat(new_relation, "\n");#ifdef MPQS_DEBUG { char ejk [MPQS_STRING_LENGTH]; GEN Qx_2, prod_pi_ei, pi_ei; char *s; long pi, exi; pari_sp av1 = avma; Qx_2 = modii(sqri(new_Y), kN); strcpy(ejk, new_relation); s = strchr(ejk, ':') + 2; s = strtok(s, " \n"); prod_pi_ei = gun; while (s != NULL) { exi = atol(s); if (exi == 0) break; s = strtok(NULL, " \n"); pi = atol(s); pi_ei = powmodulo(stoi(FB[pi]), stoi(exi), kN); prod_pi_ei = modii(mulii(prod_pi_ei, pi_ei), kN); s = strtok(NULL, " \n"); } avma = av1; if (!egalii(Qx_2, prod_pi_ei)) { free(ei); err(talker, "MPQS: combined large prime relation is false"); } }#endif if (fputs(new_relation, FNEW) < 0) { free(ei); bummer(FNEW_str); } avma = av2; } /* while */ free(ei); if (DEBUGLEVEL >= 4) fprintferr("MPQS: combined %ld full relation%s\n", c, (c!=1 ? "s" : "")); return c;} |
while (i < number_of_candidates) | while (i < (ulong)number_of_candidates) | mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN, long k, double sqrt_kN, long *FB, long *start_1, long *start_2, ulong M, long bin_index, long *candidates, long number_of_candidates, long lp_bound, long start_index_FB_for_A, FILE *FREL, FILE *LPREL) /* NB FREL, LPREL are actually FNEW, LPNEW when we get called */{ GEN Qx, A_2x_plus_B, Y, Qx_div_p; double a, b, inv_2_a; long av, powers_of_2, p, tmp_p, remd_p, bi; long z1, z2, x, number_of_relations, x_minus_M; char *relations; ulong i, pi, ei, size_of_FB; int useless_cand;#ifdef MPQS_DEBUG_VERBOSE static char complaint[256], complaint0[256];#endif /* FIXME: this is probably right !!! */ /* * compute the roots of Q(X); this will be used to find the sign of * Q(x) after reducing mod kN */ a = gtodouble(A); inv_2_a = 1 / (2.0 * a); b = gtodouble(B); z1 = (long) ((-b - sqrt_kN) * inv_2_a); z2 = (long) ((-b + sqrt_kN) * inv_2_a); number_of_relations = 0; /* FIXME: this is definitely too loooooong ... */ /* then take the size of the FB into account. We have in the worst case: a leading " 1 1", a trailing " 0\n" with the final NUL character, and in between up to size_of_FB pairs each consisting of an exponent, a subscript into FB, and two spaces. Moreover, subscripts into FB fit into 5 digits, and exponents fit into 3 digits with room to spare -- anything needing 3 or more digits for the subscript must come with an exponent of at most 2 digits. Moreover the product of the first 58 primes is larger than 10^110, so there cannot be more than 60 pairs in all, even if size_of_FB > 10^4. --GN */ size_of_FB = FB[0]; /* one less than usually: don't count FB[1] */ if (size_of_FB > 60) size_of_FB = 60; relations = (char *) gpmalloc((8 + size_of_FB * 9) * sizeof(char));#ifdef MPQS_DEBUG_VERBOSE complaint[0] = '\0';#endif#ifdef MPQS_DEBUG size_of_FB = FB[0] + 1; /* last useful subscript into FB */#endif i = 0; while (i < number_of_candidates) {#ifdef MPQS_DEBUG_VERYVERBOSE /* this one really fills the screen... */ fprintferr("%c", (char)('0' + i%10));#endif x = candidates[i++]; relations[0] = '\0'; av = avma; /* A_2x_plus_B = (A*(2x)+B), Qx = (A*(2x)+B)^2/(4*A) = Q(x) */ x_minus_M = x - M; A_2x_plus_B = modii(addii(mulis(A, x_minus_M << 1), B), kN); Y = subii(kN, A_2x_plus_B); if (absi_cmp(A_2x_plus_B, Y) < 0) Y = A_2x_plus_B; /* absolute value of smallest absolute residue of A_2x_plus_B mod kN */ Qx = modii(sqri(Y), kN); /* Most of the time, gcd(Qx, kN) will be either 1 or k. However, it may happen that Qx is a multiple of N, especially when N is small, and this will lead to havoc below -- so we have to be a little bit careful. Of course we cannot possibly afford to compute the gcd each time through this loop unless we are debugging... --GN */#ifdef MPQS_DEBUG { long av1 = avma, ks; GEN g = mppgcd(Qx, kN);/* if ((ks = kronecker(divii(Qx, g), divii(kN, g))) != 1) */ if (is_pm1(g)) { if ((ks = kronecker(Qx, kN)) != 1) { fprintferr("\nMPQS: 4*A*Q(x) = %Z\n", Qx); fprintferr("\tKronecker symbol %ld\n", ks); err(talker, "MPQS: 4*A*Q(x) is not a square (mod kN)"); } }#ifdef MPQS_DEBUG_VERBOSE else if (cmpis(g,k) /* != 0 */ ) { char *gs = GENtostr(g); sprintf(complaint, "\nMPQS: gcd(4*A*Q(x), kN) = %s\n", gs); free(gs); if (strcmp(complaint, complaint0) != 0) { fprintferr(complaint); strcpy(complaint0, complaint); } }#endif avma = av1; }#endif Qx = modii(mulii(Qx, inv_A4), kN); /* check the sign of Qx */ if (z1 < x_minus_M && x_minus_M < z2) { Qx = subii(kN, Qx); /* i = 1, ei = 1, pi */ mpqs_add_factor(relations, 1, 1); } if (!signe(Qx)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("<+>");#endif avma = av; continue; } /* divide by powers of 2; note that we're really dealing with 4*A*Q(x), so we remember an extra factor 2^2 */ powers_of_2 = vali(Qx); Qx = shifti(Qx, -powers_of_2); mpqs_add_factor(relations, powers_of_2 + 2, 2); if (!signe(Qx)) /* this shouldn't happen */ {#ifdef MPQS_DEBUG_VERBOSE fprintferr("<*>");#endif avma = av; continue; } /* we handled the case p = 2 already */ pi = 3; bi = bin_index; useless_cand = 0;#ifdef MPQS_DEBUG_VERBOSE fprintferr("a");#endif /* FB[3] .. FB[start_index_FB_for_A] do not divide A . * p = FB[start_index_FB_for_A+j+1] divides A (to the first power) * iff the 2^j bit in bin_index is set */ while ((p = FB[pi]) != 0 && !useless_cand) { tmp_p = x % p; ei = 0; if (bi && pi > start_index_FB_for_A) { ei = bi & 1; /* either 0 or 1 */ bi >>= 1; } if (tmp_p == start_1[pi] || tmp_p == start_2[pi]) { /* p divides Q(x) and possibly A */ remd_p = mpqs_div_rem(Qx, p, &Qx_div_p); if (remd_p) { useless_cand = 1; break; } do { ei++; Qx = Qx_div_p; remd_p = mpqs_div_rem(Qx, p, &Qx_div_p); } while (remd_p == 0); } if (ei) /* p might divide A but not Q(x) */ mpqs_add_factor(relations, ei, pi); pi++; } if (useless_cand) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b<");#endif avma = av; continue; }#ifdef MPQS_DEBUG_VERBOSE fprintferr("\bb");#endif if (is_pm1(Qx)) { char *Qxstring = GENtostr(Y); strcat(relations, " 0"); fprintf(FREL, "%s :%s\n", Qxstring, relations); number_of_relations++;#ifdef MPQS_DEBUG { GEN Qx_2, prod_pi_ei, pi_ei; long lr = strlen(relations); char *s, *t = gpmalloc(lr+1); long pi, ei, av1 = avma;#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b(");#endif Qx_2 = modii(sqri(Y), kN); prod_pi_ei = gun; strcpy(t, relations); s = strtok(relations, " \n"); while (s != NULL) { ei = atol(s); if (ei == 0) break; s = strtok(NULL, " \n"); pi = atol(s); pi_ei = powmodulo(stoi(FB[pi]), stoi(ei), kN); prod_pi_ei = modii(mulii(prod_pi_ei, pi_ei), kN); s = strtok(NULL, " \n"); } if (!egalii(Qx_2, prod_pi_ei)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("!)\n");#endif fprintferr("MPQS: %s :%s\n", Qxstring, t); fprintferr("\tQx_2 = %Z\n", Qx_2); fprintferr("\t rhs = %Z\n", prod_pi_ei); err(talker, "MPQS: wrong full relation found!!"); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr(":)");#endif avma = av1; free(t); }#endif free(Qxstring); } else if (cmpis(Qx, lp_bound) > 0) { /* TO BE DONE: check for double large prime */ /* moved this else clause here where I think it belongs -- GN */#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b.");#endif } else if (k==1 || cgcd(k, itos(Qx)) == 1) { /* if (mpqs_isprime(itos(Qx))) */ char *Qxstring = GENtostr(Y); char *L1string = GENtostr(Qx); strcat(relations, " 0"); fprintf(LPREL, "%s @ %s :%s\n", L1string, Qxstring, relations);#ifdef MPQS_DEBUG { GEN Qx_2, prod_pi_ei, pi_ei; long lr = strlen(relations); char *s, *t = gpmalloc(lr+1); long pi, ei, av1 = avma;#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b(");#endif Qx_2 = modii(sqri(Y), kN); prod_pi_ei = gun; strcpy(t, relations); s = strtok(relations, " \n"); while (s != NULL) { ei = atol(s); if (ei == 0) break; s = strtok(NULL, " \n"); pi = atol(s); pi_ei = powmodulo(stoi(FB[pi]), stoi(ei), kN); prod_pi_ei = modii(mulii(prod_pi_ei, pi_ei), kN); s = strtok(NULL, " \n"); } prod_pi_ei = modii(mulii(prod_pi_ei, Qx), kN); if (!egalii(Qx_2, prod_pi_ei)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("!)\n");#endif fprintferr("MPQS: %s @ %s :%s\n", L1string, Qxstring, t); fprintferr("\tQx_2 = %Z\n", Qx_2); fprintferr("\t rhs = %Z\n", prod_pi_ei); err(talker, "MPQS: wrong large prime relation found!!"); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr(";)");#endif avma = av1; free(t); }#endif free(Qxstring); free(L1string); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr("\b<k>");#endif avma = av; } /* while */#ifdef MPQS_DEBUG_VERBOSE fprintferr("\n");#endif free(relations); return number_of_relations;} |
if (bi && pi > start_index_FB_for_A) | if (bi && pi > (ulong)start_index_FB_for_A) | mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN, long k, double sqrt_kN, long *FB, long *start_1, long *start_2, ulong M, long bin_index, long *candidates, long number_of_candidates, long lp_bound, long start_index_FB_for_A, FILE *FREL, FILE *LPREL) /* NB FREL, LPREL are actually FNEW, LPNEW when we get called */{ GEN Qx, A_2x_plus_B, Y, Qx_div_p; double a, b, inv_2_a; long av, powers_of_2, p, tmp_p, remd_p, bi; long z1, z2, x, number_of_relations, x_minus_M; char *relations; ulong i, pi, ei, size_of_FB; int useless_cand;#ifdef MPQS_DEBUG_VERBOSE static char complaint[256], complaint0[256];#endif /* FIXME: this is probably right !!! */ /* * compute the roots of Q(X); this will be used to find the sign of * Q(x) after reducing mod kN */ a = gtodouble(A); inv_2_a = 1 / (2.0 * a); b = gtodouble(B); z1 = (long) ((-b - sqrt_kN) * inv_2_a); z2 = (long) ((-b + sqrt_kN) * inv_2_a); number_of_relations = 0; /* FIXME: this is definitely too loooooong ... */ /* then take the size of the FB into account. We have in the worst case: a leading " 1 1", a trailing " 0\n" with the final NUL character, and in between up to size_of_FB pairs each consisting of an exponent, a subscript into FB, and two spaces. Moreover, subscripts into FB fit into 5 digits, and exponents fit into 3 digits with room to spare -- anything needing 3 or more digits for the subscript must come with an exponent of at most 2 digits. Moreover the product of the first 58 primes is larger than 10^110, so there cannot be more than 60 pairs in all, even if size_of_FB > 10^4. --GN */ size_of_FB = FB[0]; /* one less than usually: don't count FB[1] */ if (size_of_FB > 60) size_of_FB = 60; relations = (char *) gpmalloc((8 + size_of_FB * 9) * sizeof(char));#ifdef MPQS_DEBUG_VERBOSE complaint[0] = '\0';#endif#ifdef MPQS_DEBUG size_of_FB = FB[0] + 1; /* last useful subscript into FB */#endif i = 0; while (i < number_of_candidates) {#ifdef MPQS_DEBUG_VERYVERBOSE /* this one really fills the screen... */ fprintferr("%c", (char)('0' + i%10));#endif x = candidates[i++]; relations[0] = '\0'; av = avma; /* A_2x_plus_B = (A*(2x)+B), Qx = (A*(2x)+B)^2/(4*A) = Q(x) */ x_minus_M = x - M; A_2x_plus_B = modii(addii(mulis(A, x_minus_M << 1), B), kN); Y = subii(kN, A_2x_plus_B); if (absi_cmp(A_2x_plus_B, Y) < 0) Y = A_2x_plus_B; /* absolute value of smallest absolute residue of A_2x_plus_B mod kN */ Qx = modii(sqri(Y), kN); /* Most of the time, gcd(Qx, kN) will be either 1 or k. However, it may happen that Qx is a multiple of N, especially when N is small, and this will lead to havoc below -- so we have to be a little bit careful. Of course we cannot possibly afford to compute the gcd each time through this loop unless we are debugging... --GN */#ifdef MPQS_DEBUG { long av1 = avma, ks; GEN g = mppgcd(Qx, kN);/* if ((ks = kronecker(divii(Qx, g), divii(kN, g))) != 1) */ if (is_pm1(g)) { if ((ks = kronecker(Qx, kN)) != 1) { fprintferr("\nMPQS: 4*A*Q(x) = %Z\n", Qx); fprintferr("\tKronecker symbol %ld\n", ks); err(talker, "MPQS: 4*A*Q(x) is not a square (mod kN)"); } }#ifdef MPQS_DEBUG_VERBOSE else if (cmpis(g,k) /* != 0 */ ) { char *gs = GENtostr(g); sprintf(complaint, "\nMPQS: gcd(4*A*Q(x), kN) = %s\n", gs); free(gs); if (strcmp(complaint, complaint0) != 0) { fprintferr(complaint); strcpy(complaint0, complaint); } }#endif avma = av1; }#endif Qx = modii(mulii(Qx, inv_A4), kN); /* check the sign of Qx */ if (z1 < x_minus_M && x_minus_M < z2) { Qx = subii(kN, Qx); /* i = 1, ei = 1, pi */ mpqs_add_factor(relations, 1, 1); } if (!signe(Qx)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("<+>");#endif avma = av; continue; } /* divide by powers of 2; note that we're really dealing with 4*A*Q(x), so we remember an extra factor 2^2 */ powers_of_2 = vali(Qx); Qx = shifti(Qx, -powers_of_2); mpqs_add_factor(relations, powers_of_2 + 2, 2); if (!signe(Qx)) /* this shouldn't happen */ {#ifdef MPQS_DEBUG_VERBOSE fprintferr("<*>");#endif avma = av; continue; } /* we handled the case p = 2 already */ pi = 3; bi = bin_index; useless_cand = 0;#ifdef MPQS_DEBUG_VERBOSE fprintferr("a");#endif /* FB[3] .. FB[start_index_FB_for_A] do not divide A . * p = FB[start_index_FB_for_A+j+1] divides A (to the first power) * iff the 2^j bit in bin_index is set */ while ((p = FB[pi]) != 0 && !useless_cand) { tmp_p = x % p; ei = 0; if (bi && pi > start_index_FB_for_A) { ei = bi & 1; /* either 0 or 1 */ bi >>= 1; } if (tmp_p == start_1[pi] || tmp_p == start_2[pi]) { /* p divides Q(x) and possibly A */ remd_p = mpqs_div_rem(Qx, p, &Qx_div_p); if (remd_p) { useless_cand = 1; break; } do { ei++; Qx = Qx_div_p; remd_p = mpqs_div_rem(Qx, p, &Qx_div_p); } while (remd_p == 0); } if (ei) /* p might divide A but not Q(x) */ mpqs_add_factor(relations, ei, pi); pi++; } if (useless_cand) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b<");#endif avma = av; continue; }#ifdef MPQS_DEBUG_VERBOSE fprintferr("\bb");#endif if (is_pm1(Qx)) { char *Qxstring = GENtostr(Y); strcat(relations, " 0"); fprintf(FREL, "%s :%s\n", Qxstring, relations); number_of_relations++;#ifdef MPQS_DEBUG { GEN Qx_2, prod_pi_ei, pi_ei; long lr = strlen(relations); char *s, *t = gpmalloc(lr+1); long pi, ei, av1 = avma;#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b(");#endif Qx_2 = modii(sqri(Y), kN); prod_pi_ei = gun; strcpy(t, relations); s = strtok(relations, " \n"); while (s != NULL) { ei = atol(s); if (ei == 0) break; s = strtok(NULL, " \n"); pi = atol(s); pi_ei = powmodulo(stoi(FB[pi]), stoi(ei), kN); prod_pi_ei = modii(mulii(prod_pi_ei, pi_ei), kN); s = strtok(NULL, " \n"); } if (!egalii(Qx_2, prod_pi_ei)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("!)\n");#endif fprintferr("MPQS: %s :%s\n", Qxstring, t); fprintferr("\tQx_2 = %Z\n", Qx_2); fprintferr("\t rhs = %Z\n", prod_pi_ei); err(talker, "MPQS: wrong full relation found!!"); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr(":)");#endif avma = av1; free(t); }#endif free(Qxstring); } else if (cmpis(Qx, lp_bound) > 0) { /* TO BE DONE: check for double large prime */ /* moved this else clause here where I think it belongs -- GN */#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b.");#endif } else if (k==1 || cgcd(k, itos(Qx)) == 1) { /* if (mpqs_isprime(itos(Qx))) */ char *Qxstring = GENtostr(Y); char *L1string = GENtostr(Qx); strcat(relations, " 0"); fprintf(LPREL, "%s @ %s :%s\n", L1string, Qxstring, relations);#ifdef MPQS_DEBUG { GEN Qx_2, prod_pi_ei, pi_ei; long lr = strlen(relations); char *s, *t = gpmalloc(lr+1); long pi, ei, av1 = avma;#ifdef MPQS_DEBUG_VERBOSE fprintferr("\b(");#endif Qx_2 = modii(sqri(Y), kN); prod_pi_ei = gun; strcpy(t, relations); s = strtok(relations, " \n"); while (s != NULL) { ei = atol(s); if (ei == 0) break; s = strtok(NULL, " \n"); pi = atol(s); pi_ei = powmodulo(stoi(FB[pi]), stoi(ei), kN); prod_pi_ei = modii(mulii(prod_pi_ei, pi_ei), kN); s = strtok(NULL, " \n"); } prod_pi_ei = modii(mulii(prod_pi_ei, Qx), kN); if (!egalii(Qx_2, prod_pi_ei)) {#ifdef MPQS_DEBUG_VERBOSE fprintferr("!)\n");#endif fprintferr("MPQS: %s @ %s :%s\n", L1string, Qxstring, t); fprintferr("\tQx_2 = %Z\n", Qx_2); fprintferr("\t rhs = %Z\n", prod_pi_ei); err(talker, "MPQS: wrong large prime relation found!!"); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr(";)");#endif avma = av1; free(t); }#endif free(Qxstring); free(L1string); }#ifdef MPQS_DEBUG_VERBOSE else fprintferr("\b<k>");#endif avma = av; } /* while */#ifdef MPQS_DEBUG_VERBOSE fprintferr("\n");#endif free(relations); return number_of_relations;} |
if (flag == d_RETURN) return strtoGEN(pp->cmd? pp->cmd: ""); | if (flag == d_RETURN) return flisexpr(pp->cmd? pp->cmd:(char *) ""); | sd_prettyprinter(char *v, int flag){ gp_pp *pp = GP_DATA->pp; if (*v && !(GP_DATA->flags & TEXMACS)) { char *old = pp->cmd; int cancel = (!strcmp(v,"no")); if (GP_DATA->flags & SECURE) err_secure("prettyprinter",v); if (!strcmp(v,"yes")) v = DFT_PRETTYPRINTER; if (old && strcmp(old,v) && pp->file) { pariFILE *f; if (cancel) f = NULL; else { f = try_pipe(v, mf_OUT | mf_TEST); if (!f) { err(warner,"broken prettyprinter: '%s'",v); return gnil; } } pari_fclose(pp->file); pp->file = f; } pp->cmd = cancel? NULL: pari_strdup(v); if (old) free(old); if (flag == d_INITRC) return gnil; } if (flag == d_RETURN) return strtoGEN(pp->cmd? pp->cmd: ""); if (flag == d_ACKNOWLEDGE) pariputsf(" prettyprinter = \"%s\"\n",pp->cmd? pp->cmd: ""); return gnil;} |
for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk2]); tabeta[pk2] = (long)FpV_red(p1, N); | for (i=1; i<=pk; i++) p1[i] = (long)FpX_res(gpowgs(polx[0],i-1), tabcyc[pk2], N); tabeta[pk2] = (long)p1; | filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; gpmem_t av; int pk,pk2,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1,a=gzero,a2=gzero; pk = u_pow(p,k); ishack = isinstep5 && (pk >= lg((GEN)tabcyc) || !signe(tabcyc[pk])); pk2 = pkfalse; tabcyc[pk2] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk2]); tabeta[pk2] = (long)FpV_red(p1, N); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk2] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk2] = (long)p1; } if (pk > 2 && smodis(N,pk) == 1) { int ph,jj; GEN vpa,p1,p2,p3; if (DEBUGLEVEL&& !isinstep5) fprintferr("%ld ",pk); a = finda(N,pk,p); if (!a) return; ph = pk - pk/p; vpa = cgetg(ph+1,t_COL); vpa[1] = (long)a; if (k>1) a2 = gsqr(a); jj = 1; for (i=2; i<pk; i++) /* vpa[i] = a^i */ if (i%p) { jj++; vpa[jj] = lmul((i%p==1) ? a2 : a, (GEN)vpa[jj-1]); } if (jj!=ph) err(bugparier,"filltabs1"); if (!gcmp1(gmul(a,(GEN)vpa[ph]))) { if (signe(errfill)<=0) errfill = stoi(-1); return; } p1 = cgetg(ph+1,t_MAT); p2 = cgetg(ph+1,t_COL); p1[ph] = (long)p2; for (i=1; i<=ph; i++) p2[i] = un; p1[ph-1] = (long)vpa; p3 = vpa; for (j=3; j<=ph; j++) { p2 = cgetg(ph+1,t_COL); p1[ph+1-j] = (long)p2; for (i=1; i<=ph; i++) p2[i] = lmul((GEN)vpa[i],(GEN)p3[i]); p3 = p2; } tabmatvite[pk2] = p1; tabmatinvvite[pk2] = invmat(p1); } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); av = avma; m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } avma = av; if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk2] = taba; setlg(tabt, e); tabtall[pk2] = tabt;} |
get_limx(long N, long prec, GEN *pteps, long flag) | get_limx(long r1, long r2, long prec, GEN *pteps, long flag) | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); | GEN eps, a, r, c0, A0, limx, Pi = mppi(prec), N, p1; | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); | N = addss(r1, 2*r2); a = gmul(gpow(gdeux, gsubgs(gdiv(stoi(r1), N), 1), DEFAULTPREC), N); r = addss(r1, r2); | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); | c0 = gpow(gmul2n(Pi, 1), gdiv(subis(r, 1), gdeux), DEFAULTPREC); c0 = gmul(c0, gdiv(gdeux, N)); c0 = gmul(c0, gpow(gdeux, gmul(gdiv(stoi(r1), gdeux), gsubsg(1, gdiv(addis(r, 1), N))), DEFAULTPREC)); | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); | A0 = glog(gdiv(gmul2n(c0, 1), eps), DEFAULTPREC); | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); | limx = gpow(gdiv(a, A0), gdiv(N, gdeux), DEFAULTPREC); p1 = gsub(glog(A0, DEFAULTPREC), glog(a, DEFAULTPREC)); p1 = gmul(gmul(p1, N), addis(r, 1)); p1 = gdiv(p1, gmul2n(gadd(gmul2n(A0, 1), addis(r, 1)), 1)); limx = gmul(limx, gaddgs(p1, 1)); | get_limx(long N, long prec, GEN *pteps, long flag){ GEN gN, mu, alpha, beta, eps, A0, c1, c0, c2, lneps, limx, Pi = mppi(prec); gN = stoi(N); mu = gmul2n(gN, -1); alpha = gmul2n(stoi(N + 3), -1); beta = gpui(gdeux, gmul2n(gN, -1), 3); if (flag) *pteps = eps = gmul2n(gpowgs(dbltor(10.), -prec), -1); else *pteps = eps = gmul2n(gpowgs(dbltor(10.), (long)(-(prec-2) / pariK1)), -1); A0 = gmul2n(gun, N); A0 = gmul(A0, gpowgs(mu, N + 2)); A0 = gmul(A0, gpowgs(gmul2n(Pi, 1), 1 - N)); A0 = gsqrt(A0, 3); c1 = gmul(mu, gpui(beta, ginv(mu), 3)); c0 = gdiv(gmul(A0, gpowgs(gmul(gdeux, Pi), N - 1)), mu); c0 = gmul(c0, gpui(c1, gsub(gun, alpha), 3)); c2 = gdiv(gsub(alpha, gun), mu); lneps = glog(gdiv(c0, eps), 3); limx = gdiv(gsub(glog(lneps, 3), glog(c1, 3)), gadd(c2, gdiv(lneps, mu))); limx = gmul(gpui(gdiv(c1, lneps), mu, 3), gadd(gun, gmul(c2, gmul(mu, limx)))); return limx;} |
y = lllgram(qf_base_change(gmael(nf,5,3),idprod,1), 2*prec-2); y = gmul(idprod, (GEN)y[1]); | y = ideallllred_elt(nf, idprod); | findalpha(GEN nf,GEN x,GEN id,long prec){ GEN p1,idprod,y; GEN alp = idealaddtoone_i(nf,x,id); idprod = idealmullll(nf,x,id); y = lllgram(qf_base_change(gmael(nf,5,3),idprod,1), 2*prec-2); y = gmul(idprod, (GEN)y[1]); /* small vector in idprod */ p1 = ground(element_div(nf,alp,y)); alp = gsub(alp,element_mul(nf,p1,y)); return gcmp0(alp)? y: alp;} |
get_jac(Cache *C, ulong q, int pk, GEN tabf, GEN tabg) | get_jac(Cache *C, ulong q, long pk, GEN tabf, GEN tabg) | get_jac(Cache *C, ulong q, int pk, GEN tabf, GEN tabg){ ulong x, qm3s2; GEN vpk = vecsmall_const(pk, 0); qm3s2 = (q-3)>>1; for (x=1; x<=qm3s2; x++) vpk[ tabg[x]%pk + 1 ] += 2; vpk[ (2*tabf[qm3s2+1])%pk + 1 ]++; return u_red(vpk, C->cyc);} |
return THREAD_STATUS_PROXY_BLOCKING; | return RTEMS_PROXY_BLOCKING; | rtems_status_code _Message_queue_Translate_core_message_queue_return_code ( unsigned32 the_message_queue_status){ switch ( the_message_queue_status ) { case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL: return RTEMS_SUCCESSFUL; case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE: return RTEMS_INVALID_SIZE; case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY: return RTEMS_TOO_MANY; case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED: return RTEMS_UNSATISFIED; case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT: return RTEMS_UNSATISFIED; case CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED: return RTEMS_OBJECT_WAS_DELETED; case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT: return RTEMS_TIMEOUT; case THREAD_STATUS_PROXY_BLOCKING: return THREAD_STATUS_PROXY_BLOCKING; } _Internal_error_Occurred( /* XXX */ INTERNAL_ERROR_RTEMS_API, TRUE, the_message_queue_status ); return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */} |
(Objects_Name) 0, | (rtems_name) 0, | void _Partition_MP_Send_extract_proxy ( Thread_Control *the_thread){ _Partition_MP_Send_process_packet( PARTITION_MP_EXTRACT_PROXY, the_thread->Wait.id, (Objects_Name) 0, the_thread->Object.id );} |
if (typ(rnf)!=t_VEC || lg(rnf)!=12) err(idealer1); | if (typ(rnf)!=t_VEC || lg(rnf)!=14) err(idealer1); | checkrnf(GEN rnf){ if (typ(rnf)!=t_VEC || lg(rnf)!=12) err(idealer1);} |
borneroots = addsr(1, gmul(borne, borneroots)); | borneroots = addsr(1, gmul2n(gmul(borne, borneroots), 5 + (n >> 1))); | 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; for (i = 1; i <= n; i++) { z = (GEN) L[i]; if (signe(z[2])) break; L[i] = z[1]; } M = vandermondeinverse(L, gmul(T, realun(DEFAULTPREC)), 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);} |
gb->valsol = itos(gceil(gdiv(glog(gmul2n(borneroots, 4 + (n >> 1)), DEFAULTPREC), glog(gb->l, DEFAULTPREC)))); | gb->valsol = itos(gceil(gdiv(glog(borneroots, DEFAULTPREC), glog(gb->l, DEFAULTPREC)))); | 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; for (i = 1; i <= n; i++) { z = (GEN) L[i]; if (signe(z[2])) break; L[i] = z[1]; } M = vandermondeinverse(L, gmul(T, realun(DEFAULTPREC)), 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);} |
GEN zinit,p1,pii2,q,u,y,y1,u1,qn,negu,uinv,et,etnew,uhalf; | GEN Z,zinit,p1,pii2,q,u,y,y1,u1,qn,negu,uinv,et,etnew,uhalf; | ellsigma(GEN w, GEN z, long flag, long prec){ long toadd; gpmem_t av=avma, lim, av1; GEN zinit,p1,pii2,q,u,y,y1,u1,qn,negu,uinv,et,etnew,uhalf; int doprod = (flag >= 2); int dolog = (flag & 1); SL2_red T; if (!get_periods(w, &T)) err(typeer,"ellsigma"); Z = reduce_z(z, prec, &T); et = _elleta(&T, prec); etnew = gadd(gmul(T.x,(GEN)et[1]), gmul(T.y,(GEN)et[2])); zinit = Z? gmul(Z,T.W2): gzero; p1 = gadd(zinit, gmul2n(gadd(gmul(T.x,T.W1),gmul(T.y,T.W2)),-1)); etnew = gmul(etnew, p1); pii2 = PiI2(prec); if (mpodd(T.x) || mpodd(T.y)) etnew = gadd(etnew, gmul2n(pii2,-1)); if (!Z) { /* FIXME ??? */ if (dolog) Z = gadd(etnew, glog(z,prec)); else Z = gmul(gexp(etnew,prec), z); return gerepileupto(av, Z); } y1 = gadd(etnew,gmul2n(gmul(gmul(Z,zinit),(GEN)et[2]),-1)); /* 9.065 = 2*Pi/log(2) */ toadd = (long)ceil(9.065*fabs(gtodouble(gimag(Z)))); uhalf = gexp(gmul(gmul2n(pii2,-1),Z),prec); u = gsqr(uhalf); if (doprod) { /* use product */ q=gexp(gmul(pii2,T.tau),prec); uinv=ginv(u); u1=gsub(uhalf,ginv(uhalf)); y=gdiv(gmul(T.W2,u1),pii2); av1=avma; lim=stack_lim(av1,1); qn=q; negu=stoi(-1); for(;;) { p1=gmul(gadd(gmul(qn,u),negu),gadd(gmul(qn,uinv),negu)); p1=gdiv(p1,gsqr(gadd(qn,negu))); y=gmul(y,p1); qn=gmul(q,qn); if (gexpo(qn) <= - bit_accuracy(prec) - 5 - toadd) break; if (low_stack(lim, stack_lim(av1,1))) { GEN *gptr[2]; gptr[0]=&y; gptr[1]=&qn; if(DEBUGMEM>1) err(warnmem,"ellsigma"); gerepilemany(av1,gptr,2); } } } else { /* use sum */ GEN q8,qn2,urn,urninv; long n; q8=gexp(gmul2n(gmul(pii2,T.tau),-3),prec); q=gpowgs(q8,8); u=gneg_i(u); uinv=ginv(u); y=gzero; av1=avma; lim=stack_lim(av1,1); qn=q; qn2=gun; urn=uhalf; urninv=ginv(uhalf); for(n=0;;n++) { y=gadd(y,gmul(qn2,gsub(urn,urninv))); qn2=gmul(qn,qn2); qn=gmul(q,qn); urn=gmul(urn,u); urninv=gmul(urninv,uinv); if (gexpo(qn2) + n*toadd <= - bit_accuracy(prec) - 5) break; if (low_stack(lim, stack_lim(av1,1))) { GEN *gptr[5]; gptr[0]=&y; gptr[1]=&qn; gptr[2]=&qn2; gptr[3]=&urn; gptr[4]=&urninv; if(DEBUGMEM>1) err(warnmem,"ellsigma"); gerepilemany(av1,gptr,5); } } p1=gmul(q8,gmul(gdiv(gdiv(T.W2,pii2),gpowgs(trueeta(T.tau,prec),3)),y)); } if (dolog) return gerepileupto(av, gadd(y1,glog(p1,prec))); else return gerepileupto(av, gmul(p1,gexp(y1,prec)));} |
main( int argc, char* argv[] ) | main( void ) | main( int argc, char* argv[] ){ // Create the event manager and test controller CPPUNIT_NS::TestResult controller; // Add a listener that colllects test result CPPUNIT_NS::TestResultCollector result; controller.addListener( &result ); // Add a listener that print dots as test run. CPPUNIT_NS::BriefTestProgressListener progress; controller.addListener( &progress ); // Add the top suite to the test runner CPPUNIT_NS::TestRunner runner; runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); runner.run( controller ); // Print test in a compiler compatible format. CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); outputter.write(); return result.wasSuccessful() ? 0 : 1;} |
res = lisseq((char *)p); if (br_status != br_NONE) br_status = br_NONE; else if (! is_universal_constant(res)) res = forcecopy(res); | res = fun_seq((char *)p); | call_fun(GEN p, GEN *arg, GEN *loc, int narg, int nloc){ GEN res; long i; p++; /* skip NULL */ /* push new values for formal parameters */ for (i=0; i<narg; i++) copyvalue(*p++, *arg++); for (i=0; i<nloc; i++) pushvalue(*p++, make_arg(*loc++)); /* dumps arglist from identifier() to the garbage zone */ res = lisseq((char *)p); if (br_status != br_NONE) br_status = br_NONE; else if (! is_universal_constant(res)) /* important for gnil */ res = forcecopy(res); /* make result safe */ /* pop out ancient values of formal parameters */ for (i=0; i<nloc; i++) killvalue(*--p); for (i=0; i<narg; i++) killvalue(*--p); return res;} |
Thread_Control *the_thread; unsigned32 number_broadcasted; | CORE_message_queue_Status core_status; | rtems_status_code rtems_message_queue_broadcast( Objects_Id id, void *buffer, unsigned32 size, unsigned32 *count){ register Message_queue_Control *the_message_queue; Objects_Locations location; Thread_Control *the_thread; unsigned32 number_broadcasted; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: _Thread_Executing->Wait.return_argument = count; return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_BROADCAST_REQUEST, id, buffer, &size, 0, /* option_set not used */ MPCI_DEFAULT_TIMEOUT ); case OBJECTS_LOCAL: { Thread_Wait_information *waitp; unsigned32 constrained_size; number_broadcasted = 0; while ( (the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) { waitp = &the_thread->Wait; number_broadcasted += 1; constrained_size = size; if (size > the_message_queue->maximum_message_size) constrained_size = the_message_queue->maximum_message_size; _Message_queue_Copy_buffer(buffer, waitp->return_argument, constrained_size); *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = size; if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, id, the_thread ); } } _Thread_Enable_dispatch(); *count = number_broadcasted; return RTEMS_SUCCESSFUL; } default: return RTEMS_INTERNAL_ERROR; }} |
{ Thread_Wait_information *waitp; unsigned32 constrained_size; | core_status = _CORE_message_queue_Broadcast( &the_message_queue->message_queue, buffer, size, id, _Message_queue_Core_message_queue_mp_support, count ); _Thread_Enable_dispatch(); return _Message_queue_Translate_core_message_queue_return_code( core_status ); | rtems_status_code rtems_message_queue_broadcast( Objects_Id id, void *buffer, unsigned32 size, unsigned32 *count){ register Message_queue_Control *the_message_queue; Objects_Locations location; Thread_Control *the_thread; unsigned32 number_broadcasted; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: _Thread_Executing->Wait.return_argument = count; return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_BROADCAST_REQUEST, id, buffer, &size, 0, /* option_set not used */ MPCI_DEFAULT_TIMEOUT ); case OBJECTS_LOCAL: { Thread_Wait_information *waitp; unsigned32 constrained_size; number_broadcasted = 0; while ( (the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) { waitp = &the_thread->Wait; number_broadcasted += 1; constrained_size = size; if (size > the_message_queue->maximum_message_size) constrained_size = the_message_queue->maximum_message_size; _Message_queue_Copy_buffer(buffer, waitp->return_argument, constrained_size); *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = size; if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, id, the_thread ); } } _Thread_Enable_dispatch(); *count = number_broadcasted; return RTEMS_SUCCESSFUL; } default: return RTEMS_INTERNAL_ERROR; }} |
number_broadcasted = 0; while ( (the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) { waitp = &the_thread->Wait; number_broadcasted += 1; constrained_size = size; if (size > the_message_queue->maximum_message_size) constrained_size = the_message_queue->maximum_message_size; _Message_queue_Copy_buffer(buffer, waitp->return_argument, constrained_size); *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = size; if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, id, the_thread ); } } _Thread_Enable_dispatch(); *count = number_broadcasted; return RTEMS_SUCCESSFUL; } default: return RTEMS_INTERNAL_ERROR; | rtems_status_code rtems_message_queue_broadcast( Objects_Id id, void *buffer, unsigned32 size, unsigned32 *count){ register Message_queue_Control *the_message_queue; Objects_Locations location; Thread_Control *the_thread; unsigned32 number_broadcasted; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: _Thread_Executing->Wait.return_argument = count; return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_BROADCAST_REQUEST, id, buffer, &size, 0, /* option_set not used */ MPCI_DEFAULT_TIMEOUT ); case OBJECTS_LOCAL: { Thread_Wait_information *waitp; unsigned32 constrained_size; number_broadcasted = 0; while ( (the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) { waitp = &the_thread->Wait; number_broadcasted += 1; constrained_size = size; if (size > the_message_queue->maximum_message_size) constrained_size = the_message_queue->maximum_message_size; _Message_queue_Copy_buffer(buffer, waitp->return_argument, constrained_size); *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = size; if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, id, the_thread ); } } _Thread_Enable_dispatch(); *count = number_broadcasted; return RTEMS_SUCCESSFUL; } default: return RTEMS_INTERNAL_ERROR; }} |
|
return RTEMS_INTERNAL_ERROR; | rtems_status_code rtems_message_queue_broadcast( Objects_Id id, void *buffer, unsigned32 size, unsigned32 *count){ register Message_queue_Control *the_message_queue; Objects_Locations location; Thread_Control *the_thread; unsigned32 number_broadcasted; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: _Thread_Executing->Wait.return_argument = count; return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_BROADCAST_REQUEST, id, buffer, &size, 0, /* option_set not used */ MPCI_DEFAULT_TIMEOUT ); case OBJECTS_LOCAL: { Thread_Wait_information *waitp; unsigned32 constrained_size; number_broadcasted = 0; while ( (the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) { waitp = &the_thread->Wait; number_broadcasted += 1; constrained_size = size; if (size > the_message_queue->maximum_message_size) constrained_size = the_message_queue->maximum_message_size; _Message_queue_Copy_buffer(buffer, waitp->return_argument, constrained_size); *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = size; if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, id, the_thread ); } } _Thread_Enable_dispatch(); *count = number_broadcasted; return RTEMS_SUCCESSFUL; } default: return RTEMS_INTERNAL_ERROR; }} |
|
if ( _Attributes_Is_global( attribute_set ) && | if ( (is_global = _Attributes_Is_global( attribute_set ) ) && | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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 ( _Attributes_Is_global( attribute_set ) && (_MPCI_table->maximum_packet_size < max_message_size)) { return RTEMS_INVALID_SIZE; } | if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) ) return RTEMS_INVALID_SIZE; | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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 ( _Attributes_Is_global( attribute_set ) && !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, name, the_message_queue->Object.id, FALSE ) ) ) { | if ( is_global && !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, name, the_message_queue->Object.id, FALSE ) ) ) { | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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;} |
the_message_queue->maximum_pending_messages = count; | the_message_queue->attribute_set = attribute_set; | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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;} |
the_message_queue->attribute_set = attribute_set; the_message_queue->number_of_pending_messages = 0; | if (_Attributes_Is_priority( attribute_set ) ) the_message_queue_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; else the_message_queue_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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;} |
_Chain_Initialize_empty( &the_message_queue->Pending_messages ); | if ( ! _CORE_message_queue_Initialize( &the_message_queue->message_queue, OBJECTS_RTEMS_MESSAGE_QUEUES, &the_message_queue_attributes, count, max_message_size, _Message_queue_MP_Send_extract_proxy ) ) { if ( is_global ) _Objects_MP_Close( &_Message_queue_Information, the_message_queue->Object.id); | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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;} |
_Thread_queue_Initialize( &the_message_queue->Wait_queue, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); | _Message_queue_Free( the_message_queue ); _Thread_Enable_dispatch(); return RTEMS_TOO_MANY; } | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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 ( _Attributes_Is_global( attribute_set ) ) | if ( is_global ) | rtems_status_code rtems_message_queue_create( rtems_name name, unsigned32 count, unsigned32 max_message_size, rtems_attribute attribute_set, Objects_Id *id){ register Message_queue_Control *the_message_queue; if ( !rtems_is_name_valid( name ) ) return RTEMS_INVALID_NAME; if ( _Attributes_Is_global( attribute_set ) && !_System_state_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 ) && (_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_Allocate_and_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, OBJECTS_RTEMS_MESSAGE_QUEUES, _Attributes_Is_priority( attribute_set ) ? THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, STATES_WAITING_FOR_MESSAGE, _Message_queue_MP_Send_extract_proxy, RTEMS_TIMEOUT ); _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;} |
unsigned32 *size_p, | unsigned32 *size, | rtems_status_code rtems_message_queue_receive( Objects_Id id, void *buffer, unsigned32 *size_p, unsigned32 option_set, rtems_interval timeout){ register Message_queue_Control *the_message_queue; Objects_Locations location; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_RECEIVE_REQUEST, id, buffer, size_p, option_set, timeout ); case OBJECTS_LOCAL: if ( ! _Message_queue_Seize(the_message_queue, option_set, buffer, size_p)) { _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } _Thread_Enable_dispatch(); return _Thread_Executing->Wait.return_code; } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */} |
size_p, | size, | rtems_status_code rtems_message_queue_receive( Objects_Id id, void *buffer, unsigned32 *size_p, unsigned32 option_set, rtems_interval timeout){ register Message_queue_Control *the_message_queue; Objects_Locations location; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_RECEIVE_REQUEST, id, buffer, size_p, option_set, timeout ); case OBJECTS_LOCAL: if ( ! _Message_queue_Seize(the_message_queue, option_set, buffer, size_p)) { _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } _Thread_Enable_dispatch(); return _Thread_Executing->Wait.return_code; } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */} |
if ( ! _Message_queue_Seize(the_message_queue, option_set, buffer, size_p)) { _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } | if ( _Options_Is_no_wait( option_set ) ) wait = FALSE; else wait = TRUE; _CORE_message_queue_Seize( &the_message_queue->message_queue, the_message_queue->Object.id, buffer, size, wait, timeout ); | rtems_status_code rtems_message_queue_receive( Objects_Id id, void *buffer, unsigned32 *size_p, unsigned32 option_set, rtems_interval timeout){ register Message_queue_Control *the_message_queue; Objects_Locations location; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_RECEIVE_REQUEST, id, buffer, size_p, option_set, timeout ); case OBJECTS_LOCAL: if ( ! _Message_queue_Seize(the_message_queue, option_set, buffer, size_p)) { _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } _Thread_Enable_dispatch(); return _Thread_Executing->Wait.return_code; } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */} |
return _Thread_Executing->Wait.return_code; | return( _Message_queue_Translate_core_message_queue_return_code( _Thread_Executing->Wait.return_code ) ); | rtems_status_code rtems_message_queue_receive( Objects_Id id, void *buffer, unsigned32 *size_p, unsigned32 option_set, rtems_interval timeout){ register Message_queue_Control *the_message_queue; Objects_Locations location; the_message_queue = _Message_queue_Get( id, &location ); switch ( location ) { case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_REMOTE: return _Message_queue_MP_Send_request_packet( MESSAGE_QUEUE_MP_RECEIVE_REQUEST, id, buffer, size_p, option_set, timeout ); case OBJECTS_LOCAL: if ( ! _Message_queue_Seize(the_message_queue, option_set, buffer, size_p)) { _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } _Thread_Enable_dispatch(); return _Thread_Executing->Wait.return_code; } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */} |