LZ77 encoder, LZ77 encoding method and data compression device
By adopting a parallel hash processing module and a hash linked list structure in the LZ77 encoder, the inefficiency problem caused by the serial processing of the Deflate algorithm is solved, efficient parallel encoding of multiple strings is achieved, and the data compression efficiency is improved. .
Patent Information
- Application Number
- CN202410735898.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-08-30
AI Technical Summary
The existing Deflate algorithm cannot meet the high efficiency requirements of actual application scenarios during the data compression process, mainly due to the low efficiency caused by its serial processing method.
A LZ77 encoder is designed, which uses a multi-level RAM structure and a hash linked list structure through the hash processing module to realize parallel hash processing and matching search of string groups, and can process multiple strings in one clock cycle. Perform parallel encoding to improve data compression efficiency.
Through parallel processing, data compression efficiency is significantly improved, multiple strings can be encoded in one clock cycle, and data compression efficiency and performance are improved.
Smart Images

Figure CN118573207A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an LZ77 encoder, an LZ77 encoding method and a data compression device. Background Art
[0002] In big data services, database services, web network services, and storage services, compression and decompression technologies are required to reduce storage resources and transmission bandwidth requirements and improve data transmission throughput. Compression is divided into lossy compression and lossless compression. Lossy compression is applied to data such as video and voice, and lossless compression is applied to files and other occasions where information must be completely restored. Deflate is a data lossless compression algorithm, including LZ77 coding and Huffman coding. Its basic principle is to first use the LZ77 algorithm to find repeated fragments in the data, and then use Huffman coding to further compress the data. This combined compression technology makes the Deflate algorithm have good performance in compression efficiency and speed, so it is widely used in various data transmission and storage scenarios.
[0003] At present, the Deflate algorithm is mainly implemented in software form, and the encoding process is also processed serially, which makes it difficult for the Deflate algorithm to meet the high-efficiency requirements for data compression in actual application scenarios. Summary of the invention
[0004] In view of this, the embodiments of the present disclosure are directed to providing an LZ77 encoder, an LZ77 encoding method and a data compression device to improve data compression efficiency.
[0005] In one aspect of the present disclosure, a LZ77 encoder is provided, wherein the LZ77 encoder is used to parallelize LZ77 encoding of a string group within one clock cycle to obtain code element information of the string group, wherein the string group comes from data to be compressed, and a string group contains two or more strings; wherein the LZ77 encoder includes a hash processing module, wherein a hash dictionary in the hash processing module includes multiple partitions, each partition includes multiple storage blocks, and the storage blocks are physical RAMs, and the hash processing module is used to address partitions and storage blocks in the hash dictionary according to hash values of each string in the string group, so as to perform parallel hash processing on the string group.
[0006] In some implementations, the hash dictionary uses a multi-level RAM structure.
[0007] In some implementations, the partition includes a storage block for writing data and multiple storage blocks for reading data, and the multiple storage blocks for reading data are in a hash linked list structure.
[0008] In some implementations, the hash processing module is also used to calculate the location information of each string in the string group; the storage block includes a first RAM and a second RAM that can be accessed simultaneously, the first RAM is used to store the content of the string, and the second RAM is used to store the location information of the string.
[0009] In some embodiments, the partition also includes: a first register and a second register; wherein the first register is used to record the value of a block counter, and the value of the block counter indicates a currently writable storage block; the second register is used to store the value of a high-validity identification bit, and the high-validity identification bit is used to indicate whether all storage blocks in the partition are readable.
[0010] In some embodiments, the hash processing module is used to address the partitions and storage blocks in the hash dictionary in the following manner: calculate the hash value of the string; and determine the partition address and RAM row address corresponding to the string based on the hash value of the string, the partition address is used to address the partition in the hash dictionary, and the RAM row address is used to address the RAM row of the storage block.
[0011] In some implementations, the hash processing module is further used to write the string into the hash dictionary after addressing the partition and storage block in the hash dictionary according to the hash value, and simultaneously query the existing string in the hash dictionary to obtain candidate matching information of the string.
[0012] In some implementations, the storage block has an identifier, and the identifier of the storage block is used as a valid flag bit of an existing character string in the hash dictionary.
[0013] In some implementations, the hash processing module is used to access the corresponding partition in the hash dictionary according to the partition address, and cyclically write data to the corresponding RAM rows of each storage block in the partition in turn according to the RAM row address, thereby writing the string into the hash dictionary.
[0014] In some embodiments, the hash processing module is used to write the string into the storage block indicated by the value of the block counter in the first register; and to read in parallel each storage block in the partition except the writable storage block indicated by the value of the block calculator to query the existing string in the hash dictionary to obtain candidate matching information of the string when the value of the high-significant identification bit in the second register indicates that all storage blocks in the partition are readable.
[0015] In some embodiments, the LZ77 encoder further includes: a string matching module and a trimming matching module; the string matching module is used to perform parallel matching search based on the position information of each string in the string group and the candidate matching item information to obtain the first code element information of the string group; the trimming matching module is used to perform parallel trimming based on the position information of each string in the string group and its first code element information to obtain the second code element information of the string group.
[0016] In some implementations, the character strings in the character string group are of equal length and adjacent character strings overlap each other by a predetermined length.
[0017] One aspect of the present disclosure provides an LZ77 encoding method, which is executed by the above-mentioned LZ77 encoder.
[0018] In one aspect of the present disclosure, a data compression device is provided, comprising the above-mentioned LZ77 encoder and a Huffman encoder, wherein the Huffman encoder is used to perform Huffman encoding on the code element information of the string group to obtain a coded code stream of the string group.
[0019] In some implementations, the data compression device further includes one or more of the following:
[0020] An input buffer unit, used for instantiating the string group from the serial string of the data to be compressed according to a pre-configured parallel window size;
[0021] A code stream packing unit, used for packing the coded code stream obtained by the Huffman encoder and aligning the byte boundary to obtain compressed data;
[0022] The output buffer unit can be used to output buffer the compressed data packaged by the code stream packaging unit.
[0023] According to the disclosed embodiment, the hash dictionary is formed by a physical RAM, which can perform parallel LZ77 encoding on multiple character strings at the same time, effectively improving data compression efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 It is a schematic diagram of the structure of the LZ77 encoder provided in an embodiment of the present application;
[0026] Figure 2 is an example diagram of a string group involved in an embodiment of the present application;
[0027] Figure 3 is an example diagram of the partition structure of the hash dictionary involved in the embodiment of the present application;
[0028] Figure 4 is an example diagram of a storage block structure of a single partition involved in an embodiment of the present application;
[0029] Figure 5 is an exemplary composition structure diagram of the LZ77 encoder provided in an embodiment of the present application;
[0030] Figure 6 It is a schematic diagram of the LZ77 encoding method provided in an embodiment of the present application;
[0031] Figure 7 : is a schematic diagram of an exemplary implementation flow of the LZ77 encoding method provided in an embodiment of the present application;
[0032] Figure 8 This is an example diagram of a hash function involving an embodiment of the present application with three characters as input variables;
[0033] Fig. 9 This is an example diagram of a partition read-write conflict involved in an embodiment of the present application;
[0034] Fig.10 This is an example diagram of overlapping matching within a parallel window involved in an embodiment of the present application;
[0035] Fig.11 is an example diagram of overlapping matching between parallel windows involved in an embodiment of the present application;
[0036] Fig.12 It is a structural schematic diagram of a data compression device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0038] Figure 1 FIG. 1 shows a schematic diagram of the structure of the LZ77 encoder provided by an embodiment of the present disclosure. Figure 1 As shown, the LZ77 encoder 100 provided in the embodiment of the present disclosure can be used to perform parallel LZ77 encoding on a string group within one clock cycle to obtain the code element information of the string group.
[0039] The LZ77 encoder 100 includes a hash processing module, in which a hash dictionary includes multiple partitions (banks), each partition includes multiple storage blocks (blocks) (for example, n blocks, where n is an integer greater than 1), and the storage blocks are physical RAMs. The partitions and storage blocks in the hash dictionary can be addressed according to the hash values generated by the LZ77 encoder during the encoding process. The hash processing module can be used to address the partitions and storage blocks in the hash dictionary according to the hash values of each string in the string group to perform parallel hash processing on the string group.
[0040] The string group comes from the data to be compressed, and a string group may include two or more strings. In some implementations, the strings in each string group may be of equal length and overlap with each other by a predetermined length, and the length of a single string in the string group, the predetermined length of overlap of adjacent strings, and the number of strings in the string group may all be flexibly set according to actual needs.
[0041] In some implementations, the string group can be instantiated from the serial string in the data to be compressed according to a preset parallelization window size (parallelization window size, pws), and the number of strings in the string group and the length of a single string can be determined according to the parallel window size. Assuming that the size of the parallel window (window) of the LZ77 encoder 100 is Q, the number of strings in the string group can be set to Q, the length of a single string is also set to Q, the length of the overlapping of adjacent strings can be set to Q-1 or other values, and the Q strings processed in parallel can be regarded as a processing window. Q is an integer greater than 3. For example, Q can take values such as 8 and 16.
[0042] Figure 2 An example diagram showing a string group is shown. Figure 2 As shown, when Q=8, the characters in the parallel window window0 are numbered from 0 to 7 according to the byte order, and the characters in the parallel window window1 are numbered from 8 to 15. The serial strings (0 to 15) in the adjacent parallel windows window0 and window1 can be instantiated into 8 strings, and the length of each string is 8, that is, 0-7 bytes are used as string 0, 1-8 bytes are used as string 1, and so on until 7-14 bytes are used as string 7. The 8 strings (i.e., string 0 to string 7) form a string group.
[0043] See also Figure 1, the hash dictionary may include m partitions, each partition includes n storage blocks, m is an integer greater than 1, and n is an integer greater than 1. The partition may have an identifier, and the storage block may have an identifier. The identifier of the storage block can be used as a valid flag bit of an existing string in the hash dictionary (that is, a valid flag bit of the string corresponding to the candidate match item), so that parallel matching and searching can be performed through the valid flag bit during the LZ77 encoding process.
[0044] In an example, the identifier of a storage block can be a storage block number, the identifier of a partition can be a partition number, multiple partitions in the hash dictionary can be numbered sequentially, and the storage blocks in each partition can also be numbered sequentially. Figure 1 , when the hash dictionary contains m partitions and each partition contains n storage blocks, the storage block numbers can be sequentially set to: Block0, Block1, ..., Block-n-1, and the partition numbers can be sequentially set to: Bank0, Bank1, ..., Bank-m-1.
[0045] The number of partitions in the hash dictionary can be determined based on the number of strings in the string group (that is, the number of parallelized strings of the LZ77 encoder). Considering that the existing strings in the hash dictionary need to be queried while writing strings to the hash dictionary during the LZ77 encoding process, in order to reduce read-write conflicts, the number of partitions can be an integer multiple of the number of parallel strings Q. For example, the number of partitions can be equal to the number of parallel strings Q, and the partition depth is 256. For another example, considering that the sliding window capacity required by the deflate algorithm specification is 32kB, that is, the hash dictionary needs to store 32kB of data, therefore, preferably, the hash dictionary can contain 2*Q partitions, and the partition depth is 256.
[0046] Figure 3 An example diagram of the partition structure of a hash dictionary is shown. Figure 3 , assuming that the number of strings processed in parallel by the LZ77 encoder in one clock cycle (ie, the number of strings in a string group) is 8, 2*8=16 partitions can be set in the hash dictionary, and these partitions are: Bank0, Bank1, ..., Bank15.
[0047] The hash dictionary may adopt a single-level RAM structure or a multi-level RAM structure. Preferably, the hash dictionary may adopt a multi-level RAM structure to better support parallel reading and writing. For example, multiple storage blocks in each partition may adopt a hash linked list structure to form a hash dictionary of a multi-level RAM structure. In some embodiments, each partition may include a storage block for writing data and multiple storage blocks for reading data, and the multiple storage blocks for reading data are in a hash linked list structure, and the address lines of each storage block in the partition are connected to the address port of the partition to receive a RAM row address, and the RAM row address is used to address the RAM row of the storage block in the partition, and the RAM row address can be obtained according to the hash value.
[0048] It has been verified that four matching items in LZ77 encoding can achieve the best matching efficiency. Therefore, in some implementations, one partition may include four storage blocks for reading data. That is, preferably, one partition may include one storage block for reading data and four storage blocks for reading data. Figure 4 An example diagram of a partitioned storage block structure is shown. Figure 3 and Figure 4 Each partition can contain 5 storage blocks Block0~Block5. The first storage block Block0 is used to write data, and the other 4 storage blocks Block1~Block4 are used to read data. Storage blocks Block1~Block4 are hash linked list structures, which can solve read-write conflicts when continuous hash hits occur.
[0049] The hash processing module can also be used to calculate the position information of each string in the string group. The position information of the string can be used for hash conflict resolution in parallel hash processing, subsequent parallel matching search and parallel pruning, etc. Figure 4 , a storage block may include a first RAM and a second RAM that can be accessed simultaneously, the first RAM is used to store the content of the string, and the second RAM is used to store the position information of the string. The position information of the string is used to indicate the position of the first character in the string in the data to be compressed. For example, the position information of the string may be the distance between the first character of the string and the first character of the data to be compressed, and the distance may be represented by the number of characters or the number of bytes.
[0050] See also Figure 4 , the address line of the first RAM is connected to the address line of the second RAM and connected to the address port of the partition, the first RAM and the second RAM can simultaneously use the RAM row address as the receiving address, and the first RAM and the second RAM can be accessed simultaneously.
[0051] The bit width of the first RAM can be determined according to the length of a single string and the number of strings in a string group. For example, in order to better avoid read-write conflicts, the bit width of the first RAM can be the product of the length of a single string and the number of strings in a string group. For example, if the length of a single string is 8 and the number of strings in a string group is also 8, the bit width of the first RAM can be set to 64, and the depth of the first RAM can be set to 256.
[0052] The bit width of the second RAM can be flexibly set as needed. For example, if the length of a single string is 8, and the number of strings in a string group is also 8, the bit width of the second RAM can be set to 15, and the depth of the second RAM can be set to 256.
[0053] In some implementations, the partition may further include: a first register and a second register, the first register being used to record the value of a block counter, the value of the block counter indicating the currently writable storage block; the second register being used to store the value of a high-validity flag, the high-validity flag being used to indicate whether all storage blocks in the partition are readable. When a string group arrives, for each string in the string group, the hash processing module may determine the currently writable storage block through the block counter value of the first register in the partition, and jointly determine to read one or more of the other storage blocks through the high-validity flag value of the second register and the block counter value of the first register to complete the candidate matching query of the string. It can be seen that the hash processing module can read and write each storage block in the partition efficiently, quickly and in parallel by querying the value of the first register and the value of the second register.
[0054] In some implementations, the first register may be a 3-bit wide register, and the value of the block counter in the first register may be a binary number of a storage block identifier. Figure 4 For example, assuming that a partition contains 5 storage blocks, the storage blocks are numbered Block0 to Block4, the value of the block counter in the first register can be a binary number from 0 to 4, the reset value and initial value of the block counter are both 0, and the block counter is reset to 0 after the value reaches 5.
[0055] In some implementations, the value of the high-significant flag in the second register is used to indicate whether the high-significant flag is valid. If the high-significant flag is valid, it indicates that all storage blocks in the partition are readable. If the high-significant flag is invalid, only some storage blocks in the partition are readable or no storage blocks are readable. For example, the high-significant flag can have two values, 0 and 1, respectively. "1" indicates that the high-significant flag is valid, and "0" indicates that the high-significant flag is invalid.
[0056] After the block counter is fully loaded and reset for the first time, all storage blocks in the partition have been written to the string. At this time, the high-effective flag can be set to valid, indicating that all storage blocks in the partition are readable. Once the high-effective flag is set to valid, it will remain valid during the parallel LZ77 encoding of a string group. After the parallel LZ77 encoding of a string group is completed, the high-effective flag in the second register will be cleared to 0, and the block counter in the first register will be cleared to 0, indicating that the entire hash dictionary is cleared.
[0057] In some implementations, the hash processing module may perform cyclic reading and writing of each storage block in the partition according to the value of the first register and the value of the second register to complete its parallel hash processing. Table 1 shows Figure 4 The partition structure shown in the figure shows the readable storage block, writable storage block, high-signal bit value and block counter value in the cyclic read and write process. Figure 4 When the partition structure is used, the cyclic write order of the storage blocks in each partition can be set to: Block0→Block1→Block2→Block3→Block4. When the high effective flag indicates that only some storage blocks are readable, the cyclic read order of the storage blocks in the partition can be: Block0→Block0&Block1→Block0&Block1&Block2→Block0&Block1&Block2&Block3. When the high effective flag indicates that all storage blocks are readable, the cyclic read order in the partition can be: Block1&Block2&Block3&Block4→Block0&Block2&Block3&Block4→Block0&Block1&Block3&Block4→Block0&Block1&Block2&Block4→Block0&Block1&Block2&Block3.
[0058] Table 1
[0059]
[0060]
[0061] See also Figure 4 The first register and the second register can be set at the address port of the partition or other suitable positions, so that the hash processing module can query the value of the first register and the value of the second register while accessing each storage block in the partition.
[0062] It should be noted that Figure 4It is only an example. Those skilled in the art should understand that in a specific application, the specific structure of each storage block in the partition, the deployment mode of the first register and the second register, etc. can adopt any other applicable mode, and the embodiments of the present disclosure do not limit this.
[0063] In some embodiments, the hash processing module 110 can be used to address partitions and storage blocks in the hash dictionary in the following manner: calculate the hash value of the string, determine the partition address and RAM row address corresponding to the string based on the hash value of the string, the partition address is used to address the partition in the hash dictionary, and the RAM row address is used to address the RAM row in the storage block.
[0064] In one example, the hash value may include a first address field and a second address field, the first address field can be used to determine a partition address, and the second address field can be used to determine a RAM address. For example, the first address field can be used directly as a partition address, and the second address field can be used directly as a RAM address. For another example, a preset address conversion method can be used to convert the first address field into a partition address, and a preset address conversion method can be used to convert the second address field into a RAM row address. Of course, this is only an example, and it should be understood that any other applicable methods are applied to the embodiments of the present disclosure to obtain partition addresses and RAM addresses through hash value calculations.
[0065] The length of the first address field and the length of the second address field can be preset according to factors such as the number of strings in the string group, the length of the string, the partitioning conditions, the capacity of the RAM in the storage block, etc. For example, see Figure 5 As shown in the figure, when the string length is 8 and the string contains 8 strings, the hash value calculated by the hash processing module is 12 bits. The lower 4 bits of the 12-bit hash value can be used as the partition address, and the upper 8 bits can be used as the RAM row address. If 4*Q partitioning is used (Q is the string length or the number of strings in the string group), the lower 5 bits of the hash value can be used as the partition address, and the upper 7 bits can be used as the RAM row address of the storage block. Here, high and low are used to describe the domain segment of the address.
[0066] The hash processing module 110 can be used to perform parallel hash processing on the string group. In addition to addressing the partitions and storage blocks in the hash dictionary, the parallel hash processing can also include but is not limited to: writing the string into the hash dictionary and querying the existing string in the hash dictionary to obtain candidate matching information of the string.
[0067] After determining the partition address and RAM row address of each string, the hash processing module can be used to access the corresponding partition in the hash dictionary according to the partition address, and cyclically write data to the corresponding RAM row of each storage block in the partition according to the RAM row address, so as to write the string into the hash dictionary. In this way, the string newly written into the hash dictionary will overwrite the existing string farthest from the newly written string in the hash dictionary, that is, the newly written string will overwrite the oldest string in the hash dictionary, thereby realizing pipeline parallel LZ77 encoding, which can further improve the efficiency of LZ77 encoding.
[0068] In some implementations, the hash processing module can be used to write the string into the storage block indicated by the value of the block counter in the first register, and can also be used to read all storage blocks in the partition except the writable storage block indicated by the value of the block counter in the first register in parallel when the value of the high effective flag bit in the second register indicates that all storage blocks in the partition are readable, so as to efficiently complete the query of the existing string in the hash dictionary and obtain the candidate matching item information of the string. Thus, the hash processing module can cyclically read and write the storage blocks in each partition in the hash dictionary according to the value of the first register and the value of the second register, so as to complete the writing of the string and the query of the candidate matching items.
[0069] Specifically, the operation of the hash processing module writing a string into the hash dictionary may include: writing the current string into the RAM row address of the first RAM in the storage block, and writing the location information of the current string into the RAM row address of the second RAM in the storage block.
[0070] Specifically, the operation of the hash processing module querying an existing string in the hash dictionary to obtain candidate matching item information of the string may include: reading out an existing string in the hash dictionary that overlaps with the current string (i.e., the content of the candidate matching item) from the first RAM of the storage block, and simultaneously reading the location information of the existing string from the second RAM of the storage block to form candidate matching item information of the current string.
[0071] Figure 5 An exemplary structural diagram of the LZ77 encoder provided by the embodiment of the present disclosure is shown. Figure 5 In addition to the aforementioned hash processing module 110 (the hash processing module 110 includes a hash dictionary 111, which is the aforementioned hash dictionary), the LZ77 encoder 100 may also include: a string matching module 120 and a matching pruning module 130. The main functions of the string matching module 120 and the matching pruning module 130 are as follows:
[0072] The string matching module 120 may be used to perform parallel matching search on the string group according to the position information of each string in the string group and the candidate matching item information to obtain the first code element information of the string group;
[0073] The trimming and matching module 130 may be used to perform parallel trimming of the string group and its matching items according to the position information of each string in the string group and its first code element information to obtain the second code element information of the string group.
[0074] For the specific implementation of the parallel hash processing of the hash processor module 110, the parallel matching search of the string matching module 120, and the parallel pruning of the trimming matching module 130, please refer to the method part below, which will not be repeated here.
[0075] It should be noted that the data to be compressed referred to herein may be text, images or other data types that need to be compressed. The embodiment of the present disclosure does not limit the size, type and acquisition method of the data to be compressed.
[0076] The LZ77 encoder of the disclosed embodiment can perform parallel LZ77 encoding on multiple character strings, thereby effectively improving data compression efficiency.
[0077] The disclosed embodiment also provides a LZ77 encoding method, which is executed by the LZ77 encoder described above.
[0078] Figure 6 FIG. 1 is a flowchart of the LZ77 encoding method provided by an embodiment of the present disclosure. Figure 6 , the method 600 may include: performing parallel LZ77 encoding on a string group within a clock cycle to obtain code element information of the string group, the string group comes from the data to be compressed, and a string group contains two or more strings; wherein the parallel LZ77 encoding includes: performing parallel hash processing on the string group, the parallel hash processing includes: addressing partitions and storage blocks in a hash dictionary according to the hash value of each string, the hash dictionary includes multiple partitions, each partition includes multiple storage blocks, and the storage block is a physical RAM.
[0079] Figure 7 FIG. 6 shows an exemplary implementation process of the method 600 according to an embodiment of the present disclosure. Figure 7 , the method 600 of the embodiment of the present disclosure may include the following steps:
[0080] Step 601, parallel hash processing, that is, parallel hash processing is performed on the character string, and the parallel hash processing includes: addressing partitions and storage blocks in the hash dictionary according to the hash value of each character string;
[0081] Step 602, parallel matching search, that is, performing parallel matching search according to the position information of each string in the string group and the candidate matching item information to obtain the first code element information of the string group;
[0082] Step 603 , parallel pruning, that is, performing parallel pruning according to the position information of each string in the string group and the first symbol information thereof to obtain the second symbol information of the string group.
[0083] The specific implementation of each step in method 600 is described in detail below.
[0084] In step 601, addressing the partitions and storage blocks in the hash dictionary according to the hash values of each string may include: calculating the hash value of the string, determining the partition address and RAM row address of the string according to the hash value of the string, the partition address is used to address the partition in the hash dictionary, and the RAM row address is used to address the RAM row in the storage block. For the specific implementation method of determining the partition address and RAM row address by hash value, please refer to the above LZ77 encoder part, which will not be repeated here.
[0085] In step 601, after addressing the partitions and storage blocks in the hash dictionary, the process may further include: writing the character string into the hash dictionary, and simultaneously searching the existing character string in the hash dictionary to obtain candidate matching information of the character string.
[0086] In some implementations, step 601 may further include: calculating the position information of each string in the string group. In step 601, the partition in the hash dictionary may be accessed according to the partition address of the string, the content of the string may be written into a corresponding row of a first RAM of a currently writable storage block in the partition according to the RAM row address of the string, and the position information of the string may be written into a corresponding row of a second RAM of a currently writable storage block in the partition according to the RAM row address of the string.
[0087] Specifically, data can be written to the corresponding RAM row in the storage block indicated by the value of the block counter in the first register according to the RAM row address; and when the value of the high effective flag bit in the second register indicates that all storage blocks of the corresponding partition are readable, each storage block in the partition except the writable storage block indicated by the value of the block counter in the first register is read in parallel. Thus, the parallel reading and writing of the string and the pipeline hash processing can be realized through the first register and the second register, further improving the efficiency of LZ77 encoding.
[0088] A candidate match item refers to an existing string in the hash dictionary that has duplicate characters with the current string. The candidate match item information may include, but is not limited to, the valid flag of the candidate match item and the content of the string corresponding to the candidate match item. The valid flag of the candidate match item can be represented by the identifier of the storage block in the hash dictionary that stores the string corresponding to the candidate match item. For example, the length of the valid flag of the candidate match item is the same as the length of the string corresponding to the candidate match item. Each bit in the valid flag is the identifier of the storage block in the hash dictionary that stores the character at the corresponding bit in the corresponding string.
[0089] In some embodiments, the candidate match item information may include the content, position information, valid flag bits of the character string corresponding to the candidate match item, and its matching length and matching distance with the current character string. The matching length is used to indicate the number of overlapping characters between the current character string and its candidate match item. The matching distance can be the distance between the character string and the candidate match item, which can be but is not limited to the distance between the first character of the current character string and the first character of the candidate match item, and the distance is the number of characters or bytes.
[0090] In some implementations, writing a string into a hash dictionary includes: accessing a corresponding partition in the hash dictionary according to a partition address, and cyclically writing data to a corresponding RAM row of each storage block in the partition in turn according to a RAM row address. By writing a string into the RAM of each storage block in the hash dictionary in a cyclic writing manner, only a partition address and a RAM row address are required to complete the string writing. In the process of writing the string, there is no need to locate the storage block in real time. While realizing parallel writing of each string in the string group, pipeline hash processing is realized, further improving the efficiency of LZ77 encoding.
[0091] Exemplarily, the specific implementation process of the parallel hash processing in step 601 may include the following steps a1 to a4:
[0092] Step a1, parallelize the calculation of the hash value and position information of each string in the string group.
[0093] For each string, some characters can be selected from the string as the input variables of the hash function according to the length of the input variable of the hash function, and the hash function can be used to perform hash calculation to obtain the hash value of the string. A part of the address field in the hash value is used to determine the partition address in the hash dictionary, and another part of the address field is used to determine the RAM row address of the storage block in the partition. For example, when the string length is 8 and the string group contains 8 strings, 3 characters in the string can be used as the input variables of the hash function for hash calculation to generate a 12-bit hash value. Figure 7 A diagram showing an example of input variables for a hash function. Figure 7, when the string length is 8 and the string group contains 8 strings, the first 3 characters in a string can be used as input variables of the hash function for hash calculation.
[0094] In the process of hash calculation using hash functions, the hash processing module can obtain uniformly randomly distributed hash values by performing multiplication, XOR and shift operations on the string to minimize the number of hash conflicts in the string, thereby providing a higher compression ratio.
[0095] In one example, the hash processing module uses a hash function to perform a parallel hash calculation on each string in the string group. The parallel hash calculation can be expressed as follows:
[0096] {for(i=0;i <Q;i++)loop
[0097] hash_value[i]=(current_window[i]x31)⊕current_window[i+1];
[0098] hash_value[i]=hash_value[i]<<3;
[0099] hash_value[i]=hash_value[i]x3)⊕current_window[i+2];
[0100] hash_value[i]=hash_value[i]<<4;
[0101] hash_value[i]=(hash_value[i]x3)⊕current_window[i+3];
[0102] hash_value[i]=hash_value[i]<<5;
[0103] hash_value[i]=(hash_value[i]x3)⊕current_window[i+4];
[0104] endfor}
[0105] Among them, for represents a for loop, hash_value represents a hash value, i represents a string number, "x" represents multiplication, << represents a shift operation, and ⊕ represents an XOR operation. The input of the hash calculation can be the parallel processing window current_window[2*Q], and the output of the hash calculation is the hash value hash_value[Q] of the string group, where Q represents the number of strings in the string group.
[0106] While performing the hash calculation on the string group in parallel, the position information of each string in the string group can be calculated in parallel. The position information of a string can be the distance between the first character of the string and the first character of the data to be compressed.
[0107] Step a2, handling hash conflicts;
[0108] Hash conflicts include but are not limited to read-write conflicts caused by two or more strings needing to access the same partition or the same storage block in the hash dictionary at the same time. Fig. 9 An example diagram showing two strings in the same string group needing to access the same partition at the same time. Fig. 9 As shown, string 1 and string 3 need to access partition 2 at the same time, resulting in a hash conflict.
[0109] Since the RAM address port resources are limited, and some RAM address ports have only one, the above hash conflicts need to be resolved to avoid affecting the LZ77 encoding efficiency due to data congestion. Considering that the hash value directly determines the partition address and RAM address, it is possible to directly determine whether a hash conflict will occur based on the hash value of the string. If a hash conflict occurs, timely measures can be taken to avoid data congestion.
[0110] In some implementations, when it is determined that a hash conflict may occur, one string may be selected from two or more strings that may have a hash conflict to continue subsequent addressing and other processing, while the other strings may not be processed and output in the form of original characters. In this way, although a certain compression rate will be lost, the pipeline blockage of the LZ77 code can be avoided, which is conducive to improving hardware utilization, reducing costs and improving overall compression efficiency.
[0111] In some implementations, if the hash values of two or more strings in the same string group are partially the same, these strings will most likely have a hash conflict, and subsequent addressing and other processing can be performed on only one of these strings, while the other strings can be directly output as original characters without subsequent processing.
[0112] In an example, if the first address field in the hash values of two or more strings in the same string group is the same, it indicates that the partition addresses of these strings will be the same, and these strings will need to access the same partition at the same time. At this time, subsequent addressing and other hash processing can be performed on one of the strings, while for other strings, no subsequent processing is required and the original characters can be directly output.
[0113] In an example, if the first address field in the hash values of two or more strings in the same string group is the same, it indicates that the partition addresses of these strings will be the same, and these strings will need to access the same partition at the same time. At this time, subsequent addressing and other hash processing can be performed on one of the strings, while for other strings, no subsequent processing is required and the original characters can be directly output.
[0114] In an example, if the first address field and the second address field in the hash values of two or more strings in the same string group are the same, and the partition has only one writable storage block, it indicates that the partition address and RAM row address of these strings will be the same, and these strings are likely to need to access the same RAM row of the same storage block in the same partition at the same time. At this time, subsequent addressing and other processing can be performed on one of the strings, while no subsequent processing is required for the other strings, and the original characters can be directly output.
[0115] In some implementations, considering that the string that is sorted later may continue to perform LZ77 encoding in subsequent processing, therefore, among two or more strings that may have hash conflicts, one of the strings can be selected according to the position information of the string to continue the subsequent addressing and other processing, while the other strings may not be processed subsequently. For example, the string with the smallest position information value, that is, the string at the front, can be selected to continue the subsequent processing. For another example, any string with a position information value in the first x bits (x is an integer greater than 1, and x is less than the total number of strings with hash conflicts), that is, any string in the x front strings, can be selected to perform subsequent addressing and other processing. Here, the string at the front refers to the string with the smallest distance between the first character and the first character of the data to be compressed relative to other strings, that is, the string with the smallest value of position information.
[0116] In some implementations, the strings in each string group may be numbered, and the string numbers may be sorted from front to back according to the positions of the strings, with strings with larger numbers being positioned further back and strings with smaller numbers being positioned further forward. Figure 2 In the example of , the string group contains 8 strings, and the strings are numbered 0 to 7. The string numbered 0 is located at the front, and the string numbered 7 is located at the back, that is, the first character of the string numbered 0 is closest to the first character of the data to be compressed, and the first character of the string numbered 7 is farthest from the first character of the data to be compressed. At this time, among two or more strings that may have hash conflicts, subsequent addressing and other processing can be continued for any string of the x strings with relatively smaller numbers, and other strings can be left unprocessed.
[0117] See also Figure 8For example, the subsequent addressing and other processing can be performed on the string 1 with a smaller number, and no subsequent processing can be performed on the string 3, and the string 3 can be output in the form of original characters.
[0118] Step a3, performing address decoding according to the hash value to obtain the partition address and RAM row address of each string in the string group, writing each string in the string group into the hash dictionary in parallel according to the partition address and RAM row address, and querying the existing strings in the hash dictionary to obtain the candidate matching information of each string in the string group.
[0119] In some implementations, the match length may be calculated by reading the content of the string corresponding to the candidate match item from the hash dictionary (i.e., the existing string stored in the hash dictionary) and comparing it byte by byte with the current string to obtain the number of overlapping characters between the candidate match item and the current string, which is the match length of the candidate match item. If the starting bytes of the candidate match item and the current string are different, the match length is 0, i.e., no match. If the match length between the candidate match item and the current string is less than 3, it is an invalid match and is excluded. For example, if the first 5 bytes of the current string and the candidate match item are the same, and the 6th byte is different, the match length of the two is 5. If the starting bytes of the current string and the candidate match item are different, the match length of the two is 0.
[0120] Step a4: outputting the original content, position information and candidate matching information of each string in the string group to provide them to the string matching module for subsequent parallel search and matching.
[0121] Step 602 can be performed by the string matching module described above. Specifically, in step 602, the string group can be matched and searched in parallel according to the position information of each string in the string group and its candidate matching information to obtain the first code element information of the string group. The first code element information may include but is not limited to the original character and the matching tuple. The original character is the character for which the first matching item is not found after the string is encoded by LZ77 (for example, the string is selected to be directly output without subsequent processing due to hash conflict, etc.). A matching tuple includes the matching length and matching distance of a first matching item. The matching tuple can be expressed as<len,dist> , len represents the matching length of the first matching item, and dist represents the matching distance of the first matching item. In addition, the first code element information may also include: a character identifier, which is used to indicate which bytes of the string in the string group output the original characters and which bytes output the matching tuple after LZ77 encoding. For example, if the string is an 8-bit character, its character identifier may also be 8 bits, and the value of a certain bit in the character identifier may indicate whether the character at the corresponding bit in the string outputs the original character or the matching tuple.
[0122] The first match item can be selected from the candidate match items according to the match length. If the string has only one candidate match item, the candidate match item can be used as its first match item. If the string has two or more candidate match items, the candidate match item with the longest match length among the two or more candidate match items is used as the first match item of the string.
[0123] Exemplarily, the specific implementation process of the parallel matching search in step 602 may include the following steps b1 to b3:
[0124] Step b1, selecting a valid matching item from candidate matching items according to the matching length;
[0125] Specifically, if the matching length between the candidate match and the current string is less than 3, it is an invalid match and is excluded. If the matching length between the candidate match and the current string is greater than or equal to 3, it is a valid match.
[0126] Step b2: for each character string in the character string group, compare the matching lengths of its valid matching items, select the first matching item of the character string from the valid matching items, and set the valid flag bits of other valid matching items of the character string to 0.
[0127] Step b3: for each character string in the character string group, calculate the matching distance between the character string and its first matching item.
[0128] For example, the matching distance between the string and its first matching item can be obtained by subtracting the position information of the first matching item from the position information of the string, and the difference is the matching distance between the string and the first matching item. The position information of the string and the position information of the first matching item can be read from the second RAM of the corresponding storage block of the hash dictionary.
[0129] Given that there may be matching overlap problems between parallel windows and within parallel windows. Fig.10 shows an example diagram of matching overlap within a parallel window, Fig.11 Figure 2 shows a schematic diagram of matching overlap between parallel windows. Fig.10 and Fig.11 After the hash processing module and the string matching module obtain the first code element information of the string group, it is necessary to eliminate these matching overlaps to further improve the compression rate of the LZ77 encoder. Step 603 in method 600 can eliminate these matching overlaps.
[0130] The parallel pruning of step 603 can be performed by the matching pruning module 130 mentioned above. Specifically, in step 603, the string group and its first matching item can be parallelized and pruned according to the position information of each string in the string group and its first code element information to obtain the second code element information of the string group, and the second code element information includes: the original string, the second matching tuple, and the second matching tuple includes the matching length and matching distance of the second matching item. The second code element information can also include: the character identifier of the string, and the character identifier is used to indicate which bytes of the string in the string group output the original characters and which bytes output the matching tuple after LZ77 encoding. For example, if the string is an 8-bit character, its character identifier can also be 8 bits, and the value of a certain bit in the character identifier can indicate whether the character of the corresponding bit in the string outputs the original character or the matching tuple. The parallel pruning of step 603 can eliminate the matching overlap between parallel windows (for example, between window0 and window1 in the above text) and the matching overlap within the parallel window (for example, within window0 or window1 in the above text).
[0131] The parallel matching search in step 602 and the parallel pruning in step 603 may be implemented by using any applicable existing method, and the embodiments of the present disclosure do not impose any limitation on this.
[0132] In some implementations, before step 601, method 600 may further include: instantiating a string group from the serial string in the data to be compressed according to a preset parallel window size. Here, the specific implementation method of instantiating the string group can be referred to the above Figure 2 The records are not repeated here.
[0133] The LZ77 encoding method of the embodiment of the present disclosure can realize parallel LZ77 encoding of multiple character strings, which can effectively improve data compression efficiency.
[0134] The embodiment of the present disclosure also provides a data compression device. Fig.12 FIG. 1 is a schematic diagram showing the structure of a data compression device provided by an embodiment of the present disclosure. Fig.12 The data compression device 1200 may include the LZ77 encoder 100 and the Huffman encoder 300 described above. The Huffman encoder 300 may be used to perform Huffman encoding on the symbol information of the string group to obtain the encoded code stream of the string group. The data compression device of the disclosed embodiment can realize parallel encoding of the data to be compressed, efficiently and quickly complete data compression, and achieve the purpose of saving data storage resources.
[0135] In some implementations, the Huffman encoder 300 may use dynamic and / or static Huffman encoding to complete the parallel Huffman encoding of the string group. Among them, static Huffman uses a pre-defined code table, which is suitable for encoding information with a relatively fixed input character distribution, and will reduce the compression performance when the character distribution changes greatly. Dynamic Huffman encoding can dynamically encode according to the character ratings statistically obtained in the string, thereby obtaining a higher compression rate.
[0136] See also Fig.12 The data compression device 1200 of the embodiment of the present disclosure may also include one or more of the following: an input buffer unit 400, a code stream packaging unit 500, and an output buffer unit 700. The functions of each part are as follows:
[0137] An input buffer unit 400, which can be used to instantiate a string group from a serial string of data to be compressed according to a pre-configured parallel window size;
[0138] The code stream packing unit 500 may be used to pack the variable-length coded code stream obtained by the Huffman encoder 300 and align the byte boundaries to obtain compressed data.
[0139] The output buffer unit 700 may be used to output buffer the compressed data packaged by the code stream packaging unit 500.
[0140] The specific implementation method of the input buffer unit 400 to obtain the string group can be found in the above Figure 2 The records are not repeated here.
[0141] The LZ77 encoder 100 and the data compression device 1200 of the embodiment of the present disclosure can be implemented by an application specific integrated circuit (ASIC). The hash dictionary can be a RAM array in the ASIC. Since ASIC has the advantages of smaller size, lower power consumption, improved reliability, improved performance, enhanced confidentiality, and reduced cost compared with general integrated circuits in mass production, it is beneficial to reduce the manufacturing cost of the data compression device. The various modules of the LZ77 encoder can be circuit structures in the ASIC. For example, the hash processing module, the string matching module, and the matching pruning module can be independent circuit structures in the ASIC, and these circuit structures are connected to each other to form the LZ77 encoder 100. It can be understood that the LZ77 encoder and the data compression device of the embodiment of the present disclosure can also be implemented by other hardware circuits, such as FPGA, etc., and this is not limited by the embodiment of the present disclosure.
[0142] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. An LZ77 encoder, characterized in that: The LZ77 encoder is used for parallelizing LZ77 encoding of a string group within one clock cycle to obtain code element information of the string group, wherein the string group comes from the data to be compressed, and a string group includes two or more strings; Among them, the LZ77 encoder includes a hash processing module, the hash dictionary in the hash processing module includes multiple partitions, each partition includes multiple storage blocks, the storage block is a physical RAM, and the hash processing module is used to address the partitions and storage blocks in the hash dictionary according to the hash value of each string in the string group, so as to perform parallel hash processing on the string group.
2. The LZ77 encoder according to claim 1, characterized in that: The hash dictionary adopts a multi-level RAM structure.
3. The LZ77 encoder according to claim 2, characterized in that: The partition includes a storage block for writing data and multiple storage blocks for reading data, and the multiple storage blocks for reading data are in a hash linked list structure.
4. The LZ77 encoder according to claim 1, characterized in that: The hash processing module is further used to calculate the position information of each string in the string group; The storage block includes a first RAM and a second RAM that can be accessed simultaneously, the first RAM is used to store the content of the string, and the second RAM is used to store the location information of the string.
5. The LZ77 encoder according to claim 1, characterized in that: The partition also includes: a first register and a second register; wherein the first register is used to record the value of a block counter, the value of the block counter indicates a currently writable storage block; the second register is used to store the value of a high-validity identification bit, the high-validity identification bit is used to indicate whether all storage blocks in the partition are readable.
6. The LZ77 encoder according to claim 1, characterized in that: The hash processing module is used to address the partitions and storage blocks in the hash dictionary in the following manner: Calculating a hash value of the string; and, A partition address and a RAM row address corresponding to the string are determined according to the hash value of the string, the partition address is used to address a partition in the hash dictionary, and the RAM row address is used to address a RAM row of the storage block.
7. The LZ77 encoder according to any one of claims 1 to 6, characterized in that: The hash processing module is further used to write the string into the hash dictionary after addressing the partition and storage block in the hash dictionary according to the hash value, and query the existing string in the hash dictionary to obtain candidate matching item information of the string.
8. The LZ77 encoder according to claim 7, characterized in that: The storage block has an identifier, and the identifier of the storage block is used as a valid flag bit of an existing character string in the hash dictionary.
9. The LZ77 encoder according to claim 7, characterized in that: The hash processing module is used to access the corresponding partition in the hash dictionary according to the partition address, and cyclically write data to the corresponding RAM row of each storage block in the partition in turn according to the RAM row address, so as to write the string into the hash dictionary.
10. The LZ77 encoder according to claim 7, characterized in that: The hash processing module is used to write the string into the storage block indicated by the value of the block counter in the first register; and to read in parallel each storage block in the partition except the writable storage block indicated by the value of the block calculator to query the existing string in the hash dictionary to obtain candidate matching item information of the string when the value of the high effective identification bit in the second register indicates that all storage blocks in the partition are readable.
11. The LZ77 encoder according to claim 7, characterized in that: The LZ77 encoder also includes: a string matching module and a clipping matching module; The string matching module is used to perform parallel matching search according to the position information of each string in the string group and the candidate matching item information to obtain the first code element information of the string group; The trimming and matching module is used to perform parallel trimming according to the position information of each character string in the character string group and the first code element information thereof to obtain the second code element information of the character string group.
12. The LZ77 encoder according to claim 1, characterized in that: The character strings in the character string group are of equal length and adjacent character strings overlap each other by a predetermined length.
13. A LZ77 encoding method, characterized in that: The LZ77 encoding method is executed by the LZ77 encoder described in any one of claims 1 to 12.
14. A data compression device, characterized in that: It comprises the LZ77 encoder and the Huffman encoder as claimed in any one of claims 1 to 12, wherein the Huffman encoder is used to perform Huffman encoding on the code element information of the string group to obtain the encoded code stream of the string group.
15. The device according to claim 14, characterized in that Also includes one or more of the following: An input buffer unit, used for instantiating the string group from the serial string of the data to be compressed according to a pre-configured parallel window size; A code stream packing unit, used for packing the coded code stream obtained by the Huffman encoder and aligning the byte boundary to obtain compressed data; The output buffer unit can be used to output buffer the compressed data packaged by the code stream packaging unit.
