Rate This Document
Findability
Accuracy
Completeness
Readability

Multi-Instruction Conversion

This sample demonstrates how to use the source code porting function of the Kunpeng Porting Advisor to perform multi-instruction conversion in inline assembly.

Scanning the Source Code

  1. Download the source package from GitHub or Gitee to obtain the code sample.

    The downloaded source package is devkitdemo-main.zip. The ./devkitdemo-main/Porting_advisor/testdemo/asm_trans/mult_inline_asm file extracted from the package is the code to be scanned for porting.

  2. Before porting the source code, compile the original code on the x86 platform. Go to the source code directory, for example, demo_mult_inline_asm.
    Use GCC to compile and generate the binary file a.out. Execute ./a.out and the result is generated. See Figure 1.
    Figure 1 Results of the compilation and binary file execution on the x86 platform
  3. Log in to the Kunpeng DevKit. In the navigation pane on the left, choose Porting Advisor > Source Code Porting. The page for creating a source code porting task is displayed.

    Select Architecture source code porting for Source Code Porting and click Upload to upload the downloaded mult_inline_asm folder. Select other options as required. See Figure 2.

    Figure 2 Source Code Porting page
  4. Click Start. Figure 3 shows an example report.
    Figure 3 Architecture source code porting report

Modifying the Source Code

  1. Click View Suggested Code on the page of the source code porting report. See Figure 4.
    Figure 4 Source code porting suggestions

  2. Under File list on the left, switch between files to view the source code modification suggestions, as shown in Figure 5:
    Figure 5 File list

  3. Modify the file based on the report. On the Source Code Porting Suggestions page, check the modification suggestions and modify the source code accordingly.

    On the Source Code Porting Suggestions page, view the suggestions for modifying the gcd.c file. See Figure 6:

    Figure 6 Suggestions for modifying gcd.c

    Click Quick Fix > Replace with Suggested Code. Figure 7 shows the new code (the x86_64 branch and AArch64 branch are distinguished during the modification).

    Figure 7 New code
  4. Modify the file based on the report. On the Source Code Porting Suggestions page, check the modification suggestions and modify the source code based on the suggestions.

    On the Source Code Porting Suggestions page, view the suggestions for modifying the Makefile file, as shown in Figure 8:

    Figure 8 Suggestions for modifying Makefile

    According to the preceding suggestions, add the option FLAGS = -fsigned-char to the compile command in Makefile.

    Figure 9 Code after modification:

Compiling the Code

  1. Use an SSH tool to remotely log in to the server. Run the following command to go to the directory where the source code is stored:
    cd /opt/DevKit/workspace/devadmin/porting/sourcecode/mult_inline_asm

    /opt: tool installation directory. Replace it with the actual directory.

  2. Run the make command to compile the source code. The binary file gcd is generated, producing the same compilation result as on the x86 platform. This indicates that the source code has been successfully ported, as shown in Figure 10:
    Figure 10 Compilation result on the Kunpeng platform

    The gcd.c file is generated after quick fix is performed in the Kunpeng Porting Advisor. Compile the gcd.c file on the Kunpeng platform to generate a binary file. If the execution result of the binary file on the Kunpeng platform is the same as that on the x86 platform, the porting is successful.