96 #include <config_auto.h> 100 #include "allheaders.h" 102 #define OUTROOT "fhmtgen" 103 #define TEMPLATE1 "hmttemplate1.txt" 104 #define TEMPLATE2 "hmttemplate2.txt" 106 #define PROTOARGS "(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);" 108 #define L_BUF_SIZE 512 114 static char wpldecls[][60] = {
116 "l_int32 wpls2, wpls3;",
117 "l_int32 wpls2, wpls3, wpls4;",
119 "l_int32 wpls5, wpls6;",
120 "l_int32 wpls5, wpls6, wpls7;",
121 "l_int32 wpls5, wpls6, wpls7, wpls8;",
123 "l_int32 wpls9, wpls10;",
124 "l_int32 wpls9, wpls10, wpls11;",
125 "l_int32 wpls9, wpls10, wpls11, wpls12;",
127 "l_int32 wpls13, wpls14;",
128 "l_int32 wpls13, wpls14, wpls15;",
129 "l_int32 wpls13, wpls14, wpls15, wpls16;",
131 "l_int32 wpls17, wpls18;",
132 "l_int32 wpls17, wpls18, wpls19;",
133 "l_int32 wpls17, wpls18, wpls19, wpls20;",
135 "l_int32 wpls21, wpls22;",
136 "l_int32 wpls21, wpls22, wpls23;",
137 "l_int32 wpls21, wpls22, wpls23, wpls24;",
139 "l_int32 wpls25, wpls26;",
140 "l_int32 wpls25, wpls26, wpls27;",
141 "l_int32 wpls25, wpls26, wpls27, wpls28;",
143 "l_int32 wpls29, wpls30;",
144 "l_int32 wpls29, wpls30, wpls31;"};
146 static char wpldefs[][24] = {
147 " wpls2 = 2 * wpls;",
148 " wpls3 = 3 * wpls;",
149 " wpls4 = 4 * wpls;",
150 " wpls5 = 5 * wpls;",
151 " wpls6 = 6 * wpls;",
152 " wpls7 = 7 * wpls;",
153 " wpls8 = 8 * wpls;",
154 " wpls9 = 9 * wpls;",
155 " wpls10 = 10 * wpls;",
156 " wpls11 = 11 * wpls;",
157 " wpls12 = 12 * wpls;",
158 " wpls13 = 13 * wpls;",
159 " wpls14 = 14 * wpls;",
160 " wpls15 = 15 * wpls;",
161 " wpls16 = 16 * wpls;",
162 " wpls17 = 17 * wpls;",
163 " wpls18 = 18 * wpls;",
164 " wpls19 = 19 * wpls;",
165 " wpls20 = 20 * wpls;",
166 " wpls21 = 21 * wpls;",
167 " wpls22 = 22 * wpls;",
168 " wpls23 = 23 * wpls;",
169 " wpls24 = 24 * wpls;",
170 " wpls25 = 25 * wpls;",
171 " wpls26 = 26 * wpls;",
172 " wpls27 = 27 * wpls;",
173 " wpls28 = 28 * wpls;",
174 " wpls29 = 29 * wpls;",
175 " wpls30 = 30 * wpls;",
176 " wpls31 = 31 * wpls;"};
178 static char wplstrp[][10] = {
"+ wpls",
"+ wpls2",
"+ wpls3",
"+ wpls4",
179 "+ wpls5",
"+ wpls6",
"+ wpls7",
"+ wpls8",
180 "+ wpls9",
"+ wpls10",
"+ wpls11",
"+ wpls12",
181 "+ wpls13",
"+ wpls14",
"+ wpls15",
"+ wpls16",
182 "+ wpls17",
"+ wpls18",
"+ wpls19",
"+ wpls20",
183 "+ wpls21",
"+ wpls22",
"+ wpls23",
"+ wpls24",
184 "+ wpls25",
"+ wpls26",
"+ wpls27",
"+ wpls28",
185 "+ wpls29",
"+ wpls30",
"+ wpls31"};
187 static char wplstrm[][10] = {
"- wpls",
"- wpls2",
"- wpls3",
"- wpls4",
188 "- wpls5",
"- wpls6",
"- wpls7",
"- wpls8",
189 "- wpls9",
"- wpls10",
"- wpls11",
"- wpls12",
190 "- wpls13",
"- wpls14",
"- wpls15",
"- wpls16",
191 "- wpls17",
"- wpls18",
"- wpls19",
"- wpls20",
192 "- wpls21",
"- wpls22",
"- wpls23",
"- wpls24",
193 "- wpls25",
"- wpls26",
"- wpls27",
"- wpls28",
194 "- wpls29",
"- wpls30",
"- wpls31"};
215 const char *filename)
219 PROCNAME(
"fhmtautogen");
222 return ERROR_INT(
"sela not defined", procName, 1);
226 return ERROR_INT(
"code generation problem", procName, 1);
257 const char *filename)
260 char *str_proto1, *str_proto2, *str_proto3;
261 char *str_doc1, *str_doc2, *str_doc3, *str_doc4;
262 char *str_def1, *str_def2, *str_proc1, *str_proc2;
263 char *str_dwa1, *str_low_dt, *str_low_ds;
265 l_int32 i, nsels, nbytes, actstart, end, newstart;
269 PROCNAME(
"fhmtautogen1");
272 return ERROR_INT(
"sela not defined", procName, 1);
276 return ERROR_INT(
"no sels in sela", procName, 1);
279 if ((filestr = (
char *)
l_binaryRead(TEMPLATE1, &size)) == NULL)
280 return ERROR_INT(
"filestr not made", procName, 1);
284 return ERROR_INT(
"sa2 not made", procName, 1);
290 sprintf(bigbuf,
"PIX *pixHMTDwa_%d(PIX *pixd, PIX *pixs, " 291 "const char *selname);", fileindex);
293 sprintf(bigbuf,
"PIX *pixFHMTGen_%d(PIX *pixd, PIX *pixs, " 294 "const char *selname);", fileindex);
296 sprintf(bigbuf,
"l_int32 fhmtgen_low_%d(l_uint32 *datad, l_int32 w,\n" 297 " l_int32 h, l_int32 wpld,\n" 298 " l_uint32 *datas, l_int32 wpls,\n" 299 " l_int32 index);", fileindex);
301 sprintf(bigbuf,
" * PIX *pixHMTDwa_%d()", fileindex);
303 sprintf(bigbuf,
" * PIX *pixFHMTGen_%d()", fileindex);
305 sprintf(bigbuf,
" * \\brief pixHMTDwa_%d()", fileindex);
307 sprintf(bigbuf,
" * \\brief pixFHMTGen_%d()", fileindex);
309 sprintf(bigbuf,
"pixHMTDwa_%d(PIX *pixd,", fileindex);
311 sprintf(bigbuf,
"pixFHMTGen_%d(PIX *pixd,", fileindex);
313 sprintf(bigbuf,
" PROCNAME(\"pixHMTDwa_%d\");", fileindex);
315 sprintf(bigbuf,
" PROCNAME(\"pixFHMTGen_%d\");", fileindex);
317 sprintf(bigbuf,
" pixt2 = pixFHMTGen_%d(NULL, pixt1, selname);",
321 " fhmtgen_low_%d(datad, w, h, wpld, datat, wpls, index);",
325 " fhmtgen_low_%d(datad, w, h, wpld, datas, wpls, index);",
350 sprintf(bigbuf,
"\nstatic l_int32 NUM_SELS_GENERATED = %d;", nsels);
352 sprintf(bigbuf,
"static char SEL_NAMES[][80] = {");
354 for (i = 0; i < nsels - 1; i++) {
355 sprintf(bigbuf,
" \"%s\",",
359 sprintf(bigbuf,
" \"%s\"};",
401 nbytes = strlen(filestr);
403 snprintf(bigbuf,
L_BUF_SIZE,
"%s.%d.c", filename, fileindex);
405 sprintf(bigbuf,
"%s.%d.c", OUTROOT, fileindex);
439 const char *filename)
441 char *filestr, *fname, *linestr;
442 char *str_doc1, *str_doc2, *str_doc3, *str_def1;
444 char breakstring[] =
" break;";
445 char staticstring[] =
"static void";
446 l_int32 i, k, l, nsels, nbytes, nhits, nmisses;
447 l_int32 actstart, end, newstart;
448 l_int32 argstart, argend, loopstart, loopend, finalstart, finalend;
450 SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6;
453 PROCNAME(
"fhmtautogen2");
456 return ERROR_INT(
"sela not defined", procName, 1);
460 return ERROR_INT(
"no sels in sela", procName, 1);
463 if ((filestr = (
char *)
l_binaryRead(TEMPLATE2, &size)) == NULL)
464 return ERROR_INT(
"filestr not made", procName, 1);
468 return ERROR_INT(
"sa1 not made", procName, 1);
473 return ERROR_INT(
"sa2 not made", procName, 1);
475 for (i = 0; i < nsels; i++) {
476 sprintf(bigbuf,
"fhmt_%d_%d", fileindex, i);
482 for (i = 0; i < nsels; i++) {
484 sprintf(bigbuf,
"static void %s%s", fname, PROTOARGS);
489 sprintf(bigbuf,
" * l_int32 fhmtgen_low_%d()",
492 sprintf(bigbuf,
" * void fhmt_%d_*()", fileindex);
511 for (i = 0; i < nsels; i++) {
517 return ERROR_INT(
"linestr not retrieved", procName, 1);
523 sprintf(bigbuf,
" * fhmtgen_low_%d()", fileindex);
525 sprintf(bigbuf,
"fhmtgen_low_%d(l_uint32 *datad,", fileindex);
539 for (i = 0; i < nsels; i++) {
540 sprintf(bigbuf,
" case %d:", i);
542 sprintf(bigbuf,
" %s(datad, w, h, wpld, datas, wpls);",
559 sarrayParseRange(sa1, newstart, &finalstart, &finalend, &newstart,
"--", 0);
562 for (i = 0; i < nsels; i++) {
566 sprintf(bigbuf,
"%s(l_uint32 *datad,", fname);
576 return ERROR_INT(
"sel not returned", procName, 1);
585 for (k = 0; k < sel->
sy; k++) {
586 for (l = 0; l < sel->
sx; l++) {
587 if (sel->
data[k][l] == 1)
589 else if (sel->
data[k][l] == 2)
595 "lept_stderr(\"Error in HMT: no hits in sel!\\n\");\n}\n\n");
609 return ERROR_INT(
"sa6 not made", procName, 1);
620 nbytes = strlen(filestr);
622 snprintf(bigbuf,
L_BUF_SIZE,
"%slow.%d.c", filename, fileindex);
624 sprintf(bigbuf,
"%slow.%d.c", OUTROOT, fileindex);
645 char emptystring[] =
"";
646 l_int32 i, j, ymax, dely;
649 PROCNAME(
"sarrayMakeWplsCode");
652 return (
SARRAY *)ERROR_PTR(
"sel not defined", procName, NULL);
655 for (i = 0; i < sel->
sy; i++) {
656 for (j = 0; j < sel->
sx; j++) {
657 if (sel->
data[i][j] == 1 || sel->
data[i][j] == 2) {
658 dely = L_ABS(i - sel->
cy);
659 ymax = L_MAX(ymax, dely);
664 L_WARNING(
"ymax > 31; truncating to 31\n", procName);
691 for (i = 2; i <= ymax; i++)
709 l_int32 i, j, ntot, nfound, type, delx, dely;
712 PROCNAME(
"sarrayMakeInnerLoopDWACode");
715 return (
SARRAY *)ERROR_PTR(
"sel not defined", procName, NULL);
718 ntot = nhits + nmisses;
720 for (i = 0; i < sel->
sy; i++) {
721 for (j = 0; j < sel->
sx; j++) {
722 type = sel->
data[i][j];
723 if (type == SEL_HIT || type == SEL_MISS) {
729 L_WARNING(
"barrel shift string not made\n", procName);
733 sprintf(bigbuf,
" *dptr = %s;",
string);
734 else if (nfound == 1)
735 sprintf(bigbuf,
" *dptr = %s %s",
string, land);
736 else if (nfound < ntot)
737 sprintf(bigbuf,
" %s %s",
string, land);
739 sprintf(bigbuf,
" %s;",
string);
761 PROCNAME(
"makeBarrelshiftString");
763 if (delx < -31 || delx > 31)
764 return (
char *)ERROR_PTR(
"delx out of bounds", procName, NULL);
765 if (dely < -31 || dely > 31)
766 return (
char *)ERROR_PTR(
"dely out of bounds", procName, NULL);
770 if (type == SEL_HIT) {
771 if ((delx == 0) && (dely == 0))
772 sprintf(bigbuf,
"(*sptr)");
773 else if ((delx == 0) && (dely < 0))
774 sprintf(bigbuf,
"(*(sptr %s))", wplstrm[absy - 1]);
775 else if ((delx == 0) && (dely > 0))
776 sprintf(bigbuf,
"(*(sptr %s))", wplstrp[absy - 1]);
777 else if ((delx < 0) && (dely == 0))
778 sprintf(bigbuf,
"((*(sptr) >> %d) | (*(sptr - 1) << %d))",
780 else if ((delx > 0) && (dely == 0))
781 sprintf(bigbuf,
"((*(sptr) << %d) | (*(sptr + 1) >> %d))",
783 else if ((delx < 0) && (dely < 0))
784 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
785 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
786 else if ((delx > 0) && (dely < 0))
787 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
788 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
789 else if ((delx < 0) && (dely > 0))
790 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
791 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
793 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
794 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
796 if ((delx == 0) && (dely == 0))
797 sprintf(bigbuf,
"(~*sptr)");
798 else if ((delx == 0) && (dely < 0))
799 sprintf(bigbuf,
"(~*(sptr %s))", wplstrm[absy - 1]);
800 else if ((delx == 0) && (dely > 0))
801 sprintf(bigbuf,
"(~*(sptr %s))", wplstrp[absy - 1]);
802 else if ((delx < 0) && (dely == 0))
803 sprintf(bigbuf,
"((~*(sptr) >> %d) | (~*(sptr - 1) << %d))",
805 else if ((delx > 0) && (dely == 0))
806 sprintf(bigbuf,
"((~*(sptr) << %d) | (~*(sptr + 1) >> %d))",
808 else if ((delx < 0) && (dely < 0))
809 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
810 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
811 else if ((delx > 0) && (dely < 0))
812 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
813 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
814 else if ((delx < 0) && (dely > 0))
815 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
816 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
818 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
819 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()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()