Finite-state machine coverage rate statistical method for VCD file
By reading YAML and VCD files, using hash tables and custom hash algorithms to calculate the coverage rate of the finite state machine, the problem of inability to effectively analyze coverage rate when processing VCD files in the prior art is solved, and efficient coverage is achieved Speed up the rate calculation and verification process.
Patent Information
- Application Number
- CN202411411033.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-10
AI Technical Summary
The prior art cannot effectively analyze the coverage of the finite state machine when processing VCD files, and the processing speed is slow and the memory usage is high.
By reading the YAML format files in the design stage and the VCD files generated after simulation, using hash table mapping technology and custom hash algorithms, the coverage of the finite state machine is calculated and output to the file in a specified form.
The coverage of finite state machines is achieved quickly and efficiently, reducing time complexity to O(1), speeding up the efficiency of the verification process, and reducing memory usage.
Smart Images

Figure CN119473872A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of computers, and in particular to a finite state machine coverage statistics method for a VCD file. Background Art
[0002] VCD (Value Change Dump), as part of the IEEE 1364 standard (Verilog hardware description language), is an ASCII-encoded file format that records in detail the changes in signals during the simulation process. These records make it possible to track the changes in the value of the signal during the simulation, so as to accurately analyze whether the states and transitions of the finite state machine (FSM) are adequately covered by the test. However, existing research points out that traditional VCD file processing technology mainly relies on a sequential reading method, that is, reading from the beginning to the end of the file. This method not only processes a large amount of irrelevant information, but also uses a general information storage structure, resulting in slow parsing speed and high memory usage. More importantly, these methods fail to provide effective analysis statistics for the coverage of finite state machines. Summary of the invention
[0003] The purpose of the present invention is to overcome the deficiencies of the prior art and provide a finite state machine coverage statistics method for a VCD file.
[0004] To achieve the above purpose, the technical solution provided by the present invention is:
[0005] A finite state machine coverage statistics method for a VCD file, comprising:
[0006] Read the YAML format file of the finite states and transition behaviors between states written in the design phase to obtain the state transition information of the signal;
[0007] Read the VCD file generated after simulation to obtain the state transfer information generated by the simulation of the signal under the stimulus condition;
[0008] Calculate the coverage of the finite state machine of the specified signal in the VCD file and output it to the file in the specified form.
[0009] Furthermore, the YAML format file of the finite states and transition behaviors between states written in the design phase is read to obtain the state transition information of the signal, including:
[0010] Open a YAML file that records a limited number of states and transition behaviors between states;
[0011] Read the YAML format file word by word, set the enumeration type as an environment variable and name it Title, and assign a value to the environment variable Title according to the read word;
[0012] Extract information based on the environment variable Title and store the extracted information in an unordered hash table object of type std::unordered_map, using the signal name as the mapping location;
[0013] After reading the YAML format file, an unordered hash table object of type std::unordered_map is returned.
[0014] Furthermore, in the process of reading the YAML format file, the string type representing the state transfer is converted into a long integer (long long type) through string processing to reduce the memory in the calculation process.
[0015] Furthermore, when reading a YAML format file, the std::unordered_map::size() method is used to determine the total number of signals to be processed; the determined total number of signals to be processed will be used as a benchmark for subsequent loops; in each iteration of the loop, the std::unordered_map::size() method will be called again for each signal to retrieve the total number of state transitions associated with a specific signal name, so that each signal defined in the YAML format file and its corresponding number of state transitions can be accurately processed.
[0016] Furthermore, the VCD file generated after the simulation is read to obtain the state transition information generated by the simulation of the signal under the stimulus condition, including:
[0017] Open the VCD file and read the signal variable definition part in the VCD file word by word.
[0018] Among them, a conditional statement is used to process according to the word content information, an identifier corresponding to the specified information is recorded, and a hash value of a custom hash function is calculated for this signal identifier, and stored in an object of the vector type;
[0019] Next, the simulation information part of the VCD file is read line by line, and the first character of each line of string is processed using the switch method to record the new state of the specified signal at the simulation time and the corresponding old state;
[0020] After reading the VCD file, return the vertor container including the required signals and corresponding state transitions, and close the VCD file.
[0021] Further, calculating the hash value of the signal identifier custom hash function includes:
[0022] Receive the string to be hashed, create an integer variable named len, calculate the length of the string using the std::string.length() function and assign it to the variable len;
[0023] Iterate over each character in the string, subtract 33 from the ASCII code value of each character and multiply the result by 94 to the power of i, where i is the position of the character in the string, and accumulate the result to get the hash value;
[0024] Convert the calculation method of multiplying 94 to the power of n into a shift calculation, which takes much less time than calling the pow function in C++;
[0025] Returns the result of calculating the current identifier string using a custom hash function;
[0026] The calculation formula is:
[0027]
[0028] Among them, n is the length of the string, i is the position of the current character in the string (from right to left), ASCII (X i ) is the ASCII code corresponding to the i-th character.
[0029] Furthermore, the coverage of the finite state machine of the specified signal in the VCD file is calculated, including:
[0030] Use the std::unordered_map::size() method to process the unordered hash table variable returned by reading the YAML format file to determine the total number of signals to be processed;
[0031] For each signal, call the std::unordered_map::size() method to retrieve the total number of state transitions associated with the specific signal name;
[0032] The total number of state transitions associated with each signal name is used as the small loop benchmark to traverse and match whether the transition between the old state and the new state of the current signal during the simulation corresponds to the specified state transition. If the match is successful, the total number of coverage variables is increased by one;
[0033] The finite state machine coverage of the current signal is calculated using the coverage calculation formula.
[0034] Furthermore, the finite state machine coverage calculation formula is:
[0035]
[0036] Compared with the prior art, the principles and advantages of this technical solution are as follows:
[0037] By directly parsing the YAML format file that records finite states and their transition behaviors, the hash table mapping technology is used to establish a mapping relationship between signal names and state transition information, achieving a constant-level efficiency of O(1) with time complexity reduced.
[0038] When processing the VCD files generated by simulation, two strategic file reading methods are adopted, targeting the variable definition and simulation data parts respectively, which simplifies the file processing process.
[0039] In order to solve the hash table conflict problem of identifiers in VCD files, a custom hash algorithm is used to ensure the uniqueness and accuracy of data processing.
[0040] In the processing of simulation data, we filter data according to the specific rules of the first characters, retaining only the key state transition information. At the same time, when storing this information, we use a custom hash function to quickly locate the target container, further reducing the time complexity to O(1).
[0041] In the calculation stage of the finite state machine coverage, a hash algorithm is applied to efficiently match the predetermined state transfers, reducing the time complexity of the matching process to O(1).
[0042] This technical solution can effectively overcome the shortcomings of the existing technology in processing VCD files and counting finite state machine coverage under resource-constrained conditions. It not only speeds up the statistical speed of finite state machine coverage, but also improves the efficiency of the verification process, bringing significant performance improvements to the verification stage of integrated circuit design. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the services required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A principle flow chart of a finite state machine coverage statistics method for a VCD file of the present invention;
[0045] Figure 2 A flow chart showing the principle of reading a YAML format file recording a finite number of states and transition behaviors between states in a finite state machine coverage statistics method of a VCD file of the present invention to obtain state transition information of a signal;
[0046] Figure 3A principle flow chart of a finite state machine coverage statistics method for a VCD file of the present invention for reading a VCD file generated after simulation to obtain state transfer information generated by simulation of a signal under excitation conditions;
[0047] Figure 4 It is a principle flow chart of calculating the hash value of a custom hash function of a signal identifier in a finite state machine coverage statistics method of a VCD file of the present invention;
[0048] Figure 5 A flow chart of the principle of calculating the coverage rate of the finite state machine of a specified signal in a VCD file in a finite state machine coverage rate statistics method of a VCD file of the present invention;
[0049] Figure 6 A YAML format file content diagram of a finite number of states and transition behaviors between states written in the design phase of a finite state machine coverage statistics method for a VCD file of the present invention;
[0050] Figure 7 It is a VCD file content diagram generated after simulation in a finite state machine coverage statistics method for a VCD file of the present invention. DETAILED DESCRIPTION
[0051] The present invention will be further described below in conjunction with specific embodiments:
[0052] like Figure 1 As shown, the finite state machine coverage statistics method of a VCD file described in this embodiment includes the following steps:
[0053] S1. Read the YAML format file of the finite states and transition behaviors between states written in the design phase to obtain the state transition information of the signal;
[0054] like Figure 2 As shown, the specific process of this step is as follows:
[0055] S1-1. Open the YAML format file. If the opening fails, an error message is output and the program exits. If the opening succeeds, an enumeration type variable is created and named Title.
[0056] S1-2. Read the YAML file word by word. There are five kinds of reading results: "FSM:", "LINKS:", "MODULE:", "STATES:", "TRANSITIONS:". The Title is assigned corresponding values, indicating that the corresponding characters are read.
[0057] S1-3. Extract information according to the environment variable Title. If "FSM:" is read, the Title is 0. Read the next word, record the current word as the signal name, and access it to the std::unordered_map type, named fsmsignalmap unordered hash table object, use the signal name as the mapping position, and assign the signal name string to its string type member, named signal_name; if "MODULE:" is read, the Title is assigned to 1, read the next word, the current word is the name of the module to which the signal belongs, and record the current string in the string type member module_name of the unordered hash table object fsmsignalmap; if "STATES:" is read, the Title is assigned to 2, read the next word, the current string is the state name, extract the state through string processing, access the state name through a temporary variable, and continue to read the next word. The string is the decimal number corresponding to the state name, which is converted into a long integer long through string processing. Long type, the main purpose is to reduce the memory used in the calculation process, and access the two to the secondary unordered hash table of states_map mapped by signal name in the fsmsignalmap unordered hash table object. There are usually multiple consecutive lines of state names and their corresponding decimal numbers. Continue to read the next word. Since the Title has not changed, it will continue to read until the Title changes. If "TRANSITIONS:" is read, the Title is assigned a value of 3, and the next word is read. The current string is the state migration. The old state name and the new state name are extracted through string processing. The state name is mapped through the previously accessed states_map secondary unordered hash table to find the decimal number corresponding to the state name, and access it to the transitions_map secondary unordered hash table mapped by signal name in the fsmsignalmap unordered hash table object. There are usually multiple consecutive lines of state migration. Continue to read the next word. Since the Title has not changed, it will continue to read until the Title changes.
[0058] S1-4, continue to read the YAML format file until the end, and use
[0059] std::unordered_map::size() method is used to determine the total number of signals to be processed. This number will be used as a benchmark for subsequent loops. In each iteration of the loop, the std::unordered_map::size() method will be called again for each signal to retrieve the total number of state transitions associated with a specific signal name. In this way, each signal defined in the YAML format file and its corresponding number of state transitions can be accurately processed.
[0060] S2, read the VCD file generated after the simulation, and obtain the state transfer information generated by the simulation of the signal under the excitation condition;
[0061] like Figure 3 As shown, the specific process of this step is as follows:
[0062] S2-1. Open the VCD file and read it word by word. There are five situations that need to be processed for the string content: "$var", "$scope", "$upscope", "$enddefinitions", "$timescale";
[0063] S2-2. Use the if statement to process according to the word content information. When the string is "$var", continue to read the next word. If the next word is one of "wire", "reg", or "integer", continue to read the next word. The current string represents the bit width of the current signal state. Continue to read the next word. The current string represents the identifier corresponding to the current signal, which is stored in the string type of the structure, named identifier variable. Continue to read the next word. The current string represents the name corresponding to the current signal. Then read the next word. If it is "$end", it means that the bit width of the current signal state starts from bit 0 by default. If not, the string represents the bit width range of the current signal state. Using the name of the signal read as an index, the std::unordered_map::count() function is used to check whether there is a corresponding signal in the fsmsignalmap unordered hash table object that stores the state transfer information of the signal. If not, the current loop is jumped out and the next loop is entered. If yes, the custom hash calculation method computer_hash() function is used to calculate the hash value corresponding to the identifier of the read signal, and the hash value is stored as an index in the corresponding bottom position of the std::vector type named vcdinfo container, and the bool type successread object in the vcdinfo structure object is set to true, and the default state is false. When the string is "$scope", continue to read the next word. If the next word is one of "module", "begin", or "function", continue to read two words. When the current string is judged to be "$end", the current loop is jumped out and the next loop is continued. When the string is "$upscope", continue to read the next word. When the current string is judged to be "$end", the current loop is jumped out and the next loop is continued. When the string is "$timescale", extract the time unit, continue to read the next word, and when the current string is judged to be "$end", jump out of the current loop and continue to the next loop. When the string is "$enddefinitions", continue to read the next word, and when the current string is judged to be "$end", it marks the end of the VCD variable definition part, and ends the entire loop;
[0064] S2-3. After processing the variable definition part of the VCD file, the simulation information part of the VCD file is processed next. The information is read line by line. For the first character of each line of the string, there are five situations that need to be processed: "#", "b", "1", "0", "x", and "z". Use the switch statement to process. The specific processing process is that when the first character of the string is "#", the current string contains time information, and the time information is obtained after string processing. When the first character of the string is "b", the current string is a multi-bit width signal state value. The string contains the identifier, state value, and bit width information corresponding to the signal. First, extract the identifier, use the computer_hash() function to calculate the hash value corresponding to the identifier, and then use the hash value as an index to find whether the successread of the corresponding position of the vcdinfo container of the vector type is true. If so, it means that the signal is the signal that needs to be recorded. The state information string is extracted through string processing, and the string is converted to a decimal number in combination with the bit width read in the variable definition part. The decimal number corresponding to the current state value is recorded, the current switch ends and the next line is read. If not, jump out of the current switch and continue to read the next line. When the first character of the string is "1", the current string is a unit-width signal state value and the state value is 1. The string contains the identifier and state value corresponding to the signal. First, extract the identifier, use the computer_hash() function to calculate the hash value corresponding to the identifier of the read signal, and then use the hash value as the index to find whether the successread of the corresponding position of the vector type vcdinfo container is true. If so, it means that the signal is the signal that needs to be recorded. Record the decimal number corresponding to the current state value, end the current switch and read the next line. If not, jump out of the current switch and continue to read the next line. When the first character of the string is "0", the current string is a unit-width signal state value and the state value is 0. The same operation as "1" is performed here, except that the state value is 0. When the first character of the string is "x" or "z", the current string is a unit-width signal state value set to -1. The same operation as "1" is performed here, except that the state value is -1. For other cases, skip the current switch and continue to read the next line. When the reading is completed, the variable simulation part is extracted, the VCD file is closed, and the vector type vcdinfo container is returned;
[0065] In step S2-2 and step S2-3, if Figure 4 As shown, the hash value of the custom hash function of the signal identifier is calculated, specifically including:
[0066] Receive the string to be hashed, create an integer variable named len, calculate the length of the string using the std::string.length() function and assign it to the variable len;
[0067] Iterate over each character in the string, subtract 33 from the ASCII code value of each character and multiply the result by 94 to the power of i, where i is the position of the character in the string, and accumulate the result to get the hash value;
[0068] Convert the calculation method of multiplying 94 to the power of n into a shift calculation, which takes much less time than calling the pow function in C++;
[0069] Returns the result of calculating the current identifier string using a custom hash function. The data type is int.
[0070] The calculation formula is:
[0071]
[0072] Among them, n is the length of the string, i is the position of the current character in the string, ASCII (X i ) is the ASCII code corresponding to the i-th character.
[0073] S3, calculate the coverage of the finite state machine of the specified signal in the VCD file,
[0074] like Figure 5 As shown, the specific process includes:
[0075] S3-1. Use the std::unordered_map::size() method to process the unordered hash table variable fsmsignalmap returned by reading the YAML format file to determine the total number of signals to be processed. The total number of signals is specified as an int integer variable named signalnum, which will be used as the benchmark for subsequent loops. In each iteration of the loop, the std::unordered_map::size() method will be called again for each signal to retrieve the total number of state transitions associated with a specific signal name as an int type variable named statesnum. In this way, each signal defined in the YAML format file and its corresponding number of state transitions can be accurately processed.
[0076] S3-2. The total number of signals signalnum is used as the benchmark of the large loop. The hash value of the signal's corresponding identifier is calculated by using the custom computer_hash() hash function as the base mark of the vector type vcdinfo container returned by querying the VCD file. The total number of state transitions associated with the signal name, statesnum, is used as the benchmark of the small loop. The current signal is traversed to match whether the transition between the old state and the new state during the simulation corresponds to the specified state transition. If the match is successful, the total number variable is overwritten and increased by one, which is recorded as the int type variable success.
[0077] S3-3. The total number of signals signalnum is used as the benchmark of the large loop. The coverage rate of the finite state machine of the current signal is calculated by the coverage rate calculation formula and output to the file in the specified format. The output format is "module name.signal name", "total number of current signal coverage", "number of specified state transitions of the current signal", and "coverage rate (keep two decimal places)".
[0078] The coverage calculation formula is:
[0079]
[0080] The embodiments described above are only preferred embodiments of the present invention and are not intended to limit the scope of implementation of the present invention. Therefore, all changes made according to the shape and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A finite state machine coverage statistics method for VCD files, characterized in that ,include: Read the YAML format file of the finite states and transition behaviors between states written in the design phase to obtain the state transition information of the signal; Read the VCD file generated after simulation to obtain the state transfer information generated by the simulation of the signal under the stimulus condition; Calculate the coverage of the finite state machine of the specified signal in the VCD file and output it to the file in the specified form.
2. The finite state machine coverage statistics method of a VCD file according to claim 1, characterized in that: Read the YAML format file of the finite states and transition behaviors between states written in the design phase to obtain the state transition information of the signal, including: Open a YAML file that records a limited number of states and transition behaviors between states; Read the YAML format file word by word, set the enumeration type as an environment variable and name it Title, and assign a value to the environment variable Title according to the read word; Extract information based on the environment variable Title and store the extracted information in an unordered hash table object of type std::unordered_map, using the signal name as the mapping location; After reading the YAML format file, an unordered hash table object of type std::unordered_map is returned.
3. The finite state machine coverage statistics method of a VCD file according to claim 2, characterized in that: When reading a YAML format file, the string type representing the state transfer is converted into a long integer through string processing.
4. A finite state machine coverage statistics method for a VCD file according to any one of claims 1 to 3, characterized in that: When reading a YAML file, use the std::unordered_map::size() method to determine the total number of signals to be processed; the total number of signals to be processed will be used as a basis for subsequent loops; in each iteration of the loop, for each signal, call std::unordered_map::size() method to retrieve the total number of state transitions associated with a particular signal name.
5. The finite state machine coverage statistics method of a VCD file according to claim 4, characterized in that: Read the VCD file generated after simulation to obtain the state transition information generated by the simulation of the signal under the stimulus condition, including: Open the VCD file, and first read the signal variable definition part of the VCD file by word by word; wherein, conditional statements are used for processing according to the word content information, and the identifier corresponding to the specified information and the hash value of the custom hash function calculated for this signal identifier are recorded and stored in a vector type object; Next, the simulation information part of the VCD file is read line by line, and the first character of each line of string is processed using the switch method to record the new state of the specified signal at the simulation time and the corresponding old state; After reading the VCD file, return the vertor container including the required signals and corresponding state transitions, and close the VCD file.
6. The finite state machine coverage statistics method of a VCD file according to claim 5, characterized in that: Calculate the hash value of the signal identifier using the custom hash function, including: Receive the string to be hashed, create an integer variable named len, calculate the length of the string using the std::string.length() function and assign it to the variable len; Iterate over each character in the string, subtract 33 from the ASCII code value of each character and multiply the result by 94 to the power of i, where i is the position of the character in the string, and accumulate the result to get the hash value; Convert the calculation method of multiplying 94 to the power of n into a shift calculation, which takes much less time than calling the pow function in C++; Returns the result of calculating the current identifier string using a custom hash function; The calculation formula is: Among them, n is the length of the string, i is the position of the current character in the string, ASCII (X i ) is the ASCII code corresponding to the i-th character.
7. The finite state machine coverage statistics method of a VCD file according to claim 6, characterized in that: Calculate the coverage of the finite state machine of the specified signal in the VCD file, including: Use the std::unordered_map::size() method to process the unordered hash table object returned by reading the YAML file to determine the total number of signals to be processed; For each signal, call the std::unordered_map::size() method to retrieve the total number of state transitions associated with the specific signal name; The total number of state transitions associated with each signal name is used as the small loop benchmark to traverse and match whether the transition between the old state and the new state of the current signal during the simulation corresponds to the specified state transition. If the match is successful, the total number of coverage variables is increased by one; The finite state machine coverage of the current signal is calculated using the coverage calculation formula.
8. The finite state machine coverage statistics method of a VCD file according to claim 7, characterized in that: The formula for calculating the coverage of the finite state machine is:
Citation Information
Patent Citations
VCD file analysis method based on perfect hash structure and post-processing logic
CN117272976A
FSM state transition coverage rate calculation method and system based on bucket sorting
CN118228648A
Cited By
FSM coverage rate data acquisition method during simulation, electronic equipment and storage medium
CN121303006A