Decoding method, system and device and storage medium
By determining n-level comparisons based on the maximum code length in the Hoffman encoding and decoding method and generating the decoding code length, the problems of low decoding efficiency and large circuit area in the prior art are solved, and efficient decoding and Reduce hardware costs.
Patent Information
- Application Number
- CN202411317513.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2024-12-31
AI Technical Summary
The existing Hoffman encoding and decoding methods have problems such as low efficiency and large circuit area in hardware circuit design, especially in parallel mode, the circuit area is required to reconstruct Hoffman tree memory space. It's also very big.
By determining the n-level comparison based on the maximum code length of the data to be decoded, and selecting the corresponding maximum code for comparison at each level of comparison, an n-bit binary number is generated to determine the decoded code length, and then finding the original value in the encoding lookup table , reduce the number of comparators and improve decoding efficiency.
Decode a decoded data within each clock cycle, improves decoding efficiency and effectively reduces the area of the circuit hardware, especially in the case of a large maximum code length, which significantly reduces the hardware cost.
Smart Images

Figure CN119232172A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a decoding method, system, device and storage medium. Background Art
[0002] Huffman compression is a classic algorithm that splits the original value into symbols, counts the probability of each symbol appearing, and constructs a Huffman tree based on the frequency. Symbols with relatively high probabilities are encoded using shorter codes, and vice versa, they are encoded using longer codes to achieve lossless compression. This is a typical variable-length coding.
[0003] The paradigm Huffman coding proposes some mandatory rules based on Huffman coding. Then, according to the rules, the Huffman coding tree can be reconstructed using less data information.
[0004] Since Huffman coding is a variable-length coding, when decoding, it is necessary to compare the codes of each word length to determine the effective code length. In hardware circuit design, there are usually two implementation methods: serial and parallel. For the serial method, one shift and one comparison are performed in each clock cycle. This method has a small circuit area, but the efficiency is not high. The time for each piece of data depends on the length of the current code. For the parallel method, in order to decode a piece of data in each clock cycle, multiple comparators are required to compare simultaneously. The number of comparators depends on the maximum code length L after encoding. max , it is very efficient compared to the serial method, but the circuit area is large; there are also some parallel methods, which take the method of reconstructing the Huffman code tree and use the data to be decoded as the address for addressing. The logic is relatively simple and it can also decode one data per clock cycle, but the storage space required for the reconstructed Huffman tree is very large, and there is also the problem of large circuit area. Summary of the invention
[0005] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a decoding method, a decoding system, a method, a device and a storage medium, which can improve decoding efficiency and save hardware circuit area.
[0006] In a first aspect, a decoding method according to an embodiment of the present invention comprises the following steps:
[0007] According to the maximum code length L of the data to be decoded max , determine n = ceil (log2L max );
[0008] The data to be decoded is compared at the same time at the nth level. At the xth level comparison, if the value of the data to be decoded is less than or equal to the set code length M, xyThe maximum code of the x-th level comparison is 0, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y) The maximum code is compared with the value of the data to be decoded; if the value of the data to be decoded is greater than the set code length M xy The maximum code of the x-th level comparison is 1, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y+1) The maximum code is compared with the value of the data to be decoded, where 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the xth level comparison;
[0009] According to the n-level comparison result, an n-bit binary number is obtained, Result[n:1]={nth level result, ..., second level result, first level result}, and the decoding code length L of the data to be decoded is determined. decode =Result[n:1]+1.
[0010] According to some embodiments of the present invention, the following steps are also included:
[0011] According to the decoding code length L decode , find the corresponding original value in the encoding lookup table.
[0012] According to some embodiments of the present invention, the decoding code length L decode , the steps of searching for the corresponding original value in the encoding lookup table include:
[0013] According to the decoding code length L decode , determine the position value Position,
[0014]
[0015] According to the position value Position, the original value corresponding to the encoding lookup table is determined.
[0016] According to some embodiments of the present invention, when comparing the to-be-decoded data at the xth level, the code length M is set from z xy The corresponding maximum code in selects one of them and compares it with the value of the data to be decoded. The y value starts from zero and increases by one to the maximum value. z=2 x-1 .
[0017] In a second aspect, a decoding system according to an embodiment of the present invention includes:
[0018] The comparison module has n comparators, namely, the first-stage comparator, the second-stage comparator, ... the x-stage comparator ... the n-1-stage comparator and the n-stage comparator. The first input terminal of each stage comparator inputs the data to be decoded, n=ceil(log2Lmax ), L max is the maximum code length of the data to be decoded;
[0019] A signal generating module, wherein the n output terminals of the signal generating module are respectively electrically connected to the second input terminals corresponding to the first-stage comparator to the n-th-stage comparator, and the n-1 feedback terminals of the signal generating module are respectively electrically connected to the output terminals corresponding to the first-stage comparator to the n-1-th-stage comparator, and the output terminal corresponding to the signal generating module outputs the corresponding code length M according to the feedback signals of the n-1 feedback terminals. xy The maximum code, if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The signal generation module selects the input setting code length M to the second input terminal of the x+1th comparator. (x+1)(2y) The maximum code; if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The signal generation module selects the input setting code length M to the second input terminal of the x+1th comparator. (x+1)(2y+1) The maximum encoding, 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the x-th level comparator, y is an integer;
[0020] A decoding module is electrically connected to the output terminals of the first-level comparator to the n-th-level comparator, respectively. The decoding module can obtain an n-bit binary number according to the results of the first-level comparator to the n-th-level comparator, Result[n:1]={n-th-level result, ..., second-level result, first-level result}, so as to determine the decoding code length L of the data to be decoded. decode =Result[n:1]+1.
[0021] According to some embodiments of the present invention, the decoding module is further configured to: decode , find the corresponding original value in the encoding lookup table.
[0022] According to some embodiments of the present invention, the decoding code length L decode , the steps of searching for the corresponding original value in the encoding lookup table include:
[0023] According to the decoding code length L decode , determine the position value Position,
[0024]
[0025] According to the position value Position, the original value corresponding to the encoding lookup table is determined.
[0026] According to some embodiments of the present invention, each output terminal of the signal generation module will generate a signal from z set code lengths M xy The corresponding maximum code selects one of the outputs, and the y value starts from zero and increases by one to the maximum value, z = 2 x-1 , x is the value of the x-th level comparator corresponding to the output end of the signal generating module.
[0027] In a third aspect, a decoding device according to an embodiment of the present invention includes a memory and a processor, and the processor implements the decoding method as described in the above embodiment when executing a computer program stored in the memory.
[0028] In a fourth aspect, a storage medium according to an embodiment of the present invention stores program instructions thereon, and when the program instructions are executed by a processor, the decoding method as described in the above embodiment is implemented.
[0029] The embodiment of the present invention has at least the following beneficial effects: since the code length of the decoded data is compared by performing n levels of comparison at the same time, and each level of comparison has a corresponding set code length M xy Taking the maximum coded signal as the benchmark, an effective code length of decoded data can be decoded in each clock cycle, and the decoded data can be further obtained by obtaining the effective code length, that is, an original data can be decoded in each clock cycle, which effectively improves the decoding efficiency; and the decoding hardware involved is also effectively reduced compared with the existing method, effectively reducing the area of the circuit hardware.
[0030] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0032] Figure 1 A schematic diagram of a decoding method according to an embodiment of the present invention;
[0033] Figure 2 for Figure 1 A schematic diagram showing the process principle of the decoding method;
[0034] Figure 3 A schematic flowchart of a decoding method according to another embodiment of the present invention;
[0035] Figure 4 A schematic diagram of a coding lookup table of a decoding method according to Embodiment 1 of the present invention;
[0036] Figure 5A schematic diagram of the process principle of the decoding method according to the first embodiment of the present invention;
[0037] Figure 6 is a schematic structural diagram of a decoding system according to an embodiment of the present invention;
[0038] Figure 7 Schematic diagram of the structure of a decoding system according to Embodiment 1 of the present invention;
[0039] Figure 8 4 is a schematic diagram of the structure of a decoding device according to an embodiment of the present invention.
[0040] Reference numerals:
[0041] Label name Label name 100 Comparison Modules 400 Memory 200 Signal generation module 500 processor 300 Decoding module DETAILED DESCRIPTION
[0042] The following will be combined with the embodiments and drawings to clearly and completely describe the concept, specific structure and technical effects of the present invention, so as to fully understand the purpose, scheme and effect of the present invention. It should be noted that the embodiments and features in the embodiments of this application can be combined with each other without conflict.
[0043] It should be noted that, unless otherwise specified, when a feature is referred to as being "fixed" or "connected" to another feature, it may be directly fixed or connected to the other feature, or it may be indirectly fixed or connected to the other feature. In addition, the descriptions of up, down, left, right, top, bottom, etc. used in the present invention are only relative to the relative positional relationship of the components of the present invention in the drawings.
[0044] It should be noted that, unless otherwise specified, when a feature is referred to as being "electrically connected" or "electrically connected" to another feature, the two features may be directly connected via pins, or connected via cables, or connected via wireless transmission. The specific electrical connection method is a common method for those skilled in the art, and those skilled in the art can achieve the connection as needed.
[0045] In addition, unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by those skilled in the art. The terms used in this specification are only for describing specific embodiments, not for limiting the present invention. The term "and / or" used herein includes any combination of one or more related listed items.
[0046] It should be understood that, although the terms first, second, third, etc. may be used to describe various elements in the present disclosure, these elements should not be limited to these terms. These terms are only used to distinguish elements of the same type from each other. For example, without departing from the scope of the present disclosure, the first element may also be referred to as the second element, and similarly, the second element may also be referred to as the first element.
[0047] First, refer to Figure 1 , according to an embodiment of the present invention, the decoding method comprises the following steps:
[0048] S100, according to the maximum code length L of the data to be decoded max , determine n = ceil (log2L max );
[0049] S200, perform n-level comparisons on the data to be decoded at the same time. In the x-th level comparison, if the value of the data to be decoded is less than or equal to the set code length M xy The maximum code of the x-th level comparison is 0, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y) The maximum code is compared with the value of the data to be decoded; if the value of the data to be decoded is greater than the set code length M xy The maximum code of the x-th level comparison is 1, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y+1) The maximum code is compared with the value of the data to be decoded, where 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the xth level comparison;
[0050] S300, obtain an n-bit binary number according to the n-level comparison result, Result[n:1]={nth level result, ..., second level result, first level result}, and determine the decoding code length L of the data to be decoded decode =Result[n:1]+1.
[0051] It should be noted that before designing any decoding method, the designer knows in advance the maximum code length L of the data to be decoded. max Therefore, we can directly determine the number of levels n that need to be compared simultaneously, and also determine the set code length M of each level. xy Therefore, step S100 can be determined in the initial design. After the number of levels to be decoded is determined, when the same decoded data is subsequently decoded, the decoding code length can be obtained by directly executing steps S200 and S300 without repeating step S100. max ), represents n rounded upwards to an integer, according to the maximum code length L of the decoded data maxThe value of log2L is first calculated max , according to log2L max The final value is rounded up to an integer to determine n. It can also be backward compatible, that is, the maximum code length of the actual data to be decoded is less than or equal to 2n, then steps S100, S200 and S300 can be performed in sequence, that is, the number of levels currently required for comparison can be determined first, and the current number of levels for decoding comparison should be less than or equal to n set at the beginning.
[0052] In addition, it should be noted that, according to different encoding methods, the code length A of any data can be determined by combining the code length with the encoding lookup table to determine its corresponding maximum code as Code_max[A], so the code length M is set xy The maximum code is Code_max[M xy ].
[0053] Reference Figure 2 , when executing step S200, derivation can be performed from the first level to the nth level respectively,
[0054] First level, that is, x = 1, then 0 ≤ y ≤ 2 1-1 -1=0, then the setting code length corresponding to the first level is 1, which is M 10 , set the code length M 10 The corresponding maximum code is Code_max[M 10 ];
[0055] The second level, that is, x = 2, then 0 ≤ y ≤ 2 2-1 -1=1, then the setting code length corresponding to the second level is 2, which is M 20 and M 21 , the corresponding maximum codes are Code_max[M 20 ] and Code_max[M 21 ];
[0056] The third level, that is, x = 3, then 0 ≤ y ≤ 2 3-1 -1=3, then the setting code length corresponding to the second level is 4, which is M 30 、M 31 、M 32 and M 33 , the corresponding maximum codes are Code_max[M 30 ]、Code_max[M 31 ]、Code_max[M 32 ] and Code_max[M 33 ];
[0057] …
[0058] For level n-1, 0≤y≤2 (n-1)-1 -1=2 n-2 -1, then the second level corresponding to the setting code length is 2 n-2 , which is M (n-1)0 、M (n-1)1 、M (n-1)2 、M (n-1)3 ……、 and The corresponding maximum codes are Code_max[M (n-1)0 ]、Code_max[M (n-1)1 ]、Code_max[M (n-1)2 ]、Code_max[M (n-1)3 ]……、 and
[0059] For the nth level, 0≤y≤2 n-1 -1, then the second level corresponding to the setting code length is 2 n-1 , which is M n0 、M n1 、M n2 、M n3 ……、 and The corresponding maximum codes are Code_max[M n0 ]、Code_max[M n1 ]、Code_max[M n2 ]、Code_max[M n3 ]……、 and
[0060] It can be seen that at the xth level comparison, 0≤y≤2 x-1 -1, y is rounded and incremented from 0 to the maximum value, there will be 2 x-1 Set code length M xy The corresponding maximum code is waiting to be selected. The selected result is determined by the comparison results of the first level to the x-1th level. The specific selection method can be executed according to step S200.
[0061] For example, in the first level comparison, when the value of the data to be decoded is less than or equal to the set code length M 10 The maximum code, the first level comparison result is 0, then in the second level comparison, select the set code length M 20 The maximum code is compared with the value of the data to be decoded; when the value of the data to be decoded is greater than the set code length M 10 The maximum code, the first level comparison result is 1, then in the second level comparison, select the set code length M 21Compare the maximum code with the value of the data to be decoded;
[0062] In the second level comparison, if M is selected 20 , when the value of the data to be decoded is less than or equal to the set code length M 20 The maximum code, the second level comparison result is 0, then in the third level comparison, select the set code length M 30 The maximum code is compared with the value of the data to be decoded; when the value of the data to be decoded is greater than the set code length M 20 The maximum code, the second level comparison result is 1, then in the third level comparison, select the set code length M 31 Compare the maximum code with the value of the data to be decoded;
[0063] In the second level comparison, if M is selected 21 , when the value of the data to be decoded is less than or equal to the set code length M 21 The maximum code, the second level comparison result is 0, then in the third level comparison, select the set code length M 32 The maximum code is compared with the value of the data to be decoded; when the value of the data to be decoded is greater than the set code length M 20 The maximum code, then the second level comparison result is 1, then in the third level comparison, select the set code length M 33 The maximum code is compared with the value of the data to be decoded.
[0064] By analogy, combined with the above content, it can be seen that in the first level comparison, because there is only one set code length M 10 Therefore, starting from the first comparison result, the code length M of the previous level can be set according to the comparison result of the previous level and the set code length M of the previous level as in step S200. xy The corresponding maximum code is used to jointly determine the maximum code corresponding to the set code length that should be selected at the next level.
[0065] It should be noted that the comparison from the first level to the nth level is performed synchronously within one clock cycle. When comparing from the first level, the set code length of the next level will be quickly determined, and the comparison results from the first level to the nth level will be obtained synchronously.
[0066] In addition, in step S300, the comparison results from the first level to the nth level are n-bit binary numbers, and the order of the nth level results to the first level results needs to be sorted, so as to obtain Result[n:1]={nth level result, ..., second level result, first level result}, so as to determine the decoding code length L of the data to be decoded. decode =Result[n:1]+1
[0067] Reference Figure 3 In some embodiments of the present invention, the following steps are also included:
[0068] S400, according to the decoding code length L decode , find the corresponding original value in the encoding lookup table.
[0069] Specifically, in the actual decoding process, if it is necessary to determine the original value corresponding to the data to be decoded, by repeatedly executing steps S200, S300 and S400, the data to be decoded can be further decoded to obtain the original value of each data to be decoded.
[0070] In some embodiments of the present invention, according to the decoding code length L decode , the steps of searching for the corresponding original value in the encoding lookup table include:
[0071] S410, according to the decoding code length L decode , determine the position value Position,
[0072]
[0073] S420: Determine the original value corresponding to the encoding lookup table according to the position value Position.
[0074] It should be noted that, according to different encoding rules, the same code length may have different numbers of codes. After determining the selected encoding rule, we can know how many codes the corresponding code length has, and determine the set code length M. xy What is the corresponding maximum code? The coding rules applicable to the present invention include but are not limited to normal Huffman coding, Shannon-Fanno coding, Shannon coding, Fano coding, etc. As long as the decoding method is formulated according to the code length, it can be applied.
[0075] In some embodiments of the present invention, when comparing the data to be decoded at the xth level, the code length M is set from z xy The corresponding maximum code in selects one of them and compares it with the value of the data to be decoded. The y value starts from zero and increases by one to the maximum value. z = 2 x-1 . For each level of comparison, there will be a corresponding number of set code lengths M xy The corresponding maximum code is selected as a candidate. According to the comparison results of the first to the x-1th level, the set code length M to be selected at the current level will be determined. xy The maximum encoding of the data to be decoded can be finally determined by comparing the results of n levels. decode The numerical value of .
[0076] In some embodiments of the present invention, the step of performing n-level comparison on the data to be decoded comprises:
[0077] S210, setting n comparators, namely a first-stage comparator, a second-stage comparator, ... an x-th-stage comparator, ... an n-1-th-stage comparator and an n-th-stage comparator;
[0078] S220, the first input terminal of each level of comparator inputs the data to be decoded, and the second input terminal of each level of comparator inputs the data from the z set code length M xy Select one of the corresponding maximum codes and input it. x is the value corresponding to the x-th comparator. The y value starts from zero and increases by one to the maximum value. z=2 x-1 ;
[0079] S230: If the value of the data to be decoded by the x-th comparator is greater than the set code length M xy The maximum code, then the second input terminal of the x+1th level comparator selects the input setting code length M (x+1)(2y) The maximum code; if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The maximum code, then the second input terminal of the x+1th level comparator selects the input setting code length M (x+1)(2y+1) Maximum encoding.
[0080] It can be known that, since the comparator is a conventional and mature electronic component, when a simple comparison is required to obtain a result of 0 or 1, a mature comparator on the market can be directly used. Similarly, an integrated circuit component capable of comparison can be designed according to actual needs. Therefore, in the decoding method of the above embodiment, the comparison method involved includes but is not limited to being implemented by a comparator.
[0081] It should be noted that before designing any decoding method, the designer knows in advance the maximum code length L of the decoded data. max Therefore, we can directly determine the number of levels n that need to be compared simultaneously, and also determine the set code length M of each level. xy Therefore, according to step S100, after determining the number of levels to be decoded under the initial design, a corresponding number of comparators are used for comparison. When the same decoded data is subsequently decoded, steps S200 and S300 are directly executed to obtain the decoded code length without repeating step S100. Where n = ceil (log2L max ), represents n rounded upwards to an integer, according to the maximum code length L of the decoded data max The value of log2L is first calculated. max , according to log2L maxThe final value is rounded upward to determine n. It can also be backward compatible, that is, when the maximum code length of the actual data to be decoded is less than or equal to 2n, the number of required comparators is determined according to the maximum code length of the actual data to be decoded, and then steps S100, S200 and S300 can be performed in sequence. Specifically, when executing step S100, it is determined that several levels of comparison are required, and the corresponding number of comparators are started in step S200, and the remaining ones are left unchanged. For example, assuming that there are 6 comparators in a certain design, when the maximum code length of the data to be decoded is 16 bits, if in a certain decoding, according to step S100, it is determined that 4 levels of comparison are required, that is, it can be determined that 4 comparators are required, then when executing step 200, only the first 4 comparators are started for comparison, and according to the case where n is 4 and the corresponding encoding rules, the set code length corresponding to each level and the corresponding maximum code are determined, and then the code length of the data to be decoded is decoded according to steps S200 and S300 to determine the effective code length of the data to be decoded.
[0082] In addition, it should be noted that the setting code length M input to the second terminal of each comparator is xy The maximum coded signal can be generated by the signal generating module 200 according to the setting, and the signal to be received by the next-level comparator is selected according to the comparison result of the previous-level comparator. The signal generating module 200 can be a digital signal processor DSP, a digital logic simulator, or a digital logic circuit such as a field programmable gate array FPGA, which can output a corresponding data stream according to an external feedback signal or a control signal.
[0083] Specifically, the above steps are explained in detail in combination with actual conditions. Example 1:
[0084] The maximum code length L in the known data to be decoded max =16, the paradigm Huffman coding rule is used, so the number of codes for each code length is (0,1,2,3,1,1,2,1,1,2,1,2,3,2,1,1), and the coding lookup table corresponding to the original value is as follows Figure 4 As shown, according to Figure 4 , the corresponding maximum codes are:
[0085] Code_max[2]=00;
[0086] Code_max[3]=011;
[0087] Code_max[4]=1010;
[0088] Code_max[5]=10110;
[0089] Code_max[6]=101110;
[0090] Code_max[7] = 1011111;
[0091] Code_max[8]=11000000;
[0092] Code_max[9]=110000010;
[0093] Code_max
[10] =1100000111;
[0094] Code_max
[11] =11000010000;
[0095] Code_max
[12] =110000100011;
[0096] Code_max
[13] =1100001001010;
[0097] Code_max
[14] =11000010010111;
[0098] Code_max
[15] =110000100110000;
[0099] Code_max
[16] =1100001001100010;
[0100] The data to be decoded is data[22:1]=1100001000101011000001.
[0101] According to step S100, it can be determined that n=ceil(log2L max )ceil(log216)=4; At the same time, combined with step S210 to step S230, it can be known that 4 comparators are set, referring to Figure 5 , the first to fourth levels are:
[0102] First level, that is, x = 1, then 0 ≤ y ≤ 2 1-1 -1=0, then the setting code length corresponding to the first level is 1, which is according to Figure 4 The encoding lookup table shows that the set code length M 10 The maximum code is Code_max[M 10 ] = 11000000;
[0103] The second level, that is, x = 2, then 0 ≤ y ≤ 2 2-1 -1=1, then the second level corresponding setting code length is 2, which are and according to Figure 4 The encoding lookup table shows that the set code length M 20 The maximum code is Code_max[M 20 ]=1010, set the code length M 21 The maximum code is Code_max[M 21 ]=110000100011;
[0104] The third level, that is, x = 3, then 0 ≤ y ≤ 2 3-1 -1=3, then the second level corresponding setting code length is 4, which are and according to Figure 4 The encoding lookup table shows that the set code length M 30 The maximum code is Code_max[M 30 ]=00, set the code length to M 31 The maximum code is Code_max[M 31 ]=101110, set the code length M 32 The maximum code is Code_max[M 32 ]=1100000111, set the code length to M 33 The maximum code is Code_max[M 33 ]=11000010010111;
[0105] The fourth level, that is, x = 4, then 0 ≤ y ≤ 2 4-1 -1=7, then the second level corresponding setting code length is 7, which are and According to Figure 4 The encoding lookup table shows that the set code length M 41 The maximum code is Code_max[M 41 ]=011, set the code length M 42 The maximum code is Code_max[M 42 ]=10110, set the code length M 43 The maximum code is Code_max[M 43 ]=1011111, set the code length to M 44 The maximum code is Code_max[M 44 ]=110000010, set the code length M 45 The maximum code is Code_max[M 45 ]=11000010000, set the code length M 46 The maximum code is Code_max[M 46=1100001001010, set the code length M 47 The maximum code of 47 is Code_max[M 47 =110000100110000, where, referring to Figure 4 the code lookup table of Figure 4 , it can be seen that there is no corresponding maximum code for the set code length M 40 Therefore, the maximum code of the set code length M 40 can be set to Code_max[M 40 =0, so that the data to be decoded with a code length of 1 can be decoded synchronously.
[0106] The comparison process of the four-level comparator used in the first embodiment is as Figure 5 shown. When the data to be decoded is data[22:1]=1100001000101011000001, the first ends of the first-level comparator to the fourth-level comparator are respectively input with the data to be decoded, and the second ends of the first-level comparator to the fourth-level comparator are input with the corresponding maximum codes. Combining with step S200, the specific process is as follows:
[0107] Since the data input to the second end of the first-level comparator is Code_max[M 10 =11000000, the data input to the first end of the first-level comparator is the high 8 bits of the data to be decoded data[22:1] - 11000010. Since 11000010>11000000, the comparison result of the first-level comparator is 1;
[0108] According to the set code length M 10 of the first-level comparator and the comparison result, it can be known that the data input to the second end of the second-level comparator should be Code_max[M 21 =110000100011. Therefore, the data input to the first end of the second-level comparator is the high 12 bits of the data to be decoded data[22:1] - 110000100010. Since 110000100010<1100001>00011, the comparison result of the second-level comparator is 0;
[0109] According to the set code length M 21 of the second-level comparator and the comparison result, it can be known that the data input to the second end of the third-level comparator should be Code_max[M 32 =1100000111. Therefore, the data input to the first end of the third-level comparator is the high 10 bits of the data to be decoded data[22:1] - 1100001000. Since 1100001000>1100000111, the comparison result of the third-level comparator is 1;
[0110] According to the set code length M 32As a result of the comparison, it can be seen that the second terminal of the fourth-level comparator should input Code_max[M 45 ]=11000010000, so the data input to the first end of the fourth-level comparator is the high 11 bits of the data to be decoded data[22:1]——11000010001. Since 11000010001>11000010000, the comparison result of the fourth-level comparator is 1;
[0111] Therefore, combining the results of the first to fourth comparators, we can get Result[4:1]={1, 0, 1, 1}='D11. Then, according to step S300, we can get the decoding code length L of the data to be decoded. decode =Result[4:1]+1=12. Therefore, the effective code length of the first decoded data of the to-be-decoded data [22:1] is 12, and the remaining 10 bits of data enter the decoding of the next round of clock cycles.
[0112] Then according to step S410 and step S420, it can be calculated that, Substitute 16 into the corresponding encoding lookup table of the original value, that is Figure 4 In the data[22:11], the corresponding original value is 8'H0F.
[0113] In combination with the data to be decoded in the first embodiment, it can be known that the effective decoding code length of the data to be decoded is 12 bits, and the decoded data can be obtained in a single clock cycle;
[0114] Compared with the serial method, the serial method needs 12 comparisons, that is, 12 serial shifts are required, which greatly improves the efficiency. max The larger it is, the longer the effective code length can be when decoding each piece of data, and the more significant the improvement in efficiency.
[0115] Compared with the parallel method, the usual parallel method requires a maximum code length of L max comparators, that is, 16 comparators, while this solution only needs n=ceil(log2L max ) comparators, that is, 4 comparators, the hardware circuit cost is greatly reduced. max When the value is larger, the number of comparators required by the conventional parallel method is more, and the area advantage of this solution is more significant. For example, when the maximum code length is 64 bits, the conventional parallel method requires 64 comparators, while this solution only requires log264=6 comparators.
[0116] It should be noted that, according to the first embodiment, it can be known that, in some cases, when executing the steps of the present invention, in some cases, the corresponding code length may not have a corresponding maximum code, such as the set code length M in the first embodiment. 40 Therefore, in order to decode smoothly, there are two ways to solve it according to the actual situation:
[0117] The first is if there is no code in the first few bits: starting from the 1-bit code length, if the code length is 1, set its code to Code_max[1]=0, if the code length is 2, set its code to Code_max[2]=00, and if the code length is 3, set its code to Code_max[3]=000; and so on. If the code length is a and there is no maximum code in the previous code lengths of 1 bit to a-1 bits, then set the code with the first high a bits of the input being 0 as the corresponding maximum code;
[0118] If there is no maximum code in the middle or last few bits, for example, in the code lookup table for n-bit code length, if there is no corresponding code for a bit of code length, then determine the maximum code for a-1 bits, and add a 0 after it. For example, the maximum code for a 4-bit code length is Code_max[4]=1010, and there is no corresponding code for a code length of 5, then based on Code_max[4]=1010, set Code_max[5]=10100. If there is still no code for a code length of 6, set Code_max[6]=101000. If there is still no code for a code length of 7, set Code_max[7]=1010000. And so on. If there is a maximum code according to the number of bits of the previous code length, just add bits and fill with zeros until the maximum code for the corresponding code length is found, then no further padding is required.
[0119] Second, refer to Figure 6 , a decoding system according to an embodiment of the present invention comprises:
[0120] The comparison module 100 has n comparators, namely, a first-stage comparator, a second-stage comparator, ..., an x-th-stage comparator, ..., an n-1-th-stage comparator and an n-th-stage comparator. The first input terminal of each stage of the comparator inputs the data to be decoded, n=ceil(log2L max ), L max is the maximum code length of the data to be decoded;
[0121] The signal generating module 200, the n output terminals of the signal generating module 200 are electrically connected to the second input terminals corresponding to the first-stage comparator to the n-th-stage comparator, and the n-1 feedback terminals of the signal generating module 200 are electrically connected to the output terminals corresponding to the first-stage comparator to the n-1-th-stage comparator, and the signal generating module 200 outputs the corresponding code length M according to the feedback signals of the n-1 feedback terminals. xy The maximum code, if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The signal generation module 200 will select the input setting code length M to the second input terminal of the x+1th stage comparator. (x+1)(2y) The maximum code; if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The signal generation module 200 will select the input setting code length M to the second input terminal of the x+1th stage comparator. (x+1)(2y+1) The maximum encoding, 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the x-th level comparator, y is an integer;
[0122] The decoding module 300 is electrically connected to the output terminals of the first-stage comparator to the n-stage comparator, respectively. The decoding module 300 can obtain an n-bit binary number according to the results of the first-stage comparator to the n-stage comparator, Result[n:1]={n-stage result, ..., second-stage result, first-stage result}, so as to determine the decoding code length L of the data to be decoded. decode =Result[n:1]+1.
[0123] Other structures and operations of the decoding system according to the embodiment of the present invention are known to those skilled in the art and will not be described in detail here.
[0124] It can be known that, since the comparator is a conventional and mature electronic component, when a simple comparison is required to obtain a result of 0 or 1, a mature comparator on the market can be directly used. Similarly, an integrated circuit component capable of comparison can be designed according to actual needs; wherein, the signal generating module 200 can be a digital signal processor DSP, a digital logic simulator, or a digital logic circuit such as a field programmable gate array FPGA, which can output a corresponding data stream according to an external feedback signal or a control signal, and the decoding module 300 can be implemented using FPGA, ASIC or a dedicated decoding chip, and specific applicable hardware can be used according to actual decoding requirements.
[0125] It should be noted that before designing any decoding system, the designer knows in advance the maximum code length L of the decoding data to be decoded. maxTherefore, in combination with step S100 of the above method, the number n of comparators that need to be compared simultaneously can be directly determined, and the set code length M corresponding to each level of comparators can also be determined. xy The code length value. It can also be backward compatible, that is, when the maximum code length of the actual data to be decoded is less than or equal to 2n, the number of required comparators is determined according to the maximum code length of the actual data to be decoded, and the corresponding number of comparators can be directly started. For example, assuming that there are 6 comparators designed in a certain time, when the maximum code length of the data to be decoded is 16 bits, if in a certain decoding, it is determined that only 4 levels of comparison are required, that is, it can be determined that 4 comparators are required, then only the first 4 comparators are started for comparison, and according to the case where n is 4 and the corresponding encoding rules, the signal generation module 200 will again determine the set code length and the corresponding maximum code corresponding to each level, and then determine the maximum code signal that needs to be input to the next level comparator according to the comparison result of the previous level comparator and the selected maximum code, and decode the code length of the data to be decoded in conjunction with the corresponding level. The decoding module 300 finally determines the effective code length of the data to be decoded according to the results of all comparators.
[0126] It should be noted that the results of the output terminals of the first-stage comparator to the n-th-stage comparator need to be arranged in the order of Result[n:1], so the decoding module 300 can be set to arrange the order of receiving the comparison results, and can also be used in conjunction with an adder or accumulator to calculate the decoding code length L decode .
[0127] In some embodiments of the present invention, the decoding module 300 is further configured to decode the code length L decode , find the corresponding original value in the encoding lookup table.
[0128] In some embodiments of the present invention, the decoding module 300 decodes the code length L decode , the specific steps of finding the corresponding original value in the encoding lookup table include:
[0129] According to the decoding code length L decode , determine the position value Position,
[0130]
[0131] According to the position value Position, the original value corresponding to the encoding lookup table is determined.
[0132] In some embodiments of the present invention, each output terminal of the signal generation module 200 will receive z set code lengths M xy The corresponding maximum code selects one of the outputs, and the y value starts from zero and increases by one to the maximum value, z = 2x -1 , x is the value of the xth level comparator corresponding to the output terminal of the signal generation module 200. When each level of comparator makes comparisons, the signal generation module 200 will have a corresponding number of set code lengths M xy The corresponding maximum code is output as the candidate signal. According to the comparison results of the first to the x-1th level, the set code length M to be selected at the current xth level will be determined. xy The maximum encoding, finally, the decoding module 300 can determine the decoding code length L of the data to be decoded according to the comparison result of the n-level comparator. decode The numerical value of .
[0133] Reference Figure 7 , a decoding system, applied to the method of the above-mentioned embodiment 1, comprising:
[0134] The comparison module 100 has four comparators, namely a first-stage comparator, a second-stage comparator, a third-stage comparator and a fourth-stage comparator; the first input terminal of each stage comparator inputs the data to be decoded data[22:1];
[0135] The signal generating module 200 has four output terminals electrically connected to the second input terminals corresponding to the first to fourth level comparators, and three feedback terminals electrically connected to the output terminals corresponding to the first to third level comparators, respectively. The signal generating module 200 outputs the corresponding code length M according to the feedback signals of the three feedback terminals. xy Maximum encoding of
[0136] The decoding module 300 is electrically connected to the output terminals of the first to fourth stage comparators respectively.
[0137] The signals that may be received by the second input terminals of the first-stage comparator to the fourth-stage comparator are as follows:
[0138] First-stage comparator: The set code length is 1, which is M 10 =8, the maximum coded signal output by the signal generation module 200 is Code_max[M 10 ] = 11000000;
[0139] Second stage comparator: There are two setting code lengths, M 20 =4 and M 21 =12, the maximum coded signals output by the signal generation module 200 are Code_max[M 20 ]=1010 and Code_max[M 21 ] = one of 110000100011;
[0140] The third - level comparator: There are 4 set code lengths, which are M 30 = 2, M 31 = 6, M 32 = 10, and M 33 = 14. The signal generation module 200 will output the maximum encoded signals as one of Code_max[M 30 = 00, Code_max[M 31 = 101110, Code_max[M 32 = 1100000111, and Code_max[M 33 = 11000010010111;
[0141] The fourth - level comparator: There are 7 set code lengths, which are M 40 = 1, M 41 = 3, M 42 = 5, M 43 = 7, M 44 = 9, M 45 = 11, M 46 = 13, and M 47 = 15. The signal generation module 200 will output the maximum encoded signals as one of Code_max[M 40 = 0, Code_max[M 41 = 011, Code_max[M 42 = 10110, Code_max[M 43 = 1011111, Code_max[M 44 = 1100000, Code_max[M 45 = 11000010000, Code_max[M 46 = 1100001001010, and Code_max[M 47 = 110000100110000;
[0142] Therefore, each output terminal of the signal generation module 200 can output the corresponding maximum encoded signal according to the corresponding comparator, and determine the signal to be selected and output currently according to the result of the previous - level comparator and the maximum encoded signal of the selected set code length;
[0143] When the data to be decoded is data[22:1]=1100001000101011000001, the first - level to fourth - level comparators input the data to be decoded at their first terminals respectively, and input the corresponding maximum encoded signals at their second terminals. Combining with step S200, the specific process is as follows:
[0144] Since the signal generation module 200 inputs Code_max[M 10 = 11000000 to the second terminal of the first - stage comparator, the data input to the first terminal of the first - stage comparator is the high 8 - bit of the data to be decoded data[22:1] - - 11000010. Since 11000010 > 11000000, the comparison result of the first - stage comparator is 1;
[0145] According to the set code length M of the first - stage comparator 10 and the comparison result, the signal generation module 200 inputs Code_max[M 21 = 110000100011 to the second terminal of the second - stage comparator. So the data input to the first terminal of the second - stage comparator is the high 12 - bit of the data to be decoded data[22:1] - - 110000100010. Since 110000100010 <1100001>00011, the comparison result of the second - stage comparator is 0;
[0146] According to the set code length M of the second - stage comparator 21 and the comparison result, the signal generation module 200 inputs Code_max[M 32 = 1100000111 to the second terminal of the third - stage comparator. So the data input to the first terminal of the third - stage comparator is the high 10 - bit of the data to be decoded data[22:1] - - 1100001000. Since 1100001000 > 1100000111, the comparison result of the third - stage comparator is 1;
[0147] According to the set code length M of the third - stage comparator 32 and the comparison result, the signal generation module 200 should input Code_max[M 45 = 11000010000 to the second terminal of the fourth - stage comparator. So the data input to the first terminal of the fourth - stage comparator is the high 11 - bit of the data to be decoded data[22:1] - - 11000010001. Since 11000010001 > 11000010000, the comparison result of the fourth - stage comparator is 1;
[0148] Finally, the decoding module 300 combines the results of the first - stage comparator to the fourth - stage comparator, and can get Result[4:1] = {1, 0, 1, 1} = 'D11. Then according to step S300, the decoding code length L of the data to be decoded can be obtained decode = Result[4:1]+1 = 12. So the effective code length of the data to be decoded data[22:1] is 12, and the remaining 10 - bit data enters the decoding of the next clock cycle.
[0149] Then the decoding module 300 further performs decoding according to the effective code length 12, and it can be calculated that, Substitute 16 into the corresponding encoding lookup table of the original value, that is Figure 4 , the corresponding original value of data[22:11] is 8'H0F.
[0150] Thirdly, refer to Figure 8 The decoding device according to the embodiment of the present invention includes a memory 400 and a processor 500. The processor 500 implements the decoding method of the above embodiment when executing the computer program stored in the memory 400. For the specific steps of the method, reference can be made to the corresponding contents disclosed in the above embodiments, which will not be described in detail here.
[0151] Other structures and operations of the decoding device according to the embodiment of the present invention are known to those skilled in the art and will not be described in detail here.
[0152] In a fourth aspect, a storage medium according to an embodiment of the present invention stores program instructions thereon, and when the program instructions are executed by the processor 500, a decoding method as in the above embodiment is implemented.
[0153] Other structures and operations of the storage medium according to the embodiment of the present invention are known to those skilled in the art and will not be described in detail here.
[0154] According to the embodiments of the present invention, by such configuration, at least the following effects can be achieved:
[0155] In combination with the embodiments of the present invention, it can be known that when the maximum code length of the data to be decoded is L max When the effective code length is assumed to be A bits, the decoded data can be obtained in a single clock cycle when the present invention is used for decoding;
[0156] Compared with the conventional serial method, the present invention requires A comparisons, that is, A serial shifts, and the efficiency is greatly improved. When the maximum code length L max The larger it is, the longer the effective code length can be when decoding each piece of data, and the more significant the improvement in efficiency.
[0157] Compared with the conventional serial parallel method, the conventional parallel method requires a maximum code length L max comparators, while this solution only needs n=ceil(log2L max ) comparators, the hardware circuit cost is greatly reduced. maxWhen the value is larger, the number of comparators required by the conventional parallel method is more, and the area advantage of this solution is more significant. For example, when the maximum code length is 64 bits, the conventional parallel method requires 64 comparators, while this solution only requires log264=6 comparators.
[0158] Therefore, the embodiment of the present invention adopts n-level comparison for the code length of the decoded data at the same time, and each level of comparison has a corresponding set code length M. xy Taking the maximum coded signal as the reference, an effective code length of decoded data can be decoded in each clock cycle, and the decoded data can be further obtained by obtaining the effective code length, that is, an original data can be decoded in each clock cycle, which effectively improves the decoding efficiency; and the decoding hardware involved is also effectively reduced compared with the existing method, which effectively reduces the area of the circuit hardware;
[0159] The above is only a preferred embodiment of the present invention. The present invention is not limited to the above implementation. As long as the technical effect of the present invention is achieved by the same means, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the scope of protection of the present disclosure. All should belong to the protection scope of the present invention. Within the protection scope of the present invention, its technical scheme and / or implementation method can have various modifications and changes.
Claims
1. A decoding method, characterized in that: The following steps are involved: According to the maximum code length L of the data to be decoded max , determine n = ceil (log2L max ); The data to be decoded is compared at the same time at the nth level. At the xth level comparison, if the value of the data to be decoded is less than or equal to the set code length M, xy The maximum code of the x-th level comparison is 0, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y) The maximum code is compared with the value of the data to be decoded; if the value of the data to be decoded is greater than the set code length M xy The maximum code of the x-th level comparison is 1, and when the x+1-th level comparison is performed, the set code length M is selected. (x+1)(2y+1) The maximum code is compared with the value of the data to be decoded, where 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the x-th level comparison, y is an integer; According to the n-level comparison result, an n-bit binary number is obtained, Result[n:1]={nth level result, ..., second level result, first level result}, and the decoding code length L of the data to be decoded is determined. decode =Result[n:1]+1.
2. The decoding method according to claim 1, characterized in that: The following steps are also included: According to the decoding code length L decode , find the corresponding original value in the encoding lookup table.
3. The decoding method according to claim 2, characterized in that: The decoding code length L decode , the steps of searching for the corresponding original value in the encoding lookup table include: According to the decoding code length L decode , determine the position value Position, According to the position value Position, the original value corresponding to the encoding lookup table is determined.
4. The decoding method according to claim 1, characterized in that: When comparing the data to be decoded at the xth level, the code length M is set from z xy The corresponding maximum code in selects one of them and compares it with the value of the data to be decoded. The y value starts from zero and increases by one to the maximum value. z=2 x-1 .
5. A decoding system, characterized in that: include: The comparison module has n comparators, namely, the first-stage comparator, the second-stage comparator, ... the x-stage comparator ... the n-1-stage comparator and the n-stage comparator. The first input terminal of each stage comparator inputs the data to be decoded, n=ceil(log2L max ), L max is the maximum code length of the data to be decoded; A signal generating module, wherein the n output terminals of the signal generating module are respectively electrically connected to the second input terminals corresponding to the first-stage comparator to the n-th-stage comparator, and the n-1 feedback terminals of the signal generating module are respectively electrically connected to the output terminals corresponding to the first-stage comparator to the n-1-th-stage comparator, and the output terminal corresponding to the signal generating module outputs the corresponding code length M according to the feedback signals of the n-1 feedback terminals. xy The maximum code, if the value of the data to be decoded by the x-th level comparator is greater than the set code length M xy The signal generation module selects the input setting code length M to the second input terminal of the x+1th comparator. (x+1)(2y) Maximum encoding of If the value of the data to be decoded by the x-th comparator is greater than the set code length M xy The signal generation module selects the input setting code length M to the second input terminal of the x+1th comparator. (x+1)(2y+1) The maximum encoding, 1≤x≤n、0≤y≤2 x-1 -1, x is the value of the x-th level comparator, y is an integer; A decoding module is electrically connected to the output terminals of the first-level comparator to the n-th-level comparator, respectively. The decoding module can obtain an n-bit binary number according to the results of the first-level comparator to the n-th-level comparator, Result[n:1]={n-th-level result, ..., second-level result, first-level result}, so as to determine the decoding code length L of the data to be decoded. decode =Result[n:1]+1.
6. The decoding system according to claim 5, characterized in that: The decoding module is also used to decode the code length L decode , find the corresponding original value in the encoding lookup table.
7. The decoding system according to claim 6, characterized in that: The decoding code length L decode , the steps of searching for the corresponding original value in the encoding lookup table include: According to the decoding code length L decode , determine the position value Position, According to the position value Position, the original value corresponding to the encoding lookup table is determined.
8. The decoding system according to claim 5, characterized in that: Each output terminal of the signal generation module will receive z set code lengths M xy The corresponding maximum code selects one of the outputs, and the y value starts from zero and increases by one to the maximum value, z = 2 x-1 , x is the value of the x-th level comparator corresponding to the output end of the signal generating module.
9. A decoding device, comprising a memory and a processor, characterized in that: When the processor executes the computer program stored in the memory, the decoding method according to any one of claims 1 to 5 is implemented.
10. A storage medium having program instructions stored thereon, wherein the program instructions, when executed by a processor, implement the decoding method according to any one of claims 1 to 5.