static int hadamard8_intra8x8_c(MpegEncContext *s, uint8_t *src, uint8_t *dummy, ptrdiff_t stride, int h) { int i, temp[64], sum = 0; av_assert2(h == 8); for (i = 0; i < 8; i++) { // FIXME: try pointer walks BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1], src[stride * i + 0], src[stride * i + 1]); BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3], src[stride * i + 2], src[stride * i + 3]); BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5], src[stride * i + 4], src[stride * i + 5]); BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7], src[stride * i + 6], src[stride * i + 7]); BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]); BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]); BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]); BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]); BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]); BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]); BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]); BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]); } for (i = 0; i < 8; i++) { BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]); BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]); BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]); BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]); BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]); BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]); BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]); BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]); sum += BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) + BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) + BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) + BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]); } sum -= FFABS(temp[8 * 0] + temp[8 * 4]); // -mean return sum; }
/* Need some options here: user settable metric table, verbosity options, etc */ main(int argc,char *argv[]) { unsigned int bitcnt = 0; int beststate,i; long cmetric[64],nmetric[64]; unsigned long paths[2*PATHMEM]; register unsigned long dec; int mets[8]; unsigned int pi = 0,first=1; unsigned char symbols[3]; int mettab[2][256]; /* Initialize metric table (make this an option) * This table assumes a symbol of 0 is the * strongest possible '0', and a symbol * of 255 is the strongest possible '1'. A symbol * of 128 is an erasure */ for(i=0;i<256;i++){ mettab[0][i] = 128 - i; mettab[1][255-i] = 127 - i; } cmetric[0] = 0; for(i=1;i<64;i++) cmetric[i] = -99999; /* Main loop -- read input symbols and run ACS butterflies, * periodically tracing back to produce decoded output data. * The loop is unrolled to process two bits per iteration. */ for(;;){ /* Renormalize metrics to prevent overflow */ if(cmetric[0] > (LONG_MAX - RENORMALIZE)){ for(i=0;i<64;i++) cmetric[i] -= LONG_MAX; } else if(cmetric[0] < LONG_MIN+RENORMALIZE){ for(i=0;i<64;i++) cmetric[i] += LONG_MAX; } /* Read input symbol pair and compute branch metrics */ symbols[0] = getchar(); symbols[1] = getchar(); symbols[2] = getchar(); if(feof(stdin)) break; mets[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]] + mettab[0][symbols[2]]; mets[1] = mettab[0][symbols[0]] + mettab[0][symbols[1]] + mettab[1][symbols[2]]; mets[3] = mettab[0][symbols[0]] + mettab[1][symbols[1]] + mettab[1][symbols[2]]; mets[2] = mettab[0][symbols[0]] + mettab[1][symbols[1]] + mettab[0][symbols[2]]; mets[6] = mettab[1][symbols[0]] + mettab[1][symbols[1]] + mettab[0][symbols[2]]; mets[7] = mettab[1][symbols[0]] + mettab[1][symbols[1]] + mettab[1][symbols[2]]; mets[5] = mettab[1][symbols[0]] + mettab[0][symbols[1]] + mettab[1][symbols[2]]; mets[4] = mettab[1][symbols[0]] + mettab[0][symbols[1]] + mettab[0][symbols[2]]; /* On even numbered bits, the butterflies read from cmetrics[] * and write to nmetrics[]. On odd numbered bits, the reverse * is done */ /* These macro calls were generated by genbut.c * and rearranged by hand for speed */ dec = 0; BUTTERFLY(0,0); BUTTERFLY(14,0); BUTTERFLY(2,7); BUTTERFLY(12,7); BUTTERFLY(1,6); BUTTERFLY(15,6); BUTTERFLY(3,1); BUTTERFLY(13,1); BUTTERFLY(4,5); BUTTERFLY(10,5); BUTTERFLY(6,2); BUTTERFLY(8,2); BUTTERFLY(5,3); BUTTERFLY(11,3); BUTTERFLY(7,4); BUTTERFLY(9,4); paths[2*pi] = dec; dec = 0; BUTTERFLY(19,0); BUTTERFLY(29,0); BUTTERFLY(17,7); BUTTERFLY(31,7); BUTTERFLY(18,6); BUTTERFLY(28,6); BUTTERFLY(16,1); BUTTERFLY(30,1); BUTTERFLY(23,5); BUTTERFLY(25,5); BUTTERFLY(21,2); BUTTERFLY(27,2); BUTTERFLY(22,3); BUTTERFLY(24,3); BUTTERFLY(20,4); BUTTERFLY(26,4); paths[2*pi+1] = dec; pi++; /* Read input symbol pair and compute branch metrics */ symbols[0] = getchar(); symbols[1] = getchar(); symbols[2] = getchar(); if(feof(stdin)) break; mets[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]] + mettab[0][symbols[2]]; mets[1] = mettab[0][symbols[0]] + mettab[0][symbols[1]] + mettab[1][symbols[2]]; mets[3] = mettab[0][symbols[0]] + mettab[1][symbols[1]] + mettab[1][symbols[2]]; mets[2] = mettab[0][symbols[0]] + mettab[1][symbols[1]] + mettab[0][symbols[2]]; mets[6] = mettab[1][symbols[0]] + mettab[1][symbols[1]] + mettab[0][symbols[2]]; mets[7] = mettab[1][symbols[0]] + mettab[1][symbols[1]] + mettab[1][symbols[2]]; mets[5] = mettab[1][symbols[0]] + mettab[0][symbols[1]] + mettab[1][symbols[2]]; mets[4] = mettab[1][symbols[0]] + mettab[0][symbols[1]] + mettab[0][symbols[2]]; dec = 0; BUTTERFLY2(0,0); BUTTERFLY2(14,0); BUTTERFLY2(2,7); BUTTERFLY2(12,7); BUTTERFLY2(1,6); BUTTERFLY2(15,6); BUTTERFLY2(3,1); BUTTERFLY2(13,1); BUTTERFLY2(4,5); BUTTERFLY2(10,5); BUTTERFLY2(6,2); BUTTERFLY2(8,2); BUTTERFLY2(5,3); BUTTERFLY2(11,3); BUTTERFLY2(7,4); BUTTERFLY2(9,4); paths[2*pi] = dec; dec = 0; BUTTERFLY2(19,0); BUTTERFLY2(29,0); BUTTERFLY2(17,7); BUTTERFLY2(31,7); BUTTERFLY2(18,6); BUTTERFLY2(28,6); BUTTERFLY2(16,1); BUTTERFLY2(30,1); BUTTERFLY2(23,5); BUTTERFLY2(25,5); BUTTERFLY2(21,2); BUTTERFLY2(27,2); BUTTERFLY2(22,3); BUTTERFLY2(24,3); BUTTERFLY2(20,4); BUTTERFLY2(26,4); paths[2*pi+1] = dec; pi = (pi + 1) % PATHMEM; if((pi % TRACECHUNK) == 0){ if(!first) traceback(paths,pi); first = 0; } } flush(paths,pi); }