Optimization method and system for SW Go runtime library byte slicing operation and medium

By employing vectorized parallel computation and a secure overloading mechanism, the problem of insufficient memory management and short vector instructions in the byte slicing operation of the Shenwei platform's Go runtime library was resolved, achieving efficient parallel processing of byte operations and improving the operating efficiency of the Shenwei platform.

CN121541884APending Publication Date: 2026-02-17WUXI ADVANCED TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511657544.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-13
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

The byte slicing operation of the Shenwei platform's Go runtime library does not fully utilize the Go compiler's memory management mechanism and Shenwei's short vector instructions. In addition, the handling of branches of different lengths leads to more judgments and jumps, which increases the program's runtime.

Method used

Vectorized parallel computing is adopted, utilizing the 256-bit vector operation instructions of the Shenwei architecture to process 32-byte data blocks. Based on the Go compiler's mechanism of allocating memory in 8KB pages, safe overloading is performed when processing byte slices with a length of less than 32 bytes, and address range judgment is used to avoid cross-page access to unallocated memory.

Benefits of technology

Significantly reduces memory accesses and computations, improves algorithm parallelism, reduces the performance impact of judgments and jumps, improves the execution efficiency of byte operations, and supports the efficient operation of the Go compiler in scenarios such as encryption/decryption, network communication, and file I/O.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121541884A_ABST
    Figure CN121541884A_ABST
Patent Text Reader

Abstract

The invention discloses an optimization method and system for SW Go runtime library byte slicing operation and a medium, and belongs to the technical field of compilers, the method comprises the following steps: judging the type of the current byte slicing operation based on a calling function name: executing byte counting to count the occurrence frequency of a specified byte in a byte slice when the type is Count; when the byte is IndexByte, executing byte search to return an index with a specified byte appearing for the first time in a byte slice, adopting vectorization parallel operation, processing a 32-byte data block by utilizing a 256-bit vector operation instruction of an SW architecture, and allocating a basic unit according to a mechanism of a Go compiler by taking a 8KB page as a memory; and when the byte slice with the processing length less than 32 bytes is processed, carrying out secure excess loading operation. The method solves the problems that in the prior art, a Go compiler memory management mechanism and SW short vector instruction acceleration are not utilized, and due to processing of branches with different lengths, more judgment transfer is caused, and the running duration is increased during dynamic adjustment.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to a method, system and medium for optimizing Shenwei Go runtime library byte slice operation, and belongs to the technical field of compilers. BACKGROUND

[0002] Go language is widely used in cloud computing infrastructure construction, AI model deployment and other key scenarios due to its native concurrency capability and high efficiency brought by static compilation characteristics. The byte slice operation of Go language is the core of byte data processing, and plays a key role in typical scenarios such as encryption and decryption, network communication and file I / O. The mainstream processor platforms such as X86 and AArch64 optimize the core byte slice operation in the runtime library based on the memory allocation strategy of the Go compiler and the instruction set and architecture characteristics of the processor platform, and implement the optimization based on Plan9 assembly to improve the running efficiency of the program. The Shenwei processor platform also uses Plan9 assembly to optimize the core byte slice operation to a certain extent.

[0003] Currently, the core byte slice operation of the Shenwei platform Go runtime library is implemented based on Plan9 assembly, and different basic instruction sequences are used to process different byte slice lengths. This method has two defects: first, it does not fully utilize the memory management mechanism of the Go compiler, and does not take advantage of the Shenwei short vector instruction to accelerate; second, the algorithm framework has too many judgments and transfers due to the different branches for different lengths, which increases the running time when the byte slice length and capacity are dynamically adjusted according to the data. To solve the above problems, this paper proposes an optimization method for Shenwei Go runtime library byte slice operation to fully utilize the performance of Shenwei processor. SUMMARY

[0004] The purpose of the present application is to provide an optimization method, system and medium for Shenwei Go runtime library byte slice operation, which implements safe overloading for byte slices with a length less than 32 bytes according to the memory allocation mechanism of the Go compiler with 8KB pages as the basic unit, so that any length of byte slice operation can be accelerated by using the Shenwei short vector instruction, to solve the problem that the prior art does not utilize the memory management mechanism of the Go compiler and the Shenwei short vector instruction acceleration, and has too many judgments and transfers due to different branches for different lengths, and the running time increases when dynamically adjusting.

