我要评分
获取效率
正确性
完整性
易理解

Porting Assembly Code Automatically with the Kunpeng DevKit

The Kunpeng DevKit Porting Advisor analyzes and locates the content of x86 assemblies that needs to be modified in your source code and also provides modification suggestions. For details, see related content in Kunpeng Porting Advisor User Guide.

The following describes how to use the Kunpeng Porting Advisor to port the assembly code:

  1. Scan the source code.
    1. Go to Source Code Porting of the Porting Advisor for scan and analysis.
    2. Save the source code file to be ported to the /opt/portadv/portadmin/sourcecode/ directory and click Start Analysis.

      Perform analysis and obtain the scan and analysis report.

  2. Modify the source code.
    1. After the source code scan is complete, the Kunpeng Porting Advisor generates a source code porting report. In the report, click View Suggestion Code to access the source code file and obtain the source code modification suggestions.
    2. Based on the suggestions, click Quick Fix to quickly modify the source code.
      The following code example shows how to port the x86 assembly command cpuid to the Arm platform.
      //The original code segment on the x86 platform:
      asm volatile("cpuid\n\t"
      : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
      : "0"(1));
      
      //After clicking Quick Fix:
      #if defined  __X86_64__
      asm volatile("cpuidnt"
      : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
      : "0"(1));
      #elif defined  __aarch64__
      // Suggestion:
      {
      eax = 1;
      GetSupportedCPUID(&eax,&ebx,&ecx,&edx);
      }
      #endif

    As shown in the preceding sample, the upper part is the initial source code. After you click Quick Fix, it is automatically changed into the lower part, and an Arm code branch is automatically generated.

    Because there is no assembly code on the Kunpeng platform corresponding to cpuid, the tool implements the cpuid function in the C language. In this way, the x86 assembly code can be quickly ported.