src/fec.c
static void
generate_gf(void)
{
    int i;
    gf mask;
    char *Pp =  allPp[GF_BITS] ;

    mask = 1;   /* x ** 0 = 1 */
    gf_exp[GF_BITS] = 0; /* will be updated at the end of the 1st loop */
    /*
     * first, generate the (polynomial representation of) powers of \alpha,
     * which are stored in gf_exp[i] = \alpha ** i .
     * At the same time build gf_log[gf_exp[i]] = i .
     * The first GF_BITS powers are simply bits shifted to the left.
     */
    for (i = 0; i < GF_BITS; i++, mask <<= 1 ) {
        gf_exp[i] = mask;
        gf_log[gf_exp[i]] = i;
        /*
         * If Pp[i] == 1 then \alpha ** i occurs in poly-repr
         * gf_exp[GF_BITS] = \alpha ** GF_BITS
         */
        if ( Pp[i] == '1' )
            gf_exp[GF_BITS] ^= mask;
    }
    /*
     * now gf_exp[GF_BITS] = \alpha ** GF_BITS is complete, so can als
     * compute its inverse.
     */
    gf_log[gf_exp[GF_BITS]] = GF_BITS;
    /*
     * Poly-repr of \alpha ** (i+1) is given by poly-repr of
     * \alpha ** i shifted left one-bit and accounting for any
     * \alpha ** GF_BITS term that may occur when poly-repr of
     * \alpha ** i is shifted.
     */
    mask = 1 << (GF_BITS - 1 ) ;
    for (i = GF_BITS + 1; i < GF_SIZE; i++) {
        if (gf_exp[i - 1] >= mask)
            gf_exp[i] = gf_exp[GF_BITS] ^ ((gf_exp[i - 1] ^ mask) << 1);
        else
            gf_exp[i] = gf_exp[i - 1] << 1;
        gf_log[gf_exp[i]] = i;
    }
    /*
     * log(0) is not defined, so use a special value
     */
    gf_log[0] = GF_SIZE ;
    /* set the extended gf_exp values for fast multiply */
    for (i = 0 ; i < GF_SIZE ; i++)
        gf_exp[i + GF_SIZE] = gf_exp[i] ;

    /*
     * again special cases. 0 has no inverse. This used to
     * be initialized to GF_SIZE, but it should make no difference
     * since noone is supposed to read from here.
    */
    inverse[0] = 0 ;
    inverse[1] = 1;
    for (i=2; i<=GF_SIZE; i++)
        inverse[i] = gf_exp[GF_SIZE-gf_log[i]];
}
/*
 * initialize the data structures used for computations in GF.
 */
initialize the data structures used for computations in GF.
initialize the data structures used for computations in GF .
static void
generate_gf(void)
{
    int i;
    gf mask;
    char *Pp =  allPp[GF_BITS] ;
    mask = 1;   
    gf_exp[GF_BITS] = 0; 
    for (i = 0; i < GF_BITS; i++, mask <<= 1 ) {
        gf_exp[i] = mask;
        gf_log[gf_exp[i]] = i;
        if ( Pp[i] == '1' )
            gf_exp[GF_BITS] ^= mask;
    }
    gf_log[gf_exp[GF_BITS]] = GF_BITS;
    mask = 1 << (GF_BITS - 1 ) ;
    for (i = GF_BITS + 1; i < GF_SIZE; i++) {
        if (gf_exp[i - 1] >= mask)
            gf_exp[i] = gf_exp[GF_BITS] ^ ((gf_exp[i - 1] ^ mask) << 1);
        else
            gf_exp[i] = gf_exp[i - 1] << 1;
        gf_log[gf_exp[i]] = i;
    }
    gf_log[0] = GF_SIZE ;
    for (i = 0 ; i < GF_SIZE ; i++)
        gf_exp[i + GF_SIZE] = gf_exp[i] ;
    inverse[0] = 0 ;
    inverse[1] = 1;
    for (i=2; i<=GF_SIZE; i++)
        inverse[i] = gf_exp[GF_SIZE-gf_log[i]];
}
static void generate_gf ( void ) { int i ; gf mask ; char * Pp = allPp [ GF_BITS ] ; mask = 1 ; gf_exp [ GF_BITS ] = 0 ; for ( i = 0 ; i < GF_BITS ; i ++ , mask <<= 1 ) { gf_exp [ i ] = mask ; gf_log [ gf_exp [ i ] ] = i ; if ( Pp [ i ] == ' ' ) gf_exp [ GF_BITS ] ^= mask ; } gf_log [ gf_exp [ GF_BITS ] ] = GF_BITS ; mask = 1 << ( GF_BITS - 1 ) ; for ( i = GF_BITS + 1 ; i < GF_SIZE ; i ++ ) { if ( gf_exp [ i - 1 ] >= mask ) gf_exp [ i ] = gf_exp [ GF_BITS ] ^ ( ( gf_exp [ i - 1 ] ^ mask ) << 1 ) ; else gf_exp [ i ] = gf_exp [ i - 1 ] << 1 ; gf_log [ gf_exp [ i ] ] = i ; } gf_log [ 0 ] = GF_SIZE ; for ( i = 0 ; i < GF_SIZE ; i ++ ) gf_exp [ i + GF_SIZE ] = gf_exp [ i ] ; inverse [ 0 ] = 0 ; inverse [ 1 ] = 1 ; for ( i = 2 ; i <= GF_SIZE ; i ++ ) inverse [ i ] = gf_exp [ GF_SIZE - gf_log [ i ] ] ; }
initialize the data structures used for computations in GF.
initialize the data structures used for computations in GF .
/* x ** 0 = 1 */ /* will be updated at the end of the 1st loop */ /*
     * first, generate the (polynomial representation of) powers of \alpha,
     * which are stored in gf_exp[i] = \alpha ** i .
     * At the same time build gf_log[gf_exp[i]] = i .
     * The first GF_BITS powers are simply bits shifted to the left.
     */ /*
         * If Pp[i] == 1 then \alpha ** i occurs in poly-repr
         * gf_exp[GF_BITS] = \alpha ** GF_BITS
         */ /*
     * now gf_exp[GF_BITS] = \alpha ** GF_BITS is complete, so can als
     * compute its inverse.
     */ /*
     * Poly-repr of \alpha ** (i+1) is given by poly-repr of
     * \alpha ** i shifted left one-bit and accounting for any
     * \alpha ** GF_BITS term that may occur when poly-repr of
     * \alpha ** i is shifted.
     */ /*
     * log(0) is not defined, so use a special value
     */ /* set the extended gf_exp values for fast multiply */ /*
     * again special cases. 0 has no inverse. This used to
     * be initialized to GF_SIZE, but it should make no difference
     * since noone is supposed to read from here.
    */