[0005] To solve the above technical problems, the present application is realized by the following technical scheme.

[0006] In a first aspect, the present application provides an optimization method for Shenwei Go runtime library byte slice operation, comprising:

[0007] determining the type of the current byte slice operation based on the function name called:

[0008] When the function name is Count, a byte counting operation is performed to count the number of occurrences of a specified byte in a byte slice;

[0009] When the function name is IndexByte, a byte lookup operation is performed to return the index of the first occurrence of a specified byte in a byte slice;

[0010] The byte counting operation and the byte lookup operation are both vectorized parallel operations, a 256-bit vector operation instruction of the SWIFT architecture is used to process a 32-byte data block, and according to the mechanism of the Go compiler that takes 8KB pages as the basic unit of memory allocation, a safe overloading operation is performed when processing a byte slice with a length less than 32 bytes, and address interval judgment is used to avoid cross-page access to unallocated memory.

[0011] Further, the byte counting operation includes the following steps:

[0012] Step S200: input a pointer to the starting address of a byte slice , the length of the byte slice , a specified byte , and a pointer to save the return value address , initialize a first integer general register Rc and a third vector register Vc for counting, and store the specified byte in the second vector register Vb for 32 times for data preparation, and then execute step S202;

[0013] Step S202: branch jump based on the length of the byte slice , wherein

[0014] if the length of the byte slice is less than or equal to 0, execute step S210;

[0015] if the length of the byte slice is greater than 0 and less than 32, execute step S208;

[0016] if the length of the byte slice is greater than or equal to 32, execute step S204;

[0017] Step S204: load consecutive 32 bytes into the first vector register Va, compare the first vector register Va and the second vector register Vb by byte using the VComparePerByte instruction to obtain a first comparison result, store the first comparison result in the fourth vector register Vtmp, count the number of non-zero bits in the fourth vector register Vtmp by using the VPopCount instruction and accumulate it to the third vector register Vc, update the pointer to the starting address of the byte slice and the length of the byte slice , and execute step S206;

[0018] Step S206: If the byte slice length is greater than 32, continue to execute step S204, otherwise transfer the count value in the third vector register Vc to the first integer general register Rc, and determine the byte slice length, wherein if the byte slice length is 0, execute step S210, otherwise execute step S208. Step S208: When the byte slice length is less than 32, determine whether the address of the 32nd byte accessed from the pointer pointing to the start address of the byte slice is within the 32-byte interval range from all 8KB integer multiple addresses, if within the 32-byte interval range, move the pointer pointing to the start address of the byte slice to the position of the pointer pointing to the start address of the byte slice, otherwise do not move the pointer pointing to the start address of the byte slice, and load 32 bytes from the address pointed to by the pointer pointing to the start address of the byte slice for safe excess comparison, extract the valid comparison result by shifting or masking operation, count the number of non-zero bits in the valid comparison result and accumulate to the first integer general register Rc, and then execute step S210.

[0019] Step S210: Store the count value in the first integer general register Rc to the address pointed to by the pointer pointing to the return value address. Further, in step S204, the pointer pointing to the start address of the byte slice is incremented by 32, and the byte slice length is decremented by 32. Further, if the pointer pointing to the start address of the byte slice is within the 32-byte interval range from all 8KB integer multiple addresses, move the pointer pointing to the start address of the byte slice to the position of the pointer pointing to the start address of the byte slice, load 32 bytes to the first vector register Va, compare the first vector register Va and the second vector register Vb by byte using the VComparePerByte instruction to obtain a second comparison result, store the second comparison result to the fourth vector register Vtmp, right shift the fourth vector register Vtmp by 8 bits to remove invalid bits, and then count the number of non-zero bits. If the pointer pointing to the start address of the byte slice is not within the 32-byte interval range from all 8KB integer multiple addresses, do not move the pointer pointing to the start address of the byte slice, and load 32 bytes from the address pointed to by the pointer pointing to the start address of the byte slice for safe excess comparison, extract the valid comparison result by shifting or masking operation, count the number of non-zero bits in the valid comparison result and accumulate to the first integer general register Rc, and then execute step S210.

[0020] Step S210: Store the count value in the first integer general register Rc to the address pointed to by the pointer pointing to the return value address.

