rem
stringlengths 0
83.5k
| add
stringlengths 0
223k
| context
stringlengths 10
471k
| meta
stringlengths 120
236
|
---|---|---|---|
} 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;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/c9df8d8f7cbfac48be82e927354b28848630539c/libio_sockets.c/clean/c/src/exec/libcsupport/src/libio_sockets.c |
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;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/af0200363e8d0a69648bd78fd5ee2d0ee5f40624/rtems_syscall.c/clean/c/src/exec/libnetworking/rtems/rtems_syscall.c |
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);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/2d7d605fdfde31394a46a9bc57f39f20e2f39334/timer.c/clean/c/src/lib/libbsp/i386/pc386/timer/timer.c |
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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3e08d4ee6242f1a0ea4afe9dc0a20800632184fe/rtmonuse.c/buggy/cpukit/libmisc/rtmonuse/rtmonuse.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/396563f37e475af678516ab5fc7a28538411a2d9/polarit3.c/buggy/src/basemath/polarit3.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/396563f37e475af678516ab5fc7a28538411a2d9/polarit3.c/buggy/src/basemath/polarit3.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ | if (DEBUGLEVEL>5) msgtimer("resultant mod %ld (bound 2^%ld)", p,expi(q)); if (expi(q) >= bound) break; /* DONE */ | 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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3e08d4ee6242f1a0ea4afe9dc0a20800632184fe/shell.c/buggy/cpukit/libmisc/shell/shell.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/1558baf8c3b715dd704e6dddf2c7f1f51dc47e84/buch1.c/buggy/src/basemath/buch1.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/1558baf8c3b715dd704e6dddf2c7f1f51dc47e84/buch1.c/buggy/src/basemath/buch1.c |
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,®); /* 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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/57053d514f841efa1b4cd798bf32179239d2d44f/buch2.c/clean/src/basemath/buch2.c |
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,®); /* 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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/57053d514f841efa1b4cd798bf32179239d2d44f/buch2.c/clean/src/basemath/buch2.c |
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,®); /* 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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/57053d514f841efa1b4cd798bf32179239d2d44f/buch2.c/clean/src/basemath/buch2.c |
|
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/7168973a923818508c45aa17d871c53e9225fad1/base2.c/clean/src/basemath/base2.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/7168973a923818508c45aa17d871c53e9225fad1/base2.c/clean/src/basemath/base2.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/7168973a923818508c45aa17d871c53e9225fad1/base2.c/clean/src/basemath/base2.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a359ce125544e6952961f755ac643cf90ca1ccb7/sumiter.c/buggy/src/language/sumiter.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a359ce125544e6952961f755ac643cf90ca1ccb7/sumiter.c/buggy/src/language/sumiter.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a359ce125544e6952961f755ac643cf90ca1ccb7/sumiter.c/buggy/src/language/sumiter.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a359ce125544e6952961f755ac643cf90ca1ccb7/sumiter.c/buggy/src/language/sumiter.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a359ce125544e6952961f755ac643cf90ca1ccb7/sumiter.c/buggy/src/language/sumiter.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/49e7d01f20292f82822521d68c87e4368c94e39d/intnum.c/buggy/src/language/intnum.c |
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); }} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b03001ef86c74799b6280212f7a40aee0823ed89/aprcl.c/clean/src/modules/aprcl.c |
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); }} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b03001ef86c74799b6280212f7a40aee0823ed89/aprcl.c/clean/src/modules/aprcl.c |
_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;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/652524d9538f50e229349314043cedb5a15f18be/mqueueunlink.c/buggy/cpukit/posix/src/mqueueunlink.c |
|
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);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/0b2c943b8c7eb0332df6ca9f0ca4334f9e6a8b78/bspstart.c/clean/c/src/lib/libbsp/m68k/uC5282/startup/bspstart.c |
return( (unsigned32)_CPUClockSpeed); | return( (uint32_t)_CPUClockSpeed); | unsigned32 bsp_get_CPU_clock_speed(void){ extern char _CPUClockSpeed[]; return( (unsigned32)_CPUClockSpeed);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/0b2c943b8c7eb0332df6ca9f0ca4334f9e6a8b78/bspstart.c/clean/c/src/lib/libbsp/m68k/uC5282/startup/bspstart.c |
#ifdef RTEMS_DEBUG rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); #endif | void bsp_libc_init(){ extern int end; rtems_unsigned32 heap_start;#ifdef RTEMS_DEBUG rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );#endif heap_start = (rtems_unsigned32) &end; if (heap_start & (CPU_ALIGNMENT-1)) heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* * Init the RTEMS libio facility to provide UNIX-like system * calls for use by newlib (ie: provide __open, __close, etc) * Uses malloc() to get area for the iops, so must be after malloc init */ rtems_libio_init(); /* * Set up for the libc handling. */ if (BSP_Configuration.ticks_per_timeslice > 0) libc_init(1); /* reentrant if possible */ else libc_init(0); /* non-reentrant */ /* * Initialize the stack bounds checker */#ifdef STACK_CHECKER_ON Stack_check_Initialize();#endif} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3652ad356bf13abe0963c992cbbda96476d31609/bspstart.c/clean/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c |
|
/* * Initialize the stack bounds checker */ #ifdef STACK_CHECKER_ON Stack_check_Initialize(); #endif | void bsp_libc_init(){ extern int end; rtems_unsigned32 heap_start;#ifdef RTEMS_DEBUG rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );#endif heap_start = (rtems_unsigned32) &end; if (heap_start & (CPU_ALIGNMENT-1)) heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* * Init the RTEMS libio facility to provide UNIX-like system * calls for use by newlib (ie: provide __open, __close, etc) * Uses malloc() to get area for the iops, so must be after malloc init */ rtems_libio_init(); /* * Set up for the libc handling. */ if (BSP_Configuration.ticks_per_timeslice > 0) libc_init(1); /* reentrant if possible */ else libc_init(0); /* non-reentrant */ /* * Initialize the stack bounds checker */#ifdef STACK_CHECKER_ON Stack_check_Initialize();#endif} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3652ad356bf13abe0963c992cbbda96476d31609/bspstart.c/clean/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c |
|
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)⪈ 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)≥ goto L2; } goto L1; case '!': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)⪈ 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2c01f3b4cd0756e92b0ec68c965975ebe4e423c1/anal.c/clean/src/language/anal.c |
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)⪈ 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)≥ goto L2; } goto L1; case '!': if (analyseur[1] == '=') { analyseur+=2; f[1]=(PFGEN)⪈ 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2c01f3b4cd0756e92b0ec68c965975ebe4e423c1/anal.c/clean/src/language/anal.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/3d54ff1684e9546785c2b9d2bd99411ef83582db/elliptic.c/buggy/src/modules/elliptic.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/3d54ff1684e9546785c2b9d2bd99411ef83582db/elliptic.c/buggy/src/modules/elliptic.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/3d54ff1684e9546785c2b9d2bd99411ef83582db/elliptic.c/buggy/src/modules/elliptic.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/3d54ff1684e9546785c2b9d2bd99411ef83582db/elliptic.c/buggy/src/modules/elliptic.c |
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();} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/7fbef7863951899f518b70548f508ad618f9ebbd/mqueueunlink.c/clean/c/src/exec/posix/src/mqueueunlink.c |
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();} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/7fbef7863951899f518b70548f508ad618f9ebbd/mqueueunlink.c/clean/c/src/exec/posix/src/mqueueunlink.c |
ab = 1; | void a(){} | 7945 /local/tlutelli/issta_data/temp/c/2005_temp/2005/7945/9dcb87c308d430ab799f788b3498814f92fcfc6b/a.c/buggy/src/test/project1/sub1/a.c |
|
extern int gg; gg = 0; | void b(){ extern int ff; ff = 0;} | 7945 /local/tlutelli/issta_data/temp/c/2005_temp/2005/7945/33690e23354607c3448e82b6f64f5495664c418c/b.c/buggy/src/test/project1/sub1/b.c |
|
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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/c87608fd821faf8c936d9ac51373186cc2f1f4e9/task1.c/buggy/testsuites/sptests/sp20/task1.c |
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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/c87608fd821faf8c936d9ac51373186cc2f1f4e9/task1.c/buggy/testsuites/sptests/sp20/task1.c |
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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/c87608fd821faf8c936d9ac51373186cc2f1f4e9/task1.c/buggy/testsuites/sptests/sp20/task1.c |
long lb,tb,i; | long lb, tb, i; | 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b1c6c222f6b5eac19b9440823ddaff3ad0558d29/arith1.c/buggy/src/basemath/arith1.c |
lb=lg(b); if (lb==1) return cgetg(1,t_VEC); | lb = lg(b); if (lb==1) return cgetg(1,t_VEC); | 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b1c6c222f6b5eac19b9440823ddaff3ad0558d29/arith1.c/buggy/src/basemath/arith1.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b1c6c222f6b5eac19b9440823ddaff3ad0558d29/arith1.c/buggy/src/basemath/arith1.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/89ee40bb6081bde21b98f4e41620df9b1d20fca0/ifactor1.c/clean/src/basemath/ifactor1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c |
GEN y,c,d; long i,j,k,r,t,n; | GEN y, c, d; long i, j, k, r, t, n; | 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c |
if (t==j) continue; | if (t == j) continue; | 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c |
|
{ 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c |
unsigned32 baudrate /* baud rate to use */ | uint32_t baudrate /* baud rate to use */ | 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);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3e08d4ee6242f1a0ea4afe9dc0a20800632184fe/serdbgio.c/clean/cpukit/libmisc/serdbg/serdbgio.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a0d8bd4ca3992fcf4e709bbc857cacac191dae1b/trans2.c/buggy/src/basemath/trans2.c |
|
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/a0d8bd4ca3992fcf4e709bbc857cacac191dae1b/trans2.c/buggy/src/basemath/trans2.c |
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/819c29b05ce2b9ff19e5d336713ce0753f46d652/polarit3.c/clean/src/basemath/polarit3.c |
|
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]); } }} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2edc82b0d172402925241429eca01a236af8dd01/arith1.c/buggy/src/basemath/arith1.c |
} else if (l > lp) { /* degree decreases */ 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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8aae61076285d1203dd2c62c9b7cf5c4a4e4a778/polarit3.c/buggy/src/basemath/polarit3.c |
|
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c |
|
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;} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d3de7e02a93356b9ace88132cf2b2d1d2820bfd1/gen2.c/buggy/src/basemath/gen2.c |
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);} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
if (DEBUGLEVEL>5) msgtimer("resultant mod %ld", p); if (cmpii(q, bound) >= 0) break; /* DONE */ | if (DEBUGLEVEL>5) msgtimer("resultant mod %ld (bound 2^%ld)", p,expi(q)); if (expi(q) >= bound) break; /* DONE */ | 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));} | 2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fb106e433493a99b7b083a32bc824515ed57d1c/polarit3.c/buggy/src/basemath/polarit3.c |
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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
#endif | 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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
#endif | 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. */} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
(*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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
* 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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
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; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
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 );} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
(*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 );} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
fp++; | SONIC_STATIC int sonic_raw (struct iface *iface, struct mbuf **bpp){ struct sonic *dp = &sonic[iface->dev]; void *rp = dp->sonic; struct mbuf *bp; TransmitDescriptorPointer_t tdp; volatile struct TransmitDescriptorFragLink *fp; unsigned int packetSize; int i; static char padBuf[64]; /* * Update the log. */ iface->rawsndcnt++; iface->lastsent = secclock (); dump (iface, IF_TRACE_OUT, *bpp); /* * It would not do to have two tasks active in the transmit * loop at the same time. * The blocking is simple-minded since the odds of two tasks * simultaneously attempting to use this code are low. The only * way that two tasks can try to run here is: * 1) Task A enters this code and ends up having to * wait for a transmit buffer descriptor. * 2) Task B gains control and tries to transmit a packet. * The RTEMS/KA9Q scheduling semaphore ensures that there * are no race conditions associated with manipulating the * txWaitTid variable. */ if (dp->txWaitTid) { dp->txRawWait++; while (dp->txWaitTid) rtems_ka9q_ppause (10); } /* * Free up transmit descriptors. */ sonic_retire_tda (dp); /* * Wait for transmit descriptor to become available. */ if (dp->tdaActiveCount == dp->tdaCount) { /* * Find out who we are */ if (dp->txWaitTid == 0) rtems_task_ident (RTEMS_SELF, 0, &dp->txWaitTid); /* * Clear old events. */ sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); /* * Wait for transmit descriptor to become available. * Note that the transmit descriptors are checked * *before* * entering the wait loop -- this catches * the possibility that a transmit descriptor became * available between the `if' the started this block, * and the clearing of the interrupt status register. */ sonic_retire_tda (dp); while (dp->tdaActiveCount == dp->tdaCount) { /* * Enable transmitter interrupts. */ sonic_write_register( rp, SONIC_REG_IMR, sonic_read_register( rp, SONIC_REG_IMR) | (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) ); /* * Wait for interrupt */ rtems_ka9q_event_receive (INTERRUPT_EVENT, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT); sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); sonic_retire_tda (dp); } } /* * Get the head of the packet mbuf chain. */ bp = *bpp; /* * Fill in the transmit descriptor fragment descriptors. * ===CACHE=== * If data cache is operating in write-back mode, flush cached * data to memory. */ tdp = dp->tdaHead->next; tdp->mbufp = bp; packetSize = 0; fp = tdp->frag; for (i = 0 ; i < MAXIMUM_FRAGS_PER_DESCRIPTOR ; i++, fp++) { fp->frag_lsw = LSW(bp->data); fp->frag_msw = MSW(bp->data); fp->frag_size = bp->cnt; packetSize += bp->cnt; /* * Break out of the loop if this mbuf is the last in the frame. */ if ((bp = bp->next) == NULL) break; } /* * Pad short packets. */ if ((packetSize < 64) && (i < MAXIMUM_FRAGS_PER_DESCRIPTOR)) { int padSize = 64 - packetSize; fp->frag_lsw = LSW(padBuf); fp->frag_msw = MSW(padBuf); fp->frag_size = padSize; packetSize += padSize; i++; fp++; } /* * Fill Transmit Descriptor */ tdp->pkt_size = packetSize; tdp->frag_count = i; tdp->status = 0; /* * Chain onto list and start transmission. */ tdp->linkp = &fp->frag_link; *tdp->linkp = LSW(tdp->next) | TDA_LINK_EOL; *dp->tdaHead->linkp &= ~TDA_LINK_EOL; sonic_write_register( rp, SONIC_REG_CR, CR_TXP ); dp->tdaActiveCount++; dp->tdaHead = tdp; /* * Let KA9Q know the packet is on the way. */ dp->txWaitTid = 0; *bpp = NULL; return 0;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
|
tdp->frag_count = i; | tdp->frag_count = i + 1; | SONIC_STATIC int sonic_raw (struct iface *iface, struct mbuf **bpp){ struct sonic *dp = &sonic[iface->dev]; void *rp = dp->sonic; struct mbuf *bp; TransmitDescriptorPointer_t tdp; volatile struct TransmitDescriptorFragLink *fp; unsigned int packetSize; int i; static char padBuf[64]; /* * Update the log. */ iface->rawsndcnt++; iface->lastsent = secclock (); dump (iface, IF_TRACE_OUT, *bpp); /* * It would not do to have two tasks active in the transmit * loop at the same time. * The blocking is simple-minded since the odds of two tasks * simultaneously attempting to use this code are low. The only * way that two tasks can try to run here is: * 1) Task A enters this code and ends up having to * wait for a transmit buffer descriptor. * 2) Task B gains control and tries to transmit a packet. * The RTEMS/KA9Q scheduling semaphore ensures that there * are no race conditions associated with manipulating the * txWaitTid variable. */ if (dp->txWaitTid) { dp->txRawWait++; while (dp->txWaitTid) rtems_ka9q_ppause (10); } /* * Free up transmit descriptors. */ sonic_retire_tda (dp); /* * Wait for transmit descriptor to become available. */ if (dp->tdaActiveCount == dp->tdaCount) { /* * Find out who we are */ if (dp->txWaitTid == 0) rtems_task_ident (RTEMS_SELF, 0, &dp->txWaitTid); /* * Clear old events. */ sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); /* * Wait for transmit descriptor to become available. * Note that the transmit descriptors are checked * *before* * entering the wait loop -- this catches * the possibility that a transmit descriptor became * available between the `if' the started this block, * and the clearing of the interrupt status register. */ sonic_retire_tda (dp); while (dp->tdaActiveCount == dp->tdaCount) { /* * Enable transmitter interrupts. */ sonic_write_register( rp, SONIC_REG_IMR, sonic_read_register( rp, SONIC_REG_IMR) | (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) ); /* * Wait for interrupt */ rtems_ka9q_event_receive (INTERRUPT_EVENT, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT); sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); sonic_retire_tda (dp); } } /* * Get the head of the packet mbuf chain. */ bp = *bpp; /* * Fill in the transmit descriptor fragment descriptors. * ===CACHE=== * If data cache is operating in write-back mode, flush cached * data to memory. */ tdp = dp->tdaHead->next; tdp->mbufp = bp; packetSize = 0; fp = tdp->frag; for (i = 0 ; i < MAXIMUM_FRAGS_PER_DESCRIPTOR ; i++, fp++) { fp->frag_lsw = LSW(bp->data); fp->frag_msw = MSW(bp->data); fp->frag_size = bp->cnt; packetSize += bp->cnt; /* * Break out of the loop if this mbuf is the last in the frame. */ if ((bp = bp->next) == NULL) break; } /* * Pad short packets. */ if ((packetSize < 64) && (i < MAXIMUM_FRAGS_PER_DESCRIPTOR)) { int padSize = 64 - packetSize; fp->frag_lsw = LSW(padBuf); fp->frag_msw = MSW(padBuf); fp->frag_size = padSize; packetSize += padSize; i++; fp++; } /* * Fill Transmit Descriptor */ tdp->pkt_size = packetSize; tdp->frag_count = i; tdp->status = 0; /* * Chain onto list and start transmission. */ tdp->linkp = &fp->frag_link; *tdp->linkp = LSW(tdp->next) | TDA_LINK_EOL; *dp->tdaHead->linkp &= ~TDA_LINK_EOL; sonic_write_register( rp, SONIC_REG_CR, CR_TXP ); dp->tdaActiveCount++; dp->tdaHead = tdp; /* * Let KA9Q know the packet is on the way. */ dp->txWaitTid = 0; *bpp = NULL; return 0;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
tdp->linkp = &fp->frag_link; | tdp->linkp = &(fp+1)->frag_link; | SONIC_STATIC int sonic_raw (struct iface *iface, struct mbuf **bpp){ struct sonic *dp = &sonic[iface->dev]; void *rp = dp->sonic; struct mbuf *bp; TransmitDescriptorPointer_t tdp; volatile struct TransmitDescriptorFragLink *fp; unsigned int packetSize; int i; static char padBuf[64]; /* * Update the log. */ iface->rawsndcnt++; iface->lastsent = secclock (); dump (iface, IF_TRACE_OUT, *bpp); /* * It would not do to have two tasks active in the transmit * loop at the same time. * The blocking is simple-minded since the odds of two tasks * simultaneously attempting to use this code are low. The only * way that two tasks can try to run here is: * 1) Task A enters this code and ends up having to * wait for a transmit buffer descriptor. * 2) Task B gains control and tries to transmit a packet. * The RTEMS/KA9Q scheduling semaphore ensures that there * are no race conditions associated with manipulating the * txWaitTid variable. */ if (dp->txWaitTid) { dp->txRawWait++; while (dp->txWaitTid) rtems_ka9q_ppause (10); } /* * Free up transmit descriptors. */ sonic_retire_tda (dp); /* * Wait for transmit descriptor to become available. */ if (dp->tdaActiveCount == dp->tdaCount) { /* * Find out who we are */ if (dp->txWaitTid == 0) rtems_task_ident (RTEMS_SELF, 0, &dp->txWaitTid); /* * Clear old events. */ sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); /* * Wait for transmit descriptor to become available. * Note that the transmit descriptors are checked * *before* * entering the wait loop -- this catches * the possibility that a transmit descriptor became * available between the `if' the started this block, * and the clearing of the interrupt status register. */ sonic_retire_tda (dp); while (dp->tdaActiveCount == dp->tdaCount) { /* * Enable transmitter interrupts. */ sonic_write_register( rp, SONIC_REG_IMR, sonic_read_register( rp, SONIC_REG_IMR) | (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) ); /* * Wait for interrupt */ rtems_ka9q_event_receive (INTERRUPT_EVENT, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT); sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); sonic_retire_tda (dp); } } /* * Get the head of the packet mbuf chain. */ bp = *bpp; /* * Fill in the transmit descriptor fragment descriptors. * ===CACHE=== * If data cache is operating in write-back mode, flush cached * data to memory. */ tdp = dp->tdaHead->next; tdp->mbufp = bp; packetSize = 0; fp = tdp->frag; for (i = 0 ; i < MAXIMUM_FRAGS_PER_DESCRIPTOR ; i++, fp++) { fp->frag_lsw = LSW(bp->data); fp->frag_msw = MSW(bp->data); fp->frag_size = bp->cnt; packetSize += bp->cnt; /* * Break out of the loop if this mbuf is the last in the frame. */ if ((bp = bp->next) == NULL) break; } /* * Pad short packets. */ if ((packetSize < 64) && (i < MAXIMUM_FRAGS_PER_DESCRIPTOR)) { int padSize = 64 - packetSize; fp->frag_lsw = LSW(padBuf); fp->frag_msw = MSW(padBuf); fp->frag_size = padSize; packetSize += padSize; i++; fp++; } /* * Fill Transmit Descriptor */ tdp->pkt_size = packetSize; tdp->frag_count = i; tdp->status = 0; /* * Chain onto list and start transmission. */ tdp->linkp = &fp->frag_link; *tdp->linkp = LSW(tdp->next) | TDA_LINK_EOL; *dp->tdaHead->linkp &= ~TDA_LINK_EOL; sonic_write_register( rp, SONIC_REG_CR, CR_TXP ); dp->tdaActiveCount++; dp->tdaHead = tdp; /* * Let KA9Q know the packet is on the way. */ dp->txWaitTid = 0; *bpp = NULL; return 0;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
sonic_write_register( rp, SONIC_REG_IMR, sonic_read_register( rp, SONIC_REG_IMR) | (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) ); | SONIC_STATIC int sonic_raw (struct iface *iface, struct mbuf **bpp){ struct sonic *dp = &sonic[iface->dev]; void *rp = dp->sonic; struct mbuf *bp; TransmitDescriptorPointer_t tdp; volatile struct TransmitDescriptorFragLink *fp; unsigned int packetSize; int i; static char padBuf[64]; /* * Update the log. */ iface->rawsndcnt++; iface->lastsent = secclock (); dump (iface, IF_TRACE_OUT, *bpp); /* * It would not do to have two tasks active in the transmit * loop at the same time. * The blocking is simple-minded since the odds of two tasks * simultaneously attempting to use this code are low. The only * way that two tasks can try to run here is: * 1) Task A enters this code and ends up having to * wait for a transmit buffer descriptor. * 2) Task B gains control and tries to transmit a packet. * The RTEMS/KA9Q scheduling semaphore ensures that there * are no race conditions associated with manipulating the * txWaitTid variable. */ if (dp->txWaitTid) { dp->txRawWait++; while (dp->txWaitTid) rtems_ka9q_ppause (10); } /* * Free up transmit descriptors. */ sonic_retire_tda (dp); /* * Wait for transmit descriptor to become available. */ if (dp->tdaActiveCount == dp->tdaCount) { /* * Find out who we are */ if (dp->txWaitTid == 0) rtems_task_ident (RTEMS_SELF, 0, &dp->txWaitTid); /* * Clear old events. */ sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); /* * Wait for transmit descriptor to become available. * Note that the transmit descriptors are checked * *before* * entering the wait loop -- this catches * the possibility that a transmit descriptor became * available between the `if' the started this block, * and the clearing of the interrupt status register. */ sonic_retire_tda (dp); while (dp->tdaActiveCount == dp->tdaCount) { /* * Enable transmitter interrupts. */ sonic_write_register( rp, SONIC_REG_IMR, sonic_read_register( rp, SONIC_REG_IMR) | (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) ); /* * Wait for interrupt */ rtems_ka9q_event_receive (INTERRUPT_EVENT, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT); sonic_write_register( rp, SONIC_REG_ISR, ISR_PINT | ISR_TXDN | ISR_TXER ); sonic_retire_tda (dp); } } /* * Get the head of the packet mbuf chain. */ bp = *bpp; /* * Fill in the transmit descriptor fragment descriptors. * ===CACHE=== * If data cache is operating in write-back mode, flush cached * data to memory. */ tdp = dp->tdaHead->next; tdp->mbufp = bp; packetSize = 0; fp = tdp->frag; for (i = 0 ; i < MAXIMUM_FRAGS_PER_DESCRIPTOR ; i++, fp++) { fp->frag_lsw = LSW(bp->data); fp->frag_msw = MSW(bp->data); fp->frag_size = bp->cnt; packetSize += bp->cnt; /* * Break out of the loop if this mbuf is the last in the frame. */ if ((bp = bp->next) == NULL) break; } /* * Pad short packets. */ if ((packetSize < 64) && (i < MAXIMUM_FRAGS_PER_DESCRIPTOR)) { int padSize = 64 - packetSize; fp->frag_lsw = LSW(padBuf); fp->frag_msw = MSW(padBuf); fp->frag_size = padSize; packetSize += padSize; i++; fp++; } /* * Fill Transmit Descriptor */ tdp->pkt_size = packetSize; tdp->frag_count = i; tdp->status = 0; /* * Chain onto list and start transmission. */ tdp->linkp = &fp->frag_link; *tdp->linkp = LSW(tdp->next) | TDA_LINK_EOL; *dp->tdaHead->linkp &= ~TDA_LINK_EOL; sonic_write_register( rp, SONIC_REG_CR, CR_TXP ); dp->tdaActiveCount++; dp->tdaHead = tdp; /* * Let KA9Q know the packet is on the way. */ dp->txWaitTid = 0; *bpp = NULL; return 0;} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
|
printf( "Incoming packet %p\n", rdp ); | /* printf( "Incoming packet %p\n", rdp ); */ | SONIC_STATIC void sonic_rx (int dev, void *p1, void *p2){ struct iface *iface = (struct iface *)p1; struct sonic *dp = (struct sonic *)p2; void *rp = dp->sonic; struct mbuf *bp; rtems_unsigned16 status; ReceiveDescriptorPointer_t rdp; ReceiveResourcePointer_t rwp, rea; rtems_unsigned16 newMissedTally, oldMissedTally; int continuousCount; rwp = dp->rsa; rea = rwp; rdp = dp->rda; /* XXX was rdp_last */ /* * Start the receiver */ oldMissedTally = sonic_read_register( rp, SONIC_REG_MPT ); sonic_write_register( rp, SONIC_REG_CR, CR_RRRA ); sonic_write_register( rp, SONIC_REG_CR, CR_RXEN ); /* * Input packet handling loop */ continuousCount = 0; for (;;) { /* * Wait till SONIC supplies a Receive Descriptor. */ if (rdp->in_use == RDA_FREE) { continuousCount = 0; sonic_rda_wait (dp, rdp); }printf( "Incoming packet %p\n", rdp ); /* * Check that packet is valid */ status = rdp->status; if (status & RDA_STATUS_PRX) { struct mbuf **mbp; void *p; /* * Get the mbuf pointer */ p = PTR(rdp->pkt_msw, rdp->pkt_lsw); mbp = (struct mbuf **)p - 1; bp = *mbp; /* * 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. */ bp->cnt = rdp->byte_count - sizeof (uint32); net_route (iface, &bp); /* * Give the network code a chance to digest the * packet. This guards against a flurry of * incoming packets (usually an ARP storm) from * using up all the available memory. */ if (++continuousCount >= dp->rdaCount) kwait_null (); /* * 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. */ bp = ambufw (RBUF_SIZE); mbp = (struct mbuf **)bp->data; bp->data += sizeof *mbp; *mbp = bp; /* * Reuse Receive Resource. */ rwp->buff_ptr_lsw = LSW(bp->data); rwp->buff_ptr_msw = MSW(bp->data); rwp++; if (rwp == rea) rwp = dp->rsa; sonic_write_register( rp, SONIC_REG_RWP , LSW(rwp) ); /* * Tell the SONIC to reread the RRA. */ if (sonic_read_register( rp, SONIC_REG_ISR ) & ISR_RBE) sonic_write_register( rp, SONIC_REG_ISR, ISR_RBE ); } else { if (status & RDA_STATUS_COL) dp->rxCollision++; if (status & RDA_STATUS_FAER) dp->rxNonOctet++; else if (status & RDA_STATUS_CRCR) dp->rxBadCRC++; } /* * Count missed packets */ newMissedTally = sonic_read_register( rp, SONIC_REG_MPT ); if (newMissedTally != oldMissedTally) { dp->rxMissed += (newMissedTally - oldMissedTally) & 0xFFFF; newMissedTally = oldMissedTally; } /* * Move to next receive descriptor */ rdp->link |= RDA_LINK_EOL; rdp->in_use = RDA_FREE; rdp = rdp->next; rdp->link &= ~RDA_LINK_EOL; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
/* printf( "Routing the packet\n" ); */ | SONIC_STATIC void sonic_rx (int dev, void *p1, void *p2){ struct iface *iface = (struct iface *)p1; struct sonic *dp = (struct sonic *)p2; void *rp = dp->sonic; struct mbuf *bp; rtems_unsigned16 status; ReceiveDescriptorPointer_t rdp; ReceiveResourcePointer_t rwp, rea; rtems_unsigned16 newMissedTally, oldMissedTally; int continuousCount; rwp = dp->rsa; rea = rwp; rdp = dp->rda; /* XXX was rdp_last */ /* * Start the receiver */ oldMissedTally = sonic_read_register( rp, SONIC_REG_MPT ); sonic_write_register( rp, SONIC_REG_CR, CR_RRRA ); sonic_write_register( rp, SONIC_REG_CR, CR_RXEN ); /* * Input packet handling loop */ continuousCount = 0; for (;;) { /* * Wait till SONIC supplies a Receive Descriptor. */ if (rdp->in_use == RDA_FREE) { continuousCount = 0; sonic_rda_wait (dp, rdp); }printf( "Incoming packet %p\n", rdp ); /* * Check that packet is valid */ status = rdp->status; if (status & RDA_STATUS_PRX) { struct mbuf **mbp; void *p; /* * Get the mbuf pointer */ p = PTR(rdp->pkt_msw, rdp->pkt_lsw); mbp = (struct mbuf **)p - 1; bp = *mbp; /* * 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. */ bp->cnt = rdp->byte_count - sizeof (uint32); net_route (iface, &bp); /* * Give the network code a chance to digest the * packet. This guards against a flurry of * incoming packets (usually an ARP storm) from * using up all the available memory. */ if (++continuousCount >= dp->rdaCount) kwait_null (); /* * 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. */ bp = ambufw (RBUF_SIZE); mbp = (struct mbuf **)bp->data; bp->data += sizeof *mbp; *mbp = bp; /* * Reuse Receive Resource. */ rwp->buff_ptr_lsw = LSW(bp->data); rwp->buff_ptr_msw = MSW(bp->data); rwp++; if (rwp == rea) rwp = dp->rsa; sonic_write_register( rp, SONIC_REG_RWP , LSW(rwp) ); /* * Tell the SONIC to reread the RRA. */ if (sonic_read_register( rp, SONIC_REG_ISR ) & ISR_RBE) sonic_write_register( rp, SONIC_REG_ISR, ISR_RBE ); } else { if (status & RDA_STATUS_COL) dp->rxCollision++; if (status & RDA_STATUS_FAER) dp->rxNonOctet++; else if (status & RDA_STATUS_CRCR) dp->rxBadCRC++; } /* * Count missed packets */ newMissedTally = sonic_read_register( rp, SONIC_REG_MPT ); if (newMissedTally != oldMissedTally) { dp->rxMissed += (newMissedTally - oldMissedTally) & 0xFFFF; newMissedTally = oldMissedTally; } /* * Move to next receive descriptor */ rdp->link |= RDA_LINK_EOL; rdp->in_use = RDA_FREE; rdp = rdp->next; rdp->link &= ~RDA_LINK_EOL; }} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/301a2a3c0b46df149e0194b6742cdafc196a6656/sonic.c/buggy/c/src/lib/libbsp/powerpc/dmv177/sonic/sonic.c |
|
sc->rxDaemonTid = rtems_bsdnet_newproc ("SNrx", 4096, sonic_rxDaemon, sc); | SONIC_STATIC void sonic_init (void *arg){ struct sonic_softc *sc = arg; struct ifnet *ifp = &sc->arpcom.ac_if; void *rp = sc->sonic; int rcr; if (sc->txDaemonTid == 0) { /* * Set up SONIC hardware */ sonic_initialize_hardware (sc); /* * Start driver tasks */ sc->txDaemonTid = rtems_bsdnet_newproc ("SNtx", 4096, sonic_txDaemon, sc); sc->rxDaemonTid = rtems_bsdnet_newproc ("SNrx", 4096, sonic_rxDaemon, sc); } /* * Set flags appropriately */ rcr = (*sc->read_register)( rp, SONIC_REG_RCR ); if (ifp->if_flags & IFF_PROMISC) rcr |= RCR_PRO; else rcr &= ~RCR_PRO; (*sc->write_register)( rp, SONIC_REG_RCR, rcr); /* * Tell the world that we're running. */ ifp->if_flags |= IFF_RUNNING; /* * Enable receiver and transmitter */ /* (*sc->write_register)( rp, SONIC_REG_IMR, 0 ); */ sonic_enable_interrupts( sc, (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) | (IMR_PRXEN | IMR_RBAEEN) ); (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */ CR_RXEN);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
|
/* (*sc->write_register)( rp, SONIC_REG_IMR, 0 ); */ sonic_enable_interrupts( sc, (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) | (IMR_PRXEN | IMR_RBAEEN) ); (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */ CR_RXEN); | sonic_enable_interrupts( sc, IMR_TXEREN | (IMR_PRXEN | IMR_RBAEEN) ); sonic_command( sc, CR_RXEN ); | SONIC_STATIC void sonic_init (void *arg){ struct sonic_softc *sc = arg; struct ifnet *ifp = &sc->arpcom.ac_if; void *rp = sc->sonic; int rcr; if (sc->txDaemonTid == 0) { /* * Set up SONIC hardware */ sonic_initialize_hardware (sc); /* * Start driver tasks */ sc->txDaemonTid = rtems_bsdnet_newproc ("SNtx", 4096, sonic_txDaemon, sc); sc->rxDaemonTid = rtems_bsdnet_newproc ("SNrx", 4096, sonic_rxDaemon, sc); } /* * Set flags appropriately */ rcr = (*sc->read_register)( rp, SONIC_REG_RCR ); if (ifp->if_flags & IFF_PROMISC) rcr |= RCR_PRO; else rcr &= ~RCR_PRO; (*sc->write_register)( rp, SONIC_REG_RCR, rcr); /* * Tell the world that we're running. */ ifp->if_flags |= IFF_RUNNING; /* * Enable receiver and transmitter */ /* (*sc->write_register)( rp, SONIC_REG_IMR, 0 ); */ sonic_enable_interrupts( sc, (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN) | (IMR_PRXEN | IMR_RBAEEN) ); (*sc->write_register)(rp, SONIC_REG_CR, /* CR_TXP | */ CR_RXEN);} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |
if ((imr & (IMR_PRXEN | IMR_RBAEEN)) && (isr & (ISR_PKTRX | ISR_RBAE))) { | if (imr & isr & (IMR_PRXEN | IMR_RBAEEN)) { | SONIC_STATIC rtems_isr sonic_interrupt_handler (rtems_vector_number v){ struct sonic_softc *sc = sonic_softc; unsigned32 isr, imr; void *rp;#if (NSONIC > 1) /* * Find the device which requires service */ for (;;) { if (sc->vector == v) break; if (++sc == &sonic[NSONIC]) return; /* Spurious interrupt? */ }#endif /* NSONIC > 1 */ /* * Get pointer to SONIC registers */ rp = sc->sonic; sc->Interrupts++; isr = (*sc->read_register)( rp, SONIC_REG_ISR ); imr = (*sc->read_register)( rp, SONIC_REG_IMR ); /* * Packet received or receive buffer area exceeded? */ if ((imr & (IMR_PRXEN | IMR_RBAEEN)) && (isr & (ISR_PKTRX | ISR_RBAE))) { imr &= ~(IMR_PRXEN | IMR_RBAEEN); sc->rxInterrupts++; rtems_event_send (sc->rxDaemonTid, INTERRUPT_EVENT); } /* * Packet started, transmitter done or transmitter error? */ if ((imr & (IMR_PINTEN | IMR_PTXEN | IMR_TXEREN)) && (isr & (ISR_PINT | ISR_TXDN | ISR_TXER))) { imr &= ~(IMR_PINTEN | IMR_PTXEN | IMR_TXEREN); sc->txInterrupts++; rtems_event_send (sc->txDaemonTid, INTERRUPT_EVENT); } (*sc->write_register)( rp, SONIC_REG_IMR, imr );} | 10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/f1f42b454dc955624d7bb2d78c0c9718c814a24b/sonic.c/clean/c/src/libchip/network/sonic.c |