Rate This Document
Findability
Accuracy
Completeness
Readability

Checking Byte Alignment

Prerequisites

  • The Kunpeng DevKit has been successfully installed and the required tools have been installed.

Procedure

  1. Log in to the Kunpeng DevKit. Choose Affinity Analysis > Byte Alignment Check. See Figure 1.
    Figure 1 Creating a byte alignment check task
  2. Click Check. After the check is complete, the report page is displayed. Click View Suggested Source Code for the file that you want to modify. The source code modification suggestion page is displayed. Figure 2 shows the suggestions for modifying the wtdbg2-2.5/dbgcns.h file.
    Figure 2 Source code modification suggestions
    Table 1 Page description

    Parameter

    Description

    File List

    Lists the source files analyzed.

    Original Source Code

    Original source code.

    Structure Variable Memory Allocation

    Displays the 32-bit and 64-bit memory spaces that need to be aligned in the code.

  3. Modify the source code for byte alignment based on the memory allocation results of structure variables displayed in the report.

    In modern computers, memory space is divided by byte. Theoretically, a variable of any type may be accessed from any memory address. In actual practice, however, a specific type of variables is often accessed from a specific memory address, which requires various types of data to be arranged spatially according to certain rules, rather than in order. This is byte alignment.

    Based on the byte alignment check result, you can modify the source file on your local PC by aligning bytes to optimize the code expression.

    1. Based on the byte alignment check result, locate the problems. See the following figure:
      Figure 3 Byte alignment check result
    2. Modify the wtdbg2-2.5/dbgcns.h file for byte alignment on your local PC based on the check result.

      Refer to the following for byte alignment:

      • The start position of a data member must be an integer multiple of its size, such as 1 byte, 2 bytes, or 4 bytes.
      • If the length of a member variable in the structure is not the power of 2, consider the byte alignment method of the member variable and its subsequent member variables. For example, if the length of a member variable is 3 bytes, it needs to be padded to align with the subsequent member variable that is 4 bytes.
      • The total size of the structure must be an integer multiple of the length of the largest memory variable.

      Adjust the positions of variables hz and kmask. See the following figure:

      Figure 4 Source code byte alignment
    3. After preceding steps are complete, check the byte alignment again. The check result shows that no holes exist in the 64-bit DBG structure after alignment. See the following figure:
      Figure 5 Check result after byte alignment