[0021] Further, in step S204, the pointer pointing to the start address of the byte slice is incremented by 32, and the byte slice length is decremented by 32. Further, if the pointer pointing to the start address of the byte slice is within the 32-byte interval range from all 8KB integer multiple addresses, move the pointer pointing to the start address of the byte slice to the position of the pointer pointing to the start address of the byte slice, load 32 bytes to the first vector register Va, compare the first vector register Va and the second vector register Vb by byte using the VComparePerByte instruction to obtain a second comparison result, store the second comparison result to the fourth vector register Vtmp, right shift the fourth vector register Vtmp by 8 bits to remove invalid bits, and then count the number of non-zero bits.

[0022] If the pointer pointing to the start address of the byte slice is not within the 32-byte interval range from all 8KB integer multiple addresses, do not move the pointer pointing to the start address of the byte slice, and load 32 bytes from the address pointed to by the pointer pointing to the start address of the byte slice for safe excess comparison, extract the valid comparison result by shifting or masking operation, count the number of non-zero bits in the valid comparison result and accumulate to the first integer general register Rc, and then execute step S210.

[0023] If the pointer pointing to the start address of the byte slice is not within the 32-byte interval range from all 8KB integer multiple addresses, do not move the pointer pointing to the start address of the byte slice, and load 32 bytes from the address pointed to by the pointer pointing to the start address of the byte slice for safe excess comparison, extract the valid comparison result by shifting or masking operation, count the number of non-zero bits in the valid comparison result and accumulate to the first integer general register Rc, and then execute step S210. ​​​​​​​​​​If the address is not a multiple of 8KB and falls within a 32-byte range, the pointer to the start address of the byte slice will not be moved. Load 32 bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va with the second vector register Vb byte by byte to obtain the third comparison result. Store the third comparison result into the fourth vector register Vtmp. Transfer the value in the fourth vector register Vtmp to the second integer general-purpose register tmp and compare it with the low-order vector register Vtmp. A 64-bit mask with 1s and 0s is ANDed to retain the valid bits, and then the number of non-zero bits is counted.

[0024] Furthermore, the byte lookup step includes:

[0025] Step S500: Input a pointer to the starting address of the byte slice. Byte slice length , specified bytes and a pointer to store the return value address Copy the pointer to the starting address of the byte slice. for and will specify bytes Make 32 copies and store them in the second vector register Vb, where, A pointer to the starting address of a byte slice. Backup;

[0026] Pre-loop branch judgment sub-step S510: Based on byte slice length Perform a branch jump, where,

[0027] If the byte slice length If the value is less than or equal to 0, proceed to step S560;

[0028] If the byte slice length If the value is greater than 0 and less than 32, proceed to step S540;

[0029] If the byte slice length If the value is greater than or equal to 32, proceed to step S520;

[0030] Step S520: Load 32 consecutive bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the fourth comparison result. Store the fourth comparison result into the fourth vector register Vtmp. If the fourth vector register Vtmp is not all zeros, proceed to step S550; otherwise, update the pointer to the starting address of the byte slice. and byte slice length and execute step S530;

[0031] Step S530: If the byte slice length If the length of the byte slice is greater than or equal to 32, proceed to step S520; if the byte slice length is... If the value is 0, proceed to step S560; otherwise, proceed to step S540.

[0032] Step S540: When the byte slice length When the value is less than 32, if the pointer points to the starting address of the byte slice... Within a 32-byte range starting at any address that is a multiple of 8KB, a pointer will be placed to the starting address of the byte slice. Move to the pointer pointing to the start address of the byte slice. Location and set signs Otherwise, do not move the pointer to the starting address of the byte slice. Without setting any flags, the pointer to the starting address of the byte slice... Load 32 bytes at the pointed address and perform a safe overload comparison to obtain the fifth comparison result. Store the fifth comparison result in the fourth vector register Vtmp. If the fourth vector register Vtmp is all 0, execute step S560; otherwise, execute step S550.

[0033] Step S550: If the flag If already set, shift the fourth vector register Vtmp to the right. Otherwise, do not move the fourth vector register Vtmp. Obtain the index of the first non-zero bit starting from the least significant bit in the fourth vector register Vtmp using the CountTailZero instruction. ,like Greater than or equal to the length of the byte slice Then proceed to step S560; otherwise, calculate... The value is used as the final index and stored in a pointer to the return value address. ;

[0034] Step S560: Store -1 in the pointer to the return value address. The address it points to.

[0035] Further, in step S520, the pointer to the starting address of the byte slice... The length of the byte slice is incremented by 32. Decrease by 32.

