A fast solution method for the reciprocal of floating point numbers based on simple SIMD instructions

By constructing a floating-point reciprocal approximation calculation formula and a value table for segmented estimation ky, combined with simple SIMD instructions and Newton iteration method, the problem of low reciprocal operation performance in the existing technology is solved, and fast and accurate floating-point reciprocal calculation is achieved , suitable for a variety of processors.

CN118885151BActive Publication Date: 2024-11-26北京麟卓信息科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411354972.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2024-11-26
Estimated Expiration
2044-09-27

AI Technical Summary

Technical Problem

When existing processors perform floating-point division operations, they lack division-related SIMD instructions, which leads to the need for multi-step transformation to achieve reciprocal solution. The SIMD instructions supported by the processor are highly complex, which limits the computing performance.

Method used

By constructing a positive floating-point reciprocal approximation calculation formula, introducing calculation parameters ky, estimating ky's value table in segments, and using simple SIMD instructions to combine to realize floating-point reciprocal operation, including basic operations such as vector subtraction, comparison, and multiplication, combined with Newton's Iterative method improves calculation accuracy.

Benefits of technology

Fast approximation of floating-point inverse is realized, which improves the computing speed of the processor and reduces the dependence on complex SIMD instructions, and is suitable for various processors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_1
    Figure SMS_1
  • Figure SMS_21
    Figure SMS_21
  • Figure QLYQS_1
    Figure QLYQS_1
Patent Text Reader

Abstract

The present invention discloses a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction, by introducing calculation parameters related to the reciprocal ky Construct a calculation formula for the approximate reciprocal of a positive floating-point number, and convert the reciprocal operation into a combination of simple SIMD instructions; then, based on the calculation accuracy of the reciprocal calculation and the value range of positive floating-point numbers, use simple SIMD instructions to estimate the calculation parameters in segments. ky The value of ky Segmented estimation value table, for input vector, according to calculation accuracy and element value range from ky Get the corresponding calculation parameters from the segmented estimate table ky , and then use simple SIMD instructions to calculate the integer value of the binary integer part of each element, and finally based on the calculation parameters ky The reciprocal of the element is calculated according to the constructed formula, the binary integer value of the integer part of the element and the binary representation of the element to complete the reciprocal calculation of the input vector, which effectively improves the calculation speed of the processor for the reciprocal operation and reduces the requirement for the processor to support complex instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of computer software development, and in particular relates to a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction. Background Art

[0002] ‌SIMD instructions are an effective way to improve the computing performance of processors. Processors such as Intel CPU, Qualcomm DSP and Baidu Kunlun Core XPU all provide SIMD instructions. However, due to the complexity of the hardware implementation of SIMD instructions, some processors only provide SIMD instructions related to the three mathematical operations of addition, subtraction and multiplication, simple logical operations, and other operations, and do not provide SIMD instructions related to division operations. Therefore, when using SIMD instructions for division operations, it is usually necessary to perform multiple steps of transformation based on existing SIMD instructions to achieve it. For example, there is a method in the prior art of first solving the reciprocal square root of a positive number and then squaring it to achieve the reciprocal solution. However, this method requires the processor to provide SIMD instructions related to the reciprocal square root operation, which is then adapted to the solution of positive numbers. Summary of the invention

[0003] In view of this, the present invention provides a method for quickly solving the reciprocal of a floating-point number based on simple SIMD instructions, and adopts simple SIMD instructions to realize the rapid estimation of a relatively accurate approximate value of the reciprocal of a floating-point number.

[0004] The present invention provides a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction, which specifically comprises the following steps:

[0005] Step 1: Construct a calculation formula for the approximate reciprocal of a positive floating-point number, as shown below:

[0006]

[0007] in, xI A positive floating point number x The binary representation of , Ex and Mx Positive floating point numbers x The binary integer value of the exponent part and the binary integer value of the integer part; Y A positive floating point number y The binary representation of ky is the calculation parameter;

[0008] Step 2: Given the calculation accuracy AP ,according to Ex Based on the calculation formula for the reciprocal approximation of positive floating-point numbers constructed in step 1, ky Perform segmented estimation to form a calculation accuracy AP , kyThe estimated value and its corresponding floating point range ky Table of estimated values ​​by segment;

