Method for improving readability of register model modeling code, storage medium
By derive the subclass of the UVM register model my_reg_enum_field, the problem of unintuitive register model modeling code is solved, and the enumeration type conversion of register field is realized, which improves code readability and work efficiency.
Patent Information
- Application Number
- CN202210418218.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-21
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-04-21
AI Technical Summary
In the prior art, the register model modeling code based on UVM verification method is not intuitive, and design and verification developers need to read the document multiple times to understand the meaning of field, resulting in inefficiency.
By derive the field base class of the UVM register model, generate the subclass my_reg_enum_field, the extension interface method supports calling enum type values, and adds conversion and checking of enum type in the register field, and uses subclasses to replace the base class for read and write access.
Improve the readability of register fields, avoid repeated flipping through design documents, and improve the work efficiency of design and verification developers.
Smart Images

Figure CN114880028B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of chip verification, and particularly relates to a method and a storage medium for improving the readability of register model modeling code. Background Art
[0002] Generally, we model the registers of the DUT based on the UVM verification method. The UVM provides the following register model classes for verification developers to use, including:
[0003] Register field: The register field. The function of each specific bit (field) in the register, which has a corresponding width and offset, as well as read / write, read only, and write only attributes.
[0004] Register: The register. It contains one or more register fields.
[0005] Register block: The register block. It corresponds to a specific hardware and can be understood as a container. This container contains one or more registers and one or more register maps. The register model we mentioned actually refers to an instance of a register block.
[0006] Memory: The memory. It is modeled by uvm_mem, including size and address range. It is part of the register block, and its offset depends on the register map. It also has read / write, read only, and write only attributes. However, when reading and writing an address each time, the data read and written is the entire data of that address, rather than an operation on certain bits. Therefore, it does not have the concept of register field similar to that of registers.
[0007] Register map: Register address mapping table. It is used to define the offset of the internal register and memory address space for its parent module on the bus. Each register has its address when added to the register model. The uvm_reg_map stores these addresses and converts them into accessible physical addresses. When the register model uses the front-door access method to perform read or write operations, the uvm_reg_map will convert the address into an absolute address, start a read or write sequence, and return the result of the read or write. Inside each reg_block, there is at least one uvm_reg_map.
[0008] Let's look at an example below.
[0009] For example, there is a control register ctrl_reg, and its register fields are as Figure 1 shown.
[0010] Its construction code is as Figure 2 shown. It can be seen that we first declare three fields included therein, namely invert_field, border_field, and reserved_field. All three are derived from the uvm_reg_field class, have the "RW" attribute of being readable and writable, and are located at the 0th bit, 1st bit, and 2nd to 15th bits of the example register ctrl_reg respectively.
[0011] Then, let's see how to read and write the above register in the verification environment. As Figure 3 shown. It can be seen that we first obtain the handle of the register model, and then call the read and write methods write and read of the example register ctrl_reg instantiated in the handle to complete the reading and writing of the target field in the register. For example, we can write 1'b1 to the invert_field therein, and then read out the written value.
[0012] The above solution is provided based on the UVM verification methodology and is also a commonly adopted solution. However, there is a defect, that is, we don't know the meaning represented by the value of the field in the register. It is just a string of 0 or 1 signals, which is not intuitive and thus difficult to understand. This leads to the designers and verification developers having to repeatedly flip through the design documents to check the meaning represented by the value of the corresponding field, and often forget, which greatly reduces the work efficiency of the chip design and verification process. Summary of the Invention
[0013] According to an embodiment of the present invention, a method for improving the readability of the modeling code of the register model is provided, including the following steps:
[0014] Create a UVM register model, derive from the field base class of the UVM register model to generate a subclass;
[0015] In the subclass, expand or add a series of interface methods to support method calls for enumeration type values;
[0016] Create an enumeration type variable corresponding to the register field of the preset UVM register model;
[0017] Use the subclass to replace the field base class to reconstruct the example register;
[0018] Use the interface method of the subclass to perform read and write access to the register field.
[0019] Furthermore, expanding or adding a series of interface methods in the subclass includes the following sub-steps:
[0020] Add a correctness check for the configured width and the width of the enumeration type in the configuration method of the register field and the method for obtaining the bit width;
[0021] Add a conversion of the enumeration data type in each of the other interface methods of the register field.
[0022] Furthermore, when calling the write method of the register field, an enumeration type value can be directly written.
[0023] Furthermore, when calling the read method of the register field, an enumeration type value can be directly read.
[0024] Furthermore, the enumeration type value written or read in the register field can be converted into a string and printed through the built-in interface method of the register field.
[0025] According to another embodiment of the present invention, there is provided a storage medium having non-volatile program code executable by a processor, and the program code causes the processor to run a method for improving the readability of the register model modeling code.
[0026] According to the method and storage medium for improving the readability of the register model modeling code according to the embodiments of the present invention, the encoding method for enhancing the readability of the register field avoids repeatedly referring to the design document many times, saves the time of the design and verification developers, and improves their work efficiency.
[0027] It should be understood that both the foregoing general description and the following detailed description are exemplary and intended to provide further explanation of the claimed technology. Brief Description of the Drawings
[0028] Figure 1It is a component structure diagram of an example register in the prior art.
[0029] Figure 2 It is a construction code diagram in the prior art.
[0030] Figure 3 It is a code diagram for reading a register in a verification environment in the prior art.
[0031] Figure 4 It is a flowchart of a method for improving the readability of register model modeling code according to an embodiment of the present invention.
[0032] Figure 5 It is a structure diagram of a method for improving the readability of register model modeling code according to an embodiment of the present invention.
[0033] Figure 6 It is a sub-step flowchart of a method for improving the readability of register model modeling code according to an embodiment of the present invention. Detailed implementation manner
[0034] The following will further elaborate on the preferred embodiments of the present invention in detail with reference to the accompanying drawings.
[0035] First, it will be combined with Figures 4 to 6 Describe a method for improving the readability of register model modeling code according to an embodiment of the present invention, which is used for chip verification and has a wide range of application scenarios.
[0036] As Figures 4 to 5 shown, the method for improving the readability of register model modeling code according to an embodiment of the present invention includes the following steps:
[0037] In S1, as Figure 4 shown, create a UVM register model, derive from the field base class uvm_reg_field of the UVM register model to generate a subclass my_reg_enum_field.
[0038] In S2, as Figure 4 shown, extend or add a series of interface methods in the subclass my_reg_enum_field to support method calls for enumerated type values.
[0039] Furthermore, the extension or addition of a series of interface methods in the subclass my_reg_enum_field includes the following sub-steps:
[0040] In S21, as Figure 6 shown, add a correctness check for the configured width size and the width of the enumerated type enum in the configure method of the register field and the get_n_bits method for obtaining the bit width.
[0041] In S22, as Figure 6 shown, add the conversion of the enumerated data type in each of the other interface methods (including the read and write methods) of the register field.
[0042] In S3, as Figure 4 shown, create an enumerated variable corresponding to the register field of the preset UVM register model. Take invert_field as an example. For example, set the enumerated variable invert_field_e for it, which are INVERT_YES and INVERT_NO respectively, representing the values 1'b1 and 1'b0 respectively.
[0043] In S4, as Figure 4 shown, use the subclass my_reg_enum_field to replace the field base class uvm_reg_field to reconstruct the example register ctrl_reg. In this embodiment, when calling the configure method of the register field, the parameter passed changes from the original 1'b0 to INVERT_NO, so that we can clearly know the initial value of the configured register field, thereby improving its readability.
[0044] In S5, as Figure 4 shown, use the interface method of the subclass my_reg_enum_field to perform read and write access to the register field.
[0045] Furthermore, in this embodiment, when calling the write method of the register field, the enumerated type value INVERT_YES can be directly written instead of 1'b1 before.
[0046] Furthermore, in this embodiment, when calling the read method of the register field, the enumerated type value can be directly read.
[0047] Furthermore, in this embodiment, the enumerated type value written or read in the register field can be converted into a string and printed through the built-in interface method name() of the register field, rather than the previous string of 0 or 1 numbers that are difficult to understand.
[0048] According to another embodiment of the present invention, a storage medium with non-volatile program code executable by a processor is provided, and the program code causes the processor to run a method for improving the readability of the register model modeling code.
[0049] Above, refer to Figures 4 to 6A method and storage medium for improving the readability of register model modeling code according to an embodiment of the present invention are described. The coding method for improving the readability of register fields avoids repeatedly referring to design documents, saves the time of design and verification developers, and improves their work efficiency.
[0050] It should be noted that in this specification, the terms "including", "comprising" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.
[0051] Although the content of the present invention has been described in detail through the above preferred embodiments, it should be recognized that the above description should not be considered as a limitation of the present invention. After those skilled in the art have read the above content, various modifications and alternatives to the present invention will be obvious. Therefore, the protection scope of the present invention should be defined by the appended claims.
Claims
1. A method for improving the readability of code for modeling a register model, characterized in that: The following steps are included: Create a UVM register model, derive the field base class of the UVM register model, and generate a subclass; Expand or add a series of interface methods in the subclass to support method calls of enumeration type values; Create an enumerated variable corresponding to the register field of the preset UVM register model; Rebuild the example register using the subclass instead of the field base class; Use the interface method of the subclass to read and write access to the register field; Extending or adding a series of interface methods in the subclass includes the following substeps: Add a check on the correctness of the configured width and the width of the enumeration type in the register field configuration method and the method for obtaining the bit width; Add conversion of enumerated data types in other interface methods of the register field.
2. The method for improving the readability of register modeling code according to claim 1, wherein: When the write method of the register field is called, the enumeration type value can be written directly.
3. The method for improving the readability of register modeling code according to claim 2, wherein: When the read method of the register field is called, the enumeration type value can be directly read.
4. The method for improving the readability of register modeling code according to claim 3, wherein: The enumeration type value written or read in the register field can be converted into a string and printed out through the built-in interface method of the register field.
5. A storage medium having a non-volatile program code executable by a processor, characterized in that: The program code enables the processor to execute the method for improving the readability of register modeling code according to any one of claims 1 to 4.
Citation Information
Patent Citations
Methods and apparatus for automation of register maps
CN101334806A
Automatic chip register code generation method and system thereof
CN105607897A