[0036] Furthermore, the first non-zero bit index The calculation is based on the position of the first non-zero bit in the fourth vector register Vtmp.

[0037] The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 1 is characterized in that the vectorized parallel operation uses the VComparePerByte instruction of the Shenwei architecture to compare bytes, and uses the VPopCount instruction to count the number of non-zero bits in the fourth vector register Vtmp.

[0038] Secondly, the present invention provides an optimization system for byte slicing operations in the Shenwei Go runtime library, for implementing the optimization method for byte slicing operations in the Shenwei Go runtime library as described in the first aspect.

[0039] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the optimization method for byte slicing operations of the Shenwei Go runtime library as described in the first aspect.

[0040] Compared with the prior art, the beneficial effects achieved by the present invention are as follows:

[0041] 1. This invention addresses two commonly used byte operations: byte counting and byte lookup. Compared to the original approach of using different processing granularities for different byte slice lengths, it fully utilizes the 256-bit short vector instructions of the Shenwei architecture to process byte slices of various lengths, significantly reducing the number of memory accesses and operations, and improving algorithm parallelism. Furthermore, the algorithm framework proposed in this invention has fewer branches, further reducing the performance impact of conditional statements and jumps. Therefore, the optimization method proposed in this invention can improve the execution efficiency of byte operations in the Go runtime library, supporting the efficient operation of the Go compiler in typical scenarios such as encryption / decryption, network communication, and file I / O.

[0042] 2. This invention leverages the Go compiler's mechanism of allocating memory in 8KB pages as the basic unit. It implements a safe overloading method for byte slices shorter than 32 bytes, enabling byte counting and lookup operations on byte slices of any length to be implemented using Shenwei short vector instructions. This significantly improves algorithm parallelism and execution efficiency. Compared to algorithm frameworks that use different branches for different lengths, this invention mainly includes two computational stages and two judgment stages to handle different byte slice lengths, reducing the performance impact of judgments and branching. This invention has a certain degree of reusability; currently, it implements byte counting and byte lookup algorithms, and in the future, it can be used for other byte slice operations in the Go runtime library. Attached Figure Description

[0043] Figure 1 This is a flowchart illustrating an optimization method for byte slicing operations in the Shenwei Go runtime library provided in an embodiment of the present invention;

[0044] Figure 2This is a flowchart illustrating the byte counting operation provided in an embodiment of the present invention;

[0045] Figure 3 This is a flowchart illustrating the byte lookup operation provided in an embodiment of the present invention. Detailed Implementation

[0046] The technical solution of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solution of the present invention, rather than limitations thereof. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0047] Example 1

[0048] like Figure 1 As shown, this embodiment introduces an optimization method for byte slicing operations in the Shenwei Go runtime library, including:

[0049] Step 1: Determine the type of the current byte slice operation based on the function name being called.

[0050] This invention quickly identifies the operation type by function name, reduces branch judgment overhead, realizes fast routing of byte slice operation types, and improves the initialization efficiency of byte operations in the Go runtime library.

[0051] Step 1.1: When the function name is Count, perform a byte counting operation to count the number of times the specified byte appears in the byte slice.

[0052] This invention uses Shenwei 256-bit short vector instructions to implement vectorized parallel counting of 32-byte data blocks. By using single instruction to process multiple data, it reduces the number of memory accesses and arithmetic instructions. Combined with the Go compiler's mechanism of using 8KB pages as the smallest memory allocation unit, it improves parallel processing capabilities in byte counting scenarios and reduces execution latency during dynamic adjustments.

[0053] Step 1.2: When the function name is IndexByte, perform a byte lookup operation and return the index of the first occurrence of the specified byte in the byte slice.

[0054] This invention implements vectorized parallel lookup of 32-byte data blocks based on Shenwei short vector instructions. By using address range judgment and safe overloading mechanism, it avoids cross-page access risks when processing byte slices with a length of less than 32 bytes, reduces the number of judgment jumps, and optimizes the execution efficiency and security of byte lookup operations.

[0055] The byte counting operation and the byte lookup operation both adopt vectorized parallel computing. The 256-bit vector operation instructions of the Shenwei architecture are used to process 32-byte data blocks. Based on the Go compiler's mechanism of allocating memory in 8KB pages, a safe overload operation is performed when processing byte slices with a length of less than 32 bytes. Address range judgment is used to avoid cross-page access to unallocated memory.

