Subversion Repositories Kolibri OS

Rev

Rev 6617 | Rev 6652 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6617 Rev 6639
Line 196... Line 196...
196
	ret
196
	ret
197
endp
197
endp
Line 198... Line 198...
198
 
198
 
199
; =========================================================================
199
; =========================================================================
200
;int (strm, level, version, stream_size)
200
;int (strm, level, version, stream_size)
201
;    z_streamp strm;
201
;    z_streamp strm
202
;    int level;
202
;    int level
203
;    const char *version;
203
;    const char *version
204
;    int stream_size;
204
;    int stream_size
205
align 4
205
align 4
206
proc deflateInit_, strm:dword, level:dword, version:dword, stream_size:dword
206
proc deflateInit_, strm:dword, level:dword, version:dword, stream_size:dword
207
	stdcall deflateInit2_, [strm], [level], Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,\
207
	stdcall deflateInit2_, [strm], [level], Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,\
208
			Z_DEFAULT_STRATEGY, [version], [stream_size]
208
			Z_DEFAULT_STRATEGY, [version], [stream_size]
Line 218... Line 218...
218
endp
218
endp
Line 219... Line 219...
219
 
219
 
220
; =========================================================================
220
; =========================================================================
221
;int (strm, level, method, windowBits, memLevel, strategy,
221
;int (strm, level, method, windowBits, memLevel, strategy,
222
;                  version, stream_size)
222
;                  version, stream_size)
223
;    z_streamp strm;
223
;    z_streamp strm
224
;    int  level;
224
;    int  level
225
;    int  method;
225
;    int  method
226
;    int  windowBits;
226
;    int  windowBits
227
;    int  memLevel;
227
;    int  memLevel
228
;    int  strategy;
228
;    int  strategy
229
;    const char *version;
229
;    const char *version
230
;    int stream_size;
230
;    int stream_size
231
align 4
231
align 4
232
proc deflateInit2_ uses ebx ecx edx edi, strm:dword, level:dword, method:dword,\
232
proc deflateInit2_ uses ebx ecx edx edi, strm:dword, level:dword, method:dword,\
233
	windowBits:dword, memLevel:dword, strategy:dword, version:dword, stream_size:dword
233
	windowBits:dword, memLevel:dword, strategy:dword, version:dword, stream_size:dword
234
locals
234
locals
Line 431... Line 431...
431
	ret
431
	ret
432
endp
432
endp
Line 433... Line 433...
433
 
433
 
434
; =========================================================================
434
; =========================================================================
435
;int (strm, dictionary, dictLength)
435
;int (strm, dictionary, dictLength)
436
;    z_streamp strm;
436
;    z_streamp strm
437
;    const Bytef *dictionary;
437
;    const Bytef *dictionary
438
;    uInt  dictLength;
438
;    uInt  dictLength
439
align 4
439
align 4
440
proc deflateSetDictionary uses ebx edi, strm:dword, dictionary:dword, dictLength:dword
440
proc deflateSetDictionary uses ebx edi, strm:dword, dictionary:dword, dictLength:dword
441
locals
441
locals
442
;    deflate_state *s;
442
;    deflate_state *s;
Line 516... Line 516...
516
	ret
516
	ret
517
endp
517
endp
Line 518... Line 518...
518
 
518
 
519
; =========================================================================
519
; =========================================================================
520
;int (strm)
520
;int (strm)
521
;    z_streamp strm;
521
;    z_streamp strm
522
align 4
522
align 4
523
proc deflateResetKeep uses ebx edi, strm:dword
523
proc deflateResetKeep uses ebx edi, strm:dword
Line 524... Line 524...
524
;    deflate_state *s;
524
;    deflate_state *s;
Line 561... Line 561...
561
	mov dword[edi+deflate_state.status],eax
561
	mov dword[edi+deflate_state.status],eax
562
	stdcall adler32, 0, Z_NULL, 0
562
	stdcall adler32, 0, Z_NULL, 0
563
if GZIP eq 1
563
if GZIP eq 1
564
	cmp dword[edi+deflate_state.wrap],2
564
	cmp dword[edi+deflate_state.wrap],2
565
	jne @f
565
	jne @f
566
		stdcall calc_crc32, 0, Z_NULL, 0
566
		xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
567
	@@:
567
	@@:
568
end if
568
end if
569
	mov dword[ebx+z_stream.adler],eax
569
	mov dword[ebx+z_stream.adler],eax
570
	mov dword[edi+deflate_state.last_flush],Z_NO_FLUSH
570
	mov dword[edi+deflate_state.last_flush],Z_NO_FLUSH
Line 576... Line 576...
576
	ret
576
	ret
577
endp
577
endp
Line 578... Line 578...
578
 
578
 
579
; =========================================================================
579
; =========================================================================
580
;int (strm)
580
;int (strm)
581
;    z_streamp strm;
581
;    z_streamp strm
582
align 4
582
align 4
583
proc deflateReset uses ebx, strm:dword
583
proc deflateReset uses ebx, strm:dword
584
	mov ebx,[strm]
584
	mov ebx,[strm]
585
;zlib_debug 'deflateReset'
585
	zlib_debug 'deflateReset'
586
	stdcall deflateResetKeep, ebx
586
	stdcall deflateResetKeep, ebx
587
	cmp eax,0
587
	cmp eax,0
588
	jne @f ;if (..==Z_OK)