[0009] Step 3: For the input vector in whose elements are floating-point numbers and can be directly processed by SIMD instructions, a vector subtraction instruction is used to implement the subtraction operation between the input vector in and the input vector in to obtain the all-zero vector out; then a vector comparison instruction is used to compare the input vector in with the all-zero vector out, and a sign vector sign is formed from the comparison result; finally, a scalar multiplication vector instruction and a scalar addition vector instruction are used to correct the sign of each element in the sign vector sign to make it the same as the sign of the corresponding element of the input vector in;

[0010] Step 4: Use the vector multiplication instruction to multiply the sign vector sign and the input vector in to realize the positive number conversion of the input vector in;

[0011] Step 5: For each element in the input vector in, calculate the floating point number according to the determined calculation precision and the floating point range to which the element belongs. ky Look up the corresponding ky Estimated value, corresponding to all elements ky The estimated values ​​form a floating point vector vky;

[0012] Step 6: Convert the input vector in to an unsigned integer vector in_int, and use the bitwise AND instruction to perform a bitwise AND operation on in_int and the scalar 0x1fffff to obtain a vector Mx_int; use the sum instruction to perform a sum operation on Mx_int and the scalar 0x3f800000, and update Mx_int with the result of the sum operation; convert Mx_int to a floating-point vector Mx_float, and then use the multiplication instruction to perform a multiplication operation on Mx_float and the scalar 0x3f800000. Perform multiplication calculation to obtain a floating point vector Mx;

[0013] Step 7: Based on the floating-point vector vky obtained in step 5 and the floating-point vector Mx obtained in step 6, use addition, subtraction and multiplication instructions to complete the formula The floating-point vector magic is obtained by calculation; the vector forced conversion instruction is used to convert the magic value into an unsigned integer vector magic_int, and the vector minus vector instruction is used to subtract in_int and magic_int to obtain an unsigned integer vector out_int, and then out_int is converted to a floating-point vector out_f; finally, the multiplication instruction is used to multiply out_f and sign to obtain the approximate value of the reciprocal of the input vector in.

[0014] Furthermore, the method of constructing the calculation formula for the reciprocal approximation of a positive floating-point number in step 1 is:

[0015] Step 1.1, let positive floating point number x The reciprocal of y , then: , ,in, Ey and My Positive floating point numbers y The binary integer value of the exponent part and the binary integer value of the integer part; xI and Y satisfy ,in, kx is the calculation parameter, , ;

[0016] Step 1.2: Expand using Taylor formula and take kx The second-order estimate of is: , constructed from this .

[0017] Further, in step 2 ky The process of constructing the segmented estimate table is:

[0018] Step 2.1: Integer Ex The value range is [0,255], which is divided into NE Segments, each segment contains 256 / NE data, and record the data quantity as LE , then i The value of the segment data is in the range of , corresponding to i The floating point range that segment data can represent is ;

[0019] Step 2.2: For each segment of data, convert it from the floating point range Winning NEF Data ky Estimates, among which j Floating point numbers are represented as x ij , x ij The value of ;

[0020] Step 2.3, Settings ky After the initial value, according to the calculation accuracy AP For each floating point number x ij Iterative calculation using feedback ky The value of is taken as a quasi-estimate;

[0021] Step 2.4: Use Calculate each segment of data NEF Accurate estimate ky ij The average ky i ,Will ky i As the corresponding segment data ky An estimate of AP , ky i And the floating point range of its corresponding segment data constitute ky Table of segmented estimates.

[0022] Furthermore, the calculation method of the quasi-estimated value in step 2.3 is:

[0023] Step 2.3.1. Calculate floating point numbers x ij The reciprocal of y ij ;

[0024] Step 2.3.2: x ij Corresponding xI ij Substitution Calculated Y ij , and then Y ij Convert the binary representation of a floating point number to Y ij ;

[0025] Step 2.3.3: According to the formula Calculate the difference in results d ij ,like d ij The absolute value is not greater than the calculation precision AP , then ky The current value of ky ij , execute step 2.4; otherwise, according to the formula renew ky After obtaining the value of , execute step 2.3.2.

[0026] Furthermore, the Newton iteration method is used to process the floating-point vector out_f and the positive input vector in to obtain the positive floating-point reciprocal.

[0027] Furthermore, the method of using Newton's iteration method to process the floating-point vector out_f and the positive input vector in to obtain the reciprocal of the positive floating-point number is:

