/* assume that b points to at least 2 chars */ uint to_index( char * b ) { if( b[1] == '+' ) return POSITIVE( *b ); else return NEGATIVE( *b ); } /**~ end to_index ~**/
/* * graphical equaliser using the function eq to boost/cut the stream. */ void BandPassFilterFFT::EQ(uint8_t *stream, double(*eq)(double, void*), void *args) { double band_data[2*samples]; /* * EQ the data */ for(uint32_t i=0; i<=freqs; i++) // Go over each frequency. { double Eq = eq(f[i], args); REAL(band_data,POSITIVE(i,samples)) = Eq * REAL(fcache,POSITIVE(i,samples)); IMAG(band_data,POSITIVE(i,samples)) = Eq * IMAG(fcache,POSITIVE(i,samples)); REAL(band_data,NEGATIVE(i,samples)) = Eq * REAL(fcache,NEGATIVE(i,samples)); IMAG(band_data,NEGATIVE(i,samples)) = Eq * IMAG(fcache,NEGATIVE(i,samples)); } fft_inverse(band_data, stream); }
static void bind_rdataset(dns_ecdb_t *ecdb, dns_ecdbnode_t *node, rdatasetheader_t *header, dns_rdataset_t *rdataset) { unsigned char *raw; /* * Caller must be holding the node lock. */ REQUIRE(!dns_rdataset_isassociated(rdataset)); rdataset->methods = &rdataset_methods; rdataset->rdclass = ecdb->common.rdclass; rdataset->type = header->type; rdataset->covers = header->covers; rdataset->ttl = header->ttl; rdataset->trust = header->trust; if (NXDOMAIN(header)) rdataset->attributes |= DNS_RDATASETATTR_NXDOMAIN; if (NEGATIVE(header)) rdataset->attributes |= DNS_RDATASETATTR_NEGATIVE; rdataset->private1 = ecdb; rdataset->private2 = node; raw = (unsigned char *)header + sizeof(*header); rdataset->private3 = raw; rdataset->count = 0; /* * Reset iterator state. */ rdataset->privateuint4 = 0; rdataset->private5 = NULL; INSIST(node->references > 0); node->references++; }
/* * using the frequency fft data, band pass between frequencies in f[bandlo] <= f <= f[bandhi] */ void BandPassFilterFFT::band_window(double *band_data, uint32_t bandhi, uint32_t bandlo) { /* * Split the data in to frequency bands. */ for(uint32_t i=0; i<=freqs; i++) // Go over each frequency... { if ((i <= bandhi) && (i>=bandlo)) // ...and copy over the frequencies in the the band window... { REAL(band_data,POSITIVE(i,samples)) = REAL(fcache,POSITIVE(i,samples)); IMAG(band_data,POSITIVE(i,samples)) = IMAG(fcache,POSITIVE(i,samples)); REAL(band_data,NEGATIVE(i,samples)) = REAL(fcache,NEGATIVE(i,samples)); IMAG(band_data,NEGATIVE(i,samples)) = IMAG(fcache,NEGATIVE(i,samples)); } else // ...and set the other frequencies to zero. { REAL(band_data,POSITIVE(i,samples)) = 0.; IMAG(band_data,POSITIVE(i,samples)) = 0.; REAL(band_data,NEGATIVE(i,samples)) = 0.; IMAG(band_data,NEGATIVE(i,samples)) = 0.; } } }
int main( int argc, char ** argv ) { /* Vars */ uint i, j, k; node block; /* check to make sure an input file was supplied */ /* get the number of blocks (the first line of input) */ /* I am just assuming that the input will always be */ /* correct since this is for a competition */ if( argc == 2) get_num_blocks(argv[1]); else exit(EXIT_FAILURE); /* Initialize the graph and cycles arrays */ /* The graph array is an incidence matrix */ /* if graph(i,j) is true, then there is a */ /* directed edge from i -> j */ for( i = 0; i < SIZE; ++i ) { for( j = 0; j < SIZE; ++j ) { graph[i][j] = NO_CONN; } } /* Get the input blocks */ for( i = 0; i < num_blocks; ++i ) { /* for each block... */ if( get_block( &block ) > 2 ) { /* if the block has more than 2 '00' terms then just skip it */ /* if the block has 3 or 4 sides with '00' terms then it */ /* cannot connect to anything so it doesn't matter */ continue; } /* else // block has less than 2 zeros */ /* if a block matches itself, then the structure is unbounded */ /* We wouldn't have to do this, but it is a simple enough check */ /* and as n -> 40,000 it can save a lot of time */ for( k = 0; k < 4; ++k ) { for( j = 0; j < 4; ++j ) { if( block[k*2] == block[j*2] && block[k*2+1] != block[j*2+1] ) goto unbounded; } } /* else // block does not match itself */ /* add links to the graph */ for( j = 0; j < 4; ++j ) { /* For each side... */ /* assume correct formatting so only need to test first block for if 0 */ if( block[j*2] == '0' ) { /* no links can be added */ continue; } else { for( k = 0; k < 4; ++k ) { /* for every other side on the block... */ if( j == k ) /* same side we are already on, so continue */ continue; else if( block[k*2] == '0' ) /* side is 00 so continue */ continue; /* else add link */ /* The basic idea for the links is, add a directed edge */ /* between the opposite of that side (i.d. opposite of */ /* P- is P+) to each of the other sides on the block. */ /* This is because if you can connect to the current */ /* side of the block (i.d. block[j*2]) then you will */ /* connect with the opposite of this block, and it will */ /* connect you to any of the other sides of the current */ /* block. */ /* The problem is actually pretty nice since you can */ /* rotate and reflect, the geometry of the block doesnt */ /* actually matter. */ if( block[j*2+1] == '+' ) graph[ NEGATIVE( block[j*2] ) ][ to_index( &block[k*2] ) ] = 1; /* else the block is negative */ else graph[ POSITIVE( block[j*2] ) ][ to_index( &block[k*2] ) ] = 1; } } } /* turn on __DEBUG__ if you want to see the graph */ print_graph(); } /* graph is all set up, just check for cycles */ if( traverse() ) goto unbounded; /* U mad bro? */ /* if we made it here then it is a bounded structure */ printf("bounded\n"); exit(EXIT_SUCCESS); unbounded: printf("unbounded\n"); exit(EXIT_SUCCESS); } /**~ end main ~**/
void callArithmeticLogicUnit(uint8_t signal){ LoadMemoryAddress(MAR); __uint40_t result; switch(signal) { case SIGNAL_LOAD: AC = MBR; break; case SIGNAL_LOADABS: AC = ABS40(MBR); break; case SIGNAL_LOADNEG: AC = INV40(MBR); break; case SIGNAL_LOADNABS: AC = INV40(ABS40(MBR)); break; case SIGNAL_LOADMQ: AC = MQ; break; case SIGNAL_LOADMQX: MQ = MBR; break; case SIGNAL_ADD: AC += MBR; break; case SIGNAL_ADDABS: if(NEGATIVE(MBR)) AC -= ABS40(MBR); else AC += ABS40(MBR); break; case SIGNAL_SUB: AC -= MBR; break; case SIGNAL_SUBABS: if(NEGATIVE(MBR)) AC += ABS40(MBR); else AC -= ABS40(MBR); break; case SIGNAL_MUL: { if(NEGATIVE(MBR) && !NEGATIVE(MQ) || !NEGATIVE(MBR) && NEGATIVE(MQ)){ result = INV40(ABS40(MBR) * ABS40(MQ)); MQ = ABS40(result); result >>= 40; AC = result; } else{ result = ABS40(MBR) * ABS40(MQ); MQ = ABS40(result); result >>= 40; AC = result; } }
bool isAcumulatorNonNegative(){ if (NEGATIVE(AC)) return false; else return true; }