Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help optimizing Win32 compressor!

94 views
Skip to first unread message

Harry Potter

unread,
Jun 12, 2020, 4:16:28 PM6/12/20
to
Hi! I have an issue. I am working on compression, and the code is way too slow. :( I need help optimizing my code. A code snippet follows:
-----------------------
static unsigned char po_getnumlits2 (int pos)
{
register unsigned char i, j, l=0;
unsigned char* tmpcptr=&InBuffer[pos];
for (i=1; i<=100; ++i) {
--tmpcptr;
if (pos-i<0) break;
//l=1;
for (j=i-1; j>0; --j) {
if (tmpcptr[0]==tmpcptr[j])
{--l; break;}
} ++l;
} return l>100?100:l;
}

static unsigned char po_getnum (int in, unsigned char len)
{
unsigned i, j, k, l, l2;
unsigned x;
unsigned char comp=0;
unsigned char* y;
if (j<0) {po_compl=EstimDist (k, po_getnumlits(in))+1; po_offs[0]=k; return 1;}
po_offs[0]=-1;
return 0;
}
for (i=j=k=0; i<len; ++i) {
j=0; y=&InBuffer[in+i];
for (k=0; k<100 && j<100; /*++k*/) {
if (len<6 && j>=32) {j=100; break;}
m=0;
--y;
if ((unsigned)y<(unsigned)&InBuffer) {j= 100; break;}
if (cin[i]==*y) break;
if (j>=0) {
for (l=1;l<=j; ++l) {
if (*y==y[l]) {
m=1; break;
}
}
}
if (m) {++j; continue;}

++j;
++k;
}
if (k<100 && j<100) {
po_offs[i]=k; //comp+=/*5-(k<4)*/(k<6?1:getnumbits(po_getnumlits(vz.InPos-buflen+i+1)));
if (0 && 1 || len>=3 && len<4) comp+=(k<8?4:EstimDist(k-8, po_getnumlits2(l2)-8))+(0 && buflen>=4)+1; //n=1;
else if (len<6) comp+=EstimDist(k, po_getnumlits(in+i));
else comp+=EstimDist (k, po_getnumlits2(in+i)); continue;
}
else {
po_offs[i]=-1;
if ((len<5)) x=po_writelit (in+i, InBuffer[in+i], &l);
else x=po_writelit1a (in+i, InBuffer[in+i], &l);
comp+=GetHuffLen (&cin[i], 1);
po_nl1[i]=x; po_nl2[i]=l;
}
}
po_compl=comp;
return 1;
}

static unsigned po_writelit1a (int pos, unsigned char c, unsigned *outlen)
{
register unsigned i, k, l, m;
register unsigned j;
register unsigned char* s=&InBuffer[pos];
memset (&litsused, 0, sizeof(litsused));
for (i=1; i<=100; ++i) {
if (pos-i<0) break;
--s;
litsused[*s]=1;
}
if (pos) {
k=InBuffer[pos-1];
} else k=0;
for (j=i=l=0; j<256; ++j) {
if (!litsused[j&255] && HuffEnv.entrynum[j]>=0) {
if ((j&255)<c) i++;
l++;
}
}
*outlen=(unsigned) l;
return i;
}
-------------------------
I'm compiling on a Win10/64 laptop with an Intel Celeron N2830 microprocessor using DMC.

Matthias Waldhauer

unread,
Aug 26, 2020, 3:55:47 AM8/26/20
to
Harry Potter schrieb am Freitag, 12. Juni 2020 um 22:16:28 UTC+2:
> Hi! I have an issue. I am working on compression, and the code is way too slow. :( I need help optimizing my code. A code snippet follows:
> -----------------------

Did you try profiling it?

M.

Harry Potter

unread,
Sep 11, 2020, 2:29:45 PM9/11/20
to
The program was written for Digital Mars C. How do I profile it?

Matthias Waldhauer

unread,
Sep 29, 2020, 6:06:09 AM9/29/20
to
Harry Potter schrieb am Freitag, 11. September 2020 um 20:29:45 UTC+2:
> The program was written for Digital Mars C. How do I profile it?
> On Friday, June 12, 2020 at 4:16:28 PM UTC-4, Harry Potter wrote:
> > Hi! I have an issue. I am working on compression, and the code is way too slow. :( I need help optimizing my code. A code snippet follows:
> > [...]
> > I'm compiling on a Win10/64 laptop with an Intel Celeron N2830 microprocessor using DMC.

There seems to be profiling support for Digital Mars:
https://digitalmars.com/ctg/trace.html

And there are also other tools to profile the code independently from the used compiler (CodeXL, etc.). You could also measure execution time of specific parts of the code and just output the results.

But the code could probably also be compiled without any big problems using other compilers.

- M.

Harry Potter

unread,
Sep 30, 2020, 4:56:26 PM9/30/20
to
Hi! I tried the profiling and need help. How do I reorganize the functions as specified by the docs. you showed me? I tried to recompile the code using Open Watcom for the optimizations but ran into some undefined functions. Some of the functions are defined by the ANSI/ISO standard, and the rest are defined in the program code. How do I fix this?
0 new messages