Rev 6851 | Rev 6855 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6851 | Rev 6854 | ||
---|---|---|---|
Line 564... | Line 564... | ||
564 | ; OUT assertions: the field len is set to the optimal bit length, the |
564 | ; OUT assertions: the field len is set to the optimal bit length, the |
565 | ; array bl_count contains the frequencies for each bit length. |
565 | ; array bl_count contains the frequencies for each bit length. |
566 | ; The length opt_len is updated; static_len is also updated if stree is |
566 | ; The length opt_len is updated; static_len is also updated if stree is |
567 | ; not null. |
567 | ; not null. |
Line 568... | Line -... | ||
568 | - | ||
569 | ;void (s, desc) |
- | |
570 | ; deflate_state* s |
568 | |
571 | ; tree_desc* desc ;the tree descriptor |
569 | ;void (deflate_state* s, tree_desc* desc) |
572 | align 4 |
570 | align 16 |
573 | proc gen_bitlen, s:dword, desc:dword |
571 | proc gen_bitlen, s:dword, desc:dword |
574 | locals |
572 | locals |
575 | tree dd ? ;ct_data* ;= desc.dyn_tree |
573 | tree dd ? ;ct_data* ;= desc.dyn_tree |
576 | max_code dd ? ;int ;= desc.max_code |
574 | max_code dd ? ;int ;= desc.max_code |
Line 622... | Line 620... | ||
622 | mov word[eax+Len],0 ;root of the heap |
620 | mov word[eax+Len],0 ;root of the heap |
Line 623... | Line 621... | ||
623 | 621 | ||
624 | mov eax,[edi+deflate_state.heap_max] |
622 | mov eax,[edi+deflate_state.heap_max] |
625 | inc eax |
623 | inc eax |
- | 624 | mov [h],eax |
|
- | 625 | jmp @f |
|
626 | mov [h],eax |
626 | align 4 |
- | 627 | .cycle1: |
|
- | 628 | inc dword[h] |
|
627 | .cycle1: |
629 | @@: |
628 | cmp dword[h],HEAP_SIZE |
630 | cmp dword[h],HEAP_SIZE |
629 | jge .cycle1end ;for (..;..<..;..) |
631 | jge .cycle1end ;for (..;..<..;..) |
630 | mov eax,[h] |
632 | mov eax,[h] |
631 | mov ecx,[edi+deflate_state.heap+4*eax] |
633 | mov ecx,[edi+4*eax+deflate_state.heap] |
632 | ;ecx = n |
- | |
633 | mov eax,sizeof.ct_data |
- | |
634 | imul eax,ecx |
634 | ;ecx = n |
635 | add eax,[tree] |
635 | mov edx,[tree] |
636 | movzx eax,word[eax+Dad] |
- | |
637 | imul eax,sizeof.ct_data |
- | |
638 | add eax,[tree] |
636 | movzx eax,word[edx+sizeof.ct_data*ecx+Dad] |
639 | movzx eax,word[eax+Len] |
637 | movzx eax,word[edx+sizeof.ct_data*eax+Len] |
640 | inc eax |
638 | inc eax |
641 | mov [bits],eax ;bits = tree[tree[n].Dad].Len + 1 |
639 | mov [bits],eax ;bits = tree[tree[n].Dad].Len + 1 |
642 | mov eax,[max_length] |
640 | mov eax,[max_length] |
643 | cmp [bits],eax |
641 | cmp [bits],eax |
644 | jle @f ;if (..>..) |
642 | jle @f ;if (..>..) |
645 | mov [bits],eax |
643 | mov [bits],eax |
646 | inc dword[overflow] |
644 | inc dword[overflow] |
647 | @@: |
645 | @@: |
648 | mov esi,[bits] |
646 | mov eax,[bits] |
649 | mov eax,sizeof.ct_data |
- | |
650 | imul eax,ecx |
- | |
651 | add eax,[tree] |
- | |
652 | mov word[eax+Len],si |
647 | mov [edx+sizeof.ct_data*ecx+Len],ax |
Line 653... | Line 648... | ||
653 | ; We overwrite tree[n].Dad which is no longer needed |
648 | ; We overwrite tree[n].Dad which is no longer needed |
654 | - | ||
655 | cmp ecx,[max_code] |
- | |
656 | jle @f |
649 | |
657 | inc dword[h] |
- | |
Line 658... | Line -... | ||
658 | jmp .cycle1 ;if (..>..) continue ;not a leaf node |
- | |
659 | @@: |
- | |
660 | 650 | cmp ecx,[max_code] |
|
661 | mov eax,[bits] |
651 | jg .cycle1 ;if (..>..) continue ;not a leaf node |
662 | shl eax,1 ;*= sizeof.uint_16 |
652 | |
663 | inc word[eax+edi+deflate_state.bl_count] |
653 | inc word[edi+2*eax+deflate_state.bl_count] |
664 | mov dword[xbits],0 |
654 | mov dword[xbits],0 |
665 | cmp ecx,[base] |
655 | cmp ecx,[base] |
666 | jl @f ;if (..>=..) |
656 | jl @f ;if (..>=..) |
667 | mov eax,ecx |
657 | mov eax,ecx |
668 | sub eax,[base] |
658 | sub eax,[base] |
669 | shl eax,2 ;*= sizeof.dd |
659 | shl eax,2 ;*= sizeof.dd |
670 | add eax,[extra] |
660 | add eax,[extra] |
671 | mov eax,[eax] |
- | |
672 | mov [xbits],eax |
- | |
673 | @@: |
- | |
674 | mov eax,sizeof.ct_data |
661 | mov eax,[eax] |
675 | imul eax,ecx |
662 | mov [xbits],eax |
676 | add eax,[tree] |
663 | @@: |
677 | movzx eax,word[eax+Freq] |
664 | movzx eax,word[edx+sizeof.ct_data*ecx+Freq] |
678 | mov [f],ax |
665 | mov [f],ax |
679 | mov esi,[bits] |
666 | mov esi,[bits] |
680 | add esi,[xbits] |
667 | add esi,[xbits] |
681 | imul eax,esi |
668 | imul eax,esi |
682 | add [edi+deflate_state.opt_len],eax |
669 | add [edi+deflate_state.opt_len],eax |
683 | cmp dword[stree],0 |
670 | cmp dword[stree],0 |
684 | je @f ;if (..) |
671 | je @f ;if (..) |
685 | movzx eax,word[f] |
672 | movzx eax,word[f] |
686 | mov esi,sizeof.ct_data |
673 | mov esi,sizeof.ct_data |
687 | imul esi,ecx |
674 | imul esi,ecx |
688 | add esi,[tree] |
675 | add esi,[tree] ;;;must be [stree] but don't work |
689 | movzx esi,word[esi+Len] |
676 | movzx esi,word[esi+Len] |
690 | add esi,[xbits] |
677 | add esi,[xbits] |
691 | imul eax,esi |
- | |
692 | add [edi+deflate_state.static_len],eax |
678 | imul eax,esi |
693 | @@: |
679 | add [edi+deflate_state.static_len],eax |
694 | inc dword[h] |
680 | @@: |
695 | jmp .cycle1 |
681 | jmp .cycle1 |
696 | align 4 |
682 | align 4 |
Line 737... | Line 723... | ||
737 | mov [bits],eax |
723 | mov [bits],eax |
738 | .cycle3: |
724 | .cycle3: |
739 | cmp dword[bits],0 |
725 | cmp dword[bits],0 |
740 | je .end_f ;for (..;..!=0;..) |
726 | je .end_f ;for (..;..!=0;..) |
741 | mov eax,[bits] |
727 | mov eax,[bits] |
742 | shl eax,1 ;*= sizeof.dw |
- | |
743 | movzx ecx,word[eax+edi+deflate_state.bl_count] |
728 | movzx ecx,word[edi+2*eax+deflate_state.bl_count] |
744 | .cycle4: ;while (..!=0) |
729 | .cycle4: ;while (..!=0) |
745 | cmp ecx,0 |
730 | test ecx,ecx |
746 | je .cycle4end |
731 | jz .cycle4end |
747 | dec dword[h] |
732 | dec dword[h] |
748 | mov eax,[h] |
733 | mov eax,[h] |
749 | mov eax,[edi+deflate_state.heap+4*eax] |
734 | mov eax,[edi+4*eax+deflate_state.heap] |
750 | mov [m],eax ;m = s.heap[--h] |
735 | mov [m],eax ;m = s.heap[--h] |
751 | cmp eax,[max_code] |
736 | cmp eax,[max_code] |
752 | jg .cycle4 ;if (..>..) continue |
737 | jg .cycle4 ;if (..>..) continue |
753 | mov esi,[m] |
738 | mov esi,[m] |
754 | imul esi,sizeof.ct_data |
- | |
755 | add esi,[tree] ;esi = &tree[m] |
- | |
756 | mov eax,[bits] |
739 | mov eax,[bits] |
757 | cmp word[esi+Len],ax |
740 | cmp word[edx+sizeof.ct_data*esi+Len],ax |
758 | je @f ;if (..!=..) |
741 | je @f ;if (..!=..) |
759 | ; Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); |
742 | ; Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); |
760 | movzx ebx,word[esi+Len] |
743 | movzx ebx,word[esi+Len] |
761 | sub eax,ebx |
744 | sub eax,ebx |
762 | movzx ebx,word[esi+Freq] |
745 | movzx ebx,word[esi+Freq] |
Line 897... | Line 880... | ||
897 | 880 | ||
898 | mov edx,[tree] |
881 | mov edx,[tree] |
899 | xor ecx,ecx |
882 | xor ecx,ecx |
900 | .cycle0: ;for (..;..<..;..) |
883 | .cycle0: ;for (..;..<..;..) |
901 | cmp ecx,[elems] |
884 | cmp ecx,[elems] |
902 | jge .cycle0end |
885 | jge .cycle1 |
903 | cmp word[edx+Freq],0 |
886 | cmp word[edx+Freq],0 |
904 | je @f ;if (..!=0) |
887 | je @f ;if (..!=0) |
905 | inc dword[edi+deflate_state.heap_len] |
888 | inc dword[edi+deflate_state.heap_len] |
906 | mov eax,[edi+deflate_state.heap_len] |
889 | mov eax,[edi+deflate_state.heap_len] |
Line 913... | Line 896... | ||
913 | mov word[edx+Len],0 |
896 | mov word[edx+Len],0 |
914 | .end0: |
897 | .end0: |
915 | add edx,sizeof.ct_data |
898 | add edx,sizeof.ct_data |
916 | inc ecx |
899 | inc ecx |
917 | jmp .cycle0 |
900 | jmp .cycle0 |
918 | align 4 |
- | |
919 | .cycle0end: |
- | |
Line 920... | Line 901... | ||
920 | 901 | ||
921 | ; The pkzip format requires that at least one distance code exists, |
902 | ; The pkzip format requires that at least one distance code exists, |
922 | ; and that at least one bit should be sent even if there is only one |
903 | ; and that at least one bit should be sent even if there is only one |
923 | ; possible code. So to avoid special checks later on we force at least |
904 | ; possible code. So to avoid special checks later on we force at least |
Line -... | Line 905... | ||
- | 905 | ; two codes of non zero frequency. |
|
924 | ; two codes of non zero frequency. |
906 | |
925 | 907 | align 4 |
|
926 | .cycle1: ;while (..<..) |
908 | .cycle1: ;while (..<..) |
927 | cmp dword[edi+deflate_state.heap_len],2 |
909 | cmp dword[edi+deflate_state.heap_len],2 |
928 | jge .cycle1end |
910 | jge .cycle1end |
Line 958... | Line 940... | ||
958 | 940 | ||
959 | ; The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, |
941 | ; The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, |
Line 960... | Line 942... | ||
960 | ; establish sub-heaps of increasing lengths: |
942 | ; establish sub-heaps of increasing lengths: |
961 | 943 | ||
962 | mov ecx,[edi+deflate_state.heap_len] |
944 | mov ecx,[edi+deflate_state.heap_len] |
963 | shr ecx,1 |
945 | sar ecx,1 |
964 | .cycle2: ;for (..;..>=..;..) |
946 | .cycle2: ;for (..;..>=..;..) |
965 | cmp ecx,1 |
947 | cmp ecx,1 |
966 | jl .cycle2end |
948 | jl .cycle2end |