int calfun_(integer *n, doublereal *x, doublereal *fun) { double val ; if( scalx ){ /* in this case, inputs x[] are in range 0..1, */ int ii ; /* and need to be scaled to their 'true' values */ for( ii=0 ; ii < *n ; ii++ ){ if( !isfinite(x[ii]) || x[ii] < -999.9f || x[ii] > 999.9f ){ fprintf(stderr,"** ERROR: calfun[%d]=%g --> 0\n",ii,x[ii]) ; x[ii] = 0.0f ; } sx[ii] = sxmin[ii] + sxsiz[ii]*PRED01(x[ii]); } val = userfun( (int)(*n) , sx ) ; /* input = scaled x[] */ } else if( mapx ){ /* in this case, the parameters given as input */ int ii ; /* are just a subset of all the parameters, so */ /* we must expand the array to the full size. */ for( ii=0 ; ii < *n ; ii++ ) mapar[mapin[ii]] = x[ii] ; val = userfun( mapx , mapar ) ; } else { val = userfun( (int)(*n) , (double *)x ) ; /* input = unscaled x[] */ } *fun = (doublereal)val ; return 0 ; }
int main(int argc, char *argv[]) { int i, num_sol = 0; for (numi = 1; numi <= MAXNUMI && num_sol == 0; ++numi) { printf("Searching for programs with %d operations.\n", numi); // Compute all the correct answers and save them in an array. for (i = 0; i < NTRIALX; i++) { #if NARGS == 1 correct_result[i] = userfun(trialx[i]); #else for (int j = 0; j < NTRIALY; j++) correct_result[i][j] = userfun(trialx[i], trialy[j]); #endif } /* Preload the instruction array with the first instruction and the lowest register number, with copies of this instruction filling the whole array from 0 to numi - 1. */ for (i = 0; i < numi; i++) { pgm[i].op = 0; // Index first insn in isa. pgm[i].opnd[0] = isa[0].opndstart[0]; pgm[i].opnd[1] = isa[0].opndstart[1]; pgm[i].opnd[2] = isa[0].opndstart[2]; /* Ensure that the instruction does not have all immediate operands, etc. */ fix_operands(i); } // Check the above program, generate the next, check it, etc. num_sol = search(); printf("Found %d solutions.\n", num_sol); if (counters) { int total = 0; printf("Counters = "); for (i = 0; i < numi; i++) { printf("%d, ", counter[i]); total = total + counter[i]; } printf("total = %d\n", total); } } return 0; }
int main(int argc, char *argv[]) { int i, j, k, num_sol; clock_t t_start, t_finish; char *end_num; // End of number, set by strtol. /* Obtain parameter (number of instructions (actually operations) for the sought program) and check it. */ if (argc != 2 || *argv[1] == '?') goto tell; numi = strtol(argv[1], &end_num, 0); if (*end_num != '\0') { fprintf(stderr, "Invalid first argument, must be a decimal integer.\n"); return 1; } if (numi < 1 || numi > MAXNUMI) { fprintf(stderr, "Number of insns must be from 1 to %d.\n", MAXNUMI); return 1; } ofile = fopen(OFILE, "w"); if (ofile == NULL) { fprintf(stderr, "Could not open file %s for output.\n", OFILE); return 1; } printb(3, "Searching for programs with %d operations.\n", numi); t_start = clock(); // Compute all the correct answers and save them in an array. for (i = 0; i < NTRIALX; i++) { #if NARGS == 1 correct_result[i] = userfun(trialx[i]); #elif NARGS == 2 for (j = 0; j < NTRIALY; j++) correct_result[i][j] = userfun(trialx[i], trialy[j]); #elif NARGS == 3 for (k = 0; k < NTRIALZ; k++) for (j = 0; j < NTRIALY; j++) correct_result[i][j][k] = userfun(trialx[i], trialy[j], trialz[k]); #endif } /* Preload the instruction array with the first instruction and the lowest register number, with copies of this instruction filling the whole array from 0 to numi - 1. */ for (i = 0; i < numi; i++) { pgm[i].op = 0; // Index first insn in isa. pgm[i].opnd[0] = isa[0].opndstart[0]; pgm[i].opnd[1] = isa[0].opndstart[1]; pgm[i].opnd[2] = isa[0].opndstart[2]; /* Ensure that the instruction does not have all immediate operands, etc. */ fix_operands(i); } num_sol = search(); // Check the above program, generate // the next, check it, etc. t_finish = clock(); printb(3, "Found %d solutions.\n", num_sol); if (counters) { int total = 0; printb(3, "Counters = "); for (i = 0; i < numi; i++) { printb(3, "%d, ", counter[i]); total = total + counter[i]; } printb(3, "total = %d\n", total); } printb(3, "Process time = %.3f secs\n", (double)(t_finish - t_start)/CLOCKS_PER_SEC); return 0; tell: fprintf(stderr, "Format is: %s n, where n is the number of operations to try.\n", argv[0]); return 0; }