[0056] This invention utilizes vectorized parallel computation, employing Shenwei 256-bit short vector instructions to perform vectorized byte counting / searching on 32-byte data blocks. Through single instruction multiple data technology, it achieves parallel processing of 32-byte data within a single cycle, significantly reducing the number of memory accesses and computation instructions, and improving the algorithm's parallel throughput.

[0057] This invention optimizes memory management by combining the Go compiler's mechanism of allocating memory in 8KB pages as the basic unit. When processing byte slices with a length of less than 32 bytes, it performs safe overloading, giving full play to the parallel processing advantages of vector instructions. At the same time, it uses an address range judgment mechanism to ensure that memory access does not cross pages, avoiding security issues caused by accessing unallocated memory addresses.

[0058] This invention eliminates the complex judgment logic of "different branches of different lengths" by using a unified vectorized processing framework, reducing the performance loss caused by branch prediction failure. At the same time, the safe overloading mechanism effectively avoids the risk of accessing unallocated memory space, improving execution efficiency while ensuring operational security, and ultimately achieving a dual improvement in the execution efficiency and reliability of byte operations.

[0059] Example 2

[0060] Based on the same inventive concept as Embodiment 1, this embodiment introduces the implementation steps of an optimization method for byte slicing operations in the Shenwei Go runtime library, including:

[0061] Step 1: Determine the type of the current byte slice operation based on the function name being called.

[0062] Step 1.1: When the function name is Count, perform a byte counting operation to count the number of times the specified byte appears in the byte slice.

[0063] like Figure 2 As shown, in this embodiment, the byte counting operation includes the following steps:

[0064] Step S200: Input a pointer to the starting address of the byte slice. Byte slice length , specified bytes and a pointer to store the return value address Initialize the first integer general-purpose register Rc and the third vector register Vc used for counting, and set the specified byte... After copying the data 32 times and storing it in the second vector register Vb for data preparation, proceed to step S202.

[0065] Step S202: Based on byte slice length Perform a branch jump, where,

[0066] If the byte slice length If the value is less than or equal to 0, proceed to step S210;

[0067] If the byte slice length If the value is greater than 0 and less than 32, proceed to step S208;

[0068] If the byte slice length If the value is greater than or equal to 32, proceed to step S204;

[0069] Step S204: Load 32 consecutive bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the first comparison result. Store the first comparison result into the fourth vector register Vtmp. Use the VPopCount instruction to count the non-zero bits in the fourth vector register Vtmp and accumulate them into the vector register Vc. Update the pointer to the starting address of the byte slice. and byte slice length And execute step S206, wherein the pointer to the starting address of the byte slice The length of the byte slice is incremented by 32. Decrease by 32;

[0070] Step S206: If the byte slice length If the value is greater than 32, continue to step S204; otherwise, transfer the count value in the third vector register Vc to the first integer general-purpose register Rc, and determine the byte slice length. If the byte slice length... If the value is 0, proceed to step S210; otherwise, proceed to step S208.

[0071] Step S208: When the byte slice length When the value is less than 32, the judgment is made from the pointer to the starting address of the byte slice. If the address of the 32nd byte to be accessed is within a 32-byte range starting from any address that is a multiple of 8KB, then a pointer to the starting address of the byte slice will be generated. Move to the pointer pointing to the start address of the byte slice. The pointer to the start address of the byte slice will be moved only if the position is correct; otherwise, the pointer to the start address of the byte slice will not be moved. and from the pointer to the starting address of the byte slice Load 32 bytes at the pointed address for safe overload comparison, extract the valid comparison result through shift or mask operation, count the non-zero bits in the valid comparison result and accumulate them into the first integer general-purpose register Rc before executing step S210;

[0072] In this embodiment, if the pointer points to the starting address of the byte slice Within a 32-byte range starting at any address that is a multiple of 8KB, a pointer will be placed to the starting address of the byte slice. Move to the pointer pointing to the start address of the byte slice. At the specified position, load 32 bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the second comparison result. Store the second comparison result into the fourth vector register Vtmp. Shift the fourth vector register Vtmp to the right. After removing invalid bits, count the number of non-zero bits.

