rem
stringlengths
0
274k
add
stringlengths
0
169k
context
stringlengths
9
471k
strcpy( PreviousNodeName, NodeName ); break; }
strcpy( PreviousNodeName, NodeName );
void BuildTexinfoNodes( void ) { Line_Control *line; Line_Control *new_line; Line_Control *next_node; char Buffer[ BUFFER_SIZE ]; char ChapterName[ BUFFER_SIZE ]; char NodeName[ BUFFER_SIZE ]; char NextNode[ BUFFER_SIZE ]; char NextNodeName[ BUFFER_SIZE ]; char PreviousNodeName[ BUFFER_SIZE ]; char UpNodeName[ BUFFER_SIZE ]; char SectionName[ BUFFER_SIZE ]; char MenuBuffer[ BUFFER_SIZE ]; Line_Control *node_insert_point; Line_Control *menu_insert_point; Line_Control *node_line; boolean next_found; int menu_items; strcpy( PreviousNodeName, DocsPreviousNode ); for ( line = (Line_Control *) Lines.first ; !_Chain_Is_last( &line->Node ) ; line = (Line_Control *) line->Node.next ) { menu_insert_point = (Line_Control *) line->Node.next; switch ( Keywords[ line->keyword ].level ) { case TEXT: case HEADING: break; case SECTION: if ( line->keyword == KEYWORD_END ) goto bottom; if ( line->keyword == KEYWORD_CHAPTER || line->keyword == KEYWORD_CHAPHEADING ) { LineCopyFromRight( line, ChapterName ); strcpy( UpNodeName, DocsUpNode ); strcpy( NodeName, ChapterName ); } else { LineCopySectionName( line, Buffer ); sprintf( NodeName, "%s %s", ChapterName, Buffer ); strcpy( UpNodeName, ChapterName ); } strcpy( SectionName, NodeName ); /* * Go ahead and put it on the chain in the right order (ahead of * the menu) and we can fill it in later (after the menu is built). */ new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); node_line = AllocateLine(); _Chain_Insert( line->Node.previous, &node_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); menu_items = 0; if ( line->keyword == KEYWORD_CHAPTER || line->keyword == KEYWORD_CHAPHEADING ) { next_node = (Line_Control *) line->Node.next; next_found = FALSE; for ( ; ; ) { if ( next_node->keyword == KEYWORD_END ) break; if ( Keywords[ next_node->keyword ].level == SECTION ) { LineCopySectionName( next_node, Buffer ); if ( !next_found ) { next_found = TRUE; sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } if ( menu_items == 0 ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } menu_items++; new_line = AllocateLine(); sprintf( new_line->Contents, "* %s %s::", ChapterName, Buffer ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } next_node = (Line_Control *) next_node->Node.next; } } else { next_node = (Line_Control *) line->Node.next; next_found = FALSE; for ( ; ; ) { if ( Keywords[ next_node->keyword ].level == SECTION ) { if ( !next_found ) { if ( next_node->keyword == KEYWORD_END ) { strcpy( NextNodeName, DocsNextNode ); } else { LineCopySectionName( next_node, Buffer ); sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } next_found = TRUE; } break; } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { LineCopySectionName( next_node, MenuBuffer ); /* has next node */ if ( menu_items == 0 ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } menu_items++; new_line = AllocateLine(); sprintf( new_line->Contents, "* %s::", MenuBuffer ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); if ( !next_found ) { next_found = TRUE; strcpy( NextNodeName, MenuBuffer ); } } next_node = (Line_Control *) next_node->Node.next; } } if ( menu_items ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@end menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); }#if 0 fprintf( stderr, "@node %s, %s, %s, %s\n", NodeName, NextNodeName, PreviousNodeName, UpNodeName );#endif /* node_line was previously inserted */ sprintf( node_line->Contents, "@node %s, %s, %s, %s", NodeName, NextNodeName, PreviousNodeName, UpNodeName ); strcpy( PreviousNodeName, NodeName ); break; case SUBSECTION: strcpy( UpNodeName, SectionName ); LineCopyFromRight( line, NodeName ); new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); next_node = (Line_Control *) line->Node.next; for ( ; ; ) { if ( Keywords[ next_node->keyword ].level == SECTION ) { if ( next_node->keyword == KEYWORD_END ) { strcpy( NextNodeName, DocsNextNode ); } else { LineCopySectionName( next_node, Buffer ); sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } break; } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { LineCopyFromRight( next_node, NextNodeName ); break; } next_node = (Line_Control *) next_node->Node.next; }#if 0 fprintf( stderr, "@node %s, %s, %s, %s\n", NodeName, NextNodeName, PreviousNodeName, UpNodeName );#endif new_line = AllocateLine(); sprintf( new_line->Contents, "@node %s, %s, %s, %s", NodeName, NextNodeName, PreviousNodeName, UpNodeName ); _Chain_Insert( line->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); strcpy( PreviousNodeName, NodeName ); break; } }bottom:}
bottom:
void BuildTexinfoNodes( void ) { Line_Control *line; Line_Control *new_line; Line_Control *next_node; char Buffer[ BUFFER_SIZE ]; char ChapterName[ BUFFER_SIZE ]; char NodeName[ BUFFER_SIZE ]; char NextNode[ BUFFER_SIZE ]; char NextNodeName[ BUFFER_SIZE ]; char PreviousNodeName[ BUFFER_SIZE ]; char UpNodeName[ BUFFER_SIZE ]; char SectionName[ BUFFER_SIZE ]; char MenuBuffer[ BUFFER_SIZE ]; Line_Control *node_insert_point; Line_Control *menu_insert_point; Line_Control *node_line; boolean next_found; int menu_items; strcpy( PreviousNodeName, DocsPreviousNode ); for ( line = (Line_Control *) Lines.first ; !_Chain_Is_last( &line->Node ) ; line = (Line_Control *) line->Node.next ) { menu_insert_point = (Line_Control *) line->Node.next; switch ( Keywords[ line->keyword ].level ) { case TEXT: case HEADING: break; case SECTION: if ( line->keyword == KEYWORD_END ) goto bottom; if ( line->keyword == KEYWORD_CHAPTER || line->keyword == KEYWORD_CHAPHEADING ) { LineCopyFromRight( line, ChapterName ); strcpy( UpNodeName, DocsUpNode ); strcpy( NodeName, ChapterName ); } else { LineCopySectionName( line, Buffer ); sprintf( NodeName, "%s %s", ChapterName, Buffer ); strcpy( UpNodeName, ChapterName ); } strcpy( SectionName, NodeName ); /* * Go ahead and put it on the chain in the right order (ahead of * the menu) and we can fill it in later (after the menu is built). */ new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); node_line = AllocateLine(); _Chain_Insert( line->Node.previous, &node_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); menu_items = 0; if ( line->keyword == KEYWORD_CHAPTER || line->keyword == KEYWORD_CHAPHEADING ) { next_node = (Line_Control *) line->Node.next; next_found = FALSE; for ( ; ; ) { if ( next_node->keyword == KEYWORD_END ) break; if ( Keywords[ next_node->keyword ].level == SECTION ) { LineCopySectionName( next_node, Buffer ); if ( !next_found ) { next_found = TRUE; sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } if ( menu_items == 0 ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } menu_items++; new_line = AllocateLine(); sprintf( new_line->Contents, "* %s %s::", ChapterName, Buffer ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } next_node = (Line_Control *) next_node->Node.next; } } else { next_node = (Line_Control *) line->Node.next; next_found = FALSE; for ( ; ; ) { if ( Keywords[ next_node->keyword ].level == SECTION ) { if ( !next_found ) { if ( next_node->keyword == KEYWORD_END ) { strcpy( NextNodeName, DocsNextNode ); } else { LineCopySectionName( next_node, Buffer ); sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } next_found = TRUE; } break; } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { LineCopySectionName( next_node, MenuBuffer ); /* has next node */ if ( menu_items == 0 ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); } menu_items++; new_line = AllocateLine(); sprintf( new_line->Contents, "* %s::", MenuBuffer ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); if ( !next_found ) { next_found = TRUE; strcpy( NextNodeName, MenuBuffer ); } } next_node = (Line_Control *) next_node->Node.next; } } if ( menu_items ) { new_line = AllocateLine(); strcpy( new_line->Contents, "@end menu" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); }#if 0 fprintf( stderr, "@node %s, %s, %s, %s\n", NodeName, NextNodeName, PreviousNodeName, UpNodeName );#endif /* node_line was previously inserted */ sprintf( node_line->Contents, "@node %s, %s, %s, %s", NodeName, NextNodeName, PreviousNodeName, UpNodeName ); strcpy( PreviousNodeName, NodeName ); break; case SUBSECTION: strcpy( UpNodeName, SectionName ); LineCopyFromRight( line, NodeName ); new_line = AllocateLine(); strcpy( new_line->Contents, "@ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); next_node = (Line_Control *) line->Node.next; for ( ; ; ) { if ( Keywords[ next_node->keyword ].level == SECTION ) { if ( next_node->keyword == KEYWORD_END ) { strcpy( NextNodeName, DocsNextNode ); } else { LineCopySectionName( next_node, Buffer ); sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); } break; } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { LineCopyFromRight( next_node, NextNodeName ); break; } next_node = (Line_Control *) next_node->Node.next; }#if 0 fprintf( stderr, "@node %s, %s, %s, %s\n", NodeName, NextNodeName, PreviousNodeName, UpNodeName );#endif new_line = AllocateLine(); sprintf( new_line->Contents, "@node %s, %s, %s, %s", NodeName, NextNodeName, PreviousNodeName, UpNodeName ); _Chain_Insert( line->Node.previous, &new_line->Node ); new_line = AllocateLine(); strcpy( new_line->Contents, "@end ifinfo" ); _Chain_Insert( line->Node.previous, &new_line->Node ); strcpy( PreviousNodeName, NodeName ); break; } }bottom:}
return u_FpX_rem(z,pol,p, 0);
return u_FpX_rem(z,pol,p);
u_FpXQ_mul(GEN y,GEN x,GEN pol,ulong p){ GEN z = u_FpX_mul(y,x,p); return u_FpX_rem(z,pol,p, 0);}
idmul(GEN x, GEN y) { return idealmul(static_OBJ, x, y); }
idmul(void *nf, GEN x, GEN y) { return idealmul((GEN) nf, x, y); }
idmul(GEN x, GEN y) { return idealmul(static_OBJ, x, y); }
idpow(GEN x, GEN n) { return idealpow(static_OBJ, x, n); }
idpow(void *nf, GEN x, GEN n) { return idealpow((GEN) nf, x, n); }
idpow(GEN x, GEN n) { return idealpow(static_OBJ, x, n); }
idmulred(GEN x, GEN y) { return idealmulred(static_OBJ, x, y, 0); }
idmulred(void *nf, GEN x, GEN y) { return idealmulred((GEN) nf, x, y, 0); }
idmulred(GEN x, GEN y) { return idealmulred(static_OBJ, x, y, 0); }
if (!OBJ) return _factorback(fa, e, &gmul, &powgi);
if (!OBJ) return _factorback(fa, e, &_agmul, &_apowgi, NULL);
factorback_i(GEN fa, GEN e, GEN OBJ, int red){ if (!OBJ) { if (e) { OBJ = _checknf(e); if (OBJ) e = NULL; } if (!OBJ) return _factorback(fa, e, &gmul, &powgi); } static_OBJ = OBJ; if (red) return _factorback(fa, e, &idmulred, &idpowred); else return _factorback(fa, e, &idmul, &idpow);}
static_OBJ = OBJ; if (red) return _factorback(fa, e, &idmulred, &idpowred); else return _factorback(fa, e, &idmul, &idpow);
if (red) return _factorback(fa, e, &idmulred, &idpowred, OBJ); else return _factorback(fa, e, &idmul, &idpow, OBJ);
factorback_i(GEN fa, GEN e, GEN OBJ, int red){ if (!OBJ) { if (e) { OBJ = _checknf(e); if (OBJ) e = NULL; } if (!OBJ) return _factorback(fa, e, &gmul, &powgi); } static_OBJ = OBJ; if (red) return _factorback(fa, e, &idmulred, &idpowred); else return _factorback(fa, e, &idmul, &idpow);}
return (((unsigned long)pt->base) & ~(LD_MIN_PT_SIZE-1)) | ( ((pt->size-1) >> LD_MIN_PT_SIZE) & ((1<<(LD_HASH_SIZE-(LD_MIN_PT_SIZE-LD_PTEG_SIZE)))-1) );
return (((unsigned long) pt->base) & ~((1 << LD_MIN_PT_SIZE) - 1)) | (((pt->size - 1) >> LD_MIN_PT_SIZE) & ((1 << (LD_HASH_SIZE - (LD_MIN_PT_SIZE - LD_PTEG_SIZE))) - 1) );
triv121PgTblSDR1(Triv121PgTbl pt){ return (((unsigned long)pt->base) & ~(LD_MIN_PT_SIZE-1)) | ( ((pt->size-1) >> LD_MIN_PT_SIZE) & ((1<<(LD_HASH_SIZE-(LD_MIN_PT_SIZE-LD_PTEG_SIZE)))-1) );}
if (ctx->state == READ_DONE) {
if (ctx->state == READ_TERM) {
static apr_status_t consume_chunk(headers_context_t *ctx){ /* move to the next state, resetting the amount read. */ ++ctx->state; ctx->amt_read = 0; /* end of this header. move to the next one. */ if (ctx->state == READ_DONE) { ctx->cur_read = ctx->cur_read->next; if (ctx->cur_read == NULL) { /* there is no more data. leave us at READ_DONE and signal completion to the caller. */ return APR_EOF; } /* there _is_ another header, so reset the read state */ ctx->state = READ_HEADER; } /* there is more data which can be read immediately. */ return APR_SUCCESS;}
if (ctx->cur_read == NULL) { return APR_EOF;
if (ctx->cur_read != NULL) { ctx->state = READ_HEADER;
static apr_status_t consume_chunk(headers_context_t *ctx){ /* move to the next state, resetting the amount read. */ ++ctx->state; ctx->amt_read = 0; /* end of this header. move to the next one. */ if (ctx->state == READ_DONE) { ctx->cur_read = ctx->cur_read->next; if (ctx->cur_read == NULL) { /* there is no more data. leave us at READ_DONE and signal completion to the caller. */ return APR_EOF; } /* there _is_ another header, so reset the read state */ ctx->state = READ_HEADER; } /* there is more data which can be read immediately. */ return APR_SUCCESS;}
ctx->state = READ_HEADER;
static apr_status_t consume_chunk(headers_context_t *ctx){ /* move to the next state, resetting the amount read. */ ++ctx->state; ctx->amt_read = 0; /* end of this header. move to the next one. */ if (ctx->state == READ_DONE) { ctx->cur_read = ctx->cur_read->next; if (ctx->cur_read == NULL) { /* there is no more data. leave us at READ_DONE and signal completion to the caller. */ return APR_EOF; } /* there _is_ another header, so reset the read state */ ctx->state = READ_HEADER; } /* there is more data which can be read immediately. */ return APR_SUCCESS;}
reducebetanaive(GEN bnfz, GEN be, GEN b, long ell)
reducebetanaive(GEN bnfz, GEN be, GEN b, GEN ell)
reducebetanaive(GEN bnfz, GEN be, GEN b, long ell){ long i,k,n,ru,r1, prec = nfgetprec(bnfz); GEN z,p1,p2,nmax,c, nf = checknf(bnfz); if (DEBUGLEVEL) fprintferr("reduce modulo (Z_K^*)^l\n"); r1 = nf_get_r1(nf); if (!b) { if (typ(be) != t_COL) be = algtobasis(nf, be); b = gmul(gmael(nf,5,1), be); } n = max((ell>>1), 3); z = cgetg(n+1, t_VEC); c = gmulgs(greal((GEN)bnfz[3]), ell); c = logarch2arch(c, r1, prec); /* = embeddings of fu^ell */ c = gprec_w(gnorm(c), DEFAULTPREC); b = gprec_w(gnorm(b), DEFAULTPREC); /* need little precision */ z[1] = (long)concatsp(c, vecinv(c)); for (k=2; k<=n; k++) z[k] = (long) vecmul((GEN)z[1], (GEN)z[k-1]); nmax = T2_from_embed_norm(b, r1); ru = lg(c)-1; c = zerovec(ru); for(;;) { GEN B = NULL; long besti = 0, bestk = 0; for (k=1; k<=n; k++) for (i=1; i<=ru; i++) { p1 = vecmul(b, gmael(z,k,i)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk = k; continue; } p1 = vecmul(b, gmael(z,k,i+ru)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk =-k; } } if (!B) break; b = B; c[besti] = laddis((GEN)c[besti], bestk); } if (DEBUGLEVEL) fprintferr("unit exponents = %Z\n",c); return fix_be(bnfz,be,c);}
n = max((ell>>1), 3);
n = max((itos(ell)>>1), 3);
reducebetanaive(GEN bnfz, GEN be, GEN b, long ell){ long i,k,n,ru,r1, prec = nfgetprec(bnfz); GEN z,p1,p2,nmax,c, nf = checknf(bnfz); if (DEBUGLEVEL) fprintferr("reduce modulo (Z_K^*)^l\n"); r1 = nf_get_r1(nf); if (!b) { if (typ(be) != t_COL) be = algtobasis(nf, be); b = gmul(gmael(nf,5,1), be); } n = max((ell>>1), 3); z = cgetg(n+1, t_VEC); c = gmulgs(greal((GEN)bnfz[3]), ell); c = logarch2arch(c, r1, prec); /* = embeddings of fu^ell */ c = gprec_w(gnorm(c), DEFAULTPREC); b = gprec_w(gnorm(b), DEFAULTPREC); /* need little precision */ z[1] = (long)concatsp(c, vecinv(c)); for (k=2; k<=n; k++) z[k] = (long) vecmul((GEN)z[1], (GEN)z[k-1]); nmax = T2_from_embed_norm(b, r1); ru = lg(c)-1; c = zerovec(ru); for(;;) { GEN B = NULL; long besti = 0, bestk = 0; for (k=1; k<=n; k++) for (i=1; i<=ru; i++) { p1 = vecmul(b, gmael(z,k,i)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk = k; continue; } p1 = vecmul(b, gmael(z,k,i+ru)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk =-k; } } if (!B) break; b = B; c[besti] = laddis((GEN)c[besti], bestk); } if (DEBUGLEVEL) fprintferr("unit exponents = %Z\n",c); return fix_be(bnfz,be,c);}
c = gmulgs(greal((GEN)bnfz[3]), ell);
c = gmul(greal((GEN)bnfz[3]), ell);
reducebetanaive(GEN bnfz, GEN be, GEN b, long ell){ long i,k,n,ru,r1, prec = nfgetprec(bnfz); GEN z,p1,p2,nmax,c, nf = checknf(bnfz); if (DEBUGLEVEL) fprintferr("reduce modulo (Z_K^*)^l\n"); r1 = nf_get_r1(nf); if (!b) { if (typ(be) != t_COL) be = algtobasis(nf, be); b = gmul(gmael(nf,5,1), be); } n = max((ell>>1), 3); z = cgetg(n+1, t_VEC); c = gmulgs(greal((GEN)bnfz[3]), ell); c = logarch2arch(c, r1, prec); /* = embeddings of fu^ell */ c = gprec_w(gnorm(c), DEFAULTPREC); b = gprec_w(gnorm(b), DEFAULTPREC); /* need little precision */ z[1] = (long)concatsp(c, vecinv(c)); for (k=2; k<=n; k++) z[k] = (long) vecmul((GEN)z[1], (GEN)z[k-1]); nmax = T2_from_embed_norm(b, r1); ru = lg(c)-1; c = zerovec(ru); for(;;) { GEN B = NULL; long besti = 0, bestk = 0; for (k=1; k<=n; k++) for (i=1; i<=ru; i++) { p1 = vecmul(b, gmael(z,k,i)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk = k; continue; } p1 = vecmul(b, gmael(z,k,i+ru)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk =-k; } } if (!B) break; b = B; c[besti] = laddis((GEN)c[besti], bestk); } if (DEBUGLEVEL) fprintferr("unit exponents = %Z\n",c); return fix_be(bnfz,be,c);}
return fix_be(bnfz,be,c);
return fix_be(bnfz, be, gmul(ell,c));
reducebetanaive(GEN bnfz, GEN be, GEN b, long ell){ long i,k,n,ru,r1, prec = nfgetprec(bnfz); GEN z,p1,p2,nmax,c, nf = checknf(bnfz); if (DEBUGLEVEL) fprintferr("reduce modulo (Z_K^*)^l\n"); r1 = nf_get_r1(nf); if (!b) { if (typ(be) != t_COL) be = algtobasis(nf, be); b = gmul(gmael(nf,5,1), be); } n = max((ell>>1), 3); z = cgetg(n+1, t_VEC); c = gmulgs(greal((GEN)bnfz[3]), ell); c = logarch2arch(c, r1, prec); /* = embeddings of fu^ell */ c = gprec_w(gnorm(c), DEFAULTPREC); b = gprec_w(gnorm(b), DEFAULTPREC); /* need little precision */ z[1] = (long)concatsp(c, vecinv(c)); for (k=2; k<=n; k++) z[k] = (long) vecmul((GEN)z[1], (GEN)z[k-1]); nmax = T2_from_embed_norm(b, r1); ru = lg(c)-1; c = zerovec(ru); for(;;) { GEN B = NULL; long besti = 0, bestk = 0; for (k=1; k<=n; k++) for (i=1; i<=ru; i++) { p1 = vecmul(b, gmael(z,k,i)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk = k; continue; } p1 = vecmul(b, gmael(z,k,i+ru)); p2 = T2_from_embed_norm(p1,r1); if (gcmp(p2,nmax) < 0) { B=p1; nmax=p2; besti=i; bestk =-k; } } if (!B) break; b = B; c[besti] = laddis((GEN)c[besti], bestk); } if (DEBUGLEVEL) fprintferr("unit exponents = %Z\n",c); return fix_be(bnfz,be,c);}
c = gerepileupto(av2, gcopy(c));
c = gerepilecopy(av2, c);
newtoncharpoly(GEN a, GEN chi, GEN pp, GEN ns){ GEN v, c, s, t; long n = degpol(chi), j, k, vn = varn(chi), av = avma, av2, lim; v = newtonsums(a, chi, pp, ns); av2 = avma; lim = stack_lim(av2, 1); c = cgetg(n + 2, t_VEC); c[1] = un; if (n%2) c[1] = lneg((GEN)c[1]); for (k = 2; k <= n+1; k++) c[k] = zero; for (k = 2; k <= n+1; k++) { s = gzero; for (j = 1; j < k; j++) { t = gmul((GEN)v[j], (GEN)c[k-j]); if (!(j%2)) t = gneg(t); s = gadd(s, t); } c[k] = ldiv(s, stoi(k - 1)); if (low_stack(lim, stack_lim(av2, 1))) { if(DEBUGMEM>1) err(warnmem, "newtoncharpoly"); c = gerepileupto(av2, gcopy(c)); } } k = (n%2)? 1: 2; for ( ; k <= n+1; k += 2) c[k] = lneg((GEN)c[k]); return gerepileupto(av, gtopoly(c, vn));}
} iop->flags |= LIBIO_FLAGS_HANDLER_SOCK;
} iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
int rtems_bsdnet_makeFdForSocket( void *so){ rtems_libio_t *iop; iop = rtems_libio_allocate(); if (iop == 0) { errno = ENFILE; return -1; } iop->flags |= LIBIO_FLAGS_HANDLER_SOCK; iop->data1 = so; return iop - rtems_libio_iops;}
error = so_ioctl (so, command, buffer);
error = so_ioctl (iop, so, command, buffer);
rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer){ struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); if ((so = iop->data1) == NULL) { errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } error = so_ioctl (so, command, buffer); rtems_bsdnet_semaphore_release (); if (error) { errno = error; return -1; } return 0;}
void timerOn(const rtems_raw_irq_connect_data* used)
timerOn(const rtems_raw_irq_connect_data* used)
void timerOn(const rtems_raw_irq_connect_data* used){ /* load timer for US_PER_ISR microsecond period */ outport_byte(TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN); outport_byte(TIMER_CNTR0, US_TO_TICK(US_PER_ISR) >> 0 & 0xff); outport_byte(TIMER_CNTR0, US_TO_TICK(US_PER_ISR) >> 8 & 0xff); /* * enable interrrupt at i8259 level */ pc386_irq_enable_at_i8259s(used->idtIndex - PC386_IRQ_VECTOR_BASE);}
unsigned32 i;
uint32_t i;
void Period_usage_Reset( void ){ unsigned32 i; Period_usage_t *the_usage; for ( i=0 ; i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ; i++ ) { the_usage = &Period_usage_Information[ i ]; the_usage->count = 0; the_usage->missed_count = 0; the_usage->min_cpu_time = 0xFFFFFFFF; the_usage->max_cpu_time = 0; the_usage->total_cpu_time = 0; the_usage->min_wall_time = 0xFFFFFFFF; the_usage->max_wall_time = 0; the_usage->total_wall_time = 0; }}
P = FpXX_red(P, p);
P = FpXX_red(P, p); btop = avma;
FpXQX_safegcd(GEN P, GEN Q, GEN T, GEN p){ gpmem_t btop, ltop = avma, st_lim; long dg, vx = varn(P); GEN U, q; P = FpXX_red(P, p); Q = FpXX_red(Q, p); if (!signe(P)) return gerepileupto(ltop, Q); if (!signe(Q)) { avma = (gpmem_t)P; return P; } T = FpX_red(T, p); btop = avma; st_lim = stack_lim(btop, 1); dg = lgef(P)-lgef(Q); if (dg < 0) { swap(P, Q); dg = -dg; } for(;;) { U = FpXQ_invsafe(leading_term(Q), T, p); if (!U) { avma = ltop; return NULL; } do /* set P := P % Q */ { q = FpXQ_mul(U, gneg(leading_term(P)), T, p); P = gadd(P, FpXQX_mul(monomial(q, dg, vx), Q, T, p)); P = FpXQX_red(P, T, p); /* wasteful, but negligible */ dg = lgef(P)-lgef(Q); } while (dg >= 0); if (!signe(P)) break; if (low_stack(st_lim, stack_lim(btop, 1))) { GEN *bptr[2]; bptr[0]=&P; bptr[1]=&Q; if (DEBUGLEVEL>1) err(warnmem,"FpXQX_safegcd"); gerepilemany(btop, bptr, 2); } swap(P, Q); dg = -dg; } Q = FpXQX_FpXQ_mul(Q, U, T, p); /* normalize GCD */ return gerepileupto(ltop, Q);}
if (!signe(Q)) { avma = (gpmem_t)P; return P; }
if (!signe(Q)) { avma = btop; return P; }
FpXQX_safegcd(GEN P, GEN Q, GEN T, GEN p){ gpmem_t btop, ltop = avma, st_lim; long dg, vx = varn(P); GEN U, q; P = FpXX_red(P, p); Q = FpXX_red(Q, p); if (!signe(P)) return gerepileupto(ltop, Q); if (!signe(Q)) { avma = (gpmem_t)P; return P; } T = FpX_red(T, p); btop = avma; st_lim = stack_lim(btop, 1); dg = lgef(P)-lgef(Q); if (dg < 0) { swap(P, Q); dg = -dg; } for(;;) { U = FpXQ_invsafe(leading_term(Q), T, p); if (!U) { avma = ltop; return NULL; } do /* set P := P % Q */ { q = FpXQ_mul(U, gneg(leading_term(P)), T, p); P = gadd(P, FpXQX_mul(monomial(q, dg, vx), Q, T, p)); P = FpXQX_red(P, T, p); /* wasteful, but negligible */ dg = lgef(P)-lgef(Q); } while (dg >= 0); if (!signe(P)) break; if (low_stack(st_lim, stack_lim(btop, 1))) { GEN *bptr[2]; bptr[0]=&P; bptr[1]=&Q; if (DEBUGLEVEL>1) err(warnmem,"FpXQX_safegcd"); gerepilemany(btop, bptr, 2); } swap(P, Q); dg = -dg; } Q = FpXQX_FpXQ_mul(Q, U, T, p); /* normalize GCD */ return gerepileupto(ltop, Q);}
return u_FpX_rem(z,pol,p, 0);
return u_FpX_rem(z,pol,p);
u_FpXQ_sqr(GEN y,GEN pol,ulong p){ GEN z = u_FpX_sqr(y,p); return u_FpX_rem(z,pol,p, 0);}
ulong av = avma, av2, lim;
ulong av = avma, av2, lim, bound;
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound;
GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp;
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound);
if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: 2^%ld\n",bound);
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
fprintferr("bound for resultant coeffs: %Z\n",bound);
fprintferr("bound for resultant coeffs: 2^%ld\n",bound);
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break;
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld (bound 2^%ld)", p,expi(q)); if (expi(q) >= bound) break;
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B;
GEN *gptr[3]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &B;
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0);
gerepilemany(av2,gptr,lambda? 3: 2); b = u_allocpol(deg(B), 0);
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
return gerepileupto(av, gcopy(H));
return gerepileupto(av, H);
ZY_ZXY_resultant(GEN A, GEN B0, long *lambda){ int checksqfree = lambda? 1: 0, delete = 0; ulong av = avma, av2, lim; long i,n, lb, dres = deg(A)*deg(B0), nmax = (dres+1)>>1; long vX = varn(B0), vY = varn(A); /* assume vX < vY */ GEN x = cgetg(dres+2, t_VECSMALL); GEN y = cgetg(dres+2, t_VECSMALL), cB,B,q,a,b,ev,H,Hp,bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; if (vY == MAXVARN) { vY = fetch_var(); delete = 1; B0 = gsubst(B0, MAXVARN, polx[vY]); A = dummycopy(A); setvarn(A, vY); } cB = content(B0); if (typ(cB) == t_POL) cB = content(cB); if (gcmp1(cB)) cB = NULL; else B0 = gdiv(B0, cB); av2 = avma; lim = stack_lim(av,2); if (lambda) { *lambda = -1; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); } else B = poleval(B0, polx[MAXVARN]); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant coeffs: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); for (i=2; i<lb; i++) b[i] = (long)u_Fp_FpX((GEN)B[i], 0, p); /* Evaluate at 0 (if dres even) and +/- n, so that P_n(X) = P_{-n}(-X), * where P_i is Lagrange polynomial: P_i(j) = 1 if i=j, 0 otherwise */ for (i=0,n = 1; n <= nmax; n++) { ev = vec_u_FpX_eval(b, n, p); i++; x[i] = n; y[i] = u_FpX_resultant(a, ev, p); ev = vec_u_FpX_eval(b, p-n, p); i++; x[i] = p-n; y[i] = u_FpX_resultant(a, ev, p); } if (i == dres) { ev = vec_u_FpX_eval(b, 0, p); i++; x[i] = 0; y[i] = u_FpX_resultant(a, ev, p); } Hp = u_FpV_polint(x,y, p); if (checksqfree) { if (u_FpX_is_squarefree(Hp, p)) { if (DEBUGLEVEL>4) fprintferr("Final lambda = %ld\n",*lambda); checksqfree = 0; } else { (*lambda)++; H = NULL; avma = av2; B = poleval(B0, gadd(polx[MAXVARN], gmulsg(-*lambda, polx[vY]))); lb = lgef(B); b = u_allocpol(deg(B), 0); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) { fprintferr("Restarting with lambda = %ld\n",*lambda); fprintferr("bound for resultant coeffs: %Z\n",bound); } continue; } } if (!H) H = init_CRT(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT(H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[4]; gptr[0] = &H; gptr[1] = &q; gptr[2] = &bound; gptr[3] = &B; if (DEBUGMEM>1) err(warnmem,"ZY_ZXY_resultant"); gerepilemany(av2,gptr,lambda? 4: 2); b = u_allocpol(deg(B), 0); } } setvarn(H, vX); if (delete) delete_var(); H = cB? gmul(H, gpowgs(cB, deg(A))): gcopy(H); return gerepileupto(av, gcopy(H));}
rtems_unsigned32 task_stacksize,
uint32_t task_stacksize,
rtems_status_code shell_init (char * task_name, rtems_unsigned32 task_stacksize, rtems_task_priority task_priority, char * devname, tcflag_t tcflag, int forever) { rtems_id task_id; rtems_status_code sc; shell_env_t * shell_env; sc=rtems_task_create(new_rtems_name(task_name), task_priority, task_stacksize?task_stacksize:RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_LOCAL | RTEMS_FLOATING_POINT, &task_id); if (sc!=RTEMS_SUCCESSFUL) { rtems_error(sc,"creating task %s in shell_init()",task_name); return sc; }; shell_env=malloc(sizeof(shell_env_t)); if (!shell_env) { rtems_task_delete(task_id); sc=RTEMS_NO_MEMORY; rtems_error(sc,"allocating shell_env %s in shell_init()",task_name); return sc; }; if (global_shell_env.magic!=new_rtems_name("SENV")) { global_shell_env.magic =new_rtems_name("SENV"); global_shell_env.devname ="/dev/console"; global_shell_env.taskname ="GLOBAL"; global_shell_env.tcflag =0; global_shell_env.exit_shell=0; global_shell_env.forever =TRUE; }; shell_env->magic =global_shell_env.magic; shell_env->devname =devname; shell_env->taskname =task_name; shell_env->tcflag =tcflag; shell_env->exit_shell=FALSE; shell_env->forever =forever; return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);}
reg = gcdrealnoer(gcoeff(matc,1,i),reg,&e);
reg = gcdreal(gcoeff(matc,1,i),reg,&e);
get_reg(GEN matc, long sreg){ long i,e,maxe; GEN reg = mpabs(gcoeff(matc,1,1)); e = maxe = 0; for (i=2; i<=sreg; i++) { reg = gcdrealnoer(gcoeff(matc,1,i),reg,&e); if (!reg) return NULL; maxe = maxe? max(maxe,e): e; } if (DEBUGLEVEL) { if (DEBUGLEVEL>7) { fprintferr("reg = "); outerr(reg); } msgtimer("regulator"); } return reg;}
if (DEBUGLEVEL>7) { fprintferr("reg = "); outerr(reg); }
if (DEBUGLEVEL>7) fprintferr("reg = %Z",reg);
get_reg(GEN matc, long sreg){ long i,e,maxe; GEN reg = mpabs(gcoeff(matc,1,1)); e = maxe = 0; for (i=2; i<=sreg; i++) { reg = gcdrealnoer(gcoeff(matc,1,i),reg,&e); if (!reg) return NULL; maxe = maxe? max(maxe,e): e; } if (DEBUGLEVEL) { if (DEBUGLEVEL>7) { fprintferr("reg = "); outerr(reg); } msgtimer("regulator"); } return reg;}
subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i];
ex = cgetg(lgsub,t_VECSMALL); subvperm = gcopy(vperm);
buchall(GEN P,GEN gcbach,GEN gcbach2,GEN gRELSUP,GEN gborne,long nbrelpid, long minsfb,long flun,long prec){ long av = avma,av0,av1,limpile,i,j,k,ss,cmptglob,lgsub; long N,R1,R2,RU,PRECREG,PRECREGINT,KCCO,KCCOPRO,RELSUP; long extrarel,nlze,sreg,nrelsup,nreldep,phase,slim,matcopymax; long first = 1, sfb_increase = 0, sfb_trials = 0; long **mat,**matcopy,*vperm,*subvperm,*ex; double cbach,cbach2,drc,LOGD2,lim,LIMC,LIMC2; GEN p1,p2,lmatt2,fu,zu,nf,D,xarch,met,W,reg,lfun,z,clh; GEN B,C,u1,u2,c1,sublambda,pdep,parch,liste,invp,clg1,clg2; GEN CHANGE=NULL, extramat=NULL, extraC=NULL; if (DEBUGLEVEL) timer2(); if (typ(P)==t_POL) nf = NULL; else { nf=checknf(P); P=(GEN)nf[1]; } if (typ(gRELSUP)!=t_INT) gRELSUP=gtrunc(gRELSUP); RELSUP = itos(gRELSUP); if (RELSUP<=0) err(talker,"not enough relations in bnfxxx"); /* Initializations */ N=lgef(P)-3; if (!nf) { nf=initalgall0(P, flun>=0? nf_REGULAR: nf_DIFFERENT, max(BIGDEFAULTPREC,prec)); if (lg(nf)==3) /* P was a non-monic polynomial, nfinit changed it */ { CHANGE=(GEN)nf[2]; nf=(GEN)nf[1]; } if (DEBUGLEVEL) msgtimer("initalg"); } if (N<=1) return buchall_for_degree_one_pol(nf,CHANGE,flun); zu=rootsof1(nf); zu[2] = lmul((GEN)nf[7],(GEN)zu[2]); if (DEBUGLEVEL) msgtimer("rootsof1"); R1=itos(gmael(nf,2,1)); R2=(N-R1)>>1; RU=R1+R2; D=(GEN)nf[3]; drc=fabs(gtodouble(D)); LOGD2=log(drc); LOGD2 = LOGD2*LOGD2; lim = exp(-(double)N) * sqrt(2*PI*N*drc) * pow(4/PI,(double)R2); if (lim < 3.) lim = 3.; cbach = min(12., gtodouble(gcbach)); cbach /= 2; cbach2 = gtodouble(gcbach2); if (DEBUGLEVEL) { fprintferr("N = %ld, R1 = %ld, R2 = %ld, RU = %ld\n",N,R1,R2,RU); fprintferr("D = %Z\n",D); } av0 = avma; matcopy = NULL; powsubfactorbase = NULL;INCREASEGEN: if (first) first = 0; else { desallocate(matcopy); avma = av0; } sfb_trials = sfb_increase = 0; cbach = check_bach(cbach,12.); nreldep = nrelsup = 0; LIMC = cbach*LOGD2; if (LIMC < 20.) LIMC = 20.; LIMC2=max(3. * N, max(cbach,cbach2)*LOGD2); if (LIMC2 < LIMC) LIMC2=LIMC; if (DEBUGLEVEL) { fprintferr("LIMC = %.1f, LIMC2 = %.1f\n",LIMC,LIMC2); } /* initialize factorbase, subfactorbase, vperm */ lfun = factorbasegen(nf,(long)LIMC2,(long)LIMC); if (!lfun) goto INCREASEGEN; vperm = cgetg(KC+1,t_VECSMALL); ss = subfactorbasegen(N,(long)min(lim,LIMC2), minsfb, vperm); if (ss == -1) goto INCREASEGEN; lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; PRECREGINT = DEFAULTPREC + ((expi(D)*(lgsub-2)+((N*N)>>2))>>TWOPOTBITS_IN_LONG); PRECREG = max(prec+1,PRECREGINT); KCCO = KC+RU-1 + max(ss,RELSUP); if (DEBUGLEVEL) { fprintferr("nbrelsup = %ld, ss = %ld, ",RELSUP,ss); fprintferr("KCZ = %ld, KC = %ld, KCCO = %ld \n",KCZ,KC,KCCO); flusherr(); } mat=(long**)gpmalloc(sizeof(long*)*(KCCO+1)); setlg(mat, KCCO+1); C = cgetg(KCCO+1,t_MAT); cmptglob=0; /* trivial relations */ for (i=1; i<=KCZ; i++) { GEN P = idealbase[i]; if (isclone(P)) { /* all prime divisors in factorbase */ unsetisclone(P); cmptglob++; mat[cmptglob] = p1 = col_0(KC); C[cmptglob] = (long)(p2 = cgetg(RU+1,t_COL)); k = numideal[factorbase[i]]; p1[0] = k+1; p1 += k; /* for already_found_relation */ k = lg(P); for (j=1; j<k; j++) p1[j] = itos(gmael(P,j,3)); for (j=1; j<=RU; j++) p2[j] = zero; } } /* initialize for other relations */ for (i=cmptglob+1; i<=KCCO; i++) { mat[i] = col_0(KC); C[i] = (long) (p1 = cgetg(RU+1,t_COL)); for (j=1; j<=RU; j++) { p2=cgetg(3,t_COMPLEX); p2[1]=lgetr(PRECREG); p2[2]=lgetr(PRECREG); p1[j]=(long)p2; } } av1 = avma; liste = new_chunk(KC+1); for (i=1; i<=KC; i++) liste[i]=0; invp = cmptglob? relationrank(mat,KC,cmptglob,liste): idmat(KC); /* relations through elements of small norm */ cmptglob = small_norm_for_buchall(cmptglob,mat,C,KCCO,(long)LIMC, PRECREG,nf,gborne,nbrelpid,invp,liste); if (cmptglob < 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (small_norm)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } avma = av1; limpile=stack_lim(av1,1); slim = KCCO; phase = 0; nlze = matcopymax = 0; /* for lint */ lmatt2 = NULL; /* random relations */ if (cmptglob == KCCO) /* enough relations, initialize nevertheless */ ((void(*)(long))random_relation)(-1); else { GEN maarch; long **ma; if (DEBUGLEVEL) { fprintferr("\n#### Looking for random relations\n"); flusherr(); } LABELINT: if (sfb_increase) { /* increase subfactorbase */ sfb_increase = 0; if (++sfb_trials > SFB_MAX || subfactorbasegen(N,(long)min(lim,LIMC2), lgsub-1+SFB_STEP, vperm) < 0) goto INCREASEGEN; if (DEBUGLEVEL) fprintferr("*** Increasing subfactorbase\n"); if (powsubfactorbase) { /* desallocate using _old_ lgsub value */ for (i=lgsub-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; nreldep = nrelsup = 0; } if (phase == 0) { ma = mat; maarch = C; } else /* reduced the relation matrix at least once */ { extrarel = nlze; if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; slim = cmptglob+extrarel; setlg(extraC,extrarel+1); setlg(extramat,extrarel+1); if (slim > matcopymax) { matcopy = (long**)gprealloc(matcopy, (2*slim+1) * sizeof(long*), (matcopymax+1) * sizeof(long*)); matcopymax = 2 * slim; } setlg(matcopy,slim+1); if (DEBUGLEVEL) fprintferr("\n(need %ld more relation%s)\n", extrarel, (extrarel==1)?"":"s"); for (j=cmptglob+1; j<=slim; j++) matcopy[j] = col_0(KC); maarch = extraC - cmptglob; /* start at 0, the others at cmptglob */ ma = matcopy; } if (!lmatt2) { lmatt2 = compute_matt2(RU,nf); av1 = avma; } if (!powsubfactorbase) { powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); av1 = avma; } ss = random_relation(phase,cmptglob,slim,(long)LIMC,N,RU,PRECREG, PRECREGINT,nf,vperm,subvperm,ma,maarch,lmatt2,ex); if (ss < 0) /* could not find relations */ { if (phase == 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); } if (ss != -1) { /* precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (random_relation)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; } goto INCREASEGEN; } if (phase) for (j=1; j<=extrarel; j++) { long *c = matcopy[cmptglob+j]; GEN *g = (GEN*) extramat[j]; for (k=1; k<=KC; k++) g[k] = stoi(c[vperm[k]]); } cmptglob = ss; } /* reduce relation matrices */ if (phase == 0) /* never reduced before */ { matcopymax = 10*KCCO + MAXRELSUP; matcopy = (long**)gpmalloc(sizeof(long*)*(matcopymax + 1)); setlg(matcopy, KCCO+1); for (j=1; j<=KCCO; j++) matcopy[j] = col_dup(KC,mat[j]); W = hnfspec(mat,vperm,&pdep,&B,&C,lgsub-1); for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); KCCOPRO = KCCO; phase = 1; /* keep some room for the extra relation. We will update matrix size when * extrarel goes down */ nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; extrarel = nlze; /* in case the regulator is 0 */ if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; extramat =cgetg(extrarel+1,t_MAT); extraC=cgetg(extrarel+1,t_MAT); for (j=1; j<=extrarel; j++) { extramat[j]=lgetg(KC+1,t_COL); extraC[j]=lgetg(RU+1,t_COL); for (i=1; i<=RU; i++) { p1 = cgetg(3,t_COMPLEX); mael(extraC,j,i)=(long)p1; p1[1]=lgetr(PRECREG); p1[2]=lgetr(PRECREG); } } } else { if (low_stack(limpile, stack_lim(av1,1))) { GEN *gptr[6]; if(DEBUGMEM>1) err(warnmem,"buchall"); gptr[0]=&W; gptr[1]=&C; gptr[2]=&B; gptr[3]=&pdep; gptr[4]=&extramat; gptr[5]=&extraC; gerepilemany(av1,gptr,6); } W = hnfadd(W,vperm,&pdep,&B,&C, extramat,extraC); nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; KCCOPRO += extrarel; if (nlze && ++nreldep > MAXRELSUP) { sfb_increase=1; goto LABELINT; } } if (nlze) goto LABELINT; /* dependent rows */ /* first attempt at regulator for the check */ sreg = KCCOPRO - (lg(B)-1) - (lg(W)-1); /* = zc (cf hnffinal) */ xarch = cgetg(sreg+1,t_MAT); /* cols corresponding to units */ for (j=1; j<=sreg; j++) xarch[j] = C[j]; reg = compute_multiple_of_R(xarch,RU,N,PRECREG,&sublambda); if (!reg) { /* not full rank for units */ if (DEBUGLEVEL) fprintferr("regulator is zero.\n"); if (++nrelsup > MAXRELSUP) goto INCREASEGEN; nlze=MIN_EXTRA; goto LABELINT; } if (!sublambda) { /* anticipate precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (bestappr)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } /* class number */ if (DEBUGLEVEL) fprintferr("\n"); clh = compute_class_number(W,&met,&u1,&u2); /* check */ z = mulrr(lfun,gmul(gmul2n(gpuigs(shiftr(mppi(DEFAULTPREC),1),-R2),-R1), gsqrt(absi(D),DEFAULTPREC))); z = mulri(z,(GEN)zu[1]); /* z = Res (zeta_K, s = 1) * w D^(1/2) / [ 2^r1 (2pi)^r2 ] = h R */ p1 = gmul2n(divir(clh,z), 1); c1 = compute_check(sublambda,p1,&parch,&reg); /* c1 should be close to 2, and not much smaller */ if (c1 && gcmpgs(gmul2n(c1,1),3) < 0) { c1=NULL; nrelsup=MAXRELSUP; } if (!c1 || gcmpgs(c1,3) > 0) { if (++nrelsup <= MAXRELSUP) { if (DEBUGLEVEL) { if (c1) fprintferr("\n ***** check = %f\n\n",gtodouble(c1)/2); else fprintferr("\n ***** check = NULL\n\n"); flusherr(); } nlze=MIN_EXTRA; goto LABELINT; } if (!c1 || cbach<11.99) { sfb_increase=1; goto LABELINT; } err(warner,"suspicious check. Suggest increasing extra relations."); } /* Phase "be honest" */ if (KCZ2 > KCZ) { if (!powsubfactorbase) powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); if (!be_honest(nf,RU,PRECREGINT)) goto INCREASEGEN; } /* regulator, roots of unity, fundamental units */ if (flun < 0 || flun > 1) { xarch = cleancol(gmul(xarch,parch),N,PRECREG); if (DEBUGLEVEL) msgtimer("cleancol"); } if (labs(flun) > 1) { fu = getfu(nf,&xarch,reg,flun,&k,PRECREG); if (k) fu = gmul((GEN)nf[7],fu); else if (labs(flun) > 2) { prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (getfu)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } } /* class group generators */ if (DEBUGLEVEL) fprintferr("\n"); class_group_gen(nf,met,clh,u1,u2,vperm, &clg1, &clg2, PRECREGINT); /* cleanup */ desallocate(matcopy); i = lg(C)-sreg; C += sreg; C[0] = evaltyp(t_MAT)|evallg(i); C = cleancol(C,N,PRECREG); settyp(vperm, t_COL); for (i=1; i<=KC; i++) vperm[i]=lstoi(vperm[i]); c1 = gdiv(gmul(reg,clh),z); return gerepileupto(av, buchall_end(nf,CHANGE,flun,k,fu,clg1,clg2,reg,c1,zu,W,B,xarch,C,vectbase,vperm));}
subfactorbasegen(N,(long)min(lim,LIMC2), lgsub-1+SFB_STEP, vperm) < 0)
subfactorbasegen(N,(long)min(lim,LIMC2), lgsub-1+SFB_STEP, NULL) < 0)
buchall(GEN P,GEN gcbach,GEN gcbach2,GEN gRELSUP,GEN gborne,long nbrelpid, long minsfb,long flun,long prec){ long av = avma,av0,av1,limpile,i,j,k,ss,cmptglob,lgsub; long N,R1,R2,RU,PRECREG,PRECREGINT,KCCO,KCCOPRO,RELSUP; long extrarel,nlze,sreg,nrelsup,nreldep,phase,slim,matcopymax; long first = 1, sfb_increase = 0, sfb_trials = 0; long **mat,**matcopy,*vperm,*subvperm,*ex; double cbach,cbach2,drc,LOGD2,lim,LIMC,LIMC2; GEN p1,p2,lmatt2,fu,zu,nf,D,xarch,met,W,reg,lfun,z,clh; GEN B,C,u1,u2,c1,sublambda,pdep,parch,liste,invp,clg1,clg2; GEN CHANGE=NULL, extramat=NULL, extraC=NULL; if (DEBUGLEVEL) timer2(); if (typ(P)==t_POL) nf = NULL; else { nf=checknf(P); P=(GEN)nf[1]; } if (typ(gRELSUP)!=t_INT) gRELSUP=gtrunc(gRELSUP); RELSUP = itos(gRELSUP); if (RELSUP<=0) err(talker,"not enough relations in bnfxxx"); /* Initializations */ N=lgef(P)-3; if (!nf) { nf=initalgall0(P, flun>=0? nf_REGULAR: nf_DIFFERENT, max(BIGDEFAULTPREC,prec)); if (lg(nf)==3) /* P was a non-monic polynomial, nfinit changed it */ { CHANGE=(GEN)nf[2]; nf=(GEN)nf[1]; } if (DEBUGLEVEL) msgtimer("initalg"); } if (N<=1) return buchall_for_degree_one_pol(nf,CHANGE,flun); zu=rootsof1(nf); zu[2] = lmul((GEN)nf[7],(GEN)zu[2]); if (DEBUGLEVEL) msgtimer("rootsof1"); R1=itos(gmael(nf,2,1)); R2=(N-R1)>>1; RU=R1+R2; D=(GEN)nf[3]; drc=fabs(gtodouble(D)); LOGD2=log(drc); LOGD2 = LOGD2*LOGD2; lim = exp(-(double)N) * sqrt(2*PI*N*drc) * pow(4/PI,(double)R2); if (lim < 3.) lim = 3.; cbach = min(12., gtodouble(gcbach)); cbach /= 2; cbach2 = gtodouble(gcbach2); if (DEBUGLEVEL) { fprintferr("N = %ld, R1 = %ld, R2 = %ld, RU = %ld\n",N,R1,R2,RU); fprintferr("D = %Z\n",D); } av0 = avma; matcopy = NULL; powsubfactorbase = NULL;INCREASEGEN: if (first) first = 0; else { desallocate(matcopy); avma = av0; } sfb_trials = sfb_increase = 0; cbach = check_bach(cbach,12.); nreldep = nrelsup = 0; LIMC = cbach*LOGD2; if (LIMC < 20.) LIMC = 20.; LIMC2=max(3. * N, max(cbach,cbach2)*LOGD2); if (LIMC2 < LIMC) LIMC2=LIMC; if (DEBUGLEVEL) { fprintferr("LIMC = %.1f, LIMC2 = %.1f\n",LIMC,LIMC2); } /* initialize factorbase, subfactorbase, vperm */ lfun = factorbasegen(nf,(long)LIMC2,(long)LIMC); if (!lfun) goto INCREASEGEN; vperm = cgetg(KC+1,t_VECSMALL); ss = subfactorbasegen(N,(long)min(lim,LIMC2), minsfb, vperm); if (ss == -1) goto INCREASEGEN; lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; PRECREGINT = DEFAULTPREC + ((expi(D)*(lgsub-2)+((N*N)>>2))>>TWOPOTBITS_IN_LONG); PRECREG = max(prec+1,PRECREGINT); KCCO = KC+RU-1 + max(ss,RELSUP); if (DEBUGLEVEL) { fprintferr("nbrelsup = %ld, ss = %ld, ",RELSUP,ss); fprintferr("KCZ = %ld, KC = %ld, KCCO = %ld \n",KCZ,KC,KCCO); flusherr(); } mat=(long**)gpmalloc(sizeof(long*)*(KCCO+1)); setlg(mat, KCCO+1); C = cgetg(KCCO+1,t_MAT); cmptglob=0; /* trivial relations */ for (i=1; i<=KCZ; i++) { GEN P = idealbase[i]; if (isclone(P)) { /* all prime divisors in factorbase */ unsetisclone(P); cmptglob++; mat[cmptglob] = p1 = col_0(KC); C[cmptglob] = (long)(p2 = cgetg(RU+1,t_COL)); k = numideal[factorbase[i]]; p1[0] = k+1; p1 += k; /* for already_found_relation */ k = lg(P); for (j=1; j<k; j++) p1[j] = itos(gmael(P,j,3)); for (j=1; j<=RU; j++) p2[j] = zero; } } /* initialize for other relations */ for (i=cmptglob+1; i<=KCCO; i++) { mat[i] = col_0(KC); C[i] = (long) (p1 = cgetg(RU+1,t_COL)); for (j=1; j<=RU; j++) { p2=cgetg(3,t_COMPLEX); p2[1]=lgetr(PRECREG); p2[2]=lgetr(PRECREG); p1[j]=(long)p2; } } av1 = avma; liste = new_chunk(KC+1); for (i=1; i<=KC; i++) liste[i]=0; invp = cmptglob? relationrank(mat,KC,cmptglob,liste): idmat(KC); /* relations through elements of small norm */ cmptglob = small_norm_for_buchall(cmptglob,mat,C,KCCO,(long)LIMC, PRECREG,nf,gborne,nbrelpid,invp,liste); if (cmptglob < 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (small_norm)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } avma = av1; limpile=stack_lim(av1,1); slim = KCCO; phase = 0; nlze = matcopymax = 0; /* for lint */ lmatt2 = NULL; /* random relations */ if (cmptglob == KCCO) /* enough relations, initialize nevertheless */ ((void(*)(long))random_relation)(-1); else { GEN maarch; long **ma; if (DEBUGLEVEL) { fprintferr("\n#### Looking for random relations\n"); flusherr(); } LABELINT: if (sfb_increase) { /* increase subfactorbase */ sfb_increase = 0; if (++sfb_trials > SFB_MAX || subfactorbasegen(N,(long)min(lim,LIMC2), lgsub-1+SFB_STEP, vperm) < 0) goto INCREASEGEN; if (DEBUGLEVEL) fprintferr("*** Increasing subfactorbase\n"); if (powsubfactorbase) { /* desallocate using _old_ lgsub value */ for (i=lgsub-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; nreldep = nrelsup = 0; } if (phase == 0) { ma = mat; maarch = C; } else /* reduced the relation matrix at least once */ { extrarel = nlze; if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; slim = cmptglob+extrarel; setlg(extraC,extrarel+1); setlg(extramat,extrarel+1); if (slim > matcopymax) { matcopy = (long**)gprealloc(matcopy, (2*slim+1) * sizeof(long*), (matcopymax+1) * sizeof(long*)); matcopymax = 2 * slim; } setlg(matcopy,slim+1); if (DEBUGLEVEL) fprintferr("\n(need %ld more relation%s)\n", extrarel, (extrarel==1)?"":"s"); for (j=cmptglob+1; j<=slim; j++) matcopy[j] = col_0(KC); maarch = extraC - cmptglob; /* start at 0, the others at cmptglob */ ma = matcopy; } if (!lmatt2) { lmatt2 = compute_matt2(RU,nf); av1 = avma; } if (!powsubfactorbase) { powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); av1 = avma; } ss = random_relation(phase,cmptglob,slim,(long)LIMC,N,RU,PRECREG, PRECREGINT,nf,vperm,subvperm,ma,maarch,lmatt2,ex); if (ss < 0) /* could not find relations */ { if (phase == 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); } if (ss != -1) { /* precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (random_relation)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; } goto INCREASEGEN; } if (phase) for (j=1; j<=extrarel; j++) { long *c = matcopy[cmptglob+j]; GEN *g = (GEN*) extramat[j]; for (k=1; k<=KC; k++) g[k] = stoi(c[vperm[k]]); } cmptglob = ss; } /* reduce relation matrices */ if (phase == 0) /* never reduced before */ { matcopymax = 10*KCCO + MAXRELSUP; matcopy = (long**)gpmalloc(sizeof(long*)*(matcopymax + 1)); setlg(matcopy, KCCO+1); for (j=1; j<=KCCO; j++) matcopy[j] = col_dup(KC,mat[j]); W = hnfspec(mat,vperm,&pdep,&B,&C,lgsub-1); for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); KCCOPRO = KCCO; phase = 1; /* keep some room for the extra relation. We will update matrix size when * extrarel goes down */ nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; extrarel = nlze; /* in case the regulator is 0 */ if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; extramat =cgetg(extrarel+1,t_MAT); extraC=cgetg(extrarel+1,t_MAT); for (j=1; j<=extrarel; j++) { extramat[j]=lgetg(KC+1,t_COL); extraC[j]=lgetg(RU+1,t_COL); for (i=1; i<=RU; i++) { p1 = cgetg(3,t_COMPLEX); mael(extraC,j,i)=(long)p1; p1[1]=lgetr(PRECREG); p1[2]=lgetr(PRECREG); } } } else { if (low_stack(limpile, stack_lim(av1,1))) { GEN *gptr[6]; if(DEBUGMEM>1) err(warnmem,"buchall"); gptr[0]=&W; gptr[1]=&C; gptr[2]=&B; gptr[3]=&pdep; gptr[4]=&extramat; gptr[5]=&extraC; gerepilemany(av1,gptr,6); } W = hnfadd(W,vperm,&pdep,&B,&C, extramat,extraC); nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; KCCOPRO += extrarel; if (nlze && ++nreldep > MAXRELSUP) { sfb_increase=1; goto LABELINT; } } if (nlze) goto LABELINT; /* dependent rows */ /* first attempt at regulator for the check */ sreg = KCCOPRO - (lg(B)-1) - (lg(W)-1); /* = zc (cf hnffinal) */ xarch = cgetg(sreg+1,t_MAT); /* cols corresponding to units */ for (j=1; j<=sreg; j++) xarch[j] = C[j]; reg = compute_multiple_of_R(xarch,RU,N,PRECREG,&sublambda); if (!reg) { /* not full rank for units */ if (DEBUGLEVEL) fprintferr("regulator is zero.\n"); if (++nrelsup > MAXRELSUP) goto INCREASEGEN; nlze=MIN_EXTRA; goto LABELINT; } if (!sublambda) { /* anticipate precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (bestappr)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } /* class number */ if (DEBUGLEVEL) fprintferr("\n"); clh = compute_class_number(W,&met,&u1,&u2); /* check */ z = mulrr(lfun,gmul(gmul2n(gpuigs(shiftr(mppi(DEFAULTPREC),1),-R2),-R1), gsqrt(absi(D),DEFAULTPREC))); z = mulri(z,(GEN)zu[1]); /* z = Res (zeta_K, s = 1) * w D^(1/2) / [ 2^r1 (2pi)^r2 ] = h R */ p1 = gmul2n(divir(clh,z), 1); c1 = compute_check(sublambda,p1,&parch,&reg); /* c1 should be close to 2, and not much smaller */ if (c1 && gcmpgs(gmul2n(c1,1),3) < 0) { c1=NULL; nrelsup=MAXRELSUP; } if (!c1 || gcmpgs(c1,3) > 0) { if (++nrelsup <= MAXRELSUP) { if (DEBUGLEVEL) { if (c1) fprintferr("\n ***** check = %f\n\n",gtodouble(c1)/2); else fprintferr("\n ***** check = NULL\n\n"); flusherr(); } nlze=MIN_EXTRA; goto LABELINT; } if (!c1 || cbach<11.99) { sfb_increase=1; goto LABELINT; } err(warner,"suspicious check. Suggest increasing extra relations."); } /* Phase "be honest" */ if (KCZ2 > KCZ) { if (!powsubfactorbase) powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); if (!be_honest(nf,RU,PRECREGINT)) goto INCREASEGEN; } /* regulator, roots of unity, fundamental units */ if (flun < 0 || flun > 1) { xarch = cleancol(gmul(xarch,parch),N,PRECREG); if (DEBUGLEVEL) msgtimer("cleancol"); } if (labs(flun) > 1) { fu = getfu(nf,&xarch,reg,flun,&k,PRECREG); if (k) fu = gmul((GEN)nf[7],fu); else if (labs(flun) > 2) { prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (getfu)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } } /* class group generators */ if (DEBUGLEVEL) fprintferr("\n"); class_group_gen(nf,met,clh,u1,u2,vperm, &clg1, &clg2, PRECREGINT); /* cleanup */ desallocate(matcopy); i = lg(C)-sreg; C += sreg; C[0] = evaltyp(t_MAT)|evallg(i); C = cleancol(C,N,PRECREG); settyp(vperm, t_COL); for (i=1; i<=KC; i++) vperm[i]=lstoi(vperm[i]); c1 = gdiv(gmul(reg,clh),z); return gerepileupto(av, buchall_end(nf,CHANGE,flun,k,fu,clg1,clg2,reg,c1,zu,W,B,xarch,C,vectbase,vperm));}
subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i];
buchall(GEN P,GEN gcbach,GEN gcbach2,GEN gRELSUP,GEN gborne,long nbrelpid, long minsfb,long flun,long prec){ long av = avma,av0,av1,limpile,i,j,k,ss,cmptglob,lgsub; long N,R1,R2,RU,PRECREG,PRECREGINT,KCCO,KCCOPRO,RELSUP; long extrarel,nlze,sreg,nrelsup,nreldep,phase,slim,matcopymax; long first = 1, sfb_increase = 0, sfb_trials = 0; long **mat,**matcopy,*vperm,*subvperm,*ex; double cbach,cbach2,drc,LOGD2,lim,LIMC,LIMC2; GEN p1,p2,lmatt2,fu,zu,nf,D,xarch,met,W,reg,lfun,z,clh; GEN B,C,u1,u2,c1,sublambda,pdep,parch,liste,invp,clg1,clg2; GEN CHANGE=NULL, extramat=NULL, extraC=NULL; if (DEBUGLEVEL) timer2(); if (typ(P)==t_POL) nf = NULL; else { nf=checknf(P); P=(GEN)nf[1]; } if (typ(gRELSUP)!=t_INT) gRELSUP=gtrunc(gRELSUP); RELSUP = itos(gRELSUP); if (RELSUP<=0) err(talker,"not enough relations in bnfxxx"); /* Initializations */ N=lgef(P)-3; if (!nf) { nf=initalgall0(P, flun>=0? nf_REGULAR: nf_DIFFERENT, max(BIGDEFAULTPREC,prec)); if (lg(nf)==3) /* P was a non-monic polynomial, nfinit changed it */ { CHANGE=(GEN)nf[2]; nf=(GEN)nf[1]; } if (DEBUGLEVEL) msgtimer("initalg"); } if (N<=1) return buchall_for_degree_one_pol(nf,CHANGE,flun); zu=rootsof1(nf); zu[2] = lmul((GEN)nf[7],(GEN)zu[2]); if (DEBUGLEVEL) msgtimer("rootsof1"); R1=itos(gmael(nf,2,1)); R2=(N-R1)>>1; RU=R1+R2; D=(GEN)nf[3]; drc=fabs(gtodouble(D)); LOGD2=log(drc); LOGD2 = LOGD2*LOGD2; lim = exp(-(double)N) * sqrt(2*PI*N*drc) * pow(4/PI,(double)R2); if (lim < 3.) lim = 3.; cbach = min(12., gtodouble(gcbach)); cbach /= 2; cbach2 = gtodouble(gcbach2); if (DEBUGLEVEL) { fprintferr("N = %ld, R1 = %ld, R2 = %ld, RU = %ld\n",N,R1,R2,RU); fprintferr("D = %Z\n",D); } av0 = avma; matcopy = NULL; powsubfactorbase = NULL;INCREASEGEN: if (first) first = 0; else { desallocate(matcopy); avma = av0; } sfb_trials = sfb_increase = 0; cbach = check_bach(cbach,12.); nreldep = nrelsup = 0; LIMC = cbach*LOGD2; if (LIMC < 20.) LIMC = 20.; LIMC2=max(3. * N, max(cbach,cbach2)*LOGD2); if (LIMC2 < LIMC) LIMC2=LIMC; if (DEBUGLEVEL) { fprintferr("LIMC = %.1f, LIMC2 = %.1f\n",LIMC,LIMC2); } /* initialize factorbase, subfactorbase, vperm */ lfun = factorbasegen(nf,(long)LIMC2,(long)LIMC); if (!lfun) goto INCREASEGEN; vperm = cgetg(KC+1,t_VECSMALL); ss = subfactorbasegen(N,(long)min(lim,LIMC2), minsfb, vperm); if (ss == -1) goto INCREASEGEN; lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; PRECREGINT = DEFAULTPREC + ((expi(D)*(lgsub-2)+((N*N)>>2))>>TWOPOTBITS_IN_LONG); PRECREG = max(prec+1,PRECREGINT); KCCO = KC+RU-1 + max(ss,RELSUP); if (DEBUGLEVEL) { fprintferr("nbrelsup = %ld, ss = %ld, ",RELSUP,ss); fprintferr("KCZ = %ld, KC = %ld, KCCO = %ld \n",KCZ,KC,KCCO); flusherr(); } mat=(long**)gpmalloc(sizeof(long*)*(KCCO+1)); setlg(mat, KCCO+1); C = cgetg(KCCO+1,t_MAT); cmptglob=0; /* trivial relations */ for (i=1; i<=KCZ; i++) { GEN P = idealbase[i]; if (isclone(P)) { /* all prime divisors in factorbase */ unsetisclone(P); cmptglob++; mat[cmptglob] = p1 = col_0(KC); C[cmptglob] = (long)(p2 = cgetg(RU+1,t_COL)); k = numideal[factorbase[i]]; p1[0] = k+1; p1 += k; /* for already_found_relation */ k = lg(P); for (j=1; j<k; j++) p1[j] = itos(gmael(P,j,3)); for (j=1; j<=RU; j++) p2[j] = zero; } } /* initialize for other relations */ for (i=cmptglob+1; i<=KCCO; i++) { mat[i] = col_0(KC); C[i] = (long) (p1 = cgetg(RU+1,t_COL)); for (j=1; j<=RU; j++) { p2=cgetg(3,t_COMPLEX); p2[1]=lgetr(PRECREG); p2[2]=lgetr(PRECREG); p1[j]=(long)p2; } } av1 = avma; liste = new_chunk(KC+1); for (i=1; i<=KC; i++) liste[i]=0; invp = cmptglob? relationrank(mat,KC,cmptglob,liste): idmat(KC); /* relations through elements of small norm */ cmptglob = small_norm_for_buchall(cmptglob,mat,C,KCCO,(long)LIMC, PRECREG,nf,gborne,nbrelpid,invp,liste); if (cmptglob < 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (small_norm)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } avma = av1; limpile=stack_lim(av1,1); slim = KCCO; phase = 0; nlze = matcopymax = 0; /* for lint */ lmatt2 = NULL; /* random relations */ if (cmptglob == KCCO) /* enough relations, initialize nevertheless */ ((void(*)(long))random_relation)(-1); else { GEN maarch; long **ma; if (DEBUGLEVEL) { fprintferr("\n#### Looking for random relations\n"); flusherr(); } LABELINT: if (sfb_increase) { /* increase subfactorbase */ sfb_increase = 0; if (++sfb_trials > SFB_MAX || subfactorbasegen(N,(long)min(lim,LIMC2), lgsub-1+SFB_STEP, vperm) < 0) goto INCREASEGEN; if (DEBUGLEVEL) fprintferr("*** Increasing subfactorbase\n"); if (powsubfactorbase) { /* desallocate using _old_ lgsub value */ for (i=lgsub-1; i; i--) free(powsubfactorbase[i]); free(powsubfactorbase); powsubfactorbase = NULL; } lgsub = lg(subfactorbase); subvperm = new_chunk(lgsub); ex = new_chunk(lgsub); for (i=1; i<lgsub; i++) subvperm[i]=vperm[i]; nreldep = nrelsup = 0; } if (phase == 0) { ma = mat; maarch = C; } else /* reduced the relation matrix at least once */ { extrarel = nlze; if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; slim = cmptglob+extrarel; setlg(extraC,extrarel+1); setlg(extramat,extrarel+1); if (slim > matcopymax) { matcopy = (long**)gprealloc(matcopy, (2*slim+1) * sizeof(long*), (matcopymax+1) * sizeof(long*)); matcopymax = 2 * slim; } setlg(matcopy,slim+1); if (DEBUGLEVEL) fprintferr("\n(need %ld more relation%s)\n", extrarel, (extrarel==1)?"":"s"); for (j=cmptglob+1; j<=slim; j++) matcopy[j] = col_0(KC); maarch = extraC - cmptglob; /* start at 0, the others at cmptglob */ ma = matcopy; } if (!lmatt2) { lmatt2 = compute_matt2(RU,nf); av1 = avma; } if (!powsubfactorbase) { powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); av1 = avma; } ss = random_relation(phase,cmptglob,slim,(long)LIMC,N,RU,PRECREG, PRECREGINT,nf,vperm,subvperm,ma,maarch,lmatt2,ex); if (ss < 0) /* could not find relations */ { if (phase == 0) { for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); } if (ss != -1) { /* precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (random_relation)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; } goto INCREASEGEN; } if (phase) for (j=1; j<=extrarel; j++) { long *c = matcopy[cmptglob+j]; GEN *g = (GEN*) extramat[j]; for (k=1; k<=KC; k++) g[k] = stoi(c[vperm[k]]); } cmptglob = ss; } /* reduce relation matrices */ if (phase == 0) /* never reduced before */ { matcopymax = 10*KCCO + MAXRELSUP; matcopy = (long**)gpmalloc(sizeof(long*)*(matcopymax + 1)); setlg(matcopy, KCCO+1); for (j=1; j<=KCCO; j++) matcopy[j] = col_dup(KC,mat[j]); W = hnfspec(mat,vperm,&pdep,&B,&C,lgsub-1); for (j=1; j<=KCCO; j++) free(mat[j]); free(mat); KCCOPRO = KCCO; phase = 1; /* keep some room for the extra relation. We will update matrix size when * extrarel goes down */ nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; extrarel = nlze; /* in case the regulator is 0 */ if (extrarel < MIN_EXTRA) extrarel = MIN_EXTRA; extramat =cgetg(extrarel+1,t_MAT); extraC=cgetg(extrarel+1,t_MAT); for (j=1; j<=extrarel; j++) { extramat[j]=lgetg(KC+1,t_COL); extraC[j]=lgetg(RU+1,t_COL); for (i=1; i<=RU; i++) { p1 = cgetg(3,t_COMPLEX); mael(extraC,j,i)=(long)p1; p1[1]=lgetr(PRECREG); p1[2]=lgetr(PRECREG); } } } else { if (low_stack(limpile, stack_lim(av1,1))) { GEN *gptr[6]; if(DEBUGMEM>1) err(warnmem,"buchall"); gptr[0]=&W; gptr[1]=&C; gptr[2]=&B; gptr[3]=&pdep; gptr[4]=&extramat; gptr[5]=&extraC; gerepilemany(av1,gptr,6); } W = hnfadd(W,vperm,&pdep,&B,&C, extramat,extraC); nlze = lg(pdep)>1? lg(pdep[1])-1: lg(B[1])-1; KCCOPRO += extrarel; if (nlze && ++nreldep > MAXRELSUP) { sfb_increase=1; goto LABELINT; } } if (nlze) goto LABELINT; /* dependent rows */ /* first attempt at regulator for the check */ sreg = KCCOPRO - (lg(B)-1) - (lg(W)-1); /* = zc (cf hnffinal) */ xarch = cgetg(sreg+1,t_MAT); /* cols corresponding to units */ for (j=1; j<=sreg; j++) xarch[j] = C[j]; reg = compute_multiple_of_R(xarch,RU,N,PRECREG,&sublambda); if (!reg) { /* not full rank for units */ if (DEBUGLEVEL) fprintferr("regulator is zero.\n"); if (++nrelsup > MAXRELSUP) goto INCREASEGEN; nlze=MIN_EXTRA; goto LABELINT; } if (!sublambda) { /* anticipate precision problems */ prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (bestappr)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } /* class number */ if (DEBUGLEVEL) fprintferr("\n"); clh = compute_class_number(W,&met,&u1,&u2); /* check */ z = mulrr(lfun,gmul(gmul2n(gpuigs(shiftr(mppi(DEFAULTPREC),1),-R2),-R1), gsqrt(absi(D),DEFAULTPREC))); z = mulri(z,(GEN)zu[1]); /* z = Res (zeta_K, s = 1) * w D^(1/2) / [ 2^r1 (2pi)^r2 ] = h R */ p1 = gmul2n(divir(clh,z), 1); c1 = compute_check(sublambda,p1,&parch,&reg); /* c1 should be close to 2, and not much smaller */ if (c1 && gcmpgs(gmul2n(c1,1),3) < 0) { c1=NULL; nrelsup=MAXRELSUP; } if (!c1 || gcmpgs(c1,3) > 0) { if (++nrelsup <= MAXRELSUP) { if (DEBUGLEVEL) { if (c1) fprintferr("\n ***** check = %f\n\n",gtodouble(c1)/2); else fprintferr("\n ***** check = NULL\n\n"); flusherr(); } nlze=MIN_EXTRA; goto LABELINT; } if (!c1 || cbach<11.99) { sfb_increase=1; goto LABELINT; } err(warner,"suspicious check. Suggest increasing extra relations."); } /* Phase "be honest" */ if (KCZ2 > KCZ) { if (!powsubfactorbase) powsubfactgen(nf,CBUCHG+1,PRECREG,PRECREGINT); if (!be_honest(nf,RU,PRECREGINT)) goto INCREASEGEN; } /* regulator, roots of unity, fundamental units */ if (flun < 0 || flun > 1) { xarch = cleancol(gmul(xarch,parch),N,PRECREG); if (DEBUGLEVEL) msgtimer("cleancol"); } if (labs(flun) > 1) { fu = getfu(nf,&xarch,reg,flun,&k,PRECREG); if (k) fu = gmul((GEN)nf[7],fu); else if (labs(flun) > 2) { prec=(PRECREG<<1)-2; if (DEBUGLEVEL) err(warnprec,"buchall (getfu)",prec); avma = av0; nf = nfnewprec(nf,prec); av0 = avma; cbach /= 2; goto INCREASEGEN; } } /* class group generators */ if (DEBUGLEVEL) fprintferr("\n"); class_group_gen(nf,met,clh,u1,u2,vperm, &clg1, &clg2, PRECREGINT); /* cleanup */ desallocate(matcopy); i = lg(C)-sreg; C += sreg; C[0] = evaltyp(t_MAT)|evallg(i); C = cleancol(C,N,PRECREG); settyp(vperm, t_COL); for (i=1; i<=KC; i++) vperm[i]=lstoi(vperm[i]); c1 = gdiv(gmul(reg,clh),z); return gerepileupto(av, buchall_end(nf,CHANGE,flun,k,fu,clg1,clg2,reg,c1,zu,W,B,xarch,C,vectbase,vperm));}
long av,tetpil,l;
long av,l;
factcp(GEN p, GEN f, GEN beta, GEN pp, GEN ns){ long av,tetpil,l; GEN chi,nu, b = cgetg(4,t_VEC); chi=mycaract(f,beta,p,pp,ns); av=avma; nu=(GEN)factmod(chi,p)[1]; l=lg(nu)-1; nu=lift_intern((GEN)nu[1]); tetpil=avma; b[1]=(long)chi; b[2]=lpile(av,tetpil,gcopy(nu)); b[3]=lstoi(l); return b;}
nu=lift_intern((GEN)nu[1]); tetpil=avma;
nu=lift_intern((GEN)nu[1]);
factcp(GEN p, GEN f, GEN beta, GEN pp, GEN ns){ long av,tetpil,l; GEN chi,nu, b = cgetg(4,t_VEC); chi=mycaract(f,beta,p,pp,ns); av=avma; nu=(GEN)factmod(chi,p)[1]; l=lg(nu)-1; nu=lift_intern((GEN)nu[1]); tetpil=avma; b[1]=(long)chi; b[2]=lpile(av,tetpil,gcopy(nu)); b[3]=lstoi(l); return b;}
b[2]=lpile(av,tetpil,gcopy(nu));
b[2]=lpilecopy(av,nu);
factcp(GEN p, GEN f, GEN beta, GEN pp, GEN ns){ long av,tetpil,l; GEN chi,nu, b = cgetg(4,t_VEC); chi=mycaract(f,beta,p,pp,ns); av=avma; nu=(GEN)factmod(chi,p)[1]; l=lg(nu)-1; nu=lift_intern((GEN)nu[1]); tetpil=avma; b[1]=(long)chi; b[2]=lpile(av,tetpil,gcopy(nu)); b[3]=lstoi(l); return b;}
long i, j, m, n, s;
long i, j, m, n;
matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch){ GEN y, z, p1; long i, j, m, n, s; long c1[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; long c2[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; s=signe(ncol); if (ep1 == ep2 && ep1) err(talker, "identical index variables in matrix"); if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1); push_val(ep1, c1); push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++) { c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++) { c1[2] = j; p1 = lisseq_nobreak(ch); z[j] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } } pop_val(ep2); pop_val(ep1); return y;}
s=signe(ncol);
if (typ(ncol) != t_INT || typ(nlig) != t_INT) err(typeer,"matrix");
matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch){ GEN y, z, p1; long i, j, m, n, s; long c1[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; long c2[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; s=signe(ncol); if (ep1 == ep2 && ep1) err(talker, "identical index variables in matrix"); if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1); push_val(ep1, c1); push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++) { c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++) { c1[2] = j; p1 = lisseq_nobreak(ch); z[j] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } } pop_val(ep2); pop_val(ep1); return y;}
if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1);
m = itos(ncol); n = itos(nlig); if (m < 0) err(talker,"negative number of columns in matrix"); if (n < 0) err(talker,"negative number of rows in matrix"); if (!m) return cgetg(1,t_MAT); if (!n) return zeromat(0, m); if (!ep1 || !ep2 || !ch) return zeromat(n, m);
matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch){ GEN y, z, p1; long i, j, m, n, s; long c1[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; long c2[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; s=signe(ncol); if (ep1 == ep2 && ep1) err(talker, "identical index variables in matrix"); if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1); push_val(ep1, c1); push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++) { c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++) { c1[2] = j; p1 = lisseq_nobreak(ch); z[j] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } } pop_val(ep2); pop_val(ep1); return y;}
push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++)
push_val(ep2, c2); y = cgetg(m+1,t_MAT); for (i=1; i<=m; i++)
matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch){ GEN y, z, p1; long i, j, m, n, s; long c1[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; long c2[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; s=signe(ncol); if (ep1 == ep2 && ep1) err(talker, "identical index variables in matrix"); if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1); push_val(ep1, c1); push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++) { c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++) { c1[2] = j; p1 = lisseq_nobreak(ch); z[j] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } } pop_val(ep2); pop_val(ep1); return y;}
c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++)
c2[2] = i; z = cgetg(n+1,t_COL); y[i] = (long)z; for (j=1; j<=n; j++)
matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch){ GEN y, z, p1; long i, j, m, n, s; long c1[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; long c2[]={evaltyp(t_INT)|_evallg(3), evalsigne(1)|evallgefint(3), 1}; s=signe(ncol); if (ep1 == ep2 && ep1) err(talker, "identical index variables in matrix"); if (typ(ncol)!=t_INT || s<0) err(talker,"bad number of columns in matrix"); if (!s) return cgetg(1,t_MAT); s=signe(nlig); if (typ(nlig)!=t_INT || s<0) err(talker,"bad number of rows in matrix"); m = itos(ncol)+1; n = itos(nlig)+1; if (!s) return zeromat(1, m-1); if (!ep1 || !ep2 || !ch) return zeromat(n-1, m-1); push_val(ep1, c1); push_val(ep2, c2); y = cgetg(m,t_MAT); for (i=1; i<m; i++) { c2[2] = i; z = cgetg(n,t_COL); y[i] = (long)z; for (j=1; j<n; j++) { c1[2] = j; p1 = lisseq_nobreak(ch); z[j] = isonstack(p1)? (long)p1 : (long)forcecopy(p1); } } pop_val(ep2); pop_val(ep1); return y;}
if (lg(a1) != 2 || !insinC(a2)) err(talker,"incorrect a or b in intnum");
if (lg(a1) != 2 || !isinC(a2)) err(talker,"incorrect a or b in intnum");
transcode(GEN a, long warn){ GEN a1, a2; long la; if (typ(a) != t_VEC) return f_REG; la = lg(a); if (la == 1 || la > 3) err(talker,"incorrect a or b in intnum"); if (la == 2) return gsigne((GEN)a[1]) > 0 ? f_YSLOW : -f_YSLOW; a1 = (GEN)a[1]; a2 = (GEN)a[2]; if (typ(a1) != t_VEC) { if (!isinC(a1) || !isinR(a2) || gcmpgs(a2, -1) <= 0) err(talker,"incorrect a or b in intnum"); return gsigne(a2) < 0 ? f_SING : f_REG; } if (lg(a1) != 2 || !insinC(a2)) err(talker,"incorrect a or b in intnum"); return gsigne((GEN)a1[1]) * code_aux(a2, warn);}
int lfaq, p, e, j;
long lfaq, p, e, j;
calcjac(Cache **pC, GEN globfa, GEN *ptabfaq, GEN *ptabj){ GEN J, tabf, tabg, faq, tabfaq, tabj, P, E, PE; int lfaq, p, e, j; ulong i, q, l; pari_sp av; l = lg(globfa); *ptabfaq = tabfaq= cgetg(l,t_VEC); *ptabj = tabj = cgetg(l,t_VEC); for (i=1; i<l; i++) { q = globfa[i]; /* odd prime */ faq = factoru(q-1); gel(tabfaq,i) = faq; P = gel(faq,1); lfaq = lg(P); E = gel(faq,2); PE= gel(faq,3); av = avma; compute_fg(q, 1, &tabf, &tabg); J = cgetg(lfaq,t_VEC); J[1] = lgetg(1,t_STR); /* dummy */ for (j=2; j<lfaq; j++) /* skip p = P[1] = 2 */ { long pe = PE[j]; p = P[j]; e = E[j]; gel(J,j) = get_jac(pC[pe], q, pe, tabf, tabg); } gel(tabj,i) = gerepilecopy(av, J); }}
faq = factoru(q-1); gel(tabfaq,i) = faq;
faq = factoru_pow(q-1); gel(tabfaq,i) = faq;
calcjac(Cache **pC, GEN globfa, GEN *ptabfaq, GEN *ptabj){ GEN J, tabf, tabg, faq, tabfaq, tabj, P, E, PE; int lfaq, p, e, j; ulong i, q, l; pari_sp av; l = lg(globfa); *ptabfaq = tabfaq= cgetg(l,t_VEC); *ptabj = tabj = cgetg(l,t_VEC); for (i=1; i<l; i++) { q = globfa[i]; /* odd prime */ faq = factoru(q-1); gel(tabfaq,i) = faq; P = gel(faq,1); lfaq = lg(P); E = gel(faq,2); PE= gel(faq,3); av = avma; compute_fg(q, 1, &tabf, &tabg); J = cgetg(lfaq,t_VEC); J[1] = lgetg(1,t_STR); /* dummy */ for (j=2; j<lfaq; j++) /* skip p = P[1] = 2 */ { long pe = PE[j]; p = P[j]; e = E[j]; gel(J,j) = get_jac(pC[pe], q, pe, tabf, tabg); } gel(tabj,i) = gerepilecopy(av, J); }}
_Workspace_Free( the_mq->Object.name );
int mq_unlink( const char *name){ int status; register POSIX_Message_queue_Control *the_mq; Objects_Id the_mq_id; _Thread_Disable_dispatch(); status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); if ( status != 0 ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( status ); } /* * Don't support unlinking a remote message queue. */ if ( !_Objects_Is_local_id(the_mq_id) ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( ENOSYS ); } the_mq = (POSIX_Message_queue_Control *) _Objects_Get_local_object( &_POSIX_Message_queue_Information, _Objects_Get_index( the_mq_id ) ); #if 0 && defined(RTEMS_MULTIPROCESSING) if ( the_mq->process_shared == PTHREAD_PROCESS_SHARED ) { _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq_id ); }#endif the_mq->linked = FALSE; _POSIX_Message_queue_Namespace_remove( the_mq ); _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); return 0;}
unsigned32 bsp_get_CPU_clock_speed(void)
uint32_t bsp_get_CPU_clock_speed(void)
unsigned32 bsp_get_CPU_clock_speed(void){ extern char _CPUClockSpeed[]; return( (unsigned32)_CPUClockSpeed);}
return( (unsigned32)_CPUClockSpeed);
return( (uint32_t)_CPUClockSpeed);
unsigned32 bsp_get_CPU_clock_speed(void){ extern char _CPUClockSpeed[]; return( (unsigned32)_CPUClockSpeed);}
GEN *gptr[2]; int n = 1; gptr[0]=&e2; if (e1) gptr[n++]=&e1;
GEN *gptr[2]; gptr[0]=&e2; gptr[1]=&e1;
expr(void){ PFGEN f[] = { NULL,NULL,NULL,NULL }; GEN aux,e,e1,e2,e3; long av = avma, lim = stack_lim(av,2); e1 = e2 = e3 = UNDEF;L3: aux = facteur(); if (br_status) return NULL; e3 = f[3]? f[3](e3,aux): aux; switch(*analyseur) { case '*': analyseur++; f[3] = (PFGEN)&gmul; goto L3; case '/': analyseur++; f[3] = (PFGEN)&gdiv; goto L3; case '%': analyseur++; f[3] = (PFGEN)&gmod; goto L3; case '\\': if (*++analyseur == '/') { analyseur++; f[3]=(PFGEN)&gdivround; goto L3; } f[3] = (PFGEN)&gdivent; goto L3; case '<': case '>': if (analyseur[1] == *analyseur) { f[3] = (*analyseur == '<')? (PFGEN)&gshift_l : (PFGEN)&gshift_r; analyseur += 2; goto L3; } } f[3] = NULL;L2: if (e3 == UNDEF) goto L3; e2 = f[2]? f[2](e2,e3): e3; e3 = UNDEF; if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[2]; int n = 1; gptr[0]=&e2; if (e1) gptr[n++]=&e1; if(DEBUGMEM>1) err(warnmem,"expr"); gerepilemany(av,gptr,n); } switch(*analyseur) { case '+': analyseur++; f[2]=(PFGEN)&gadd; goto L3; case '-': analyseur++; f[2]=(PFGEN)&gsub; goto L3; } f[2] = NULL;L1: if (e2 == UNDEF) goto L2; e1 = f[1]? f[1](e1,e2): e2; e2 = UNDEF; switch(*analyseur) { case '<': switch(*++analyseur) { case '=': analyseur++; f[1]=(PFGEN)&gle; goto L2; case '>': analyseur++; f[1]=(PFGEN)&gne; goto L2; } f[1]=(PFGEN)&glt; goto L2; case '>': if (*++analyseur == '=') { analyseur++; f[1]=(PFGEN)&gge; goto L2; } f[1]=(PFGEN)&ggt; goto L2; case '=': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)&geq; goto L2; } goto L1; case '!': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)&gne; goto L2; } goto L1; } f[1] = NULL;/* L0: */ if (e1 == UNDEF) goto L1; e = f[0]? (gcmp0(e1)? gzero: gun): e1; e1 = UNDEF; switch(*analyseur) { case '&': if (*++analyseur == '&') analyseur++; if (gcmp0(e)) { skipexpr(); return gzero; } f[0]=(PFGEN)1L; goto L1; case '|': if (*++analyseur == '|') analyseur++; if (!gcmp0(e)) { skipexpr(); return gun; } f[0]=(PFGEN)1L; goto L1; } return e;}
gerepilemany(av,gptr,n);
gerepilemany(av,gptr,(e1==UNDEF)?1: 2);
expr(void){ PFGEN f[] = { NULL,NULL,NULL,NULL }; GEN aux,e,e1,e2,e3; long av = avma, lim = stack_lim(av,2); e1 = e2 = e3 = UNDEF;L3: aux = facteur(); if (br_status) return NULL; e3 = f[3]? f[3](e3,aux): aux; switch(*analyseur) { case '*': analyseur++; f[3] = (PFGEN)&gmul; goto L3; case '/': analyseur++; f[3] = (PFGEN)&gdiv; goto L3; case '%': analyseur++; f[3] = (PFGEN)&gmod; goto L3; case '\\': if (*++analyseur == '/') { analyseur++; f[3]=(PFGEN)&gdivround; goto L3; } f[3] = (PFGEN)&gdivent; goto L3; case '<': case '>': if (analyseur[1] == *analyseur) { f[3] = (*analyseur == '<')? (PFGEN)&gshift_l : (PFGEN)&gshift_r; analyseur += 2; goto L3; } } f[3] = NULL;L2: if (e3 == UNDEF) goto L3; e2 = f[2]? f[2](e2,e3): e3; e3 = UNDEF; if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[2]; int n = 1; gptr[0]=&e2; if (e1) gptr[n++]=&e1; if(DEBUGMEM>1) err(warnmem,"expr"); gerepilemany(av,gptr,n); } switch(*analyseur) { case '+': analyseur++; f[2]=(PFGEN)&gadd; goto L3; case '-': analyseur++; f[2]=(PFGEN)&gsub; goto L3; } f[2] = NULL;L1: if (e2 == UNDEF) goto L2; e1 = f[1]? f[1](e1,e2): e2; e2 = UNDEF; switch(*analyseur) { case '<': switch(*++analyseur) { case '=': analyseur++; f[1]=(PFGEN)&gle; goto L2; case '>': analyseur++; f[1]=(PFGEN)&gne; goto L2; } f[1]=(PFGEN)&glt; goto L2; case '>': if (*++analyseur == '=') { analyseur++; f[1]=(PFGEN)&gge; goto L2; } f[1]=(PFGEN)&ggt; goto L2; case '=': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)&geq; goto L2; } goto L1; case '!': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)&gne; goto L2; } goto L1; } f[1] = NULL;/* L0: */ if (e1 == UNDEF) goto L1; e = f[0]? (gcmp0(e1)? gzero: gun): e1; e1 = UNDEF; switch(*analyseur) { case '&': if (*++analyseur == '&') analyseur++; if (gcmp0(e)) { skipexpr(); return gzero; } f[0]=(PFGEN)1L; goto L1; case '|': if (*++analyseur == '|') analyseur++; if (!gcmp0(e)) { skipexpr(); return gun; } f[0]=(PFGEN)1L; goto L1; } return e;}
do_agm(GEN *ptx1, GEN a1, GEN b1, long prec)
do_agm(GEN *ptx1, GEN a1, GEN b1)
do_agm(GEN *ptx1, GEN a1, GEN b1, long prec){ const long G = 6 - bit_accuracy(prec), s = signe(b1); GEN p1, r1, a, b, x, x1; x1 = gmul2n(gsub(a1,b1),-2); if (gcmp0(x1)) err(precer,"initell"); for(;;) { a = a1; b = b1; x = x1; b1 = sqrtr(gmul(a,b)); setsigne(b1, s); a1 = gmul2n(gadd(gadd(a,b), gmul2n(b1,1)),-2); r1 = gsub(a1,b1); p1 = sqrtr( gdiv(gadd(x,r1),x) ); x1 = gmul(x,gsqr(gmul2n(gaddsg(1,p1),-1))); if (gcmp0(r1) || gexpo(r1) <= G + gexpo(b1)) break; } *ptx1 = x1; return ginv(gmul2n(a1,2));}
const long G = 6 - bit_accuracy(prec), s = signe(b1);
const long s = signe(b1), l = min(lg(a1), lg(b1)), G = 6 - bit_accuracy(l);
do_agm(GEN *ptx1, GEN a1, GEN b1, long prec){ const long G = 6 - bit_accuracy(prec), s = signe(b1); GEN p1, r1, a, b, x, x1; x1 = gmul2n(gsub(a1,b1),-2); if (gcmp0(x1)) err(precer,"initell"); for(;;) { a = a1; b = b1; x = x1; b1 = sqrtr(gmul(a,b)); setsigne(b1, s); a1 = gmul2n(gadd(gadd(a,b), gmul2n(b1,1)),-2); r1 = gsub(a1,b1); p1 = sqrtr( gdiv(gadd(x,r1),x) ); x1 = gmul(x,gsqr(gmul2n(gaddsg(1,p1),-1))); if (gcmp0(r1) || gexpo(r1) <= G + gexpo(b1)) break; } *ptx1 = x1; return ginv(gmul2n(a1,2));}
x1 = gmul2n(gsub(a1,b1),-2);
x1 = gmul2n(subrr(a1,b1),-2);
do_agm(GEN *ptx1, GEN a1, GEN b1, long prec){ const long G = 6 - bit_accuracy(prec), s = signe(b1); GEN p1, r1, a, b, x, x1; x1 = gmul2n(gsub(a1,b1),-2); if (gcmp0(x1)) err(precer,"initell"); for(;;) { a = a1; b = b1; x = x1; b1 = sqrtr(gmul(a,b)); setsigne(b1, s); a1 = gmul2n(gadd(gadd(a,b), gmul2n(b1,1)),-2); r1 = gsub(a1,b1); p1 = sqrtr( gdiv(gadd(x,r1),x) ); x1 = gmul(x,gsqr(gmul2n(gaddsg(1,p1),-1))); if (gcmp0(r1) || gexpo(r1) <= G + gexpo(b1)) break; } *ptx1 = x1; return ginv(gmul2n(a1,2));}
b1 = sqrtr(gmul(a,b)); setsigne(b1, s); a1 = gmul2n(gadd(gadd(a,b), gmul2n(b1,1)),-2); r1 = gsub(a1,b1); p1 = sqrtr( gdiv(gadd(x,r1),x) ); x1 = gmul(x,gsqr(gmul2n(gaddsg(1,p1),-1))); if (gcmp0(r1) || gexpo(r1) <= G + gexpo(b1)) break;
b1 = sqrtr(mulrr(a,b)); setsigne(b1, s); a1 = gmul2n(addrr(addrr(a,b), gmul2n(b1,1)),-2); r1 = subrr(a1,b1); p1 = sqrtr( divrr(addrr(x,r1),x) ); x1 = mulrr(x, gsqr(gmul2n(addsr(1,p1),-1))); if (!signe(r1) || expo(r1) <= G + expo(b1)) break;
do_agm(GEN *ptx1, GEN a1, GEN b1, long prec){ const long G = 6 - bit_accuracy(prec), s = signe(b1); GEN p1, r1, a, b, x, x1; x1 = gmul2n(gsub(a1,b1),-2); if (gcmp0(x1)) err(precer,"initell"); for(;;) { a = a1; b = b1; x = x1; b1 = sqrtr(gmul(a,b)); setsigne(b1, s); a1 = gmul2n(gadd(gadd(a,b), gmul2n(b1,1)),-2); r1 = gsub(a1,b1); p1 = sqrtr( gdiv(gadd(x,r1),x) ); x1 = gmul(x,gsqr(gmul2n(gaddsg(1,p1),-1))); if (gcmp0(r1) || gexpo(r1) <= G + gexpo(b1)) break; } *ptx1 = x1; return ginv(gmul2n(a1,2));}
if ( status != 0 )
if ( status != 0 ) { _Thread_Enable_dispatch();
int mq_unlink( const char *name){ int status; register POSIX_Message_queue_Control *the_mq; Objects_Id the_mq_id; Objects_Locations location; status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); if ( status != 0 ) set_errno_and_return_minus_one( status ); the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); switch ( location ) { case OBJECTS_ERROR: set_errno_and_return_minus_one( EINVAL ); case OBJECTS_REMOTE: _Thread_Dispatch(); return POSIX_MP_NOT_IMPLEMENTED(); set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: #if defined(RTEMS_MULTIPROCESSING) _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id );#endif the_mq->linked = FALSE; _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); return 0; } return POSIX_BOTTOM_REACHED();}
the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); switch ( location ) { case OBJECTS_ERROR: set_errno_and_return_minus_one( EINVAL ); case OBJECTS_REMOTE: _Thread_Dispatch(); return POSIX_MP_NOT_IMPLEMENTED(); set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: #if defined(RTEMS_MULTIPROCESSING) _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id ); #endif the_mq->linked = FALSE; _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); return 0; } return POSIX_BOTTOM_REACHED();
the_mq->linked = FALSE; _POSIX_Message_queue_Namespace_remove( the_mq ); _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); return 0;
int mq_unlink( const char *name){ int status; register POSIX_Message_queue_Control *the_mq; Objects_Id the_mq_id; Objects_Locations location; status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); if ( status != 0 ) set_errno_and_return_minus_one( status ); the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); switch ( location ) { case OBJECTS_ERROR: set_errno_and_return_minus_one( EINVAL ); case OBJECTS_REMOTE: _Thread_Dispatch(); return POSIX_MP_NOT_IMPLEMENTED(); set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: #if defined(RTEMS_MULTIPROCESSING) _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id );#endif the_mq->linked = FALSE; _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); return 0; } return POSIX_BOTTOM_REACHED();}
ab = 1;
void a(){}
extern int gg; gg = 0;
void b(){ extern int ff; ff = 0;}
rtems_unsigned32 argument
uint32_t argument
rtems_task Task_1_through_6( rtems_unsigned32 argument){ rtems_id rmid; rtems_id test_rmid; rtems_unsigned32 index; rtems_unsigned32 pass; rtems_unsigned32 failed; rtems_status_code status; status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_create id = 0x%08x\n", rmid ); status = rtems_rate_monotonic_ident( argument, &test_rmid ); directive_failed( status, "rtems_rate_monotonic_ident" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_ident id = 0x%08x\n", test_rmid ); if ( rmid != test_rmid ) { printf( "RMID's DO NOT MATCH (0x%x and 0x%x)\n", rmid, test_rmid ); rtems_test_exit( 0 ); } put_name( Task_name[ argument ], FALSE ); printf( "- (0x%08x) period %d\n", rmid, Periods[ argument ] ); status = rtems_task_wake_after( 2 ); directive_failed( status, "rtems_task_wake_after" ); switch ( argument ) { case 1: case 2: case 3: case 4: while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period" ); Count.count[ argument ]++; } break; case 5: pass = 0; failed = 0; status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 1 of TA5" ); Get_all_counters(); while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 2 of TA5" ); Get_all_counters(); for( index = 1 ; index <= 4 ; index++ ) { if ( Temporary_count.count[ index ] != Iterations[ index ] ) { puts_nocr( "FAIL -- " ); put_name ( Task_name[ index ], FALSE ); printf ( " Actual=%d, Expected=%d\n", Temporary_count.count[ index ], Iterations[ index ] ); failed += 1; } } if ( failed == 5 ) rtems_test_exit( 0 ); pass += 1; printf( "TA5 - PERIODS CHECK OK (%d)\n", pass ); fflush( stdout ); if ( pass == 10 ) { puts( "*** END OF TEST 20 ***" ); rtems_test_exit( 0 ); } } break; case 6: /* test changing periods */ { unsigned32 time[TA6_ITERATIONS+1]; rtems_interval period; period = 1*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[0] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[0]);*/ for (index = 1; index <= TA6_ITERATIONS; index++) { period = (index+1)*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[index] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[index]);*/ } for (index = 1; index <= TA6_ITERATIONS; index++) { rtems_interval meas = time[index] - time[index-1]; period = index*TA6_PERIOD_FACTOR; printf("TA6 - Actual: %d Expected: %d", meas, period); if (period == meas) printf(" - OK\n"); else printf(" - FAILED\n"); } } rtems_task_suspend(RTEMS_SELF); break; }}
rtems_unsigned32 index; rtems_unsigned32 pass; rtems_unsigned32 failed;
uint32_t index; uint32_t pass; uint32_t failed;
rtems_task Task_1_through_6( rtems_unsigned32 argument){ rtems_id rmid; rtems_id test_rmid; rtems_unsigned32 index; rtems_unsigned32 pass; rtems_unsigned32 failed; rtems_status_code status; status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_create id = 0x%08x\n", rmid ); status = rtems_rate_monotonic_ident( argument, &test_rmid ); directive_failed( status, "rtems_rate_monotonic_ident" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_ident id = 0x%08x\n", test_rmid ); if ( rmid != test_rmid ) { printf( "RMID's DO NOT MATCH (0x%x and 0x%x)\n", rmid, test_rmid ); rtems_test_exit( 0 ); } put_name( Task_name[ argument ], FALSE ); printf( "- (0x%08x) period %d\n", rmid, Periods[ argument ] ); status = rtems_task_wake_after( 2 ); directive_failed( status, "rtems_task_wake_after" ); switch ( argument ) { case 1: case 2: case 3: case 4: while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period" ); Count.count[ argument ]++; } break; case 5: pass = 0; failed = 0; status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 1 of TA5" ); Get_all_counters(); while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 2 of TA5" ); Get_all_counters(); for( index = 1 ; index <= 4 ; index++ ) { if ( Temporary_count.count[ index ] != Iterations[ index ] ) { puts_nocr( "FAIL -- " ); put_name ( Task_name[ index ], FALSE ); printf ( " Actual=%d, Expected=%d\n", Temporary_count.count[ index ], Iterations[ index ] ); failed += 1; } } if ( failed == 5 ) rtems_test_exit( 0 ); pass += 1; printf( "TA5 - PERIODS CHECK OK (%d)\n", pass ); fflush( stdout ); if ( pass == 10 ) { puts( "*** END OF TEST 20 ***" ); rtems_test_exit( 0 ); } } break; case 6: /* test changing periods */ { unsigned32 time[TA6_ITERATIONS+1]; rtems_interval period; period = 1*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[0] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[0]);*/ for (index = 1; index <= TA6_ITERATIONS; index++) { period = (index+1)*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[index] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[index]);*/ } for (index = 1; index <= TA6_ITERATIONS; index++) { rtems_interval meas = time[index] - time[index-1]; period = index*TA6_PERIOD_FACTOR; printf("TA6 - Actual: %d Expected: %d", meas, period); if (period == meas) printf(" - OK\n"); else printf(" - FAILED\n"); } } rtems_task_suspend(RTEMS_SELF); break; }}
unsigned32 time[TA6_ITERATIONS+1];
uint32_t time[TA6_ITERATIONS+1];
rtems_task Task_1_through_6( rtems_unsigned32 argument){ rtems_id rmid; rtems_id test_rmid; rtems_unsigned32 index; rtems_unsigned32 pass; rtems_unsigned32 failed; rtems_status_code status; status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_create id = 0x%08x\n", rmid ); status = rtems_rate_monotonic_ident( argument, &test_rmid ); directive_failed( status, "rtems_rate_monotonic_ident" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_ident id = 0x%08x\n", test_rmid ); if ( rmid != test_rmid ) { printf( "RMID's DO NOT MATCH (0x%x and 0x%x)\n", rmid, test_rmid ); rtems_test_exit( 0 ); } put_name( Task_name[ argument ], FALSE ); printf( "- (0x%08x) period %d\n", rmid, Periods[ argument ] ); status = rtems_task_wake_after( 2 ); directive_failed( status, "rtems_task_wake_after" ); switch ( argument ) { case 1: case 2: case 3: case 4: while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period" ); Count.count[ argument ]++; } break; case 5: pass = 0; failed = 0; status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 1 of TA5" ); Get_all_counters(); while ( FOREVER ) { status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); directive_failed( status, "rtems_rate_monotonic_period 2 of TA5" ); Get_all_counters(); for( index = 1 ; index <= 4 ; index++ ) { if ( Temporary_count.count[ index ] != Iterations[ index ] ) { puts_nocr( "FAIL -- " ); put_name ( Task_name[ index ], FALSE ); printf ( " Actual=%d, Expected=%d\n", Temporary_count.count[ index ], Iterations[ index ] ); failed += 1; } } if ( failed == 5 ) rtems_test_exit( 0 ); pass += 1; printf( "TA5 - PERIODS CHECK OK (%d)\n", pass ); fflush( stdout ); if ( pass == 10 ) { puts( "*** END OF TEST 20 ***" ); rtems_test_exit( 0 ); } } break; case 6: /* test changing periods */ { unsigned32 time[TA6_ITERATIONS+1]; rtems_interval period; period = 1*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[0] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[0]);*/ for (index = 1; index <= TA6_ITERATIONS; index++) { period = (index+1)*TA6_PERIOD_FACTOR; status = rtems_rate_monotonic_period( rmid, period); directive_failed( status, "rtems_rate_monotonic_period of TA6" ); time[index] = _Watchdog_Ticks_since_boot; /* timestamp */ /*printf("%d - %d\n", period, time[index]);*/ } for (index = 1; index <= TA6_ITERATIONS; index++) { rtems_interval meas = time[index] - time[index-1]; period = index*TA6_PERIOD_FACTOR; printf("TA6 - Actual: %d Expected: %d", meas, period); if (period == meas) printf(" - OK\n"); else printf(" - FAILED\n"); } } rtems_task_suspend(RTEMS_SELF); break; }}
y = (GEN) gpmalloc(lb*sizeof(long)); for (i=1; i<lb; i++) y[i]=coeff(b,1,i); x = sfcont2(y,x,flag); free(y); return x;
y = cgetg(lb, t_VEC); for (i=1; i<lb; i++) y[i] = mael(b,i,1); x = sfcont2(y,x,flag); return x;
contfrac0(GEN x, GEN b, long flag){ long lb,tb,i; GEN y; if (!b || gcmp0(b)) return sfcont(x,flag); tb = typ(b); if (tb == t_INT) return sfcont(x,itos(b)); if (! is_matvec_t(tb)) err(typeer,"contfrac0"); lb=lg(b); if (lb==1) return cgetg(1,t_VEC); if (tb != t_MAT) return sfcont2(b,x,flag); if (lg(b[1])==1) return sfcont(x,flag); y = (GEN) gpmalloc(lb*sizeof(long)); for (i=1; i<lb; i++) y[i]=coeff(b,1,i); x = sfcont2(y,x,flag); free(y); return x;}
is_357_power(GEN x, GEN *pt, long *mask)
is_357_power(GEN x, GEN *pt, ulong *mask)
is_357_power(GEN x, GEN *pt, long *mask){ long lx = lgefint(x), exponent = 0, residue, resbyte; pari_sp av = avma; GEN y; *mask &= 7; /* paranoia */ if (!*mask) return 0; /* useful when running in a loop */ if (DEBUGLEVEL >= 5) { fprintferr("OddPwrs: is %Z\n\t...a", x); if (*mask&1) fprintferr(" 3rd%s", (*mask==7?",":(*mask!=1?" or":""))); if (*mask&2) fprintferr(" 5th%s", (*mask==7?", or":(*mask&4?" or":""))); if (*mask&4) fprintferr(" 7th"); fprintferr(" power?\n\tmodulo: resid. (remaining possibilities)\n"); } residue = (lx == 3)? x[2]: smodis(x, 211*209*61*203);#define check_res(N, shift) {\ resbyte = residue%N; if (resbyte > (N>>1)) resbyte = N - resbyte;\ *mask &= (powersmod[resbyte] >> shift); \ if (DEBUGLEVEL >= 5)\ fprintferr("\t %3ld: %3ld (3rd %ld, 5th %ld, 7th %ld)\n",\ N, resbyte, *mask&1, (*mask>>1)&1, (*mask>>2)&1);\ if (!*mask) return 0;\} check_res(211, 0); if (*mask & 3) check_res(209, 3); if (*mask & 3) check_res( 61, 6); if (*mask & 5) check_res(203, 9); residue = (lx == 3)? x[2]: smodis(x, 117*31*43*71); if (*mask & 1) check_res(117,12); if (*mask & 3) check_res( 31,15); if (*mask & 5) check_res( 43,18); if (*mask & 6) check_res( 71,21); /* priority to higher powers: if we have a 21st, it is easier to rediscover * that its 7th root is a cube than that its cube root is a 7th power */ if ( (resbyte = *mask & 4) ) exponent = 7; else if ( (resbyte = *mask & 2) ) exponent = 5; else { resbyte = 1; exponent = 3; } y = mpround( sqrtnr(itor(x, 3 + (lx-2) / exponent), exponent) ); if (!egalii(gpowgs(y, exponent), x)) { if (DEBUGLEVEL >= 5) { if (exponent == 3) fprintferr("\tBut it nevertheless wasn't a cube.\n"); else fprintferr("\tBut it nevertheless wasn't a %ldth power.\n", exponent); } *mask &= ~resbyte; /* turn the bit off */ avma = av; return 0; } if (!pt) { avma = av; return exponent; } avma = (pari_sp)y; *pt = gerepileuptoint(av, y); return exponent;}
long n, j, la, lb;
long n, j, da, db;
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
y[j++] = (long)gen_0;
gel(y, j++) = gen_0;
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p);
da = degpol(a); db = degpol(b); n += da + db; setlg(y, n+1); if (db) gel(y,j) = FpX_normalize(b,p); if (da) gel(y,j+db) = FpX_normalize(a,p);
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2)
a = gel(y,j); da = degpol(a); if (da==1) gel(y,j++) = subii(p, gel(a,2)); else if (da==2)
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p);
gel(y, j++) = r; gel(y, j++) = otherroot(a,r, p);
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la)
b = FpX_gcd(a,b, p); db = degpol(b); if (db && db < da)
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break;
gel(y,j+db) = FpX_div(a,b, p); gel(y,j) = b; break;
FpX_roots_i(GEN f, GEN p){ long n, j, la, lb; GEN y, pol, pol0, a, b, q = shifti(p,-1); y = cgetg(lg(f), t_COL); j = 1; if (!ZX_valuation(f, &f)) n = 0; else { y[j++] = (long)gen_0; if (lg(f) <= 3) { setlg(y, 2); return y; } n = 1; } /* take gcd(x^(p-1) - 1, f) by splitting (x^q-1) * (x^q+1) */ b = FpXQ_pow(polx[varn(f)],q, f,p); if (lg(b) < 3) err(talker,"not a prime in rootmod"); b = ZX_s_add(b,-1); /* b = x^((p-1)/2) - 1 mod f */ a = FpX_gcd(f,b, p); b = ZX_s_add(b, 2); /* b = x^((p-1)/2) + 1 mod f */ b = FpX_gcd(f,b, p); la = degpol(a); lb = degpol(b); n += la + lb; setlg(y, n+1); if (lb) y[j] = (long)FpX_normalize(b,p); if (la) y[j+lb] = (long)FpX_normalize(a,p); pol = gadd(polx[varn(f)], gen_1); pol0 = constant_term(pol); while (j <= n) { /* cf FpX_split_Berlekamp */ a = (GEN)y[j]; la = degpol(a); if (la==1) y[j++] = lsubii(p, (GEN)a[2]); else if (la==2) { GEN r = FpX_quad_root(a, p, 0); y[j++] = (long)r; y[j++] = (long)otherroot(a,r, p); } else for (pol0[2]=1; ; pol0[2]++) { b = ZX_s_add(FpXQ_pow(pol,q, a,p), -1); /* pol^(p-1)/2 - 1 */ b = FpX_gcd(a,b, p); lb = degpol(b); if (lb && lb < la) { b = FpX_normalize(b, p); y[j+lb] = (long)FpX_div(a,b, p); y[j] = (long)b; break; } if (pol0[2] == 100 && !BSW_psp(p)) err(talker, "not a prime in polrootsmod"); } } return sort(y);}
piv = coeff(x,t,k) % p;
piv = ( coeff(x,t,k) %= p );
u_FpM_ker_sp(GEN x, ulong p, long deplin){ GEN y,c,d; long i,j,k,r,t,n; ulong a, piv, m; n = lg(x)-1; m=lg(x[1])-1; r=0; c = new_chunk(m+1); for (k=1; k<=m; k++) c[k] = 0; d = new_chunk(n+1); a = 0; /* for gcc -Wall */ for (k=1; k<=n; k++) { for (j=1; j<=m; j++) if (!c[j]) { a = coeff(x,j,k) % p; if (a) break; } if (j > m) { if (deplin) { c = cgetg(n+1, t_VECSMALL); for (i=1; i<k; i++) c[i] = coeff(x,d[i],k) % p; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; return c; } r++; d[k] = 0; } else { c[j] = k; d[k] = j; piv = p - u_invmod(a, p); /* -1/a */ coeff(x,j,k) = p-1; for (i=k+1; i<=n; i++) coeff(x,j,i) = (piv * coeff(x,j,i)) % p; for (t=1; t<=m; t++) { if (t==j) continue; piv = coeff(x,t,k) % p; if (!piv) continue; coeff(x,t,k) = 0; if (piv == 1) for (i=k+1; i<=n; i++) _u_Fp_add((GEN)x[i],t,j,p); else { if (u_OK_ULONG(p)) for (i=k+1; i<=n; i++) _u_Fp_addmul_OK((GEN)x[i],t,j,piv,p); else for (i=k+1; i<=n; i++) _u_Fp_addmul((GEN)x[i],t,j,piv,p); } } } } if (deplin) return NULL; y = cgetg(r+1, t_MAT); for (j=k=1; j<=r; j++,k++) { GEN c = cgetg(n+1, t_VECSMALL); y[j] = (long)c; while (d[k]) k++; for (i=1; i<k; i++) if (d[i]) c[i] = coeff(x,d[i],k) % p; else c[i] = 0; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; } return y;}
coeff(x,t,k) = 0;
u_FpM_ker_sp(GEN x, ulong p, long deplin){ GEN y,c,d; long i,j,k,r,t,n; ulong a, piv, m; n = lg(x)-1; m=lg(x[1])-1; r=0; c = new_chunk(m+1); for (k=1; k<=m; k++) c[k] = 0; d = new_chunk(n+1); a = 0; /* for gcc -Wall */ for (k=1; k<=n; k++) { for (j=1; j<=m; j++) if (!c[j]) { a = coeff(x,j,k) % p; if (a) break; } if (j > m) { if (deplin) { c = cgetg(n+1, t_VECSMALL); for (i=1; i<k; i++) c[i] = coeff(x,d[i],k) % p; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; return c; } r++; d[k] = 0; } else { c[j] = k; d[k] = j; piv = p - u_invmod(a, p); /* -1/a */ coeff(x,j,k) = p-1; for (i=k+1; i<=n; i++) coeff(x,j,i) = (piv * coeff(x,j,i)) % p; for (t=1; t<=m; t++) { if (t==j) continue; piv = coeff(x,t,k) % p; if (!piv) continue; coeff(x,t,k) = 0; if (piv == 1) for (i=k+1; i<=n; i++) _u_Fp_add((GEN)x[i],t,j,p); else { if (u_OK_ULONG(p)) for (i=k+1; i<=n; i++) _u_Fp_addmul_OK((GEN)x[i],t,j,piv,p); else for (i=k+1; i<=n; i++) _u_Fp_addmul((GEN)x[i],t,j,piv,p); } } } } if (deplin) return NULL; y = cgetg(r+1, t_MAT); for (j=k=1; j<=r; j++,k++) { GEN c = cgetg(n+1, t_VECSMALL); y[j] = (long)c; while (d[k]) k++; for (i=1; i<k; i++) if (d[i]) c[i] = coeff(x,d[i],k) % p; else c[i] = 0; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; } return y;}
{ if (u_OK_ULONG(p)) for (i=k+1; i<=n; i++) _u_Fp_addmul_OK((GEN)x[i],t,j,piv,p); else for (i=k+1; i<=n; i++) _u_Fp_addmul((GEN)x[i],t,j,piv,p); }
for (i=k+1; i<=n; i++) _u_Fp_addmul((ulong*)x[i],t,j,piv,p);
u_FpM_ker_sp(GEN x, ulong p, long deplin){ GEN y,c,d; long i,j,k,r,t,n; ulong a, piv, m; n = lg(x)-1; m=lg(x[1])-1; r=0; c = new_chunk(m+1); for (k=1; k<=m; k++) c[k] = 0; d = new_chunk(n+1); a = 0; /* for gcc -Wall */ for (k=1; k<=n; k++) { for (j=1; j<=m; j++) if (!c[j]) { a = coeff(x,j,k) % p; if (a) break; } if (j > m) { if (deplin) { c = cgetg(n+1, t_VECSMALL); for (i=1; i<k; i++) c[i] = coeff(x,d[i],k) % p; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; return c; } r++; d[k] = 0; } else { c[j] = k; d[k] = j; piv = p - u_invmod(a, p); /* -1/a */ coeff(x,j,k) = p-1; for (i=k+1; i<=n; i++) coeff(x,j,i) = (piv * coeff(x,j,i)) % p; for (t=1; t<=m; t++) { if (t==j) continue; piv = coeff(x,t,k) % p; if (!piv) continue; coeff(x,t,k) = 0; if (piv == 1) for (i=k+1; i<=n; i++) _u_Fp_add((GEN)x[i],t,j,p); else { if (u_OK_ULONG(p)) for (i=k+1; i<=n; i++) _u_Fp_addmul_OK((GEN)x[i],t,j,piv,p); else for (i=k+1; i<=n; i++) _u_Fp_addmul((GEN)x[i],t,j,piv,p); } } } } if (deplin) return NULL; y = cgetg(r+1, t_MAT); for (j=k=1; j<=r; j++,k++) { GEN c = cgetg(n+1, t_VECSMALL); y[j] = (long)c; while (d[k]) k++; for (i=1; i<k; i++) if (d[i]) c[i] = coeff(x,d[i],k) % p; else c[i] = 0; c[k] = 1; for (i=k+1; i<=n; i++) c[i] = 0; } return y;}
unsigned32 baudrate
uint32_t baudrate
int serdbg_open/*-------------------------------------------------------------------------*\| Purpose: || try to open given serial debug port |+---------------------------------------------------------------------------+| Input Parameters: |\*-------------------------------------------------------------------------*/( const char *dev_name, /* name of device to open */ unsigned32 baudrate /* baud rate to use */)/*-------------------------------------------------------------------------*\| Return Value: || 0 on success, -1 and errno otherwise |\*=========================================================================*/{ boolean err_occurred = FALSE; rtems_libio_t *iop = NULL; struct termios act_termios; tcflag_t baudcode = B0;#define FD_STORE_CNT 3 int fd_store[FD_STORE_CNT]; int fd_store_used = 0; /* * translate baudrate into baud code */ switch(baudrate) { case 50: baudcode = B50; break; case 75: baudcode = B75; break; case 110: baudcode = B110; break; case 134: baudcode = B134; break; case 150: baudcode = B150; break; case 200: baudcode = B200; break; case 300: baudcode = B300; break; case 600: baudcode = B600; break; case 1200: baudcode = B1200; break; case 1800: baudcode = B1800; break; case 2400: baudcode = B2400; break; case 4800: baudcode = B4800; break; case 9600: baudcode = B9600; break; case 19200: baudcode = B19200; break; case 38400: baudcode = B38400; break; case 57600: baudcode = B57600; break; case 115200: baudcode = B115200; break; case 230400: baudcode = B230400; break; case 460800: baudcode = B460800; break; default : err_occurred = TRUE; errno = EINVAL; break; } /* * open device for serdbg operation * skip any fds that are between 0..2, because they are * reserved for stdin/out/err */ if (!err_occurred && (dev_name != NULL) && (dev_name[0] != '\0')) { do { serdbg_fd = open(dev_name,O_RDWR); if (serdbg_fd < 0) { err_occurred = TRUE; } else { if (serdbg_fd < 3) { if (fd_store_used >= FD_STORE_CNT) { err_occurred = TRUE; } else { fd_store[fd_store_used++] = serdbg_fd; } } } } while (!err_occurred && (serdbg_fd < 3)); } /* * close any fds, that have been placed in fd_store * so fd 0..2 are reusable again */ while (--fd_store_used >= 0) { close(fd_store[fd_store_used]); } /* * capture tty structure */ if (!err_occurred) { iop = &rtems_libio_iops[serdbg_fd]; serdbg_tty = iop->data1; } /* * set device baudrate * (and transp mode, this is not really needed) * ... */ /* * ... get fd settings */ if (!err_occurred && (0 != tcgetattr(serdbg_fd,&act_termios))) { err_occurred = TRUE; } if (!err_occurred) { act_termios.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); act_termios.c_oflag &= ~OPOST; act_termios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); cfsetospeed(&act_termios,baudcode); cfsetispeed(&act_termios,baudcode); if (0 != tcsetattr(serdbg_fd,TCSANOW,&act_termios)) { err_occurred = TRUE; } } return (err_occurred ? -1 : 0);}
GEN z, y = cgetr(lg(x));
mpath(GEN x){ GEN z, y = cgetr(lg(x)); pari_sp av = avma; z = mplog( addrs(divsr(2,subsr(1,x)), -1) ); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;}
z = mplog( addrs(divsr(2,subsr(1,x)), -1) ); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;
GEN z = logr_abs( addrs(divsr(2,subsr(1,x)), -1) ); setexpo(z, expo(z)-1); return gerepileuptoleaf(av, z);
mpath(GEN x){ GEN z, y = cgetr(lg(x)); pari_sp av = avma; z = mplog( addrs(divsr(2,subsr(1,x)), -1) ); setexpo(z, expo(z)-1); affrr(z, y); avma = av; return y;}
c = u_FpX_rem(a,b,p,0);
c = u_FpX_rem(a,b,p);
u_FpX_gcd(GEN a, GEN b, ulong p){ GEN c; if (lgef(b) > lgef(a)) swap(a, b); while (signe(b)) { c = u_FpX_rem(a,b,p,0); a = b; b = c; } return a;}
if (lgefint(p) == 3) { pari_sp av = avma; ulong pp = (long)p[2]; GEN Tl = ZX_to_Flx(T, pp); GEN Vl = ZXXV_to_FlxXV(V, pp, varn(T)); modulo = (GEN)pp; Tmodulo = Tl; Tl = divide_conquer_prod(Vl, &_FlxqX_mul); return gerepileupto(av, FlxX_to_ZXX(Tl)); }
FpXQXV_prod(GEN V, GEN T, GEN p){ modulo = p; Tmodulo = T; return divide_conquer_prod(V, &_FpXQX_mul);}
GEN d = mppgcd(p,x);
GEN d = gcdii(p,x);
Fp_gener_fact(GEN p, GEN fa){ pari_sp av0 = avma; long k, i; GEN x, q, V; if (egalii(p, gdeux)) return gun; if (lgefint(p) == 3) return utoi(u_gener_fact((ulong)p[2], fa)); q = subis(p, 1); if (!fa) { fa = V = (GEN)decomp(q)[1]; k = lg(fa)-1; } else { fa = (GEN)fa[1]; k = lg(fa)-1; V = cgetg(k + 1, t_VEC); } for (i=1; i<=k; i++) V[i] = (long)diviiexact(q, (GEN)fa[i]); x = utoi(2UL); for (;; x[2]++) { GEN d = mppgcd(p,x); if (!is_pm1(d)) continue; for (i = k; i; i--) { GEN e = powmodulo(x, (GEN)V[i], p); if (is_pm1(e)) break; } if (!i) { avma = av0; return utoi((ulong)x[2]); } }}
} else if (l > lp) { GEN x = cgetg(l, t_VECSMALL); for (i=1; i<lp; i++) x[i] = Hp[i]; for ( ; i<l; i++) x[i] = 0; Hp = x; lp = l;
ZX_incremental_CRT(GEN *ptH, GEN Hp, GEN q, GEN qp, ulong p){ GEN H = *ptH, h, lim = shifti(qp,-1); ulong qinv = Fl_inv(umodiu(q,p), p); long i, l = lg(H), lp = lg(Hp); int stable = 1; if (l < lp) { /* degree increases */ GEN x = cgetg(lp, t_POL); for (i=1; i<l; i++) x[i] = H[i]; for ( ; i<lp; i++) x[i] = zero; *ptH = H = x; stable = 0; } for (i=2; i<lp; i++) { h = u_chinese_coprime((GEN)H[i],Hp[i],q,p,qinv,qp); if (h) { if (cmpii(h,lim) > 0) h = subii(h,qp); H[i] = (long)h; stable = 0; } } return stable;}
if (dotime) sgt6 = timer();
step6(GEN N, ulong t, GEN et){ GEN N1,r,p1; ulong i; gpmem_t av; N1 = resii(N, et); r = gun; av = avma; for (i=1; i<t; i++) { r = resii(mulii(r,N1), et); if (!signe(resii(N,r)) && !gcmp1(r) && !egalii(r,N)) { p1 = cgetg(3,t_VEC); p1[1] = (long)r; p1[2] = zero; return p1; } if ((i & 0x1f) == 0) r = gerepileuptoint(av, r); } return gun;}
if (Z) *Z = shiftpol(x, v);
if (Z) *Z = shiftpol_i(x, v);
ZX_valuation(GEN x, GEN *Z){ long v; if (!signe(x)) { if (Z) *Z = zeropol(varn(x)); return VERYBIGINT; } for (v = 0;; v++) if (signe((GEN)x[2+v])) break; if (Z) *Z = shiftpol(x, v); return v;}
c = u_FpX_rem(a,b, p,0);
c = u_FpX_rem(a,b, p);
u_FpX_resultant(GEN a, GEN b, ulong p){ long da,db,dc,cnt; ulong lb,av, res = 1UL; GEN c; if (!signe(a) || !signe(b)) return 0; da = deg(a); db = deg(b); if (db > da) { swapspec(a,b, da,db); if (da & db & 1) res = p-res; } if (!da) return 1; /* = res * a[2] ^ db, since 0 <= db <= da = 0 */ cnt = 0; av = avma; while (db) { lb = b[db+2]; if (da & db & 1) res = p - res; c = u_FpX_rem(a,b, p,0); a = b; b = c; dc = deg(c); if (dc < 0) { avma = av; return 0; } if (lb != 1) res = mulssmod(res, powuumod(lb, da - dc, p), p); if (++cnt == 4) { cnt = 0; avma = av; } da = db; /* = deg(a) */ db = dc; /* = deg(b) */ } avma = av; return mulssmod(res, powuumod(b[2], da, p), p);}
ulong av = avma, av2, lim, Hp; GEN q, a, b, H, bound;
ulong av = avma, av2, lim, Hp, bound; GEN q, a, b, H;
ZX_resultant(GEN A, GEN B){ ulong av = avma, av2, lim, Hp; GEN q, a, b, H, bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; av2 = avma; lim = stack_lim(av,2); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); b = u_Fp_FpX(B, 0, p); Hp= u_FpX_resultant(a, b, p); if (!H) H = init_CRT_i(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT_i(&H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[2]; gptr[0] = &H; gptr[1] = &q; if (DEBUGMEM>1) err(warnmem,"ZX_resultant"); gerepilemany(av2,gptr, 2); } } return gerepileuptoint(av, icopy(H));}
if (DEBUGLEVEL>4) fprintferr("bound for resultant: %Z\n",bound);
if (DEBUGLEVEL>4) fprintferr("bound for resultant: 2^%ld\n",bound);
ZX_resultant(GEN A, GEN B){ ulong av = avma, av2, lim, Hp; GEN q, a, b, H, bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; av2 = avma; lim = stack_lim(av,2); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); b = u_Fp_FpX(B, 0, p); Hp= u_FpX_resultant(a, b, p); if (!H) H = init_CRT_i(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT_i(&H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[2]; gptr[0] = &H; gptr[1] = &q; if (DEBUGMEM>1) err(warnmem,"ZX_resultant"); gerepilemany(av2,gptr, 2); } } return gerepileuptoint(av, icopy(H));}
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break;
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld (bound 2^%ld)", p,expi(q)); if (expi(q) >= bound) break;
ZX_resultant(GEN A, GEN B){ ulong av = avma, av2, lim, Hp; GEN q, a, b, H, bound; byteptr d = diffptr + 3000; ulong p = 27449; /* p = prime(3000) */ q = H = NULL; av2 = avma; lim = stack_lim(av,2); bound = ZY_ZXY_ResBound(A,B); if (DEBUGLEVEL>4) fprintferr("bound for resultant: %Z\n",bound); for(;;) { p += *d++; if (!*d) err(primer1); a = u_Fp_FpX(A, 0, p); b = u_Fp_FpX(B, 0, p); Hp= u_FpX_resultant(a, b, p); if (!H) H = init_CRT_i(Hp, &q, p); else /* could make it probabilistic ??? [e.g if stable twice, etc] */ (void)incremental_CRT_i(&H, Hp, &q, p); if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ if (low_stack(lim, stack_lim(av,2))) { GEN *gptr[2]; gptr[0] = &H; gptr[1] = &q; if (DEBUGMEM>1) err(warnmem,"ZX_resultant"); gerepilemany(av2,gptr, 2); } } return gerepileuptoint(av, icopy(H));}
if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) {
if ( (*sc->read_register)( rp, SONIC_REG_SR ) <= SONIC_REVISION_B ) {
SONIC_STATIC void sonic_initialize_hardware(struct sonic_softc *sc){ void *rp = sc->sonic; int i; unsigned char *hwaddr; rtems_isr_entry old_handler; TransmitDescriptorPointer_t tdp; ReceiveDescriptorPointer_t ordp, rdp; ReceiveResourcePointer_t rwp; struct mbuf *m; void *p; CamDescriptorPointer_t cdp; /* * The Revision B SONIC has a horrible bug known as the "Zero * Length Packet bug". The initial board used to develop this * driver had a newer revision of the SONIC so there was no reason * to check for this. If you have the Revision B SONIC chip, then * you need to add some code to the RX path to handle this weirdness. */ if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) { rtems_fatal_error_occurred( 0x0BADF00D ); /* don't eat this part :) */ } /* * Set up circular linked list in Transmit Descriptor Area. * Use the PINT bit in the transmit configuration field to * request an interrupt on every other transmitted packet. * * NOTE: sonic_allocate() zeroes all of the memory allocated. */ sc->tdaActiveCount = 0; sc->tdaTail = sonic_allocate(sc->tdaCount * sizeof *tdp);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "tdaTail = %p\n", sc->tdaTail );#endif tdp = sc->tdaTail; for (i = 0 ; i < sc->tdaCount ; i++) { /* * Start off with the table of outstanding mbuf's */ /* * status, pkt_config, pkt_size, and all fragment fields * are set to zero by sonic_allocate. *//* XXX not used by the BSD drivers*/ if (i & 1) tdp->pkt_config = TDA_CONFIG_PINT; tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_tx_descriptor( tdp );#endif tdp++; } tdp--; sc->tdaHead = tdp; tdp->link_pad = LSW(sc->tdaTail) | TDA_LINK_EOL; tdp->next = (TransmitDescriptor_t *)sc->tdaTail; tdp->linkp = &sc->tdaTail->frag[0].frag_link; /* * Set up circular linked list in Receive Descriptor Area. * Leaves sc->rda pointing at the `beginning' of the list. * * NOTE: The RDA and CDP must have the same MSW for their addresses. */ sc->rda = sonic_allocate( (sc->rdaCount * sizeof(ReceiveDescriptor_t)) + sizeof(CamDescriptor_t) ); sc->cdp = (CamDescriptorPointer_t) ((unsigned char *)sc->rda + (sc->rdaCount * sizeof(ReceiveDescriptor_t)));#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rda area = %p\n", sc->rda ); printf( "cdp area = %p\n", sc->cdp );#endif ordp = rdp = sc->rda; for (i = 0 ; i < sc->rdaCount ; i++) { /* * status, byte_count, pkt_ptr0, pkt_ptr1, and seq_no are set * to zero by sonic_allocate. */ rdp->link = LSW(rdp + 1); rdp->in_use = RDA_FREE; rdp->next = (ReceiveDescriptor_t *)(rdp + 1); ordp = rdp; rdp++; } /* * Link the last desriptor to the 1st one and mark it as the end * of the list. */ ordp->next = sc->rda; ordp->link = LSW(sc->rda) | RDA_LINK_EOL; sc->rdp_last = rdp; /* * Allocate the receive resource area. * In accordance with National Application Note 746, make the * receive resource area bigger than the receive descriptor area. * This has the useful side effect of making the receive resource * area big enough to hold the CAM descriptor area. */ sc->rsa = sonic_allocate((sc->rdaCount + RRA_EXTRA_COUNT) * sizeof *sc->rsa);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rsa area = %p\n", sc->rsa );#endif /* * Set up list in Receive Resource Area. * Allocate space for incoming packets. */ rwp = sc->rsa; for (i = 0 ; i < (sc->rdaCount + RRA_EXTRA_COUNT) ; i++, rwp++) { /* * Allocate memory for buffer. * Place a pointer to the mbuf at the beginning of the buffer * so we can find the mbuf when the SONIC returns the buffer * to the driver. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = &sc->arpcom.ac_if; sc->rda[i].mbufp = m; p = mtod (m, void *); /* * Set up RRA entry */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( &sc->rda[i] );#endif } sc->rea = rwp;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rea area = %p\n", sc->rea );#endif /* * Issue a software reset. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX ); /* * Set up data configuration registers. */ (*sc->write_register)( rp, SONIC_REG_DCR, sc->dcr_value ); (*sc->write_register)( rp, SONIC_REG_DCR2, sc->dc2_value ); (*sc->write_register)( rp, SONIC_REG_CR, CR_STP | CR_RXDIS | CR_HTX ); /* * Mask all interrupts */ (*sc->write_register)( rp, SONIC_REG_IMR, 0x0 ); /* XXX was backwards */ /* * Clear outstanding interrupts. */ (*sc->write_register)( rp, SONIC_REG_ISR, 0x7FFF ); /* * Clear the tally counters */ (*sc->write_register)( rp, SONIC_REG_CRCT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_FAET, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_MPT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_RSC, 0 ); /* * Set the Receiver mode * * Enable/disable reception of broadcast packets */ if (sc->acceptBroadcast) (*sc->write_register)( rp, SONIC_REG_RCR, RCR_BRD ); else (*sc->write_register)( rp, SONIC_REG_RCR, 0 ); /* * Set up Resource Area pointers */ (*sc->write_register)( rp, SONIC_REG_URRA, MSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RSA, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_REA, LSW(sc->rea) ); (*sc->write_register)( rp, SONIC_REG_RRP, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RWP, LSW(sc->rsa) ); /* XXX was rea */ (*sc->write_register)( rp, SONIC_REG_URDA, MSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_CRDA, LSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_UTDA, MSW(sc->tdaTail) ); (*sc->write_register)( rp, SONIC_REG_CTDA, LSW(sc->tdaTail) ); /* * Set End Of Buffer Count register to the value recommended * in Note 1 of Section 3.4.4.4 of the SONIC data sheet. */ (*sc->write_register)( rp, SONIC_REG_EOBC, RBUF_WC - 2 ); /* * Issue the load RRA command */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RRRA ); while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_RRRA) continue; /* * Remove device reset */ (*sc->write_register)( rp, SONIC_REG_CR, 0 ); /* * Set up the SONIC CAM with our hardware address. */ hwaddr = sc->arpcom.ac_enaddr; cdp = sc->cdp;#if (SONIC_DEBUG & SONIC_DEBUG_CAM) printf( "hwaddr: %2x:%2x:%2x:%2x:%2x:%2x\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5] );#endif cdp->cep = 0; /* Fill first and only entry in CAM */ cdp->cap0 = hwaddr[1] << 8 | hwaddr[0]; cdp->cap1 = hwaddr[3] << 8 | hwaddr[2]; cdp->cap2 = hwaddr[5] << 8 | hwaddr[4]; cdp->ce = 0x0001; /* Enable first entry in CAM */ (*sc->write_register)( rp, SONIC_REG_CDC, 1 ); /* 1 entry in CDA */ (*sc->write_register)( rp, SONIC_REG_CDP, LSW(cdp) ); (*sc->write_register)( rp, SONIC_REG_CR, CR_LCAM ); /* Load the CAM */ while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_LCAM) continue; /* * Verify that CAM was properly loaded. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX );#if (SONIC_DEBUG & SONIC_DEBUG_CAM) (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ printf ("Loaded Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE ));#endif (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ if (((*sc->read_register)( rp, SONIC_REG_CAP2 ) != cdp->cap2) || ((*sc->read_register)( rp, SONIC_REG_CAP1 ) != cdp->cap1) || ((*sc->read_register)( rp, SONIC_REG_CAP0 ) != cdp->cap0) || ((*sc->read_register)( rp, SONIC_REG_CE ) != cdp->ce)) { printf ("Failed to load Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE )); rtems_panic ("SONIC LCAM"); } (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */CR_RXEN | CR_STP); /* * Attach SONIC interrupt handler *//* XXX (*sc->write_register)( rp, SONIC_REG_IMR, 0 );*/ old_handler = set_vector(sonic_interrupt_handler, sc->vector, 1); /* * Remainder of hardware initialization is * done by the receive and transmit daemons. */}
sc->tdaActiveCount = 0;
SONIC_STATIC void sonic_initialize_hardware(struct sonic_softc *sc){ void *rp = sc->sonic; int i; unsigned char *hwaddr; rtems_isr_entry old_handler; TransmitDescriptorPointer_t tdp; ReceiveDescriptorPointer_t ordp, rdp; ReceiveResourcePointer_t rwp; struct mbuf *m; void *p; CamDescriptorPointer_t cdp; /* * The Revision B SONIC has a horrible bug known as the "Zero * Length Packet bug". The initial board used to develop this * driver had a newer revision of the SONIC so there was no reason * to check for this. If you have the Revision B SONIC chip, then * you need to add some code to the RX path to handle this weirdness. */ if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) { rtems_fatal_error_occurred( 0x0BADF00D ); /* don't eat this part :) */ } /* * Set up circular linked list in Transmit Descriptor Area. * Use the PINT bit in the transmit configuration field to * request an interrupt on every other transmitted packet. * * NOTE: sonic_allocate() zeroes all of the memory allocated. */ sc->tdaActiveCount = 0; sc->tdaTail = sonic_allocate(sc->tdaCount * sizeof *tdp);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "tdaTail = %p\n", sc->tdaTail );#endif tdp = sc->tdaTail; for (i = 0 ; i < sc->tdaCount ; i++) { /* * Start off with the table of outstanding mbuf's */ /* * status, pkt_config, pkt_size, and all fragment fields * are set to zero by sonic_allocate. *//* XXX not used by the BSD drivers*/ if (i & 1) tdp->pkt_config = TDA_CONFIG_PINT; tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_tx_descriptor( tdp );#endif tdp++; } tdp--; sc->tdaHead = tdp; tdp->link_pad = LSW(sc->tdaTail) | TDA_LINK_EOL; tdp->next = (TransmitDescriptor_t *)sc->tdaTail; tdp->linkp = &sc->tdaTail->frag[0].frag_link; /* * Set up circular linked list in Receive Descriptor Area. * Leaves sc->rda pointing at the `beginning' of the list. * * NOTE: The RDA and CDP must have the same MSW for their addresses. */ sc->rda = sonic_allocate( (sc->rdaCount * sizeof(ReceiveDescriptor_t)) + sizeof(CamDescriptor_t) ); sc->cdp = (CamDescriptorPointer_t) ((unsigned char *)sc->rda + (sc->rdaCount * sizeof(ReceiveDescriptor_t)));#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rda area = %p\n", sc->rda ); printf( "cdp area = %p\n", sc->cdp );#endif ordp = rdp = sc->rda; for (i = 0 ; i < sc->rdaCount ; i++) { /* * status, byte_count, pkt_ptr0, pkt_ptr1, and seq_no are set * to zero by sonic_allocate. */ rdp->link = LSW(rdp + 1); rdp->in_use = RDA_FREE; rdp->next = (ReceiveDescriptor_t *)(rdp + 1); ordp = rdp; rdp++; } /* * Link the last desriptor to the 1st one and mark it as the end * of the list. */ ordp->next = sc->rda; ordp->link = LSW(sc->rda) | RDA_LINK_EOL; sc->rdp_last = rdp; /* * Allocate the receive resource area. * In accordance with National Application Note 746, make the * receive resource area bigger than the receive descriptor area. * This has the useful side effect of making the receive resource * area big enough to hold the CAM descriptor area. */ sc->rsa = sonic_allocate((sc->rdaCount + RRA_EXTRA_COUNT) * sizeof *sc->rsa);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rsa area = %p\n", sc->rsa );#endif /* * Set up list in Receive Resource Area. * Allocate space for incoming packets. */ rwp = sc->rsa; for (i = 0 ; i < (sc->rdaCount + RRA_EXTRA_COUNT) ; i++, rwp++) { /* * Allocate memory for buffer. * Place a pointer to the mbuf at the beginning of the buffer * so we can find the mbuf when the SONIC returns the buffer * to the driver. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = &sc->arpcom.ac_if; sc->rda[i].mbufp = m; p = mtod (m, void *); /* * Set up RRA entry */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( &sc->rda[i] );#endif } sc->rea = rwp;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rea area = %p\n", sc->rea );#endif /* * Issue a software reset. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX ); /* * Set up data configuration registers. */ (*sc->write_register)( rp, SONIC_REG_DCR, sc->dcr_value ); (*sc->write_register)( rp, SONIC_REG_DCR2, sc->dc2_value ); (*sc->write_register)( rp, SONIC_REG_CR, CR_STP | CR_RXDIS | CR_HTX ); /* * Mask all interrupts */ (*sc->write_register)( rp, SONIC_REG_IMR, 0x0 ); /* XXX was backwards */ /* * Clear outstanding interrupts. */ (*sc->write_register)( rp, SONIC_REG_ISR, 0x7FFF ); /* * Clear the tally counters */ (*sc->write_register)( rp, SONIC_REG_CRCT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_FAET, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_MPT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_RSC, 0 ); /* * Set the Receiver mode * * Enable/disable reception of broadcast packets */ if (sc->acceptBroadcast) (*sc->write_register)( rp, SONIC_REG_RCR, RCR_BRD ); else (*sc->write_register)( rp, SONIC_REG_RCR, 0 ); /* * Set up Resource Area pointers */ (*sc->write_register)( rp, SONIC_REG_URRA, MSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RSA, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_REA, LSW(sc->rea) ); (*sc->write_register)( rp, SONIC_REG_RRP, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RWP, LSW(sc->rsa) ); /* XXX was rea */ (*sc->write_register)( rp, SONIC_REG_URDA, MSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_CRDA, LSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_UTDA, MSW(sc->tdaTail) ); (*sc->write_register)( rp, SONIC_REG_CTDA, LSW(sc->tdaTail) ); /* * Set End Of Buffer Count register to the value recommended * in Note 1 of Section 3.4.4.4 of the SONIC data sheet. */ (*sc->write_register)( rp, SONIC_REG_EOBC, RBUF_WC - 2 ); /* * Issue the load RRA command */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RRRA ); while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_RRRA) continue; /* * Remove device reset */ (*sc->write_register)( rp, SONIC_REG_CR, 0 ); /* * Set up the SONIC CAM with our hardware address. */ hwaddr = sc->arpcom.ac_enaddr; cdp = sc->cdp;#if (SONIC_DEBUG & SONIC_DEBUG_CAM) printf( "hwaddr: %2x:%2x:%2x:%2x:%2x:%2x\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5] );#endif cdp->cep = 0; /* Fill first and only entry in CAM */ cdp->cap0 = hwaddr[1] << 8 | hwaddr[0]; cdp->cap1 = hwaddr[3] << 8 | hwaddr[2]; cdp->cap2 = hwaddr[5] << 8 | hwaddr[4]; cdp->ce = 0x0001; /* Enable first entry in CAM */ (*sc->write_register)( rp, SONIC_REG_CDC, 1 ); /* 1 entry in CDA */ (*sc->write_register)( rp, SONIC_REG_CDP, LSW(cdp) ); (*sc->write_register)( rp, SONIC_REG_CR, CR_LCAM ); /* Load the CAM */ while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_LCAM) continue; /* * Verify that CAM was properly loaded. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX );#if (SONIC_DEBUG & SONIC_DEBUG_CAM) (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ printf ("Loaded Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE ));#endif (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ if (((*sc->read_register)( rp, SONIC_REG_CAP2 ) != cdp->cap2) || ((*sc->read_register)( rp, SONIC_REG_CAP1 ) != cdp->cap1) || ((*sc->read_register)( rp, SONIC_REG_CAP0 ) != cdp->cap0) || ((*sc->read_register)( rp, SONIC_REG_CE ) != cdp->ce)) { printf ("Failed to load Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE )); rtems_panic ("SONIC LCAM"); } (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */CR_RXEN | CR_STP); /* * Attach SONIC interrupt handler *//* XXX (*sc->write_register)( rp, SONIC_REG_IMR, 0 );*/ old_handler = set_vector(sonic_interrupt_handler, sc->vector, 1); /* * Remainder of hardware initialization is * done by the receive and transmit daemons. */}
if (i & 1)
if (i & 3)
SONIC_STATIC void sonic_initialize_hardware(struct sonic_softc *sc){ void *rp = sc->sonic; int i; unsigned char *hwaddr; rtems_isr_entry old_handler; TransmitDescriptorPointer_t tdp; ReceiveDescriptorPointer_t ordp, rdp; ReceiveResourcePointer_t rwp; struct mbuf *m; void *p; CamDescriptorPointer_t cdp; /* * The Revision B SONIC has a horrible bug known as the "Zero * Length Packet bug". The initial board used to develop this * driver had a newer revision of the SONIC so there was no reason * to check for this. If you have the Revision B SONIC chip, then * you need to add some code to the RX path to handle this weirdness. */ if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) { rtems_fatal_error_occurred( 0x0BADF00D ); /* don't eat this part :) */ } /* * Set up circular linked list in Transmit Descriptor Area. * Use the PINT bit in the transmit configuration field to * request an interrupt on every other transmitted packet. * * NOTE: sonic_allocate() zeroes all of the memory allocated. */ sc->tdaActiveCount = 0; sc->tdaTail = sonic_allocate(sc->tdaCount * sizeof *tdp);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "tdaTail = %p\n", sc->tdaTail );#endif tdp = sc->tdaTail; for (i = 0 ; i < sc->tdaCount ; i++) { /* * Start off with the table of outstanding mbuf's */ /* * status, pkt_config, pkt_size, and all fragment fields * are set to zero by sonic_allocate. *//* XXX not used by the BSD drivers*/ if (i & 1) tdp->pkt_config = TDA_CONFIG_PINT; tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_tx_descriptor( tdp );#endif tdp++; } tdp--; sc->tdaHead = tdp; tdp->link_pad = LSW(sc->tdaTail) | TDA_LINK_EOL; tdp->next = (TransmitDescriptor_t *)sc->tdaTail; tdp->linkp = &sc->tdaTail->frag[0].frag_link; /* * Set up circular linked list in Receive Descriptor Area. * Leaves sc->rda pointing at the `beginning' of the list. * * NOTE: The RDA and CDP must have the same MSW for their addresses. */ sc->rda = sonic_allocate( (sc->rdaCount * sizeof(ReceiveDescriptor_t)) + sizeof(CamDescriptor_t) ); sc->cdp = (CamDescriptorPointer_t) ((unsigned char *)sc->rda + (sc->rdaCount * sizeof(ReceiveDescriptor_t)));#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rda area = %p\n", sc->rda ); printf( "cdp area = %p\n", sc->cdp );#endif ordp = rdp = sc->rda; for (i = 0 ; i < sc->rdaCount ; i++) { /* * status, byte_count, pkt_ptr0, pkt_ptr1, and seq_no are set * to zero by sonic_allocate. */ rdp->link = LSW(rdp + 1); rdp->in_use = RDA_FREE; rdp->next = (ReceiveDescriptor_t *)(rdp + 1); ordp = rdp; rdp++; } /* * Link the last desriptor to the 1st one and mark it as the end * of the list. */ ordp->next = sc->rda; ordp->link = LSW(sc->rda) | RDA_LINK_EOL; sc->rdp_last = rdp; /* * Allocate the receive resource area. * In accordance with National Application Note 746, make the * receive resource area bigger than the receive descriptor area. * This has the useful side effect of making the receive resource * area big enough to hold the CAM descriptor area. */ sc->rsa = sonic_allocate((sc->rdaCount + RRA_EXTRA_COUNT) * sizeof *sc->rsa);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rsa area = %p\n", sc->rsa );#endif /* * Set up list in Receive Resource Area. * Allocate space for incoming packets. */ rwp = sc->rsa; for (i = 0 ; i < (sc->rdaCount + RRA_EXTRA_COUNT) ; i++, rwp++) { /* * Allocate memory for buffer. * Place a pointer to the mbuf at the beginning of the buffer * so we can find the mbuf when the SONIC returns the buffer * to the driver. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = &sc->arpcom.ac_if; sc->rda[i].mbufp = m; p = mtod (m, void *); /* * Set up RRA entry */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( &sc->rda[i] );#endif } sc->rea = rwp;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rea area = %p\n", sc->rea );#endif /* * Issue a software reset. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX ); /* * Set up data configuration registers. */ (*sc->write_register)( rp, SONIC_REG_DCR, sc->dcr_value ); (*sc->write_register)( rp, SONIC_REG_DCR2, sc->dc2_value ); (*sc->write_register)( rp, SONIC_REG_CR, CR_STP | CR_RXDIS | CR_HTX ); /* * Mask all interrupts */ (*sc->write_register)( rp, SONIC_REG_IMR, 0x0 ); /* XXX was backwards */ /* * Clear outstanding interrupts. */ (*sc->write_register)( rp, SONIC_REG_ISR, 0x7FFF ); /* * Clear the tally counters */ (*sc->write_register)( rp, SONIC_REG_CRCT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_FAET, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_MPT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_RSC, 0 ); /* * Set the Receiver mode * * Enable/disable reception of broadcast packets */ if (sc->acceptBroadcast) (*sc->write_register)( rp, SONIC_REG_RCR, RCR_BRD ); else (*sc->write_register)( rp, SONIC_REG_RCR, 0 ); /* * Set up Resource Area pointers */ (*sc->write_register)( rp, SONIC_REG_URRA, MSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RSA, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_REA, LSW(sc->rea) ); (*sc->write_register)( rp, SONIC_REG_RRP, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RWP, LSW(sc->rsa) ); /* XXX was rea */ (*sc->write_register)( rp, SONIC_REG_URDA, MSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_CRDA, LSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_UTDA, MSW(sc->tdaTail) ); (*sc->write_register)( rp, SONIC_REG_CTDA, LSW(sc->tdaTail) ); /* * Set End Of Buffer Count register to the value recommended * in Note 1 of Section 3.4.4.4 of the SONIC data sheet. */ (*sc->write_register)( rp, SONIC_REG_EOBC, RBUF_WC - 2 ); /* * Issue the load RRA command */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RRRA ); while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_RRRA) continue; /* * Remove device reset */ (*sc->write_register)( rp, SONIC_REG_CR, 0 ); /* * Set up the SONIC CAM with our hardware address. */ hwaddr = sc->arpcom.ac_enaddr; cdp = sc->cdp;#if (SONIC_DEBUG & SONIC_DEBUG_CAM) printf( "hwaddr: %2x:%2x:%2x:%2x:%2x:%2x\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5] );#endif cdp->cep = 0; /* Fill first and only entry in CAM */ cdp->cap0 = hwaddr[1] << 8 | hwaddr[0]; cdp->cap1 = hwaddr[3] << 8 | hwaddr[2]; cdp->cap2 = hwaddr[5] << 8 | hwaddr[4]; cdp->ce = 0x0001; /* Enable first entry in CAM */ (*sc->write_register)( rp, SONIC_REG_CDC, 1 ); /* 1 entry in CDA */ (*sc->write_register)( rp, SONIC_REG_CDP, LSW(cdp) ); (*sc->write_register)( rp, SONIC_REG_CR, CR_LCAM ); /* Load the CAM */ while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_LCAM) continue; /* * Verify that CAM was properly loaded. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX );#if (SONIC_DEBUG & SONIC_DEBUG_CAM) (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ printf ("Loaded Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE ));#endif (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ if (((*sc->read_register)( rp, SONIC_REG_CAP2 ) != cdp->cap2) || ((*sc->read_register)( rp, SONIC_REG_CAP1 ) != cdp->cap1) || ((*sc->read_register)( rp, SONIC_REG_CAP0 ) != cdp->cap0) || ((*sc->read_register)( rp, SONIC_REG_CE ) != cdp->ce)) { printf ("Failed to load Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE )); rtems_panic ("SONIC LCAM"); } (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */CR_RXEN | CR_STP); /* * Attach SONIC interrupt handler *//* XXX (*sc->write_register)( rp, SONIC_REG_IMR, 0 );*/ old_handler = set_vector(sonic_interrupt_handler, sc->vector, 1); /* * Remainder of hardware initialization is * done by the receive and transmit daemons. */}
tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);
tdp->status = 0; tdp->frag_count = 0; tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);
SONIC_STATIC void sonic_initialize_hardware(struct sonic_softc *sc){ void *rp = sc->sonic; int i; unsigned char *hwaddr; rtems_isr_entry old_handler; TransmitDescriptorPointer_t tdp; ReceiveDescriptorPointer_t ordp, rdp; ReceiveResourcePointer_t rwp; struct mbuf *m; void *p; CamDescriptorPointer_t cdp; /* * The Revision B SONIC has a horrible bug known as the "Zero * Length Packet bug". The initial board used to develop this * driver had a newer revision of the SONIC so there was no reason * to check for this. If you have the Revision B SONIC chip, then * you need to add some code to the RX path to handle this weirdness. */ if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) { rtems_fatal_error_occurred( 0x0BADF00D ); /* don't eat this part :) */ } /* * Set up circular linked list in Transmit Descriptor Area. * Use the PINT bit in the transmit configuration field to * request an interrupt on every other transmitted packet. * * NOTE: sonic_allocate() zeroes all of the memory allocated. */ sc->tdaActiveCount = 0; sc->tdaTail = sonic_allocate(sc->tdaCount * sizeof *tdp);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "tdaTail = %p\n", sc->tdaTail );#endif tdp = sc->tdaTail; for (i = 0 ; i < sc->tdaCount ; i++) { /* * Start off with the table of outstanding mbuf's */ /* * status, pkt_config, pkt_size, and all fragment fields * are set to zero by sonic_allocate. *//* XXX not used by the BSD drivers*/ if (i & 1) tdp->pkt_config = TDA_CONFIG_PINT; tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_tx_descriptor( tdp );#endif tdp++; } tdp--; sc->tdaHead = tdp; tdp->link_pad = LSW(sc->tdaTail) | TDA_LINK_EOL; tdp->next = (TransmitDescriptor_t *)sc->tdaTail; tdp->linkp = &sc->tdaTail->frag[0].frag_link; /* * Set up circular linked list in Receive Descriptor Area. * Leaves sc->rda pointing at the `beginning' of the list. * * NOTE: The RDA and CDP must have the same MSW for their addresses. */ sc->rda = sonic_allocate( (sc->rdaCount * sizeof(ReceiveDescriptor_t)) + sizeof(CamDescriptor_t) ); sc->cdp = (CamDescriptorPointer_t) ((unsigned char *)sc->rda + (sc->rdaCount * sizeof(ReceiveDescriptor_t)));#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rda area = %p\n", sc->rda ); printf( "cdp area = %p\n", sc->cdp );#endif ordp = rdp = sc->rda; for (i = 0 ; i < sc->rdaCount ; i++) { /* * status, byte_count, pkt_ptr0, pkt_ptr1, and seq_no are set * to zero by sonic_allocate. */ rdp->link = LSW(rdp + 1); rdp->in_use = RDA_FREE; rdp->next = (ReceiveDescriptor_t *)(rdp + 1); ordp = rdp; rdp++; } /* * Link the last desriptor to the 1st one and mark it as the end * of the list. */ ordp->next = sc->rda; ordp->link = LSW(sc->rda) | RDA_LINK_EOL; sc->rdp_last = rdp; /* * Allocate the receive resource area. * In accordance with National Application Note 746, make the * receive resource area bigger than the receive descriptor area. * This has the useful side effect of making the receive resource * area big enough to hold the CAM descriptor area. */ sc->rsa = sonic_allocate((sc->rdaCount + RRA_EXTRA_COUNT) * sizeof *sc->rsa);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rsa area = %p\n", sc->rsa );#endif /* * Set up list in Receive Resource Area. * Allocate space for incoming packets. */ rwp = sc->rsa; for (i = 0 ; i < (sc->rdaCount + RRA_EXTRA_COUNT) ; i++, rwp++) { /* * Allocate memory for buffer. * Place a pointer to the mbuf at the beginning of the buffer * so we can find the mbuf when the SONIC returns the buffer * to the driver. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = &sc->arpcom.ac_if; sc->rda[i].mbufp = m; p = mtod (m, void *); /* * Set up RRA entry */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( &sc->rda[i] );#endif } sc->rea = rwp;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rea area = %p\n", sc->rea );#endif /* * Issue a software reset. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX ); /* * Set up data configuration registers. */ (*sc->write_register)( rp, SONIC_REG_DCR, sc->dcr_value ); (*sc->write_register)( rp, SONIC_REG_DCR2, sc->dc2_value ); (*sc->write_register)( rp, SONIC_REG_CR, CR_STP | CR_RXDIS | CR_HTX ); /* * Mask all interrupts */ (*sc->write_register)( rp, SONIC_REG_IMR, 0x0 ); /* XXX was backwards */ /* * Clear outstanding interrupts. */ (*sc->write_register)( rp, SONIC_REG_ISR, 0x7FFF ); /* * Clear the tally counters */ (*sc->write_register)( rp, SONIC_REG_CRCT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_FAET, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_MPT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_RSC, 0 ); /* * Set the Receiver mode * * Enable/disable reception of broadcast packets */ if (sc->acceptBroadcast) (*sc->write_register)( rp, SONIC_REG_RCR, RCR_BRD ); else (*sc->write_register)( rp, SONIC_REG_RCR, 0 ); /* * Set up Resource Area pointers */ (*sc->write_register)( rp, SONIC_REG_URRA, MSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RSA, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_REA, LSW(sc->rea) ); (*sc->write_register)( rp, SONIC_REG_RRP, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RWP, LSW(sc->rsa) ); /* XXX was rea */ (*sc->write_register)( rp, SONIC_REG_URDA, MSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_CRDA, LSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_UTDA, MSW(sc->tdaTail) ); (*sc->write_register)( rp, SONIC_REG_CTDA, LSW(sc->tdaTail) ); /* * Set End Of Buffer Count register to the value recommended * in Note 1 of Section 3.4.4.4 of the SONIC data sheet. */ (*sc->write_register)( rp, SONIC_REG_EOBC, RBUF_WC - 2 ); /* * Issue the load RRA command */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RRRA ); while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_RRRA) continue; /* * Remove device reset */ (*sc->write_register)( rp, SONIC_REG_CR, 0 ); /* * Set up the SONIC CAM with our hardware address. */ hwaddr = sc->arpcom.ac_enaddr; cdp = sc->cdp;#if (SONIC_DEBUG & SONIC_DEBUG_CAM) printf( "hwaddr: %2x:%2x:%2x:%2x:%2x:%2x\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5] );#endif cdp->cep = 0; /* Fill first and only entry in CAM */ cdp->cap0 = hwaddr[1] << 8 | hwaddr[0]; cdp->cap1 = hwaddr[3] << 8 | hwaddr[2]; cdp->cap2 = hwaddr[5] << 8 | hwaddr[4]; cdp->ce = 0x0001; /* Enable first entry in CAM */ (*sc->write_register)( rp, SONIC_REG_CDC, 1 ); /* 1 entry in CDA */ (*sc->write_register)( rp, SONIC_REG_CDP, LSW(cdp) ); (*sc->write_register)( rp, SONIC_REG_CR, CR_LCAM ); /* Load the CAM */ while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_LCAM) continue; /* * Verify that CAM was properly loaded. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX );#if (SONIC_DEBUG & SONIC_DEBUG_CAM) (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ printf ("Loaded Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE ));#endif (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ if (((*sc->read_register)( rp, SONIC_REG_CAP2 ) != cdp->cap2) || ((*sc->read_register)( rp, SONIC_REG_CAP1 ) != cdp->cap1) || ((*sc->read_register)( rp, SONIC_REG_CAP0 ) != cdp->cap0) || ((*sc->read_register)( rp, SONIC_REG_CE ) != cdp->ce)) { printf ("Failed to load Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE )); rtems_panic ("SONIC LCAM"); } (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */CR_RXEN | CR_STP); /* * Attach SONIC interrupt handler *//* XXX (*sc->write_register)( rp, SONIC_REG_IMR, 0 );*/ old_handler = set_vector(sonic_interrupt_handler, sc->vector, 1); /* * Remainder of hardware initialization is * done by the receive and transmit daemons. */}
sc->rdp_last = rdp;
sc->rdp_last = ordp;
SONIC_STATIC void sonic_initialize_hardware(struct sonic_softc *sc){ void *rp = sc->sonic; int i; unsigned char *hwaddr; rtems_isr_entry old_handler; TransmitDescriptorPointer_t tdp; ReceiveDescriptorPointer_t ordp, rdp; ReceiveResourcePointer_t rwp; struct mbuf *m; void *p; CamDescriptorPointer_t cdp; /* * The Revision B SONIC has a horrible bug known as the "Zero * Length Packet bug". The initial board used to develop this * driver had a newer revision of the SONIC so there was no reason * to check for this. If you have the Revision B SONIC chip, then * you need to add some code to the RX path to handle this weirdness. */ if ( (*sc->read_register)( rp, SONIC_REG_SR ) < SONIC_REVISION_C ) { rtems_fatal_error_occurred( 0x0BADF00D ); /* don't eat this part :) */ } /* * Set up circular linked list in Transmit Descriptor Area. * Use the PINT bit in the transmit configuration field to * request an interrupt on every other transmitted packet. * * NOTE: sonic_allocate() zeroes all of the memory allocated. */ sc->tdaActiveCount = 0; sc->tdaTail = sonic_allocate(sc->tdaCount * sizeof *tdp);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "tdaTail = %p\n", sc->tdaTail );#endif tdp = sc->tdaTail; for (i = 0 ; i < sc->tdaCount ; i++) { /* * Start off with the table of outstanding mbuf's */ /* * status, pkt_config, pkt_size, and all fragment fields * are set to zero by sonic_allocate. *//* XXX not used by the BSD drivers*/ if (i & 1) tdp->pkt_config = TDA_CONFIG_PINT; tdp->frag_count = 0; tdp->frag[0].frag_link = LSW(tdp + 1); tdp->link_pad = LSW(tdp + 1) | TDA_LINK_EOL; tdp->linkp = &((tdp + 1)->frag[0].frag_link); tdp->next = (TransmitDescriptor_t *)(tdp + 1);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_tx_descriptor( tdp );#endif tdp++; } tdp--; sc->tdaHead = tdp; tdp->link_pad = LSW(sc->tdaTail) | TDA_LINK_EOL; tdp->next = (TransmitDescriptor_t *)sc->tdaTail; tdp->linkp = &sc->tdaTail->frag[0].frag_link; /* * Set up circular linked list in Receive Descriptor Area. * Leaves sc->rda pointing at the `beginning' of the list. * * NOTE: The RDA and CDP must have the same MSW for their addresses. */ sc->rda = sonic_allocate( (sc->rdaCount * sizeof(ReceiveDescriptor_t)) + sizeof(CamDescriptor_t) ); sc->cdp = (CamDescriptorPointer_t) ((unsigned char *)sc->rda + (sc->rdaCount * sizeof(ReceiveDescriptor_t)));#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rda area = %p\n", sc->rda ); printf( "cdp area = %p\n", sc->cdp );#endif ordp = rdp = sc->rda; for (i = 0 ; i < sc->rdaCount ; i++) { /* * status, byte_count, pkt_ptr0, pkt_ptr1, and seq_no are set * to zero by sonic_allocate. */ rdp->link = LSW(rdp + 1); rdp->in_use = RDA_FREE; rdp->next = (ReceiveDescriptor_t *)(rdp + 1); ordp = rdp; rdp++; } /* * Link the last desriptor to the 1st one and mark it as the end * of the list. */ ordp->next = sc->rda; ordp->link = LSW(sc->rda) | RDA_LINK_EOL; sc->rdp_last = rdp; /* * Allocate the receive resource area. * In accordance with National Application Note 746, make the * receive resource area bigger than the receive descriptor area. * This has the useful side effect of making the receive resource * area big enough to hold the CAM descriptor area. */ sc->rsa = sonic_allocate((sc->rdaCount + RRA_EXTRA_COUNT) * sizeof *sc->rsa);#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rsa area = %p\n", sc->rsa );#endif /* * Set up list in Receive Resource Area. * Allocate space for incoming packets. */ rwp = sc->rsa; for (i = 0 ; i < (sc->rdaCount + RRA_EXTRA_COUNT) ; i++, rwp++) { /* * Allocate memory for buffer. * Place a pointer to the mbuf at the beginning of the buffer * so we can find the mbuf when the SONIC returns the buffer * to the driver. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = &sc->arpcom.ac_if; sc->rda[i].mbufp = m; p = mtod (m, void *); /* * Set up RRA entry */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( &sc->rda[i] );#endif } sc->rea = rwp;#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "rea area = %p\n", sc->rea );#endif /* * Issue a software reset. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX ); /* * Set up data configuration registers. */ (*sc->write_register)( rp, SONIC_REG_DCR, sc->dcr_value ); (*sc->write_register)( rp, SONIC_REG_DCR2, sc->dc2_value ); (*sc->write_register)( rp, SONIC_REG_CR, CR_STP | CR_RXDIS | CR_HTX ); /* * Mask all interrupts */ (*sc->write_register)( rp, SONIC_REG_IMR, 0x0 ); /* XXX was backwards */ /* * Clear outstanding interrupts. */ (*sc->write_register)( rp, SONIC_REG_ISR, 0x7FFF ); /* * Clear the tally counters */ (*sc->write_register)( rp, SONIC_REG_CRCT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_FAET, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_MPT, 0xFFFF ); (*sc->write_register)( rp, SONIC_REG_RSC, 0 ); /* * Set the Receiver mode * * Enable/disable reception of broadcast packets */ if (sc->acceptBroadcast) (*sc->write_register)( rp, SONIC_REG_RCR, RCR_BRD ); else (*sc->write_register)( rp, SONIC_REG_RCR, 0 ); /* * Set up Resource Area pointers */ (*sc->write_register)( rp, SONIC_REG_URRA, MSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RSA, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_REA, LSW(sc->rea) ); (*sc->write_register)( rp, SONIC_REG_RRP, LSW(sc->rsa) ); (*sc->write_register)( rp, SONIC_REG_RWP, LSW(sc->rsa) ); /* XXX was rea */ (*sc->write_register)( rp, SONIC_REG_URDA, MSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_CRDA, LSW(sc->rda) ); (*sc->write_register)( rp, SONIC_REG_UTDA, MSW(sc->tdaTail) ); (*sc->write_register)( rp, SONIC_REG_CTDA, LSW(sc->tdaTail) ); /* * Set End Of Buffer Count register to the value recommended * in Note 1 of Section 3.4.4.4 of the SONIC data sheet. */ (*sc->write_register)( rp, SONIC_REG_EOBC, RBUF_WC - 2 ); /* * Issue the load RRA command */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RRRA ); while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_RRRA) continue; /* * Remove device reset */ (*sc->write_register)( rp, SONIC_REG_CR, 0 ); /* * Set up the SONIC CAM with our hardware address. */ hwaddr = sc->arpcom.ac_enaddr; cdp = sc->cdp;#if (SONIC_DEBUG & SONIC_DEBUG_CAM) printf( "hwaddr: %2x:%2x:%2x:%2x:%2x:%2x\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5] );#endif cdp->cep = 0; /* Fill first and only entry in CAM */ cdp->cap0 = hwaddr[1] << 8 | hwaddr[0]; cdp->cap1 = hwaddr[3] << 8 | hwaddr[2]; cdp->cap2 = hwaddr[5] << 8 | hwaddr[4]; cdp->ce = 0x0001; /* Enable first entry in CAM */ (*sc->write_register)( rp, SONIC_REG_CDC, 1 ); /* 1 entry in CDA */ (*sc->write_register)( rp, SONIC_REG_CDP, LSW(cdp) ); (*sc->write_register)( rp, SONIC_REG_CR, CR_LCAM ); /* Load the CAM */ while ((*sc->read_register)( rp, SONIC_REG_CR ) & CR_LCAM) continue; /* * Verify that CAM was properly loaded. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_RST | CR_STP | CR_RXDIS | CR_HTX );#if (SONIC_DEBUG & SONIC_DEBUG_CAM) (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ printf ("Loaded Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE ));#endif (*sc->write_register)( rp, SONIC_REG_CEP, 0 ); /* Select first entry in CAM */ if (((*sc->read_register)( rp, SONIC_REG_CAP2 ) != cdp->cap2) || ((*sc->read_register)( rp, SONIC_REG_CAP1 ) != cdp->cap1) || ((*sc->read_register)( rp, SONIC_REG_CAP0 ) != cdp->cap0) || ((*sc->read_register)( rp, SONIC_REG_CE ) != cdp->ce)) { printf ("Failed to load Ethernet address into SONIC CAM.\n" " Wrote %04x%04x%04x - %#x\n" " Read %04x%04x%04x - %#x\n", cdp->cap2, cdp->cap1, cdp->cap0, cdp->ce, (*sc->read_register)( rp, SONIC_REG_CAP2 ), (*sc->read_register)( rp, SONIC_REG_CAP1 ), (*sc->read_register)( rp, SONIC_REG_CAP0 ), (*sc->read_register)( rp, SONIC_REG_CE )); rtems_panic ("SONIC LCAM"); } (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */CR_RXEN | CR_STP); /* * Attach SONIC interrupt handler *//* XXX (*sc->write_register)( rp, SONIC_REG_IMR, 0 );*/ old_handler = set_vector(sonic_interrupt_handler, sc->vector, 1); /* * Remainder of hardware initialization is * done by the receive and transmit daemons. */}
(*sc->write_register)( rp, SONIC_REG_ISR, ISR_RBE );
sonic_clear_interrupts( sc, ISR_RBE );
SONIC_STATIC void sonic_rxDaemon (void *arg){ struct sonic_softc *sc = (struct sonic_softc *)arg; struct ifnet *ifp = &sc->arpcom.ac_if; void *rp = sc->sonic; struct mbuf *m; rtems_unsigned16 status; ReceiveDescriptorPointer_t rdp; ReceiveResourcePointer_t rwp, rea; rtems_unsigned16 newMissedTally, oldMissedTally; rwp = sc->rsa; rea = sc->rea; rdp = sc->rda; /* * Start the receiver */ oldMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); /* * Input packet handling loop */ for (;;) { /* * Wait till SONIC supplies a Receive Descriptor. */ if (rdp->in_use == RDA_FREE) { sonic_rda_wait (sc, rdp); }#if (SONIC_DEBUG & SONIC_DEBUG_DESCRIPTORS) printf( "Incoming packet %p status=0x%04x\n", rdp, rdp->status );#endif /* * Check that packet is valid */ status = rdp->status; if (status & RDA_STATUS_PRX) { struct ether_header *eh; void *p; /* * Pass the packet up the chain. * The mbuf count is reduced to remove * the frame check sequence at the end * of the packet. * ===CACHE=== * Invalidate cache entries for this memory. */#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( rdp );#endif m = rdp->mbufp; m->m_len = m->m_pkthdr.len = rdp->byte_count - sizeof(rtems_unsigned32) - sizeof(struct ether_header); eh = mtod (m, struct ether_header *); m->m_data += sizeof(struct ether_header); #if (SONIC_DEBUG & SONIC_DEBUG_DUMP_RX_MBUFS) Dump_Buffer( (void *) eh, sizeof(struct ether_header) ); Dump_Buffer( (void *) m, 96 /* m->m_len*/ );#endif /* printf( "ether_input %p\n", m ); */ ether_input (ifp, eh, m); /* * Sanity check that Receive Resource Area is * still in sync with Receive Descriptor Area * The buffer reported in the Receive Descriptor * should be the same as the buffer in the Receive * Resource we are about to reuse. *//* XXX figure out whether this is valid or not */#if 0 if ((LSW(p) != rwp->buff_ptr_lsw) || (MSW(p) != rwp->buff_ptr_msw)) rtems_panic ("SONIC RDA/RRA");#endif /* * Allocate a new mbuf. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = ifp; rdp->mbufp = m; p = mtod (m, void *); /* * Reuse Receive Resource. */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0; rwp++; if (rwp == rea) {#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "Wrapping RWP from %p to %p\n", rwp, sc->rsa );#endif rwp = sc->rsa; } (*sc->write_register)( rp, SONIC_REG_RWP , LSW(rwp) ); /* * Tell the SONIC to reread the RRA. */ if ((*sc->read_register)( rp, SONIC_REG_ISR ) & ISR_RBE) (*sc->write_register)( rp, SONIC_REG_ISR, ISR_RBE ); } else { if (status & RDA_STATUS_COL) sc->rxCollision++; if (status & RDA_STATUS_FAER) sc->rxNonOctet++; else if (status & RDA_STATUS_CRCR) sc->rxBadCRC++; } /* * Count missed packets */ newMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); if (newMissedTally != oldMissedTally) { sc->rxMissed += (newMissedTally - oldMissedTally) & 0xFFFF; newMissedTally = oldMissedTally; } /* * Move to next receive descriptor */ rdp->in_use = RDA_FREE; rdp = rdp->next; rdp->link &= ~RDA_LINK_EOL; }}
* Move to next receive descriptor
* Move to next receive descriptor and update EOL
SONIC_STATIC void sonic_rxDaemon (void *arg){ struct sonic_softc *sc = (struct sonic_softc *)arg; struct ifnet *ifp = &sc->arpcom.ac_if; void *rp = sc->sonic; struct mbuf *m; rtems_unsigned16 status; ReceiveDescriptorPointer_t rdp; ReceiveResourcePointer_t rwp, rea; rtems_unsigned16 newMissedTally, oldMissedTally; rwp = sc->rsa; rea = sc->rea; rdp = sc->rda; /* * Start the receiver */ oldMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); /* * Input packet handling loop */ for (;;) { /* * Wait till SONIC supplies a Receive Descriptor. */ if (rdp->in_use == RDA_FREE) { sonic_rda_wait (sc, rdp); }#if (SONIC_DEBUG & SONIC_DEBUG_DESCRIPTORS) printf( "Incoming packet %p status=0x%04x\n", rdp, rdp->status );#endif /* * Check that packet is valid */ status = rdp->status; if (status & RDA_STATUS_PRX) { struct ether_header *eh; void *p; /* * Pass the packet up the chain. * The mbuf count is reduced to remove * the frame check sequence at the end * of the packet. * ===CACHE=== * Invalidate cache entries for this memory. */#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( rdp );#endif m = rdp->mbufp; m->m_len = m->m_pkthdr.len = rdp->byte_count - sizeof(rtems_unsigned32) - sizeof(struct ether_header); eh = mtod (m, struct ether_header *); m->m_data += sizeof(struct ether_header); #if (SONIC_DEBUG & SONIC_DEBUG_DUMP_RX_MBUFS) Dump_Buffer( (void *) eh, sizeof(struct ether_header) ); Dump_Buffer( (void *) m, 96 /* m->m_len*/ );#endif /* printf( "ether_input %p\n", m ); */ ether_input (ifp, eh, m); /* * Sanity check that Receive Resource Area is * still in sync with Receive Descriptor Area * The buffer reported in the Receive Descriptor * should be the same as the buffer in the Receive * Resource we are about to reuse. *//* XXX figure out whether this is valid or not */#if 0 if ((LSW(p) != rwp->buff_ptr_lsw) || (MSW(p) != rwp->buff_ptr_msw)) rtems_panic ("SONIC RDA/RRA");#endif /* * Allocate a new mbuf. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = ifp; rdp->mbufp = m; p = mtod (m, void *); /* * Reuse Receive Resource. */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0; rwp++; if (rwp == rea) {#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "Wrapping RWP from %p to %p\n", rwp, sc->rsa );#endif rwp = sc->rsa; } (*sc->write_register)( rp, SONIC_REG_RWP , LSW(rwp) ); /* * Tell the SONIC to reread the RRA. */ if ((*sc->read_register)( rp, SONIC_REG_ISR ) & ISR_RBE) (*sc->write_register)( rp, SONIC_REG_ISR, ISR_RBE ); } else { if (status & RDA_STATUS_COL) sc->rxCollision++; if (status & RDA_STATUS_FAER) sc->rxNonOctet++; else if (status & RDA_STATUS_CRCR) sc->rxBadCRC++; } /* * Count missed packets */ newMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); if (newMissedTally != oldMissedTally) { sc->rxMissed += (newMissedTally - oldMissedTally) & 0xFFFF; newMissedTally = oldMissedTally; } /* * Move to next receive descriptor */ rdp->in_use = RDA_FREE; rdp = rdp->next; rdp->link &= ~RDA_LINK_EOL; }}
rdp->link &= ~RDA_LINK_EOL;
SONIC_STATIC void sonic_rxDaemon (void *arg){ struct sonic_softc *sc = (struct sonic_softc *)arg; struct ifnet *ifp = &sc->arpcom.ac_if; void *rp = sc->sonic; struct mbuf *m; rtems_unsigned16 status; ReceiveDescriptorPointer_t rdp; ReceiveResourcePointer_t rwp, rea; rtems_unsigned16 newMissedTally, oldMissedTally; rwp = sc->rsa; rea = sc->rea; rdp = sc->rda; /* * Start the receiver */ oldMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); /* * Input packet handling loop */ for (;;) { /* * Wait till SONIC supplies a Receive Descriptor. */ if (rdp->in_use == RDA_FREE) { sonic_rda_wait (sc, rdp); }#if (SONIC_DEBUG & SONIC_DEBUG_DESCRIPTORS) printf( "Incoming packet %p status=0x%04x\n", rdp, rdp->status );#endif /* * Check that packet is valid */ status = rdp->status; if (status & RDA_STATUS_PRX) { struct ether_header *eh; void *p; /* * Pass the packet up the chain. * The mbuf count is reduced to remove * the frame check sequence at the end * of the packet. * ===CACHE=== * Invalidate cache entries for this memory. */#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY_DESCRIPTORS) sonic_print_rx_descriptor( rdp );#endif m = rdp->mbufp; m->m_len = m->m_pkthdr.len = rdp->byte_count - sizeof(rtems_unsigned32) - sizeof(struct ether_header); eh = mtod (m, struct ether_header *); m->m_data += sizeof(struct ether_header); #if (SONIC_DEBUG & SONIC_DEBUG_DUMP_RX_MBUFS) Dump_Buffer( (void *) eh, sizeof(struct ether_header) ); Dump_Buffer( (void *) m, 96 /* m->m_len*/ );#endif /* printf( "ether_input %p\n", m ); */ ether_input (ifp, eh, m); /* * Sanity check that Receive Resource Area is * still in sync with Receive Descriptor Area * The buffer reported in the Receive Descriptor * should be the same as the buffer in the Receive * Resource we are about to reuse. *//* XXX figure out whether this is valid or not */#if 0 if ((LSW(p) != rwp->buff_ptr_lsw) || (MSW(p) != rwp->buff_ptr_msw)) rtems_panic ("SONIC RDA/RRA");#endif /* * Allocate a new mbuf. */ MGETHDR (m, M_WAIT, MT_DATA); MCLGET (m, M_WAIT); m->m_pkthdr.rcvif = ifp; rdp->mbufp = m; p = mtod (m, void *); /* * Reuse Receive Resource. */ rwp->buff_ptr_lsw = LSW(p); rwp->buff_ptr_msw = MSW(p); rwp->buff_wc_lsw = RBUF_WC; rwp->buff_wc_msw = 0; rwp++; if (rwp == rea) {#if (SONIC_DEBUG & SONIC_DEBUG_MEMORY) printf( "Wrapping RWP from %p to %p\n", rwp, sc->rsa );#endif rwp = sc->rsa; } (*sc->write_register)( rp, SONIC_REG_RWP , LSW(rwp) ); /* * Tell the SONIC to reread the RRA. */ if ((*sc->read_register)( rp, SONIC_REG_ISR ) & ISR_RBE) (*sc->write_register)( rp, SONIC_REG_ISR, ISR_RBE ); } else { if (status & RDA_STATUS_COL) sc->rxCollision++; if (status & RDA_STATUS_FAER) sc->rxNonOctet++; else if (status & RDA_STATUS_CRCR) sc->rxBadCRC++; } /* * Count missed packets */ newMissedTally = (*sc->read_register)( rp, SONIC_REG_MPT ); if (newMissedTally != oldMissedTally) { sc->rxMissed += (newMissedTally - oldMissedTally) & 0xFFFF; newMissedTally = oldMissedTally; } /* * Move to next receive descriptor */ rdp->in_use = RDA_FREE; rdp = rdp->next; rdp->link &= ~RDA_LINK_EOL; }}
void *rp = sc->sonic;
SONIC_STATIC void sonic_stop (struct sonic_softc *sc){ void *rp = sc->sonic; struct ifnet *ifp = &sc->arpcom.ac_if; ifp->if_flags &= ~IFF_RUNNING; /* * Stop the transmitter and receiver. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_HTX | CR_RXDIS );}
(*sc->write_register)( rp, SONIC_REG_CR, CR_HTX | CR_RXDIS );
sonic_command(sc, CR_HTX | CR_RXDIS );
SONIC_STATIC void sonic_stop (struct sonic_softc *sc){ void *rp = sc->sonic; struct ifnet *ifp = &sc->arpcom.ac_if; ifp->if_flags &= ~IFF_RUNNING; /* * Stop the transmitter and receiver. */ (*sc->write_register)( rp, SONIC_REG_CR, CR_HTX | CR_RXDIS );}