An optimization method of segment index search algorithm and storage medium
Patent Information
- Application Number
- CN202510312365.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-17
- Publication Date
- 2026-09-18
AI Technical Summary
[0040]然而,现有技术存在的缺陷在于:段索引遍历搜寻的逻辑判断较多,CPU占用率高;从而导致:
[0088] 1. High-efficiency parallel computing: Utilizing the SIMD (Single Instruction Multiple Data) instruction set, it can process multiple data simultaneously (such as eight 16-bit unsigned integers), significantly improving computational efficiency.
Smart Images

Figure CN122777528A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data search technology, and specifically relates to an optimization method for a segment index search algorithm and a storage medium. Background Technology
[0002] In existing technologies, segment index traversal search is a method for finding specific elements or elements that meet specific conditions in data structures (such as arrays, linked lists, trees, etc.). Its core idea is to divide the data into several segments (or blocks), then quickly locate the segment that may contain the target element using an index, and then perform a detailed traversal and search within that segment. This method is often used to improve the search efficiency of large-scale datasets, especially when the data distribution is uneven or efficient algorithms such as binary search cannot be directly used.
[0003] Typically, segment indexes are implemented by calculating the search index using a fixed formula. The formula for calculating the segment index varies depending on the way the data is segmented and its distribution characteristics, as follows:
[0004] 1) Uniform segmentation: Calculated using a simple mathematical formula:
[0005] Assumption:
[0006] The data is divided into k segments evenly.
[0007] The size of each segment is block_size.
[0008] The value of the target element is target.
[0009] The minimum value of the data is min_value, and the maximum value is max_value.
[0010] The formula for calculating the segment index block_index is:
[0011]
[0012] Formula explanation:
[0013] target-min_value: Maps the target value to a relative position starting from 0.
[0014] / block_size: The segment where the target value is calculated.
[0015] Round down to ensure the result is an integer index.
[0016] 2) Non-uniform segmentation: Determined by predefined segmentation boundaries:
[0017] If the data is not evenly segmented, the segment index can be determined by predefined segment boundaries. Assume: the segment boundary array is bounds, where bounds[i] represents the end value of the i-th segment.
[0018] The target value is target.
[0019] The formula for calculating the segment index block_index is:
[0020] block_index=find_first_index_where target≤bounds[i]
[0021] Formula explanation:
[0022] Iterate through the bounds array and find the first index i that satisfies target <= bounds[i]. This index is the segment where the target value is located.
[0023] 3) Hash segmentation: Suitable for situations where data distribution is uneven.
[0024] If the data is unevenly distributed and segment boundaries cannot be predefined, a hash function can be used to map the target value to a segment index. Assumption:
[0025] The number of segments is k.
[0026] The hash function is hash(value).
[0027] The formula for calculating the segment index block_index is:
[0028] block_index=hash(target)mod k
[0029] Formula explanation:
[0030] The target value is mapped to an integer using a hash function, and then the segment index is determined by taking the modulo of k.
[0031] 4) Multidimensional data: Combine the indexes of each dimension into a multidimensional segment index:
[0032] For multidimensional data, the index of each dimension can be calculated and then combined into a multidimensional segment index. Assumption:
[0033] The data has d dimensions.
[0034] The number of segments in each dimension is k_1,k_2,...,k_d.
[0035] The target values in each dimension are target_1, target_2, ..., target_d.
[0036] The segment index for each dimension is then:
[0037]
[0038] The final multi-dimensional segment index is:
[0039] block_index=(block_index1, block_index2,..., block_index d ).
[0040] However, the existing technology has the following drawbacks: the segment index traversal search involves many logical judgments, resulting in high CPU utilization; thus leading to:
[0041] High index maintenance costs:
[0042] When data changes dynamically (e.g., with frequent insert and delete operations), index maintenance costs are high. Each data change may require re-segmentation and index updates, adding extra overhead.
[0043] Difficulty in choosing segment size:
[0044] The size of a segment directly affects search efficiency. If the segment is too large, the time complexity of traversing within the segment is high; if the segment is too small, the number of indexes increases, leading to increased overhead for index lookups. Choosing the appropriate segment size is a challenging task.
[0045] Performance degradation when data is unevenly distributed:
[0046] If the data is unevenly distributed, some segments may contain a large amount of data, while other segments may contain less. This can lead to excessively long traversal times for some segments, affecting the overall search efficiency.
[0047] Not suitable for high-dimensional data:
[0048] For high-dimensional data (such as multidimensional arrays or data in multidimensional space), the creation and searching of segment indexes become complex, making it difficult to effectively narrow the search scope.
[0049] High memory usage:
[0050] Index structures require additional memory space for storage, especially when the data volume is large, the index itself may consume a lot of memory resources.
[0051] Parallelization is difficult:
[0052] Parallelization of segment index traversal search is quite complex, especially when data distribution is uneven or segment sizes are inconsistent, making it difficult to effectively distribute tasks to multiple processors or computing nodes.
[0053] In addition, the technical terms in this field include:
[0054] 1. T32: A chip independently developed by Ingenic, supporting SIMD128.
[0055] 1. SIMD: Single Instruction Multiple Data, where a single instruction can execute multiple data streams, thus improving program processing speed. (Each register is 128 bits wide).
[0056] 2. Commonly used character descriptions: word: C++ character, representing 32 bits; short: C++ character, representing 16 bits; byte: C++ character, representing 8 bits. Characters can be converted to each other based on their bit width; 1 word = 2 shorts = 4 bytes.
[0057] 3. Segment index search: Search row threshold comparison index.
[0058] 4. isp: image signal processing.
[0059] 5. Thres_sum[3]: Three threshold parameters calculated by the isp upper-layer algorithm, used for searching and comparing indexes. Summary of the Invention
[0060] To address the aforementioned problems, the objective of this application is to optimize the segment index search logic by using SIMD instructions to perform multiple threshold block index calculations, thereby improving the implementation logic. Existing technologies involve point-by-point cumulative comparisons, resulting in low computational efficiency, while this invention can calculate multiple numerical thresholds in parallel.
[0061] Specifically, this invention provides an optimization method for a segment index search algorithm. The method uses SIMD instructions to segment the data according to specific needs and performs multiple threshold block index calculations. This is a parallel threshold accumulation and segment index calculation method based on SIMD instructions. The specific number of segments can be set according to the actual data numerical distribution; assuming three thresholds, the method includes the following steps:
[0062] S1, initialize the accumulator HIST_SUM_VR to 0 to store the current accumulated value;
[0063] S2, initialize the maximum value register MAX_VAL to the maximum value of a 16-bit unsigned integer, 65535, to update the threshold that has met the conditions;
[0064] S3, load threshold vectors THRES_SUM_VR0, THRES_SUM_VR1, and THRES_SUM_VR2, which correspond to the first threshold, the second threshold, and the third threshold, respectively. The specific threshold values can be set according to the actual application scenario.
[0065] S4, use SIMD instructions to load the data block BLOCK_HIST_VR0 in parallel, and perform accumulation calculation on the accumulator HIST_SUM_VR;
[0066] S5, using the comparison instruction _mx128_cleu_h, determines whether the accumulated value HIST_SUM_VR has reached each threshold, and generates masks MASK_VR0, MASK_VR1, and MASK_VR2;
[0067] S6, based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, use the bit selection instruction _mx128_bselv to update the segment indices THRESL, THRESM, and THRESR;
[0068] S7. Based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, update the thresholds that have met the conditions to the maximum value MAX_VAL to prevent subsequent accumulation operations from affecting the index results.
[0069] The initialization methods for the accumulator HIST_SUM_VR in step S1 include:
[0070] Use the _mx128_li_h instruction to initialize HIST_SUM_VR to 0.
[0071] The loading methods for the threshold vectors THRES_SUM_VR0, THRES_SUM_VR1, and THRES_SUM_VR2 in step S3 include:
[0072] S3.1, use the _mx128_lu1q instruction to load the threshold vector from memory.
[0073] THRES_SUM_VR0;
[0074] S3.2, use the _mx128_repi_h instruction to copy the 0th, 1st and 2nd elements of THRES_SUM_VR0 to the entire register respectively, generating THRES_SUM_VR0, THRES_SUM_VR1 and THRES_SUM_VR2.
[0075] The loading methods for data block BLOCK_HIST_VR0 in step S4 include:
[0076] The _mx128_lu1q instruction loads a data block BLOCK_HIST_VR0 from memory, loading eight 16-bit unsigned integers at a time.
[0077] The accumulation calculation method in step S4 includes:
[0078] The _mx128_adduu_h instruction is used to perform an unsigned saturation addition operation between BLOCK_HIST_VR0 and HIST_SUM_VR, and then HIST_SUM_VR is updated.
[0079] The update methods for the segmented indexes THRESL, THRESM, and THRESR in step S6 include:
[0080] The current row index i is loaded using the _mx128_lu1q instruction, and then copied to the entire register using the _mx128_repi_h instruction, generating THRESL_IDX;
[0081] Use the _mx128_bselv instruction to select and update THRESL, THRESM, and THRESR based on the masks MASK_VR0, MASK_VR1, and MASK_VR2.
[0082] The threshold update method in step S7 includes:
[0083] The _mx128_bselv instruction is used to update the thresholds that meet the conditions to the maximum value MAX_VAL based on the masks MASK_VR0, MASK_VR1, and MASK_VR2.
[0084] The method is applicable to the accumulation of multiple thresholds and segmented index calculation, including but not limited to three thresholds.
[0085] The method is applicable to multiple cumulative calculations, including but not limited to 32 cumulative calculations.
[0086] The present invention also relates to a computer-readable storage medium storing program code for performing any of the methods described above.
[0087] Therefore, the advantage of this application lies in: calculating different threshold parameters by repeatedly accumulating through the simd instruction; it has the following advantages:
[0088] 1. High-efficiency parallel computing: Utilizing the SIMD (Single Instruction Multiple Data) instruction set, it can process multiple data simultaneously (such as eight 16-bit unsigned integers), significantly improving computational efficiency.
[0089] 2. Flexible segmented index calculation: Supports parallel calculation and index update of multiple thresholds (such as thresholdL, thresholdM, thresholdR), suitable for various segmentation requirements.
[0090] 3. Dynamic threshold update: After the threshold condition is met, the threshold is updated to the maximum value (MAX_VAL), avoiding unnecessary subsequent accumulation and index update operations, thus improving the calculation accuracy.
[0091] 4. High versatility: The technical solution is not limited to a specific number of thresholds or data size, and can be flexibly extended to more thresholds (such as multiple segmentation points) and larger datasets.
[0092] 5. Memory access optimization: Using SIMD instructions (such as _mx128_lu1q) to load multiple data at once reduces the number of memory accesses and improves data throughput.
[0093] 6. Code simplicity and maintainability: By using SIMD instructions and mask operations, the complex threshold judgment and index update logic is simplified into a small number of instructions, reducing code complexity.
[0094] 7. High performance and low latency: Through parallel computing and dynamic threshold updates, computational latency is significantly reduced, making it suitable for applications with high real-time requirements.
[0095] 8. Scalability: The technical solution is not only applicable to 3 thresholds, but can also be extended to more thresholds; it is not only applicable to 32 accumulations, but can also be extended to more accumulations.
[0096] 9. Hardware compatibility: Based on the general SIMD instruction set, it is compatible with multiple hardware platforms (such as CPU, GPU, etc.) and has high portability.
[0097] 10. High resource utilization: Through parallel computing and dynamic threshold updates, computing resources and memory bandwidth are fully utilized, avoiding resource waste.
[0098] In summary, this technical solution achieves efficient parallel computing, flexible segmented index calculation, and dynamic threshold updates through the SIMD instruction set, offering advantages such as high performance, low latency, strong versatility, and good scalability. Furthermore, its concise code, optimized memory access, and high hardware compatibility make it suitable for various application scenarios with high real-time requirements and large data volumes, such as image processing, signal processing, and data analysis. Attached Figure Description
[0099] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.
[0100] Figure 1This is a flowchart illustrating the method.
[0101] Figure 2 This is a schematic diagram of an embodiment of the method, taking the array block_hist
[32] [8], with 32 rows and 8 columns as an example.
[0102] Figure 3 This is a schematic diagram of the code implementation in this embodiment of the method, which calculates the indices corresponding to three thresholds (thresL, thresM, and thresR) by accumulating the data in block_hist.
[0103] Figure 4 This is a schematic diagram of the code implementation in this embodiment of the method, which uses the SIMD instruction set to perform parallel accumulation and threshold index calculation of block_hist data. Detailed Implementation
[0104] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.
[0105] This application provides an optimization method for a segment index search algorithm, such as... Figure 1 As shown, the method uses SIMD instructions to segment the data according to specific needs and performs multiple threshold block index calculations. This is a parallel threshold accumulation and segmented index calculation method based on SIMD instructions. The specific number of segments can be set according to the actual data value distribution; assuming three thresholds, the method includes the following steps:
[0106] 1.S1, Initialize the accumulator HIST_SUM_VR to 0 to store the current accumulated value; the initialization method of the accumulator HIST_SUM_VR includes:
[0107] Use the _mx128_li_h instruction to initialize HIST_SUM_VR to 0.
[0108] S2, initialize the maximum value register MAX_VAL to the maximum value of a 16-bit unsigned integer, 65535, to update the threshold that has met the conditions.
[0109] S3, load threshold vectors THRES_SUM_VR0, THRES_SUM_VR1, and THRES_SUM_VR2, which correspond to the first threshold, the second threshold, and the third threshold, respectively. The specific threshold values can be set according to the actual application scenario.
[0110] The loading methods for the threshold vectors THRES_SUM_VR0, THRES_SUM_VR1, and THRES_SUM_VR2 include:
[0111] S3.1, use the _mx128_lu1q instruction to load the threshold vector from memory.
[0112] THRES_SUM_VR0;
[0113] S3.2, use the _mx128_repi_h instruction to copy the 0th, 1st and 2nd elements of THRES_SUM_VR0 to the entire register respectively, generating THRES_SUM_VR0, THRES_SUM_VR1 and THRES_SUM_VR2.
[0114] S4, use SIMD instructions to load the data block BLOCK_HIST_VR0 in parallel, and perform accumulation calculation on the accumulator HIST_SUM_VR;
[0115] The loading methods for the data block BLOCK_HIST_VR0 include:
[0116] The _mx128_lu1q instruction loads a data block BLOCK_HIST_VR0 from memory, loading eight 16-bit unsigned integers at a time;
[0117] The accumulation calculation method includes:
[0118] The _mx128_adduu_h instruction is used to perform an unsigned saturation addition operation between BLOCK_HIST_VR0 and HIST_SUM_VR, and then HIST_SUM_VR is updated.
[0119] S5, using the comparison instruction _mx128_cleu_h, determines whether the accumulated value HIST_SUM_VR has reached each threshold, and generates masks MASK_VR0, MASK_VR1, and MASK_VR2;
[0120] S6, based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, use the bit selection instruction _mx128_bselv to update the segment indices THRESL, THRESM, and THRESR;
[0121] The update methods for the segmented indexes THRESL, THRESM, and THRESR include:
[0122] The current row index i is loaded using the _mx128_lu1q instruction, and then copied to the entire register using the _mx128_repi_h instruction, generating THRESL_IDX;
[0123] Use the _mx128_bselv instruction to select and update THRESL, THRESM, and THRESR based on the masks MASK_VR0, MASK_VR1, and MASK_VR2.
[0124] S7, based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, update the thresholds that have met the conditions to the maximum value MAX_VAL to prevent subsequent accumulation operations from affecting the indexing results; the threshold update method includes:
[0125] The _mx128_bselv instruction is used to update the thresholds that meet the conditions to the maximum value MAX_VAL based on the masks MASK_VR0, MASK_VR1, and MASK_VR2.
[0126] The method is applicable to the accumulation and segmented index calculation of multiple thresholds, including but not limited to three thresholds; that is, it is not limited to the accumulation of three thresholds, and can calculate the accumulation and judgment of multiple thresholds at the same time.
[0127] The method is applicable to multiple cumulative calculations, including but not limited to 32 cumulative calculations, and can be repeated as many times as required.
[0128] It also includes a computer-readable storage medium storing program code for performing the method according to any one of claims 1 to 9.
[0129] This invention achieves parallel loading and accumulation of data through instructions such as _mx128_lu1q and _mx128_adduu_h, reducing the number of loops and computation time; through masks (MASK_VR0, MASK_VR1, MASK_VR2) and bit selection instructions (_mx128_bselv), the segment index can be dynamically updated to adapt to different threshold conditions. The threshold register is dynamically updated using the `_mx128_bselv` instruction combined with a mask, ensuring that each threshold is calculated only once. By adjusting the threshold vector and the number of accumulations, it can adapt to different application scenarios, such as multi-level segmented index calculations or large-scale data processing. Through batch loading and parallel computing, memory bandwidth utilization is optimized, making it particularly suitable for processing large-scale data blocks. Using a unified instruction set (such as `_mx128_cleu_h` and `_mx128_bselv`) to process multiple thresholds reduces code redundancy and improves maintainability. In fields such as image processing and signal processing that require fast segmented index calculations, this technical solution can provide high-performance computing capabilities. By adjusting the threshold vector and the number of loops, it can flexibly adapt to different segmentation requirements and data processing scales. Using standardized SIMD instructions (such as loading, addition, comparison, bit selection, etc.), it can run efficiently on different hardware platforms. Once the threshold condition is met, the relevant calculations are stopped immediately, reducing unnecessary resource consumption.
[0130] To better illustrate the technical solution of this method, specific embodiments are described below:
[0131] Taking the array block_hist
[32] [8], with 32 rows and 8 columns, as an example; Figure 2 As shown, where:
[0132] Yellow: 0-8, the first threshold (thresL);
[0133] Green: 0-16, the second threshold thresM;
[0134] Purple: 0-30, the third threshold thresR;
[0135] The specific implementation code is as follows: Figure 3 As shown,
[0136] The main function of this code is to calculate the indices corresponding to three thresholds (thresL, thresM, thresR) by accumulating the data in block_hist. The code consists of three nested loops:
[0137] Outer loop: Iterate through k (0 to 7) and process the data in each column.
[0138] Middle loop: Iterates through i (0 to 31), accumulates data, and calculates the first threshold thresL. Inner loop: After finding thresL, continues to accumulate data and calculates the second threshold thresM and the third threshold thresR.
[0139] The specific process includes:
[0140] 1. Initialization
[0141] The outer loop variable k starts from 0 and iterates up to 7 (a total of 8 columns).
[0142] At the beginning of each column, hist_sum is initialized to 0 to accumulate the data in the current column.
[0143] 2. Calculate the first threshold, thresL
[0144] In the middle loop: iterate through i (from 0 to 31), accumulating block_hist[i][k] row by row into hist_sum. After each accumulation, check if hist_sum is greater than or equal to the first threshold thres_sum[0]. If the condition is met:
[0145] Assign the current row index i to thresL.
[0146] Exit the middle loop and enter the inner loop to calculate the second threshold thresM.
[0147] If the conditions are not met:
[0148] Continue adding data to the next row.
[0149] 3. Calculate the second threshold thresM
[0150] Inner loop: Starting from j=i, iterate up to 31, and continue to accumulate block_hist[j+1][k] to hist_sum.
[0151] After each accumulation, check if hist_sum is greater than or equal to the second threshold thres_sum[1]. If the condition is met:
[0152] Assign the current row index j to thresM.
[0153] Exit the inner loop and enter the next inner loop to calculate the third threshold, thresR.
[0154] If the conditions are not met:
[0155] Continue adding data to the next row.
[0156] 4. Calculate the third threshold, thresR.
[0157] Inner loop: Starting from i=j, iterate up to 31, and continue to accumulate block_hist[j+1][k] to hist_sum.
[0158] After each accumulation, check if hist_sum is greater than or equal to the third threshold thres_sum[2]. If the condition is met:
[0159] Assign the current row index i to thresR.
[0160] Break out of the inner loop and end the threshold calculation for the current column.
[0161] If the conditions are not met:
[0162] Continue adding data to the next row.
[0163] 5. Update column index k
[0164] After completing the threshold calculation for the current column, increment k and proceed to the threshold calculation for the next column.
[0165] Repeat the above process until k reaches 8, then end the outer loop.
[0166] The key points mentioned above are:
[0167] Accumulation and threshold judgment:
[0168] After each accumulation, immediately check whether the threshold condition is met to ensure that the index is updated in a timely manner.
[0169] Nested loops:
[0170] The outer loop processes each column, while the middle and inner loops calculate three thresholds respectively.
[0171] Index update:
[0172] The index of each threshold (thresL, thresM, thresR) is dynamically updated through summation and judgment.
[0173] Exit the loop early:
[0174] Once the threshold condition is met, immediately exit the current loop to avoid unnecessary calculations.
[0175] This process uses nested loops and accumulation operations to calculate the threshold index for each column of data. Its core idea is to quickly locate the index value that meets the conditions through dynamic accumulation and threshold judgment, offering high efficiency and flexibility.
[0176] The instructions are explained below:
[0177] _mx128_lu1q(void*p,0); Retrieves 128 bits of data from address p; 16 bits can load 8 values simultaneously; (Load Unaligned 1Quad-word)
[0178] li_h 0 0 0 0 0 0 0 0
[0179] _mx128_li_h(0): Initialize the register to a fixed 16-bit value; (Immediate Load)
[0180] vrs 0 1 2 3 4 5 6 7 shuf 2 2 2 2 2 2 2 2
[0181] _mx128_repi_h(vrs,2); Copies the second 16-bit data in register vrs to the entire register (Immediate Replicate Vector Element).
[0182]
[0183]
[0184] _mx128_adduu_h(vrs, vrt); Adds two unsigned 16-bit data values (Unsigned SaturateAdd).
[0185] vrs 0 1 2 3 4 5 6 7 vrt 3 4 5 6 7 0 1 2 cleu FF FF FF FF FF 0 0 0
[0186] _mx128_cleu_h(vrs,vrt); Compares vrs and vrt (vrs0 <= vrt0) ? 0xFF:0; (CompareLess-Than-or-Equal Unsigned.)
[0187] vrs 0 1 2 3 4 5 6 7 vrt 3 4 5 6 7 0 1 2 vrr FF FF FF FF FF 0 0 0 bselv 0 1 2 3 4 0 1 2
[0188] _mx128_bselv(vrs,vrt,vrr); Bit Select; Selects the corresponding data based on each bit of vrr. vrr0? vrt0:vrs0.
[0189] The following implementation utilizes the SIMD (Single Instruction Multiple Data) instruction set to perform parallel accumulation and threshold index calculation on block_hist data. The core function is to dynamically calculate the indices corresponding to three thresholds (thresL, thresM, thresR) by accumulating data, and update the thresholds after certain conditions are met to prevent duplicate calculations. The process includes initialization, data loading, accumulation calculation, threshold judgment, index update, and threshold update steps; including:
[0190] The value of hist_sum is initialized to 0, and h represents 16-bit HIST_SUM_VR = (v8u16)_mx128_li_h(0);
[0191] The 16-bit maximum value is initialized to 65535, which will be used to update the searched threshold sum in the future;
[0192] MAX_VAL=(v8u16)_mx128_li_h(65535);
[0193] Get three thresholds: thresholdL, thresholdM, and thresholdRTHRES_SUM_VR0 = _mx128_lu1q(&thres_sum[0],0);
[0194] THRES_SUM_VR2=_mx128_repi_h(THRES_SUM_VR0,2); / / thresR
[0195] THRES_SUM_VR1=_mx128_repi_h(THRES_SUM_VR0,1); / / thresM
[0196] THRES_SUM_VR0=_mx128_repi_h(THRES_SUM_VR0,0); / / thresL
[0197] Code implementation as follows Figure 4 As shown, the detailed process includes:
[0198] 1. Initialization
[0199] Initialize the accumulator:
[0200] Use _mx128_li_h(0) to initialize the accumulator HIST_SUM_VR to 0, which will be used to store the current accumulated value.
[0201] Initialize maximum value:
[0202] Use _mx128_li_h(65535) to initialize MAX_VAL to the maximum value of 65535, a 16-bit unsigned integer, for subsequent updates of thresholds that already meet the conditions.
[0203] 2. Loading threshold
[0204] Load threshold vector:
[0205] The threshold vector THRES_SUM_VR0 is loaded from memory using _mx128_lu1q(&thres_sum[0],0).
[0206] Replication threshold:
[0207] The _mx128_repi_h instruction is used to copy the 0th, 1st, and 2nd elements of THRES_SUM_VR0 to the entire register, generating three threshold vectors:
[0208] THRES_SUM_VR0: corresponds to the first threshold thresL.
[0209] THRES_SUM_VR1: corresponds to the second threshold thresM.
[0210] THRES_SUM_VR2: corresponds to the third threshold thresR.
[0211] 3. Main loop (iterating through rows)
[0212] Loop variable: i ranges from 0 to 31, iterating through each row.
[0213] 3.1 Loading Data
[0214] Load data blocks:
[0215] Use _mx128_lu1q(&block_hist[i],0) to load the eight 16-bit unsigned integers of the current line from memory into BLOCK_HIST_VR0.
[0216] 3.2 Cumulative Calculation
[0217] Cumulative data:
[0218] Use _mx128_adduu_h(HIST_SUM_VR,BLOCK_HIST_VR0) to perform an unsigned saturation addition operation between BLOCK_HIST_VR0 and HIST_SUM_VR, and update HIST_SUM_VR.
[0219] 3.3 Get the index of the current row
[0220] Load line index:
[0221] Use _mx128_lu1q(&i,0) to load the current row index i into THRESL_IDX.
[0222] Copy row index:
[0223] The 0th element of THRESL_IDX is copied to the entire register using _mx128_repi_h(THRESL_IDX,0), generating an index vector that can be used for multiple thresholds.
[0224] 3.4 Threshold Judgment
[0225] Determine the first threshold:
[0226] Use _mx128_cleu_h(THRES_SUM_VR0,HIST_SUM_VR) to compare whether HIST_SUM_VR is greater than or equal to THRES_SUM_VR0, and generate the mask MASK_VR0.
[0227] Determine the second threshold:
[0228] Use _mx128_cleu_h(THRES_SUM_VR1,HIST_SUM_VR) to compare whether HIST_SUM_VR is greater than or equal to THRES_SUM_VR1, and generate the mask MASK_VR1.
[0229] Determine the third threshold:
[0230] Use _mx128_cleu_h(THRES_SUM_VR2,HIST_SUM_VR) to compare whether HIST_SUM_VR is greater than or equal to THRES_SUM_VR2, and generate the mask MASK_VR2.
[0231] 3.5 Update Index
[0232] Update the first threshold index:
[0233] Update THRESL based on the mask MASK_VR0 using _mx128_bselv(THRESL,THRESL_IDX,MASK_VR0).
[0234] Update the second threshold index:
[0235] Update THRESM based on the mask MASK_VR1 using _mx128_bselv(THRESM,THRESL_IDX,MASK_VR1).
[0236] Update the third threshold index:
[0237] Update THRESR using _mx128_bselv(THRESR,THRESL_IDX,MASK_VR2) based on the mask MASK_VR2.
[0238] 3.6 Update threshold
[0239] Update the first threshold:
[0240] Use _mx128_bselv(THRES_SUM_VR0,MAX_VAL,MASK_VR0) to update THRES_SUM_VR0 to MAX_VAL based on the mask MASK_VR0.
[0241] Update the second threshold:
[0242] Use _mx128_bselv(THRES_SUM_VR1,MAX_VAL,MASK_VR1) to update THRES_SUM_VR1 to MAX_VAL based on the mask MASK_VR1.
[0243] Update the third threshold:
[0244] Use _mx128_bselv(THRES_SUM_VR2,MAX_VAL,MASK_VR2) to update THRES_SUM_VR2 to MAX_VAL based on the mask MASK_VR2.
[0245] It achieves efficient data loading, cumulative calculation, threshold determination, and index updating through SIMD instructions. Its core advantage lies in:
[0246] Parallel computing: Processing multiple data simultaneously to improve computational efficiency.
[0247] Dynamic updates: Once the threshold condition is met, the threshold and index are updated immediately to avoid redundant calculations. Flexibility: Supports parallel calculation of multiple thresholds, suitable for various segmentation requirements.
[0248] In summary, this invention proposes an optimization method for segment index search algorithm, which uses SIMD instructions to perform multiple threshold block index calculations, namely, a parallel threshold accumulation and segment index calculation method based on SIMD instructions. The core process of the entire technical solution includes steps such as initialization, loading, accumulation, comparison, index update, and threshold update.
[0249] The main differences from existing technologies lie in efficient parallel computing, dynamic threshold updates, and flexible segmented index calculations. The specific differences compared to existing technologies are as follows:
[0250] 1. Parallel computing vs. serial computing
[0251] Existing technology: Traditional methods usually employ serial calculation, traversing the data one by one and performing accumulation and threshold judgment, which results in low computational efficiency.
[0252] This technical solution utilizes SIMD instruction sets (such as _mx128_lu1q and _mx128_adduu_h) to achieve parallel computing, enabling the simultaneous processing of multiple data (such as eight 16-bit unsigned integers), thus significantly improving computational efficiency.
[0253] 2. Dynamic threshold update vs. static threshold determination
[0254] Existing technology: Traditional methods continue to accumulate and judge after threshold judgment, resulting in unnecessary computational overhead.
[0255] This technical solution uses masks (such as MASK_VR0, MASK_VR1, MASK_VR2) and bit selection instructions (such as _mx128_bselv) to update the threshold to the maximum value (MAX_VAL) after the threshold condition is met, avoiding unnecessary subsequent calculations and improving efficiency.
[0256] 3. Flexible segmented index calculation vs. fixed segmented index calculation
[0257] Existing technology: Traditional methods typically use fixed segmented indexes for calculation, which makes it difficult to dynamically adapt to different threshold conditions and data distributions.
[0258] This technical solution supports parallel computation and index updates of multiple thresholds (such as thresholds L, thresholds M, and thresholds R) through SIMD instructions and mask operations, and can flexibly adapt to different segmentation requirements.
[0259] 4. Batch data loading vs. single-point data loading
[0260] Existing technology: Traditional methods typically load data point by point, resulting in low memory access efficiency.
[0261] This technical solution uses SIMD instructions (such as _mx128_lu1q) to load multiple data (such as 8 16-bit unsigned integers) at once, reducing the number of memory accesses and optimizing memory bandwidth utilization.
[0262] 5. Unified instruction set processing vs. distributed logic processing
[0263] Existing technology: Traditional methods usually require writing complex logic code to handle multiple thresholds and segmented indexes, resulting in redundant and difficult-to-maintain code.
[0264] This technical solution utilizes a unified SIMD instruction set (such as _mx128_cleu_h and...).
[0265] The `_mx128_bselv` function handles multiple thresholds and segmented indices, simplifying the code logic and improving maintainability.
[0266] 6. Parallel multi-threshold judgment vs. sequential single-threshold judgment
[0267] Existing technology: Traditional methods typically determine thresholds one by one, resulting in high computational latency.
[0268] This technical solution, through SIMD instructions and masking operations, can simultaneously determine multiple thresholds (such as thresholds L, thresholds M, and thresholds R), significantly reducing computational latency.
[0269] 7. High scalability vs. fixed size limitations
[0270] Existing technology: Traditional methods are usually designed for a fixed number of thresholds and data scales, making them difficult to scale flexibly.
[0271] This technical solution can be flexibly extended to more thresholds and larger datasets by adjusting the threshold vector and the number of iterations, adapting to different application scenarios.
[0272] 8. High hardware compatibility vs. strong hardware dependency
[0273] Existing technology: Traditional methods may rely on specific hardware architectures or optimization techniques, resulting in poor portability.
[0274] This technical solution is based on a general SIMD instruction set, is compatible with multiple hardware platforms (such as CPU, GPU, etc.), and has high portability.
[0275] 9. High resource utilization rate vs. resource waste
[0276] Existing technology: Traditional methods continue calculations even after a threshold condition is met, leading to resource waste. This technical solution: Through dynamic threshold updates and mask operations, related calculations are stopped immediately after the threshold condition is met, fully utilizing computing resources and memory bandwidth.
[0277] 10. High real-time performance vs. large computational latency: Existing technologies: Traditional methods have high computational latency due to serial computation and fixed logic, making it difficult to meet real-time requirements.
[0278] This technical solution significantly reduces computation latency through parallel computing and dynamic threshold updates, making it suitable for applications with high real-time requirements.
[0279] Furthermore, compared with existing technologies, this technical solution has significant advantages in parallel computing, dynamic threshold updating, flexible segmented index calculation, batch data loading, unified instruction set processing, multi-threshold parallel judgment, scalability, hardware compatibility, resource utilization, and real-time performance. These differences make this technical solution far superior to traditional methods in terms of efficiency, flexibility, and applicability, making it particularly suitable for application scenarios that handle large-scale data and have high real-time requirements.
[0280] The instructions involved in this technical solution are applicable to the Ingenic T32 chip, and the same logic can be extended to other chip models in the future.
[0281] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0282] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0283] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An optimization method for a segment index search algorithm, characterized in that, The method uses SIMD instructions to segment the data according to specific needs and performs multiple threshold block index calculations. It is a parallel threshold accumulation and segmented index calculation method based on SIMD instructions. The specific number of segments can be set according to the actual data value distribution; assuming three thresholds, it includes the following steps: S1, initialize the accumulator HIST_SUM_VR to 0 to store the current accumulated value; S2, initialize the maximum value register MAX_VAL to the maximum value of a 16-bit unsigned integer, 65535, to update the threshold that has met the conditions; S3, load threshold vectors THRES_SUM_VR0 and THRES_SUM_VR1. THRES_SUM_VR2 corresponds to the first threshold, the second threshold, and the third threshold, respectively. The specific threshold values can be set according to the actual application scenario. S4, use SIMD instructions to load the data block BLOCK_HIST_VR0 in parallel, and perform accumulation calculation on the accumulator HIST_SUM_VR; S5, using the comparison instruction _mx128_cleu_h, determines whether the accumulated value HIST_SUM_VR has reached each threshold, and generates masks MASK_VR0, MASK_VR1, and MASK_VR2; S6, based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, use the bit selection instruction _mx128_bselv to update the segment indices THRESL, THRESM, and THRESR; S7. Based on the masks MASK_VR0, MASK_VR1, and MASK_VR2, update the thresholds that have met the conditions to the maximum value MAX_VAL to prevent subsequent accumulation operations from affecting the index results.
2. The optimization method of the segment index search algorithm according to claim 1, characterized in that, The initialization methods for the accumulator HIST_SUM_VR in step S1 include: Use the _mx128_li_h instruction to initialize HIST_SUM_VR to 0.
3. The optimization method of the segment index search algorithm according to claim 1, characterized in that, The loading methods for the threshold vectors THRES_SUM_VR0, THRES_SUM_VR1, and THRES_SUM_VR2 in step S3 include: S3.1, use the _mx128_lu1q instruction to load the threshold vector THRES_SUM_VR0 from memory; S3.2, use the _mx128_repi_h instruction to copy the 0th, 1st, and 2nd elements of THRES_SUM_VR0 to the entire register respectively, generating THRES_SUM_VR0. THRES_SUM_VR1, THRES_SUM_VR2.
4. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The loading methods for data block BLOCK_HIST_VR0 in step S4 include: The _mx128_lu1q instruction loads a data block BLOCK_HIST_VR0 from memory, loading eight 16-bit unsigned integers at a time.
5. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The accumulation calculation method in step S4 includes: The _mx128_adduu_h instruction is used to perform an unsigned saturation addition operation between BLOCK_HIST_VR0 and HIST_SUM_VR, and then HIST_SUM_VR is updated.
6. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The update methods for the segmented indexes THRESL, THRESM, and THRESR in step S6 include: The current row index i is loaded using the _mx128_lu1q instruction, and then copied to the entire register using the _mx128_repi_h instruction, generating THRESL_IDX; Use the _mx128_bselv instruction based on the masks MASK_VR0 and MASK_VR1. MASK_VR2 selects to update THRESL, THRESM, and THRESR.
7. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The threshold update method in step S7 includes: Use the _mx128_bselv instruction based on the masks MASK_VR0 and MASK_VR1. MASK_VR2 updates the threshold that has met the conditions to the maximum value MAX_VAL.
8. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The method is applicable to the accumulation of multiple thresholds and segmented index calculation, including but not limited to three thresholds.
9. An optimization method for a segment index search algorithm according to claim 1, characterized in that, The method is applicable to multiple cumulative calculations, including but not limited to 32 cumulative calculations.
10. A computer-readable storage medium, characterized in that, It stores program code for performing the method according to any one of claims 1 to 9.