• Need help optimizing Win32 compressor!

    From Harry Potter@21:1/5 to All on Fri Jun 12 13:16:27 2020
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matthias Waldhauer@21:1/5 to Harry Potter on Wed Aug 26 00:55:46 2020
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Harry Potter on Fri Sep 11 11:29:43 2020
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matthias Waldhauer@21:1/5 to Harry Potter on Tue Sep 29 03:06:06 2020
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Wed Sep 30 13:56:25 2020
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)