[0028] The iteration body is constructed as follows: a multiplication instruction is used to multiply the positive input vector in with the floating-point vector out_f, and then the result of the multiplication operation is multiplied by 2.0 to obtain an intermediate result vector tmp, and out_f is updated using the result of the multiplication of tmp and out_f; the iteration body is executed twice to obtain the reciprocal of the positive floating-point number.

[0029] Furthermore, the corresponding operation process of the iterative body in the Kunlun core XPU is: float32x16_t tmp =vvmul_float32x16(in, out_f), tmp = svsub_float32x16(2.0f, tmp) and out_f = vvmul_float32x16(out_f, tmp). Beneficial Effects

[0030] The present invention introduces a calculation parameter related to the inverse ky Construct a calculation formula for the approximate reciprocal of a positive floating-point number, and convert the reciprocal operation into a combination of simple SIMD instructions; then, based on the calculation accuracy of the reciprocal calculation and the value range of positive floating-point numbers, use simple SIMD instructions to estimate the calculation parameters in segments. ky The value of ky Segmented estimation value table, for input vector, according to calculation accuracy and element value range from ky Get the corresponding calculation parameters from the segmented estimate table ky , and then use simple SIMD instructions to calculate the integer value of the binary integer part of each element, and finally based on the calculation parameters ky The reciprocal of the element is calculated based on the constructed formula using the binary integer value of the integer part of the element and the binary representation of the element, thereby completing the reciprocal calculation of the input vector, which effectively improves the processor's calculation speed for the reciprocal operation and reduces the requirement for the processor to support complex instructions. DETAILED DESCRIPTION

[0031] The present invention is described in detail with reference to the following embodiments.

[0032] The present invention provides a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction. The core idea is to introduce calculation parameters related to the reciprocal. ky Construct a calculation formula for the approximate reciprocal of a positive floating-point number, and convert the reciprocal operation into a combination of simple SIMD instructions; then, based on the calculation accuracy of the reciprocal calculation and the value range of positive floating-point numbers, use simple SIMD instructions to estimate the calculation parameters in segments. ky The value of ky Segmented estimation value table, for input vector, according to calculation accuracy and element value range from ky Get the corresponding calculation parameters from the segmented estimate table ky , and then use simple SIMD instructions to calculate the integer value of the binary integer part of each element, and finally based on the calculation parameters ky The reciprocal of the element is calculated based on the constructed formula using the binary integer value of the integer part of the element and the binary representation of the element, thereby completing the reciprocal calculation of the input vector.

[0033] The present invention provides a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction, which specifically comprises the following steps:

[0034] Step 1: Construct a calculation formula for the approximate reciprocal of a positive floating-point number, as shown below:

[0035]

[0036] in, xI A positive floating point number x The binary representation of is , Ex and Mx Positive floating point numbers x The exponent part and the integer part of a binary integer value; Y A positive floating point number y The binary representation of ky is the calculation parameter.

[0037] The calculation formula for the reciprocal approximate value of a positive floating point number constructed by the present invention is derived as follows:

[0038] Step 1.1, let the positive floating point number be x , whose reciprocal is y , then: .

[0039] For a 32-bit floating point number, the highest bit, i.e. the 32nd bit, is the sign bit, the 8 bits from the 24th to the 31st bit are the exponent bits, and the 23 bits from the 1st to the 23rd bit are the mantissa bits. x The corresponding decimal value is ,in, sf is the decimal value corresponding to the sign bit, mf is the decimal value corresponding to the mantissa, ef The decimal value corresponding to the exponent bit.

[0040] Step 1.2: Convert positive floating point numbers x and y The binary representation of the integer is represented as xI and Y , then: , ,in, Ex and Mx Positive floating point numbers x The exponent part and the integer part are binary integer values, Ey and My Positive floating point numbers y The exponent part and the integer part are binary integer values.

[0041] at the same time, xI and Y Existence relationship: ,in, kx and ky are all calculated parameters, and there are: , .

[0042] Step 1.3: Expand using Taylor formula and take kx The second-order estimate of is: , from which we have: .

[0043] From this we can see that when a positive floating point number x , Mx and xI If the quantities are known, then ky You can accurately obtain positive floating point numbers x The reciprocal value of .

