-
Notifications
You must be signed in to change notification settings - Fork 1
/
txtfast.cfg
179 lines (166 loc) · 5.35 KB
/
txtfast.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Model for text
enum {SMC=1,APM1,DS,AVG,SCM,RCM,CM,MX,ST,MM,DHS,SM,SK,APM2,ERR,TAPM,UAS,LMX,STA};
int t[14]={} ; // ={} - let VM to alloc memory and set values to 0
int info;
int c1,word0,word1,apmfails;
int primes[14]={ 0, 257,251,241,239,233,229,227,223,211,199,197,193,191 };
// Parameters
// tuned on enwik8 first <25MB
int m_e[9]={}; // mixer error
int m_s[9]={17};// mixer shift
int m_m[9]={24};// mixer error mul
int c_r[8]={5, 4, 6, 4, 12, 16, 4,0}; // contextmap run mul
int c_s[8]={35, 28, 41, 54, 42, 38, 44, 35}; // contextmap pr mul
int c_s2[8]={10, 3, 7, 13, 10, 11, 15, 12}; // ...
int c_s3[8]={44, 32, 34, 51, 16, 43, 30, 30};
int c_s4[8]={6, 4, 5, 9, 13, 11, 19, 9};
int e_l[8]={1487, 1971, 1685, 1629, 1898, 1695, 1046, 1414};
int e_h[8]={3894, 3842, 3942, 3638, 3787, 3597, 3850, 3984};
enum Flags {
selOther = 0,
selSpace = 1,
selWord = 2,
selNumber = 3,
selData = 4,
selPunct = 5,
selNL = 6,
selTFWord = 7
};
enum WText {
fUpper = 7,
fEscape = 12,
};
int oState, wtype;
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 matchMod(int y,int bpos){
int cx;
if (bpos==0){
//update match
h=(h*887*8+c1+1)&0xfffff; // update context hash
if (len>3) len=len+(len<MAXLEN), ++ptr;
else { // find match
len=1;
ptr=tm[h];
if (ptr && (pos-ptr)<0x400000)
while (buf(len+1)==bufr(ptr-len-1) && len<MAXLEN) ++len;
}
tm[h]=pos; // update hash table
//if (len>3 ) 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,h;
int ismatch;
apmfails=apmfails<<1;
j=y?pr^4095:pr;
j=vmx(ERR,bpos,j);
apmfails=apmfails|j;
if (bpos== 0){
c1=c4&0xff;
buffer[pos&BMASK]=c1;
pos++;
for (i=13; i>0; --i) // update order 0-11 context hashes
t[i]=t[i-1]*primes[i]+c1;
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 (j>='A' && c1<='Z') j =j+32;
if (j>='a' && j<='z') {
word0=word0*2104+j; //263*8
nState=selWord;
}
else {
word1=word0*83;
word0=0;
if (c1=='.' || c1=='!' || c1=='?' || c1==',' || c1==';' || c1==':') {nState=selPunct;}
if (c1==32 || c1==10) {
if (c1==32) nState=selSpace;
if (c1==10 ) {nState=selNL; wtype=(wtype<<3);}
} else if (nState!=selPunct )nState=selData;
}
if (c1>128) nState=selWord;
if (c1>='0' && c1<='9') {
nState=selNumber;
}
// state
if (c1==64) nState=7;
if (c1==fEscape) nState=0;
// switch state if its new
if (oState!=nState){
wtype=(wtype<<3)+nState;
oState=nState;
}
h=word0*271+c1;
vmx(CM, 4,word0);
vmx(CM, 4,h+word1);
vmx(CM, 5,t[2]);
vmx(CM, 6,0);
vmx(CM, 7,((wtype>>3)<<8)|(c4&0xff));
}
ismatch=matchMod( y, bpos);
if (ismatch) ord=3+ (len>=5) +(len>=8)+(len>=8); else ord=0;
vmx(MX,0,ord << 3 | bpos);
vmx(APM2,0,apmfails*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;
vms(1,0,0,0,0,0,8,1,0,0,0,0,0,1,8,0,0,1,6+1);
// state tables
vmi(STA,0,41+(40<<16),4|(5<<16),23+(14<<16)+(9<<24));
vmi(STA,1,33+(31<<16),14|(25<<16),10+(11<<16)+(21<<24));
vmi(STA,2,35+(56<<16),18|(23<<16),1+(9<<16)+(23<<24));
vmi(STA,3,49+(50<<16),14|(6<<16),3+(18<<16)+(17<<24));
vmi(STA,4,57+(47<<16),10|(1<<16),5+(20<<16)+(24<<24));
vmi(STA,5,41+(40<<16),3|(5<<16),23+(16<<16)+(2<<24));
vmi(STA,6,43+(46<<16),21|(1<<16),3+(14<<16)+(13<<24));
// match
vmi(SMC,0,64<<8,1023,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]);//3-5
vmi(CM,1,16*4096+(2<<24),1+256*c_r[1]+c_s[1]*0x10000+0x1000000*c_s2[1],0+256*c_s3[1]+0x10000*c_s4[1]);// o6
vmi(CM,2,16*4096+(3<<24),1+256*c_r[2]+c_s[2]*0x10000+0x1000000*c_s2[2],0+256*c_s3[2]+0x10000*c_s4[2]);// o8
vmi(CM,3,16*4096+(4<<24),1+256*c_r[3]+c_s[3]*0x10000+0x1000000*c_s2[3],0+256*c_s3[3]+0x10000*c_s4[3]);// o13
vmi(CM,4,16*4096+(5<<24),2+256*c_r[4]+c_s[4]*0x10000+0x1000000*c_s2[4],0+256*c_s3[4]+0x10000*c_s4[4]);// w
vmi(CM,5,16*4096+(6<<24),1+256*c_r[5]+c_s[5]*0x10000+0x1000000*c_s2[5],0+256*c_s3[5]+0x10000*c_s4[5]); // o2
vmi(CM,6,0+(0<<24),1+256*c_r[6]+c_s[6]*0x10000+0x1000000*c_s2[6],0+256*c_s3[6]+0x10000*c_s4[6]); // o0
vmi(CM,7,1*4096+(7<<24),1+256*c_r[7]+c_s[7]*0x10000+0x1000000*c_s2[7],0+256*c_s3[7]+0x10000*c_s4[7]); // type
vmi(MX,0,m_s[0]+256*m_e[0]+0x1000000*m_m[0], 56,0);
for (i=0;i<8;i++) vmi(ERR,i,e_l[i]+(e_h[i]<<16),0,0);
vmi(APM2,0,0x800,24+40*256,0);
}