588
	jne @f ;if (..==Z_OK)
589
		stdcall lm_init, [ebx+z_stream.state]
589
		stdcall lm_init, [ebx+z_stream.state]
590
	@@:
590
	@@:
591
	ret
591
	ret
Line 592... Line 592...
592
endp
592
endp
593
 
593
 
594
; =========================================================================
594
; =========================================================================
595
;int (strm, head)
595
;int (strm, head)
596
;    z_streamp strm;
596
;    z_streamp strm
597
;    gz_headerp head;
597
;    gz_headerp head
598
align 4
598
align 4
599
proc deflateSetHeader uses ebx, strm:dword, head:dword
599
proc deflateSetHeader uses ebx, strm:dword, head:dword
600
	mov ebx,[strm]
600
	mov ebx,[strm]
Line 619... Line 619...
619
	ret
619
	ret
620
endp
620
endp
Line 621... Line 621...
621
 
621
 
622
; =========================================================================
622
; =========================================================================
623
;int (strm, pending, bits)
623
;int (strm, pending, bits)
624
;    unsigned *pending;
624
;    unsigned *pending
625
;    int *bits;
625
;    int *bits
626
;    z_streamp strm;
626
;    z_streamp strm
627
align 4
627
align 4
628
proc deflatePending uses ebx edi, strm:dword, pending:dword, bits:dword
628
proc deflatePending uses ebx edi, strm:dword, pending:dword, bits:dword
629
	mov ebx,[strm]
629
	mov ebx,[strm]
630
	cmp ebx,Z_NULL
630
	cmp ebx,Z_NULL
Line 653... Line 653...
653
	ret
653
	ret
654
endp
654
endp
Line 655... Line 655...
655
 
655
 
656
; =========================================================================
656
; =========================================================================
657
;int (strm, bits, value)
657
;int (strm, bits, value)
658
;    z_streamp strm;
658
;    z_streamp strm
659
;    int bits;
659
;    int bits
660
;    int value;
660
;    int value
661
align 4
661
align 4
662
proc deflatePrime uses ebx edi, strm:dword, bits:dword, value:dword
662
proc deflatePrime uses ebx edi, strm:dword, bits:dword, value:dword
Line 663... Line 663...
663
;    int put;
663
;    int put;
Line 689... Line 689...
689
	ret
689
	ret
690
endp
690
endp
Line 691... Line 691...
691
 
691
 
692
; =========================================================================
692
; =========================================================================
693
;int (strm, level, strategy)
693
;int (strm, level, strategy)
694
;    z_streamp strm;
694
;    z_streamp strm
695
;    int level;
695
;    int level
696
;    int strategy;
696
;    int strategy
697
align 4
697
align 4
698
proc deflateParams uses ebx edi, strm:dword, level:dword, strategy:dword
698
proc deflateParams uses ebx edi, strm:dword, level:dword, strategy:dword
699
;    compress_func func;
699
;    compress_func func;
Line 746... Line 746...
746
	ret
746
	ret
747
endp
747
endp
Line 748... Line 748...
748
 
748
 
749
; =========================================================================
749
; =========================================================================
750
;int (strm, good_length, max_lazy, nice_length, max_chain)
750
;int (strm, good_length, max_lazy, nice_length, max_chain)
751
;    z_streamp strm;
751
;    z_streamp strm
752
;    int good_length;
752
;    int good_length
753
;    int max_lazy;
753
;    int max_lazy
754
;    int nice_length;
754
;    int nice_length
755
;    int max_chain;
755
;    int max_chain
756
align 4
756
align 4
757
proc deflateTune uses ebx, strm:dword, good_length:dword, max_lazy:dword,\
757
proc deflateTune uses ebx, strm:dword, good_length:dword, max_lazy:dword,\
758
			nice_length:dword, max_chain:dword
758
			nice_length:dword, max_chain:dword
759
	mov ebx,[strm]
759
	mov ebx,[strm]
Line 795... Line 795...
795
; every combination of windowBits and memLevel.  But even the conservative
795
; every combination of windowBits and memLevel.  But even the conservative
796
; upper bound of about 14% expansion does not seem onerous for output buffer
796
; upper bound of about 14% expansion does not seem onerous for output buffer
797
; allocation.
797
; allocation.
Line 798... Line 798...
798
 
798
 
799
;uLong (strm, sourceLen)
799
;uLong (strm, sourceLen)
800
;    z_streamp strm;
800
;    z_streamp strm
801
;    uLong sourceLen;
801
;    uLong sourceLen
802
align 4
802
align 4
803
proc deflateBound, strm:dword, sourceLen:dword
803
proc deflateBound, strm:dword, sourceLen:dword
804
;    deflate_state *s;
804
;    deflate_state *s;
805
;    uLong complen, wraplen;
805
;    uLong complen, wraplen;
806
;    Bytef *str;
806
;    Bytef *str;
Line 807... Line 807...
807
;zlib_debug 'deflateBound'
807
	zlib_debug 'deflateBound'
808
 
808
 
809
	; conservative upper bound for compressed data
809
	; conservative upper bound for compressed data
Line 861... Line 861...
861
; Put a short in the pending buffer. The 16-bit value is put in MSB order.
861
; Put a short in the pending buffer. The 16-bit value is put in MSB order.
862
; IN assertion: the stream state is correct and there is enough room in
862
; IN assertion: the stream state is correct and there is enough room in
863
; pending_buf.
863
; pending_buf.
Line 864... Line 864...
864
 