[0044] Step 2: Calculate the required precision according to the reciprocal of the floating point number AP , according to the positive floating point number x The binary integer value of the exponential part of the positive floating-point number is calculated based on the approximate reciprocal value calculation formula constructed in step 1. ky Perform segmented estimation to form a calculation accuracy AP , ky The estimated value and its corresponding floating point range ky Table of segmented estimates.

[0045] Above ky The process of building the segmented estimates table includes the following steps:

[0046] Step 2.1: Integer Ex The value range is [0,255], which is divided into NE Segments, each segment contains 256 / NE data, and record the data quantity as LE , then i The value of the segment data is in the range of , corresponding to i The floating point range that segment data can represent is .

[0047] Step 2.2: For each segment of data, convert it from the floating point range Winning NEF Data ky Estimates, among which j Floating point numbers are represented as x ij , x ij The value of .

[0048] Step 2.3, Settings ky After the initial value, according to the calculation accuracy AP For every positive floating point number x ij Iterative calculation using feedback ky The values ​​of include:

[0049] Step 2.3.1. Calculate positive floating point numbers x ij The reciprocal of y ij ;

[0050] Step 2.3.2: x ij Corresponding xI ij Substitution Calculated Y ij , and then Y ij Convert the binary representation of a floating point number to Y ij ;

[0051] Step 2.3.3: According to the formula Calculate the difference in results d ij ,like d ij The absolute value is not greater than the calculation precision AP , then ky The current value of ky ij , execute step 2.4; otherwise, according to the formula renew ky After obtaining the value of , execute step 2.3.2.

[0052] Step 2.4: Calculate the value of each segment of data NEF Accurate estimate ky ij The average ky i ,Right now, ,Will kyi As the corresponding segment data ky The estimated value of AP , ky i And the floating point range of its corresponding segment data Save to ky Segmented estimates table.

[0053] For example, you can ky The segmented estimated value is denoted as ktb, which contains NE Rows of data, and each row records the following floating point numbers: AP , , and ky i .

[0054] Step 3: For the input vector in whose elements are floating-point numbers and can be directly processed by SIMD instructions, a vector subtraction instruction is used to implement the subtraction operation between the input vector in and the input vector in to obtain the all-zero vector out; then a vector comparison instruction is used to compare the input vector in with the all-zero vector out, and the comparison result forms a sign vector sign. Specifically, if in[ m ] is less than out[ m ] then sign[ m ] is 1, otherwise sign[ m ] is 0; finally, the scalar multiplication vector instruction and the scalar addition vector instruction are used to correct the sign of each element in the sign vector sign so that it is the same as the sign of the corresponding element of the input vector in, thereby obtaining the sign of each element in the input vector in.

[0055] Step 4: Use the vector multiplication instruction to multiply the symbol vector sign and the input vector in to realize the positive conversion of the input vector in.

[0056] For example, in the Kunlun core XPU, the positive number operation process is: in = vvmul_float32x16(in,sign), vvmul_float32x16 is a vector multiplication instruction.

[0057] Step 5: For each element in the input vector in, calculate the floating point number according to the determined calculation precision and the floating point range to which the element belongs. ky Look up the corresponding ky Estimated value, corresponding to all elements ky The estimated values ​​form a floating point vector vky.

[0058] Step 6. Convert the input vector in to an unsigned integer vector in_int, and use the bitwise AND instruction to perform bitwise AND calculation on in_int and the scalar 0x1fffff to obtain the vector Mx_int; use the sum instruction to perform sum calculation on the vector Mx_int and the scalar 0x3f800000, and use the sum calculation result to update the vector Mx_int; convert the vector Mx_int to a floating-point vector Mx_float, and the value of the element in Mx_float is , and then use the multiplication instruction to multiply the vector Mx_float and the scalar The multiplication is performed to obtain a floating point vector Mx.

[0059] Step 7: Based on the floating-point vector vky obtained in step 5 and the floating-point vector Mx obtained in step 6, use addition, subtraction and multiplication instructions to complete the formula The floating-point vector magic is obtained by calculation; the vector forced conversion instruction is used to convert the floating-point vector magic into an unsigned integer vector magic_int, and the vector subtraction instruction is used to subtract the vector in_int from the vector magic_int to obtain the unsigned integer vector out_int, and then the vector out_int is converted to a floating-point vector out_f, and the vector out_f is the approximate value of the reciprocal of the positive input vector in; the multiplication instruction is used to multiply the vector out_f and the vector sign to obtain the approximate value of the reciprocal of the input vector in.