[0073] In this embodiment, if the pointer points to the starting address of the byte slice If the address is not a multiple of 8KB and falls within a 32-byte range, the pointer to the start address of the byte slice will not be moved. Load 32 bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va with the second vector register Vb byte by byte to obtain the third comparison result. Store the third comparison result into the fourth vector register Vtmp. Transfer the value in the fourth vector register Vtmp to the second integer general-purpose register tmp and compare it with the low-order vector register Vtmp. A 64-bit mask with 1s and 0s is ANDed to retain the valid bits, and then the number of non-zero bits is counted.

[0074] Step S210: Store the count value in the first general-purpose integer register Rc into the pointer at the return value address. The address it points to.

[0075] Step 1.2: When the function name is IndexByte, perform a byte lookup operation and return the index of the first occurrence of the specified byte in the byte slice.

[0076] like Figure 3 As shown, in this embodiment, the byte lookup step includes:

[0077] Step S500: Input a pointer to the starting address of the byte slice. Byte slice length , specified bytes and a pointer to store the return value address Copy the pointer to the starting address of the byte slice. for and will specify bytes Make 32 copies and store them in the second vector register Vb, where, A pointer to the starting address of a byte slice. Backup;

[0078] Pre-loop branch judgment sub-step S510: Based on byte slice length Perform a branch jump, where,

[0079] If the byte slice length If the value is less than or equal to 0, proceed to step S560;

[0080] If the byte slice length If the value is greater than 0 and less than 32, proceed to step S540;

[0081] If the byte slice length If the value is greater than or equal to 32, proceed to step S520;

[0082] Step S520: Load 32 consecutive bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the fourth comparison result. Store the fourth comparison result into the fourth vector register Vtmp. If the fourth vector register Vtmp is not all zeros, proceed to step S550; otherwise, update the pointer to the starting address of the byte slice. and byte slice length And execute step S530, wherein the pointer to the starting address of the byte slice... Incrementing by 32 bytes, slice length Decrease by 32;

[0083] Step S530: If the byte slice length If the length of the byte slice is greater than or equal to 32, proceed to step S520; if the byte slice length is... If the value is 0, proceed to step S560; otherwise, proceed to step S540.

[0084] Step S540: When the byte slice length When the value is less than 32, if the pointer points to the starting address of the byte slice... Within a 32-byte range starting at any address that is a multiple of 8KB, a pointer will be placed to the starting address of the byte slice. Move to the pointer pointing to the start address of the byte slice. Location and set signs Otherwise, do not move the pointer to the starting address of the byte slice. Without setting any flags, the pointer to the starting address of the byte slice... Load 32 bytes at the pointed address and perform a safe overload comparison to obtain the fifth comparison result. Store the fifth comparison result in the fourth vector register Vtmp. If the fourth vector register Vtmp is all 0, execute step S560; otherwise, execute step S550.

[0085] Step S550: If the flag If already set, shift the fourth vector register Vtmp to the right. Otherwise, do not move the fourth vector register Vtmp. Obtain the index of the first non-zero bit starting from the least significant bit in the fourth vector register Vtmp using the CountTailZero instruction. ,like Greater than or equal to the length of the byte slice Then proceed to step S560; otherwise, calculate... The value is used as the final index and stored in a pointer to the return value address. ;

[0086] In this embodiment, the first non-zero bit index The calculation is based on the position of the first non-zero bit in the fourth vector register Vtmp.

[0087] Step S560: Store -1 in the pointer to the return value address. The address it points to.

[0088] The byte counting operation and the byte lookup operation both adopt vectorized parallel computing. The 256-bit vector operation instructions of the Shenwei architecture are used to process 32-byte data blocks. Based on the Go compiler's mechanism of allocating memory in 8KB pages, a safe overload operation is performed when processing byte slices with a length of less than 32 bytes. Address range judgment is used to avoid cross-page access to unallocated memory.

[0089] In this embodiment, the vectorized parallel operation uses the VComparePerByte instruction of the Shenwei architecture to compare bytes, and uses the VPopCount instruction to count the number of non-zero bits in the fourth vector register Vtmp.

[0090] Example 3

[0091] Based on the same inventive concept as other embodiments, this embodiment introduces an optimization system for byte slicing operations of the Shenwei Go runtime library, used to implement the optimization method for byte slicing operations of the Shenwei Go runtime library as described in Embodiment 1 or 2.

[0092] For the specific functional implementation of each module in the optimization system for byte slicing operations of the Shenwei Go runtime library, please refer to the relevant content in Embodiment 1 or 2, which will not be repeated here.