864
 
865
;void (s, b)
865
;void (s, b)
866
;    deflate_state *s;
866
;    deflate_state *s
867
;    uInt b;
867
;    uInt b
868
align 4
868
align 4
869
proc putShortMSB uses ebx ecx, s:dword, b:dword
869
proc putShortMSB uses ebx ecx, s:dword, b:dword
870
	mov ebx,[s]
870
	mov ebx,[s]
871
	mov ecx,[b]
871
	mov ecx,[b]
Line 879... Line 879...
879
; through this function so some applications may wish to modify it
879
; through this function so some applications may wish to modify it
880
; to avoid allocating a large strm->next_out buffer and copying into it.
880
; to avoid allocating a large strm->next_out buffer and copying into it.
881
; (See also read_buf()).
881
; (See also read_buf()).
Line 882... Line 882...
882
 
882
 
883
;void (strm)
883
;void (strm)
884
;    z_streamp strm;
884
;    z_streamp strm
885
align 4
885
align 4
886
proc flush_pending uses eax ebx ecx edx, strm:dword
886
proc flush_pending uses eax ebx ecx edx, strm:dword
887
;ecx - len
887
;ecx - len
888
;edx - deflate_state *s
888
;edx - deflate_state *s
889
;ebx - strm
889
;ebx - strm
890
;zlib_debug 'flush_pending'
890
	zlib_debug 'flush_pending'
891
	mov ebx,[strm]
891
	mov ebx,[strm]
Line 892... Line 892...
892
	mov edx,[ebx+z_stream.state]
892
	mov edx,[ebx+z_stream.state]
893
 
893
 
Line 914... Line 914...
914
	ret
914
	ret
915
endp
915
endp
Line 916... Line 916...
916
 
916
 
917
; =========================================================================
917
; =========================================================================
918
;int (strm, flush)
918
;int (strm, flush)
919
;    z_streamp strm;
919
;    z_streamp strm
920
;    int flush;
920
;    int flush
921
align 4
921
align 4
922
proc deflate uses ebx ecx edx edi esi, strm:dword, flush:dword
922
proc deflate uses ebx ecx edx edi esi, strm:dword, flush:dword
923
locals
923
locals
924
	old_flush dd ? ;int ;value of flush param for previous deflate call
924
	old_flush dd ? ;int ;value of flush param for previous deflate call
Line 971... Line 971...
971
	cmp dword[edi+deflate_state.status],INIT_STATE
971
	cmp dword[edi+deflate_state.status],INIT_STATE
972
	jne .end2 ;if (..==..)
972
	jne .end2 ;if (..==..)
973
if GZIP eq 1
973
if GZIP eq 1
974
		cmp dword[edi+deflate_state.wrap],2
974
		cmp dword[edi+deflate_state.wrap],2
975
		jne .end1 ;if (..==..)
975
		jne .end1 ;if (..==..)
976
			stdcall calc_crc32, 0, Z_NULL, 0
976
			xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
977
			mov [ebx+z_stream.adler],eax
977
			mov [ebx+z_stream.adler],eax
978
			put_byte edi, 31
978
			put_byte edi, 31
979
			put_byte edi, 139
979
			put_byte edi, 139
980
			put_byte edi, 8
980
			put_byte edi, 8
981
			cmp dword[edi+deflate_state.gzhead],Z_NULL
981
			cmp dword[edi+deflate_state.gzhead],Z_NULL
Line 1105... Line 1105...
1105
			je @f ;if (..!=0)
1105
			je @f ;if (..!=0)
1106
				mov ecx,[ebx+z_stream.adler]
1106
				mov ecx,[ebx+z_stream.adler]
1107
				bswap ecx
1107
				bswap ecx
1108
				put_dword edi, ecx
1108
				put_dword edi, ecx
1109
			@@:
1109
			@@:
1110
			stdcall calc_crc32, 0, Z_NULL, 0
1110
			xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
1111
			mov [ebx+z_stream.adler],eax
1111
			mov [ebx+z_stream.adler],eax
1112
	.end2:
1112
	.end2:
1113
if GZIP eq 1
1113
if GZIP eq 1
1114
	mov edx,[edi+deflate_state.gzhead]
1114
	mov edx,[edi+deflate_state.gzhead]
1115
	cmp dword[edi+deflate_state.status],EXTRA_STATE
1115
	cmp dword[edi+deflate_state.status],EXTRA_STATE
Line 1305... Line 1305...
1305
			cmp ecx,[edi+deflate_state.pending_buf_size]
1305
			cmp ecx,[edi+deflate_state.pending_buf_size]
1306
			jg @f ;if (..<=..)
1306
			jg @f ;if (..<=..)
1307
				mov ecx,[ebx+z_stream.adler]
1307
				mov ecx,[ebx+z_stream.adler]
1308
				put_byte edi, cl
1308
				put_byte edi, cl
1309
				put_byte edi, ch
1309
				put_byte edi, ch
1310
				stdcall calc_crc32, 0, Z_NULL, 0
1310
				xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
1311
				mov [ebx+z_stream.adler],eax
1311
				mov [ebx+z_stream.adler],eax
1312
				mov dword[edi+deflate_state.status],BUSY_STATE
1312
				mov dword[edi+deflate_state.status],BUSY_STATE
1313
			@@:
1313
			@@:
1314
			jmp .end8
1314
			jmp .end8
1315
		.end9: ;else
1315
		.end9: ;else
Line 1445... Line 1445...
1445
			mov eax,Z_OK
1445
			mov eax,Z_OK
1446
			jmp .end_f
1446
			jmp .end_f
1447
	.end11:
1447
	.end11:
1448
	cmp word[ebx+z_stream.avail_out],0
1448
	cmp word[ebx+z_stream.avail_out],0
1449
	jg @f
1449
	jg @f
1450
		zlib_debug 'bug2' ;Assert(..>0)
1450
		zlib_assert 'bug2' ;Assert(..>0)
1451
	@@:
1451
	@@:
Line 1452... Line 1452...
1452
 
1452
 
1453
	cmp dword[flush],Z_FINISH
1453
	cmp dword[flush],Z_FINISH
1454
	je @f ;if (..!=0)
1454
	je @f ;if (..!=0)
Line 1494... Line 1494...
1494
	ret
1494
	ret
1495
endp
1495
endp
Line 1496... Line 1496...
1496
 
1496
 
1497
; =========================================================================
1497
; =========================================================================
1498
;int (strm)
1498
;int (strm)
1499
;    z_streamp strm;
1499
;    z_streamp strm
1500
align 4
1500
align 4
1501
proc deflateEnd uses ebx ecx edx, strm:dword
1501
proc deflateEnd uses ebx ecx edx, strm:dword
1502
	mov ebx,[strm]
1502
	mov ebx,[strm]
