A SIMD intrinsic implementation method based on the Shenwei platform

By reconstructing and testing x86 intrinsic functions on the Shenwei platform, compatibility issues between different platforms were resolved, achieving direct compatibility of x86 intrinsic functions on the Shenwei platform. This reduced the difficulty of software porting and improved the compatibility and execution efficiency of the processor platform.

CN116069397BActive Publication Date: 2026-05-26CLP KESHENTAI INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CLP KESHENTAI INFORMATION TECH CO LTD
Filing Date
2023-03-28
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing SIMD intrinsic functions suffer from compatibility issues when ported across different processor platforms, increasing the difficulty of software porting and limiting the promotion of the Shenwei platform.

Method used

By scanning the source code to determine the calls to x86 intrinsic functions, the functions were refactored into SIMD functions for the Shenwei platform and tested to ensure compatibility. The SIMD instruction set of the Shenwei platform was used to achieve compatibility with x86 intrinsic functions.

Benefits of technology

It achieves direct compatibility with x86 intrinsic functions on the Shenwei platform, reducing the difficulty of software porting and improving the compatibility and execution efficiency of the processor platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116069397B_ABST
    Figure CN116069397B_ABST
Patent Text Reader

Abstract

This invention relates to the field of SIMD technology on the Shenwei platform, and particularly to a method for implementing SIMD intrinsics based on the Shenwei platform. The method includes the following steps: S1: Scan the source code to determine if there are x86 intrinsic functions; S2: Determine if the x86 intrinsic functions can be reconstructed on the Shenwei platform; S3: Reconstruct the x86 intrinsic functions; S4: Perform testing; Test the x86 intrinsic functions reconstructed on the Shenwei platform in step S3 using libjpeg test cases. If the test results on the Shenwei platform are consistent with the test results on the x86 platform, it proves that the SIMD intrinsic functions on the Shenwei platform and the x86 intrinsic functions have the same functionality. This method can achieve x86 intrinsic compatibility at the source code level.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of SIMD technology on the Shenwei platform, and particularly to a SIMD intrinsic implementation method based on the Shenwei platform. Specifically, it relates to a method for implementing SIMD (Single Instruction Multiple Data) intrinsics (SIMD inline functions) based on the Shenwei platform (the Shenwei platform is a computer platform based on the domestic CPU—Shenwei CPU). Background Technology

[0002] (1) Current status of technological development in this industry