[0060] In order to further improve the calculation accuracy of the reciprocal of the positive input vector in, the Newton iteration method is used to process the floating point vector out_f and the positive input vector in, specifically including:

[0061] Establish an iteration body: Use a multiplication instruction to multiply the positive input vector in with the floating-point vector out_f, and then multiply the result of the multiplication operation by 2.0 to obtain an intermediate result vector tmp. Use the result of multiplying vector tmp with vector out_f to update vector out_f to obtain a more accurate reciprocal value vector out_f. For example, in the Kunlun core XPU, the operation process of the iteration body is: float32x16_t tmp = vvmul_float32x16(in, out_f), tmp = svsub_float32x16(2.0f, tmp) and out_f = vvmul_float32x16(out_f, tmp);

[0062] By executing two iterations of the iteration body, the reciprocal of a positive floating-point number with higher precision can be obtained. Example

[0063] In this implementation, a method for quickly solving the reciprocal of a floating point number based on a simple SIMD instruction provided by the present invention is used to quickly solve the reciprocal of a floating point number based on a simple SIMD instruction in the Kunlun core XPU, specifically including:

[0064] The simple SIMD instructions and expressions commonly used in Kunlun Core XPU are shown in the following table:

[0065] Table 1 Simple SIMD instructions and expressions

[0066] Vector Operations Vector Instructions (Kunlun Core) expression Vector plus vector vvadd_dataType vc = va + vb Scalar plus vector svadd_dataType vc = sa + vb Vector minus vector vvsub_dataType vc = va - vb Scalar minus vector svsub_dataType vc = sa - vb Vector multiplication vvmul_dataType vc = va * vb Scalar multiplication of vector svmul_dataType vc = sa * vb Vector is less than vector vvsetlt_dataType vc = va < vb Vector is greater than vector vvsetlt_dataType vc = va > vb Scalar vector bitwise AND svand_dataType vc = va & vb Vector floating point to integer conversion vfloat2uint vc = (uint32x16)va Vector reinterpretation vc = *(dataType*)&va

[0067] The present invention mainly uses simple vector operations such as vector addition, subtraction, multiplication, comparison and type conversion in the above table. The interfaces of vector instructions in different processors will be different. In Kunlun core, the data types in vector instructions can be half-precision floating-point vector bfloat16x32, single-precision floating-point vector float32x16_t, unsigned integer vector uint32x16_t and integer vector int32x16_t, va and vb are the input vectors of the instruction, vc is the return value vector, and sa is the corresponding scalar input. In the vector floating-point to integer instruction, va is a single-precision floating-point vector float32x16_t, and vb is an unsigned integer vector uint32x16_t. The vector reinterpretation operation obtains the address of va and treats it as an address of other data types to access and obtain other types of values.

[0068] S1. In Kunlun Core XPU, the type of input vector in is float32x16_t. Get the sign of input vector in.

[0069] The type float32x16_t in the Kunlun core XPU represents a vector consisting of 16 32-bit floating-point numbers, which can be directly processed by SIMD instructions.

[0070] S1.1. Use the vector subtraction instruction vvsub_float32x16 to perform the operation float32x16_t out =vvsub_float32x16(in, in) to subtract vector in from vector in and obtain vector out with a data value of 0.

[0071] S1.2. Use the vector comparison instruction vvsetlt_float32x16 to determine whether the elements in the vector in are less than 0 by calculating float32x16_t sign =vvsetlt_float32x16(in, out). For elements less than 0, the corresponding element in the vector sign is 1, otherwise it is 0, and the vector sign reflecting the sign of the input vector in is obtained.

[0072] S1.3. Use the scalar multiplication vector instruction svmul_float32x16 and the scalar addition vector instruction svadd_float32x16 to correct the vector sign by performing the operations sign = svmul_float32x16(-2.0f, sign) and sign = svadd_float32x16(1.0f, sign) so that the elements in the vector sign have the same sign as the corresponding elements in the vector in.

[0073] For example, if in[ m ] is a positive number, then sign[ m ] is 1.0, if in[ m ] is a negative number, then sign[ m ] is -1.0.

