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)
220 return ERROR_INT(
"sela not defined", __func__, 1);
224 return ERROR_INT(
"code generation problem", __func__, 1);
255 const char *filename)
258 char *str_proto1, *str_proto2, *str_proto3;
259 char *str_doc1, *str_doc2, *str_doc3, *str_doc4;
260 char *str_def1, *str_def2, *str_proc1, *str_proc2;
261 char *str_dwa1, *str_low_dt, *str_low_ds;
263 l_int32 i, nsels, nbytes, actstart, end, newstart;
268 return ERROR_INT(
"sela not defined", __func__, 1);
272 return ERROR_INT(
"no sels in sela", __func__, 1);
275 if ((filestr = (
char *)
l_binaryRead(TEMPLATE1, &size)) == NULL)
276 return ERROR_INT(
"filestr not made", __func__, 1);
280 return ERROR_INT(
"sa2 not made", __func__, 1);
286 sprintf(bigbuf,
"PIX *pixHMTDwa_%d(PIX *pixd, PIX *pixs, "
287 "const char *selname);", fileindex);
289 sprintf(bigbuf,
"PIX *pixFHMTGen_%d(PIX *pixd, PIX *pixs, "
290 "const char *selname);", fileindex);
292 sprintf(bigbuf,
"l_int32 fhmtgen_low_%d(l_uint32 *datad, l_int32 w,\n"
293 " l_int32 h, l_int32 wpld,\n"
294 " l_uint32 *datas, l_int32 wpls,\n"
295 " l_int32 index);", fileindex);
297 sprintf(bigbuf,
" * PIX *pixHMTDwa_%d()", fileindex);
299 sprintf(bigbuf,
" * PIX *pixFHMTGen_%d()", fileindex);
301 sprintf(bigbuf,
" * \\brief pixHMTDwa_%d()", fileindex);
303 sprintf(bigbuf,
" * \\brief pixFHMTGen_%d()", fileindex);
305 sprintf(bigbuf,
"pixHMTDwa_%d(PIX *pixd,", fileindex);
307 sprintf(bigbuf,
"pixFHMTGen_%d(PIX *pixd,", fileindex);
309 sprintf(bigbuf,
" PROCNAME(\"pixHMTDwa_%d\");", fileindex);
311 sprintf(bigbuf,
" PROCNAME(\"pixFHMTGen_%d\");", fileindex);
313 sprintf(bigbuf,
" pixt2 = pixFHMTGen_%d(NULL, pixt1, selname);",
317 " fhmtgen_low_%d(datad, w, h, wpld, datat, wpls, index);",
321 " fhmtgen_low_%d(datad, w, h, wpld, datas, wpls, index);",
346 sprintf(bigbuf,
"\nstatic l_int32 NUM_SELS_GENERATED = %d;", nsels);
348 sprintf(bigbuf,
"static char SEL_NAMES[][80] = {");
350 for (i = 0; i < nsels - 1; i++) {
351 sprintf(bigbuf,
" \"%s\",",
355 sprintf(bigbuf,
" \"%s\"};",
397 nbytes = strlen(filestr);
399 snprintf(bigbuf,
L_BUF_SIZE,
"%s.%d.c", filename, fileindex);
401 sprintf(bigbuf,
"%s.%d.c", OUTROOT, fileindex);
435 const char *filename)
437 char *filestr, *fname, *linestr;
438 char *str_doc1, *str_doc2, *str_doc3, *str_def1;
440 char breakstring[] =
" break;";
441 char staticstring[] =
"static void";
442 l_int32 i, k, l, nsels, nbytes, nhits, nmisses;
443 l_int32 actstart, end, newstart;
444 l_int32 argstart, argend, loopstart, loopend, finalstart, finalend;
446 SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6;
450 return ERROR_INT(
"sela not defined", __func__, 1);
454 return ERROR_INT(
"no sels in sela", __func__, 1);
457 if ((filestr = (
char *)
l_binaryRead(TEMPLATE2, &size)) == NULL)
458 return ERROR_INT(
"filestr not made", __func__, 1);
462 return ERROR_INT(
"sa1 not made", __func__, 1);
467 return ERROR_INT(
"sa2 not made", __func__, 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", __func__, 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", __func__, 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)
589 "lept_stderr(\"Error in HMT: no hits in sel!\\n\");\n}\n\n");
603 return ERROR_INT(
"sa6 not made", __func__, 1);
614 nbytes = strlen(filestr);
616 snprintf(bigbuf,
L_BUF_SIZE,
"%slow.%d.c", filename, fileindex);
618 sprintf(bigbuf,
"%slow.%d.c", OUTROOT, fileindex);
639 char emptystring[] =
"";
640 l_int32 i, j, ymax, dely;
644 return (
SARRAY *)ERROR_PTR(
"sel not defined", __func__, NULL);
647 for (i = 0; i < sel->
sy; i++) {
648 for (j = 0; j < sel->
sx; j++) {
649 if (sel->
data[i][j] == 1 || sel->
data[i][j] == 2) {
650 dely = L_ABS(i - sel->
cy);
651 ymax = L_MAX(ymax, dely);
656 L_WARNING(
"ymax > 31; truncating to 31\n", __func__);
683 for (i = 2; i <= ymax; i++)
701 l_int32 i, j, ntot, nfound, type, delx, dely;
705 return (
SARRAY *)ERROR_PTR(
"sel not defined", __func__, NULL);
708 ntot = nhits + nmisses;
710 for (i = 0; i < sel->
sy; i++) {
711 for (j = 0; j < sel->
sx; j++) {
712 type = sel->
data[i][j];
713 if (type == SEL_HIT || type == SEL_MISS) {
719 L_WARNING(
"barrel shift string not made\n", __func__);
723 sprintf(bigbuf,
" *dptr = %s;",
string);
724 else if (nfound == 1)
725 sprintf(bigbuf,
" *dptr = %s %s",
string, land);
726 else if (nfound < ntot)
727 sprintf(bigbuf,
" %s %s",
string, land);
729 sprintf(bigbuf,
" %s;",
string);
751 if (delx < -31 || delx > 31)
752 return (
char *)ERROR_PTR(
"delx out of bounds", __func__, NULL);
753 if (dely < -31 || dely > 31)
754 return (
char *)ERROR_PTR(
"dely out of bounds", __func__, NULL);
758 if (type == SEL_HIT) {
759 if ((delx == 0) && (dely == 0))
760 sprintf(bigbuf,
"(*sptr)");
761 else if ((delx == 0) && (dely < 0))
762 sprintf(bigbuf,
"(*(sptr %s))", wplstrm[absy - 1]);
763 else if ((delx == 0) && (dely > 0))
764 sprintf(bigbuf,
"(*(sptr %s))", wplstrp[absy - 1]);
765 else if ((delx < 0) && (dely == 0))
766 sprintf(bigbuf,
"((*(sptr) >> %d) | (*(sptr - 1) << %d))",
768 else if ((delx > 0) && (dely == 0))
769 sprintf(bigbuf,
"((*(sptr) << %d) | (*(sptr + 1) >> %d))",
771 else if ((delx < 0) && (dely < 0))
772 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
773 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
774 else if ((delx > 0) && (dely < 0))
775 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
776 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
777 else if ((delx < 0) && (dely > 0))
778 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
779 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
781 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
782 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
784 if ((delx == 0) && (dely == 0))
785 sprintf(bigbuf,
"(~*sptr)");
786 else if ((delx == 0) && (dely < 0))
787 sprintf(bigbuf,
"(~*(sptr %s))", wplstrm[absy - 1]);
788 else if ((delx == 0) && (dely > 0))
789 sprintf(bigbuf,
"(~*(sptr %s))", wplstrp[absy - 1]);
790 else if ((delx < 0) && (dely == 0))
791 sprintf(bigbuf,
"((~*(sptr) >> %d) | (~*(sptr - 1) << %d))",
793 else if ((delx > 0) && (dely == 0))
794 sprintf(bigbuf,
"((~*(sptr) << %d) | (~*(sptr + 1) >> %d))",
796 else if ((delx < 0) && (dely < 0))
797 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
798 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
799 else if ((delx > 0) && (dely < 0))
800 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
801 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
802 else if ((delx < 0) && (dely > 0))
803 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
804 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
806 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
807 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
static SARRAY * sarrayMakeWplsCode(SEL *sel)
sarrayMakeWplsCode()
l_ok fhmtautogen1(SELA *sela, l_int32 fileindex, const char *filename)
fhmtautogen1()
static SARRAY * sarrayMakeInnerLoopDWACode(SEL *sel, l_int32 nhits, l_int32 nmisses)
sarrayMakeInnerLoopDWACode()
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()
l_ok fhmtautogen2(SELA *sela, l_int32 fileindex, const char *filename)
fhmtautogen2()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_ok sarrayJoin(SARRAY *sa1, SARRAY *sa2)
sarrayJoin()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_int32 sarrayParseRange(SARRAY *sa, l_int32 start, l_int32 *pactualstart, l_int32 *pend, l_int32 *pnewstart, const char *substr, l_int32 loc)
sarrayParseRange()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok sarrayAppendRange(SARRAY *sa1, SARRAY *sa2, l_int32 start, l_int32 end)
sarrayAppendRange()
SARRAY * selaGetSelnames(SELA *sela)
selaGetSelnames()
SEL * selaGetSel(SELA *sela, l_int32 i)
selaGetSel()
l_int32 selaGetCount(SELA *sela)
selaGetCount()
char * stringNew(const char *src)
stringNew()
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()