/* tstTVG * Test the test-vector-generator software for Mark5 * Revised: 2001 December 18, JAB */ #include unsigned long tvg(int init); /* Below */ int main (int argc, char * argv[]) { /* tstTVG */ unsigned long u; int i; for (i = 1; i <= 20; i++) { u = tvg(i == 1); (void) printf(" %.3d %#.8lx \n", i, u); } /* End of for i */ return(0); } /* End of main = tstTVG */ unsigned long tvg(int init) { /* Calculate the test-vector-generator (TVG) pattern. * Reference: VSI-H Specification, Rev 1.0, 7 August 2000, available * at http://web.haystack.mit.edu/vsi/. See especially Figure 6, * page 29 and Table 13, page 20. Referring to Figure 6, q (below) * represents the Q outputs of the flip-flops, r the upper inputs of * the exors, and u the lower 16 bits of the answer (output). * Revised: 2001 December 18, JAB */ static unsigned short q; unsigned short r, u; if (init) /* Initialize? */ q = 0xffff; /* Yes */ /* Set r to a copy of q right shifted by 1 bit */ r = q >> 1; /* And set r bit 15 to a copy of q bit 2 */ if (q & 4) /* Bit 2 set? */ r |= 0x8000; /* Yes */ /* We need to overwrite r bit 14 with a copy of u bit 0, * so we need to do q exor r temporarily to get this bit */ if ((q ^ r) & 1) /* Bit 0 set? */ r |= 0x4000; /* Yes */ else /* Not set */ r &= 0xbfff; /* Now set u to q exor r */ u = q ^ r; /* Lower 16 bits of the answer */ /* For next time, set q to a copy of u right shifted by 1 bit */ q = u >> 1; /* And set q bit 15 (invisible) to a copy of q bit 0 */ if (q & 1) /* Bit 0 set? */ q |= 0x8000; /* Yes */ /* u has the lower 16 bits of the answer; the upper 16 bits * are the lower 16 bits inverted and shifted up there */ return(((unsigned long) ~u << 16) + u); } /* End of tvg() */