[0074] S2. Use the vector-to-vector multiplication instruction vvmul_float32x16 to make the input vector in positive by performing the operation in = vvmul_float32x16(in, sign).

[0075] S3, according to the calculation accuracy AP And the value range of each element in the input vector in, find ky The segmented estimated value table obtains the corresponding value of each element in the input vector in ky Estimated values, forming a floating point vector vky.

[0076] S4. By performing the operation uint32x16_t in_int =*((uint32x16_t*)&in), where uint32x16_t is an unsigned integer vector type, the floating-point vector in is interpreted as an unsigned integer vector in_int.

[0077] S5. Use the scalar vector bitwise AND vector instruction to implement the bitwise AND calculation of vector in_int and scalar 0x1fffff to obtain vector Mx_int; use the scalar plus vector vector instruction to implement the sum calculation of vector Mx_int and scalar 0x3f800000, and use the sum calculation result to update vector Mx_int; use the vector reinterpretation operation to interpret vector Mx_int as floating-point vector Mx_float; use the vector multiplication vector instruction to implement the vector Mx_float and scalar The multiplication calculation results in a floating-point vector Mx.

[0078] S6. Use floating-point vector-to-vector and vector-to-scalar addition, subtraction, and multiplication operations to complete the formula The calculation results in a floating point vector magic.

[0079] S7. Use the floating point number to unsigned integer vector forced conversion instruction to convert the floating point vector magic and other values ​​into the unsigned integer vector magic_int.

[0080] S8. Use the svsub_uint32x16 unsigned integer scalar subtraction vector instruction to perform operations uint32x16_tout_int = svsub_uint32x16(magic_int, in_int) and out_f = *((float32x16_t*)&out_int) to subtract in_int from the magic number magic_int to obtain the unsigned integer vector out_int. Then reinterpret out_int as a floating-point vector out_f to obtain the approximate value of the reciprocal of the positive floating-point number.

[0081] S9. Use the vvmul_float32x16 vector multiplication instruction to calculate the reciprocal vector out_f of the floating-point vector in by performing the operation out_f = vvmul_float32x16(out_f, sign).

[0082] S10. Construct the iteration body in Newton's iteration method through operations: float32x16_t tmp = vvmul_float32x16(in, out_f), tmp =svsub_float32x16(2.0f, tmp) and out_f = vvmul_float32x16(out_f, tmp). Iterate the iteration body twice to obtain the reciprocal of a positive floating-point number with higher precision.

[0083] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A fast solution method for the reciprocal of floating-point numbers based on simple SIMD instructions. It is characterized in that The specific steps include: Step 1: Construct a calculation formula for the approximate reciprocal of a positive floating-point number, as shown below: Where xI is the binary representation of the positive floating point number x, and , Ex and Mx are the binary integer values ​​of the exponent part and the binary integer value of the integer part of the positive floating point number x respectively; yI is a positive floating point number y The binary representation of , ky is the calculation parameter; Step 2: Given the calculation accuracy AP, ky is estimated piecewise according to the positive floating-point reciprocal approximate value calculation formula constructed by Ex based on step 1, forming a ky piecewise estimated value table consisting of the calculation accuracy AP, ky estimated value and the corresponding floating-point number range; Step 3: For the input vector in whose elements are floating-point numbers and can be directly processed by SIMD instructions, a vector subtraction instruction is used to implement the subtraction operation between the input vector in and the input vector in to obtain the all-zero vector out; then a vector comparison instruction is used to compare the input vector in with the all-zero vector out, and a sign vector sign is formed from the comparison result; finally, a scalar multiplication vector instruction and a scalar addition vector instruction are used to correct the sign of each element in the sign vector sign to make it the same as the sign of the corresponding element of the input vector in; Step 4: Use the vector multiplication instruction to multiply the sign vector sign and the input vector in to realize the positive number conversion of the input vector in; Step 5: For each element in the input vector in, find the corresponding ky estimated value in the ky segmented estimated value table according to the determined calculation accuracy and the floating point number range to which the element belongs, and form a floating point number vector vky from the ky estimated values ​​corresponding to all elements; Step 6: Convert the input vector in to an unsigned integer vector in_int, and use the bitwise AND instruction to perform a bitwise AND operation on in_int and the scalar 0x1fffff to obtain a vector Mx_int; use the sum instruction to perform a sum operation on Mx_int and the scalar 0x3f800000, and update Mx_int with the result of the sum operation; convert Mx_int to a floating-point vector Mx_float, and then use the multiplication instruction to perform a multiplication operation on Mx_float and the scalar 0x3f800000. Perform multiplication calculation to obtain a floating point vector Mx; Step 7: Based on the floating-point vector vky obtained in step 5 and the floating-point vector Mx obtained in step 6, use addition, subtraction and multiplication instructions to complete the formula The floating-point vector magic is obtained by calculation; the vector forced conversion instruction is used to convert the magic value into an unsigned integer vector magic_int, and the vector minus vector instruction is used to subtract in_int and magic_int to obtain an unsigned integer vector out_int, and then out_int is converted to a floating-point vector out_f; finally, the multiplication instruction is used to multiply out_f and sign to obtain the approximate value of the reciprocal of the input vector in.