[0093] Example 4

[0094] Based on the same inventive concept as other embodiments, this embodiment describes a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the methods of Embodiment 1 or 2 described above.

[0095] In summary, this invention addresses two commonly used byte operations: byte counting and byte lookup. Compared to the original approach of using different processing granularities for different byte slice lengths, this invention fully utilizes the 256-bit short vector instructions of the Shenwei architecture to process byte slices of various lengths, significantly reducing the number of memory accesses and operations, and improving algorithm parallelism. Furthermore, the algorithm framework proposed in this invention has fewer branches, further reducing the performance impact of judgments and jumps. Therefore, the optimization method proposed in this invention can improve the execution efficiency of byte operations in the Go runtime library, supporting the efficient operation of the Go compiler in typical scenarios such as encryption / decryption, network communication, and file I / O.

[0096] This invention leverages the Go compiler's mechanism of allocating memory in 8KB pages as the basic unit. It implements a safe overloading method for byte slices shorter than 32 bytes, enabling byte counting and lookup operations on byte slices of any length to be implemented using Shenwei short vector instructions. This significantly improves algorithm parallelism and execution efficiency. Compared to algorithm frameworks that use different branches for different lengths, this invention primarily includes two computational stages and two decision stages to handle different byte slice lengths, reducing the performance impact of decision-making and branching. This invention also possesses a degree of reusability; currently, it implements byte counting and byte lookup algorithms, and can be applied to other byte slice operations in the Go runtime library in the future.

[0097] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0098] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0099] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0100] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0101] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.

Claims

1. An optimization method for byte slicing operations in the Shenwei Go runtime library, characterized in that, include: Determine the type of the current byte slice operation based on the function name called: When the function name is Count, a byte counting operation is performed to count the number of times a specified byte appears in a byte slice. When the function name is IndexByte, a byte lookup operation is performed, returning the index of the first occurrence of the specified byte in the byte slice; The byte counting operation and the byte lookup operation both adopt vectorized parallel computing. The 256-bit vector operation instructions of the Shenwei architecture are used to process 32-byte data blocks. Based on the Go compiler's mechanism of allocating memory in 8KB pages, a safe overload operation is performed when processing byte slices with a length of less than 32 bytes. Address range judgment is used to avoid cross-page access to unallocated memory.

2. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 1, characterized in that, The byte counting operation includes the following steps: Step S200: Input a pointer to the starting address of the byte slice. Byte slice length , specified bytes and a pointer to store the return value address Initialize the first integer general-purpose register Rc and the third vector register Vc used for counting, and set the specified byte... After copying the data 32 times and storing it in the second vector register Vb for data preparation, proceed to step S202. Step S202: Based on byte slice length Perform a branch jump, where, If the byte slice length If the value is less than or equal to 0, proceed to step S210; If the byte slice length If the value is greater than 0 and less than 32, proceed to step S208; If the byte slice length If the value is greater than or equal to 32, proceed to step S204; Step S204: Load 32 consecutive bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the first comparison result. Store the first comparison result into the fourth vector register Vtmp. Use the VPopCount instruction to count the non-zero bits in the fourth vector register Vtmp and accumulate them into the third vector register Vc. Update the pointer to the starting address of the byte slice. and byte slice length And execute step S206; Step S206: If the byte slice length If the value is greater than 32, continue to step S204; otherwise, transfer the count value in the third vector register Vc to the first integer general-purpose register Rc, and determine the byte slice length. If the byte slice length... If the value is 0, proceed to step S210; otherwise, proceed to step S208. Step S208: When the byte slice length When the value is less than 32, the judgment is made from the pointer to the starting address of the byte slice. If the address of the 32nd byte to be accessed is within a 32-byte range starting from any address that is a multiple of 8KB, then a pointer to the starting address of the byte slice will be generated. Move to the pointer pointing to the start address of the byte slice. The pointer to the start address of the byte slice will be moved only if the position is correct; otherwise, the pointer to the start address of the byte slice will not be moved. and from the pointer to the starting address of the byte slice Load 32 bytes at the pointed address for safe overload comparison, extract the valid comparison result through shift or mask operation, count the non-zero bits in the valid comparison result and accumulate them into the first integer general-purpose register Rc before executing step S210; Step S210: Store the count value in the first general-purpose integer register Rc into the pointer at the return value address. The address it points to.

3. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 2, characterized in that, In step S204, the pointer to the starting address of the byte slice The length of the byte slice is incremented by 32. Decrease by 32.

4. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 2, characterized in that, If a pointer points to the starting address of a byte slice Within a 32-byte range starting at any address that is a multiple of 8KB, a pointer will be placed to the starting address of the byte slice. Move to the pointer pointing to the start address of the byte slice. At the specified position, load 32 bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the second comparison result. Store the second comparison result into the fourth vector register Vtmp. Shift the fourth vector register Vtmp to the right. After removing invalid bits, count the number of non-zero bits. If a pointer points to the starting address of a byte slice If the address is not a multiple of 8KB and falls within a 32-byte range, the pointer to the start address of the byte slice will not be moved. Load 32 bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va with the second vector register Vb byte by byte to obtain the third comparison result. Store the third comparison result into the fourth vector register Vtmp. Transfer the value in the fourth vector register Vtmp to the second integer general-purpose register tmp and compare it with the low-order vector register Vtmp. A 64-bit mask with 1s and 0s is ANDed to retain the valid bits, and then the number of non-zero bits is counted.

5. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 1, characterized in that, The byte lookup steps include: Step S500: Input a pointer to the starting address of the byte slice. Byte slice length , specified bytes and a pointer to store the return value address Copy the pointer to the starting address of the byte slice. for and will specify bytes Make 32 copies and store them in the second vector register Vb, where, A pointer to the starting address of a byte slice. Backup; Pre-loop branch judgment sub-step S510: Based on byte slice length Perform a branch jump, where, If the byte slice length If the value is less than or equal to 0, proceed to step S560; If the byte slice length If the value is greater than 0 and less than 32, proceed to step S540; If the byte slice length If the value is greater than or equal to 32, proceed to step S520; Step S520: Load 32 consecutive bytes into the first vector register Va. Use the VComparePerByte instruction to compare the first vector register Va and the second vector register Vb byte by byte to obtain the fourth comparison result. Store the fourth comparison result into the fourth vector register Vtmp. If the fourth vector register Vtmp is not all zeros, proceed to step S550; otherwise, update the pointer to the starting address of the byte slice. and byte slice length and execute step S530; Step S530: If the byte slice length If the length of the byte slice is greater than or equal to 32, proceed to step S520; if the byte slice length is... If the value is 0, proceed to step S560; otherwise, proceed to step S540. Step S540: When the byte slice length When the value is less than 32, if the pointer points to the starting address of the byte slice... Within a 32-byte range starting at any address that is a multiple of 8KB, a pointer will be placed to the starting address of the byte slice. Move to the pointer pointing to the start address of the byte slice. Location and set signs Otherwise, do not move the pointer to the starting address of the byte slice. Without setting any flags, the pointer to the starting address of the byte slice... Load 32 bytes at the pointed address and perform a safe overload comparison to obtain the fifth comparison result. Store the fifth comparison result in the fourth vector register Vtmp. If the fourth vector register Vtmp is all 0, execute step S560; otherwise, execute step S550. Step S550: If the flag If already set, shift the fourth vector register Vtmp to the right. Otherwise, do not move the fourth vector register Vtmp. Obtain the index of the first non-zero bit starting from the least significant bit in the fourth vector register Vtmp using the CountTailZero instruction. ,like Greater than or equal to the length of the byte slice Then proceed to step S560; otherwise, calculate... The value is used as the final index and stored in a pointer to the return value address. ; Step S560: Store -1 in the pointer to the return value address. The address it points to.

6. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 5, characterized in that, In step S520, the pointer to the starting address of the byte slice The length of the byte slice is incremented by 32. Decrease by 32.

7. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 5, characterized in that, The first non-zero bit index The calculation is based on the position of the first non-zero bit in the fourth vector register Vtmp.

8. The optimization method for byte slicing operations in the Shenwei Go runtime library according to claim 1, characterized in that, The vectorized parallel operation uses the VComparePerByte instruction of the Shenwei architecture to compare bytes, and uses the VPopCount instruction to count the number of non-zero bits in the fourth vector register Vtmp.

9. An optimized system for byte slicing operations in the Shenwei Go runtime library, characterized in that, This method is used to implement the optimization method for byte slicing operations of the Shenwei Go runtime library as described in any one of claims 1-8.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the optimization method for byte slicing operations of the Shenwei Go runtime library as described in any one of claims 1-8.