diff --git a/changelog.txt b/changelog.txt index 558e84f..5587173 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +pre26 + Remove TAPM component. + Minimum tune improvemnt limit on command line + Remove some code. + Individual STA component tune option in command line. + Remove FS model. + Add final fxcm model in cfg. (https://github.com/kaitz/fxcm/) pre25 APM2 tunable Reduce compiler warnings diff --git a/fs.pxv b/fs.pxv deleted file mode 100644 index 4c87bcc..0000000 --- a/fs.pxv +++ /dev/null @@ -1,8 +0,0 @@ -// describe usable models -stream 0 -model fs\fs.cfg -type 0 -detect -1 -decode -1 -encode -1 -compress 0 diff --git a/fs/fs.cfg b/fs/fs.cfg deleted file mode 100644 index 7f5cdc4..0000000 --- a/fs/fs.cfg +++ /dev/null @@ -1,28 +0,0 @@ -enum {SMC=1,APM1,DS,AVG,SCM,RCM,CM,MX,ST,MM,DHS,SM,SK,APM2,ERR,TAPM,UAS,LMX}; - -// update is called in VM after every bit -int update(int y,int c0,int bpos,int c4,int pr){ - if (bpos==0){ - vmx(TAPM,0,c4); // o2 - } - return 0; -} -//VM calls this after every block -void block(int a,int b) { - //get block info -} -// main is called only once after VM init. -int main() { - vms( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,1,0,0,0); - vmi(TAPM,0, // parameters - 2583+ // limit0 - (1906<<16), // limit1 - 2508| // limit2 - (2419<<12)| // limit3 - (2<<24), // wb1 - 2894+ // limit4 - (19<<16)+ // w1 - (30<<24) // w2 - ); - -} \ No newline at end of file diff --git a/fxcm.pxv b/fxcm.pxv new file mode 100644 index 0000000..9fc8d6c --- /dev/null +++ b/fxcm.pxv @@ -0,0 +1,14 @@ +stream 0 +model fxcm\null.cfg +stream 1 +model fxcm\fxcm.cfg +type 0 +detect -1 +decode -1 +encode -1 +compress 0 +type 1 +detect fxcm\text.det +decode fxcm\text.dec +encode fxcm\text.enc +compress 1 \ No newline at end of file diff --git a/fxcm/fxcm.cfg b/fxcm/fxcm.cfg new file mode 100644 index 0000000..93d1b21 --- /dev/null +++ b/fxcm/fxcm.cfg @@ -0,0 +1,517 @@ +// Model for text - input wit processed, dictionary processed +// +enum {SMC=1,APM1,DS,AVG,SCM,RCM,CM,MX,ST,MM,DHS,SM,SK,APM2,ERR,TAPM,UAS,LMX,STA,BYT}; +int t[14]={} ; // ={} - let VM to alloc memory and set values to 0 +int info; +int c1,c2,c3,c8,word0,word1,word2,word3,apmfails,words,spaces,wshift,w4,nl1,nl,col,fc,fc1,x4; +int wrt_w[256]={ + 2, 3, 1, 3, 3, 0, 1, 2, 3, 3, 0, 0, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, + 3, 2, 0, 2, 1, 3, 2, 1, 3, 3, 3, 3, 2, 3, 0, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2, 3, 2, 2, + 2, 2, 0, 0, 2, 3, 1, 2, 1, 2, 2, 2, 2, 2, 0, 0, + 2, 2, 2, 2, 2, 2, 2, 2, 3, 0, 2, 3, 2, 0, 2, 3, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +int wrt_t[256]={ + 0, 0, 2, 0, 5, 6, 0, 6, 0, 2, 0, 4, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 4, 1, 4, 4, 7, 4, 7, 3, 7, 2, 2, 3, 5, 3, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 5, 3, 3, 5, 5, + 0, 5, 5, 7, 5, 0, 1, 5, 4, 5, 0, 0, 6, 0, 7, 1, + 3, 3, 7, 4, 5, 5, 7, 0, 2, 2, 5, 4, 4, 7, 4, 6, + + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; + +int t1[256]={}; +int t2[0x10000]={}; +int wp[0x10000]={}; +int cpos[256]={}; +int primes[14]={ 0, 257,251,241,239,233,229,227,223,211,199,197,193,191 }; +// Parameters +// +int m_e[7]={256,256,256,256,256,256,0}; // mixer error +int m_s[7]={194, 237, 204, 70, 54, 55, 6};// mixer shift +int m_m[7]={36, 69, 19, 34, 23, 24, 4};// mixer error mul + +int c_r[22]= { 3, 4, 6, 4, 6, 6, 2, 3, 3, 3, 6, 4, 3, 4, 5, 6, 2, 6}; // contextmap run mul +int c_s[22]= {28, 26, 28, 31, 34, 31, 33, 33, 35, 35, 29, 32, 33, 34, 30, 36, 31, 32}; // contextmap pr mul +int c_s2[22]={12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12}; // ... +int c_s3[22]={43, 33, 34, 28, 34, 29, 32, 33, 37, 35, 33, 28, 31, 35, 28, 30, 33, 34}; +int c_s4[22]={ 9, 8, 9, 5, 8, 12, 15, 8, 8, 12, 10, 7, 7, 8, 12, 13, 13, 14}; +int c_s5[22]={ 6, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; // This is obsolete. + +//match +int m_o[7]={3, 30, 13, 8, 2, 7, 5}; +//mix +int m_oi[34]={0,'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','{','|','}','~'};//'_`' +int m_ox[15]={4, 25, 29, 25, 9, 23};//index + +int uasfails,uaslimit; +int e_l[8]={1830, 1997, 1973, 1851, 1897, 1690, 1998, 1842}; +int e_h[8]={4024, 4060, 3962, 3981, 4027, 4070, 3996, 4082}; + +int oState, wtype,ttype; +int nState=-1; + +int MAXLEN=62; // longest allowed match + 1 +int tm[0x100000]={}; // hash table of pointers to contexts +int h; // hash of last 7 bytes +int ptr; // points to next byte of match if any +int len; // length of match, or 0 if no match +int match,ord; +char buffer[0x400000]={}; +enum {BMASK=0x3FFFFF}; +int pos; + +int buf(int i){ + return buffer[(pos-i)&BMASK]; +} +int bufr(int i){ + return buffer[i&BMASK]; +} +int min(int a, int b) {return a3) len=len+(len3 ) printf("pos=%d len=%d ptr=%d\n", pos, len, ptr); + } + // predict match + cx=0; + if (len && c1==bufr(ptr-1)){ + match=(bufr(ptr)>>(7-bpos))&1; + if (len<16) cx=len*2+match; + else cx=(len>>2)*2+match+24; + cx=cx*256+buf(1); + }else { + len=0; + } + vmx(SMC,0,cx); + return len; +} + +// update is called in VM after every bit +int update(int y,int c0,int bpos,int c4,int pr){ + int i,j,h1,c,v17,d,f; + int ismatch,above; + apmfails=apmfails<<1; + uasfails=uasfails<<1; + j=y?pr^4095:pr; + j=vmx(ERR,bpos,j); + apmfails=apmfails|j; + uasfails=uasfails|(j&1); + if (bpos== 0){ + uaslimit=uasfails; + + wshift=0; + c8 = (c8 << 8) + (c4 >> 24); + c3=c2; + c2=c1; + c1=c4&0xff; + //if ((c1>31 && c1<97) || c1<16) w4=w4*4+vmx(BYT, c1,0); + //else + i=wrt_w[c1]; + w4=w4*4+i; + + buffer[pos&BMASK]=c1; + pos++; + //for (i=0;i<6;i++) m_ox[i]=vmx(BYT, i,0); + if ( c1!=' ' )for (h1=0;h1<6;h1++) if (c1==(m_oi[m_ox[h1]])){ if ( c1!=c2 )// || c1=='(' //|| c2=='?' || c1=='{' || c1=='(' || c1=='[' //600 37 250 + for (i=13; i>0; --i) // update order 0-11 context hashes + t[i]=t[i-1]*primes[i]; + x4 = (x4 << 8)+c2; + } + x4 = (x4 << 8)+c1; + for (i=13; i>0; --i) // update order 0-11 context hashes + t[i]=t[i-1]*primes[i]+c1+i*256; + for (i=3; i<6; ++i) + vmx(CM, 0,t[i]); + vmx(CM, 1,t[6]); + vmx(CM, 2,t[8]); + vmx(CM, 3,t[13]); + j=c1; + //if ((c1>31 && c1<97) || c1<16) nState=vmx(BYT, c1,0); + // else + // if (c1<97) nState=vmx(BYT, c1+97,0); + //else + nState=wrt_t[c1]; + words= words<<1;spaces= spaces<<1; + //if (j>='A' && j<='Z') j =j+32; + if (j>='a' && j<='z' || (c1>127 && c2!=12)) { + words=words|1; + word0=word0*2104+j; //263*8 + } + else { + if (word0){ + word3=word2*47; + word2=word1*53; + word1=word0*83; + } + wp[word0&0xffff]=pos; + word0=0; + if (c1==32) spaces++; + else if (c1==10 ) {fc=fc1=0;nl1=nl; nl=pos-1;wtype=(wtype<<3); + w4=w4|0x3fc; + words=0xfffffffc; + } + // : 16 J + // ; 17 K + // < 18 L + // = 19 M + // > 20 N + // ? 21 O + // ` 27 X + // { 28 P + // | 29 Q + // } 30 R + // ~ 31 S + else if (c1=='.' || c1==')' || c1=='O' ) { + wtype= wtype&0xffffffc0; + ttype= ttype&0xfffffff8; + words = words | 0xfffffffe; + w4=w4|204; + } + else if (c1==',' ) {words = words | 0xfffffffc;} + else if (c1=='J') { + ttype= (ttype&0xfffffff8)+4; + w4=w4|12;// 1100 + } + else if (c1=='R' || c1=='P') { + words = words | 0xfffffffc; + wtype= wtype&0xffffffc0; + ttype= (ttype&0xfffffff8)+3; + } + else if (c1=='L' || c2=='&') { + words = words | 0xfffffffc; + } + else if (c1=='M' ) { + ttype= (ttype&0xfffffff8)+4; + } + if (c1=='!' && c2=='&' ) {// ' ' to '&!' to ' ' + c1=' ';(c4=c4&0xffffff00)+' '; + w4=(w4&0xfffffffc)+wrt_w[' ']; + ttype= (ttype&0xfffffff8)+wrt_t[' ']; + } + + if (c1=='.')wshift=1; + } + + // switch state if its new + if (oState!=nState){ + wtype=(wtype<<3)+nState; + oState=nState; + } + ttype=(ttype<<3)+nState; + col=min(31, pos-nl); + if (col<=2) { + if (col==2) { + fc=min(c1,96); + if (fc=='@') fc1=1; + else fc1=0; + } + } + above=buffer[(nl1+col)&BMASK]; + if (fc=='[' && c1==32) { if(c2==']' || c3==']' ) { + fc=64;fc1=0; + }} + if (fc==' ' && c1!=' ' ) { fc=min(c1,96); + if (fc=='@') fc1=1; + else fc1=0; + } + if (fc=='*' && c1!=' ' ) fc=min(c1,96); + + if (word0) { + h1=word0*271+(c4&0xff);} + else + h1=word0*271+c1; + if (c1==12)vmx(CM, 4,0); else vmx(CM, 4,word0); + + if (c1==12)vmx(CM, 4,0); else vmx(CM, 4,h1+word1); + vmx(CM, 5,h1+ word2*71 );// 12 ???? -6k w9 + + vmx(CM, 6,((ttype&0x3f)<<16)+(c4&0xffff));// 12 ???? -6k w9 + vmx(CM, 7,w4); + + vmx(CM, 8,(c4 & 0xffffff) + ((w4 << 18) & 0xff000000)); + vmx(CM, 8,wtype&0x3fffffff); + vmx(CM, 8,(fc) + ((wtype & 0xfff) << 8 ) ); + + vmx(CM, 9,col | (fc << 15) | ((ttype & 63) << 7)); + vmx(CM, 9,(fc | ((c4 & 0xffffff) << 7))); + + vmx(CM, 10, (w4 & 3)+word0*11 ); + vmx(CM, 10, c4 & 0xffff ); + vmx(CM, 10, ((fc << 11) | c1)+((w4 & 3)<< 18)); + + vmx(CM, 11, (w4 & 15)+((ttype & 7) << 6 ) ); + vmx(CM, 11,c1 | ((col * (c1 == 32)) << 8)+((w4 & 15) << 16)); + + vmx(CM, 11, fc<< 11) ; + if (c1==12)vmx(CM, 11,0); else vmx(CM, 11, (91 * word1 + 89 * word0)) ; + + vmx(CM, 12, (c1 + ((ttype & 0x38) << 6))); + vmx(CM, 12, c1+word0); + vmx(CM, 12, ((c4 & 0xffff) << 7) | fc) ; + vmx(CM, 12, ((wtype & 0xfff)<< 8)+((w4 & 0xfc))) ; + + vmx(CM, 13, above | ((ttype & 0x3f) << 9) | (col << 19)| ((w4 & 3) << 16) ); + + vmx(CM, 13, h1+word1); + vmx(CM, 13, above | (c1 << 16)); + + vmx(CM, 14, (x4 & 0xff00ff) ); + vmx(CM, 14, (x4 & 0xff0000ff) | ((ttype & 0xE07) << 8) ); + + f=(c4>>8)&0xffff; + t2[f]=(t2[f]<<8)|c1; + f=c4&0xffff; + f=f|(t2[f]<<16); + d=(c4>>8)&0xff; + t1[d]=(t1[d]<<8)|c1; + d=c1|(t1[c1]<<8); + c=d; + vmx(CM, 14, (d& 0xffff) | ((ttype & 0x38) << 16) ); + vmx(CM, 13, (f& 0xffffff) ); + vmx(CM, 18,d );//2,5k + vmx(CM, 18,((d& 0xffff00)>>4) | ((w4 & 0xf) )| ((ttype & 0xfff) << 20) );//1k + + d = pos - cpos[c1]; + if ( d > 255 ) + d = 255; + cpos[c1] = pos; + vmx(CM, 15, (c1 << 8) | (d >> 2)| (fc << 16)); + vmx(CM, 15, (c4 & 0xffff)+(c2==c3?1:0));// + vmx(CM, 16, (ttype & 0x3ffff) | ((w4 & 255) << 24));// + vmx(CM, 16, x4 ); + + + vmx(CM, 17, 257 * word1 + 193 * (ttype & 0x7fff) ); + vmx(CM, 17, fc|((w4 & 0xfff) << 9)| ((c1 ) << 24) ); + vmx(CM, 17,(x4 & 0xffff00)| ((w4 & 3) ) ); + + vmx(CM, 18,(x4 >>16) | ((w4 & 255) << 24));//1k + vmx(CM, 18,(c1 << 11) | ((f & 0xffffff)>>16) );//0,9k so + vmx(CM, 18,fc | ((c4 & 0xffff)<< 9)| ((w4 & 0xff) << 24) ); + vmx(CM, 18, ((f >> 16) )| ((w4 & 0x3c)<< 25 )| (((ttype & 0x1ff))<< 16 ) ); + + + vmx(CM, 19, (words & 0xff)+((spaces & 0xff)<< 8)+((w4&15)<< 16)+(((ttype>>6)&511)<< 21)+(fc1<<30)); + + + vmx(CM, 19, c1 + ((32 * ttype) & 0x1fffff00)); + vmx(CM, 19,ttype); + vmx(CM, 19, ((d& 0xffff)>>8) + ((64 * w4) & 0x3ffff00)); + + d=pos-wp[word0&0xffff]; + if ( d > 255 ){ + d = 255+(c1 << 16); + } + else{ + d=(d)+(buf(d)<< 8)+(c1 << 16); + } + vmx(CM, 19, (d )| (fc << 24)); + + vmx(CM, 20, (x4&0xf0f00000)+((x4&0x0000f0f0) << 12) ); + vmx(CM, 20, word1*1471-word0*53); + vmx(CM, 20,above | ((c4 &0xffffff)<< 8)); + + if (c1==12) vmx(CM, 21, 0 ); else + vmx(CM, 21, h1+word2*79+word3*71 ); + // + vmx(SCM, 0, c1 );//500 + vmx(SCM, 1, c2*(fc1) );//300 + vmx(SCM, 2, (f & 0xffffff)>>16 );//180 + vmx(SCM, 3, ttype & 0x3f );//320 + vmx(SCM, 4, w4 & 0xff );//250 + vmx(SCM, 5, (w4 & 0xf) + 4 * (words & 0x3c) );// 150 + vmx(SCM, 6, fc1 + 2 * ((wtype & 0x3f) ) );// 150 + vmx(SCM, 7, fc );// 200 + vmx(SCM, 8, (c & 0xffff)>>8 );// 100 + if (wshift ||c1==10) { word3=word3*47,word2=word2*53, word1=word1*83; + + } + } + vmx(UAS,0,uaslimit); + ismatch=matchMod( y, bpos); + if (ismatch) { + ord=0; + for (i=0;i<6;i++) { + j=m_o[i]; + if (len>j)ord=ord+1; + } + } + + else ord=0; + + vmx(MX,0,ord << 3 | bpos); + + if (bpos==0)vmx(MX,1,(w4&63)*8+ (ttype&7) ); + else if (bpos > 3) {c=wrt_w[(c0<<(8-bpos))&255]; + vmx(MX,1,(((w4<<2)&63)+c)*8+(words&7));} + else + vmx(MX,1,(w4&63)*8+ bpos ); + + if (bpos){ + c=c0<<(8-bpos); if (bpos==1)c=c+16 * (words*2& 4); + if (bpos>3) c = wrt_w[(c0<<(8-bpos))&255]*64 ; + c=(min(bpos,5))*256+(ttype&63)+(c&192); + } + else c=((words>>0)&12)*16+(ttype&63); + // if(bpos) + // { + // c=c0<<(8-bpos); if(bpos==1)c=c+c3/2; + // c=(min(bpos,5))*256+c1/32+8*(c2/32)+(c&192); + // } + // else c=c3/128+(c4>>31)*2+4*(c2/64)+(c1&240); + + vmx(MX,2,c); + vmx(MX,3,((2 * words) & 0xfc) + ord*256 + (w4 & 3)); + c= c0<<(8- bpos); + vmx(MX,4,bpos*256+(((( words<< bpos)&255)>> bpos)|(c&255))); + if (bpos>=1) { + if (bpos==1){ + c=c + 16 * (ttype & 7);} + else if (bpos==2) { + c=c + 16 * (w4&3);} + else if (bpos==3) { + c=c + 16 *(words & 1);} + else { + c=bpos + (c&0xf0); + } + if (bpos < 4) + c=bpos + (c&0xf0); + }else c=16 * (w4&0xf); + ord=ord-1; + if (ord<0) + ord=0; + if (ismatch) + ord=ord+1; + + vmx(MX,5, c + ord*256 + 8 * fc1); + //vmx(APM2,0,(apmfails*8)*8+(wtype&3)*8+bpos); + return 0; +} +void block(int a,int b) { + info=a; +} +// main is called only once after VM init. +int main() { + int i,x,c; + vms(1,0,0,0,4+1+1+1+1+1,0,8+1+1+1+1+1+1+1+1+1+1+1+1+1+1,4+1+1+1,0,3+1+1+1,0,0,0,1-1,8,0,1,1,2+1+1+1,0); + // state tables + + for (i=0;i<34;i++) { + c=m_oi[i]; //printf("%c ",c); + if (c>='{' && c<127) c=c+'P'-'{'; + else if (c>='P' && c<'T') c=c-'P'-'{'; + else if ( (c>=':' && c<='?') || (c>='J' && c<='O') ) c=c^0x70; + if (c=='X' || c=='`') c=c^'X'^'`'; + m_oi[i]=c; //printf("%d %c\n",i,c); + } + vmi(STA,0, 28+(28<<16),31|(29<<16),23+(4<<16)+(17<<24));//28+(28<<16),32|(30<<16),22+(3<<16)+(19<<24)); + vmi(STA,1, 32+(28<<16),31|(28<<16),21+(5<<16)+(6<<24)); + vmi(STA,2, 29+(30<<16),28|(23<<16),29+(4<<16)+(22<<24));//1k on w8 same as sta0 + vmi(STA,3, 31+(27<<16),30|(27<<16),24+(4<<16)+(27<<24)); + //vmi(STA,4, 32+(28<<16),31|(28<<16),21+(5<<16)+(6<<24));//1 + + //order + //for (i=0;i<6;i++) { + // x=m_ox[i]; + // vmi(BYT,i,x,32,0); + //} + + //for (i=0;i<256;i++) { + // wrt_w[i]=(255-i)>>6; + //} + // for (i=0;i<256;i++) { + // wrt_t[i]=(i)>>5; + //} + // for (i=0;i<16;i++) { + // x=wrt_w[i]; + // vmi(BYT,i,x,3,0); + //} + // for (i=32;i<97;i++) { + // x=wrt_w[i]; + // vmi(BYT,i,x,3,0); + //} + //wrt_t + //for (i=0;i<97;i++) { + // x=wrt_t[i]; + // vmi(BYT,i+96,x,7,0); + //} + // for (i=32;i<97;i++) { + // x=wrt_t[i]; + // vmi(BYT,i,x,7,0); + //} + + // match + for (i=0;i<8;i++) vmi(ERR,i,e_l[i]+(e_h[i]<<16),0,0); + vmi(UAS,0,13,0,5); + vmi(SMC,0,64<<8,1023,0); + for (i=0;i<9;i++) + vmi(SCM,i,8,0,0); + // + vmi(CM,0,16*4096+(1<<24),4-1+256*c_r[0]+c_s[0]*0x10000+0x1000000*c_s2[0],0+256*c_s3[0]+0x10000*c_s4[0]+(c_s5[0]<<24)|(1<<28)); + vmi(CM,1,16*4096+(1<<24),1+256*c_r[1]+c_s[1]*0x10000+0x1000000*c_s2[1],0+256*c_s3[1]+0x10000*c_s4[1]+(c_s5[1]<<24)|(1<<28)); + vmi(CM,2,16*4096+(1<<24),1+256*c_r[2]+c_s[2]*0x10000+0x1000000*c_s2[2],0+256*c_s3[2]+0x10000*c_s4[2]+(c_s5[2]<<24)|(1<<28)); + vmi(CM,3,16*4096+(1<<24),1+256*c_r[3]+c_s[3]*0x10000+0x1000000*c_s2[3],0+256*c_s3[3]+0x10000*c_s4[3]+(c_s5[3]<<24)|(1<<28)); + vmi(CM,4,16*4096+(1<<24),2+256*c_r[4]+c_s[4]*0x10000+0x1000000*c_s2[4],0+256*c_s3[4]+0x10000*c_s4[4]+(c_s5[4]<<24)|(1<<28)); + vmi(CM,5,16*4096+(3<<24),1+256*c_r[5]+c_s[5]*0x10000+0x1000000*c_s2[5],0+256*c_s3[5]+0x10000*c_s4[5]+(c_s5[5]<<24)|(1<<28)); + vmi(CM,6,1*4096+(1<<24),1+256*c_r[6]+c_s[6]*0x10000+0x1000000*c_s2[6],0+256*c_s3[6]+0x10000*c_s4[6]+(c_s5[6]<<24)|(1<<28)); + vmi(CM,7,2*4096+(1<<24),1+256*c_r[7]+c_s[7]*0x10000+0x1000000*c_s2[7],0+256*c_s3[7]+0x10000*c_s4[7]+(c_s5[7]<<24)|(1<<28)); + vmi(CM,8,1*4096+(4<<24),3+256*c_r[8]+c_s[8]*0x10000+0x1000000*c_s2[8],0+256*c_s3[8]+0x10000*c_s4[8]+(c_s5[8]<<24)|(1<<28)); + vmi(CM,9,32+(1<<24),2+256*c_r[9]+c_s[9]*0x10000+0x1000000*c_s2[9],0+256*c_s3[9]+0x10000*c_s4[9]+(c_s5[9]<<24)|(1<<28)); + vmi(CM,10,32+(2<<24),3+256*c_r[10]+c_s[10]*0x10000+0x1000000*c_s2[10],0+256*c_s3[10]+0x10000*c_s4[10]+(c_s5[10]<<24)|(1<<28)); + vmi(CM,11,32+(2<<24),5-1+256*c_r[11]+c_s[11]*0x10000+0x1000000*c_s2[11],0+256*c_s3[11]+0x10000*c_s4[11]+(c_s5[11]<<24)|(1<<28)); + vmi(CM,12,16+(2<<24),4+256*c_r[12]+c_s[12]*0x10000+0x1000000*c_s2[12],0+256*c_s3[12]+0x10000*c_s4[12]+(c_s5[12]<<24)|(1<<28)); + vmi(CM,13,32+(1<<24),4+256*c_r[13]+c_s[13]*0x10000+0x1000000*c_s2[13],0+256*c_s3[13]+0x10000*c_s4[13]+(c_s5[13]<<24)|(1<<28)); + vmi(CM,14,64*2+(1<<24),3+256*c_r[14]+c_s[14]*0x10000+0x1000000*c_s2[14],0+256*c_s3[14]+0x10000*c_s4[14]+(c_s5[14]<<24)|(1<<28)); + vmi(CM,15,2+(2<<24),2+256*c_r[15]+c_s[15]*0x10000+0x1000000*c_s2[15],0+256*c_s3[15]+0x10000*c_s4[15]+(c_s5[15]<<24)|(1<<28)); + vmi(CM,16,128+(1<<24),2+256*c_r[16]+c_s[16]*0x10000+0x1000000*c_s2[16],0+256*c_s3[16]+0x10000*c_s4[16]+(c_s5[16]<<24)|(1<<28)); + vmi(CM,17,4*4096+(1<<24),3+256*c_r[17]+c_s[17]*0x10000+0x1000000*c_s2[17],0+256*c_s3[17]+0x10000*c_s4[17]+(c_s5[17]<<24)|(1<<28)); + vmi(CM,18,4*4096+(1<<24),6+256*c_r[18]+c_s[18]*0x10000+0x1000000*c_s2[18],0+256*c_s3[18]+0x10000*c_s4[18]+(c_s5[18]<<24)|(1<<28)); + vmi(CM,19,4096+(1<<24),5+256*c_r[19]+c_s[19]*0x10000+0x1000000*c_s2[19],0+256*c_s3[19]+0x10000*c_s4[19]+(c_s5[19]<<24)|(1<<28)); + vmi(CM,20,4096+(1<<24),3+256*c_r[20]+c_s[20]*0x10000+0x1000000*c_s2[20],0+256*c_s3[20]+0x10000*c_s4[20]+(c_s5[20]<<24)|(1<<28)); + vmi(CM,21,4096+(3<<24),1+256*c_r[21]+c_s[21]*0x10000+0x1000000*c_s2[21],0+256*c_s3[21]+0x10000*c_s4[21]+(c_s5[21]<<24)|(1<<28)); + + vmi(MX,0,m_s[0]+256*m_e[0]+0x1000000*m_m[0], 64,0); + vmi(MX,1,m_s[1]+256*m_e[1]+0x1000000*m_m[1], 512,0); + vmi(MX,2,m_s[2]+256*m_e[2]+0x1000000*m_m[2], 1536,0); + vmi(MX,3,m_s[3]+256*m_e[3]+0x1000000*m_m[3], 7*256,0); + vmi(MX,4,m_s[4]+256*m_e[4]+0x1000000*m_m[4], 8*256,0); + vmi(MX,5,m_s[5]+256*m_e[5]+0x1000000*m_m[5], 7*256,0); + for (i=0;i<5+1+1;i++) + vmi(MM,i,0,i,1); + vmi(MX,6,m_s[6]+256*m_e[6]+0x1000000*m_m[6], 1,1); + + //vmi(APM2,0,0x800,24+40*256,7); +} \ No newline at end of file diff --git a/fxcm/null.cfg b/fxcm/null.cfg new file mode 100644 index 0000000..6693a81 --- /dev/null +++ b/fxcm/null.cfg @@ -0,0 +1,9 @@ +int t[5]={}; +enum {SMC=1,APM1,DS,AVG,SCM,RCM,CM,MX,ST,MM,DHS}; +int update(int y,int c0,int bpos,int c4,int pr){ int i; + if (bpos==0) {for (i=4; i>0; --i) t[i]=h2(h2(i,t[i-1]),c4&0xff);} + for (i=1;i<5;++i) vmx(DS,0,c0|(t[i]<<8)); + vmx(APM1,0,c0); return 0;} +void block(int a,int b){} int main(){ vms(0,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); + vmi(DS,0,18,1023,4); vmi(AVG,0,1|(1<<8),0,1*256); + vmi(AVG,1,1|(1<<8),0,2+3*256); vmi(AVG,2,1|(1<<8),0,4+5*256); vmi(APM1,0,256,7,6);} \ No newline at end of file diff --git a/fxcm/readme.txt b/fxcm/readme.txt new file mode 100644 index 0000000..1f387f5 --- /dev/null +++ b/fxcm/readme.txt @@ -0,0 +1,2 @@ +Processed enwik8 +Data 57088865->16220467, 1997.08 sec. Models peak memory usage 1936 MB. \ No newline at end of file diff --git a/fxcm/text.dec b/fxcm/text.dec new file mode 100644 index 0000000..8f726e4 --- /dev/null +++ b/fxcm/text.dec @@ -0,0 +1,31 @@ +// Text byte swap transform - decode +int y; +char inbuf[4]={},outbuf[1024]={}; + +void putc(int c){ + outbuf[y]=c; + y++; + if (y==1024) { + y=0; + write(outbuf,1024); + } +} + +int decode(int info,int len) { + int c,pos; + y=pos=0; + while (pos='{' && c<127) c=c+('P'-'{'); + else if (c>='P' && c<'T') c=c-('P'-'{'); + else if ( (c>=':' && c<='?') || (c>='J' && c<='O') ) c=c^0x70; + if (c=='X' || c=='`') c=c^('X'^'`'); + putc(c); + } + if (y>0) {write(outbuf,y);} + return len; +} +int main() { +} diff --git a/fxcm/text.det b/fxcm/text.det new file mode 100644 index 0000000..50ce6db --- /dev/null +++ b/fxcm/text.det @@ -0,0 +1,60 @@ +// For text detection +int txtStart,txtLen; +int txtMinLen=65536; +int type,state,jstart,jend,of; +enum {DEFAULT=1,TEXT}; //internal enum +enum {NONE=0,START,INFO,END,RESET=0xfffffffe,REQUEST=0xffffffff}; //external enum +// function will report its state +// or if i=-1 then state results otherwise i is pos +// c4 is last 4 bytes +void reset(){ + state=NONE,type=DEFAULT,jstart=jend=0; + txtStart=txtLen=of=0; +} +int detect(int c4,int i) { + int p ,c; + //if state parameters recuested + if (i==REQUEST){ + if (state==NONE) return 0xffffffff; + if (state==START) return jstart; + if (state==END) {p=jend;reset();return p;} + if (state==INFO) return 1; + } + if (i==RESET) { + reset(); + return 0xffffffff; + } + c=c4&0xff; + //detect header + if (txtStart==0) txtStart=1,of=i; + if (txtStart) { + if (c>=0) { + ++txtLen; + if (txtLen>txtMinLen && type==DEFAULT){ + type=TEXT; + state=START; + jstart=of; + return state; + } + return NONE; + } + //txtLen=0; + if (type==TEXT && state==START) { + state=INFO; + jend=i; + return state; + } else if (type==TEXT && state==INFO && i>=jend) { + state=END; + type=DEFAULT; + return state; + } else if (type==TEXT){ + reset(); + } else txtStart=txtLen=0; + } + + return NONE; +} + +int main() { + reset(); +} \ No newline at end of file diff --git a/fxcm/text.enc b/fxcm/text.enc new file mode 100644 index 0000000..a994e4e --- /dev/null +++ b/fxcm/text.enc @@ -0,0 +1,30 @@ +// Text byte swap transform - encode +int y; +char inbuf[4]={},outbuf[1024]={}; + +void putc(int c){ + outbuf[y]=c; + y++; + if (y==1024) { + y=0; + write(outbuf,1024); + } +} + +int encode(int info,int len) { + int c,pos; + pos=y=0; + while (pos='{' && c<127) c=c+('P'-'{'); + else if (c>='P' && c<'T') c=c-('P'-'{'); + else if ( (c>=':' && c<='?') || (c>='J' && c<='O') ) c=c^0x70; + if (c=='X' || c=='`') c=c^('X'^'`'); + putc(c); + } + if (y>0) {write(outbuf,y);} +} +int main() { +} \ No newline at end of file diff --git a/paq8pxv.cpp b/paq8pxv.cpp index d9b724c..8c2e79d 100644 --- a/paq8pxv.cpp +++ b/paq8pxv.cpp @@ -831,6 +831,73 @@ Ilog::Ilog() { // pair, so another state with about the same ratio of n0/n1 is substituted. // Also, when a bit is observed and the count of the opposite bit is large, // then part of this count is discarded to favor newer data over old. +static const U8 State_table[256][4]={ + { 1, 2, 0, 0},{ 3, 5, 1, 0},{ 4, 6, 0, 1},{ 7, 10, 2, 0}, // 0-3 + { 8, 12, 1, 1},{ 9, 13, 1, 1},{ 11, 14, 0, 2},{ 15, 19, 3, 0}, // 4-7 + { 16, 23, 2, 1},{ 17, 24, 2, 1},{ 18, 25, 2, 1},{ 20, 27, 1, 2}, // 8-11 + { 21, 28, 1, 2},{ 22, 29, 1, 2},{ 26, 30, 0, 3},{ 31, 33, 4, 0}, // 12-15 + { 32, 35, 3, 1},{ 32, 35, 3, 1},{ 32, 35, 3, 1},{ 32, 35, 3, 1}, // 16-19 + { 34, 37, 2, 2},{ 34, 37, 2, 2},{ 34, 37, 2, 2},{ 34, 37, 2, 2}, // 20-23 + { 34, 37, 2, 2},{ 34, 37, 2, 2},{ 36, 39, 1, 3},{ 36, 39, 1, 3}, // 24-27 + { 36, 39, 1, 3},{ 36, 39, 1, 3},{ 38, 40, 0, 4},{ 41, 43, 5, 0}, // 28-31 + { 42, 45, 4, 1},{ 42, 45, 4, 1},{ 44, 47, 3, 2},{ 44, 47, 3, 2}, // 32-35 + { 46, 49, 2, 3},{ 46, 49, 2, 3},{ 48, 51, 1, 4},{ 48, 51, 1, 4}, // 36-39 + { 50, 52, 0, 5},{ 53, 43, 6, 0},{ 54, 57, 5, 1},{ 54, 57, 5, 1}, // 40-43 + { 56, 59, 4, 2},{ 56, 59, 4, 2},{ 58, 61, 3, 3},{ 58, 61, 3, 3}, // 44-47 + { 60, 63, 2, 4},{ 60, 63, 2, 4},{ 62, 65, 1, 5},{ 62, 65, 1, 5}, // 48-51 + { 50, 66, 0, 6},{ 67, 55, 7, 0},{ 68, 57, 6, 1},{ 68, 57, 6, 1}, // 52-55 + { 70, 73, 5, 2},{ 70, 73, 5, 2},{ 72, 75, 4, 3},{ 72, 75, 4, 3}, // 56-59 + { 74, 77, 3, 4},{ 74, 77, 3, 4},{ 76, 79, 2, 5},{ 76, 79, 2, 5}, // 60-63 + { 62, 81, 1, 6},{ 62, 81, 1, 6},{ 64, 82, 0, 7},{ 83, 69, 8, 0}, // 64-67 + { 84, 71, 7, 1},{ 84, 71, 7, 1},{ 86, 73, 6, 2},{ 86, 73, 6, 2}, // 68-71 + { 44, 59, 5, 3},{ 44, 59, 5, 3},{ 58, 61, 4, 4},{ 58, 61, 4, 4}, // 72-75 + { 60, 49, 3, 5},{ 60, 49, 3, 5},{ 76, 89, 2, 6},{ 76, 89, 2, 6}, // 76-79 + { 78, 91, 1, 7},{ 78, 91, 1, 7},{ 80, 92, 0, 8},{ 93, 69, 9, 0}, // 80-83 + { 94, 87, 8, 1},{ 94, 87, 8, 1},{ 96, 45, 7, 2},{ 96, 45, 7, 2}, // 84-87 + { 48, 99, 2, 7},{ 48, 99, 2, 7},{ 88,101, 1, 8},{ 88,101, 1, 8}, // 88-91 + { 80,102, 0, 9},{103, 69,10, 0},{104, 87, 9, 1},{104, 87, 9, 1}, // 92-95 + {106, 57, 8, 2},{106, 57, 8, 2},{ 62,109, 2, 8},{ 62,109, 2, 8}, // 96-99 + { 88,111, 1, 9},{ 88,111, 1, 9},{ 80,112, 0,10},{113, 85,11, 0}, // 100-103 + {114, 87,10, 1},{114, 87,10, 1},{116, 57, 9, 2},{116, 57, 9, 2}, // 104-107 + { 62,119, 2, 9},{ 62,119, 2, 9},{ 88,121, 1,10},{ 88,121, 1,10}, // 108-111 + { 90,122, 0,11},{123, 85,12, 0},{124, 97,11, 1},{124, 97,11, 1}, // 112-115 + {126, 57,10, 2},{126, 57,10, 2},{ 62,129, 2,10},{ 62,129, 2,10}, // 116-119 + { 98,131, 1,11},{ 98,131, 1,11},{ 90,132, 0,12},{133, 85,13, 0}, // 120-123 + {134, 97,12, 1},{134, 97,12, 1},{136, 57,11, 2},{136, 57,11, 2}, // 124-127 + { 62,139, 2,11},{ 62,139, 2,11},{ 98,141, 1,12},{ 98,141, 1,12}, // 128-131 + { 90,142, 0,13},{143, 95,14, 0},{144, 97,13, 1},{144, 97,13, 1}, // 132-135 + { 68, 57,12, 2},{ 68, 57,12, 2},{ 62, 81, 2,12},{ 62, 81, 2,12}, // 136-139 + { 98,147, 1,13},{ 98,147, 1,13},{100,148, 0,14},{149, 95,15, 0}, // 140-143 + {150,107,14, 1},{150,107,14, 1},{108,151, 1,14},{108,151, 1,14}, // 144-147 + {100,152, 0,15},{153, 95,16, 0},{154,107,15, 1},{108,155, 1,15}, // 148-151 + {100,156, 0,16},{157, 95,17, 0},{158,107,16, 1},{108,159, 1,16}, // 152-155 + {100,160, 0,17},{161,105,18, 0},{162,107,17, 1},{108,163, 1,17}, // 156-159 + {110,164, 0,18},{165,105,19, 0},{166,117,18, 1},{118,167, 1,18}, // 160-163 + {110,168, 0,19},{169,105,20, 0},{170,117,19, 1},{118,171, 1,19}, // 164-167 + {110,172, 0,20},{173,105,21, 0},{174,117,20, 1},{118,175, 1,20}, // 168-171 + {110,176, 0,21},{177,105,22, 0},{178,117,21, 1},{118,179, 1,21}, // 172-175 + {110,180, 0,22},{181,115,23, 0},{182,117,22, 1},{118,183, 1,22}, // 176-179 + {120,184, 0,23},{185,115,24, 0},{186,127,23, 1},{128,187, 1,23}, // 180-183 + {120,188, 0,24},{189,115,25, 0},{190,127,24, 1},{128,191, 1,24}, // 184-187 + {120,192, 0,25},{193,115,26, 0},{194,127,25, 1},{128,195, 1,25}, // 188-191 + {120,196, 0,26},{197,115,27, 0},{198,127,26, 1},{128,199, 1,26}, // 192-195 + {120,200, 0,27},{201,115,28, 0},{202,127,27, 1},{128,203, 1,27}, // 196-199 + {120,204, 0,28},{205,115,29, 0},{206,127,28, 1},{128,207, 1,28}, // 200-203 + {120,208, 0,29},{209,125,30, 0},{210,127,29, 1},{128,211, 1,29}, // 204-207 + {130,212, 0,30},{213,125,31, 0},{214,137,30, 1},{138,215, 1,30}, // 208-211 + {130,216, 0,31},{217,125,32, 0},{218,137,31, 1},{138,219, 1,31}, // 212-215 + {130,220, 0,32},{221,125,33, 0},{222,137,32, 1},{138,223, 1,32}, // 216-219 + {130,224, 0,33},{225,125,34, 0},{226,137,33, 1},{138,227, 1,33}, // 220-223 + {130,228, 0,34},{229,125,35, 0},{230,137,34, 1},{138,231, 1,34}, // 224-227 + {130,232, 0,35},{233,125,36, 0},{234,137,35, 1},{138,235, 1,35}, // 228-231 + {130,236, 0,36},{237,125,37, 0},{238,137,36, 1},{138,239, 1,36}, // 232-235 + {130,240, 0,37},{241,125,38, 0},{242,137,37, 1},{138,243, 1,37}, // 236-239 + {130,244, 0,38},{245,135,39, 0},{246,137,38, 1},{138,247, 1,38}, // 240-243 + {140,248, 0,39},{249,135,40, 0},{250, 69,39, 1},{ 80,251, 1,39}, // 244-247 + {140,252, 0,40},{249,135,41, 0},{250, 69,40, 1},{ 80,251, 1,40}, // 248-251 + {140,252, 0,41}}; // 252, 253-255 are reserved + +#define nex(state,sel) State_table[state][sel] #if 0 // change to #if 0 to generate this table at run time (4% slower) static const U8 State_table[256][4]={ @@ -934,7 +1001,7 @@ int StateTable::num_states(int x, int y) { if (x<0 || y<0 || x>=N || y>=N || y>=B || x>=b[y]) return 0; // States 0-30 are a history of the last 0-4 bits - if (x+y<=4) { // x+y choose x = (x+y)!/x!y! +/* if (x+y<=4) { // x+y choose x = (x+y)!/x!y! int r=1; for (int i=x+1; i<=x+y; ++i) r*=i; for (int i=2; i<=y; ++i) r/=i; @@ -943,7 +1010,7 @@ int StateTable::num_states(int x, int y) { // States 31-255 represent a 0,1 count and possibly the last bit // if the state is reachable by either a 0 or 1. - else + else*/ return 1+(y>0 && x+y>11; return pr=squash(dp); @@ -1432,7 +1499,6 @@ void train(short *t, short *w, int n, int err) { // prediction. Larger values are better for stationary sources. static int dt[1024]; // i -> 16K/(i+i+3) - struct StateMapContext { int N; // Number of contexts int cxt; // Context of last prediction @@ -1481,6 +1547,7 @@ struct StateMapContext { for (int i=0;i>20); } + printf("\n"); } }; @@ -1532,7 +1599,7 @@ struct APM2 { }; // based on https://encode.su/downloads/fpaq0p-sb_sh_full.rar -struct TAPM { +/*struct TAPM { U16 *t; int cxt; int pr,pr1; @@ -1592,7 +1659,7 @@ struct TAPM { } int trim(int x) { return __max(1,__min(4095,x)); } }; - +*/ // unaligned (sparse) // used with ERR struct UAS { @@ -2314,21 +2381,18 @@ class ContextMap { int mix(int m) {return mix1(m, x.c0, x.bpos, (U8) x.c4, x.y);} int get() {return result;} int inputs; - int mix3(BlockData& x, int m, int s, StateMapContext& sm); - int mix4(BlockData& x, int m, int s, StateMapContext& sm); - int (ContextMap::*mix2)(BlockData& , int , int , StateMapContext&); + int pre(int state) { assert(state>=0 && state<256); U32 n0=next(state, 2)*3+1; U32 n1=next(state, 3)*3+1; return (n1<<12) / (n0+n1); } - + }; // Find or create hash element matching checksum ch inline U8* ContextMap::E::get(U16 ch) { - if (chk[last&15]==ch) return &bh[last&15][0]; int b=0xffff, bi=0; @@ -2338,7 +2402,6 @@ inline U8* ContextMap::E::get(U16 ch) { if (pri>4!=i) b=pri, bi=i; } return last=0xf0|bi, chk[bi]=ch, (U8*)memset(&bh[bi][0], 0, 7); - } // Construct using m bytes of memory for c contexts(c+7)&-8 @@ -2361,12 +2424,11 @@ ContextMap::ContextMap(U64 m, int c, BlockData& bd,int s3,U8 *nn1,U8 *nn2,int cs cp0[i]=cp[i]=&t[0].bh[0][0]; runp[i]=cp[i]+3; } - // precalc int c=ilog(rc+1)<<(2+(~rc&1)); for (int rc=0;rc<256;rc++) { int c=ilog(rc); c=c<<(2+(~rc&1)); - c=c*cmul/4; + if (rc&1==0) c=c*cmul/4; if (cmul==1) c=0; rc1[rc+256]=clp(c); rc1[rc]=clp(-c); @@ -2384,17 +2446,15 @@ ContextMap::ContextMap(U64 m, int c, BlockData& bd,int s3,U8 *nn1,U8 *nn2,int cs if (s01) { st8[s] =clp(sc(cms4*(pre(s)-sp0))); st32[s]=clp(sc(cms3*stretch(pre(s)))); + if (s<8)st32[s]=0; }else{ st8[s] =0; st32[s]=0; } } - mix2=mix3; inputs=6; - if (rd==1)dRND=false; - // if second prediction falls off change to mix4 - if (cms2<8) mix2=mix4,dRND=false,inputs=5; + if (rd==1) dRND=false; } ContextMap::~ContextMap() { @@ -2412,83 +2472,12 @@ inline void ContextMap::set(U32 cx) { cx=cx<<16|cx>>16; cxt[i]=cx*123456791+i; } -// Predict to mixer m from bit history state s, using sm to map s to -// a probability. - -inline int ContextMap::mix3(BlockData& x, int m, int s, StateMapContext& sm) { - if (s==0){ - x.mxInputs[m].add(0); - x.mxInputs[m].add(0); - x.mxInputs[m].add(0); - x.mxInputs[m].add(0); - x.mxInputs[m].add(64); - return 0; - }else{ - sm.set(s,x.y); - int p1=sm.pr; - x.mxInputs[m].add(st1[p1]); - x.mxInputs[m].add(st2[p1]); - x.mxInputs[m].add(st8[s]); - x.mxInputs[m].add(st32[s]); - x.mxInputs[m].add(0); - return 1; - } -} -inline int ContextMap::mix4(BlockData& x, int m, int s, StateMapContext& sm) { - if (s==0){ - x.mxInputs[m].add(0); - x.mxInputs[m].add(0); - x.mxInputs[m].add(0); - x.mxInputs[m].add(64); - return 0; - }else{ - sm.set(s,x.y); - int p1=sm.pr; - x.mxInputs[m].add(st1[p1]); - x.mxInputs[m].add(st8[s]); - x.mxInputs[m].add(st32[s]); - x.mxInputs[m].add(0); - return 1; - } -} U32 getStateByteLocation(const int bpos, const int c0) { //from paq8px U32 pis = 0; //state byte position in slot - if (false) { - // this version is for readability - switch (bpos) { - case 0: //slot0 - pis = 0; - break; - case 1: //slot0 - pis = 1 + (c0 & 1); - break; - case 2: //slot1 - pis = 0; - break; - case 3: //slot1 - pis = 1 + (c0 & 1); - break; - case 4: //slot1 - pis = 3 + (c0 & 3); - break; - case 5: //slot2 - break; - case 6: //slot2 - pis = 1 + (c0 & 1); - break; - case 7: //slot2 - pis = 3 + (c0 & 3); - break; - } - } - else { - // this is a speed optimized (branchless) version of the above - const U32 smask = (U32(0x31031010) >> (bpos << 2)) & 0x0F; - pis = smask + (c0 & smask); - } - + const U32 smask = (U32(0x31031010) >> (bpos << 2)) & 0x0F; + pis = smask + (c0 & smask); return pis; } // Update the model with bit y1, and predict next bit to mixer m. @@ -2539,15 +2528,28 @@ int ContextMap::mix1(int m, int cc, int bp, int c1, int y1) { runp[i][0]=1, runp[i][1]=c1; else if (runp[i][0]<254) // same byte in context runp[i][0]+=2; - //else if (runp[i][0]==255) - // runp[i][0]=128; runp[i]=cp0[i]+3; } s = *cp[i]; } // predict from bit context - result=result+(this->*mix2)(x,m, s, sm[i]); + if (s==0){ + x.mxInputs[m].add(0); + x.mxInputs[m].add(0); + x.mxInputs[m].add(0); + x.mxInputs[m].add(0); + x.mxInputs[m].add(32*2); + }else{ + sm[i].set(s,x.y); + const int p1=sm[i].pr; + x.mxInputs[m].add(st1[p1]); + x.mxInputs[m].add(st2[p1]); + x.mxInputs[m].add(st8[s]); + x.mxInputs[m].add(st32[s]); + x.mxInputs[m].add(0); + result++; + } // predict from last byte in context int b=x.c0shift_bpos ^ (runp[i][1] >> x.bposshift); if (b<=1) { @@ -2565,8 +2567,10 @@ int ContextMap::mix1(int m, int cc, int bp, int c1, int y1) { // // Autotune component parameters +bool doRad=true; U32 cseed=0; - +U32 minTune=2; +bool e_nn[256]; void compressStream(U32 streamid,U64 size, FILE* in, FILE* out); double randfloat(){return (double(rand())+0.5)/double(RAND_MAX+1);}; @@ -2613,7 +2617,7 @@ struct VMParam { int vm_err_limit[256]; bool vm_err1[256]; int vm_err1_limit[256]; - bool vm_tapm[256]; + /* bool vm_tapm[256]; int vm_tapm_limit0[256]; int vm_tapm_limit1[256]; int vm_tapm_limit2[256]; @@ -2621,7 +2625,7 @@ struct VMParam { int vm_tapm_limit4[256]; int vm_tapm_limitw1[256]; int vm_tapm_limitw2[256]; - int vm_tapm_limitwb1[256]; + int vm_tapm_limitwb1[256];*/ bool vm_uas[256]; bool vm_uasm[256]; int vm_uas_mask[256]; @@ -2642,7 +2646,7 @@ struct VMParam { int vm_byt_limit[256]; int vm_byt_limit_max[256]; bool isactive; - void set(bool m, bool ml, bool apm, bool smc, bool ds,bool mue,bool cm,bool sm,bool cms,bool rcm,bool tapm, bool err, bool uas, bool lmx, bool sta, bool apm2, bool byt){ + void set(bool m, bool ml, bool apm, bool smc, bool ds,bool mue,bool cm,bool sm,bool cms,bool rcm,bool tapm, bool err, bool uas, bool lmx, bool *sta, bool apm2, bool byt){ isactive=true; for (int i=0;i<256;i++) vm_mixer[i]=m; for (int i=0;i<256;i++) vm_mixer_ml[i]=ml; @@ -2658,12 +2662,12 @@ struct VMParam { for (int i=0;i<256;i++) vm_cms4[i]=cms; for (int i=0;i<256;i++) vm_sm[i]=sm; for (int i=0;i<256;i++) vm_rcm[i]=rcm; - for (int i=0;i<256;i++) vm_tapm[i]=tapm; + //for (int i=0;i<256;i++) vm_tapm[i]=tapm; for (int i=0;i<256;i++) vm_err[i]=err; for (int i=0;i<256;i++) vm_err1[i]=err; for (int i=0;i<256;i++) vm_uas[i]=uas; for (int i=0;i<256;i++) vm_lmx[i]=lmx; - for (int i=0;i<256;i++) vm_nnst[i]=sta; + for (int i=0;i<256;i++) vm_nnst[i]=sta[i]; for (int i=0;i<256;i++) vm_byt[i]=byt; // no command line select for (int i=0;i<256;i++) vm_avg[i]=false; @@ -2753,43 +2757,43 @@ int CreateVector(VMParam *Param,Parameter *parameters) { for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit0[i]; - parameters[n].min=0;parameters[n].max=63; + parameters[n].min=0;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit1[i]; - parameters[n].min=0;parameters[n].max=63; + parameters[n].min=0;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit2[i]; - parameters[n].min=0;parameters[n].max=63; + parameters[n].min=0;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit3[i]; - parameters[n].min=0;parameters[n].max=63; + parameters[n].min=0;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit4[i]; - parameters[n].min=0;parameters[n].max=63; + parameters[n].min=0;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit5[i]; - parameters[n].min=3;parameters[n].max=32; + parameters[n].min=3;parameters[n].max=33; n++; } for (int i=0;i<256;i++) if (Param->vm_nnst[i]) { parameters[n].param=&Param->vm_nnst_limit6[i]; - parameters[n].min=2;parameters[n].max=32; + parameters[n].min=2;parameters[n].max=33; n++; } for (int i=0;i<256;i++) @@ -2863,6 +2867,7 @@ int CreateVector(VMParam *Param,Parameter *parameters) { parameters[n].min=1;parameters[n].max=60; n++; } + for (int i=0;i<256;i++) if (Param->vm_rcm[i]) {parameters[n].t=0; parameters[n].param=&Param->vm_rcm_limit[i]; @@ -2900,7 +2905,7 @@ int CreateVector(VMParam *Param,Parameter *parameters) { parameters[n].min=2047;parameters[n].max=4094; n++; } - for (int i=0;i<256;i++) + /*for (int i=0;i<256;i++) if (Param->vm_tapm[i]) { parameters[n].param=&Param->vm_tapm_limit0[i]; parameters[n].min=0;parameters[n].max=2048+1024; @@ -2947,7 +2952,7 @@ int CreateVector(VMParam *Param,Parameter *parameters) { parameters[n].param=&Param->vm_tapm_limitwb1[i]; parameters[n].min=1;parameters[n].max=70*2; n++; - } + }*/ for (int i=0;i<256;i++) if (Param->vm_uasm[i]) { parameters[n].param=&Param->vm_uas_mask[i]; @@ -2975,10 +2980,12 @@ void ChangeParameter(int idx,double radius) { int min_param=parameters[idx].min; int max_param=parameters[idx].max; int r=(int)(radius*double(max_param-min_param)+0.5); - /*if (*p==0){ - *p = randint(min_param,max_param); - }else*/ - *p = randint(max(min_param,*p-r),min(max_param,*p+r)); + if (doRad==true) + *p = randint(max(min_param,*p-r),min(max_param,*p+r)); + else + *p = randint(min_param,max_param); + + } void CreateProposal(VMParam *Param, double radius) { @@ -3041,9 +3048,9 @@ void Tune(int maxruns, double radius) { // we found new optimum double rate=accepted+rejected>0?double(accepted)/double(accepted+rejected):0.0; - printf("[%i] [rate: %4.1f%%], time: %d, temperature: %0.9f\r",total_runs,rate*100.0,btime,temperature); + printf("[%i] [rate: %4.1f%%], time: %d, temperature: %0.9f, proposal: %d\r",total_runs,rate*100.0,btime,temperature,proposal); - if ((proposal+2)vm_smc[0]==true) printf("\nsmc limit:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_smc[i]==true) printf("%d, ",parm2[streamid]->vm_smc_limit[i]); if (parm2[streamid]->vm_ds[0]==true) printf("\nds limit:\n"); - for (int i=0;i<256;i++) if (parm2[streamid]->vm_ds[i]==true) printf("%d, ",parm2[streamid]->vm_ds_limit[i]); + for (int i=0;i<256;i++) if (parm2[streamid]->vm_ds[i]==true) printf("%d ",parm2[streamid]->vm_ds_limit[i]); if (parm2[streamid]->vm_byt[0]==true) printf("\nbyt limit:\n"); - if (parm2[streamid]->vm_byt[0]==true) for (int i=0;i<256;i++) printf("%d, ",parm2[streamid]->vm_byt_limit[i]); + if (parm2[streamid]->vm_byt[0]==true) {for (int i=0;i<256;i++) printf("%d, ",parm2[streamid]->vm_byt_limit[i]); + + /* printf("\nGroup\n"); + for (int i=0;i<7;i++) {printf("\nGroup:%d\n",i); + for (int j=0;j<127;j++) if (parm2[streamid]->vm_byt_limit[j]==i)printf("%c",j); + }*/ + } if (parm2[streamid]->vm_cm[0]==true) printf("\ncm run limit:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_cm[i]==true) printf("%2d, ",parm2[streamid]->vm_cm_limit[i]); if (parm2[streamid]->vm_cms[0]==true) printf("\ncms rate:\n"); @@ -3851,7 +3863,7 @@ void pTune(int streamid,U64 size, FILE* in, FILE* out) { for (int i=0;i<256;i++) if (parm2[streamid]->vm_uas[i]==true) printf("%d, ",parm2[streamid]->vm_uas_bits[i]); if (parm2[streamid]->vm_uasm[0]==true) printf("\nuas mask:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_uasm[i]==true) printf("%d, ",parm2[streamid]->vm_uas_mask[i]); - if (parm2[streamid]->vm_tapm[0]==true) printf("\ntapm limit:\n"); + /*if (parm2[streamid]->vm_tapm[0]==true) printf("\ntapm limit:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_tapm[i]==true) printf( "%d+(%d<<16),%d|(%d<<12)|(%d<<24),%d+(%d<<16)+(%d<<24)\n" ,parm2[streamid]->vm_tapm_limit0[i], @@ -3860,19 +3872,26 @@ void pTune(int streamid,U64 size, FILE* in, FILE* out) { parm2[streamid]->vm_tapm_limit3[i],parm2[streamid]->vm_tapm_limitwb1[i], parm2[streamid]->vm_tapm_limit4[i], parm2[streamid]->vm_tapm_limitw1[i], - parm2[streamid]->vm_tapm_limitw2[i]); + parm2[streamid]->vm_tapm_limitw2[i]); */ if (parm2[streamid]->vm_lmx[0]==true) printf("\nlmx w:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_lmx[i]==true) printf("%d, ",parm2[streamid]->vm_lmx_w[i]); if (parm2[streamid]->vm_nnst[0]==true) printf("\nstatetable limit:\n"); for (int i=0;i<256;i++) if (parm2[streamid]->vm_nnst[i]==true) printf( - "%d+(%d<<16),%d|(%d<<16),%d+(%d<<16)+(%d<<24)\n" + "(%d): %d+(%d<<16),%d|(%d<<16),%d+(%d<<16)+(%d<<24) ",i ,parm2[streamid]->vm_nnst_limit0[i], parm2[streamid]->vm_nnst_limit1[i], parm2[streamid]->vm_nnst_limit2[i], parm2[streamid]->vm_nnst_limit3[i], parm2[streamid]->vm_nnst_limit4[i], parm2[streamid]->vm_nnst_limit5[i], - parm2[streamid]->vm_nnst_limit6[i]); + parm2[streamid]->vm_nnst_limit6[i]), + printf("%d %d %d %d %d %d %d\n",parm2[streamid]->vm_nnst_limit0[i], + parm2[streamid]->vm_nnst_limit1[i], + parm2[streamid]->vm_nnst_limit2[i], + parm2[streamid]->vm_nnst_limit3[i], + parm2[streamid]->vm_nnst_limit4[i], + parm2[streamid]->vm_nnst_limit5[i], + parm2[streamid]->vm_nnst_limit6[i]); printf("\n\n"); if (SA.GetStart()<=SA.GetBest() ){ printf("Tune failed. No improvment. Exit.\n"); @@ -4462,7 +4481,7 @@ printf("\n"); " n - sm limit\n" " o - cm sm rate\n" " p - rcm mul\n" - " q - tapm\n" + " q - tapm - not available\n" " r - err\n" " s - uas\n" " t - lmx\n" @@ -4471,9 +4490,11 @@ printf("\n"); " x - byt\n" " -o n specifies percentage of tune, default=100\n" " -r number of tune runs, default=25\n" + " -m minimum tune improvment in bytes, default=2\n" " -f full tune on all parameters, default=false\n" " -bc bc - enable bounds check at compile, dafault=false\n" " -br br - enable bounds check at runtime, dafault=false\n" + " -k k - disable radius in tune, dafault=true\n" " -j j - do JIT, dafault=false\n" " -i i - show cfg component info, default=false\n" " -s s - seed for tune, default=random\n" @@ -4500,6 +4521,7 @@ int getOption(int argc,char **argv) { else if (tmp[1]=='l') doList=true; else if (tmp[1]=='f') doFullOpt=true; else if (tmp[1]=='p') ePRT=true; + else if (tmp[1]=='k') doRad=false,printf("tune: radius disabled\n"); else if (tmp[1]=='i') doDebugInfo=true,printf("DBG: show info\n"); else if (tmp[1]=='j') doJIT=true,printf("JIT: enabled\n"); else if (tmp[1]=='0') level=0,printf("Mode: transform\n"); @@ -4509,6 +4531,7 @@ int getOption(int argc,char **argv) { else if (tmp[1]=='c' && tmp[2]!=0) config=(const char*)&tmp[2],printf("Config: %s\n",config.c_str()); else if (tmp[1]=='2') { level=2; + int n=0; ePRT=false; // disable in tune mode bool m=false; bool ml=false; bool apm=false; bool smc=false; bool ds=false; bool mue=false; bool cm=false; bool sm=false; @@ -4525,16 +4548,29 @@ int getOption(int argc,char **argv) { if (tmp[9]=='t') sm=true,printf("sm: enabled\n"); else if (tmp[9]=='f') sm=false; else printHelp(); if (tmp[10]=='t') cms=true,printf("cms: enabled\n"); else if (tmp[10]=='f') cms=false; else printHelp(); if (tmp[11]=='t') rcm=true,printf("rcm: enabled\n"); else if (tmp[11]=='f') rcm=false; else printHelp(); - if (tmp[12]=='t') tapm=true,printf("tapm: enabled\n"); else if (tmp[12]=='f') tapm=false; else printHelp(); + if (tmp[12]=='t') /*tapm=true,printf("tapm: enabled\n"); else if (tmp[12]=='f') tapm=false; else*/ printHelp(); if (tmp[13]=='t') err=true,printf("err: enabled\n"); else if (tmp[13]=='f') err=false; else printHelp(); if (tmp[14]=='t') uas=true,printf("uas: enabled\n"); else if (tmp[14]=='f') uas=false; else printHelp(); if (tmp[15]=='t') lmx=true,printf("lmx: enabled\n"); else if (tmp[15]=='f') lmx=false; else printHelp(); - if (tmp[16]=='t') sta=true,printf("sta: enabled\n"); else if (tmp[16]=='f') sta=false; else printHelp(); - if (tmp[17]=='t') apm2=true,printf("apm2: enabled\n"); else if (tmp[17]=='f') apm2=false; else printHelp(); - if (tmp[18]=='t') byt=true,printf("byt: enabled\n"); else if (tmp[18]=='f') byt=false; else printHelp(); - if (tmp[19]!=0) printHelp(); + if (tmp[16]=='t') { + /*sta=true,*/printf("sta: enabled\n"); + if (tmp[17]=='1' || tmp[17]=='0'){ + + for (int j=0;j<256;j++) + if (tmp[17+j]=='1' || tmp[17+j]=='0') { + e_nn[j]=(tmp[17+j]=='1'?true:false); + }else {n=j; + break; + } + + for (int j=n;j<256;j++) e_nn[j]=false; + }else for (int j=0;j<256;j++) e_nn[j]=true; + } else if (tmp[16]=='f') for (int j=0;j<256;j++) e_nn[j]=false; else printHelp(); + if (tmp[17+n]=='t') apm2=true,printf("apm2: enabled\n"); else if (tmp[17+n]=='f') apm2=false; else printHelp(); + if (tmp[18+n]=='t') byt=true,printf("byt: enabled\n"); else if (tmp[18+n]=='f') byt=false; else printHelp(); + if (tmp[19+n]!=0) printHelp(); // set stream parms active - for (int i=0;i<256;i++) parm1[i].set(m, ml, apm, smc, ds, mue, cm, sm, cms, rcm, tapm, err, uas, lmx,sta,apm2,byt); + for (int i=0;i<256;i++) parm1[i].set(m, ml, apm, smc, ds, mue, cm, sm, cms, rcm, tapm, err, uas, lmx,&e_nn[0],apm2,byt); } #ifdef MT else if (tmp[1]=='t') { @@ -4548,6 +4584,8 @@ int getOption(int argc,char **argv) { if (strlen(tmp+2)>0) max_fraction=clamp(atoi(tmp+2),0,100); } else if (tmp[1]=='r'){ max_runs=clamp(atoi(tmp+2),0,1000); + } else if (tmp[1]=='m'){ + minTune=atoi(tmp+2),printf("minTune: %d\n",minTune); } else printf("unknown option '%s'\n",tmp); } else { break; diff --git a/vm.cpp b/vm.cpp index 7a481fe..c98dbb0 100644 --- a/vm.cpp +++ b/vm.cpp @@ -95,7 +95,7 @@ char *mod; int totalPR; Array mcomp; //component list set in vmi ArraycmC; - int smc, apm1, rcm, scm, cm, mx,st,av,ds,mm,dhs,sm,sk,apm2,em,tapm,uas,lmx,statec,byt; + int smc, apm1, rcm, scm, cm, mx,st,av,ds,mm,dhs,sm,sk,apm2,em,/*tapm,*/uas,lmx,statec,byt; MixMap1 mmA[256]; Mixer1 mxA[256]; @@ -111,7 +111,7 @@ char *mod; SkMap skA[256]; APM2 apm2A[256]; ErrMap emA[256]; - TAPM tapmA[256]; + //TAPM tapmA[256]; UAS uasA[256]; LmxMap lmxA[256]; ByteMap bmA[256]; @@ -123,8 +123,6 @@ char *mod; int inpos; int plpos; VMParam *parm; - //FS vmstate; - // STZ vmstate; StateTable vmstate; U8 vm_nn[256][512*4]; U8 nn01[256][256]; @@ -172,9 +170,9 @@ void VM::killvm( ){ if ( apm2>0 ) { for (int i=0;i0 ) { + /* if ( tapm>0 ) { for (int i=0;i0 ) { for (int i=0;i0 ) { for (int i=0;iinitdone==1) {kprintf("VM vms error: vms allowed only in main\n ");quit();} if (v->totalc>0) {kprintf("VM vms error: vms allready called\n ");quit();} - v->smc=a, v->apm1=b,v->ds=c,v->av=d,v->scm=e, v->rcm=f, v->cm=g, v->mx=h,v->st=i,v->mm=j,v->dhs=k,v->sm=l,v->sk=m,v->apm2=o,v->em=p,v->tapm=q,v->uas=r,v->lmx=s,v->statec=sg,v->byt=bt; + v->smc=a, v->apm1=b,v->ds=c,v->av=d,v->scm=e, v->rcm=f, v->cm=g, v->mx=h,v->st=i,v->mm=j,v->dhs=k,v->sm=l,v->sk=m,v->apm2=o,v->em=p,/*v->tapm=q,*/v->uas=r,v->lmx=s,v->statec=sg,v->byt=bt; v->totalc= a+b+c+d+e+f+g+h+i+j+k+h+l+m+o+p+q+r+s+sg+bt; v->mcomp.resize(v->totalc); if (v->totalc==0 && h>0) quit("No inputs for mixer defined VM\n"); } //vmi - init components -enum {vmSMC=1,vmAPM1,vmDS,vmAVG,vmSCM,vmRCM,vmCM,vmMX,vmST,vmMM,vmDHS,vmSM,vmSK,vmAPM2,vmERR,vmTAPM,vmUAS,vmLMX,vmSTA,vmBYT}; +enum {vmSMC=1,vmAPM1,vmDS,vmAVG,vmSCM,vmRCM,vmCM,vmMX,vmST,vmMM,vmDHS,vmSM,vmSK,vmAPM2,vmERR,vmTAPM1,vmUAS,vmLMX,vmSTA,vmBYT}; const char* cNames[]={ "SMC","APM","DS ","AVG","SCM","RCM","CM ","MX ","ST ","MM ","DHS","SM ","SK ","AP2","ERR","TAP","UAS","LMX","STA","BYT" }; @@ -238,14 +234,16 @@ void printcomponent(int component){ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int indexOfInputs){ //assert(componentIndex>=0); //component index //assert(d>=0); //component context - int cms3=0,cms4=0,rd=0; - if (component==vmCM) cms3=(indexOfInputs>>8)&255,cms4=(indexOfInputs>>16)&255,rd=(indexOfInputs>>28)&1,indexOfInputs=indexOfInputs&255; + int cms3=0,cms4=0,rd=0,cmbias=2; + if (component==vmCM) cms3=(indexOfInputs>>8)&255,cms4=(indexOfInputs>>16)&255,cmbias=(indexOfInputs>>24)&15,rd=(indexOfInputs>>28)&1,indexOfInputs=indexOfInputs&255; + if ( component==vmDS) cms3=(indexOfInputs>>8)&0xffff,indexOfInputs=indexOfInputs&255; //printcomponent(component); printf(" component %d, componentIndex %d, f %d, d %d, indexOfInputs %d\n",component, componentIndex, f, d, indexOfInputs); if (v->initdone==1) {kprintf("VM vmi error: vmi allowed only in main\n ");quit();} if (v->currentc> v->totalc) {kprintf("VM vmi error: component %d not set %d - %d\n ",component,v->currentc, v->totalc);quit();} if (componentIndex> 255) {kprintf("VM vmi error: componentIndex\n ");quit();} + if (component==vmTAPM1 ) {kprintf("VM vmi error: TAPM is disabled.\n ");quit();} const int ii=componentIndex+1; - bool isInputs= (component==vmAPM1 || component==vmAPM2 || component==vmTAPM || component==vmUAS||component==vmDS||component==vmERR||component==vmBYT||component==vmSTA|| component==vmDHS || component==vmAVG || (component==vmST && indexOfInputs==-1)||(component==vmSK && indexOfInputs==-1)||(component==vmSMC && indexOfInputs==-1)); + bool isInputs= (component==vmAPM1 || component==vmAPM2 /*|| component==vmTAPM*/ || component==vmUAS||component==vmDS||component==vmERR||component==vmBYT||component==vmSTA|| component==vmDHS || component==vmAVG || (component==vmST && indexOfInputs==-1)||(component==vmSK && indexOfInputs==-1)||(component==vmSMC && indexOfInputs==-1)); if (indexOfInputs>=0 && v->x.cInputs x.cInputs++; v->x.mxInputs.resize(v->x.mxInputs.size()+1); @@ -256,15 +254,27 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde } switch (component) { - case vmSMC: {if ( indexOfInputs==-1)v->totalPR++; if (ii>v->smc ) {kprintf("VM vmi error: smc(%d) defined %d, max %d\n",component,ii, v->smc);quit(); } - if ( indexOfInputs>=0) v->x.mxInputs[indexOfInputs].ncount++; - break; } - case vmAPM1:{v->totalPR++; if (ii>v->apm1) {kprintf("VM vmi error: apm1(%d) defined %d, max %d\n",component,ii, v->apm1);quit();} - break; } + case vmSMC: { + if ( indexOfInputs==-1)v->totalPR++; + if (ii>v->smc ) { + kprintf("VM vmi error: smc(%d) defined %d, max %d\n",component,ii, v->smc); + quit(); + } + if ( indexOfInputs>=0) v->x.mxInputs[indexOfInputs].ncount++; + break; + } + case vmAPM1:{ + v->totalPR++; + if (ii>v->apm1) { + kprintf("VM vmi error: apm1(%d) defined %d, max %d\n",component,ii, v->apm1); + quit(); + } + break; + } case vmAPM2:{v->totalPR++; if (ii>v->apm2) {kprintf("VM vmi error: apm2(%d) defined %d, max %d\n",component,ii, v->apm2);quit();} break; } - case vmTAPM:{v->totalPR++; if (ii>v->tapm) {kprintf("VM vmi error: tapm(%d) defined %d, max %d\n",component,ii, v->tapm);quit();} - break; } + // case vmTAPM:{v->totalPR++; if (ii>v->tapm) {kprintf("VM vmi error: tapm(%d) defined %d, max %d\n",component,ii, v->tapm);quit();} + // break; } case vmUAS:{v->totalPR++; if (ii>v->uas) {kprintf("VM vmi error: uas(%d) defined %d, max %d\n",component,ii, v->uas);quit();} break; } case vmDS:{v->totalc=v->totalc+indexOfInputs-1;v->mcomp.resize(v->mcomp.size()+indexOfInputs); v->totalPR+=indexOfInputs; if (ii>v->ds) {kprintf("VM vmi error: ds(%d) defined %d, max %d\n",component,ii, v->ds);quit();} @@ -307,7 +317,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde } int prindex=0; - if (component==vmAPM1 || component==vmAPM2|| component==vmTAPM || component==vmUAS || component==vmDS|| component==vmDHS || component==vmAVG || component==vmLMX|| (component==vmST && indexOfInputs==-1)||(component==vmSK && indexOfInputs==-1)||(component==vmSMC && indexOfInputs==-1) || component==vmMX)prindex=v->totalPR; + if (component==vmAPM1 || component==vmAPM2|| /*component==vmTAPM ||*/ component==vmUAS || component==vmDS|| component==vmDHS || component==vmAVG || component==vmLMX|| (component==vmST && indexOfInputs==-1)||(component==vmSK && indexOfInputs==-1)||(component==vmSMC && indexOfInputs==-1) || component==vmMX)prindex=v->totalPR; // If Autotune then ignore model parameters, first run is allways with model parameters. switch (component) { case vmSMC:{ @@ -349,7 +359,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde v->apm2A[componentIndex].Init(f,(apm_l<<8)+apm_s,indexOfInputs); break; } - case vmTAPM: { + /*case vmTAPM: { int apm_l0=f&0xffff; // limit int apm_l1=f>>16; int apm_l2=d&0xfff; @@ -383,7 +393,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde } v->tapmA[componentIndex].Init(apm_l0,apm_l1,apm_l2,apm_l3,apm_l4,apm_w1,apm_w2,apm_wb1); break; - } + }*/ case vmSTA: { int sta_l0=f&0xffff; // limit int sta_l1=f>>16; @@ -393,7 +403,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde int sta_l5=(indexOfInputs>>16)&255; int sta_l6=(indexOfInputs>>24)&255; int isSta=sta_l0|sta_l1|sta_l2|sta_l3|sta_l4|sta_l5|sta_l6; - if (isSta==0)sta_l0=42,sta_l1=41,sta_l2=13,sta_l3=6,sta_l4=5,sta_l5=16,sta_l6=14; + if (isSta==0)sta_l0=42,sta_l1=41,sta_l2=13,sta_l3=6,sta_l4=5,sta_l5=41,sta_l6=64; // These parameters are bad if (v->parm){ if (v->parm->vm_nnst[componentIndex]){ if (v->parm->isactive==true) { @@ -465,12 +475,14 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde break; } case vmDS: { - int ds_l=d; + int ds_l=U32(d)&0xffff; + int ds_l1=U32(d)>>16; int stable=f>>16; if (v->parm){ if (v->parm->vm_ds[componentIndex]){ if (v->parm->isactive==true) v->parm->vm_ds_limit[componentIndex]=ds_l; ds_l=v->parm->vm_ds_limit[componentIndex]; + //printf("%d\n",ds_p0); } } U8 *n=&v->vm_nn[stable][0]; @@ -560,21 +572,23 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde v->parm->vm_byt_limit_max[componentIndex]=b_l; } b_v=v->parm->vm_byt_limit[componentIndex]; + //printf("%d, ",b_v); } v->bmA[componentIndex].Init(b_v); break; } case vmCM:{ if (componentIndex>=v->cmC.size()) printf("CM index %d to large. Max %d\n",componentIndex,v->cmC.size32()),quit(); - int cm_l=(d>>8)&255; // limit + int cm_l=(U32(d)>>8)&255; // limit if (cm_l==0) cm_l=4; - int cms_l=(d>>16)&255; // sm rate + int cms_l=(U32(d)>>16)&255; // sm rate if (cms_l==0) cms_l=32; int cms2_l=(U32(d)>>24)&255; // sm2 rate if (cms2_l==0) cms2_l=12; if (cms3==0) cms3=32; if (cms4==0) cms4=12; - int mem=f&0xffffff; + if (cmbias<2) cmbias=2; + int mem=U32(f)&0xffffff; int stindex=U32(f)>>24; if (v->parm){ if (v->parm->vm_cm[componentIndex]){ @@ -651,7 +665,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde break; } int m=indexOfInputs; - if (component==vmAVG || component==vmLMX ||component==vmAPM1|| component==vmAPM2|| component==vmTAPM|| component==vmERR|| component==vmBYT|| component==vmSTA|| component==vmUAS) m=0; + if (component==vmAVG || component==vmLMX ||component==vmAPM1|| component==vmAPM2|| /*component==vmTAPM||*/ component==vmERR|| component==vmBYT|| component==vmSTA|| component==vmUAS) m=0; if (indexOfInputs==-1) m=0; if (component==vmDS || component==vmDHS ) {m=0; for (int j=0;j< indexOfInputs;j++) v->mcomp[v->currentc++] =m+((prindex-indexOfInputs+j+1)<<24)+(componentIndex<<16)+(component<<8); @@ -668,6 +682,7 @@ void initcomponent(VM* v,int component,int componentIndex, int f,int d, int inde //if (v->mcomp[v->currentc-1]&0xff=vmMM) printf("pr[%d] ",v->mcomp[v->currentc-1]>>16&0xff); printf("\n" ); } + //when no mixer is present and some component uses mixer, crash } void initcomponent1(const int indexOfInputs, const int d, const int f,const int componentIndex, const int component, VM* v){ initcomponent( v, component, componentIndex, f, d, indexOfInputs); @@ -685,9 +700,9 @@ int setcomponent(VM* v, int c, int i, U32 f){ case vmAPM2:{ v->apm2A[i].cx=(f); break;} - case vmTAPM:{ + /*case vmTAPM:{ v->tapmA[i].set(f, v->x.y); - break;} + break;}*/ case vmDS:{ v->dsA[i].set(f,v->x.y); break;} @@ -768,15 +783,15 @@ int writefile(VM* v,U8 *i,int size){ } int writefile1(int size, U8 *i,VM* v){return writefile(v,i, size);} VM::VM(char* m,BlockData& bd,int mode, VMParam *p):data1(2024*1024),x(bd),vmMode(mode),mem(0),memSize(0),membound(0),prSize(0),mcomp(0),cmC(0),parm(p), - vmstate(42,41,13,6,5,16,14) //statable + vmstate(42,41,13,6,5,41,63) //statable 42,41,13,6,5,16,14 { data=&data1[0]; mod=m; - smc=apm1=apm2=tapm=uas=rcm=scm=cm=mx=st=av=mm=ds=dhs=sm=sk=statec=byt=currentc=totalc=initdone=mindex=totalPR=em=plpos=0; + smc=apm1=apm2=/*tapm=*/uas=rcm=scm=cm=mx=st=av=mm=ds=dhs=sm=sk=statec=byt=currentc=totalc=initdone=mindex=totalPR=em=plpos=0; debug=0; if (mode==VMCOMPRESS){ // init statetable - for (int i=0;i<256;i++) vm_nn[0][i]=vmstate.next(i,0); + /*for (int i=0;i<256;i++) vm_nn[0][i]=vmstate.next(i,0); for (int i=256;i<512;i++) vm_nn[0][i]=vmstate.next(i-256,1); for (int i=512;i<512+256;i++) vm_nn[0][i]=vmstate.next(i-512,2); for (int i=512+256;i<512+512;i++) vm_nn[0][i]=vmstate.next(i-256-512,3); @@ -787,6 +802,19 @@ VM::VM(char* m,BlockData& bd,int mode, VMParam *p):data1(2024*1024),x(bd),vmMode if ((n1-n0)==1 ) r=2; if ((n1-n0)==-1 ) r=1; nn01[0][i]=r; + }*/ + // Use original state table if none defined + for (int i=0;i<256;i++) vm_nn[0][i]=nex(i,0); + for (int i=256;i<512;i++) vm_nn[0][i]=nex(i-256,1); + for (int i=512;i<512+256;i++) vm_nn[0][i]=nex(i-512,2); + for (int i=512+256;i<512+512;i++) vm_nn[0][i]=nex(i-256-512,3); + for (int i=0;i<256;i++) { + int n0=-!nex(i,2); + int n1=-!nex(i,3); + int r=0; + if ((n1-n0)==1 ) r=2; + if ((n1-n0)==-1 ) r=1; + nn01[0][i]=r; } } //load cfg file, if error then exit @@ -807,7 +835,7 @@ VM::VM(char* m,BlockData& bd,int mode, VMParam *p):data1(2024*1024),x(bd),vmMode int maxAPM2=-1; int maxAVG=-1; int maxERR=-1; - int maxTAPM=-1; + //int maxTAPM=-1; int maxUAS=-1; int maxLMX=-1; int maxSTA=-1; @@ -840,7 +868,7 @@ VM::VM(char* m,BlockData& bd,int mode, VMParam *p):data1(2024*1024),x(bd),vmMode int index=((mcomp[i]>>16)&0xff)+1; if (compnr==vmAPM1){ maxAPM=index; } else if (compnr==vmAPM2){ maxAPM2=index; } - else if (compnr==vmTAPM){ maxTAPM=index; } + // else if (compnr==vmTAPM){ maxTAPM=index; } else if (compnr==vmSMC){ maxSMC=index; } else if (compnr==vmDS){ maxDS=index; } else if (compnr==vmCM){ maxCM=maxCMS=index; } @@ -867,9 +895,9 @@ VM::VM(char* m,BlockData& bd,int mode, VMParam *p):data1(2024*1024),x(bd),vmMode for (int i=maxAPM2;i<256;i++){ parm->vm_apm2[i]=false; } - for (int i=maxTAPM;i<256;i++){ + /*for (int i=maxTAPM;i<256;i++){ parm->vm_tapm[i]=false; - } + }*/ for (int i=maxSMC;i<256;i++){ parm->vm_smc[i]=false; } @@ -1769,10 +1797,10 @@ int VM::getPrediction( ){ prSize[prindex]=apm2A[index].p(prSize[apm2A[index].p1],x.y); break; } - case vmTAPM: {if (doPRT==true) printf("prSize[%d]=tapmA[%d].p(x.y);\n",prindex,index); + /*case vmTAPM: {if (doPRT==true) printf("prSize[%d]=tapmA[%d].p(x.y);\n",prindex,index); prSize[prindex]=tapmA[index].p(x.y); break; - } + }*/ case vmUAS: {if (doPRT==true) printf("prSize[%d]=uasA[%d].p(x.y);\n",prindex,index); prSize[prindex]=uasA[index].p(x.y); break;