2. The method for quickly solving the reciprocal of a floating point number according to claim 1, It is characterized in that The method of constructing the calculation formula for the reciprocal approximation of a positive floating-point number in step 1 is: Step 1.1, let the reciprocal of the positive floating point number x be , then: , , where Ey and My are the binary integer values ​​of the exponent part and the binary integer value of the integer part of the positive floating point number y respectively; xI and yI satisfy , where kx is the calculation parameter, , ; Step 1.2, use Taylor formula expansion and take the second-order estimate of kx, then we have: , constructed from this .

3. The method for quickly solving the reciprocal of a floating point number according to claim 1, It is characterized in that The construction process of the ky segment estimation value table in step 2 is: Step 2.1, the value range of integer Ex is [0,255], the value range is divided into NE segments, each segment contains 256 / NE data, the number of data is recorded as LE, then the value of the i-th segment data is in the range , the floating point range that can be represented by the corresponding i-th segment of data is ; Step 2.2: For each segment of data, convert it from the floating point range Take NEF data from the ky estimation, where the jth floating point number is represented by x ij , x ij The value of ; Step 2.3: After setting the initial value of ky, calculate the calculation accuracy AP for each floating point number x. ij The value of ky is calculated by feedback iteration as a quasi-estimate; Step 2.4: Use Calculate the NEF ky estimate for each segment of data ij The average value of i , will ky i As the estimated value of ky for the corresponding segment data; by calculating the accuracy AP, ky i And the floating point range of its corresponding segment data Construct the ky segment estimate value table.

4. The method for quickly solving the reciprocal of a floating point number according to claim 3, It is characterized in that The calculation method of the accurate estimate in step 2.3 is: Step 2.3.

1. Calculate the floating point number x ij The reciprocal of y ij ; Step 2.3.2: x ij Corresponding xI ij Substitution Calculate yI ij , and then yI ij The binary representation of 𝑦𝐹 is converted to a floating point number 𝑖𝑗 ; Step 2.3.3: According to the formula The calculated result difference d ij , if d ij If the absolute value of ky is not greater than the calculation accuracy AP, the current value of ky is taken as the quasi-estimated value ky. ij , execute step 2.4; otherwise, according to the formula After updating the value of ky, execute step 2.3.

2.

5. The method for quickly solving the reciprocal of a floating point number according to claim 1, It is characterized in that The Newton iteration method is used to process the floating-point vector out_f and the positive input vector in to obtain the reciprocal of the positive floating-point number.

6. The method for quickly solving the reciprocal of a floating point number according to claim 5, It is characterized in that The method of using Newton's iteration method to process the floating-point vector out_f and the positive input vector in to obtain the reciprocal of the positive floating-point number is: The iteration body is constructed as follows: a multiplication instruction is used to multiply the positive input vector in with the floating-point vector out_f, and then the result of the multiplication operation is multiplied by 2.0 to obtain an intermediate result vector tmp, and out_f is updated using the result of the multiplication of tmp and out_f; the iteration body is executed twice to obtain the reciprocal of the positive floating-point number.

7. The method for quickly solving the reciprocal of a floating point number according to claim 6, It is characterized in that The corresponding operation process of the iterative body in the Kunlun core XPU is: float32x16_t tmp = vvmul_float32x16(in, out_f), tmp = svsub_float32x16(2.0f, tmp) and out_f = vvmul_float32x16(out_f, tmp).