[0003] Modern processors include vector processing units that support the SIMD instruction set (vector processors, also known as array processors, are central processing units (CPUs) that implement instruction sets for directly manipulating one-dimensional arrays (vectors). To facilitate the use of SIMD functionality, processor manufacturers design a set of SIMD intrinsic function interfaces at the C language level. These function interfaces correspond one-to-one with SIMD instructions, achieving performance similar to assembly programming through the compiler. Currently, foreign processor manufacturers such as Intel have x86 intrinsics, and ARM (Advanced RISC Machine) has corresponding Neon intrinsics (Neon is a SIMD instruction introduced starting with the ARM v7 architecture). In China, the domestically produced Shenwei platform offers similar SIMD functions (functions implemented using the SIMD instructions of the Shenwei platform).

[0004] (2) Deficiencies in the prior art

[0005] Existing SIMD intrinsics are designed by various manufacturers for their own platforms, and there is no unified standard. This means that when porting programs with SIMD intrinsics to the Shenwei platform, porting personnel need to be familiar with the SIMD instruction sets of both platforms, which undoubtedly increases the difficulty of software porting and limits the promotion of the Shenwei platform. Summary of the Invention

[0006] The purpose of this invention is to provide a SIMD intrinsic implementation method based on the Shenwei platform, which can achieve x86 intrinsic compatibility at the source code level.

[0007] To address the aforementioned technical problems, this invention provides a SIMD intrinsic implementation method based on the Shenwei platform, comprising the following steps:

[0008] S1: Scan the source code to determine if there are x86 intrinsic functions; scan the source code for keywords related to x86 intrinsic functions, including source code and configuration files;

[0009] The keywords include: x86 intrinsic function header file name, x86 intrinsic function name prefix, and Advanced Vector Extensions;

[0010] In step S1, if the keyword is found in the scan result, it can be determined that there is a call to the x86intrinsic function in the source code;

[0011] In step S1, the source code is also compiled. If an error message "x86intrin.h not found" appears during the compilation process, it is determined that there is a call to the x86 intrinsic function in the source code.

[0012] S2: Determine whether x86 intrinsic functions can be reconstructed on the Shenwei platform; to ensure function compatibility, functions for 256-bit vectors are reconstructed. These functions are declared in the immintrin.h file with "_mm256" as the function name prefix.

[0013] S3: Refactor the x86 intrinsic function; if a corresponding Shenwei platform SIMD function exists, use the Shenwei platform SIMD function when refactoring the x86 intrinsic function; the Shenwei platform supports Shenwei platform SIMD functions in the compiler, resulting in high execution efficiency;

[0014] S4: Conduct testing; test the x86 intrinsic functions (i.e., the Shenwei platform SIMD intrinsic functions) reconstructed on the Shenwei platform in step S3 using libjpeg (an open-source cross-platform graphics processing library) test cases. If the test results on the Shenwei platform are consistent with those on the x86 platform, it proves that the Shenwei platform SIMD intrinsic functions and x86 intrinsic functions have the same functionality and their function interfaces are compatible. This ensures that code containing x86 intrinsic functions on the x86 platform can be compiled and run directly on the Shenwei platform without modification, thereby reducing the difficulty of porting.

[0015] Preferably, in step S3, if there is no corresponding Shenwei platform SIMD function (the Shenwei platform SIMD function is a function interface implemented by the Shenwei platform using SIMD instructions), and it is necessary to reconstruct the x86 intrinsic function _mm256_madd_epi16(), then the functionality of the _mm256_madd_epi16() function can be achieved by combining multiple SIMD functions such as simd_vsrlw(), simd_vbisw(), simd_vsllw(), and simd_vaddw().

[0016] The present invention has the following beneficial effects:

[0017] (1) The SIMD intrinsic of the Shenwei platform implemented by this method (i.e. the reconstructed x86 intrinsic function on the Shenwei platform) has the same name and parameters as the x86 intrinsic function on the x86 platform. The x86 intrinsic program that processes 256-bit vectors can be directly compiled and run on the Shenwei platform.

[0018] (2) The SIMD intrinsic functions implemented by this method on the Shenwei platform use SIMD functions supported by Shenwei GCC (Shenwei GCC is the C language compiler for the Shenwei platform), and have good stability.

[0019] (3) This method can be used as both a software porting method and a software optimization method.

[0020] (4) This invention provides a method for implementing SIMD intrinsics based on the Shenwei platform. It uses the Shenwei platform's SIMD instruction set to reconstruct inline functions with the same name as x86 intrinsics via SIMD functions. This allows programs using x86 intrinsic functions to compile on the Shenwei platform without modification, while ensuring the safety of the compilation process. This method significantly reduces the learning cost of SIMD instruction sets during software development or adaptation, and is of great significance for building a complete Shenwei platform ecosystem. Attached Figure Description

[0021] Figure 1 This is a schematic diagram illustrating the implementation principle of the SIMD intrinsic function _mm256_madd_epi16 of the Shenwei platform provided in this embodiment of the invention.

[0022] Figure 2 This is a schematic diagram illustrating the types and number of SIMD intrinsic functions of the Shenwei platform provided in this embodiment of the invention.

[0023] Figure 3This is a test schematic diagram of the SIMD intrinsic function of the Shenwei platform provided in an embodiment of the present invention. Implementation

[0024] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. The advantages and features of the present invention will become clearer from the following description and claims. It should be noted that the drawings are all in a very simplified form and use non-precise proportions, and are only used to facilitate and clarify the illustration of the embodiments of the present invention.

[0025] like Figure 1-3 As shown, this invention designs a SIMD intrinsic implementation method based on the Shenwei platform, which can achieve x86 intrinsic compatibility at the source code level.

[0026] The method includes the following steps:

[0027] S1: Scan the source code to determine if there are x86 intrinsic functions; scan the source code for keywords related to x86 intrinsic functions, including source code and configuration files;

[0028] The keywords include: x86 intrinsic function header file name, x86 intrinsic function name prefix, and Advanced Vector Extensions;

[0029] In step S1, if the keyword is found in the scan result, it can be determined that there is a call to the x86intrinsic function in the source code;

[0030] In step S1, the source code is also compiled. If an error message "x86intrin.h not found" appears during the compilation process, it is determined that there is a call to the x86 intrinsic function in the source code.

[0031] S2: Determine whether the x86 intrinsic function can be refactored on the Shenwei platform.

[0032] x86 intrinsic functions support 64, 128, 256, and 512-bit vector types, while the Shenwei platform only supports 256-bit vector types. To ensure function compatibility, this method only refactors functions for 256-bit vectors. These functions are declared in the immintrin.h file, prefixed with "_mm256".

[0033] S3: Refactor the x86 intrinsic function.

[0034] When refactoring x86 intrinsic functions, use Shenwei platform SIMD functions as much as possible. Shenwei platform supports Shenwei platform SIMD functions in the compiler, and their execution efficiency is relatively high.

[0035] For example, reconstructing the x86 intrinsic function `_mm256_or_si256()`, which performs a bitwise OR operation on two 256-bit vectors, is similar to the SIMD function `simd_vbisw()` in the Shenwei platform. The reconstructed x86 intrinsic function can be called directly, as shown below:

[0036] static inline__m256i FUNCTION_ATTRIBS

[0037] _mm256_or_si256(__m256i a,__m256i b)

[0038] {

[0039] return simd_vbisw(a,b);

[0040] }

[0041] If there is no corresponding SIMD function for the Shenwei platform, such as refactoring the `_mm256_madd_epi16()` function (which multiplies the packed 16-bit signed integers in `a` and `b` to produce a middle 32-bit signed integer, then horizontally sums adjacent middle 32-bit integer pairs, and finally packs them into a 256-bit vector for return), then the functionality of the `_mm256_madd_epi16()` function can be achieved by combining various SIMD functions such as `simd_vsrlw()`, `simd_vbisw()`, `simd_vsllw()`, and `simd_vaddw()`. Figure 1 As shown.

[0042] S4: Conduct the test.

[0043] In this embodiment, the x86 intrinsic function reconstructed on the Shenwei platform in step S3 is tested using libjpeg test cases. If the test results on the Shenwei platform are consistent with those on the x86 platform, it proves that the SIMDintrinsic function on the Shenwei platform and the x86 intrinsic function have the same functionality and their function interfaces are compatible. This ensures that code containing x86 intrinsic functions on the x86 platform can be compiled and run directly on the Shenwei platform without modification, thereby reducing the difficulty of porting.

[0044] like Figure 3 As shown, when libjpeg test cases are tested, they call the platform's SIMD intrinsic function. That is, when the x86 platform calls the x86 intrinsic function, the Shenwei platform calls the Shenwei platform's SIMD intrinsic function. If the test results of the two platforms are consistent, it proves that the Shenwei platform's SIMD intrinsic function has the same functionality as the x86 intrinsic function, and the function interface is compatible.

[0045] The above description is merely a description of preferred embodiments of the present invention and is not intended to limit the scope of the present invention in any way. Any changes or modifications made by those skilled in the art based on the above disclosure shall fall within the protection scope of the claims.

Claims

1. A SIMD intrinsic implementation method based on the Shenwei platform, characterized in that, Includes the following steps: S1: Scan the source code to determine if there are x86 intrinsic functions; scan the source code for keywords related to x86 intrinsic functions, including source code and configuration files; The keywords include: x86 intrinsic function header file name, x86 intrinsic function name prefix, and AdvancedVector Extensions; In step S1, if the keyword is found in the scan result, it can be determined that there is a call to the x86intrinsic function in the source code; In step S1, the source code is also compiled. If an error message "x86intrin.h not found" appears during the compilation process, it is determined that there is a call to the x86 intrinsic function in the source code. S2: Determine whether x86 intrinsic functions can be reconstructed on the Shenwei platform; to ensure function compatibility, functions for 256-bit vectors are reconstructed. These functions are declared in the immintrin.h file with "_mm256" as the function name prefix. S3: Refactor the x86 intrinsic function; if there is a corresponding Shenwei platform SIMD function, use the Shenwei platform SIMD function when refactoring the x86 intrinsic function; S4: Perform testing; test the x86 intrinsic function reconstructed by Shenwei platform in step S3 using libjpeg test cases. If the test results of Shenwei platform are consistent with the test results of x86 platform, it proves that the SIMDintrinsic function of Shenwei platform and the x86 intrinsic function have the same function and the function interface of the two are compatible.

2. The SIMD intrinsic implementation method based on the Shenwei platform as described in claim 1, characterized in that, In step S3, if there is no corresponding SIMD function for the Shenwei platform, and the _mm256_madd_epi16() function needs to be reconstructed, the functionality of the _mm256_madd_epi16() function can be achieved by combining multiple SIMD functions such as simd_vsrlw(), simd_vbisw(), simd_vsllw(), and simd_vaddw().