Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Real programmers don't comment their code. It was hard to write, it should be hard to understand.


computers / comp.compression / Need help optimizing Win32 compressor!

SubjectAuthor
* Need help optimizing Win32 compressor!Harry Potter
+- Re: Need help optimizing Win32 compressor!Matthias Waldhauer
`* Re: Need help optimizing Win32 compressor!Harry Potter
 `* Re: Need help optimizing Win32 compressor!Matthias Waldhauer
  `- Re: Need help optimizing Win32 compressor!Harry Potter

1
Subject: Re: Need help optimizing Win32 compressor!
From: Matthias Waldhauer
Newsgroups: comp.compression
Date: Wed, 26 Aug 2020 07:55 UTC
References: 1
X-Received: by 2002:ac8:6793:: with SMTP id b19mr12613385qtp.333.1598428546494;
Wed, 26 Aug 2020 00:55:46 -0700 (PDT)
X-Received: by 2002:a25:cfcc:: with SMTP id f195mr19138296ybg.390.1598428546328;
Wed, 26 Aug 2020 00:55:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.compression
Date: Wed, 26 Aug 2020 00:55:46 -0700 (PDT)
In-Reply-To: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=194.114.104.125; posting-account=mZDhIAkAAAA5yZTwP-i7JDS8KSI6Oroh
NNTP-Posting-Host: 194.114.104.125
References: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <007a0307-5607-4f67-a0fa-8ae19dbd818fn@googlegroups.com>
Subject: Re: Need help optimizing Win32 compressor!
From: matthias...@gmail.com (Matthias Waldhauer)
Injection-Date: Wed, 26 Aug 2020 07:55:46 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
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.


Subject: Re: Need help optimizing Win32 compressor!
From: Harry Potter
Newsgroups: comp.compression
Date: Fri, 11 Sep 2020 18:29 UTC
References: 1
X-Received: by 2002:a05:6214:a61:: with SMTP id ef1mr3303371qvb.115.1599848983798;
Fri, 11 Sep 2020 11:29:43 -0700 (PDT)
X-Received: by 2002:a25:6b52:: with SMTP id o18mr4157203ybm.367.1599848983542;
Fri, 11 Sep 2020 11:29:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.compression
Date: Fri, 11 Sep 2020 11:29:43 -0700 (PDT)
In-Reply-To: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=100.2.88.142; posting-account=xRocggoAAACFej4w6sQauoZjUP9yroE5
NNTP-Posting-Host: 100.2.88.142
References: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <64f97c3f-0ecf-454c-a854-3aa37001b0d2n@googlegroups.com>
Subject: Re: Need help optimizing Win32 compressor!
From: rose.jos...@yahoo.com (Harry Potter)
Injection-Date: Fri, 11 Sep 2020 18:29:43 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
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:
-----------------------
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.


Subject: Re: Need help optimizing Win32 compressor!
From: Matthias Waldhauer
Newsgroups: comp.compression
Date: Tue, 29 Sep 2020 10:06 UTC
References: 1 2
X-Received: by 2002:ad4:4a6b:: with SMTP id cn11mr3822954qvb.53.1601373967491;
Tue, 29 Sep 2020 03:06:07 -0700 (PDT)
X-Received: by 2002:a25:2786:: with SMTP id n128mr5038696ybn.116.1601373967156;
Tue, 29 Sep 2020 03:06:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!peer01.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.compression
Date: Tue, 29 Sep 2020 03:06:06 -0700 (PDT)
In-Reply-To: <64f97c3f-0ecf-454c-a854-3aa37001b0d2n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=212.86.59.242; posting-account=mZDhIAkAAAA5yZTwP-i7JDS8KSI6Oroh
NNTP-Posting-Host: 212.86.59.242
References: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com> <64f97c3f-0ecf-454c-a854-3aa37001b0d2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <92363620-5afa-4ea3-a04d-ce693a4e7e3bn@googlegroups.com>
Subject: Re: Need help optimizing Win32 compressor!
From: matthias...@gmail.com (Matthias Waldhauer)
Injection-Date: Tue, 29 Sep 2020 10:06:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2130
X-Received-Body-CRC: 1988160504
View all headers
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.


Subject: Re: Need help optimizing Win32 compressor!
From: Harry Potter
Newsgroups: comp.compression
Date: Wed, 30 Sep 2020 20:56 UTC
References: 1 2 3
X-Received: by 2002:aed:26a1:: with SMTP id q30mr4289869qtd.25.1601499385587;
Wed, 30 Sep 2020 13:56:25 -0700 (PDT)
X-Received: by 2002:a25:d3c3:: with SMTP id e186mr5988469ybf.418.1601499385465;
Wed, 30 Sep 2020 13:56:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.compression
Date: Wed, 30 Sep 2020 13:56:25 -0700 (PDT)
In-Reply-To: <92363620-5afa-4ea3-a04d-ce693a4e7e3bn@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=100.2.88.142; posting-account=xRocggoAAACFej4w6sQauoZjUP9yroE5
NNTP-Posting-Host: 100.2.88.142
References: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
<64f97c3f-0ecf-454c-a854-3aa37001b0d2n@googlegroups.com> <92363620-5afa-4ea3-a04d-ce693a4e7e3bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <195d8f99-db82-4e0a-99db-d9fe387eb3b3n@googlegroups.com>
Subject: Re: Need help optimizing Win32 compressor!
From: rose.jos...@yahoo.com (Harry Potter)
Injection-Date: Wed, 30 Sep 2020 20:56:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 4
View all headers
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?


Subject: Need help optimizing Win32 compressor!
From: Harry Potter
Newsgroups: comp.compression
Date: Fri, 12 Jun 2020 20:16 UTC
X-Received: by 2002:ac8:2aed:: with SMTP id c42mr4743800qta.202.1591992987776;
Fri, 12 Jun 2020 13:16:27 -0700 (PDT)
X-Received: by 2002:a37:2781:: with SMTP id n123mr4599188qkn.377.1591992987616;
Fri, 12 Jun 2020 13:16:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!peer01.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.compression
Date: Fri, 12 Jun 2020 13:16:27 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=100.2.88.26; posting-account=xRocggoAAACFej4w6sQauoZjUP9yroE5
NNTP-Posting-Host: 100.2.88.26
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0396d7df-bbc9-4a2b-860d-a85de5111025o@googlegroups.com>
Subject: Need help optimizing Win32 compressor!
From: rose.jos...@yahoo.com (Harry Potter)
Injection-Date: Fri, 12 Jun 2020 20:16:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4703
X-Received-Body-CRC: 1450627227
View all headers
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.


1
rocksolid light 0.7.2
clearneti2ptor