94 #include "allheaders.h" 96 #define OUTROOT "fhmtgen" 97 #define TEMPLATE1 "hmttemplate1.txt" 98 #define TEMPLATE2 "hmttemplate2.txt" 100 #define PROTOARGS "(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);" 108 static char wpldecls[][60] = {
110 "l_int32 wpls2, wpls3;",
111 "l_int32 wpls2, wpls3, wpls4;",
113 "l_int32 wpls5, wpls6;",
114 "l_int32 wpls5, wpls6, wpls7;",
115 "l_int32 wpls5, wpls6, wpls7, wpls8;",
117 "l_int32 wpls9, wpls10;",
118 "l_int32 wpls9, wpls10, wpls11;",
119 "l_int32 wpls9, wpls10, wpls11, wpls12;",
121 "l_int32 wpls13, wpls14;",
122 "l_int32 wpls13, wpls14, wpls15;",
123 "l_int32 wpls13, wpls14, wpls15, wpls16;",
125 "l_int32 wpls17, wpls18;",
126 "l_int32 wpls17, wpls18, wpls19;",
127 "l_int32 wpls17, wpls18, wpls19, wpls20;",
129 "l_int32 wpls21, wpls22;",
130 "l_int32 wpls21, wpls22, wpls23;",
131 "l_int32 wpls21, wpls22, wpls23, wpls24;",
133 "l_int32 wpls25, wpls26;",
134 "l_int32 wpls25, wpls26, wpls27;",
135 "l_int32 wpls25, wpls26, wpls27, wpls28;",
137 "l_int32 wpls29, wpls30;",
138 "l_int32 wpls29, wpls30, wpls31;"};
140 static char wpldefs[][24] = {
141 " wpls2 = 2 * wpls;",
142 " wpls3 = 3 * wpls;",
143 " wpls4 = 4 * wpls;",
144 " wpls5 = 5 * wpls;",
145 " wpls6 = 6 * wpls;",
146 " wpls7 = 7 * wpls;",
147 " wpls8 = 8 * wpls;",
148 " wpls9 = 9 * wpls;",
149 " wpls10 = 10 * wpls;",
150 " wpls11 = 11 * wpls;",
151 " wpls12 = 12 * wpls;",
152 " wpls13 = 13 * wpls;",
153 " wpls14 = 14 * wpls;",
154 " wpls15 = 15 * wpls;",
155 " wpls16 = 16 * wpls;",
156 " wpls17 = 17 * wpls;",
157 " wpls18 = 18 * wpls;",
158 " wpls19 = 19 * wpls;",
159 " wpls20 = 20 * wpls;",
160 " wpls21 = 21 * wpls;",
161 " wpls22 = 22 * wpls;",
162 " wpls23 = 23 * wpls;",
163 " wpls24 = 24 * wpls;",
164 " wpls25 = 25 * wpls;",
165 " wpls26 = 26 * wpls;",
166 " wpls27 = 27 * wpls;",
167 " wpls28 = 28 * wpls;",
168 " wpls29 = 29 * wpls;",
169 " wpls30 = 30 * wpls;",
170 " wpls31 = 31 * wpls;"};
172 static char wplstrp[][10] = {
"+ wpls",
"+ wpls2",
"+ wpls3",
"+ wpls4",
173 "+ wpls5",
"+ wpls6",
"+ wpls7",
"+ wpls8",
174 "+ wpls9",
"+ wpls10",
"+ wpls11",
"+ wpls12",
175 "+ wpls13",
"+ wpls14",
"+ wpls15",
"+ wpls16",
176 "+ wpls17",
"+ wpls18",
"+ wpls19",
"+ wpls20",
177 "+ wpls21",
"+ wpls22",
"+ wpls23",
"+ wpls24",
178 "+ wpls25",
"+ wpls26",
"+ wpls27",
"+ wpls28",
179 "+ wpls29",
"+ wpls30",
"+ wpls31"};
181 static char wplstrm[][10] = {
"- wpls",
"- wpls2",
"- wpls3",
"- wpls4",
182 "- wpls5",
"- wpls6",
"- wpls7",
"- wpls8",
183 "- wpls9",
"- wpls10",
"- wpls11",
"- wpls12",
184 "- wpls13",
"- wpls14",
"- wpls15",
"- wpls16",
185 "- wpls17",
"- wpls18",
"- wpls19",
"- wpls20",
186 "- wpls21",
"- wpls22",
"- wpls23",
"- wpls24",
187 "- wpls25",
"- wpls26",
"- wpls27",
"- wpls28",
188 "- wpls29",
"- wpls30",
"- wpls31"};
209 const char *filename)
213 PROCNAME(
"fhmtautogen");
216 return ERROR_INT(
"sela not defined", procName, 1);
220 return ERROR_INT(
"code generation problem", procName, 1);
251 const char *filename)
254 char *str_proto1, *str_proto2, *str_proto3;
255 char *str_doc1, *str_doc2, *str_doc3, *str_doc4;
256 char *str_def1, *str_def2, *str_proc1, *str_proc2;
257 char *str_dwa1, *str_low_dt, *str_low_ds;
259 l_int32 i, nsels, nbytes, actstart, end, newstart;
263 PROCNAME(
"fhmtautogen1");
266 return ERROR_INT(
"sela not defined", procName, 1);
270 return ERROR_INT(
"no sels in sela", procName, 1);
273 if ((filestr = (
char *)
l_binaryRead(TEMPLATE1, &size)) == NULL)
274 return ERROR_INT(
"filestr not made", procName, 1);
278 return ERROR_INT(
"sa2 not made", procName, 1);
284 sprintf(bigbuf,
"PIX *pixHMTDwa_%d(PIX *pixd, PIX *pixs, " 285 "const char *selname);", fileindex);
287 sprintf(bigbuf,
"PIX *pixFHMTGen_%d(PIX *pixd, PIX *pixs, " 288 "const char *selname);", fileindex);
290 sprintf(bigbuf,
"l_int32 fhmtgen_low_%d(l_uint32 *datad, l_int32 w,\n" 291 " l_int32 h, l_int32 wpld,\n" 292 " l_uint32 *datas, l_int32 wpls,\n" 293 " l_int32 index);", fileindex);
295 sprintf(bigbuf,
" * PIX *pixHMTDwa_%d()", fileindex);
297 sprintf(bigbuf,
" * PIX *pixFHMTGen_%d()", fileindex);
299 sprintf(bigbuf,
" * pixHMTDwa_%d()", fileindex);
301 sprintf(bigbuf,
" * pixFHMTGen_%d()", fileindex);
303 sprintf(bigbuf,
"pixHMTDwa_%d(PIX *pixd,", fileindex);
305 sprintf(bigbuf,
"pixFHMTGen_%d(PIX *pixd,", fileindex);
307 sprintf(bigbuf,
" PROCNAME(\"pixHMTDwa_%d\");", fileindex);
309 sprintf(bigbuf,
" PROCNAME(\"pixFHMTGen_%d\");", fileindex);
311 sprintf(bigbuf,
" pixt2 = pixFHMTGen_%d(NULL, pixt1, selname);",
315 " fhmtgen_low_%d(datad, w, h, wpld, datat, wpls, index);",
319 " fhmtgen_low_%d(datad, w, h, wpld, datas, wpls, index);",
344 sprintf(bigbuf,
"\nstatic l_int32 NUM_SELS_GENERATED = %d;", nsels);
346 sprintf(bigbuf,
"static char SEL_NAMES[][80] = {");
348 for (i = 0; i < nsels - 1; i++) {
349 sprintf(bigbuf,
" \"%s\",",
353 sprintf(bigbuf,
" \"%s\"};",
395 nbytes = strlen(filestr);
397 snprintf(bigbuf,
L_BUF_SIZE,
"%s.%d.c", filename, fileindex);
399 sprintf(bigbuf,
"%s.%d.c", OUTROOT, fileindex);
433 const char *filename)
435 char *filestr, *fname, *linestr;
436 char *str_doc1, *str_doc2, *str_doc3, *str_def1;
438 char breakstring[] =
" break;";
439 char staticstring[] =
"static void";
440 l_int32 i, k, l, nsels, nbytes, nhits, nmisses;
441 l_int32 actstart, end, newstart;
442 l_int32 argstart, argend, loopstart, loopend, finalstart, finalend;
444 SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6;
447 PROCNAME(
"fhmtautogen2");
450 return ERROR_INT(
"sela not defined", procName, 1);
454 return ERROR_INT(
"no sels in sela", procName, 1);
457 if ((filestr = (
char *)
l_binaryRead(TEMPLATE2, &size)) == NULL)
458 return ERROR_INT(
"filestr not made", procName, 1);
462 return ERROR_INT(
"sa1 not made", procName, 1);
467 return ERROR_INT(
"sa2 not made", procName, 1);
469 for (i = 0; i < nsels; i++) {
470 sprintf(bigbuf,
"fhmt_%d_%d", fileindex, i);
476 for (i = 0; i < nsels; i++) {
478 sprintf(bigbuf,
"static void %s%s", fname, PROTOARGS);
483 sprintf(bigbuf,
" * l_int32 fhmtgen_low_%d()",
486 sprintf(bigbuf,
" * void fhmt_%d_*()", fileindex);
505 for (i = 0; i < nsels; i++) {
511 return ERROR_INT(
"linestr not retrieved", procName, 1);
517 sprintf(bigbuf,
" * fhmtgen_low_%d()", fileindex);
519 sprintf(bigbuf,
"fhmtgen_low_%d(l_uint32 *datad,", fileindex);
533 for (i = 0; i < nsels; i++) {
534 sprintf(bigbuf,
" case %d:", i);
536 sprintf(bigbuf,
" %s(datad, w, h, wpld, datas, wpls);",
553 sarrayParseRange(sa1, newstart, &finalstart, &finalend, &newstart,
"--", 0);
556 for (i = 0; i < nsels; i++) {
560 sprintf(bigbuf,
"%s(l_uint32 *datad,", fname);
570 return ERROR_INT(
"sel not returned", procName, 1);
579 for (k = 0; k < sel->
sy; k++) {
580 for (l = 0; l < sel->
sx; l++) {
581 if (sel->
data[k][l] == 1)
583 else if (sel->
data[k][l] == 2)
588 linestr =
stringNew(
" fprintf(stderr, \"Error in HMT: no hits in sel!\\n\");\n}\n\n");
602 return ERROR_INT(
"sa6 not made", procName, 1);
613 nbytes = strlen(filestr);
615 snprintf(bigbuf,
L_BUF_SIZE,
"%slow.%d.c", filename, fileindex);
617 sprintf(bigbuf,
"%slow.%d.c", OUTROOT, fileindex);
638 char emptystring[] =
"";
639 l_int32 i, j, ymax, dely;
642 PROCNAME(
"sarrayMakeWplsCode");
645 return (
SARRAY *)ERROR_PTR(
"sel not defined", procName, NULL);
648 for (i = 0; i < sel->
sy; i++) {
649 for (j = 0; j < sel->
sx; j++) {
650 if (sel->
data[i][j] == 1 || sel->
data[i][j] == 2) {
651 dely = L_ABS(i - sel->
cy);
652 ymax = L_MAX(ymax, dely);
657 L_WARNING(
"ymax > 31; truncating to 31\n", procName);
684 for (i = 2; i <= ymax; i++)
702 l_int32 i, j, ntot, nfound, type, delx, dely;
705 PROCNAME(
"sarrayMakeInnerLoopDWACode");
708 return (
SARRAY *)ERROR_PTR(
"sel not defined", procName, NULL);
711 ntot = nhits + nmisses;
713 for (i = 0; i < sel->
sy; i++) {
714 for (j = 0; j < sel->
sx; j++) {
715 type = sel->
data[i][j];
716 if (type == SEL_HIT || type == SEL_MISS) {
722 L_WARNING(
"barrel shift string not made\n", procName);
726 sprintf(bigbuf,
" *dptr = %s;",
string);
727 else if (nfound == 1)
728 sprintf(bigbuf,
" *dptr = %s %s",
string, land);
729 else if (nfound < ntot)
730 sprintf(bigbuf,
" %s %s",
string, land);
732 sprintf(bigbuf,
" %s;",
string);
754 PROCNAME(
"makeBarrelshiftString");
756 if (delx < -31 || delx > 31)
757 return (
char *)ERROR_PTR(
"delx out of bounds", procName, NULL);
758 if (dely < -31 || dely > 31)
759 return (
char *)ERROR_PTR(
"dely out of bounds", procName, NULL);
763 if (type == SEL_HIT) {
764 if ((delx == 0) && (dely == 0))
765 sprintf(bigbuf,
"(*sptr)");
766 else if ((delx == 0) && (dely < 0))
767 sprintf(bigbuf,
"(*(sptr %s))", wplstrm[absy - 1]);
768 else if ((delx == 0) && (dely > 0))
769 sprintf(bigbuf,
"(*(sptr %s))", wplstrp[absy - 1]);
770 else if ((delx < 0) && (dely == 0))
771 sprintf(bigbuf,
"((*(sptr) >> %d) | (*(sptr - 1) << %d))",
773 else if ((delx > 0) && (dely == 0))
774 sprintf(bigbuf,
"((*(sptr) << %d) | (*(sptr + 1) >> %d))",
776 else if ((delx < 0) && (dely < 0))
777 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
778 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
779 else if ((delx > 0) && (dely < 0))
780 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
781 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
782 else if ((delx < 0) && (dely > 0))
783 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
784 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
786 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
787 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
789 if ((delx == 0) && (dely == 0))
790 sprintf(bigbuf,
"(~*sptr)");
791 else if ((delx == 0) && (dely < 0))
792 sprintf(bigbuf,
"(~*(sptr %s))", wplstrm[absy - 1]);
793 else if ((delx == 0) && (dely > 0))
794 sprintf(bigbuf,
"(~*(sptr %s))", wplstrp[absy - 1]);
795 else if ((delx < 0) && (dely == 0))
796 sprintf(bigbuf,
"((~*(sptr) >> %d) | (~*(sptr - 1) << %d))",
798 else if ((delx > 0) && (dely == 0))
799 sprintf(bigbuf,
"((~*(sptr) << %d) | (~*(sptr + 1) >> %d))",
801 else if ((delx < 0) && (dely < 0))
802 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
803 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
804 else if ((delx > 0) && (dely < 0))
805 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
806 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
807 else if ((delx < 0) && (dely > 0))
808 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
809 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
811 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
812 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
char * stringNew(const char *src)
stringNew()
l_int32 selaGetCount(SELA *sela)
selaGetCount()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
SARRAY * selaGetSelnames(SELA *sela)
selaGetSelnames()
l_ok sarrayAppendRange(SARRAY *sa1, SARRAY *sa2, l_int32 start, l_int32 end)
sarrayAppendRange()
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
static SARRAY * sarrayMakeInnerLoopDWACode(SEL *sel, l_int32 nhits, l_int32 nmisses)
sarrayMakeInnerLoopDWACode()
l_ok fhmtautogen2(SELA *sela, l_int32 fileindex, const char *filename)
fhmtautogen2()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok sarrayJoin(SARRAY *sa1, SARRAY *sa2)
sarrayJoin()
static SARRAY * sarrayMakeWplsCode(SEL *sel)
sarrayMakeWplsCode()
l_ok fhmtautogen(SELA *sela, l_int32 fileindex, const char *filename)
fhmtautogen()
static char * makeBarrelshiftString(l_int32 delx, l_int32 dely, l_int32 type)
makeBarrelshiftString()
SEL * selaGetSel(SELA *sela, l_int32 i)
selaGetSel()
l_int32 sarrayParseRange(SARRAY *sa, l_int32 start, l_int32 *pactualstart, l_int32 *pend, l_int32 *pnewstart, const char *substr, l_int32 loc)
sarrayParseRange()
l_ok fhmtautogen1(SELA *sela, l_int32 fileindex, const char *filename)
fhmtautogen1()
static const l_int32 L_BUF_SIZE
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()