OpenCores
URL https://opencores.org/ocsvn/hdl-deflate/hdl-deflate/trunk

Subversion Repositories hdl-deflate

[/] [hdl-deflate/] [trunk/] [deflate.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tomtor
// File: deflate.v
2
// Generated by MyHDL 0.10
3 6 tomtor
// Date: Tue Jan  1 11:29:55 2019
4 2 tomtor
 
5
 
6
`timescale 1ns/10ps
7
 
8
module deflate (
9
    i_mode,
10
    o_done,
11
    i_data,
12
    o_iprogress,
13
    o_oprogress,
14
    o_byte,
15 6 tomtor
    i_waddr,
16
    i_raddr,
17 2 tomtor
    clk,
18
    reset
19
);
20
// Deflate (de)compress
21
// 
22
// Ports:
23
 
24
input [2:0] i_mode;
25
output o_done;
26
reg o_done;
27
input [7:0] i_data;
28 6 tomtor
output [23:0] o_iprogress;
29
reg [23:0] o_iprogress;
30
output [23:0] o_oprogress;
31
reg [23:0] o_oprogress;
32 2 tomtor
output [7:0] o_byte;
33
reg [7:0] o_byte;
34 6 tomtor
input [5:0] i_waddr;
35
input [14:0] i_raddr;
36 2 tomtor
input clk;
37
input reset;
38
 
39
reg [18:0] wleaf;
40
reg [9:0] step;
41
reg static;
42
reg [4:0] state;
43
reg [8:0] spread_i;
44
reg [9:0] spread;
45 6 tomtor
reg [18:0] rleaf;
46
reg [14:0] reverse;
47 2 tomtor
reg [7:0] orbyte;
48 6 tomtor
reg [14:0] oraddr;
49
reg [23:0] old_di;
50
reg [14:0] offset;
51 2 tomtor
reg [7:0] obyte;
52
reg [7:0] ob1;
53 6 tomtor
reg [14:0] oaddr;
54 2 tomtor
reg [8:0] numLiterals;
55
reg [5:0] numDistance;
56
reg [8:0] numCodeLength;
57
reg [2:0] nb;
58
reg [4:0] minBits;
59
reg [2:0] method;
60
reg [4:0] maxBits;
61 6 tomtor
reg [14:0] lwaddr;
62
reg [14:0] lraddr;
63
reg [14:0] length;
64 2 tomtor
reg [18:0] leaf;
65
reg [14:0] lastToken;
66
reg [15:0] ladler1;
67 6 tomtor
reg [23:0] isize;
68 2 tomtor
reg [9:0] instantMaxBit;
69
reg [14:0] instantMask;
70
reg [8:0] howOften;
71
reg flush;
72
reg final;
73
reg filled;
74
reg [2:0] doo;
75
reg do_compress;
76 6 tomtor
reg [23:0] do;
77 2 tomtor
reg [2:0] dio;
78 6 tomtor
reg [23:0] di;
79 2 tomtor
reg [4:0] d_maxBits;
80
reg [9:0] d_instantMaxBit;
81
reg [14:0] d_instantMask;
82
reg [8:0] cur_static;
83 6 tomtor
reg signed [24:0] cur_search;
84
reg [3:0] cur_next;
85
reg [23:0] cur_i;
86
reg signed [6:0] cur_dist;
87
reg [23:0] cur_cstatic;
88
reg [15:0] cur_HF1;
89 5 tomtor
reg [7:0] copy2;
90 2 tomtor
reg [7:0] copy1;
91
reg [14:0] code;
92
reg [3:0] bits;
93
reg [8:0] b_numCodeLength;
94 5 tomtor
reg [7:0] b9;
95
reg [7:0] b8;
96
reg [7:0] b7;
97
reg [7:0] b6;
98
reg [7:0] b5;
99 2 tomtor
wire [31:0] b41;
100
reg [7:0] b4;
101
reg [7:0] b3;
102
reg [7:0] b2;
103 6 tomtor
wire [39:0] b15;
104 5 tomtor
wire [31:0] b14;
105
wire [79:0] b110;
106
reg [7:0] b10;
107 2 tomtor
reg [7:0] b1;
108
reg [15:0] adler2;
109
reg [15:0] adler1;
110 5 tomtor
reg [255:0] cwindow;
111 6 tomtor
reg [7:0] oram [0:32768-1];
112
reg [15:0] nextCode [0:16-1];
113 2 tomtor
reg [18:0] leaves [0:512-1];
114 6 tomtor
reg [7:0] iram [0:64-1];
115 2 tomtor
reg [3:0] distanceLength [0:32-1];
116 6 tomtor
reg d_leaves [0:1-1];
117
reg [3:0] codeLength [0:320-1];
118 2 tomtor
reg [8:0] bitLengthCount [0:16-1];
119 5 tomtor
wire smatch [0:32-1];
120 2 tomtor
 
121
assign b41[32-1:24] = b4;
122
assign b41[24-1:16] = b3;
123
assign b41[16-1:8] = b2;
124
assign b41[8-1:0] = b1;
125 6 tomtor
assign b15[40-1:32] = b1;
126
assign b15[32-1:24] = b2;
127
assign b15[24-1:16] = b3;
128
assign b15[16-1:8] = b4;
129
assign b15[8-1:0] = b5;
130 5 tomtor
assign b14[32-1:24] = b1;
131
assign b14[24-1:16] = b2;
132
assign b14[16-1:8] = b3;
133
assign b14[8-1:0] = b4;
134
assign b110[80-1:72] = b1;
135
assign b110[72-1:64] = b2;
136
assign b110[64-1:56] = b3;
137
assign b110[56-1:48] = b4;
138
assign b110[48-1:40] = b5;
139
assign b110[40-1:32] = b6;
140
assign b110[32-1:24] = b7;
141
assign b110[24-1:16] = b8;
142
assign b110[16-1:8] = b9;
143
assign b110[8-1:0] = b10;
144 2 tomtor
 
145
task MYHDL3_adv;
146
    input width;
147
    integer width;
148
    integer nshift;
149 6 tomtor
begin: MYHDL115_RETURN
150 2 tomtor
    nshift = ((dio + width) >>> 3);
151
    o_iprogress <= di;
152
    dio <= ((dio + width) & 7);
153
    di <= ($signed({1'b0, di}) + nshift);
154
    if ((nshift != 0)) begin
155
        filled <= 1'b0;
156
    end
157
end
158
endtask
159
 
160
function integer MYHDL4_get4;
161
    input boffset;
162
    input width;
163 6 tomtor
begin: MYHDL116_RETURN
164 2 tomtor
    if ((nb != 4)) begin
165
        $write("----NB----");
166
        $write("\n");
167
        $finish;
168
    end
169
    MYHDL4_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
170 6 tomtor
    disable MYHDL116_RETURN;
171 2 tomtor
end
172
endfunction
173
 
174
function integer MYHDL5_get4;
175
    input boffset;
176
    input width;
177
    integer width;
178 6 tomtor
begin: MYHDL117_RETURN
179 2 tomtor
    if ((nb != 4)) begin
180
        $write("----NB----");
181
        $write("\n");
182
        $finish;
183
    end
184
    MYHDL5_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
185 6 tomtor
    disable MYHDL117_RETURN;
186 2 tomtor
end
187
endfunction
188
 
189
task MYHDL6_adv;
190
    input width;
191
    integer width;
192
    integer nshift;
193 6 tomtor
begin: MYHDL118_RETURN
194 2 tomtor
    nshift = ((dio + width) >>> 3);
195
    o_iprogress <= di;
196
    dio <= ((dio + width) & 7);
197
    di <= ($signed({1'b0, di}) + nshift);
198
    if ((nshift != 0)) begin
199
        filled <= 1'b0;
200
    end
201
end
202
endtask
203
 
204
task MYHDL7_adv;
205
    input width;
206
    integer width;
207
    integer nshift;
208 6 tomtor
begin: MYHDL119_RETURN
209 2 tomtor
    nshift = ((dio + width) >>> 3);
210
    o_iprogress <= di;
211
    dio <= ((dio + width) & 7);
212
    di <= ($signed({1'b0, di}) + nshift);
213
    if ((nshift != 0)) begin
214
        filled <= 1'b0;
215
    end
216
end
217
endtask
218
 
219
function integer MYHDL8_get4;
220
    input boffset;
221
    integer boffset;
222
    input width;
223
    integer width;
224 6 tomtor
begin: MYHDL120_RETURN
225 2 tomtor
    if ((nb != 4)) begin
226
        $write("----NB----");
227
        $write("\n");
228
        $finish;
229
    end
230
    MYHDL8_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
231 6 tomtor
    disable MYHDL120_RETURN;
232 2 tomtor
end
233
endfunction
234
 
235
task MYHDL9_adv;
236
    input width;
237
    integer width;
238
    integer nshift;
239 6 tomtor
begin: MYHDL121_RETURN
240 2 tomtor
    nshift = $signed(($signed({1'b0, dio}) + width) >>> 3);
241
    o_iprogress <= di;
242
    dio <= (($signed({1'b0, dio}) + width) & 7);
243
    di <= ($signed({1'b0, di}) + nshift);
244
    if ((nshift != 0)) begin
245
        filled <= 1'b0;
246
    end
247
end
248
endtask
249
 
250
function integer MYHDL10_put;
251
    input d;
252
    integer d;
253
    input width;
254
    integer width;
255 6 tomtor
begin: MYHDL122_RETURN
256 2 tomtor
    if ((width > 9)) begin
257
        $finish;
258
    end
259
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
260
        $finish;
261
    end
262
    MYHDL10_put = ((ob1 | (d << doo)) & 255);
263 6 tomtor
    disable MYHDL122_RETURN;
264 2 tomtor
end
265
endfunction
266
 
267
task MYHDL11_put_adv;
268
    input d;
269
    integer d;
270
    input width;
271
    integer width;
272
    reg pshift;
273
    integer carry;
274
    integer doo_next;
275 6 tomtor
begin: MYHDL123_RETURN
276 2 tomtor
    if ((width > 9)) begin
277
        $finish;
278
    end
279
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
280
        $finish;
281
    end
282
    pshift = ((doo + width) > 8);
283
    if (pshift) begin
284
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, doo})));
285
        ob1 <= $signed($signed({1'b0, d}) >>> ($signed({1'b0, width}) - carry));
286
    end
287
    else begin
288
        ob1 <= (ob1 | (d << doo));
289
    end
290
    do <= (do + pshift);
291
    o_oprogress <= (do + pshift);
292
    doo_next = ((doo + width) & 7);
293
    if ((doo_next == 0)) begin
294
        flush <= 1'b1;
295
    end
296
    doo <= doo_next;
297
end
298
endtask
299
 
300
task MYHDL12_do_flush;
301 6 tomtor
begin: MYHDL124_RETURN
302 2 tomtor
    flush <= 1'b0;
303
    ob1 <= 0;
304
    o_oprogress <= (do + 1);
305
    do <= (do + 1);
306
end
307
endtask
308
 
309
function integer MYHDL13_put;
310 6 tomtor
    input d;
311
    integer d;
312 2 tomtor
    input [4-1:0] width;
313 6 tomtor
begin: MYHDL125_RETURN
314 2 tomtor
    if ((width > 9)) begin
315
        $finish;
316
    end
317 6 tomtor
    if ((d > ((1 << width) - 1))) begin
318 2 tomtor
        $finish;
319
    end
320 6 tomtor
    MYHDL13_put = (($signed({1'b0, ob1}) | (d << $signed({1'b0, doo}))) & 255);
321
    disable MYHDL125_RETURN;
322 2 tomtor
end
323
endfunction
324
 
325
task MYHDL14_put_adv;
326 6 tomtor
    input d;
327
    integer d;
328 2 tomtor
    input [4-1:0] width;
329
    reg pshift;
330
    integer carry;
331
    integer doo_next;
332 6 tomtor
begin: MYHDL126_RETURN
333 2 tomtor
    if ((width > 9)) begin
334
        $finish;
335
    end
336 6 tomtor
    if ((d > ((1 << width) - 1))) begin
337 2 tomtor
        $finish;
338
    end
339
    pshift = ((doo + width) > 8);
340
    if (pshift) begin
341
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, doo})));
342 6 tomtor
        ob1 <= $signed(d >>> ($signed({1'b0, width}) - carry));
343 2 tomtor
    end
344
    else begin
345 6 tomtor
        ob1 <= ($signed({1'b0, ob1}) | (d << $signed({1'b0, doo})));
346 2 tomtor
    end
347
    do <= (do + pshift);
348
    o_oprogress <= (do + pshift);
349
    doo_next = ((doo + width) & 7);
350
    if ((doo_next == 0)) begin
351
        flush <= 1'b1;
352
    end
353
    doo <= doo_next;
354
end
355
endtask
356
 
357
task MYHDL15_do_flush;
358 6 tomtor
begin: MYHDL127_RETURN
359 2 tomtor
    flush <= 1'b0;
360
    ob1 <= 0;
361
    o_oprogress <= (do + 1);
362
    do <= (do + 1);
363
end
364
endtask
365
 
366 6 tomtor
function integer MYHDL16_put;
367 2 tomtor
    input d;
368
    integer d;
369 6 tomtor
    input [4-1:0] width;
370
begin: MYHDL128_RETURN
371 2 tomtor
    if ((width > 9)) begin
372
        $finish;
373
    end
374
    if ((d > ((1 << width) - 1))) begin
375
        $finish;
376
    end
377 6 tomtor
    MYHDL16_put = (($signed({1'b0, ob1}) | (d << $signed({1'b0, doo}))) & 255);
378
    disable MYHDL128_RETURN;
379 2 tomtor
end
380
endfunction
381
 
382 6 tomtor
task MYHDL17_put_adv;
383 2 tomtor
    input d;
384
    integer d;
385 6 tomtor
    input [4-1:0] width;
386 2 tomtor
    reg pshift;
387
    integer carry;
388
    integer doo_next;
389 6 tomtor
begin: MYHDL129_RETURN
390 2 tomtor
    if ((width > 9)) begin
391
        $finish;
392
    end
393
    if ((d > ((1 << width) - 1))) begin
394
        $finish;
395
    end
396 6 tomtor
    pshift = ((doo + width) > 8);
397 2 tomtor
    if (pshift) begin
398 6 tomtor
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, doo})));
399
        ob1 <= $signed(d >>> ($signed({1'b0, width}) - carry));
400 2 tomtor
    end
401
    else begin
402
        ob1 <= ($signed({1'b0, ob1}) | (d << $signed({1'b0, doo})));
403
    end
404
    do <= (do + pshift);
405
    o_oprogress <= (do + pshift);
406 6 tomtor
    doo_next = ((doo + width) & 7);
407 2 tomtor
    if ((doo_next == 0)) begin
408
        flush <= 1'b1;
409
    end
410
    doo <= doo_next;
411
end
412
endtask
413
 
414 6 tomtor
function integer MYHDL18_rev_bits;
415
    input [24-1:0] b;
416
    input nb;
417
    integer nb;
418
    integer r;
419
begin: MYHDL130_RETURN
420
    if ((b >= (1 << nb))) begin
421 2 tomtor
        $finish;
422 6 tomtor
        $write("too few bits");
423
        $write("\n");
424 2 tomtor
    end
425 6 tomtor
    if ((nb > 15)) begin
426 2 tomtor
        $finish;
427
    end
428 6 tomtor
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
429
    r = r >>> (15 - $signed({1'b0, nb}));
430
    MYHDL18_rev_bits = r;
431
    disable MYHDL130_RETURN;
432 2 tomtor
end
433
endfunction
434
 
435 6 tomtor
function integer MYHDL19_put;
436
    input d;
437
    integer d;
438
    input width;
439
    integer width;
440 5 tomtor
begin: MYHDL131_RETURN
441 2 tomtor
    if ((width > 9)) begin
442
        $finish;
443
    end
444 6 tomtor
    if ((d > ((1 << width) - 1))) begin
445 2 tomtor
        $finish;
446
    end
447 6 tomtor
    MYHDL19_put = (($signed({1'b0, ob1}) | (d << $signed({1'b0, doo}))) & 255);
448 5 tomtor
    disable MYHDL131_RETURN;
449 2 tomtor
end
450
endfunction
451
 
452 6 tomtor
task MYHDL20_put_adv;
453
    input d;
454
    integer d;
455
    input width;
456
    integer width;
457 2 tomtor
    reg pshift;
458
    integer carry;
459
    integer doo_next;
460 5 tomtor
begin: MYHDL132_RETURN
461 2 tomtor
    if ((width > 9)) begin
462
        $finish;
463
    end
464 6 tomtor
    if ((d > ((1 << width) - 1))) begin
465 2 tomtor
        $finish;
466
    end
467 6 tomtor
    pshift = (($signed({1'b0, doo}) + width) > 8);
468 2 tomtor
    if (pshift) begin
469 6 tomtor
        carry = (width - (8 - $signed({1'b0, doo})));
470
        ob1 <= $signed(d >>> (width - carry));
471 2 tomtor
    end
472
    else begin
473 6 tomtor
        ob1 <= ($signed({1'b0, ob1}) | (d << $signed({1'b0, doo})));
474 2 tomtor
    end
475
    do <= (do + pshift);
476
    o_oprogress <= (do + pshift);
477 6 tomtor
    doo_next = (($signed({1'b0, doo}) + width) & 7);
478 2 tomtor
    if ((doo_next == 0)) begin
479
        flush <= 1'b1;
480
    end
481
    doo <= doo_next;
482
end
483
endtask
484
 
485 6 tomtor
function integer MYHDL23_put;
486
    input d;
487
    integer d;
488 5 tomtor
    input [4-1:0] width;
489
begin: MYHDL133_RETURN
490
    if ((width > 9)) begin
491
        $finish;
492
    end
493 6 tomtor
    if ((d > ((1 << width) - 1))) begin
494 5 tomtor
        $finish;
495
    end
496 6 tomtor
    MYHDL23_put = (($signed({1'b0, ob1}) | (d << $signed({1'b0, doo}))) & 255);
497 5 tomtor
    disable MYHDL133_RETURN;
498
end
499
endfunction
500
 
501 6 tomtor
task MYHDL24_put_adv;
502
    input d;
503
    integer d;
504 5 tomtor
    input [4-1:0] width;
505
    reg pshift;
506
    integer carry;
507
    integer doo_next;
508
begin: MYHDL134_RETURN
509
    if ((width > 9)) begin
510
        $finish;
511
    end
512 6 tomtor
    if ((d > ((1 << width) - 1))) begin
513 5 tomtor
        $finish;
514
    end
515
    pshift = ((doo + width) > 8);
516
    if (pshift) begin
517
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, doo})));
518 6 tomtor
        ob1 <= $signed(d >>> ($signed({1'b0, width}) - carry));
519 5 tomtor
    end
520
    else begin
521 6 tomtor
        ob1 <= ($signed({1'b0, ob1}) | (d << $signed({1'b0, doo})));
522 5 tomtor
    end
523
    do <= (do + pshift);
524
    o_oprogress <= (do + pshift);
525
    doo_next = ((doo + width) & 7);
526
    if ((doo_next == 0)) begin
527
        flush <= 1'b1;
528
    end
529
    doo <= doo_next;
530
end
531
endtask
532
 
533 6 tomtor
function integer MYHDL33_get4;
534 2 tomtor
    input boffset;
535
    input width;
536
    integer width;
537 5 tomtor
begin: MYHDL135_RETURN
538 2 tomtor
    if ((nb != 4)) begin
539
        $write("----NB----");
540
        $write("\n");
541
        $finish;
542
    end
543 6 tomtor
    MYHDL33_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
544 5 tomtor
    disable MYHDL135_RETURN;
545 2 tomtor
end
546
endfunction
547
 
548 6 tomtor
function integer MYHDL34_get4;
549 2 tomtor
    input boffset;
550
    input width;
551
    integer width;
552 5 tomtor
begin: MYHDL136_RETURN
553 2 tomtor
    if ((nb != 4)) begin
554
        $write("----NB----");
555
        $write("\n");
556
        $finish;
557
    end
558 6 tomtor
    MYHDL34_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
559 5 tomtor
    disable MYHDL136_RETURN;
560 2 tomtor
end
561
endfunction
562
 
563 6 tomtor
function integer MYHDL35_get4;
564 2 tomtor
    input boffset;
565
    integer boffset;
566
    input width;
567
    integer width;
568 5 tomtor
begin: MYHDL137_RETURN
569 2 tomtor
    if ((nb != 4)) begin
570
        $write("----NB----");
571
        $write("\n");
572
        $finish;
573
    end
574 6 tomtor
    MYHDL35_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
575 5 tomtor
    disable MYHDL137_RETURN;
576 2 tomtor
end
577
endfunction
578
 
579 6 tomtor
function integer MYHDL36_get4;
580 2 tomtor
    input boffset;
581
    integer boffset;
582
    input width;
583
    integer width;
584 5 tomtor
begin: MYHDL138_RETURN
585 2 tomtor
    if ((nb != 4)) begin
586
        $write("----NB----");
587
        $write("\n");
588
        $finish;
589
    end
590 6 tomtor
    MYHDL36_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
591 5 tomtor
    disable MYHDL138_RETURN;
592 2 tomtor
end
593
endfunction
594
 
595 6 tomtor
function integer MYHDL37_get4;
596 2 tomtor
    input boffset;
597
    integer boffset;
598
    input width;
599
    integer width;
600 5 tomtor
begin: MYHDL139_RETURN
601 2 tomtor
    if ((nb != 4)) begin
602
        $write("----NB----");
603
        $write("\n");
604
        $finish;
605
    end
606 6 tomtor
    MYHDL37_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
607 5 tomtor
    disable MYHDL139_RETURN;
608 2 tomtor
end
609
endfunction
610
 
611 6 tomtor
function integer MYHDL38_get4;
612 2 tomtor
    input boffset;
613
    integer boffset;
614
    input width;
615
    integer width;
616 5 tomtor
begin: MYHDL140_RETURN
617 2 tomtor
    if ((nb != 4)) begin
618
        $write("----NB----");
619
        $write("\n");
620
        $finish;
621
    end
622 6 tomtor
    MYHDL38_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
623 5 tomtor
    disable MYHDL140_RETURN;
624 2 tomtor
end
625
endfunction
626
 
627 6 tomtor
task MYHDL39_adv;
628 2 tomtor
    input width;
629
    integer width;
630
    integer nshift;
631 5 tomtor
begin: MYHDL141_RETURN
632 2 tomtor
    nshift = ((dio + width) >>> 3);
633
    o_iprogress <= di;
634
    dio <= ((dio + width) & 7);
635
    di <= ($signed({1'b0, di}) + nshift);
636
    if ((nshift != 0)) begin
637
        filled <= 1'b0;
638
    end
639
end
640
endtask
641
 
642 6 tomtor
function integer MYHDL40_get4;
643 2 tomtor
    input boffset;
644
    input width;
645
    integer width;
646 5 tomtor
begin: MYHDL142_RETURN
647 2 tomtor
    if ((nb != 4)) begin
648
        $write("----NB----");
649
        $write("\n");
650
        $finish;
651
    end
652 6 tomtor
    MYHDL40_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
653 5 tomtor
    disable MYHDL142_RETURN;
654 2 tomtor
end
655
endfunction
656
 
657 6 tomtor
task MYHDL41_adv;
658 2 tomtor
    input width;
659
    integer width;
660
    integer nshift;
661 5 tomtor
begin: MYHDL143_RETURN
662 2 tomtor
    nshift = ((dio + width) >>> 3);
663
    o_iprogress <= di;
664
    dio <= ((dio + width) & 7);
665
    di <= ($signed({1'b0, di}) + nshift);
666
    if ((nshift != 0)) begin
667
        filled <= 1'b0;
668
    end
669
end
670
endtask
671
 
672 6 tomtor
function integer MYHDL42_get4;
673 2 tomtor
    input boffset;
674
    input width;
675
    integer width;
676 5 tomtor
begin: MYHDL144_RETURN
677 2 tomtor
    if ((nb != 4)) begin
678
        $write("----NB----");
679
        $write("\n");
680
        $finish;
681
    end
682 6 tomtor
    MYHDL42_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
683 5 tomtor
    disable MYHDL144_RETURN;
684 2 tomtor
end
685
endfunction
686
 
687 6 tomtor
function integer MYHDL43_get4;
688 2 tomtor
    input boffset;
689
    input width;
690
    integer width;
691 5 tomtor
begin: MYHDL145_RETURN
692 2 tomtor
    if ((nb != 4)) begin
693
        $write("----NB----");
694
        $write("\n");
695
        $finish;
696
    end
697 6 tomtor
    MYHDL43_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
698 5 tomtor
    disable MYHDL145_RETURN;
699 2 tomtor
end
700
endfunction
701
 
702 6 tomtor
function integer MYHDL44_get4;
703 2 tomtor
    input boffset;
704
    input width;
705
    integer width;
706 5 tomtor
begin: MYHDL146_RETURN
707 2 tomtor
    if ((nb != 4)) begin
708
        $write("----NB----");
709
        $write("\n");
710
        $finish;
711
    end
712 6 tomtor
    MYHDL44_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
713 5 tomtor
    disable MYHDL146_RETURN;
714 2 tomtor
end
715
endfunction
716
 
717 6 tomtor
task MYHDL45_adv;
718 2 tomtor
    input width;
719
    integer width;
720
    integer nshift;
721 5 tomtor
begin: MYHDL147_RETURN
722 2 tomtor
    nshift = ((dio + width) >>> 3);
723
    o_iprogress <= di;
724
    dio <= ((dio + width) & 7);
725
    di <= ($signed({1'b0, di}) + nshift);
726
    if ((nshift != 0)) begin
727
        filled <= 1'b0;
728
    end
729
end
730
endtask
731
 
732 6 tomtor
function integer MYHDL52_rev_bits;
733
    input [16-1:0] b;
734 2 tomtor
    input [4-1:0] nb;
735
    integer r;
736 5 tomtor
begin: MYHDL148_RETURN
737 2 tomtor
    if ((b >= (1 << nb))) begin
738
        $finish;
739
        $write("too few bits");
740
        $write("\n");
741
    end
742 6 tomtor
    if ((nb > 15)) begin
743
        $finish;
744
    end
745 2 tomtor
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
746
    r = r >>> (15 - $signed({1'b0, nb}));
747 6 tomtor
    MYHDL52_rev_bits = r;
748 5 tomtor
    disable MYHDL148_RETURN;
749 2 tomtor
end
750
endfunction
751
 
752 6 tomtor
function integer MYHDL53_makeLeaf;
753 2 tomtor
    input [9-1:0] lcode;
754
    input [4-1:0] lbits;
755 5 tomtor
begin: MYHDL149_RETURN
756 6 tomtor
    if ((lcode >= (1 << 15))) begin
757 2 tomtor
        $finish;
758
    end
759 6 tomtor
    if ((lbits >= (1 << 4))) begin
760 2 tomtor
        $finish;
761
    end
762 6 tomtor
    MYHDL53_makeLeaf = ((lcode << 4) | lbits);
763 5 tomtor
    disable MYHDL149_RETURN;
764 2 tomtor
end
765
endfunction
766
 
767 6 tomtor
function integer MYHDL54_makeLeaf;
768 2 tomtor
    input [9-1:0] lcode;
769
    input [4-1:0] lbits;
770 5 tomtor
begin: MYHDL150_RETURN
771 6 tomtor
    if ((lcode >= (1 << 15))) begin
772 2 tomtor
        $finish;
773
    end
774 6 tomtor
    if ((lbits >= (1 << 4))) begin
775 2 tomtor
        $finish;
776
    end
777 6 tomtor
    MYHDL54_makeLeaf = ((lcode << 4) | lbits);
778 5 tomtor
    disable MYHDL150_RETURN;
779 2 tomtor
end
780
endfunction
781
 
782 6 tomtor
function integer MYHDL55_makeLeaf;
783 2 tomtor
    input [9-1:0] lcode;
784
    input [4-1:0] lbits;
785 5 tomtor
begin: MYHDL151_RETURN
786 6 tomtor
    if ((lcode >= (1 << 15))) begin
787 2 tomtor
        $finish;
788
    end
789 6 tomtor
    if ((lbits >= (1 << 4))) begin
790 2 tomtor
        $finish;
791
    end
792 6 tomtor
    MYHDL55_makeLeaf = ((lcode << 4) | lbits);
793 5 tomtor
    disable MYHDL151_RETURN;
794 2 tomtor
end
795
endfunction
796
 
797 6 tomtor
function integer MYHDL56_get4;
798 2 tomtor
    input boffset;
799
    input [5-1:0] width;
800 5 tomtor
begin: MYHDL152_RETURN
801 2 tomtor
    if ((nb != 4)) begin
802
        $write("----NB----");
803
        $write("\n");
804
        $finish;
805
    end
806 6 tomtor
    MYHDL56_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
807 5 tomtor
    disable MYHDL152_RETURN;
808 2 tomtor
end
809
endfunction
810
 
811 6 tomtor
function integer MYHDL57_get_bits;
812 2 tomtor
    input [19-1:0] aleaf;
813 5 tomtor
begin: MYHDL153_RETURN
814 6 tomtor
    MYHDL57_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
815 5 tomtor
    disable MYHDL153_RETURN;
816 2 tomtor
end
817
endfunction
818
 
819 6 tomtor
function integer MYHDL58_get4;
820
    input boffset;
821
    input [5-1:0] width;
822 5 tomtor
begin: MYHDL154_RETURN
823 6 tomtor
    if ((nb != 4)) begin
824
        $write("----NB----");
825
        $write("\n");
826
        $finish;
827
    end
828
    MYHDL58_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
829 5 tomtor
    disable MYHDL154_RETURN;
830 2 tomtor
end
831
endfunction
832
 
833 6 tomtor
function integer MYHDL59_get_bits;
834
    input [19-1:0] aleaf;
835
begin: MYHDL155_RETURN
836
    MYHDL59_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
837
    disable MYHDL155_RETURN;
838
end
839
endfunction
840
 
841
function integer MYHDL60_get_bits;
842
    input [19-1:0] aleaf;
843
begin: MYHDL156_RETURN
844
    MYHDL60_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
845
    disable MYHDL156_RETURN;
846
end
847
endfunction
848
 
849 5 tomtor
task MYHDL61_adv;
850 2 tomtor
    input width;
851
    integer width;
852
    integer nshift;
853 6 tomtor
begin: MYHDL157_RETURN
854 2 tomtor
    nshift = $signed(($signed({1'b0, dio}) + width) >>> 3);
855
    o_iprogress <= di;
856
    dio <= (($signed({1'b0, dio}) + width) & 7);
857
    di <= ($signed({1'b0, di}) + nshift);
858
    if ((nshift != 0)) begin
859
        filled <= 1'b0;
860
    end
861
end
862
endtask
863
 
864 5 tomtor
function integer MYHDL62_get_code;
865 2 tomtor
    input [19-1:0] aleaf;
866 6 tomtor
begin: MYHDL158_RETURN
867
    MYHDL62_get_code = (aleaf >>> 4);
868
    disable MYHDL158_RETURN;
869 2 tomtor
end
870
endfunction
871
 
872 6 tomtor
function integer MYHDL63_get4;
873
    input boffset;
874
    integer boffset;
875
    input [5-1:0] width;
876
begin: MYHDL159_RETURN
877
    if ((nb != 4)) begin
878
        $write("----NB----");
879
        $write("\n");
880
        $finish;
881
    end
882
    MYHDL63_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
883
    disable MYHDL159_RETURN;
884
end
885
endfunction
886
 
887
function integer MYHDL64_get_bits;
888 2 tomtor
    input [19-1:0] aleaf;
889 6 tomtor
begin: MYHDL160_RETURN
890
    MYHDL64_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
891
    disable MYHDL160_RETURN;
892 2 tomtor
end
893
endfunction
894
 
895 6 tomtor
function integer MYHDL65_get4;
896 2 tomtor
    input boffset;
897
    integer boffset;
898
    input [5-1:0] width;
899 6 tomtor
begin: MYHDL161_RETURN
900 2 tomtor
    if ((nb != 4)) begin
901
        $write("----NB----");
902
        $write("\n");
903
        $finish;
904
    end
905 6 tomtor
    MYHDL65_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
906
    disable MYHDL161_RETURN;
907 2 tomtor
end
908
endfunction
909
 
910 6 tomtor
function integer MYHDL66_get_bits;
911 2 tomtor
    input [19-1:0] aleaf;
912 6 tomtor
begin: MYHDL162_RETURN
913
    MYHDL66_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
914
    disable MYHDL162_RETURN;
915 2 tomtor
end
916
endfunction
917
 
918 6 tomtor
function integer MYHDL67_get4;
919 2 tomtor
    input boffset;
920
    input width;
921
    integer width;
922 6 tomtor
begin: MYHDL163_RETURN
923 2 tomtor
    if ((nb != 4)) begin
924
        $write("----NB----");
925
        $write("\n");
926
        $finish;
927
    end
928 6 tomtor
    MYHDL67_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
929
    disable MYHDL163_RETURN;
930 2 tomtor
end
931
endfunction
932
 
933 6 tomtor
function integer MYHDL68_get_code;
934 2 tomtor
    input [19-1:0] aleaf;
935 6 tomtor
begin: MYHDL164_RETURN
936
    MYHDL68_get_code = (aleaf >>> 4);
937
    disable MYHDL164_RETURN;
938 2 tomtor
end
939
endfunction
940
 
941 6 tomtor
function integer MYHDL69_get_bits;
942 2 tomtor
    input [19-1:0] aleaf;
943 6 tomtor
begin: MYHDL165_RETURN
944
    MYHDL69_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
945
    disable MYHDL165_RETURN;
946 2 tomtor
end
947
endfunction
948
 
949 6 tomtor
function integer MYHDL70_get4;
950 2 tomtor
    input boffset;
951
    integer boffset;
952
    input width;
953
    integer width;
954 6 tomtor
begin: MYHDL166_RETURN
955 2 tomtor
    if ((nb != 4)) begin
956
        $write("----NB----");
957
        $write("\n");
958
        $finish;
959
    end
960 6 tomtor
    MYHDL70_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
961
    disable MYHDL166_RETURN;
962 2 tomtor
end
963
endfunction
964
 
965 6 tomtor
function integer MYHDL71_get_bits;
966 2 tomtor
    input [19-1:0] aleaf;
967 6 tomtor
begin: MYHDL167_RETURN
968
    MYHDL71_get_bits = ($signed({1'b0, aleaf}) & ((1 << 4) - 1));
969
    disable MYHDL167_RETURN;
970 2 tomtor
end
971
endfunction
972
 
973 6 tomtor
task MYHDL72_adv;
974 2 tomtor
    input width;
975
    integer width;
976
    integer nshift;
977 6 tomtor
begin: MYHDL168_RETURN
978 2 tomtor
    nshift = $signed(($signed({1'b0, dio}) + width) >>> 3);
979
    o_iprogress <= di;
980
    dio <= (($signed({1'b0, dio}) + width) & 7);
981
    di <= ($signed({1'b0, di}) + nshift);
982
    if ((nshift != 0)) begin
983
        filled <= 1'b0;
984
    end
985
end
986
endtask
987
 
988 6 tomtor
function integer MYHDL73_get4;
989 2 tomtor
    input boffset;
990
    input width;
991
    integer width;
992 6 tomtor
begin: MYHDL169_RETURN
993 2 tomtor
    if ((nb != 4)) begin
994
        $write("----NB----");
995
        $write("\n");
996
        $finish;
997
    end
998 6 tomtor
    MYHDL73_get4 = ((b41 >>> (dio + boffset)) & ((1 << width) - 1));
999
    disable MYHDL169_RETURN;
1000 2 tomtor
end
1001
endfunction
1002
 
1003 6 tomtor
function integer MYHDL74_get4;
1004 2 tomtor
    input boffset;
1005
    integer boffset;
1006
    input width;
1007
    integer width;
1008 6 tomtor
begin: MYHDL170_RETURN
1009 2 tomtor
    if ((nb != 4)) begin
1010
        $write("----NB----");
1011
        $write("\n");
1012
        $finish;
1013
    end
1014 6 tomtor
    MYHDL74_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
1015
    disable MYHDL170_RETURN;
1016 2 tomtor
end
1017
endfunction
1018
 
1019 6 tomtor
function integer MYHDL75_rev_bits;
1020 2 tomtor
    input b;
1021
    integer b;
1022
    input nb;
1023
    integer nb;
1024
    integer r;
1025 6 tomtor
begin: MYHDL171_RETURN
1026 2 tomtor
    if ((b >= (1 << nb))) begin
1027
        $finish;
1028
        $write("too few bits");
1029
        $write("\n");
1030
    end
1031 6 tomtor
    if ((nb > 15)) begin
1032
        $finish;
1033
    end
1034 2 tomtor
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
1035
    r = r >>> (15 - $signed({1'b0, nb}));
1036 6 tomtor
    MYHDL75_rev_bits = r;
1037
    disable MYHDL171_RETURN;
1038 2 tomtor
end
1039
endfunction
1040
 
1041 6 tomtor
function integer MYHDL76_get4;
1042 2 tomtor
    input boffset;
1043
    integer boffset;
1044
    input width;
1045
    integer width;
1046 6 tomtor
begin: MYHDL172_RETURN
1047 2 tomtor
    if ((nb != 4)) begin
1048
        $write("----NB----");
1049
        $write("\n");
1050
        $finish;
1051
    end
1052 6 tomtor
    MYHDL76_get4 = ($signed($signed({1'b0, b41}) >>> ($signed({1'b0, dio}) + boffset)) & ((1 << width) - 1));
1053
    disable MYHDL172_RETURN;
1054 2 tomtor
end
1055
endfunction
1056
 
1057 6 tomtor
task MYHDL77_adv;
1058 2 tomtor
    input width;
1059
    integer width;
1060
    integer nshift;
1061 6 tomtor
begin: MYHDL173_RETURN
1062 2 tomtor
    nshift = $signed(($signed({1'b0, dio}) + width) >>> 3);
1063
    o_iprogress <= di;
1064
    dio <= (($signed({1'b0, dio}) + width) & 7);
1065
    di <= ($signed({1'b0, di}) + nshift);
1066
    if ((nshift != 0)) begin
1067
        filled <= 1'b0;
1068
    end
1069
end
1070
endtask
1071
 
1072 6 tomtor
task MYHDL78_adv;
1073 2 tomtor
    input width;
1074
    integer width;
1075
    integer nshift;
1076 6 tomtor
begin: MYHDL174_RETURN
1077 2 tomtor
    nshift = ((dio + width) >>> 3);
1078
    o_iprogress <= di;
1079
    dio <= ((dio + width) & 7);
1080
    di <= ($signed({1'b0, di}) + nshift);
1081
    if ((nshift != 0)) begin
1082
        filled <= 1'b0;
1083
    end
1084
end
1085
endtask
1086
 
1087 6 tomtor
task MYHDL79_adv;
1088
    input width;
1089
    integer width;
1090
    integer nshift;
1091
begin: MYHDL175_RETURN
1092
    nshift = ((dio + width) >>> 3);
1093
    o_iprogress <= di;
1094
    dio <= ((dio + width) & 7);
1095
    di <= ($signed({1'b0, di}) + nshift);
1096
    if ((nshift != 0)) begin
1097
        filled <= 1'b0;
1098
    end
1099
end
1100
endtask
1101 2 tomtor
 
1102 6 tomtor
 
1103 2 tomtor
always @(posedge clk) begin: DEFLATE_IO_LOGIC
1104 6 tomtor
    o_byte <= oram[(i_raddr & 32767)];
1105
    if ((i_mode == 2)) begin
1106
        iram[(i_waddr & 63)] <= i_data;
1107
        isize <= i_waddr;
1108
    end
1109 2 tomtor
end
1110
 
1111
 
1112
always @(posedge clk) begin: DEFLATE_LOGIC
1113
    integer hm;
1114
    integer skip;
1115
    reg no_adv;
1116
    integer cs_i;
1117
    reg [4-1:0] outlen;
1118 6 tomtor
    integer outbits;
1119 2 tomtor
    reg [8-1:0] bdata;
1120
    integer adler1_next;
1121 6 tomtor
    integer lencode;
1122 2 tomtor
    integer nextdist;
1123
    integer copydist;
1124
    integer extra_dist;
1125
    integer extra_bits;
1126
    integer outcode;
1127 6 tomtor
    reg [15-1:0] lfmatch;
1128
    integer distance;
1129
    integer fmatch2;
1130
    integer match;
1131 5 tomtor
    reg found;
1132
    integer fmatch;
1133
    integer si;
1134 2 tomtor
    integer stat_i;
1135
    integer clo_i;
1136
    integer n_adv;
1137
    integer dbl_i;
1138
    integer dbl;
1139
    integer dist_i;
1140
    integer limit;
1141
    reg [4-1:0] j;
1142
    integer t;
1143
    integer hf2_i;
1144
    reg [5-1:0] amb;
1145
    integer ncode;
1146 6 tomtor
    reg [16-1:0] canonical;
1147 2 tomtor
    reg [4-1:0] bits_next;
1148
    reg [15-1:0] aim;
1149
    integer cto;
1150
    integer mask;
1151
    integer token;
1152
    integer extraLength;
1153
    integer tlength;
1154
    integer distanceCode;
1155
    integer moreBits;
1156
    integer mored;
1157
    if ((!reset)) begin
1158
        $write("DEFLATE RESET");
1159
        $write("\n");
1160
        state <= 5'b00000;
1161
        o_done <= 1'b0;
1162
    end
1163
    else begin
1164
        case (state)
1165
            5'b00000: begin
1166 5 tomtor
                if ((1'b1 && (i_mode == 4))) begin
1167
                    $write("STARTC");
1168
                    $write("\n");
1169
                    do_compress <= 1'b1;
1170
                    method <= 1;
1171
                    o_done <= 1'b0;
1172
                    o_iprogress <= 0;
1173
                    o_oprogress <= 0;
1174
                    di <= 0;
1175
                    dio <= 0;
1176
                    do <= 0;
1177
                    doo <= 0;
1178
                    filled <= 1'b1;
1179
                    cur_static <= 0;
1180
                    state <= 5'b01110;
1181
                end
1182 6 tomtor
                else if ((1'b1 && (i_mode == 5))) begin
1183 5 tomtor
                    do_compress <= 1'b0;
1184
                    o_done <= 1'b0;
1185
                    o_iprogress <= 0;
1186
                    o_oprogress <= 0;
1187
                    di <= 0;
1188
                    dio <= 0;
1189
                    do <= 0;
1190
                    doo <= 0;
1191
                    filled <= 1'b1;
1192
                    state <= 5'b00001;
1193
                end
1194
                else begin
1195
                    // pass
1196
                end
1197 2 tomtor
            end
1198
            5'b00001: begin
1199 6 tomtor
                if ((!1'b1)) begin
1200
                    // pass
1201
                end
1202
                else if ((!filled)) begin
1203 2 tomtor
                    filled <= 1'b1;
1204
                end
1205
                else if ((nb < 4)) begin
1206
                    // pass
1207
                end
1208
                else if ((di == 0)) begin
1209
                    if ((b1 == 120)) begin
1210
                        $write("deflate mode");
1211
                        $write("\n");
1212
                    end
1213
                    else begin
1214
                        $write("%h", di);
1215
                        $write(" ");
1216
                        $write("%h", dio);
1217
                        $write(" ");
1218
                        $write("%h", nb);
1219
                        $write(" ");
1220
                        $write("%h", b1);
1221
                        $write(" ");
1222
                        $write("%h", b2);
1223
                        $write(" ");
1224
                        $write("%h", b3);
1225
                        $write(" ");
1226
                        $write("%h", b4);
1227
                        $write(" ");
1228
                        $write("%h", isize);
1229
                        $write("\n");
1230
                        $finish;
1231
                        o_done <= 1'b1;
1232
                        state <= 5'b00000;
1233
                    end
1234
                    MYHDL3_adv(16);
1235
                end
1236
                else begin
1237
                    if (MYHDL4_get4(0, 1)) begin
1238
                        $write("final");
1239
                        $write("\n");
1240
                        final <= 1'b1;
1241
                    end
1242
                    hm = MYHDL5_get4(1, 2);
1243
                    method <= hm;
1244
                    $write("method");
1245
                    $write(" ");
1246
                    $write("%0d", hm);
1247
                    $write("\n");
1248
                    case (hm)
1249
                        'h2: begin
1250 6 tomtor
                            if ((!1'b0)) begin
1251
                                $write("dynamic tree mode disabled");
1252
                                $write("\n");
1253
                                $finish;
1254
                            end
1255 2 tomtor
                            state <= 5'b00010;
1256
                            numCodeLength <= 0;
1257
                            numLiterals <= 0;
1258
                            static <= 1'b0;
1259
                            MYHDL6_adv(3);
1260
                        end
1261
                        'h1: begin
1262
                            static <= 1'b1;
1263
                            cur_static <= 0;
1264
                            state <= 5'b01110;
1265
                            MYHDL7_adv(3);
1266
                        end
1267
                        'h0: begin
1268
                            state <= 5'b10101;
1269
                            skip = (8 - dio);
1270
                            if ((skip <= 2)) begin
1271
                                skip = (16 - dio);
1272
                            end
1273
                            length <= MYHDL8_get4(skip, 16);
1274
                            MYHDL9_adv((skip + 16));
1275
                            cur_i <= 0;
1276
                            offset <= 7;
1277
                        end
1278
                        default: begin
1279
                            state <= 5'b00000;
1280
                            $write("Bad method");
1281
                            $write("\n");
1282
                            $finish;
1283
                        end
1284
                    endcase
1285
                end
1286
            end
1287
            5'b10110: begin
1288
                no_adv = 0;
1289 5 tomtor
                if ((!1'b1)) begin
1290
                    // pass
1291
                end
1292
                else if ((!filled)) begin
1293 2 tomtor
                    no_adv = 1;
1294
                    filled <= 1'b1;
1295
                end
1296
                else if ((nb < 4)) begin
1297
                    no_adv = 1;
1298
                    // pass
1299
                end
1300
                else if ((cur_cstatic == 0)) begin
1301
                    flush <= 1'b0;
1302
                    ob1 <= 0;
1303
                    adler1 <= 1;
1304
                    adler2 <= 0;
1305
                    ladler1 <= 0;
1306
                    oaddr <= 0;
1307
                    obyte <= 120;
1308
                end
1309
                else if ((cur_cstatic == 1)) begin
1310
                    oaddr <= 1;
1311
                    obyte <= 156;
1312
                    do <= 2;
1313
                end
1314
                else if ((cur_cstatic == 2)) begin
1315
                    oaddr <= do;
1316
                    obyte <= MYHDL10_put(3, 3);
1317
                    MYHDL11_put_adv(3, 3);
1318
                end
1319
                else if (flush) begin
1320
                    no_adv = 1;
1321
                    oaddr <= do;
1322
                    obyte <= ob1;
1323
                    MYHDL12_do_flush;
1324
                end
1325 6 tomtor
                else if ((($signed({1'b0, cur_cstatic}) >= ($signed({1'b0, isize}) - 10)) && (i_mode != 0))) begin
1326
                    $write("P");
1327
                    $write(" ");
1328
                    $write("%h", cur_cstatic);
1329
                    $write(" ");
1330
                    $write("%h", isize);
1331
                    $write("\n");
1332
                    no_adv = 1;
1333
                end
1334 2 tomtor
                else if ((($signed({1'b0, cur_cstatic}) - 3) > isize)) begin
1335
                    if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 1))) begin
1336
                        $write("Put EOF");
1337
                        $write(" ");
1338
                        $write("%h", do);
1339
                        $write("\n");
1340
                        cs_i = 256;
1341
                        outlen = codeLength[cs_i];
1342 6 tomtor
                        case (cs_i)
1343
                            0: outbits = 12;
1344
                            1: outbits = 140;
1345
                            2: outbits = 76;
1346
                            3: outbits = 204;
1347
                            4: outbits = 44;
1348
                            5: outbits = 172;
1349
                            6: outbits = 108;
1350
                            7: outbits = 236;
1351
                            8: outbits = 28;
1352
                            9: outbits = 156;
1353
                            10: outbits = 92;
1354
                            11: outbits = 220;
1355
                            12: outbits = 60;
1356
                            13: outbits = 188;
1357
                            14: outbits = 124;
1358
                            15: outbits = 252;
1359
                            16: outbits = 2;
1360
                            17: outbits = 130;
1361
                            18: outbits = 66;
1362
                            19: outbits = 194;
1363
                            20: outbits = 34;
1364
                            21: outbits = 162;
1365
                            22: outbits = 98;
1366
                            23: outbits = 226;
1367
                            24: outbits = 18;
1368
                            25: outbits = 146;
1369
                            26: outbits = 82;
1370
                            27: outbits = 210;
1371
                            28: outbits = 50;
1372
                            29: outbits = 178;
1373
                            30: outbits = 114;
1374
                            31: outbits = 242;
1375
                            32: outbits = 10;
1376
                            33: outbits = 138;
1377
                            34: outbits = 74;
1378
                            35: outbits = 202;
1379
                            36: outbits = 42;
1380
                            37: outbits = 170;
1381
                            38: outbits = 106;
1382
                            39: outbits = 234;
1383
                            40: outbits = 26;
1384
                            41: outbits = 154;
1385
                            42: outbits = 90;
1386
                            43: outbits = 218;
1387
                            44: outbits = 58;
1388
                            45: outbits = 186;
1389
                            46: outbits = 122;
1390
                            47: outbits = 250;
1391
                            48: outbits = 6;
1392
                            49: outbits = 134;
1393
                            50: outbits = 70;
1394
                            51: outbits = 198;
1395
                            52: outbits = 38;
1396
                            53: outbits = 166;
1397
                            54: outbits = 102;
1398
                            55: outbits = 230;
1399
                            56: outbits = 22;
1400
                            57: outbits = 150;
1401
                            58: outbits = 86;
1402
                            59: outbits = 214;
1403
                            60: outbits = 54;
1404
                            61: outbits = 182;
1405
                            62: outbits = 118;
1406
                            63: outbits = 246;
1407
                            64: outbits = 14;
1408
                            65: outbits = 142;
1409
                            66: outbits = 78;
1410
                            67: outbits = 206;
1411
                            68: outbits = 46;
1412
                            69: outbits = 174;
1413
                            70: outbits = 110;
1414
                            71: outbits = 238;
1415
                            72: outbits = 30;
1416
                            73: outbits = 158;
1417
                            74: outbits = 94;
1418
                            75: outbits = 222;
1419
                            76: outbits = 62;
1420
                            77: outbits = 190;
1421
                            78: outbits = 126;
1422
                            79: outbits = 254;
1423
                            80: outbits = 1;
1424
                            81: outbits = 129;
1425
                            82: outbits = 65;
1426
                            83: outbits = 193;
1427
                            84: outbits = 33;
1428
                            85: outbits = 161;
1429
                            86: outbits = 97;
1430
                            87: outbits = 225;
1431
                            88: outbits = 17;
1432
                            89: outbits = 145;
1433
                            90: outbits = 81;
1434
                            91: outbits = 209;
1435
                            92: outbits = 49;
1436
                            93: outbits = 177;
1437
                            94: outbits = 113;
1438
                            95: outbits = 241;
1439
                            96: outbits = 9;
1440
                            97: outbits = 137;
1441
                            98: outbits = 73;
1442
                            99: outbits = 201;
1443
                            100: outbits = 41;
1444
                            101: outbits = 169;
1445
                            102: outbits = 105;
1446
                            103: outbits = 233;
1447
                            104: outbits = 25;
1448
                            105: outbits = 153;
1449
                            106: outbits = 89;
1450
                            107: outbits = 217;
1451
                            108: outbits = 57;
1452
                            109: outbits = 185;
1453
                            110: outbits = 121;
1454
                            111: outbits = 249;
1455
                            112: outbits = 5;
1456
                            113: outbits = 133;
1457
                            114: outbits = 69;
1458
                            115: outbits = 197;
1459
                            116: outbits = 37;
1460
                            117: outbits = 165;
1461
                            118: outbits = 101;
1462
                            119: outbits = 229;
1463
                            120: outbits = 21;
1464
                            121: outbits = 149;
1465
                            122: outbits = 85;
1466
                            123: outbits = 213;
1467
                            124: outbits = 53;
1468
                            125: outbits = 181;
1469
                            126: outbits = 117;
1470
                            127: outbits = 245;
1471
                            128: outbits = 13;
1472
                            129: outbits = 141;
1473
                            130: outbits = 77;
1474
                            131: outbits = 205;
1475
                            132: outbits = 45;
1476
                            133: outbits = 173;
1477
                            134: outbits = 109;
1478
                            135: outbits = 237;
1479
                            136: outbits = 29;
1480
                            137: outbits = 157;
1481
                            138: outbits = 93;
1482
                            139: outbits = 221;
1483
                            140: outbits = 61;
1484
                            141: outbits = 189;
1485
                            142: outbits = 125;
1486
                            143: outbits = 253;
1487
                            144: outbits = 19;
1488
                            145: outbits = 275;
1489
                            146: outbits = 147;
1490
                            147: outbits = 403;
1491
                            148: outbits = 83;
1492
                            149: outbits = 339;
1493
                            150: outbits = 211;
1494
                            151: outbits = 467;
1495
                            152: outbits = 51;
1496
                            153: outbits = 307;
1497
                            154: outbits = 179;
1498
                            155: outbits = 435;
1499
                            156: outbits = 115;
1500
                            157: outbits = 371;
1501
                            158: outbits = 243;
1502
                            159: outbits = 499;
1503
                            160: outbits = 11;
1504
                            161: outbits = 267;
1505
                            162: outbits = 139;
1506
                            163: outbits = 395;
1507
                            164: outbits = 75;
1508
                            165: outbits = 331;
1509
                            166: outbits = 203;
1510
                            167: outbits = 459;
1511
                            168: outbits = 43;
1512
                            169: outbits = 299;
1513
                            170: outbits = 171;
1514
                            171: outbits = 427;
1515
                            172: outbits = 107;
1516
                            173: outbits = 363;
1517
                            174: outbits = 235;
1518
                            175: outbits = 491;
1519
                            176: outbits = 27;
1520
                            177: outbits = 283;
1521
                            178: outbits = 155;
1522
                            179: outbits = 411;
1523
                            180: outbits = 91;
1524
                            181: outbits = 347;
1525
                            182: outbits = 219;
1526
                            183: outbits = 475;
1527
                            184: outbits = 59;
1528
                            185: outbits = 315;
1529
                            186: outbits = 187;
1530
                            187: outbits = 443;
1531
                            188: outbits = 123;
1532
                            189: outbits = 379;
1533
                            190: outbits = 251;
1534
                            191: outbits = 507;
1535
                            192: outbits = 7;
1536
                            193: outbits = 263;
1537
                            194: outbits = 135;
1538
                            195: outbits = 391;
1539
                            196: outbits = 71;
1540
                            197: outbits = 327;
1541
                            198: outbits = 199;
1542
                            199: outbits = 455;
1543
                            200: outbits = 39;
1544
                            201: outbits = 295;
1545
                            202: outbits = 167;
1546
                            203: outbits = 423;
1547
                            204: outbits = 103;
1548
                            205: outbits = 359;
1549
                            206: outbits = 231;
1550
                            207: outbits = 487;
1551
                            208: outbits = 23;
1552
                            209: outbits = 279;
1553
                            210: outbits = 151;
1554
                            211: outbits = 407;
1555
                            212: outbits = 87;
1556
                            213: outbits = 343;
1557
                            214: outbits = 215;
1558
                            215: outbits = 471;
1559
                            216: outbits = 55;
1560
                            217: outbits = 311;
1561
                            218: outbits = 183;
1562
                            219: outbits = 439;
1563
                            220: outbits = 119;
1564
                            221: outbits = 375;
1565
                            222: outbits = 247;
1566
                            223: outbits = 503;
1567
                            224: outbits = 15;
1568
                            225: outbits = 271;
1569
                            226: outbits = 143;
1570
                            227: outbits = 399;
1571
                            228: outbits = 79;
1572
                            229: outbits = 335;
1573
                            230: outbits = 207;
1574
                            231: outbits = 463;
1575
                            232: outbits = 47;
1576
                            233: outbits = 303;
1577
                            234: outbits = 175;
1578
                            235: outbits = 431;
1579
                            236: outbits = 111;
1580
                            237: outbits = 367;
1581
                            238: outbits = 239;
1582
                            239: outbits = 495;
1583
                            240: outbits = 31;
1584
                            241: outbits = 287;
1585
                            242: outbits = 159;
1586
                            243: outbits = 415;
1587
                            244: outbits = 95;
1588
                            245: outbits = 351;
1589
                            246: outbits = 223;
1590
                            247: outbits = 479;
1591
                            248: outbits = 63;
1592
                            249: outbits = 319;
1593
                            250: outbits = 191;
1594
                            251: outbits = 447;
1595
                            252: outbits = 127;
1596
                            253: outbits = 383;
1597
                            254: outbits = 255;
1598
                            255: outbits = 511;
1599
                            256: outbits = 0;
1600
                            257: outbits = 64;
1601
                            258: outbits = 32;
1602
                            259: outbits = 96;
1603
                            260: outbits = 16;
1604
                            261: outbits = 80;
1605
                            262: outbits = 48;
1606
                            263: outbits = 112;
1607
                            264: outbits = 8;
1608
                            265: outbits = 72;
1609
                            266: outbits = 40;
1610
                            267: outbits = 104;
1611
                            268: outbits = 24;
1612
                            269: outbits = 88;
1613
                            270: outbits = 56;
1614
                            271: outbits = 120;
1615
                            272: outbits = 4;
1616
                            273: outbits = 68;
1617
                            274: outbits = 36;
1618
                            275: outbits = 100;
1619
                            276: outbits = 20;
1620
                            277: outbits = 84;
1621
                            278: outbits = 52;
1622
                            279: outbits = 116;
1623
                            280: outbits = 3;
1624
                            281: outbits = 131;
1625
                            282: outbits = 67;
1626
                            283: outbits = 195;
1627
                            284: outbits = 35;
1628
                            285: outbits = 163;
1629
                            286: outbits = 99;
1630
                            default: outbits = 227;
1631
                        endcase
1632 2 tomtor
                        $write("EOF BITS:");
1633
                        $write(" ");
1634
                        $write("%0d", cs_i);
1635
                        $write(" ");
1636
                        $write("%h", outlen);
1637
                        $write(" ");
1638 6 tomtor
                        $write("%0d", outbits);
1639 2 tomtor
                        $write("\n");
1640
                        oaddr <= do;
1641
                        obyte <= MYHDL13_put(outbits, outlen);
1642
                        MYHDL14_put_adv(outbits, outlen);
1643
                    end
1644
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 2))) begin
1645
                        $write("calc end adler");
1646
                        $write("\n");
1647
                        adler2 <= ((adler2 + ladler1) % 65521);
1648
                        if ((doo != 0)) begin
1649
                            oaddr <= do;
1650
                            obyte <= ob1;
1651
                            do <= (do + 1);
1652
                        end
1653
                    end
1654
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 3))) begin
1655
                        $write("c1");
1656
                        $write("\n");
1657
                        oaddr <= do;
1658
                        obyte <= (adler2 >>> 8);
1659
                        do <= (do + 1);
1660 6 tomtor
                        o_oprogress <= (do + 1);
1661 2 tomtor
                    end
1662
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 4))) begin
1663
                        $write("c2");
1664
                        $write("\n");
1665
                        oaddr <= do;
1666
                        obyte <= (adler2 & 255);
1667
                        do <= (do + 1);
1668 6 tomtor
                        o_oprogress <= (do + 1);
1669 2 tomtor
                    end
1670
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 5))) begin
1671
                        $write("c3");
1672
                        $write("\n");
1673
                        oaddr <= do;
1674
                        obyte <= (adler1 >>> 8);
1675
                        do <= (do + 1);
1676 6 tomtor
                        o_oprogress <= (do + 1);
1677 2 tomtor
                    end
1678
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 6))) begin
1679
                        $write("c4");
1680
                        $write("\n");
1681
                        oaddr <= do;
1682
                        obyte <= (adler1 & 255);
1683 6 tomtor
                        o_oprogress <= (do + 1);
1684 2 tomtor
                    end
1685
                    else if ((($signed({1'b0, cur_cstatic}) - 3) == (isize + 7))) begin
1686
                        $write("EOF finish");
1687
                        $write(" ");
1688
                        $write("%h", do);
1689
                        $write("\n");
1690
                        o_done <= 1'b1;
1691
                        state <= 5'b00000;
1692
                    end
1693
                    else begin
1694
                        $write("%h", cur_cstatic);
1695
                        $write(" ");
1696
                        $write("%h", isize);
1697
                        $write("\n");
1698
                        $finish;
1699
                    end
1700
                end
1701
                else begin
1702 6 tomtor
                    bdata = iram[(di & 63)];
1703
                    o_iprogress <= di;
1704 2 tomtor
                    adler1_next = ((adler1 + bdata) % 65521);
1705
                    adler1 <= adler1_next;
1706
                    adler2 <= ((adler2 + ladler1) % 65521);
1707
                    ladler1 <= adler1_next;
1708
                    state <= 5'b10111;
1709
                    cur_search <= (di - 1);
1710
                end
1711
                if ((!no_adv)) begin
1712
                    cur_cstatic <= (cur_cstatic + 1);
1713
                end
1714
            end
1715 6 tomtor
            5'b11001: begin
1716 5 tomtor
                if ((!1'b1)) begin
1717
                    // pass
1718
                end
1719
                else if (flush) begin
1720 2 tomtor
                    MYHDL15_do_flush;
1721
                end
1722 6 tomtor
                else if ((cur_i == 1024)) begin
1723
                    lencode = (length + 254);
1724
                    outlen = codeLength[lencode];
1725
                    case (lencode)
1726
                        0: outbits = 12;
1727
                        1: outbits = 140;
1728
                        2: outbits = 76;
1729
                        3: outbits = 204;
1730
                        4: outbits = 44;
1731
                        5: outbits = 172;
1732
                        6: outbits = 108;
1733
                        7: outbits = 236;
1734
                        8: outbits = 28;
1735
                        9: outbits = 156;
1736
                        10: outbits = 92;
1737
                        11: outbits = 220;
1738
                        12: outbits = 60;
1739
                        13: outbits = 188;
1740
                        14: outbits = 124;
1741
                        15: outbits = 252;
1742
                        16: outbits = 2;
1743
                        17: outbits = 130;
1744
                        18: outbits = 66;
1745
                        19: outbits = 194;
1746
                        20: outbits = 34;
1747
                        21: outbits = 162;
1748
                        22: outbits = 98;
1749
                        23: outbits = 226;
1750
                        24: outbits = 18;
1751
                        25: outbits = 146;
1752
                        26: outbits = 82;
1753
                        27: outbits = 210;
1754
                        28: outbits = 50;
1755
                        29: outbits = 178;
1756
                        30: outbits = 114;
1757
                        31: outbits = 242;
1758
                        32: outbits = 10;
1759
                        33: outbits = 138;
1760
                        34: outbits = 74;
1761
                        35: outbits = 202;
1762
                        36: outbits = 42;
1763
                        37: outbits = 170;
1764
                        38: outbits = 106;
1765
                        39: outbits = 234;
1766
                        40: outbits = 26;
1767
                        41: outbits = 154;
1768
                        42: outbits = 90;
1769
                        43: outbits = 218;
1770
                        44: outbits = 58;
1771
                        45: outbits = 186;
1772
                        46: outbits = 122;
1773
                        47: outbits = 250;
1774
                        48: outbits = 6;
1775
                        49: outbits = 134;
1776
                        50: outbits = 70;
1777
                        51: outbits = 198;
1778
                        52: outbits = 38;
1779
                        53: outbits = 166;
1780
                        54: outbits = 102;
1781
                        55: outbits = 230;
1782
                        56: outbits = 22;
1783
                        57: outbits = 150;
1784
                        58: outbits = 86;
1785
                        59: outbits = 214;
1786
                        60: outbits = 54;
1787
                        61: outbits = 182;
1788
                        62: outbits = 118;
1789
                        63: outbits = 246;
1790
                        64: outbits = 14;
1791
                        65: outbits = 142;
1792
                        66: outbits = 78;
1793
                        67: outbits = 206;
1794
                        68: outbits = 46;
1795
                        69: outbits = 174;
1796
                        70: outbits = 110;
1797
                        71: outbits = 238;
1798
                        72: outbits = 30;
1799
                        73: outbits = 158;
1800
                        74: outbits = 94;
1801
                        75: outbits = 222;
1802
                        76: outbits = 62;
1803
                        77: outbits = 190;
1804
                        78: outbits = 126;
1805
                        79: outbits = 254;
1806
                        80: outbits = 1;
1807
                        81: outbits = 129;
1808
                        82: outbits = 65;
1809
                        83: outbits = 193;
1810
                        84: outbits = 33;
1811
                        85: outbits = 161;
1812
                        86: outbits = 97;
1813
                        87: outbits = 225;
1814
                        88: outbits = 17;
1815
                        89: outbits = 145;
1816
                        90: outbits = 81;
1817
                        91: outbits = 209;
1818
                        92: outbits = 49;
1819
                        93: outbits = 177;
1820
                        94: outbits = 113;
1821
                        95: outbits = 241;
1822
                        96: outbits = 9;
1823
                        97: outbits = 137;
1824
                        98: outbits = 73;
1825
                        99: outbits = 201;
1826
                        100: outbits = 41;
1827
                        101: outbits = 169;
1828
                        102: outbits = 105;
1829
                        103: outbits = 233;
1830
                        104: outbits = 25;
1831
                        105: outbits = 153;
1832
                        106: outbits = 89;
1833
                        107: outbits = 217;
1834
                        108: outbits = 57;
1835
                        109: outbits = 185;
1836
                        110: outbits = 121;
1837
                        111: outbits = 249;
1838
                        112: outbits = 5;
1839
                        113: outbits = 133;
1840
                        114: outbits = 69;
1841
                        115: outbits = 197;
1842
                        116: outbits = 37;
1843
                        117: outbits = 165;
1844
                        118: outbits = 101;
1845
                        119: outbits = 229;
1846
                        120: outbits = 21;
1847
                        121: outbits = 149;
1848
                        122: outbits = 85;
1849
                        123: outbits = 213;
1850
                        124: outbits = 53;
1851
                        125: outbits = 181;
1852
                        126: outbits = 117;
1853
                        127: outbits = 245;
1854
                        128: outbits = 13;
1855
                        129: outbits = 141;
1856
                        130: outbits = 77;
1857
                        131: outbits = 205;
1858
                        132: outbits = 45;
1859
                        133: outbits = 173;
1860
                        134: outbits = 109;
1861
                        135: outbits = 237;
1862
                        136: outbits = 29;
1863
                        137: outbits = 157;
1864
                        138: outbits = 93;
1865
                        139: outbits = 221;
1866
                        140: outbits = 61;
1867
                        141: outbits = 189;
1868
                        142: outbits = 125;
1869
                        143: outbits = 253;
1870
                        144: outbits = 19;
1871
                        145: outbits = 275;
1872
                        146: outbits = 147;
1873
                        147: outbits = 403;
1874
                        148: outbits = 83;
1875
                        149: outbits = 339;
1876
                        150: outbits = 211;
1877
                        151: outbits = 467;
1878
                        152: outbits = 51;
1879
                        153: outbits = 307;
1880
                        154: outbits = 179;
1881
                        155: outbits = 435;
1882
                        156: outbits = 115;
1883
                        157: outbits = 371;
1884
                        158: outbits = 243;
1885
                        159: outbits = 499;
1886
                        160: outbits = 11;
1887
                        161: outbits = 267;
1888
                        162: outbits = 139;
1889
                        163: outbits = 395;
1890
                        164: outbits = 75;
1891
                        165: outbits = 331;
1892
                        166: outbits = 203;
1893
                        167: outbits = 459;
1894
                        168: outbits = 43;
1895
                        169: outbits = 299;
1896
                        170: outbits = 171;
1897
                        171: outbits = 427;
1898
                        172: outbits = 107;
1899
                        173: outbits = 363;
1900
                        174: outbits = 235;
1901
                        175: outbits = 491;
1902
                        176: outbits = 27;
1903
                        177: outbits = 283;
1904
                        178: outbits = 155;
1905
                        179: outbits = 411;
1906
                        180: outbits = 91;
1907
                        181: outbits = 347;
1908
                        182: outbits = 219;
1909
                        183: outbits = 475;
1910
                        184: outbits = 59;
1911
                        185: outbits = 315;
1912
                        186: outbits = 187;
1913
                        187: outbits = 443;
1914
                        188: outbits = 123;
1915
                        189: outbits = 379;
1916
                        190: outbits = 251;
1917
                        191: outbits = 507;
1918
                        192: outbits = 7;
1919
                        193: outbits = 263;
1920
                        194: outbits = 135;
1921
                        195: outbits = 391;
1922
                        196: outbits = 71;
1923
                        197: outbits = 327;
1924
                        198: outbits = 199;
1925
                        199: outbits = 455;
1926
                        200: outbits = 39;
1927
                        201: outbits = 295;
1928
                        202: outbits = 167;
1929
                        203: outbits = 423;
1930
                        204: outbits = 103;
1931
                        205: outbits = 359;
1932
                        206: outbits = 231;
1933
                        207: outbits = 487;
1934
                        208: outbits = 23;
1935
                        209: outbits = 279;
1936
                        210: outbits = 151;
1937
                        211: outbits = 407;
1938
                        212: outbits = 87;
1939
                        213: outbits = 343;
1940
                        214: outbits = 215;
1941
                        215: outbits = 471;
1942
                        216: outbits = 55;
1943
                        217: outbits = 311;
1944
                        218: outbits = 183;
1945
                        219: outbits = 439;
1946
                        220: outbits = 119;
1947
                        221: outbits = 375;
1948
                        222: outbits = 247;
1949
                        223: outbits = 503;
1950
                        224: outbits = 15;
1951
                        225: outbits = 271;
1952
                        226: outbits = 143;
1953
                        227: outbits = 399;
1954
                        228: outbits = 79;
1955
                        229: outbits = 335;
1956
                        230: outbits = 207;
1957
                        231: outbits = 463;
1958
                        232: outbits = 47;
1959
                        233: outbits = 303;
1960
                        234: outbits = 175;
1961
                        235: outbits = 431;
1962
                        236: outbits = 111;
1963
                        237: outbits = 367;
1964
                        238: outbits = 239;
1965
                        239: outbits = 495;
1966
                        240: outbits = 31;
1967
                        241: outbits = 287;
1968
                        242: outbits = 159;
1969
                        243: outbits = 415;
1970
                        244: outbits = 95;
1971
                        245: outbits = 351;
1972
                        246: outbits = 223;
1973
                        247: outbits = 479;
1974
                        248: outbits = 63;
1975
                        249: outbits = 319;
1976
                        250: outbits = 191;
1977
                        251: outbits = 447;
1978
                        252: outbits = 127;
1979
                        253: outbits = 383;
1980
                        254: outbits = 255;
1981
                        255: outbits = 511;
1982
                        256: outbits = 0;
1983
                        257: outbits = 64;
1984
                        258: outbits = 32;
1985
                        259: outbits = 96;
1986
                        260: outbits = 16;
1987
                        261: outbits = 80;
1988
                        262: outbits = 48;
1989
                        263: outbits = 112;
1990
                        264: outbits = 8;
1991
                        265: outbits = 72;
1992
                        266: outbits = 40;
1993
                        267: outbits = 104;
1994
                        268: outbits = 24;
1995
                        269: outbits = 88;
1996
                        270: outbits = 56;
1997
                        271: outbits = 120;
1998
                        272: outbits = 4;
1999
                        273: outbits = 68;
2000
                        274: outbits = 36;
2001
                        275: outbits = 100;
2002
                        276: outbits = 20;
2003
                        277: outbits = 84;
2004
                        278: outbits = 52;
2005
                        279: outbits = 116;
2006
                        280: outbits = 3;
2007
                        281: outbits = 131;
2008
                        282: outbits = 67;
2009
                        283: outbits = 195;
2010
                        284: outbits = 35;
2011
                        285: outbits = 163;
2012
                        286: outbits = 99;
2013
                        default: outbits = 227;
2014
                    endcase
2015
                    oaddr <= do;
2016
                    obyte <= MYHDL16_put(outbits, outlen);
2017
                    MYHDL17_put_adv(outbits, outlen);
2018
                    cur_i <= 0;
2019
                end
2020 2 tomtor
                else begin
2021
                    case ((cur_i + 1))
2022
                        0: nextdist = 1;
2023
                        1: nextdist = 2;
2024
                        2: nextdist = 3;
2025
                        3: nextdist = 4;
2026
                        4: nextdist = 5;
2027
                        5: nextdist = 7;
2028
                        6: nextdist = 9;
2029
                        7: nextdist = 13;
2030
                        8: nextdist = 17;
2031
                        9: nextdist = 25;
2032
                        10: nextdist = 33;
2033
                        11: nextdist = 49;
2034
                        12: nextdist = 65;
2035
                        13: nextdist = 97;
2036
                        14: nextdist = 129;
2037
                        15: nextdist = 193;
2038
                        16: nextdist = 257;
2039
                        17: nextdist = 385;
2040
                        18: nextdist = 513;
2041
                        19: nextdist = 769;
2042
                        20: nextdist = 1025;
2043
                        21: nextdist = 1537;
2044
                        22: nextdist = 2049;
2045
                        23: nextdist = 3073;
2046
                        24: nextdist = 4097;
2047
                        25: nextdist = 6145;
2048
                        26: nextdist = 8193;
2049
                        27: nextdist = 12289;
2050
                        28: nextdist = 16385;
2051
                        default: nextdist = 24577;
2052
                    endcase
2053
                    if ((nextdist > cur_dist)) begin
2054
                        case (cur_i)
2055
                            0: copydist = 1;
2056
                            1: copydist = 2;
2057
                            2: copydist = 3;
2058
                            3: copydist = 4;
2059
                            4: copydist = 5;
2060
                            5: copydist = 7;
2061
                            6: copydist = 9;
2062
                            7: copydist = 13;
2063
                            8: copydist = 17;
2064
                            9: copydist = 25;
2065
                            10: copydist = 33;
2066
                            11: copydist = 49;
2067
                            12: copydist = 65;
2068
                            13: copydist = 97;
2069
                            14: copydist = 129;
2070
                            15: copydist = 193;
2071
                            16: copydist = 257;
2072
                            17: copydist = 385;
2073
                            18: copydist = 513;
2074
                            19: copydist = 769;
2075
                            20: copydist = 1025;
2076
                            21: copydist = 1537;
2077
                            22: copydist = 2049;
2078
                            23: copydist = 3073;
2079
                            24: copydist = 4097;
2080
                            25: copydist = 6145;
2081
                            26: copydist = 8193;
2082
                            27: copydist = 12289;
2083
                            28: copydist = 16385;
2084
                            default: copydist = 24577;
2085
                        endcase
2086
                        extra_dist = (cur_dist - copydist);
2087
                        case ((cur_i / 2))
2088
                            0: extra_bits = 0;
2089
                            1: extra_bits = 0;
2090
                            2: extra_bits = 1;
2091
                            3: extra_bits = 2;
2092
                            4: extra_bits = 3;
2093
                            5: extra_bits = 4;
2094
                            6: extra_bits = 5;
2095
                            7: extra_bits = 6;
2096
                            8: extra_bits = 7;
2097
                            9: extra_bits = 8;
2098
                            10: extra_bits = 9;
2099
                            11: extra_bits = 10;
2100
                            12: extra_bits = 11;
2101
                            13: extra_bits = 12;
2102
                            default: extra_bits = 13;
2103
                        endcase
2104
                        if ((extra_dist > ((1 << extra_bits) - 1))) begin
2105
                            $finish;
2106
                        end
2107 6 tomtor
                        outcode = (MYHDL18_rev_bits(cur_i, 5) | (extra_dist << 5));
2108 2 tomtor
                        oaddr <= do;
2109 6 tomtor
                        obyte <= MYHDL19_put(outcode, (5 + extra_bits));
2110
                        MYHDL20_put_adv(outcode, (5 + extra_bits));
2111 2 tomtor
                        cur_i <= (($signed({1'b0, di}) - $signed({1'b0, length})) + 1);
2112 6 tomtor
                        state <= 5'b11010;
2113 2 tomtor
                    end
2114
                    else begin
2115
                        cur_i <= (cur_i + 1);
2116
                    end
2117
                end
2118
            end
2119 6 tomtor
            5'b11010: begin
2120 5 tomtor
                if ((!1'b1)) begin
2121
                    // pass
2122
                end
2123
                else if ((cur_i < di)) begin
2124 6 tomtor
                    bdata = iram[(cur_i & 63)];
2125 2 tomtor
                    adler1_next = ((adler1 + bdata) % 65521);
2126
                    adler1 <= adler1_next;
2127
                    adler2 <= ((adler2 + ladler1) % 65521);
2128
                    ladler1 <= adler1_next;
2129
                    cur_i <= (cur_i + 1);
2130
                end
2131
                else begin
2132
                    state <= 5'b10110;
2133
                end
2134
            end
2135 6 tomtor
            5'b11000: begin
2136
                if ((1'b1 && 1'b1)) begin
2137
                    lfmatch = length;
2138
                    distance = (lfmatch + 1);
2139
                    fmatch2 = (($signed({1'b0, di}) - $signed({1'b0, lfmatch})) + 2);
2140
                    lencode = 257;
2141
                    match = 3;
2142
                    if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 4)) && (iram[(fmatch2 & 63)] == b4))) begin
2143
                        lencode = 258;
2144
                        match = 4;
2145
                        if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 5)) && (iram[((fmatch2 + 1) & 63)] == b5))) begin
2146
                            lencode = 259;
2147
                            match = 5;
2148
                            if ((1'b1 && ($signed({1'b0, di}) < ($signed({1'b0, isize}) - 6)) && (iram[((fmatch2 + 2) & 63)] == b6))) begin
2149
                                lencode = 260;
2150
                                match = 6;
2151
                                if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 7)) && (iram[((fmatch2 + 3) & 63)] == b7))) begin
2152
                                    lencode = 261;
2153
                                    match = 7;
2154
                                    if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 8)) && (iram[((fmatch2 + 4) & 63)] == b8))) begin
2155
                                        lencode = 262;
2156
                                        match = 8;
2157
                                        if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 9)) && (iram[((fmatch2 + 5) & 63)] == b9))) begin
2158
                                            lencode = 263;
2159
                                            match = 9;
2160
                                            if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 10)) && (iram[((fmatch2 + 6) & 63)] == b10))) begin
2161
                                                lencode = 264;
2162
                                                match = 10;
2163
                                            end
2164
                                        end
2165
                                    end
2166
                                end
2167
                            end
2168
                        end
2169
                    end
2170
                    cur_dist <= distance;
2171
                    cur_i <= 1024;
2172
                    di <= (di + match);
2173
                    cur_cstatic <= ((cur_cstatic + match) - 1);
2174
                    length <= match;
2175
                    state <= 5'b11001;
2176
                end
2177
            end
2178 2 tomtor
            5'b10111: begin
2179 5 tomtor
                if ((!1'b1)) begin
2180
                    // pass
2181
                end
2182
                else if ((!filled)) begin
2183 2 tomtor
                    filled <= 1'b1;
2184
                end
2185
                else if ((nb < 4)) begin
2186
                    // pass
2187
                end
2188
                else begin
2189
                    if (((cur_search >= 0) && (cur_search >= ($signed({1'b0, di}) - 32)) && ($signed({1'b0, di}) < ($signed({1'b0, isize}) - 3)))) begin
2190 5 tomtor
                        if (1'b1) begin
2191
                            found = 0;
2192
                            fmatch = 0;
2193 6 tomtor
                            begin: MYHDL21_BREAK
2194 5 tomtor
                            for (si=0; si<32; si=si+1) begin
2195
                                if (smatch[si]) begin
2196
                                    fmatch = si;
2197
                                    found = 1;
2198 6 tomtor
                                    disable MYHDL21_BREAK;
2199 5 tomtor
                                end
2200
                            end
2201
                            end
2202
                            if (((!found) || ((($signed({1'b0, di}) - fmatch) - 1) < 0))) begin
2203
                                cur_search <= (-1);
2204
                            end
2205
                            else begin
2206 6 tomtor
                                length <= fmatch;
2207 5 tomtor
                                state <= 5'b11000;
2208
                            end
2209
                        end
2210 6 tomtor
                        else if (((!1'b1) && (iram[(cur_search & 63)] == b1) && (iram[((cur_search + 1) & 63)] == b2) && (iram[((cur_search + 2) & 63)] == b3))) begin
2211 2 tomtor
                            lencode = 257;
2212
                            match = 3;
2213 6 tomtor
                            if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 4)) && (iram[((cur_search + 3) & 63)] == b4))) begin
2214 2 tomtor
                                lencode = 258;
2215
                                match = 4;
2216 6 tomtor
                                if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 5)) && (iram[((cur_search + 4) & 63)] == b5))) begin
2217 2 tomtor
                                    lencode = 259;
2218
                                    match = 5;
2219 6 tomtor
                                    if ((1'b1 && ($signed({1'b0, di}) < ($signed({1'b0, isize}) - 6)) && (iram[((cur_search + 5) & 63)] == b6))) begin
2220 5 tomtor
                                        lencode = 260;
2221
                                        match = 6;
2222 6 tomtor
                                        if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 7)) && (iram[((cur_search + 6) & 63)] == b7))) begin
2223 5 tomtor
                                            lencode = 261;
2224
                                            match = 7;
2225 6 tomtor
                                            if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 8)) && (iram[((cur_search + 7) & 63)] == b8))) begin
2226 5 tomtor
                                                lencode = 262;
2227
                                                match = 8;
2228 6 tomtor
                                                if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 9)) && (iram[((cur_search + 8) & 63)] == b9))) begin
2229 5 tomtor
                                                    lencode = 263;
2230
                                                    match = 9;
2231 6 tomtor
                                                    if ((($signed({1'b0, di}) < ($signed({1'b0, isize}) - 10)) && (iram[((cur_search + 9) & 63)] == b10))) begin
2232 5 tomtor
                                                        lencode = 264;
2233
                                                        match = 10;
2234
                                                    end
2235
                                                end
2236
                                            end
2237
                                        end
2238
                                    end
2239 2 tomtor
                                end
2240
                            end
2241
                            distance = ($signed({1'b0, di}) - cur_search);
2242
                            cur_dist <= distance;
2243 6 tomtor
                            cur_i <= 1024;
2244 2 tomtor
                            di <= (di + match);
2245
                            cur_cstatic <= ((cur_cstatic + match) - 1);
2246
                            length <= match;
2247 6 tomtor
                            state <= 5'b11001;
2248 2 tomtor
                        end
2249
                        else begin
2250
                            cur_search <= (cur_search - 1);
2251
                        end
2252
                    end
2253
                    else begin
2254 6 tomtor
                        bdata = b1;
2255 2 tomtor
                        di <= (di + 1);
2256
                        outlen = codeLength[bdata];
2257 6 tomtor
                        case (bdata)
2258
                            0: outbits = 12;
2259
                            1: outbits = 140;
2260
                            2: outbits = 76;
2261
                            3: outbits = 204;
2262
                            4: outbits = 44;
2263
                            5: outbits = 172;
2264
                            6: outbits = 108;
2265
                            7: outbits = 236;
2266
                            8: outbits = 28;
2267
                            9: outbits = 156;
2268
                            10: outbits = 92;
2269
                            11: outbits = 220;
2270
                            12: outbits = 60;
2271
                            13: outbits = 188;
2272
                            14: outbits = 124;
2273
                            15: outbits = 252;
2274
                            16: outbits = 2;
2275
                            17: outbits = 130;
2276
                            18: outbits = 66;
2277
                            19: outbits = 194;
2278
                            20: outbits = 34;
2279
                            21: outbits = 162;
2280
                            22: outbits = 98;
2281
                            23: outbits = 226;
2282
                            24: outbits = 18;
2283
                            25: outbits = 146;
2284
                            26: outbits = 82;
2285
                            27: outbits = 210;
2286
                            28: outbits = 50;
2287
                            29: outbits = 178;
2288
                            30: outbits = 114;
2289
                            31: outbits = 242;
2290
                            32: outbits = 10;
2291
                            33: outbits = 138;
2292
                            34: outbits = 74;
2293
                            35: outbits = 202;
2294
                            36: outbits = 42;
2295
                            37: outbits = 170;
2296
                            38: outbits = 106;
2297
                            39: outbits = 234;
2298
                            40: outbits = 26;
2299
                            41: outbits = 154;
2300
                            42: outbits = 90;
2301
                            43: outbits = 218;
2302
                            44: outbits = 58;
2303
                            45: outbits = 186;
2304
                            46: outbits = 122;
2305
                            47: outbits = 250;
2306
                            48: outbits = 6;
2307
                            49: outbits = 134;
2308
                            50: outbits = 70;
2309
                            51: outbits = 198;
2310
                            52: outbits = 38;
2311
                            53: outbits = 166;
2312
                            54: outbits = 102;
2313
                            55: outbits = 230;
2314
                            56: outbits = 22;
2315
                            57: outbits = 150;
2316
                            58: outbits = 86;
2317
                            59: outbits = 214;
2318
                            60: outbits = 54;
2319
                            61: outbits = 182;
2320
                            62: outbits = 118;
2321
                            63: outbits = 246;
2322
                            64: outbits = 14;
2323
                            65: outbits = 142;
2324
                            66: outbits = 78;
2325
                            67: outbits = 206;
2326
                            68: outbits = 46;
2327
                            69: outbits = 174;
2328
                            70: outbits = 110;
2329
                            71: outbits = 238;
2330
                            72: outbits = 30;
2331
                            73: outbits = 158;
2332
                            74: outbits = 94;
2333
                            75: outbits = 222;
2334
                            76: outbits = 62;
2335
                            77: outbits = 190;
2336
                            78: outbits = 126;
2337
                            79: outbits = 254;
2338
                            80: outbits = 1;
2339
                            81: outbits = 129;
2340
                            82: outbits = 65;
2341
                            83: outbits = 193;
2342
                            84: outbits = 33;
2343
                            85: outbits = 161;
2344
                            86: outbits = 97;
2345
                            87: outbits = 225;
2346
                            88: outbits = 17;
2347
                            89: outbits = 145;
2348
                            90: outbits = 81;
2349
                            91: outbits = 209;
2350
                            92: outbits = 49;
2351
                            93: outbits = 177;
2352
                            94: outbits = 113;
2353
                            95: outbits = 241;
2354
                            96: outbits = 9;
2355
                            97: outbits = 137;
2356
                            98: outbits = 73;
2357
                            99: outbits = 201;
2358
                            100: outbits = 41;
2359
                            101: outbits = 169;
2360
                            102: outbits = 105;
2361
                            103: outbits = 233;
2362
                            104: outbits = 25;
2363
                            105: outbits = 153;
2364
                            106: outbits = 89;
2365
                            107: outbits = 217;
2366
                            108: outbits = 57;
2367
                            109: outbits = 185;
2368
                            110: outbits = 121;
2369
                            111: outbits = 249;
2370
                            112: outbits = 5;
2371
                            113: outbits = 133;
2372
                            114: outbits = 69;
2373
                            115: outbits = 197;
2374
                            116: outbits = 37;
2375
                            117: outbits = 165;
2376
                            118: outbits = 101;
2377
                            119: outbits = 229;
2378
                            120: outbits = 21;
2379
                            121: outbits = 149;
2380
                            122: outbits = 85;
2381
                            123: outbits = 213;
2382
                            124: outbits = 53;
2383
                            125: outbits = 181;
2384
                            126: outbits = 117;
2385
                            127: outbits = 245;
2386
                            128: outbits = 13;
2387
                            129: outbits = 141;
2388
                            130: outbits = 77;
2389
                            131: outbits = 205;
2390
                            132: outbits = 45;
2391
                            133: outbits = 173;
2392
                            134: outbits = 109;
2393
                            135: outbits = 237;
2394
                            136: outbits = 29;
2395
                            137: outbits = 157;
2396
                            138: outbits = 93;
2397
                            139: outbits = 221;
2398
                            140: outbits = 61;
2399
                            141: outbits = 189;
2400
                            142: outbits = 125;
2401
                            143: outbits = 253;
2402
                            144: outbits = 19;
2403
                            145: outbits = 275;
2404
                            146: outbits = 147;
2405
                            147: outbits = 403;
2406
                            148: outbits = 83;
2407
                            149: outbits = 339;
2408
                            150: outbits = 211;
2409
                            151: outbits = 467;
2410
                            152: outbits = 51;
2411
                            153: outbits = 307;
2412
                            154: outbits = 179;
2413
                            155: outbits = 435;
2414
                            156: outbits = 115;
2415
                            157: outbits = 371;
2416
                            158: outbits = 243;
2417
                            159: outbits = 499;
2418
                            160: outbits = 11;
2419
                            161: outbits = 267;
2420
                            162: outbits = 139;
2421
                            163: outbits = 395;
2422
                            164: outbits = 75;
2423
                            165: outbits = 331;
2424
                            166: outbits = 203;
2425
                            167: outbits = 459;
2426
                            168: outbits = 43;
2427
                            169: outbits = 299;
2428
                            170: outbits = 171;
2429
                            171: outbits = 427;
2430
                            172: outbits = 107;
2431
                            173: outbits = 363;
2432
                            174: outbits = 235;
2433
                            175: outbits = 491;
2434
                            176: outbits = 27;
2435
                            177: outbits = 283;
2436
                            178: outbits = 155;
2437
                            179: outbits = 411;
2438
                            180: outbits = 91;
2439
                            181: outbits = 347;
2440
                            182: outbits = 219;
2441
                            183: outbits = 475;
2442
                            184: outbits = 59;
2443
                            185: outbits = 315;
2444
                            186: outbits = 187;
2445
                            187: outbits = 443;
2446
                            188: outbits = 123;
2447
                            189: outbits = 379;
2448
                            190: outbits = 251;
2449
                            191: outbits = 507;
2450
                            192: outbits = 7;
2451
                            193: outbits = 263;
2452
                            194: outbits = 135;
2453
                            195: outbits = 391;
2454
                            196: outbits = 71;
2455
                            197: outbits = 327;
2456
                            198: outbits = 199;
2457
                            199: outbits = 455;
2458
                            200: outbits = 39;
2459
                            201: outbits = 295;
2460
                            202: outbits = 167;
2461
                            203: outbits = 423;
2462
                            204: outbits = 103;
2463
                            205: outbits = 359;
2464
                            206: outbits = 231;
2465
                            207: outbits = 487;
2466
                            208: outbits = 23;
2467
                            209: outbits = 279;
2468
                            210: outbits = 151;
2469
                            211: outbits = 407;
2470
                            212: outbits = 87;
2471
                            213: outbits = 343;
2472
                            214: outbits = 215;
2473
                            215: outbits = 471;
2474
                            216: outbits = 55;
2475
                            217: outbits = 311;
2476
                            218: outbits = 183;
2477
                            219: outbits = 439;
2478
                            220: outbits = 119;
2479
                            221: outbits = 375;
2480
                            222: outbits = 247;
2481
                            223: outbits = 503;
2482
                            224: outbits = 15;
2483
                            225: outbits = 271;
2484
                            226: outbits = 143;
2485
                            227: outbits = 399;
2486
                            228: outbits = 79;
2487
                            229: outbits = 335;
2488
                            230: outbits = 207;
2489
                            231: outbits = 463;
2490
                            232: outbits = 47;
2491
                            233: outbits = 303;
2492
                            234: outbits = 175;
2493
                            235: outbits = 431;
2494
                            236: outbits = 111;
2495
                            237: outbits = 367;
2496
                            238: outbits = 239;
2497
                            239: outbits = 495;
2498
                            240: outbits = 31;
2499
                            241: outbits = 287;
2500
                            242: outbits = 159;
2501
                            243: outbits = 415;
2502
                            244: outbits = 95;
2503
                            245: outbits = 351;
2504
                            246: outbits = 223;
2505
                            247: outbits = 479;
2506
                            248: outbits = 63;
2507
                            249: outbits = 319;
2508
                            250: outbits = 191;
2509
                            251: outbits = 447;
2510
                            252: outbits = 127;
2511
                            253: outbits = 383;
2512
                            254: outbits = 255;
2513
                            255: outbits = 511;
2514
                            256: outbits = 0;
2515
                            257: outbits = 64;
2516
                            258: outbits = 32;
2517
                            259: outbits = 96;
2518
                            260: outbits = 16;
2519
                            261: outbits = 80;
2520
                            262: outbits = 48;
2521
                            263: outbits = 112;
2522
                            264: outbits = 8;
2523
                            265: outbits = 72;
2524
                            266: outbits = 40;
2525
                            267: outbits = 104;
2526
                            268: outbits = 24;
2527
                            269: outbits = 88;
2528
                            270: outbits = 56;
2529
                            271: outbits = 120;
2530
                            272: outbits = 4;
2531
                            273: outbits = 68;
2532
                            274: outbits = 36;
2533
                            275: outbits = 100;
2534
                            276: outbits = 20;
2535
                            277: outbits = 84;
2536
                            278: outbits = 52;
2537
                            279: outbits = 116;
2538
                            280: outbits = 3;
2539
                            281: outbits = 131;
2540
                            282: outbits = 67;
2541
                            283: outbits = 195;
2542
                            284: outbits = 35;
2543
                            285: outbits = 163;
2544
                            286: outbits = 99;
2545
                            default: outbits = 227;
2546
                        endcase
2547 2 tomtor
                        oaddr <= do;
2548 6 tomtor
                        obyte <= MYHDL23_put(outbits, outlen);
2549
                        MYHDL24_put_adv(outbits, outlen);
2550 2 tomtor
                        state <= 5'b10110;
2551
                    end
2552
                end
2553
            end
2554
            5'b01110: begin
2555
                for (stat_i=0; stat_i<144; stat_i=stat_i+1) begin
2556
                    codeLength[stat_i] <= 8;
2557
                end
2558
                for (stat_i=144; stat_i<256; stat_i=stat_i+1) begin
2559
                    codeLength[stat_i] <= 9;
2560
                end
2561
                for (stat_i=256; stat_i<280; stat_i=stat_i+1) begin
2562
                    codeLength[stat_i] <= 7;
2563
                end
2564
                for (stat_i=280; stat_i<288; stat_i=stat_i+1) begin
2565
                    codeLength[stat_i] <= 8;
2566
                end
2567
                numCodeLength <= 288;
2568 6 tomtor
                if (do_compress) begin
2569
                    state <= 5'b10110;
2570
                end
2571
                else begin
2572
                    cur_HF1 <= 0;
2573
                    state <= 5'b00111;
2574
                end
2575 2 tomtor
            end
2576
            5'b00010: begin
2577 6 tomtor
                if (((!1'b1) || (!1'b0))) begin
2578
                    // pass
2579
                end
2580
                else if ((!filled)) begin
2581 2 tomtor
                    filled <= 1'b1;
2582
                end
2583
                else if ((nb < 4)) begin
2584
                    // pass
2585
                end
2586
                else if ((numLiterals == 0)) begin
2587 6 tomtor
                    $write("%h", di);
2588
                    $write(" ");
2589
                    $write("%h", isize);
2590
                    $write("\n");
2591
                    numLiterals <= (257 + MYHDL33_get4(0, 5));
2592 2 tomtor
                    $write("NL:");
2593
                    $write(" ");
2594 6 tomtor
                    $write("%0d", (257 + MYHDL34_get4(0, 5)));
2595 2 tomtor
                    $write("\n");
2596 6 tomtor
                    numDistance <= (1 + MYHDL35_get4(5, 5));
2597 2 tomtor
                    $write("ND:");
2598
                    $write(" ");
2599 6 tomtor
                    $write("%0d", (1 + MYHDL36_get4(5, 5)));
2600 2 tomtor
                    $write("\n");
2601 6 tomtor
                    b_numCodeLength <= (4 + MYHDL37_get4(10, 4));
2602 2 tomtor
                    $write("NCL:");
2603
                    $write(" ");
2604 6 tomtor
                    $write("%0d", (4 + MYHDL38_get4(10, 4)));
2605 2 tomtor
                    $write("\n");
2606
                    numCodeLength <= 0;
2607 6 tomtor
                    MYHDL39_adv(14);
2608 2 tomtor
                end
2609
                else begin
2610
                    if ((numCodeLength < 19)) begin
2611
                        case (numCodeLength)
2612
                            0: clo_i = 16;
2613
                            1: clo_i = 17;
2614
                            2: clo_i = 18;
2615
                            3: clo_i = 0;
2616
                            4: clo_i = 8;
2617
                            5: clo_i = 7;
2618
                            6: clo_i = 9;
2619
                            7: clo_i = 6;
2620
                            8: clo_i = 10;
2621
                            9: clo_i = 5;
2622
                            10: clo_i = 11;
2623
                            11: clo_i = 4;
2624
                            12: clo_i = 12;
2625
                            13: clo_i = 3;
2626
                            14: clo_i = 13;
2627
                            15: clo_i = 2;
2628
                            16: clo_i = 14;
2629
                            17: clo_i = 1;
2630
                            default: clo_i = 15;
2631
                        endcase
2632
                        if ((numCodeLength < b_numCodeLength)) begin
2633 6 tomtor
                            codeLength[clo_i] <= MYHDL40_get4(0, 3);
2634
                            MYHDL41_adv(3);
2635 2 tomtor
                        end
2636
                        else begin
2637
                            codeLength[clo_i] <= 0;
2638
                        end
2639
                        numCodeLength <= (numCodeLength + 1);
2640
                    end
2641
                    else begin
2642
                        numCodeLength <= 19;
2643
                        cur_HF1 <= 0;
2644
                        state <= 5'b00111;
2645
                    end
2646
                end
2647
            end
2648
            5'b00011: begin
2649 6 tomtor
                if (((!1'b1) || (!1'b0))) begin
2650
                    // pass
2651
                end
2652
                else if ((!filled)) begin
2653 2 tomtor
                    filled <= 1'b1;
2654
                end
2655
                else if ((nb < 4)) begin
2656
                    // pass
2657
                end
2658
                else if ((numCodeLength < (numLiterals + numDistance))) begin
2659
                    n_adv = 0;
2660
                    if ((code < 16)) begin
2661
                        howOften <= 1;
2662
                        lastToken <= code;
2663
                    end
2664
                    else if ((code == 16)) begin
2665 6 tomtor
                        howOften <= (3 + MYHDL42_get4(0, 2));
2666 2 tomtor
                        n_adv = 2;
2667
                    end
2668
                    else if ((code == 17)) begin
2669 6 tomtor
                        howOften <= (3 + MYHDL43_get4(0, 3));
2670 2 tomtor
                        lastToken <= 0;
2671
                        n_adv = 3;
2672
                    end
2673
                    else if ((code == 18)) begin
2674 6 tomtor
                        howOften <= (11 + MYHDL44_get4(0, 7));
2675 2 tomtor
                        lastToken <= 0;
2676
                        n_adv = 7;
2677
                    end
2678
                    else begin
2679
                        $finish;
2680
                    end
2681
                    if ((n_adv != 0)) begin
2682 6 tomtor
                        MYHDL45_adv(n_adv);
2683 2 tomtor
                    end
2684
                    state <= 5'b00100;
2685
                end
2686
                else begin
2687
                    $write("FILL UP");
2688
                    $write("\n");
2689
                    for (dbl_i=0; dbl_i<32; dbl_i=dbl_i+1) begin
2690
                        dbl = 0;
2691
                        if (((dbl_i + $signed({1'b0, numLiterals})) < numCodeLength)) begin
2692
                            dbl = codeLength[(dbl_i + $signed({1'b0, numLiterals}))];
2693
                        end
2694
                        distanceLength[dbl_i] <= dbl;
2695
                    end
2696
                    cur_i <= numLiterals;
2697
                    state <= 5'b00110;
2698
                end
2699
            end
2700 6 tomtor
            5'b00110: begin
2701
                if ((!1'b1)) begin
2702
                    // pass
2703
                end
2704
                else if ((cur_i < 320)) begin
2705
                    codeLength[cur_i] <= 0;
2706
                    cur_i <= (cur_i + 1);
2707
                end
2708
                else begin
2709
                    method <= 3;
2710
                    cur_HF1 <= 0;
2711
                    state <= 5'b00111;
2712
                end
2713
            end
2714
            5'b00101: begin
2715
                if ((1'b1 && 1'b0)) begin
2716
                    $write("DISTTREE");
2717
                    $write("\n");
2718
                    for (dist_i=0; dist_i<32; dist_i=dist_i+1) begin
2719
                        codeLength[dist_i] <= distanceLength[dist_i];
2720 2 tomtor
                    end
2721 6 tomtor
                    numCodeLength <= 32;
2722
                    method <= 4;
2723
                    cur_HF1 <= 0;
2724
                    state <= 5'b00111;
2725
                end
2726
            end
2727
            5'b00100: begin
2728
                if ((!1'b1)) begin
2729
                    // pass
2730
                end
2731
                else if ((howOften != 0)) begin
2732
                    codeLength[numCodeLength] <= lastToken;
2733
                    howOften <= (howOften - 1);
2734
                    numCodeLength <= (numCodeLength + 1);
2735
                end
2736
                else if ((numCodeLength < (numLiterals + numDistance))) begin
2737
                    cur_next <= 0;
2738
                    state <= 5'b10011;
2739
                end
2740
                else begin
2741
                    state <= 5'b00011;
2742
                end
2743
            end
2744
            5'b00111: begin
2745
                if (1'b1) begin
2746
                    if ((cur_HF1 < 16)) begin
2747
                        bitLengthCount[cur_HF1] <= 0;
2748
                    end
2749
                    if (((cur_HF1 < 1) && 1'b0)) begin
2750
                        d_leaves[cur_HF1] <= 0;
2751
                    end
2752
                    if (((method != 4) && (cur_HF1 < 512))) begin
2753
                        lwaddr <= cur_HF1;
2754
                        wleaf <= 0;
2755
                    end
2756
                    limit = 512;
2757
                    if (((method == 4) && 1'b0)) begin
2758
                        limit = 1;
2759
                    end
2760
                    if ((cur_HF1 < limit)) begin
2761
                        cur_HF1 <= (cur_HF1 + 1);
2762
                    end
2763 2 tomtor
                    else begin
2764 6 tomtor
                        $write("DID HF1 INIT");
2765
                        $write("\n");
2766
                        cur_i <= 0;
2767
                        state <= 5'b01000;
2768 2 tomtor
                    end
2769
                end
2770 6 tomtor
            end
2771
            5'b01000: begin
2772
                if ((!1'b1)) begin
2773
                    // pass
2774
                end
2775
                else if ((cur_i < numCodeLength)) begin
2776
                    j = codeLength[cur_i];
2777
                    bitLengthCount[j] <= (bitLengthCount[j] + 1);
2778
                    cur_i <= (cur_i + 1);
2779
                end
2780 2 tomtor
                else begin
2781 6 tomtor
                    bitLengthCount[0] <= 0;
2782
                    state <= 5'b01001;
2783
                    cur_i <= 1;
2784
                    if ((method == 4)) begin
2785
                        d_maxBits <= 0;
2786
                    end
2787
                    else begin
2788
                        maxBits <= 0;
2789
                    end
2790
                    minBits <= 15;
2791
                end
2792
            end
2793
            5'b01001: begin
2794
                if ((!1'b1)) begin
2795
                    // pass
2796
                end
2797
                else if ((cur_i <= 15)) begin
2798
                    if ((bitLengthCount[cur_i] != 0)) begin
2799
                        if ((cur_i < minBits)) begin
2800
                            minBits <= cur_i;
2801 2 tomtor
                        end
2802 6 tomtor
                        if ((method == 4)) begin
2803
                            if ((cur_i > d_maxBits)) begin
2804
                                d_maxBits <= cur_i;
2805 2 tomtor
                            end
2806
                        end
2807 6 tomtor
                        else begin
2808
                            if ((cur_i > maxBits)) begin
2809
                                maxBits <= cur_i;
2810 2 tomtor
                            end
2811
                        end
2812 6 tomtor
                    end
2813
                    cur_i <= (cur_i + 1);
2814
                end
2815
                else begin
2816
                    $write("%h", minBits);
2817
                    $write(" ");
2818
                    $write("%h", maxBits);
2819
                    $write("\n");
2820
                    t = 10;
2821
                    if (((method == 4) && 1'b0)) begin
2822
                        if ((t > d_maxBits)) begin
2823
                            t = d_maxBits;
2824 2 tomtor
                        end
2825 6 tomtor
                        d_instantMaxBit <= t;
2826
                        d_instantMask <= ((1 << t) - 1);
2827
                    end
2828
                    else begin
2829
                        if ((t > maxBits)) begin
2830
                            t = maxBits;
2831 2 tomtor
                        end
2832 6 tomtor
                        instantMaxBit <= t;
2833
                        instantMask <= ((1 << t) - 1);
2834
                    end
2835
                    $write("%0d", ((1 << t) - 1));
2836
                    $write("\n");
2837
                    state <= 5'b01010;
2838
                    cur_i <= minBits;
2839
                    code <= 0;
2840
                    for (hf2_i=0; hf2_i<16; hf2_i=hf2_i+1) begin
2841
                        nextCode[hf2_i] <= 0;
2842
                    end
2843
                    $write("to HF3");
2844
                    $write("\n");
2845
                end
2846
            end
2847
            5'b01010: begin
2848
                if (1'b1) begin
2849
                    amb = maxBits;
2850
                    if (((method == 4) && 1'b0)) begin
2851
                        amb = d_maxBits;
2852
                    end
2853
                    if ((cur_i <= amb)) begin
2854
                        ncode = ((code + bitLengthCount[($signed({1'b0, cur_i}) - 1)]) << 1);
2855
                        code <= ncode;
2856
                        nextCode[cur_i] <= ncode;
2857
                        cur_i <= (cur_i + 1);
2858
                    end
2859
                    else begin
2860
                        state <= 5'b01011;
2861
                        cur_i <= 0;
2862
                        spread_i <= 0;
2863
                        $write("to HF4");
2864
                        $write("\n");
2865
                    end
2866
                end
2867
            end
2868
            5'b01100: begin
2869
                if (1'b1) begin
2870
                    canonical = nextCode[bits];
2871
                    nextCode[bits] <= (nextCode[bits] + 1);
2872
                    if ((bits > 15)) begin
2873
                        $finish;
2874
                    end
2875
                    reverse <= MYHDL52_rev_bits(canonical, bits);
2876
                    leaf <= MYHDL53_makeLeaf(spread_i, bits);
2877
                    state <= 5'b01101;
2878
                end
2879
            end
2880
            5'b01101: begin
2881
                if ((!1'b1)) begin
2882
                    // pass
2883
                end
2884
                else if (((method == 4) && 1'b0)) begin
2885
                    d_leaves[reverse] <= leaf;
2886
                    if ((bits <= d_instantMaxBit)) begin
2887
                        if (((reverse + (1 << bits)) <= d_instantMask)) begin
2888
                            step <= (1 << bits);
2889
                            spread <= (reverse + (1 << bits));
2890
                            state <= 5'b10010;
2891 2 tomtor
                        end
2892 6 tomtor
                        else begin
2893
                            spread_i <= (spread_i + 1);
2894
                            state <= 5'b01011;
2895 2 tomtor
                        end
2896 6 tomtor
                    end
2897
                    else begin
2898
                        state <= 5'b01011;
2899
                        spread_i <= (spread_i + 1);
2900
                    end
2901
                end
2902
                else begin
2903
                    wleaf <= leaf;
2904
                    lwaddr <= reverse;
2905
                    if ((bits <= instantMaxBit)) begin
2906
                        if (((reverse + (1 << bits)) <= instantMask)) begin
2907
                            step <= (1 << bits);
2908
                            spread <= (reverse + (1 << bits));
2909
                            state <= 5'b10010;
2910 2 tomtor
                        end
2911 6 tomtor
                        else begin
2912
                            spread_i <= (spread_i + 1);
2913
                            state <= 5'b01011;
2914 2 tomtor
                        end
2915 6 tomtor
                    end
2916
                    else begin
2917
                        spread_i <= (spread_i + 1);
2918
                        state <= 5'b01011;
2919
                    end
2920
                end
2921
            end
2922
            5'b01011: begin
2923
                if ((!1'b1)) begin
2924
                    // pass
2925
                end
2926
                else if ((spread_i < numCodeLength)) begin
2927
                    bits_next = codeLength[spread_i];
2928
                    if ((bits_next != 0)) begin
2929
                        bits <= bits_next;
2930
                        state <= 5'b01100;
2931
                    end
2932
                    else begin
2933
                        spread_i <= (spread_i + 1);
2934
                    end
2935
                end
2936
                else begin
2937
                    if (do_compress) begin
2938
                        state <= 5'b10110;
2939
                        cur_cstatic <= 0;
2940
                    end
2941
                    else if (((method == 3) && 1'b0)) begin
2942
                        state <= 5'b00101;
2943
                    end
2944
                    else if (((method == 4) && 1'b0)) begin
2945
                        $write("DEFLATE m2!");
2946
                        $write("\n");
2947
                        state <= 5'b10011;
2948
                    end
2949
                    else if (((method == 2) && 1'b0)) begin
2950
                        numCodeLength <= 0;
2951
                        state <= 5'b10011;
2952
                    end
2953
                    else begin
2954
                        state <= 5'b10011;
2955
                    end
2956
                    cur_next <= 0;
2957
                    cur_i <= 0;
2958
                end
2959
            end
2960
            5'b10010: begin
2961
                if (1'b1) begin
2962
                    if (((method == 4) && 1'b0)) begin
2963
                        d_leaves[spread] <= MYHDL54_makeLeaf(spread_i, codeLength[spread_i]);
2964
                    end
2965
                    else begin
2966
                        lwaddr <= spread;
2967
                        wleaf <= MYHDL55_makeLeaf(spread_i, codeLength[spread_i]);
2968
                    end
2969
                    aim = instantMask;
2970
                    if (((method == 4) && 1'b0)) begin
2971
                        aim = d_instantMask;
2972
                    end
2973
                    if (($signed({1'b0, spread}) > ($signed({1'b0, aim}) - $signed({1'b0, step})))) begin
2974
                        spread_i <= (spread_i + 1);
2975
                        state <= 5'b01011;
2976
                    end
2977
                    else begin
2978
                        spread <= (spread + step);
2979
                    end
2980
                end
2981
            end
2982
            5'b10011: begin
2983
                if ((!1'b1)) begin
2984
                    // pass
2985
                end
2986
                else if ((!filled)) begin
2987
                    filled <= 1'b1;
2988
                end
2989
                else if ((nb < 4)) begin
2990
                    // pass
2991
                end
2992
                else if ((cur_next == 0)) begin
2993
                    cto = MYHDL56_get4(0, maxBits);
2994
                    mask = ((1 << instantMaxBit) - 1);
2995
                    lraddr <= (cto & mask);
2996
                    filled <= 1'b0;
2997
                    cur_next <= (instantMaxBit + 1);
2998
                end
2999
                else if ((MYHDL57_get_bits(rleaf) >= cur_next)) begin
3000
                    $write("CACHE MISS");
3001
                    $write(" ");
3002
                    $write("%h", cur_next);
3003
                    $write("\n");
3004
                    cto = MYHDL58_get4(0, maxBits);
3005
                    mask = ((1 << cur_next) - 1);
3006
                    lraddr <= (cto & mask);
3007
                    filled <= 1'b0;
3008
                    cur_next <= (cur_next + 1);
3009
                end
3010
                else begin
3011
                    if ((MYHDL59_get_bits(rleaf) < 1)) begin
3012
                        $write("< 1 bits: ");
3013
                        $write("\n");
3014
                        $finish;
3015
                    end
3016
                    MYHDL61_adv(MYHDL60_get_bits(rleaf));
3017
                    // if get_code(leaf) == 0:
3018
                    //     print("leaf 0", di, isize)
3019
                    code <= MYHDL62_get_code(rleaf);
3020
                    if (((method == 2) && 1'b0)) begin
3021
                        state <= 5'b00011;
3022
                    end
3023
                    else begin
3024
                        state <= 5'b10100;
3025
                    end
3026
                end
3027
            end
3028
            5'b01111: begin
3029
                if (((!1'b1) || (!1'b0))) begin
3030
                    // pass
3031
                end
3032
                else if ((!filled)) begin
3033
                    filled <= 1'b1;
3034
                end
3035
                else if ((nb < 4)) begin
3036
                    // pass
3037
                end
3038
                else if ((cur_next == 0)) begin
3039
                    if ((d_instantMaxBit > 10)) begin
3040
                        $finish;
3041
                    end
3042
                    token = (code - 257);
3043
                    case (token)
3044
                        0: extraLength = 0;
3045
                        1: extraLength = 0;
3046
                        2: extraLength = 0;
3047
                        3: extraLength = 0;
3048
                        4: extraLength = 0;
3049
                        5: extraLength = 0;
3050
                        6: extraLength = 0;
3051
                        7: extraLength = 0;
3052
                        8: extraLength = 1;
3053
                        9: extraLength = 1;
3054
                        10: extraLength = 1;
3055
                        11: extraLength = 1;
3056
                        12: extraLength = 2;
3057
                        13: extraLength = 2;
3058
                        14: extraLength = 2;
3059
                        15: extraLength = 2;
3060
                        16: extraLength = 3;
3061
                        17: extraLength = 3;
3062
                        18: extraLength = 3;
3063
                        19: extraLength = 3;
3064
                        20: extraLength = 4;
3065
                        21: extraLength = 4;
3066
                        22: extraLength = 4;
3067
                        23: extraLength = 4;
3068
                        24: extraLength = 5;
3069
                        25: extraLength = 5;
3070
                        26: extraLength = 5;
3071
                        27: extraLength = 5;
3072
                        default: extraLength = 0;
3073
                    endcase
3074
                    cto = MYHDL63_get4(extraLength, d_maxBits);
3075
                    mask = ((1 << d_instantMaxBit) - 1);
3076
                    leaf <= d_leaves[(cto & mask)];
3077
                    cur_next <= (instantMaxBit + 1);
3078
                end
3079
                else if ((MYHDL64_get_bits(leaf) >= cur_next)) begin
3080
                    $write("DCACHE MISS");
3081
                    $write(" ");
3082
                    $write("%h", cur_next);
3083
                    $write("\n");
3084
                    token = (code - 257);
3085
                    case (token)
3086
                        0: extraLength = 0;
3087
                        1: extraLength = 0;
3088
                        2: extraLength = 0;
3089
                        3: extraLength = 0;
3090
                        4: extraLength = 0;
3091
                        5: extraLength = 0;
3092
                        6: extraLength = 0;
3093
                        7: extraLength = 0;
3094
                        8: extraLength = 1;
3095
                        9: extraLength = 1;
3096
                        10: extraLength = 1;
3097
                        11: extraLength = 1;
3098
                        12: extraLength = 2;
3099
                        13: extraLength = 2;
3100
                        14: extraLength = 2;
3101
                        15: extraLength = 2;
3102
                        16: extraLength = 3;
3103
                        17: extraLength = 3;
3104
                        18: extraLength = 3;
3105
                        19: extraLength = 3;
3106
                        20: extraLength = 4;
3107
                        21: extraLength = 4;
3108
                        22: extraLength = 4;
3109
                        23: extraLength = 4;
3110
                        24: extraLength = 5;
3111
                        25: extraLength = 5;
3112
                        26: extraLength = 5;
3113
                        27: extraLength = 5;
3114
                        default: extraLength = 0;
3115
                    endcase
3116
                    cto = MYHDL65_get4(extraLength, d_maxBits);
3117
                    mask = ((1 << cur_next) - 1);
3118
                    leaf <= d_leaves[(cto & mask)];
3119
                    cur_next <= (cur_next + 1);
3120
                end
3121
                else begin
3122
                    state <= 5'b10000;
3123
                end
3124
            end
3125
            5'b10000: begin
3126
                if ((1'b1 && 1'b0)) begin
3127
                    if ((MYHDL66_get_bits(leaf) == 0)) begin
3128
                        $finish;
3129
                    end
3130
                    token = (code - 257);
3131
                    case (token)
3132
                        0: tlength = 3;
3133
                        1: tlength = 4;
3134
                        2: tlength = 5;
3135
                        3: tlength = 6;
3136
                        4: tlength = 7;
3137
                        5: tlength = 8;
3138
                        6: tlength = 9;
3139
                        7: tlength = 10;
3140
                        8: tlength = 11;
3141
                        9: tlength = 13;
3142
                        10: tlength = 15;
3143
                        11: tlength = 17;
3144
                        12: tlength = 19;
3145
                        13: tlength = 23;
3146
                        14: tlength = 27;
3147
                        15: tlength = 31;
3148
                        16: tlength = 35;
3149
                        17: tlength = 43;
3150
                        18: tlength = 51;
3151
                        19: tlength = 59;
3152
                        20: tlength = 67;
3153
                        21: tlength = 83;
3154
                        22: tlength = 99;
3155
                        23: tlength = 115;
3156
                        24: tlength = 131;
3157
                        25: tlength = 163;
3158
                        26: tlength = 195;
3159
                        27: tlength = 227;
3160
                        default: tlength = 258;
3161
                    endcase
3162
                    case (token)
3163
                        0: extraLength = 0;
3164
                        1: extraLength = 0;
3165
                        2: extraLength = 0;
3166
                        3: extraLength = 0;
3167
                        4: extraLength = 0;
3168
                        5: extraLength = 0;
3169
                        6: extraLength = 0;
3170
                        7: extraLength = 0;
3171
                        8: extraLength = 1;
3172
                        9: extraLength = 1;
3173
                        10: extraLength = 1;
3174
                        11: extraLength = 1;
3175
                        12: extraLength = 2;
3176
                        13: extraLength = 2;
3177
                        14: extraLength = 2;
3178
                        15: extraLength = 2;
3179
                        16: extraLength = 3;
3180
                        17: extraLength = 3;
3181
                        18: extraLength = 3;
3182
                        19: extraLength = 3;
3183
                        20: extraLength = 4;
3184
                        21: extraLength = 4;
3185
                        22: extraLength = 4;
3186
                        23: extraLength = 4;
3187
                        24: extraLength = 5;
3188
                        25: extraLength = 5;
3189
                        26: extraLength = 5;
3190
                        27: extraLength = 5;
3191
                        default: extraLength = 0;
3192
                    endcase
3193
                    tlength = tlength + MYHDL67_get4(0, extraLength);
3194
                    distanceCode = MYHDL68_get_code(leaf);
3195
                    case (distanceCode)
3196
                        0: distance = 1;
3197
                        1: distance = 2;
3198
                        2: distance = 3;
3199
                        3: distance = 4;
3200
                        4: distance = 5;
3201
                        5: distance = 7;
3202
                        6: distance = 9;
3203
                        7: distance = 13;
3204
                        8: distance = 17;
3205
                        9: distance = 25;
3206
                        10: distance = 33;
3207
                        11: distance = 49;
3208
                        12: distance = 65;
3209
                        13: distance = 97;
3210
                        14: distance = 129;
3211
                        15: distance = 193;
3212
                        16: distance = 257;
3213
                        17: distance = 385;
3214
                        18: distance = 513;
3215
                        19: distance = 769;
3216
                        20: distance = 1025;
3217
                        21: distance = 1537;
3218
                        22: distance = 2049;
3219
                        23: distance = 3073;
3220
                        24: distance = 4097;
3221
                        25: distance = 6145;
3222
                        26: distance = 8193;
3223
                        27: distance = 12289;
3224
                        28: distance = 16385;
3225
                        default: distance = 24577;
3226
                    endcase
3227
                    case ($signed(distanceCode >>> 1))
3228
                        0: moreBits = 0;
3229
                        1: moreBits = 0;
3230
                        2: moreBits = 1;
3231
                        3: moreBits = 2;
3232
                        4: moreBits = 3;
3233
                        5: moreBits = 4;
3234
                        6: moreBits = 5;
3235
                        7: moreBits = 6;
3236
                        8: moreBits = 7;
3237
                        9: moreBits = 8;
3238
                        10: moreBits = 9;
3239
                        11: moreBits = 10;
3240
                        12: moreBits = 11;
3241
                        13: moreBits = 12;
3242
                        default: moreBits = 13;
3243
                    endcase
3244
                    mored = MYHDL70_get4((extraLength + MYHDL69_get_bits(leaf)), moreBits);
3245
                    distance = distance + mored;
3246
                    if ((distance > $signed({1'b0, do}))) begin
3247
                        $write("%0d", distance);
3248
                        $write(" ");
3249
                        $write("%h", do);
3250
                        $write("\n");
3251
                        $finish;
3252
                    end
3253
                    MYHDL72_adv(((moreBits + extraLength) + MYHDL71_get_bits(leaf)));
3254
                    offset <= (($signed({1'b0, do}) - distance) & 32767);
3255
                    length <= tlength;
3256
                    cur_i <= 0;
3257
                    oraddr <= ($signed({1'b0, do}) - distance);
3258
                    state <= 5'b10101;
3259
                end
3260
            end
3261
            5'b10100: begin
3262
                if ((!1'b1)) begin
3263
                    // pass
3264
                end
3265
                else if ((!filled)) begin
3266
                    filled <= 1'b1;
3267
                end
3268
                else if ((nb < 4)) begin
3269
                    // pass
3270
                end
3271
                else if ((($signed({1'b0, di}) >= ($signed({1'b0, isize}) - 4)) && (!(i_mode == 0)))) begin
3272
                    // pass
3273
                end
3274
                else if ((do >= (i_raddr + 32768))) begin
3275
                    // pass
3276
                end
3277
                else if (($signed({1'b0, di}) > ($signed({1'b0, isize}) - 3))) begin
3278
                    state <= 5'b00000;
3279
                    o_done <= 1'b1;
3280
                    $write("NO EOF ");
3281
                    $write(" ");
3282
                    $write("%h", di);
3283
                    $write("\n");
3284
                    $finish;
3285
                end
3286
                else if ((code == 256)) begin
3287
                    $write("EOF:");
3288
                    $write(" ");
3289
                    $write("%h", di);
3290
                    $write(" ");
3291
                    $write("%h", do);
3292
                    $write("\n");
3293
                    if ((!final)) begin
3294
                        state <= 5'b00001;
3295
                        filled <= 1'b0;
3296
                        $write("New Block!");
3297
                        $write("\n");
3298
                    end
3299
                    else begin
3300
                        o_done <= 1'b1;
3301
                        state <= 5'b00000;
3302
                    end
3303
                end
3304
                else begin
3305
                    if ((code < 256)) begin
3306
                        oaddr <= do;
3307
                        obyte <= code;
3308
                        o_oprogress <= (do + 1);
3309
                        do <= (do + 1);
3310
                        cur_next <= 0;
3311
                        state <= 5'b10011;
3312
                    end
3313
                    else if ((code == 300)) begin
3314
                        $finish;
3315
                    end
3316
                    else begin
3317
                        if (static) begin
3318 2 tomtor
                            token = (code - 257);
3319
                            case (token)
3320
                                0: tlength = 3;
3321
                                1: tlength = 4;
3322
                                2: tlength = 5;
3323
                                3: tlength = 6;
3324
                                4: tlength = 7;
3325
                                5: tlength = 8;
3326
                                6: tlength = 9;
3327
                                7: tlength = 10;
3328
                                8: tlength = 11;
3329
                                9: tlength = 13;
3330
                                10: tlength = 15;
3331
                                11: tlength = 17;
3332
                                12: tlength = 19;
3333
                                13: tlength = 23;
3334
                                14: tlength = 27;
3335
                                15: tlength = 31;
3336
                                16: tlength = 35;
3337
                                17: tlength = 43;
3338
                                18: tlength = 51;
3339
                                19: tlength = 59;
3340
                                20: tlength = 67;
3341
                                21: tlength = 83;
3342
                                22: tlength = 99;
3343
                                23: tlength = 115;
3344
                                24: tlength = 131;
3345
                                25: tlength = 163;
3346
                                26: tlength = 195;
3347
                                27: tlength = 227;
3348
                                default: tlength = 258;
3349
                            endcase
3350
                            case (token)
3351
                                0: extraLength = 0;
3352
                                1: extraLength = 0;
3353
                                2: extraLength = 0;
3354
                                3: extraLength = 0;
3355
                                4: extraLength = 0;
3356
                                5: extraLength = 0;
3357
                                6: extraLength = 0;
3358
                                7: extraLength = 0;
3359
                                8: extraLength = 1;
3360
                                9: extraLength = 1;
3361
                                10: extraLength = 1;
3362
                                11: extraLength = 1;
3363
                                12: extraLength = 2;
3364
                                13: extraLength = 2;
3365
                                14: extraLength = 2;
3366
                                15: extraLength = 2;
3367
                                16: extraLength = 3;
3368
                                17: extraLength = 3;
3369
                                18: extraLength = 3;
3370
                                19: extraLength = 3;
3371
                                20: extraLength = 4;
3372
                                21: extraLength = 4;
3373
                                22: extraLength = 4;
3374
                                23: extraLength = 4;
3375
                                24: extraLength = 5;
3376
                                25: extraLength = 5;
3377
                                26: extraLength = 5;
3378
                                27: extraLength = 5;
3379
                                default: extraLength = 0;
3380
                            endcase
3381 6 tomtor
                            tlength = tlength + MYHDL73_get4(0, extraLength);
3382
                            t = MYHDL74_get4(extraLength, 5);
3383
                            distanceCode = MYHDL75_rev_bits(t, 5);
3384 2 tomtor
                            case (distanceCode)
3385
                                0: distance = 1;
3386
                                1: distance = 2;
3387
                                2: distance = 3;
3388
                                3: distance = 4;
3389
                                4: distance = 5;
3390
                                5: distance = 7;
3391
                                6: distance = 9;
3392
                                7: distance = 13;
3393
                                8: distance = 17;
3394
                                9: distance = 25;
3395
                                10: distance = 33;
3396
                                11: distance = 49;
3397
                                12: distance = 65;
3398
                                13: distance = 97;
3399
                                14: distance = 129;
3400
                                15: distance = 193;
3401
                                16: distance = 257;
3402
                                17: distance = 385;
3403
                                18: distance = 513;
3404
                                19: distance = 769;
3405
                                20: distance = 1025;
3406
                                21: distance = 1537;
3407
                                22: distance = 2049;
3408
                                23: distance = 3073;
3409
                                24: distance = 4097;
3410
                                25: distance = 6145;
3411
                                26: distance = 8193;
3412
                                27: distance = 12289;
3413
                                28: distance = 16385;
3414
                                default: distance = 24577;
3415
                            endcase
3416
                            case ($signed(distanceCode >>> 1))
3417
                                0: moreBits = 0;
3418
                                1: moreBits = 0;
3419
                                2: moreBits = 1;
3420
                                3: moreBits = 2;
3421
                                4: moreBits = 3;
3422
                                5: moreBits = 4;
3423
                                6: moreBits = 5;
3424
                                7: moreBits = 6;
3425
                                8: moreBits = 7;
3426
                                9: moreBits = 8;
3427
                                10: moreBits = 9;
3428
                                11: moreBits = 10;
3429
                                12: moreBits = 11;
3430
                                13: moreBits = 12;
3431
                                default: moreBits = 13;
3432
                            endcase
3433 6 tomtor
                            distance = distance + MYHDL76_get4((extraLength + 5), moreBits);
3434
                            MYHDL77_adv(((extraLength + 5) + moreBits));
3435 2 tomtor
                            offset <= ($signed({1'b0, do}) - distance);
3436
                            length <= tlength;
3437
                            cur_i <= 0;
3438 5 tomtor
                            oraddr <= ($signed({1'b0, do}) - distance);
3439 2 tomtor
                            state <= 5'b10101;
3440
                        end
3441 6 tomtor
                        else begin
3442
                            if ((!1'b0)) begin
3443
                                $write("DYNAMIC mode disabled");
3444
                                $write("\n");
3445
                                $finish;
3446 2 tomtor
                            end
3447 6 tomtor
                            state <= 5'b01111;
3448
                        end
3449
                    end
3450
                    cur_next <= 0;
3451
                end
3452
            end
3453
            5'b10101: begin
3454
                if ((!1'b1)) begin
3455
                    // pass
3456
                end
3457
                else if ((!filled)) begin
3458
                    filled <= 1'b1;
3459
                end
3460
                else if ((nb < 4)) begin
3461
                    // pass
3462
                end
3463
                else if (((cur_i == 0) && ((do + length) >= (i_raddr + 32768)))) begin
3464
                    // pass
3465
                end
3466
                else if (($signed({1'b0, di}) >= ($signed({1'b0, isize}) - 2))) begin
3467
                    // pass
3468
                end
3469
                else if ((method == 0)) begin
3470
                    if ((cur_i < length)) begin
3471
                        oaddr <= do;
3472
                        obyte <= b3;
3473
                        MYHDL78_adv(8);
3474
                        cur_i <= (cur_i + 1);
3475
                        do <= (do + 1);
3476
                        o_oprogress <= (do + 1);
3477
                    end
3478
                    else if ((!final)) begin
3479
                        MYHDL79_adv(16);
3480
                        state <= 5'b00001;
3481
                        filled <= 1'b0;
3482
                        $write("new block");
3483
                        $write("\n");
3484
                    end
3485
                    else begin
3486
                        o_done <= 1'b1;
3487
                        state <= 5'b00000;
3488
                    end
3489
                end
3490
                else if ((cur_i < (length + 2))) begin
3491
                    oraddr <= (offset + cur_i);
3492
                    if ((cur_i == 1)) begin
3493
                        copy1 <= orbyte;
3494
                    end
3495
                    if ((cur_i == 3)) begin
3496
                        copy2 <= orbyte;
3497
                    end
3498
                    if ((cur_i > 1)) begin
3499
                        if ((((offset + cur_i) & 32767) == ((do + 1) & 32767))) begin
3500
                            obyte <= copy1;
3501
                        end
3502
                        else if (((cur_i == 3) || (((offset + cur_i) & 32767) != (do & 32767)))) begin
3503
                            obyte <= orbyte;
3504
                        end
3505
                        else if ((cur_i > 2)) begin
3506
                            if ((cur_i & 1)) begin
3507
                                obyte <= copy2;
3508
                            end
3509 2 tomtor
                            else begin
3510 6 tomtor
                                obyte <= copy1;
3511 2 tomtor
                            end
3512
                        end
3513 6 tomtor
                        else begin
3514
                            obyte <= copy1;
3515
                        end
3516
                        oaddr <= do;
3517
                        o_oprogress <= (do + 1);
3518
                        do <= (do + 1);
3519
                    end
3520
                    cur_i <= (cur_i + 1);
3521 2 tomtor
                end
3522 6 tomtor
                else begin
3523
                    cur_next <= 0;
3524
                    state <= 5'b10011;
3525
                end
3526 2 tomtor
            end
3527 6 tomtor
            default: begin
3528
                $write("unknown state?!");
3529
                $write("\n");
3530
                state <= 5'b00000;
3531
            end
3532 2 tomtor
        endcase
3533
    end
3534
end
3535
 
3536
 
3537
always @(posedge clk) begin: DEFLATE_FILL_BUF
3538 5 tomtor
    integer shift;
3539 2 tomtor
    if ((!reset)) begin
3540
        $write("FILL RESET");
3541
        $write("\n");
3542
        nb <= 0;
3543
        b1 <= 0;
3544
        b2 <= 0;
3545
        b3 <= 0;
3546
        b4 <= 0;
3547 5 tomtor
        old_di <= 0;
3548 2 tomtor
    end
3549
    else begin
3550
        if ((isize < 4)) begin
3551 6 tomtor
            nb <= 0;
3552
            old_di <= 0;
3553 2 tomtor
        end
3554
        else if (((i_mode == 4) || (i_mode == 5))) begin
3555
            nb <= 0;
3556 5 tomtor
            old_di <= 0;
3557 2 tomtor
        end
3558
        else begin
3559 5 tomtor
            // if do_compress:
3560
            //     print("FILL", di, old_di, nb, b1, b2, b3, b4)
3561
            if (1'b1) begin
3562
                shift = (($signed({1'b0, di}) - $signed({1'b0, old_di})) * 8);
3563
                // if shift != 0:
3564
                //     print("shift", shift, cwindow, b1, b2, b3, b4)
3565 6 tomtor
                if (1'b1) begin
3566
                    cwindow <= (($signed({1'b0, cwindow}) << shift) | $signed($signed({1'b0, b110}) >>> (80 - shift)));
3567 5 tomtor
                end
3568 6 tomtor
                else begin
3569
                    cwindow <= (($signed({1'b0, cwindow}) << shift) | $signed($signed({1'b0, b15}) >>> (40 - shift)));
3570 5 tomtor
                end
3571
            end
3572
            if ((old_di == di)) begin
3573
                nb <= 4;
3574
            end
3575
            old_di <= di;
3576 6 tomtor
            b1 <= iram[(di & 63)];
3577
            b2 <= iram[((di + 1) & 63)];
3578
            b3 <= iram[((di + 2) & 63)];
3579
            b4 <= iram[((di + 3) & 63)];
3580
            b5 <= iram[((di + 4) & 63)];
3581 5 tomtor
            if (1'b1) begin
3582 6 tomtor
                b6 <= iram[((di + 5) & 63)];
3583
                b7 <= iram[((di + 6) & 63)];
3584
                b8 <= iram[((di + 7) & 63)];
3585
                b9 <= iram[((di + 8) & 63)];
3586
                b10 <= iram[((di + 9) & 63)];
3587 5 tomtor
            end
3588 2 tomtor
        end
3589
    end
3590
end
3591
 
3592
 
3593
always @(posedge clk) begin: DEFLATE_ORAMWRITE
3594
    oram[oaddr] <= obyte;
3595
    leaves[lwaddr] <= wleaf;
3596
end
3597
 
3598
 
3599
always @(posedge clk) begin: DEFLATE_ORAMREAD
3600
    orbyte <= oram[oraddr];
3601 6 tomtor
    rleaf <= leaves[lraddr];
3602 2 tomtor
end
3603
 
3604 5 tomtor
 
3605
 
3606
assign smatch[0] = ((({cwindow, b1, b2} >>> (8 * 0)) & 16777215) == (b14 >>> 8));
3607
 
3608
 
3609
 
3610
assign smatch[1] = ((({cwindow, b1, b2} >>> (8 * 1)) & 16777215) == (b14 >>> 8));
3611
 
3612
 
3613
 
3614
assign smatch[2] = ((({cwindow, b1, b2} >>> (8 * 2)) & 16777215) == (b14 >>> 8));
3615
 
3616
 
3617
 
3618
assign smatch[3] = ((({cwindow, b1, b2} >>> (8 * 3)) & 16777215) == (b14 >>> 8));
3619
 
3620
 
3621
 
3622
assign smatch[4] = ((({cwindow, b1, b2} >>> (8 * 4)) & 16777215) == (b14 >>> 8));
3623
 
3624
 
3625
 
3626
assign smatch[5] = ((({cwindow, b1, b2} >>> (8 * 5)) & 16777215) == (b14 >>> 8));
3627
 
3628
 
3629
 
3630
assign smatch[6] = ((({cwindow, b1, b2} >>> (8 * 6)) & 16777215) == (b14 >>> 8));
3631
 
3632
 
3633
 
3634
assign smatch[7] = ((({cwindow, b1, b2} >>> (8 * 7)) & 16777215) == (b14 >>> 8));
3635
 
3636
 
3637
 
3638
assign smatch[8] = ((({cwindow, b1, b2} >>> (8 * 8)) & 16777215) == (b14 >>> 8));
3639
 
3640
 
3641
 
3642
assign smatch[9] = ((({cwindow, b1, b2} >>> (8 * 9)) & 16777215) == (b14 >>> 8));
3643
 
3644
 
3645
 
3646
assign smatch[10] = ((({cwindow, b1, b2} >>> (8 * 10)) & 16777215) == (b14 >>> 8));
3647
 
3648
 
3649
 
3650
assign smatch[11] = ((({cwindow, b1, b2} >>> (8 * 11)) & 16777215) == (b14 >>> 8));
3651
 
3652
 
3653
 
3654
assign smatch[12] = ((({cwindow, b1, b2} >>> (8 * 12)) & 16777215) == (b14 >>> 8));
3655
 
3656
 
3657
 
3658
assign smatch[13] = ((({cwindow, b1, b2} >>> (8 * 13)) & 16777215) == (b14 >>> 8));
3659
 
3660
 
3661
 
3662
assign smatch[14] = ((({cwindow, b1, b2} >>> (8 * 14)) & 16777215) == (b14 >>> 8));
3663
 
3664
 
3665
 
3666
assign smatch[15] = ((({cwindow, b1, b2} >>> (8 * 15)) & 16777215) == (b14 >>> 8));
3667
 
3668
 
3669
 
3670
assign smatch[16] = ((({cwindow, b1, b2} >>> (8 * 16)) & 16777215) == (b14 >>> 8));
3671
 
3672
 
3673
 
3674
assign smatch[17] = ((({cwindow, b1, b2} >>> (8 * 17)) & 16777215) == (b14 >>> 8));
3675
 
3676
 
3677
 
3678
assign smatch[18] = ((({cwindow, b1, b2} >>> (8 * 18)) & 16777215) == (b14 >>> 8));
3679
 
3680
 
3681
 
3682
assign smatch[19] = ((({cwindow, b1, b2} >>> (8 * 19)) & 16777215) == (b14 >>> 8));
3683
 
3684
 
3685
 
3686
assign smatch[20] = ((({cwindow, b1, b2} >>> (8 * 20)) & 16777215) == (b14 >>> 8));
3687
 
3688
 
3689
 
3690
assign smatch[21] = ((({cwindow, b1, b2} >>> (8 * 21)) & 16777215) == (b14 >>> 8));
3691
 
3692
 
3693
 
3694
assign smatch[22] = ((({cwindow, b1, b2} >>> (8 * 22)) & 16777215) == (b14 >>> 8));
3695
 
3696
 
3697
 
3698
assign smatch[23] = ((({cwindow, b1, b2} >>> (8 * 23)) & 16777215) == (b14 >>> 8));
3699
 
3700
 
3701
 
3702
assign smatch[24] = ((({cwindow, b1, b2} >>> (8 * 24)) & 16777215) == (b14 >>> 8));
3703
 
3704
 
3705
 
3706
assign smatch[25] = ((({cwindow, b1, b2} >>> (8 * 25)) & 16777215) == (b14 >>> 8));
3707
 
3708
 
3709
 
3710
assign smatch[26] = ((({cwindow, b1, b2} >>> (8 * 26)) & 16777215) == (b14 >>> 8));
3711
 
3712
 
3713
 
3714
assign smatch[27] = ((({cwindow, b1, b2} >>> (8 * 27)) & 16777215) == (b14 >>> 8));
3715
 
3716
 
3717
 
3718
assign smatch[28] = ((({cwindow, b1, b2} >>> (8 * 28)) & 16777215) == (b14 >>> 8));
3719
 
3720
 
3721
 
3722
assign smatch[29] = ((({cwindow, b1, b2} >>> (8 * 29)) & 16777215) == (b14 >>> 8));
3723
 
3724
 
3725
 
3726
assign smatch[30] = ((({cwindow, b1, b2} >>> (8 * 30)) & 16777215) == (b14 >>> 8));
3727
 
3728
 
3729
 
3730
assign smatch[31] = ((({cwindow, b1, b2} >>> (8 * 31)) & 16777215) == (b14 >>> 8));
3731
 
3732 2 tomtor
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.