1503
zlib_debug 'deflateEnd'
1503
zlib_debug 'deflateEnd'
Line 1551... Line 1551...
1551
; Copy the source state to the destination state.
1551
; Copy the source state to the destination state.
1552
; To simplify the source, this is not supported for 16-bit MSDOS (which
1552
; To simplify the source, this is not supported for 16-bit MSDOS (which
1553
; doesn't have enough memory anyway to duplicate compression states).
1553
; doesn't have enough memory anyway to duplicate compression states).
Line 1554... Line 1554...
1554
 
1554
 
1555
;int (dest, source)
1555
;int (dest, source)
1556
;    z_streamp dest;
1556
;    z_streamp dest
1557
;    z_streamp source;
1557
;    z_streamp source
1558
align 4
1558
align 4
1559
proc deflateCopy uses edx edi esi, dest:dword, source:dword
-
 
1560
locals
1559
proc deflateCopy uses ebx edx edi esi, dest:dword, source:dword
1561
	overlay dd ? ;uint_16p
-
 
1562
endl
1560
;ebx = overlay ;uint_16p
1563
;edi = ds; deflate_state*
1561
;edi = ds ;deflate_state*
Line 1564... Line 1562...
1564
;esi = ss; deflate_state*
1562
;esi = ss ;deflate_state*
1565
 
1563
 
Line 1595... Line 1593...
1595
	ZALLOC edx, [edi+deflate_state.w_size], 4 ;sizeof.dd
1593
	ZALLOC edx, [edi+deflate_state.w_size], 4 ;sizeof.dd
1596
	mov dword[edi+deflate_state.prev],eax
1594
	mov dword[edi+deflate_state.prev],eax
1597
	ZALLOC edx, [edi+deflate_state.hash_size], 4 ;sizeof.dd
1595
	ZALLOC edx, [edi+deflate_state.hash_size], 4 ;sizeof.dd
1598
	mov dword[edi+deflate_state.head],eax
1596
	mov dword[edi+deflate_state.head],eax
1599
	ZALLOC edx, [edi+deflate_state.lit_bufsize], 4 ;sizeof.dw+2
1597
	ZALLOC edx, [edi+deflate_state.lit_bufsize], 4 ;sizeof.dw+2
1600
	mov [overlay],eax
1598
	mov ebx,eax
1601
	mov dword[edi+deflate_state.pending_buf],eax
1599
	mov dword[edi+deflate_state.pending_buf],eax
Line 1602... Line 1600...
1602
 
1600
 
1603
	cmp dword[edi+deflate_state.window],Z_NULL
1601
	cmp dword[edi+deflate_state.window],Z_NULL
1604
	je @f
1602
	je @f
Line 1616... Line 1614...
1616
 
1614
 
1617
	; following zmemcpy do not work for 16-bit MSDOS
1615
	; following zmemcpy do not work for 16-bit MSDOS
1618
	mov eax,[edi+deflate_state.w_size]
1616
	mov eax,[edi+deflate_state.w_size]
1619
	shl eax,1 ;*= 2*sizeof.db
1617
	shl eax,1 ;*= 2*sizeof.db
-
 
1618
	stdcall zmemcpy, [edi+deflate_state.window], [esi+deflate_state.window], eax
-
 
1619
	mov eax,[edi+deflate_state.w_size]
1620
	stdcall zmemcpy, [edi+deflate_state.window], [esi+deflate_state.window], eax
1620
	shl eax,2 ;*= sizeof.dd
-
 
1621
	stdcall zmemcpy, [edi+deflate_state.prev], [esi+deflate_state.prev], eax
-
 
1622
	mov eax,[edi+deflate_state.hash_size]
1621
;    zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1623
	shl eax,2 ;*= sizeof.dd
1622
;    zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1624
	stdcall zmemcpy, [edi+deflate_state.head], [esi+deflate_state.head], eax
1623
;    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1625
	stdcall zmemcpy, [edi+deflate_state.pending_buf], [esi+deflate_state.pending_buf], [edi+deflate_state.pending_buf_size]
1624
 
1626
 
-
 
1627
	mov eax,[edi+deflate_state.pending_buf]
-
 
1628
	add eax,[esi+deflate_state.pending_out]
-
 
1629
	sub eax,[esi+deflate_state.pending_buf]
1625
;    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1630
	mov [edi+deflate_state.pending_out],eax
-
 
1631
	mov eax,[edi+deflate_state.lit_bufsize]
-
 
1632
	shr eax,1 ;/=sizeof.uint_16
-
 
1633
	add eax,ebx
1626
;    ds->d_buf = overlay + ds->lit_bufsize/sizeof(uint_16);
1634
	mov [edi+deflate_state.d_buf],eax
-
 
1635
	mov eax,[edi+deflate_state.lit_bufsize]
-
 
1636
	imul eax,3 ;*=1+sizeof.uint_16
-
 
1637
	add eax,[edi+deflate_state.pending_buf]
Line 1627... Line 1638...
1627
;    ds->l_buf = ds->pending_buf + (1+sizeof(uint_16))*ds->lit_bufsize;
1638
	mov [edi+deflate_state.l_buf],eax
1628
 
1639
 
1629
	mov eax,edi
1640
	mov eax,edi
1630
	add eax,deflate_state.dyn_ltree
1641
	add eax,deflate_state.dyn_ltree
Line 1645... Line 1656...
1645
; this function so some applications may wish to modify it to avoid
1656
; this function so some applications may wish to modify it to avoid
1646
; allocating a large strm->next_in buffer and copying from it.
1657
; allocating a large strm->next_in buffer and copying from it.
1647
; (See also flush_pending()).
1658
; (See also flush_pending()).
Line 1648... Line 1659...
1648
 
1659
 
1649
;int (strm, buf, size)
1660
;int (strm, buf, size)
1650
;    z_streamp strm;
1661
;    z_streamp strm
1651
;    Bytef *buf;
1662
;    Bytef *buf
1652
;    unsigned size;
1663
;    unsigned size
1653
align 4
1664
align 4
1654
proc read_buf uses ebx ecx, strm:dword, buf:dword, size:dword
1665
proc read_buf uses ebx ecx, strm:dword, buf:dword, size:dword
1655
	mov ebx,[strm]
1666
	mov ebx,[strm]
Line 1737... Line 1748...
1737
end if
1748
end if
1738
	ret
1749
	ret
1739
endp
1750
endp
Line 1740... Line 1751...
1740
 
1751
 
1741
;uInt (s, cur_match)
1752
;uInt (s, cur_match)
1742
;    deflate_state *s;
1753
;    deflate_state *s
1743
;    IPos cur_match;                             /* current match */
1754
;    IPos cur_match ;current match
1744
align 4
1755
align 4
1745
proc longest_match uses ebx ecx edx edi esi, s:dword, cur_match:dword
1756
proc longest_match uses ebx ecx edx edi esi, s:dword, cur_match:dword
1746
if FASTEST eq 0
1757
if FASTEST eq 0
1747
; ===========================================================================
1758
; ===========================================================================
Line 1769... Line 1780...
1769
	; we prevent matches with the string of window index 0.
1780
	; we prevent matches with the string of window index 0.
Line 1770... Line 1781...
1770
 
1781
 
1771
;    Posf *prev = s->prev;
1782
;    Posf *prev = s->prev;
Line 1772... Line -...
1772
;    uInt wmask = s->w_mask;
-
 
1773
 
-
 
1774
if UNALIGNED_OK eq 1
-
 
1775
	; Compare two bytes at a time. Note: this is not always beneficial.
-
 
1776
	; Try with and without -DUNALIGNED_OK to check.
-
 
1777
 
-
 
1778
;    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
-
 
1779
;    register uint_16 scan_start = *(uint_16p*)scan;
-
 
1780
;    register uint_16 scan_end   = *(uint_16p*)(scan+best_len-1);
1783
;    uInt wmask = s->w_mask;
1781
else
1784
 
1782
;    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1785
;    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1783
;    register Byte scan_end1  = scan[best_len-1];
-
 
Line 1784... Line 1786...
1784
;    register Byte scan_end   = scan[best_len];
1786
;    register Byte scan_end1  = scan[best_len-1];
1785
end if
1787
;    register Byte scan_end   = scan[best_len];
Line 1786... Line 1788...
1786
 
1788
 
Line 1810... Line 1812...
1810
	; reasons.  Therefore uninitialized memory will be accessed, and
1812
	; reasons.  Therefore uninitialized memory will be accessed, and
1811
	; conditional jumps will be made that depend on those values.
1813
	; conditional jumps will be made that depend on those values.
1812
	; However the length of the match is limited to the lookahead, so
1814
	; However the length of the match is limited to the lookahead, so
1813
	; the output of deflate is not affected by the uninitialized values.
1815
	; the output of deflate is not affected by the uninitialized values.
Line 1814... Line -...
1814
 
-
 
1815
if ((UNALIGNED_OK eq 1) & MAX_MATCH == 258)
-
 
1816
	; This code assumes sizeof(unsigned short) == 2. Do not use
-
 
1817
	; UNALIGNED_OK if your compiler uses a different size.
-
 
1818
 
-
 
1819
;        if (*(uint_16p*)(match+best_len-1) != scan_end ||
-
 
1820
;            *(uint_16p*)match != scan_start) continue;
-
 
1821
 
-
 
1822
	; It is not necessary to compare scan[2] and match[2] since they are
-
 
1823
	; always equal when the other bytes match, given that the hash keys
-
 
1824
	; are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
-
 
1825
	; strstart+3, +5, ... up to strstart+257. We check for insufficient
-
 
1826
	; lookahead only every 4th comparison; the 128th check will be made
-
 
1827
	; at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
-
 
1828
	; necessary to put more guard bytes at the end of the window, or
-
 
1829
	; to check more often for insufficient lookahead.
-
 
1830
 
-
 
1831
;        Assert(scan[2] == match[2], "scan[2]?");
-
 
1832
;        scan++, match++;
-
 
1833
;        do {
-
 
1834
;        } while (*(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
-
 
1835
;                 *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
-
 
1836
;                 *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
-
 
1837
;                 *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
-
 
1838
;                 scan < strend);
-
 
1839
	; The funny "do {}" generates better code on most compilers
-
 
1840
 
-
 
1841
	; Here, scan <= window+strstart+257
-
 
1842
;        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
 
1843
;        if (*scan == *match) scan++;
-
 
1844
 
-
 
1845
;        len = (MAX_MATCH - 1) - (int)(strend-scan);
-
 
1846
;        scan = strend - (MAX_MATCH-1);
-
 
1847
 
-
 
1848
else ;UNALIGNED_OK
-
 
1849
 
1816
 
1850
;        if (match[best_len]   != scan_end  ||
1817
;        if (match[best_len]   != scan_end  ||
1851
;            match[best_len-1] != scan_end1 ||
1818
;            match[best_len-1] != scan_end1 ||
1852
;            *match            != *scan     ||
1819
;            *match            != *scan     ||
Line 1874... Line 1841...
1874
;        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1841
;        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
Line 1875... Line 1842...
1875
 
1842
 
1876
;        len = MAX_MATCH - (int)(strend - scan);
1843
;        len = MAX_MATCH - (int)(strend - scan);
Line 1877... Line -...
1877
;        scan = strend - MAX_MATCH;
-
 
1878
 
-
 
1879
end if ;UNALIGNED_OK
1844
;        scan = strend - MAX_MATCH;
1880
 
1845
 
1881
;        if (len > best_len) {
1846
;        if (len > best_len) {
1882
;            s->match_start = cur_match;
1847
;            s->match_start = cur_match;
1883
;            best_len = len;
-
 
1884
;            if (len >= nice_match) break;
-
 
1885
if UNALIGNED_OK eq 1
-
 
1886
;            scan_end = *(uint_16p*)(scan+best_len-1);
1848
;            best_len = len;
1887
else
1849
;            if (len >= nice_match) break;
1888
;            scan_end1  = scan[best_len-1];
-
 
1889
;            scan_end   = scan[best_len];
1850
;            scan_end1  = scan[best_len-1];
1890
end if
1851
;            scan_end   = scan[best_len];
1891
;        }
1852
;        }
Line 1892... Line 1853...
1892
;    } while ((cur_match = prev[cur_match & wmask]) > limit
1853
;    } while ((cur_match = prev[cur_match & wmask]) > limit
Line 1899... Line 1860...
1899
else ;FASTEST
1860
else ;FASTEST
Line 1900... Line 1861...
1900
 
1861
 
1901
; ---------------------------------------------------------------------------
1862
; ---------------------------------------------------------------------------
1902
; Optimized version for FASTEST only
1863
; Optimized version for FASTEST only
1903
	mov edx,[s]
1864
	mov edx,[s]
Line 1904... Line 1865...
1904
;zlib_debug 'longest_match'
1865
	zlib_debug 'longest_match'
1905
 
1866
 
Line 1906... Line 1867...
1906
	; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1867
	; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1907
	; It is easy to get rid of this optimization if necessary.
1868
	; It is easy to get rid of this optimization if necessary.
1908
 
1869
 
1909
if MAX_MATCH <> 258
1870
if MAX_MATCH <> 258
1910
	cmp dword[edx+deflate_state.hash_bits],8
1871
	cmp dword[edx+deflate_state.hash_bits],8
1911
	jge @f
1872
	jge @f
1912
		zlib_debug 'Code too clever' ;Assert(..>=.. && ..==..)
1873
		zlib_assert 'Code too clever' ;Assert(..>=.. && ..==..)
1913
	@@:
1874
	@@:
1914
end if
1875
end if
1915
	mov eax,[edx+deflate_state.window_size]
1876
	mov eax,[edx+deflate_state.window_size]
1916
	sub eax,MIN_LOOKAHEAD
1877
	sub eax,MIN_LOOKAHEAD
1917
	cmp [edx+deflate_state.strstart],eax
1878
	cmp [edx+deflate_state.strstart],eax
1918
	jle @f
1879
	jle @f
1919
		zlib_debug 'need lookahead' ;Assert(..<=..)
1880
		zlib_assert 'need lookahead' ;Assert(..<=..)
1920
	@@:
1881
	@@:
1921
	mov eax,[edx+deflate_state.strstart]
1882
	mov eax,[edx+deflate_state.strstart]
1922
	cmp [cur_match],eax
1883
	cmp [cur_match],eax
Line 1923... Line 1884...
1923
	jl @f
1884
	jl @f
1924
		zlib_debug 'no future' ;Assert(..<..)
1885
		zlib_assert 'no future' ;Assert(..<..)
1925
	@@:
1886
	@@:
Line 1948... Line 1909...
1948
 
1909
 
1949
	add edi,2
1910
	add edi,2
1950
	mov al,byte[edi]
1911
	mov al,byte[edi]
1951
	cmp al,byte[esi]
1912
	cmp al,byte[esi]
1952
	je @f
1913
	je @f
1953
		zlib_debug 'match[2]?' ;Assert(..==..)
1914
		zlib_assert 'match[2]?' ;Assert(..==..)
Line 1954... Line 1915...
1954
	@@:
1915
	@@:
1955
 
1916
 
Line 1967... Line 1928...
1967
	mov eax,[edx+deflate_state.window_size]
1928
	mov eax,[edx+deflate_state.window_size]
1968
	dec eax
1929
	dec eax
1969
	add eax,[edx+deflate_state.window]
1930
	add eax,[edx+deflate_state.window]
1970
	cmp edi,eax
1931
	cmp edi,eax
1971
	jle @f
1932
	jle @f
1972
		zlib_debug 'wild scan' ;Assert(..<=..)
1933
		zlib_assert 'wild scan' ;Assert(..<=..)
1973
	@@:
1934
	@@:
1974
	sub edi,ebx
1935
	sub edi,ebx
1975
	;edi = len
1936
	;edi = len
Line 1976... Line 1937...
1976
 
1937
 
Line 1995... Line 1956...
1995
 
1956
 
1996
; ===========================================================================
1957
; ===========================================================================
Line 1997... Line 1958...
1997
; Check that the match at match_start is indeed a match.
1958
; Check that the match at match_start is indeed a match.
1998
 
1959
 
1999
;void (s, start, match, length)
1960
;void (s, start, match, length)
2000
;    deflate_state *s;
1961
;    deflate_state *s
2001
;    IPos start, match;
1962
;    IPos start, match
2002
;    int length;
1963
;    int length
2003
align 4
1964
align 4
2004
proc check_match, s:dword, start:dword, p3match:dword, length:dword
1965
proc check_match, s:dword, start:dword, p3match:dword, length:dword
2005
if DEBUG eq 1
1966
if DEBUG eq 1
Line 2040... Line 2001...
2040
;esi = p, str, curr
2001
;esi = p, str, curr
2041
;ebx = more ;Amount of free space at the end of the window.
2002
;ebx = more ;Amount of free space at the end of the window.
2042
	;Объем свободного пространства в конце окна.
2003
	;Объем свободного пространства в конце окна.
2043
;ecx = wsize ;uInt
2004
;ecx = wsize ;uInt
2044
;edx = s.strm
2005
;edx = s.strm
2045
;zlib_debug 'fill_window'
2006
	zlib_debug 'fill_window'
2046
	mov edi,[s]
2007
	mov edi,[s]
2047
	cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
2008
	cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
2048
	jl @f
2009
	jl @f
2049
		zlib_debug 'already enough lookahead' ;Assert(..<..)
2010
		zlib_assert 'already enough lookahead' ;Assert(..<..)
2050
	@@:
2011
	@@:
Line 2051... Line 2012...
2051
 
2012
 
2052
	mov ecx,[edi+deflate_state.w_size]
2013
	mov ecx,[edi+deflate_state.w_size]
2053
	mov edx,[edi+deflate_state.strm]
2014
	mov edx,[edi+deflate_state.strm]
2054
	.cycle0: ;do
2015
	.cycle0: ;do
2055
;zlib_debug 'do'
2016
	zlib_debug 'do'
2056
		mov ebx,[edi+deflate_state.window_size]
2017
		mov ebx,[edi+deflate_state.window_size]
2057
		sub ebx,[edi+deflate_state.lookahead]
2018
		sub ebx,[edi+deflate_state.lookahead]
Line 2058... Line 2019...
2058
		sub ebx,[edi+deflate_state.strstart]
2019
		sub ebx,[edi+deflate_state.strstart]
Line 2133... Line 2094...
2133
		; Otherwise, window_size == 2*WSIZE so more >= 2.
2094
		; Otherwise, window_size == 2*WSIZE so more >= 2.
2134
		; If there was sliding, more >= WSIZE. So in all cases, more >= 2.
2095
		; If there was sliding, more >= WSIZE. So in all cases, more >= 2.
Line 2135... Line 2096...
2135
 
2096
 
2136
		cmp ebx,2
2097
		cmp ebx,2
2137
		jge @f
2098
		jge @f
2138
			zlib_debug 'more < 2' ;Assert(..>=..)
2099
			zlib_assert 'more < 2' ;Assert(..>=..)
2139
		@@:
2100
		@@:
2140
		mov eax,[edi+deflate_state.window]
2101
		mov eax,[edi+deflate_state.window]
2141
		add eax,[edi+deflate_state.strstart]
2102
		add eax,[edi+deflate_state.strstart]
2142
		add eax,[edi+deflate_state.lookahead]
2103
		add eax,[edi+deflate_state.lookahead]
Line 2258... Line 2219...
2258
 
2219
 
2259
	mov eax,[edi+deflate_state.window_size]
2220
	mov eax,[edi+deflate_state.window_size]
2260
	sub eax,MIN_LOOKAHEAD
2221
	sub eax,MIN_LOOKAHEAD
2261
	cmp [edi+deflate_state.strstart],eax
2222
	cmp [edi+deflate_state.strstart],eax
2262
	jle @f
2223
	jle @f
2263
		zlib_debug 'not enough room for search' ;Assert(..<=..)
2224
		zlib_assert 'not enough room for search' ;Assert(..<=..)
2264
	@@:
2225
	@@:
2265
popad
2226
popad
2266
	ret
2227
	ret
Line 2315... Line 2276...
2315
; only for the level=0 compression option.
2276
; only for the level=0 compression option.
2316
; NOTE: this function should be optimized to avoid extra copying from
2277
; NOTE: this function should be optimized to avoid extra copying from
2317
; window to pending_buf.
2278
; window to pending_buf.
Line 2318... Line 2279...
2318
 
2279
 
2319
;block_state (s, flush)
2280
;block_state (s, flush)
2320
;    deflate_state *s;
2281
;    deflate_state *s
2321
;    int flush;
2282
;    int flush
2322
align 4
2283
align 4
2323
proc deflate_stored uses ebx ecx edi, s:dword, flush:dword
2284
proc deflate_stored uses ebx ecx edi, s:dword, flush:dword
2324
; Stored blocks are limited to 0xffff bytes, pending_buf is limited
2285
; Stored blocks are limited to 0xffff bytes, pending_buf is limited
2325
; to pending_buf_size, and each stored block has a 5 byte header:
2286
; to pending_buf_size, and each stored block has a 5 byte header:
Line 2739... Line 2700...
2739
		;.end4:
2700
		;.end4:
2740
		jmp .cycle0
2701
		jmp .cycle0
2741
	.cycle0end:
2702
	.cycle0end:
2742
	cmp dword[flush],Z_NO_FLUSH
2703
	cmp dword[flush],Z_NO_FLUSH
2743
	jne @f
2704
	jne @f
2744
		zlib_debug 'no flush?' ;Assert (..!=..)
2705
		zlib_assert 'no flush?' ;Assert (..!=..)
2745
	@@:
2706
	@@:
2746
	cmp dword[edi+deflate_state.match_available],0
2707
	cmp dword[edi+deflate_state.match_available],0
2747
	je @f ;if (..)
2708
	je @f ;if (..)
2748
		mov eax,[edi+deflate_state.strstart]
2709
		mov eax,[edi+deflate_state.strstart]
2749
		dec eax
2710
		dec eax
Line 2778... Line 2739...
2778
; For Z_RLE, simply look for runs of bytes, generate matches only of distance
2739
; For Z_RLE, simply look for runs of bytes, generate matches only of distance
2779
; one.  Do not maintain a hash table.  (It will be regenerated if this run of
2740
; one.  Do not maintain a hash table.  (It will be regenerated if this run of
2780
; deflate switches away from Z_RLE.)
2741
; deflate switches away from Z_RLE.)
Line 2781... Line 2742...
2781
 
2742
 
2782
;block_state (s, flush)
2743
;block_state (s, flush)
2783
;    deflate_state *s;
2744
;    deflate_state *s
2784
;    int flush;
2745
;    int flush
2785
align 4
2746
align 4
2786
proc deflate_rle uses ecx edx edi esi, s:dword, flush:dword
2747
proc deflate_rle uses ecx edx edi esi, s:dword, flush:dword
2787
locals
2748
locals
2788
	bflush dd ? ;int ;set if current block must be flushed
2749
	bflush dd ? ;int ;set if current block must be flushed
Line 2844... Line 2805...
2844
			mov eax,[edx+deflate_state.window_size]
2805
			mov eax,[edx+deflate_state.window_size]
2845
			dec eax
2806
			dec eax
2846
			add eax,[edx+deflate_state.window]
2807
			add eax,[edx+deflate_state.window]
2847
			cmp edi,eax
2808
			cmp edi,eax
2848
			jle .end1
2809
			jle .end1
2849
				zlib_debug 'wild scan' ;Assert(..<=..)
2810
				zlib_assert 'wild scan' ;Assert(..<=..)
2850
		.end1:
2811
		.end1:
Line 2851... Line 2812...
2851
 
2812
 
2852
		; Emit match if have run of MIN_MATCH or longer, else emit literal
2813
		; Emit match if have run of MIN_MATCH or longer, else emit literal
2853
		cmp dword[edx+deflate_state.match_length],MIN_MATCH
2814
		cmp dword[edx+deflate_state.match_length],MIN_MATCH
Line 2901... Line 2862...
2901
; ===========================================================================
2862
; ===========================================================================
2902
; For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
2863
; For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
2903
; (It will be regenerated if this run of deflate switches away from Huffman.)
2864
; (It will be regenerated if this run of deflate switches away from Huffman.)
Line 2904... Line 2865...
2904
 
2865
 
2905
;block_state (s, flush)
2866
;block_state (s, flush)
2906
;    deflate_state *s;
2867
;    deflate_state *s
2907
;    int flush;
2868
;    int flush
2908
align 4
2869
align 4
2909
proc deflate_huff uses ebx edi, s:dword, flush:dword
2870
proc deflate_huff uses ebx edi, s:dword, flush:dword
2910
locals
2871
locals
2911
	bflush dd ? ;int ;set if current block must be flushed
2872
	bflush dd ? ;int ;set if current block must be flushed