/* TEST 1 EXERCISER PROGRAM FOR THE MULTI-LAYER PERCEPTRON Benchmark using floating-point double Author: Robert John Morton YE572246C December 1997 */ #include #define NI 77 //number of inputs to the neuron int I[] = {11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329, 11376, 13425, 17920, 30226, 28763, 18940, 15329 }; //inputs int W[] = {12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557, 12345, 21345, 31245, 16730, 31662, 25460, 13557 }; //weights int i; char s[512]; FILE *fh; double Benchmark(void) { //floating-point double computation as benchmark int i; double x; for (x = 0, i = 0; i < NI; i++) x += (double)*(I + i) * *(W + i); return(x / (NI * 32768)); } int Interger(void) { //all-interger method int i, x; for (x = 0, i = 0; i < NI; i++) x += *(I + i) * *(W + i); return(x / NI); } int LongAccum(void) { //interger product with long accumulator int i; long x; for (x = 0, i = 0; i < NI; i++) x += *(I + i) * *(W + i); return(x / NI); } int LongProd(void) { //long product with long accumulator int i; long x; for (x = 0, i = 0; i < NI; i++) x += (long)*(I + i) * *(W + i); return((x >> 15) / NI); } int SplitLong(void) { //long product with two long accumulators int i; long x, Hi, Lo; for(Hi = 0, Lo = 0, i = 0; i < NI; i++) { x = (long)*(I + i) * *(W + i); Hi += x >> 16; //add upper half of long product to Hi accumulator Lo += x & 0xFFFF; //add lower half of long product to Lo accumulator } return(((Hi << 1) + (Lo >> 15)) / NI); } int SplitASM(void) { //in-line assembler version of the above int i, ni, w; unsigned int q; long Hi, Lo; for(Hi = 0, Lo = 0, i = 0; i < NI; i++) { ni = *(I + i); //current input amplitude w = *(W + i); //corresponding input weight _asm { //MACHINE-SPECIFIC ASSEMBLER CODE mov ax, ni ; load initerger input into AX register imul w ; do signed multiply with interger weight mov ni, dx ; put ms word into unsigned interger p mov q, ax ; put ls word into unsigned variable q } Hi += ni; //add ms word into high accumulator Lo += q; //add ls word into low accumulator } return(((Hi << 1) + (Lo >> 15)) / NI); } void Test(int flag) { int c, AL1, AL2, AL3, AL4, AL5; char *r; double AL0; AL0 = Benchmark(); //floating-point double computation as benchmark AL1 = Interger(); //all-interger method AL2 = LongAccum(); //interger product with long accumulator AL3 = LongProd(); //long product with long accumulator AL4 = SplitLong(); //long product with two long accumulators AL5 = SplitASM(); //in-line assembler version of the above i += sprintf(s + i," Benchmark using floating-point double %+9.2f\n", AL0); i += sprintf(s + i," 1) int products with int accumulator %+6d \n", AL1); i += sprintf(s + i," 2) int products with long accumulator %+6d \n", AL2); i += sprintf(s + i," 3) long products with long accumulator %+6d \n", AL3); i += sprintf(s + i," 4) long products with 2 long accumulators %+6d \n", AL4); i += sprintf(s + i," 5) In-line assembler version of the above %+6d\n\n", AL5); if (flag) sprintf(s + i,"\n"); for (r = s; (c = *r) > '\0'; r++) //while character is not a null putc(c, fh); //write it to the file } main() { fh = fopen("results.txt","a"); //open file for appending i = sprintf(s, "TEST RESULTS FOR THE 5 COMPUTATION METHODS\n\n"); i += sprintf(s + i, "For positive inputs...\n"); Test(0); //test for positive inputs for (i = 0; i < NI; i++) I[i] = -I[i]; //reverse inputs i = sprintf(s, "For negative inputs...\n"); Test(1); //test for negative inputs fclose(fh); //close the file }