Electronic device and floating point data processing method and readable medium thereof

By adding a control unit to the processor, judging the operation conditions of floating-point numbers and determining the operation sequence, the problem of square root calculations exceeding the range after the reciprocating floating-point numbers is solved, and the calculation accuracy and stability are improved.

CN114356279BActive Publication Date: 2024-11-26ARM TECH CHINA CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210042675.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-14
Publication Date
2024-11-26
Estimated Expiration
2042-01-14

AI Technical Summary

Technical Problem

When a computer stores and processes floating-point numbers, due to the limited range of binary numbers, when directly performing reciprocating the floating-point numbers and then performing square root operations, it may exceed the representation range, resulting in infinity of the output or an error, affecting the calculation accuracy.

Method used

Add a control unit to the processor to determine whether the floating point number meets the square root reciprocal operation condition, and determine the order of the reciprocal and square root operations based on the value of the biased exponent E field to ensure that the result is within the representation range.

Benefits of technology

Improve the accuracy of square root reciprocating of floating point numbers, avoid infinite output and calculation errors, and effectively utilize existing processor hardware resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114356279B_ABST
    Figure CN114356279B_ABST
Patent Text Reader

Abstract

The present application relates to an electronic device and a method for processing floating-point data thereof, and a readable medium. The electronic device includes: a memory and a processor. When an instruction is executed by one or more processors of the electronic device, the processor performs the following operations: obtaining the input floating-point data to be processed; determining the biased exponent E field corresponding to the floating-point data to be processed when stored in the electronic device; determining the order of operations for performing reciprocal operations and square root operations on the floating-point data to be processed according to the value of the E field; calculating the floating-point number based on the order of operations to obtain the reciprocal square root of the floating-point data to be processed; and outputting the reciprocal square root of the floating-point data to be processed. The technical solution of the application determines the order of operations for performing reciprocal operations and square root operations on the floating-point data according to the value of the E field corresponding to the floating-point data, which can improve the accuracy of the reciprocal square root operation of the floating-point number.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to an electronic device and a floating point data processing method and a readable medium thereof. Background Art

[0002] With the development of artificial intelligence (AI), the application of reciprocal square root operation on floating point numbers is becoming more and more widespread. Referring to the IEEE 754 standard, floating point numbers can be divided into single-precision floating point numbers and double-precision floating point numbers. Among them, single-precision floating point numbers occupy 32 bits in computer memory, and double-precision floating point numbers occupy 64 bits in computer memory. For a real number, the result obtained by first performing the reciprocal operation on the real number and then performing the square root operation is the same as the result obtained by first performing the square root operation on the real number and then performing the reciprocal operation on the real number.

[0003] However, when a computer stores a floating-point number, it stores the floating-point number in a 32-bit or 64-bit binary number. Since the range of floating-point numbers that can be represented by a 32-bit or 64-bit binary number is limited, in some cases, when the reciprocal operation is directly performed on the floating-point number, the range of the reciprocal obtained exceeds the range of floating-point numbers that can be represented by the aforementioned 32-bit or 64-bit binary number. In this case, when the computer performs a square root operation on the aforementioned reciprocal, it will output an infinite value or directly report an error. Summary of the invention

[0004] In view of this, the present application provides an electronic device and a method for processing floating-point data thereof, and a readable medium. The technical solution of the present application is to add a control unit in a processor, and before performing a square root inverse calculation on a floating-point number, first determine whether the floating-point data to be calculated meets the operation conditions of the square root inverse. In the case where it is determined that the floating-point data to be calculated meets the operation conditions of the square root inverse, in order to make the calculated square root inverse result more accurate, the biased exponent E field corresponding to the floating-point data when stored in the computer can be determined, and then the order of performing the inverse operation and the square root operation on the floating-point data can be determined according to whether the value of the E field corresponding to the floating-point data reaches a set threshold. The floating-point number is calculated based on the operation order to obtain the square root inverse of the floating-point data to be processed. The method utilizes the original operation logic circuit in the processor, and only adds a control unit. Under the condition of effectively utilizing the hardware resources of the existing processor, the accuracy of the square root inverse operation of the floating-point number can be improved at a low cost.

[0005] In a first aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions executed by one or more processors of the electronic device, and

[0006] Processor, when the instruction is executed by one or more processors of the electronic device, the processor performs the following operations:

[0007] Get the input floating point data to be processed;

[0008] Determine a biased exponent E field corresponding to the floating point data to be processed when it is stored in the electronic device;

[0009] Determine whether the floating-point data to be processed meets the reciprocal square root operation condition, and determine the order of performing the reciprocal operation and the square root operation on the floating-point data to be processed according to the value of the E field;

[0010] Calculate the floating point number based on the operation order to obtain the inverse square root of the floating point data to be processed;

[0011] Output the inverse square root of the floating-point data to be processed.

[0012] In a possible implementation of the first aspect, the square root inverse operation condition includes:

[0013] The floating-point data to be processed is not any of 0, negative number, positive infinity, and NaN.

[0014] In a possible implementation of the first aspect, the processor determines the order of performing the reciprocal operation and the square root operation on the floating-point data to be processed according to the value of the E field in the following manner:

[0015] Determine the decimal value corresponding to the E field according to the value of the E field;

[0016] When it is determined that the decimal value corresponding to the E field is less than the set threshold, the operation sequence corresponding to the floating-point data to be processed is determined as follows: firstly performing a square root operation on the floating-point data to be processed to obtain a square root operation result of the floating-point data to be processed, and then performing a reciprocal operation on the square root operation result to obtain a reciprocal square root of the floating-point data to be processed; or

[0017] When it is determined that the decimal value corresponding to the E field is greater than or equal to the set threshold, the order of operations corresponding to the floating-point data to be processed is determined as follows: first, a reciprocal operation is performed on the floating-point data to be processed to obtain the reciprocal operation result of the floating-point data to be processed, and then a square root operation is performed on the reciprocal operation result to obtain the reciprocal square root of the floating-point data to be processed.

[0018] In a possible implementation of the first aspect, the processor determines the set threshold in the following manner:

[0019] Determine the number of bits of the binary value corresponding to the floating point data to be processed when it is stored in the electronic device;

[0020] Determine the floating point data range that can be represented by a multi-bit binary number having the same number of bits as the binary value corresponding to the floating point data to be processed;

[0021] The set threshold is determined according to whether the reciprocal operation result obtained after the reciprocal operation is performed on the floating-point data to be processed is within the floating-point data range.

[0022] In a possible implementation of the first aspect above, the threshold is set to 1.

[0023] In a possible implementation of the first aspect, the floating-point data to be processed is image data.

[0024] In a second aspect, an embodiment of the present application provides a method for processing floating-point data, comprising:

[0025] Get the input floating point data to be processed;

[0026] Determine a biased exponent E field corresponding to the floating point data to be processed when it is stored in the electronic device;

[0027] Determine whether the floating-point data to be processed meets the reciprocal square root operation condition, and determine the order of performing the reciprocal operation and the square root operation on the floating-point data to be processed according to the value of the E field;

[0028] Calculate the floating point number based on the operation order to obtain the inverse square root of the floating point data to be processed;

[0029] Output the inverse square root of the floating-point data to be processed.

[0030] In a possible implementation of the second aspect, the square root inverse operation condition includes:

[0031] The floating-point data to be processed is not any of 0, negative number, positive infinity, and NaN.

[0032] In a possible implementation of the second aspect, determining the order of performing the reciprocal operation and the square root operation on the floating-point data to be processed according to the value of the E field includes:

[0033] Determine the decimal value corresponding to the E field according to the value of the E field;

[0034] When it is determined that the decimal value corresponding to the E field is less than the set threshold, the operation sequence corresponding to the floating-point data to be processed is determined as follows: firstly performing a square root operation on the floating-point data to be processed to obtain a square root operation result of the floating-point data to be processed, and then performing a reciprocal operation on the square root operation result to obtain a reciprocal square root of the floating-point data to be processed; or

[0035] When it is determined that the decimal value corresponding to the E field is greater than or equal to the set threshold, the order of operations corresponding to the floating-point data to be processed is determined as follows: first, a reciprocal operation is performed on the floating-point data to be processed to obtain the reciprocal operation result of the floating-point data to be processed, and then a square root operation is performed on the reciprocal operation result to obtain the reciprocal square root of the floating-point data to be processed.

[0036] In a possible implementation of the second aspect, the method further includes:

[0037] The threshold is determined by:

[0038] Determining the number of bits of a binary value corresponding to the floating-point data to be processed when it is stored in the electronic device;

[0039] Determine the floating point data range that can be represented by a multi-bit binary number having the same number of bits as the binary value corresponding to the floating point data to be processed;

[0040] The set threshold is determined according to whether the reciprocal operation result obtained after the reciprocal operation is performed on the floating-point data to be processed is within the floating-point data range.

[0041] In a possible implementation of the second aspect, the set threshold is 1.

[0042] In a possible implementation of the second aspect, the floating-point data to be processed is image data.

[0043] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0044] A special data processing unit is used to obtain input floating point data to be processed, and determine whether the floating point data to be processed meets the inverse square root operation condition according to the biased exponent E field corresponding to the floating point data to be processed when it is stored in the electronic device;

[0045] A control unit, for determining, according to the value of the E field, the order of performing a reciprocal operation and a square root operation on the floating-point data to be processed;

[0046] A reciprocal operation unit, used for performing a reciprocal operation on the floating-point data to be processed or the square root operation result of the floating-point data to be processed;

[0047] A square root operation unit, used for performing a square root operation on the floating point data to be processed or the reciprocal operation result of the floating point data to be processed;

[0048] The multiplexer unit is used to output the inverse square root of the floating point data to be processed.

[0049] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, including: instructions are stored on the computer-readable storage medium, and when the instructions are executed on an electronic device, the electronic device executes the above-mentioned second aspect and any one of the various possible implementations of the second aspect for processing floating-point data.

[0050] In a fifth aspect, an embodiment of the present application provides a computer program product, including: the computer program product includes instructions, and the instructions are used to implement the above-mentioned second aspect and any one of the floating-point data processing methods in various possible implementations of the second aspect.

[0051] In a sixth aspect, an embodiment of the present application provides a chip device, including:

[0052] A communication interface for inputting and / or outputting information;

[0053] The processor is used to execute a computer executable program so that an electronic device equipped with the chip device executes any one of the floating-point data processing methods in the second aspect and various possible implementations of the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1A According to some embodiments of the present application, a schematic diagram of a single-precision floating-point format is shown;

[0055] Figure 1B According to some embodiments of the present application, a single-precision floating point number (1+2 -2 )*2 -3 The corresponding 32-bit floating point format storage diagram in the computer;

[0056] Figure 2 According to some embodiments of the present application, a scene diagram is shown in which a terminal recognizes a collected face image through a trained neural network model;

[0057] Figure 3A According to some embodiments of the present application, a structural block diagram of a processor in a terminal device is shown;

[0058] Figure 3B According to some embodiments of the present application, a structural block diagram of another processor in a terminal device is shown;

[0059] Figure 4According to some embodiments of the present application, an interaction diagram of each unit in a processor using a reciprocal square root operation method is shown;

[0060] Figure 5 According to some embodiments of the present application, a flow chart of a method for calculating an inverse square root is shown;

[0061] Figure 6 According to some embodiments of the present application, a structural diagram of a server is shown. DETAILED DESCRIPTION

[0062] The illustrative embodiments of the present application include but are not limited to an electronic device and a floating point data processing method thereof, and a readable medium.

[0063] The technical solution of the present application determines the numerical range of the floating-point number that needs to be operated on the reciprocal square root, and thus determines whether the floating-point number needs to be operated on the reciprocal first and then the square root of the obtained reciprocal needs to be operated on according to the numerical range of the floating-point number; or whether the floating-point number needs to be operated on the square root first to obtain the square root of the floating-point number and then the square root of the floating-point number needs to be operated on the reciprocal square root. Thus, the reciprocal square root result of the floating-point number has a higher accuracy.

[0064] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the embodiment of the present application is further described in detail below in combination with the accompanying drawings and implementation schemes. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0065] In order to more clearly illustrate the solutions of the embodiments of the present application, some terms involved in the embodiments of the present application are explained below.

[0066] (I) Floating point numbers

[0067] Floating point number: Floating point number is a common data representation method in computers. The international standard IEEE 754 (Institute of Electrical and Electronics Engineers) is a floating point number representation standard. According to the IEEE 754 standard, a floating point number consists of three parts: the sign part, the exponent part, and the mantissa / decimal part, and any floating point number V can be expressed in the following forms:

[0068] V=(-1) s *M*2 e (Formula 1)

[0069] Where V represents the floating point value, s represents the sign part, e represents the exponent part, and M represents the mantissa / decimal part (fraction). When s=0, V is a positive number; when s=1, V is a negative number; the mantissa M is a binary number, and its range is 1 to 2-ε, or 0 to 1-ε, where ε represents infinitesimal; the role of e is to weight the floating point number, and this weight is 2 to the power of e, which can be positive, negative, or 0. For example, the floating point number corresponding to the decimal number 0.15625 is (-1) 0 *1.01*2 -3 For example, the floating point value corresponding to the decimal number 0.15625 is (1+2 -2 )*2 -3 , and then write the number into the floating point representation of formula 1 (-1) 0 *1.01*2 -3 , where V is (1+2 -2 )*2 -3 , the sign part s is 0, the exponent part e is -3, and the decimal part M is 1.01.

[0070] (II) Binary representation of floating point numbers

[0071] Floating point numbers occupy three fields in computer memory, namely, the sign s field, the biased exponent E field, and the decimal / mantissa M field. Taking the 32-bit binary representation of a single-precision floating point number as an example, the sign s field is a 1-bit binary number used to represent the sign part of the floating point number, the biased exponent E field is an 8-bit binary number used to represent the exponent part of the floating point number, where the 8-bit binary number of the biased exponent E field is determined by the exponent e and the exponent bias (bias), where the exponent bias (bias) will be explained below, and the decimal / mantissa M field is a 23-bit binary number used to represent the decimal / mantissa part of the floating point number.

[0072] Figure 1A The figure shows the 32-bit binary storage format of single-precision floating-point numbers in computers. From left to right in the figure, it is from high to low, and the highest bit is considered to be the 31st bit and the lowest bit is the 0th bit. The sign s field corresponds to the highest bit 31; the biased exponent E field corresponds to the 30th to 23rd bits; the decimal / mantissa M field corresponds to the 22nd to 0th bits.

[0073] Next, we will introduce the exponent bias. Because the exponent e in floating-point expression may be a negative number, when using Figure 1AWhen the 23rd to 30th bits are used to represent the exponent e, the 8-bit binary number corresponding to the biased exponent E field can represent a range of 0 to 255, so the IEEE 754 standard stipulates an exponent bias. The exponent e and the exponent bias are correlated and calculated to obtain the value of the biased exponent E, which is then converted into an 8-bit binary number and stored in the computer to represent the exponent part of the floating point number. IEEE 754 stipulates that the bias of a single-precision floating point number is 127, and the bias of a double-precision floating point number is 1023.

[0074] The IEEE 754 international standard can classify single-precision floating-point numbers into three types: normalized floating-point numbers, denormalized floating-point numbers, and special floating-point numbers, according to the 8-bit binary value of the biased exponent E field.

[0075] Next, the above three types of single-precision floating-point numbers are introduced respectively.

[0076] (1) Normalized floating point numbers

[0077] A normalized floating point number refers to a floating point number whose biased exponent E is greater than 0 and less than 255, and whose 8-bit binary number corresponding to the biased exponent E is neither all 0 (value 0) nor all 1. In this case, the value of the biased exponent E = the value of the exponent e + the exponent bias.

[0078] Normalized floating point numbers can be adjusted by adjusting the exponent e so that the range of the decimal / mantissa M is 1≤M<2, that is, M is written in the form of 1.xxxxx, for example, 0.0101*2 -2 , by adjusting the exponent e to get 1.01*2 -4 Since the first digit is always 1, there is no need to explicitly represent the first digit 1. The M field can be used to directly represent the number after the decimal point. That is, a 24-bit binary number can be represented by a 23-bit binary number. The above floating point representation is (-1) 0 *1.01*2 -3 Floating point number (1+2 -2 )*2 -3 For example, in this floating point representation, the sign s is 0, the exponent e is -3, and the decimal / mantissa M is 1.01. In computer storage, the one-bit binary number corresponding to the field of the sign s is 0, and the value of the biased exponent E is the exponent e + the exponent bias (bias), that is, -3+127=124, so the 8-bit binary number corresponding to the biased exponent E field is 01111100, and the 23-bit binary number corresponding to the mantissa / mantissa M field is 010000000000000000000000. Figure 1B Shows a single-precision floating point number (1+2 -2 )*2-3 The corresponding 32-bit floating-point format storage diagram in the computer. The binary value of the symbol s field in the figure is the value of 0 at the 31st bit in the figure, the 8-bit binary value corresponding to the biased exponent E field is the value from the 30th to the 23rd bit in the figure, which is 01111100, and the 23-bit binary value corresponding to the mantissa / decimal M field is the value from the 22nd to the 0th bit in the figure, which is 0100000000000000000000000. According to the IEEE 754 international standard, the smallest single-precision normalized floating-point value that can be represented is 1*2 -126 , the maximum single-precision normalized floating-point value is (2-ε)*2 127 , where ε represents infinitesimal.

[0079] (2) Denormalized floating point numbers

[0080] A denormalized floating point number is a floating point number whose biased exponent E is 0 and whose 8-bit binary number corresponding to the field of the biased exponent E is all 0. The IEEE 754 standard stipulates that in this case, the exponent e = 1-exponent bias, and the range of the decimal / mantissa M is 0≤M<1, that is, the value M is in the form of 0.xxxxx. In addition, a denormalized floating point number includes 0, which can be represented by the 8-bit binary number corresponding to the biased exponent E field being all 0 and the 23-bit binary number corresponding to the M field being all 0. According to the IEEE754 international standard, the smallest representable single-precision denormalized floating point number is 2 -149 , that is 2 -23 *2 -126 , the maximum single-precision denormalized floating point number is (1-ε)*2 -126 , where ε represents infinitesimal. For the smallest single-precision denormalized floating-point number 2 -149 , that is 2 -23 *2 -126 , the corresponding floating point form is (-1) 0 *0.00000000000000000000001*2 -126 , where the sign part s is 0, the exponent part e is -126, and the decimal / mantissa part M is 0.000000000000000000000001. The corresponding 32-bit binary number stored in the computer is: the binary value of the sign s field is 0, that is, the 31st bit is 0, the 8-bit binary value corresponding to the biased exponent E field is 00000000, that is, the value from the 30th to the 23rd bit is 00000000, and the 23-bit binary value corresponding to the mantissa / decimal M field is 0000000000000000000001, that is, the value from the 22nd to the 0th bit is 000000000000000000001.

[0081] (3) Special floating point numbers

[0082] A special floating point number is a floating point number whose biased exponent E is 255 and whose 8-bit binary number corresponding to the biased exponent E field is all 1. Special floating point numbers include positive infinity, negative infinity, and not a number (NaN). When the 23-bit binary number corresponding to the M field is all 0, the resulting value represents infinity, positive infinity when s=0, and negative infinity when s=1; when the 23-bit binary number corresponding to the M field is not all 0, the resulting value is called "NaN". For example, when the result of an operation cannot be a real number or infinity, such a NaN value will be returned.

[0083] (III) Reciprocal square root

[0084] The inverse square root can be defined as follows:

[0085]

[0086] Among them, rsqrt(x) is the corresponding square root reciprocal result of parameter x. It can be understood that x is greater than 0. If x is a real number greater than 0, it can be found from Formula 2 that the results obtained by first performing a reciprocal operation and then performing a square root operation on a real number x greater than 0 are the same as those obtained by first performing a square root operation and then performing a reciprocal operation. In practical applications, real numbers are often approximated to a finite decimal. However, when computers store floating-point numbers, they store floating-point numbers as 32-bit or 64-bit binary numbers. Since the range of floating-point numbers that can be represented by 32-bit or 64-bit binary numbers is limited. Therefore, in some cases, when the reciprocal operation is directly performed on the floating-point number, the range of the reciprocal obtained exceeds the range of floating-point numbers that can be represented by the aforementioned 32-bit or 64-bit binary numbers. In this case, when the computer performs a square root operation on the aforementioned reciprocal, it will output an infinite value or directly report an error.

[0087] In order to better understand the application of a floating point data processing method in this solution in the field of artificial intelligence technology, Figure 2A scene diagram is shown in which a terminal 200 is used to perform recognition operations on a collected face image by using a trained neural network model. In the figure, the terminal 200 is deployed with a face recognition model trained by the server 100. After the terminal 200 collects the face image of the user, the face recognition model can be used to perform face recognition on the collected face image to obtain a face recognition result. It should be noted that, in some cases, the various parameters in the face recognition model are stored in floating point form. Therefore, before the face recognition model is used to recognize the face recognition image, the face image needs to be processed into floating point data. In the process of recognizing the face image using the face recognition model, a large number of square root inverse operations of floating point numbers are involved. It can be understood that the main body that performs the square root inverse operation of floating point numbers in the terminal device 200 is generally a processor.

[0088] Figure 3A The structure block diagram of a processor 210 in the terminal device 200 is shown, which includes a special data processing unit 211, a reciprocal operation unit 212, a square root operation unit 213 and a multi-way selection unit 214.

[0089] Wherein, the special data processing unit 211 is used to judge the numerical range of the input floating-point number. In some embodiments, the special data processing unit 211 can also be used to directly calculate the reciprocal square root result of the floating-point number within the special data range. Specifically, it is judged whether the input floating-point number is within the special data range. If the floating-point number is within the special data range, the corresponding result is directly obtained according to the floating-point number. Wherein, the floating-point number that can directly obtain the square root operation result through the input floating-point number, and the floating-point number that does not need to be determined as the floating-point number within the special data range by judging the order of the reciprocal operation and the square root operation of the floating-point number. Wherein, the floating-point numbers within the range of the special data specifically include 0, negative number, positive infinity and NaN, and the corresponding reciprocal square root operation results are positive infinity, NaN, 0 and NaN.

[0090] The reciprocal operation unit 212 may be used to perform a reciprocal operation on a floating point number to obtain a reciprocal operation result.

[0091] The square root operation unit 213 may be configured to perform a square root operation on the reciprocal operation result obtained in the reciprocal operation unit 212 .

[0092] The multiplexing unit 214 may output a square root inverse operation result according to the operation results sent by the special data operation unit 211 , the inverse operation unit 212 , and the square root operation unit 213 .

[0093] It is understandable that the structure shown in the embodiment of the present application does not constitute a specific limitation on the processor 210. In other embodiments of the present application, the processor 210 may include Figure 3A More or fewer components may be shown, or some components may be combined or separated, or the components may be arranged differently. Figure 3A The components shown may be implemented in hardware, software or a combination of software and hardware.

[0094] Let's take face recognition as an example. Figure 3A The processor shown in the figure briefly introduces the process of performing the inverse square root operation during face recognition:

[0095] Specifically, after the processor 210 on the terminal 200 processes the collected facial image into floating-point data, when the neural network model is used to recognize the facial image, the processor 210 involves the square root reciprocal operation in the process of recognizing the facial image data represented in floating-point form. For example, after the special data processing unit 211 receives the input facial image data represented in floating-point form, it first performs special data judgment on the data used in the input facial image recognition process to determine whether the floating-point data is within the special data range. If it is within the special data range, the corresponding operation result is directly output and the result is sent to the multi-way selection unit 214; if the floating-point data is not within the special data range, the floating-point data is sent to the reciprocal operation unit 212 for reciprocal operation, and then the reciprocal operation value obtained is sent to the square root operation unit 213 for square root operation, and finally sent to the multi-way selection unit 214, and the multi-way selection unit 214 outputs data according to the received operation result.

[0096] However, in some cases, when the input floating-point data is small enough, the result obtained by performing a reciprocal operation and then a square root operation on the floating-point number may be infinite.

[0097] For example, the single-precision floating-point value involved in the face image recognition process is 2 -149 , that is, 2 -23 *2 -126 , the corresponding floating point form is (-1) 0 *0.00000000000000000000001*2 -126 When it is determined that the number is not within the range of the special data, the reciprocal operation unit 212 is used to perform a reciprocal operation on the number, and then the square root operation unit 213 is used to perform a square root operation on the reciprocal operation result, which will cause a large error. -149 When performing the reciprocal operation, 2 -149 The reciprocal of is 2 149 , 2 149If it exceeds the maximum range that can be represented by a single-precision floating-point number, the final result will be quite different from the true value, which will cause a large error.

[0098] In order to solve the above problem, the embodiment of the present application adds a control unit in the processor, and before performing the inverse square root calculation on a floating-point number, first determines whether the floating-point data to be calculated meets the operation conditions of the inverse square root. For example, if the floating-point data to be calculated is 0, a negative number, positive infinity, NaN, etc., then the floating-point data does not meet the operation conditions of the inverse square root; if the floating-point data to be calculated is not one of 0, a negative number, positive infinity and NaN, then the floating-point data meets the operation conditions of the inverse square root, and the inverse square root operation can be performed on the floating-point data.

[0099] When it is determined that the floating-point data to be calculated meets the operation conditions of the inverse square root, in order to make the calculated inverse square root result more accurate, the biased exponent E field corresponding to the floating-point data when stored in the computer can be determined, and then the order of performing the inverse operation and the square root operation on the floating-point data can be determined based on whether the value of the E field corresponding to the floating-point data reaches a set threshold.

[0100] For example, when the value of the E field of the floating-point data to be calculated is less than the set threshold, it indicates that after the floating-point data to be calculated is inverted, the inverted result obtained exceeds the numerical range that can be represented by the 32-bit binary number / 64-bit binary number corresponding to the single-precision floating-point number / double-precision floating-point number when stored in the computer. In this case, when the computer performs a square root operation on the aforementioned inverse, it will output an infinite value or directly report an error, and the result obtained is quite different from the true value. However, when the square root operation is performed on the floating-point number, the square root obtained is still within the data range that can be represented by the aforementioned 32-bit binary number / 64-bit binary number. Therefore, the square root of the floating-point number is first calculated and then the inverse is calculated, and the inverse of the square root obtained is more accurate.

[0101] For another example, when the value of the E field of the floating-point data to be calculated is greater than or equal to the set threshold, it indicates that after the floating-point data to be calculated is inverted, the inverted result obtained is still within the numerical range that can be represented by the 32-bit binary number / 64-bit binary number corresponding to the single-precision floating-point number / double-precision floating-point number when stored in the computer. In this case, the computer can first calculate the inverse of the floating-point data and then calculate the square root, and the inverse of the square root obtained is more accurate.

[0102] The aforementioned threshold value is determined by judging whether the result of the reciprocal operation on the floating-point number to be calculated is still within the range that can be represented by the floating-point number precision. For example, for a 32-bit single-precision floating-point number, the aforementioned threshold value is that the decimal value corresponding to the E field is 1. Then, when the value of the E field of the floating-point number to be calculated is less than the threshold value, the decimal value corresponding to the E field of the floating-point number to be calculated is 0; when the value of the E field of the floating-point number to be calculated is greater than or equal to the threshold value, the decimal value corresponding to the E field of the floating-point number to be calculated is greater than or equal to 1.

[0103] For example, in some embodiments, processor 210 processes single-precision floating point data 2 -149 The calculation method proposed in this application is used to calculate the inverse square root. -149 The floating point representation of is (-1) 0 *0.00000000000000000000001*2 -126 , the decimal value corresponding to the biased exponent E field is 0. The special data processing unit 211 of the processor 210 first determines the floating point data 2 -149 Whether the operation conditions of the inverse square root are met, in determining the floating point data 2 -149 Satisfies the calculation conditions for the inverse square root (that is, floating point data 2 -149 It is not one of the special data 0, negative number, positive infinity and NaN), and then judge the floating point data 2 -149 The corresponding decimal value of the biased exponent E field is 0, that is, if the above-mentioned threshold is not reached, the floating point data 2 -149 Perform a square root operation and invert the square root operation result to obtain floating point data 2 -149 The square root result of .

[0104] For example, in some embodiments, the processor 210 processes the single-precision floating-point data 2 125 The calculation method proposed in this application is used to calculate the inverse square root. 125 The floating point representation of is (-1) 0 *1.00000000000000000000000*2 125 , the corresponding decimal value of the biased exponent E field is 252. The special data processing unit 211 of the processor 210 first determines the floating point data 2 125 Whether the operation conditions of the inverse square root are met, in determining the floating point data 2 125 Satisfies the calculation conditions for the inverse square root (that is, floating point data 2 125 It is not one of the special data 0, negative number, positive infinity and NaN), and then judge the floating point data 2125 The corresponding decimal value of the biased exponent E field is 252, which is greater than the above-mentioned threshold. 125 Find the inverse, and then perform square root operation on the inverse to get floating point data 2 125 The square root result of .

[0105] like Figure 3B FIG. 2 is a block diagram of another processor 210 provided by the present application. Figure 3A The processor 210 shown, Figure 3B The processor 210 shown is added with a control unit 215. The control unit 215 is used to determine the order of performing reciprocal operation and square root operation on the floating-point number. Specifically, it is judged whether the floating-point number reaches a threshold value. If the floating-point data does not reach the set threshold value, it is determined that the floating-point number is firstly subjected to a square root operation by the floating-point number square root operation unit 213, and then the square root operation unit 213 sends the square root operation result to the reciprocal operation unit 212 for reciprocal operation; if the floating-point data reaches the set threshold value, it is determined that the floating-point number is firstly subjected to a reciprocal operation by the reciprocal operation unit 212, and then the reciprocal operation unit 212 sends the obtained reciprocal to the square root operation unit 213 for square root operation.

[0106] For example, Figure 3B As shown in sequence numbers ①'-②'-③', when the control unit 215 determines that the floating-point number reaches the set threshold, the floating-point number is sent to the reciprocal operation unit 212, the reciprocal operation unit 212 performs a reciprocal operation on the floating-point number to obtain a reciprocal operation result, and the reciprocal operation unit 212 sends the result to the square root operation unit 213, the square root operation unit 213 calculates the square root of the reciprocal operation result, obtains a reciprocal square root operation result, and sends the result to the multi-way selection unit 214.

[0107] For example, Figure 3B As shown in sequence numbers ①-②-③, when the control unit 215 determines that the floating-point number does not meet the set threshold, the floating-point number is sent to the square root operation unit 213. The square root operation unit 213 can perform a square root operation on the floating-point number to obtain a square root operation result. The square root operation unit 213 then sends the square root operation result to the reciprocal operation unit 212. The reciprocal operation unit 212 can perform a reciprocal operation on the received square root operation result to obtain a square root reciprocal operation result, and send the result to the multi-way selection unit 214.

[0108] As described above, the technical solution of the present application can obtain relatively accurate reciprocal square root calculation results for different floating-point numbers. On the other hand, the method utilizes the original operation logic circuit in the processor and only adds a control unit. Under the condition of effectively utilizing the hardware resources of the existing processor, the accuracy of the reciprocal square root calculation of the floating-point number can be improved at a relatively low cost.

[0109] It is understandable that the structure shown in the embodiment of the present application does not constitute a specific limitation on the processor 210. In other embodiments of the present application, the processor 210 may include Figure 3B More or fewer components may be shown, or some components may be combined or separated, or the components may be arranged differently. Figure 3B The components shown may be implemented in hardware, software or a combination of software and hardware.

[0110] It can be understood that when the processor 210 performs a reciprocal square root operation on floating-point data, the processor 210 may include but is not limited to a graphics processor (GPU), a central processing unit (CPU), a field-programmable gate array (FPGA), an application-specific integrated circuit (ASIC), a graphics processor (GPU), a neural network processor (NPU), a wearable processor (WPU), a holographic image processor (HPU) or other processors that can process floating-point data stored in binary storage form. The specific processor type is not specifically required here.

[0111] It is understandable that the terminal 200 can be other electronic devices that include a processor capable of performing reciprocal square root operations of floating-point numbers, including but not limited to mobile phones, tablet computers, smart screens, wearable devices (for example, watches, bracelets, helmets, headphones, etc.), vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), and other electronic devices.

[0112] In order to better understand the technical solution of the embodiment of the present application, the following will take single-precision floating-point numbers as an example. Figure 2 The application scenarios shown and Figure 3B The structure of the processor 210 is shown in FIG. Figure 4 A method for calculating the inverse square root is shown. In some of the following embodiments, the set threshold corresponding to the biased exponent E field value of the single-precision floating point number is 1. When the value of the biased exponent E field is less than the set threshold 1 of the biased exponent E field, the 8-bit binary number corresponding to the biased exponent E field is all 0. When the value of the biased exponent E field is greater than or equal to the set threshold 1 of the biased exponent E field, the 8-bit binary number corresponding to the biased exponent E field is not all 0. Specifically, Figure 4 The interaction flow diagram shown includes the following steps:

[0113] S401: The special data processing unit 211 receives an input floating point number.

[0114] Exemplarily, the special data processing unit 211 receives the floating point data -(1+2 -2 )*2 -3 When the floating-point data is stored in the computer, the sign s field is 1, the biased exponent E field is 01111100, and the decimal / mantissa M field is 01000000000000000000000000.

[0115] S402: The special data processing unit 211 determines whether the floating point number is within the special data range, thereby determining whether the floating point number satisfies the calculation condition of the inverse square root.

[0116] In some embodiments, the special data processing unit 211 in the processor 210 determines whether the received floating-point number is within the special data range. For example, it is determined whether the input floating-point number belongs to any one of NaN, 0, negative number, and positive infinity. If the special data processing unit 211 determines that the received floating-point number is within the above-mentioned special data range, it indicates that the floating-point number does not meet the operation conditions of the reciprocal square root, and the process proceeds to step 404. If the special data processing unit 211 determines that the received floating-point number is not within the above-mentioned special data range, it indicates that the floating-point number meets the operation conditions of the reciprocal square root, and the process proceeds to step S403, and the control unit 215 further determines the operation order of the reciprocal operation and the square root operation of the floating-point number.

[0117] Specifically, the special data processing unit 211 can judge whether the floating point number is within the special data range through the 32-bit binary number of the input single-precision floating point data, that is, the field of the sign s, the field of the biased exponent E, and the field of the decimal / mantissa M. When the 8-bit binary numbers corresponding to the field of the biased exponent E are all 1, the 23-bit binary numbers corresponding to the field of M are all 0, and the 1-bit binary number corresponding to the field of s is 0, the floating point number is judged to be positive infinity; when the 8-bit binary numbers corresponding to the field of the biased exponent E are all 1, and the 23-bit binary numbers corresponding to the field of M are not all 0, the floating point number is judged to be NaN; when the 1-bit binary number corresponding to the sign s field is 1, the floating point number is judged to be negative; when the 8-bit binary numbers corresponding to the field of the biased exponent E are all 0, and the 23-bit binary numbers corresponding to the field of M are all 0, the floating point number is judged to be 0.

[0118] For example, the floating point data in the face image recognition process received by the special data processing unit 211 is a negative number: -(1+2 -2 )*2 -3 , which is special data, proceed to step 404.

[0119] Exemplarily, the special data processing unit 211 receives the floating point data (1+2 -2 )*2 -3 , is not within the special data range, and the process goes to step 403. Specifically, according to judging that the symbol s field in the 32-bit binary number of the floating-point data input in the face image recognition process is 0, and the 8-bit binary number corresponding to the field of the biased exponent E is neither all 0 nor all 1, it is judged that the face image data is not within the special data range, and the process goes to step 403.

[0120] S403 : The special data processing unit 211 sends a floating point number to the control unit 215 .

[0121] In some embodiments, the special data processing unit 211 determines that the floating point number is not within the special data range, and sends the floating point number to the control unit 215 .

[0122] Exemplarily, the special data processing unit 211 determines the floating point data (1+2 -2 )*2 -3 If it is not in the special data range, the floating point data (1+2 -2 )*2 -3 Sent to the control unit 215.

[0123] S404: The special data processing unit 211 directly calculates the inverse square root result corresponding to the input floating point data.

[0124] In some embodiments, the special data processing unit 211 directly calculates the corresponding inverse square root result according to the input floating point data.

[0125] Exemplarily, if the special data processing unit 211 determines that the floating-point data in the face image recognition process is a negative number or NaN, then the result of the inverse square root operation of the floating-point number that is a negative number or NaN is NaN.

[0126] Exemplarily, when the special data processing unit 211 determines that the floating point data in the face image recognition process is 0, the inverse square root of the special data 0 is positive infinity.

[0127] Exemplarily, when the special data processing unit 211 determines that the floating point data in the face image recognition process is positive infinity, the inverse square root result of the special data is 0.

[0128] S405: The special data processing unit 211 sends the corresponding inverse square root result of the floating point number to the multi-way selection unit 214.

[0129] In some embodiments, the special data processing unit 211 sends the inverse square root result directly calculated in step S404 to the multiplexing unit 214 .

[0130] Exemplarily, the special data processing unit 211 sends the inverse square root result NaN, positive infinity or 0 directly calculated in step S404 to the multiplexing unit 214 .

[0131] S406: The control unit 215 determines whether the value of the biased exponent E field corresponding to the floating point number reaches a set threshold.

[0132] In some embodiments, the control unit 215 judges the floating point number sent in step 403, and judges whether the decimal value of the biased exponent E field corresponding to the floating point number reaches the set threshold 1. If the decimal value of the biased exponent E field corresponding to the floating point number is greater than or equal to the set threshold 1, the process proceeds to step S412. If the decimal value of the biased exponent E field corresponding to the floating point number is less than the set threshold 1, the process proceeds to step S407.

[0133] Correspondingly, the control unit 215 determines whether the 8-bit binary number corresponding to the biased exponent E field corresponding to the floating point number is all 0, and if the 8-bit binary number corresponding to the biased exponent E field corresponding to the floating point number is not all 0, the process proceeds to step S412. If the 8-bit binary number corresponding to the biased exponent E field corresponding to the floating point number is all 0, the process proceeds to step S407.

[0134] For example, the control unit 215 receives the floating point data (1+2 -2)*2 -3 It is determined that the decimal value of the biased exponent E field of the floating point number is 124, which is greater than the set threshold value 1. The corresponding 8-bit binary number corresponding to the biased exponent E field is 01111100. The fields of the biased exponent E are not all 0, and the process goes to step S412.

[0135] For example, the control unit 215 receives the floating point value 2 received during the face image recognition process sent in step 403. -149 Make a judgment, because the floating point data 2 -149 The decimal value of the corresponding biased exponent E field is 0, which is less than the set threshold 1, that is, the field of the biased exponent value E is 00000000, and the biased exponent fields are all 0, and step S407 is entered.

[0136] S407 : The control unit 215 sends the floating point number to the square root operation unit 213 .

[0137] For example, the control unit 215 sends the floating point number 2 in the face image recognition process to the square root operation unit 213 according to the threshold condition judgment result. -149 .

[0138] S408: The square root operation unit 213 performs a square root operation on the floating point number.

[0139] Exemplarily, the square root operation unit 213 receives the floating point data 2 in the face image recognition process sent by the control unit 215. -149 Performs a square root operation.

[0140] S409: The square root operation unit 213 sends the square root operation result of the floating point number to the reciprocal operation unit 212.

[0141] For example, in some embodiments, the square root operation unit 213 sends the floating point data 2 in the face image recognition process to the reciprocal operation unit 212. -149 The square root result of .

[0142] S410: The inverse operation unit 212 inverts the square root operation result of the floating point number to obtain the inverse square root of the floating point number.

[0143] In some embodiments, the reciprocal operation unit 212 performs a reciprocal operation on the square root operation result of the floating point number sent by the square root operation unit 213 to obtain the reciprocal square root of the floating point number.

[0144] For example, the reciprocal operation unit 212 receives the floating point data 2 sent by the square root operation unit 213 during the face image recognition process. -149 The square root operation result is then used to perform the reciprocal operation of the floating-point number to obtain the reciprocal square root result of the floating-point number.

[0145] S411: The reciprocal operation unit 212 sends the reciprocal square root of the floating point number to the multi-way selection unit 214.

[0146] Exemplarily, the inverse operation unit 212 sends the floating point value 2 in the face image recognition process to the multi-path selection unit 214. -149 The result of the square root operation and then the reciprocal of the operation result.

[0147] S412: The control unit 215 sends the floating point number to the inverse operation unit 212.

[0148] In some embodiments, the control unit 215 sends a floating point number to the inverse operation unit 212 according to the threshold determination result.

[0149] For example, the control unit 215 sends the floating point data (1+2 -2 )*2 -3 .

[0150] S413: The reciprocal operation unit 212 performs a floating point number reciprocal operation.

[0151] Exemplarily, the inverse operation unit 212 receives the floating point data (1+2 -2 )*2 -3 Perform the reciprocal operation.

[0152] S414: The reciprocal operation unit 212 sends the reciprocal operation result of the floating point number to the square root operation unit 213.

[0153] For example, in some embodiments, the reciprocal operation unit 212 sends the floating point data (1+2 -2 )*2 -3 The square root result of .

[0154] S415: The square root operation unit 213 calculates the square root of the reciprocal operation result of the floating point number to obtain the reciprocal square root of the floating point number.

[0155] In some embodiments, the square root operation unit 213 performs the operation on the floating point data (1+2 -2 )*2 -3 The reciprocal operation result is used to calculate the square root to obtain the reciprocal square root of the floating-point number.

[0156] S416: The square root operation unit 213 sends the reciprocal square root of the floating point number to the multi-way selection unit 214.

[0157] For example, the floating point data (1+2 -2 )*2 -3 The reciprocal square root of .

[0158] S417: The multi-path selection unit 214 outputs the calculation result.

[0159] In some embodiments, the multi-way selection unit 214 outputs the operation result obtained by calculating the inverse square root of the floating-point number using the operation method provided by the present application.

[0160] Exemplarily, the multi-way selection unit 214 outputs the operation result of the floating point data 0 in the face image recognition process sent by the special data processing unit 211 .

[0161] Exemplarily, the multi-way selection unit 214 outputs the floating point data (1+2 -2 )*2 -3 The reciprocal square root of .

[0162] Exemplarily, the multi-way selection unit 214 outputs the floating point data 2 sent by the inverse operation unit 213 during the face image recognition process. -149 The reciprocal square root of .

[0163] It can be understood that the execution order of the above steps S401 to S417 is only an example. In other embodiments, other execution orders may be adopted, and some steps may be split or combined, which is not limited here.

[0164] Below Figure 5 The flowchart shown in the figure is taken as an example, showing the above Figures 2 to 4 The specific steps of the method for calculating the inverse square root of a floating point number involved in the method are as follows. Specifically, the processor 210 in the terminal 200 is used as the execution subject, and the floating point data is described by taking single-precision floating point data as an example. Figure 5 The flowchart shown includes the following steps:

[0165] S501: Obtain input floating point data.

[0166] In some embodiments, the processor 210 in the terminal 200 obtains input floating point data.

[0167] Exemplarily, the processor 210 in the terminal 200 obtains floating point data in the face image recognition process, such as NaN, 0, -(1+2 -2 )*2 -3 , 2 -149 、(1+2 -2)*2 -3 And other data.

[0168] S502: Determine whether the floating point data is within a special data range, where the special data range is NaN, 0, negative numbers, and positive infinity, that is, determine whether the floating point data satisfies the inverse square root operation condition.

[0169] In some embodiments, the processor 210 in the terminal 200 determines that the received floating-point number is not within the special data range, that is, it is not one of NaN, 0, a negative number, and positive infinity, then it indicates that the above floating-point data satisfies the inverse square root operation condition; conversely, if the floating-point number is within the above special data range, that is, the floating-point number is one of NaN, 0, a negative number, and positive infinity, then it indicates that the above floating-point data does not satisfy the inverse square root operation condition.

[0170] For example, the floating point data in the process of determining and obtaining the face image recognition in the processor in the terminal 200 is -(1+2 -2 )*2 -3 , is not within the special data range, then -(1+2 -2 )*2 -3 Performs a reciprocal square root operation.

[0171] S503: When the floating point data is not within the special data range, it is determined whether the value of the biased exponent E field of the floating point data reaches a set threshold.

[0172] Exemplarily, the processor 210 in the terminal 200 determines the floating point data (1+2 -2 )*2 -3 It is not within the special data range, and further determines the floating point data (1+2 -2 )*2 -3 The corresponding decimal value of the biased exponent E field is 124, reaching the set threshold of 1.

[0173] Exemplarily, the processor 210 in the terminal 200 determines the floating point data 2 received during the face image recognition process. -149 Not within the special data range, further determine the floating point data 2 in the face image recognition process -149 The decimal value of the corresponding biased exponent E field is 0, which does not reach the aforementioned set threshold of 1.

[0174] S504: Determine the order of performing the reciprocal operation and the square root operation on the floating point data according to the result of determining whether the set threshold is reached.

[0175] Exemplarily, the processor 210 in the terminal 200 determines the floating point data (1+2 -2 )*2 -3 The decimal value of the biased exponent E field is 124, which is greater than the set threshold value 1. It is determined that the next operation sequence for the floating-point number is to first perform the reciprocal operation and then perform the square root operation.

[0176] Exemplarily, the processor 210 in the terminal 200 determines the floating point data 2 received during the face image recognition process. -149 The decimal value of the biased exponent E field is 0, which does not reach the set threshold value 1. It is determined that the next operation sequence for the floating point number is to first perform a square root operation and then perform a reciprocal operation.

[0177] S505: Perform operations on the floating-point data according to the operation sequence determined above, and output the operation results.

[0178] In some embodiments, the processor 210 in the terminal 200 determines that the next operation order for the floating-point number is to first perform a reciprocal operation and then a square root operation, and outputs the reciprocal square root operation result.

[0179] Exemplarily, the processor 210 in the terminal 200 determines the floating point data (1+2 -2 )*2 -3 The next operation sequence is to first perform the reciprocal operation and then the square root operation. The reciprocal operation is first performed on the floating point number and then the square root operation is performed, and the reciprocal square root operation result is output.

[0180] In some embodiments, the processor 210 in the terminal 200 determines that the next operation order for the floating point number is to first perform a square root operation and then a reciprocal operation, first perform a square root operation and then a reciprocal operation on the floating point number, and outputs the square root reciprocal operation result.

[0181] Exemplarily, the processor 210 in the terminal 200 determines the floating point data 2 in the face image recognition process. -149 The operation order is to first calculate the square root and then calculate the reciprocal. The square root and then the reciprocal operation are performed on the floating-point number, and the square root and reciprocal operation results are output.

[0182] To facilitate understanding of the technical solutions of each implementation of the present application, the hardware structure of the terminal 200 is introduced below.

[0183] further, Figure 6 According to some embodiments of the present application, a schematic diagram of the structure of a terminal 200 is shown. Figure 6 As shown, for executing the application provided Figure 5 The terminal 200 of the floating point number reciprocal square root operation method shown may include one or more processors 210, system memory 202, non-volatile memory (NVM) 203, input / output (I / O) device 204, communication interface 205, and system control logic 206 for coupling the processor 210, system memory 202, non-volatile memory 203, communication interface 204 and input / output (I / O) device 205. Wherein: the processor 210 may include one or more single-core or multi-core processors. In some embodiments, the processor 210 may include any combination of a general-purpose processor and a special-purpose processor (e.g., a graphics processor, an application processor, a baseband processor, etc.). In some embodiments, the processor 210 may be used to execute the floating point data processing method.

[0184] The system memory 202 is a volatile memory, such as a random-access memory (RAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), etc. The system memory is used to temporarily store data and / or instructions. For example, in some embodiments, the system memory 202 can be used to store the executable program for implementing the risk level determination method.

[0185] The non-volatile memory 203 may include one or more tangible, non-temporary computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 203 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as a hard disk drive (HDD), a compact disc (CD), a digital versatile disc (DVD), a solid-state drive (SSD), etc. In some embodiments, the non-volatile memory 203 may also be a removable storage medium, such as a secure digital (SD) memory card, etc.

[0186] In particular, the system memory 202 and the non-volatile memory 203 may respectively include: a temporary copy and a permanent copy of the instruction 207. The instruction 207 may include: program instructions that, when executed by at least one of the processors 210, enable the terminal 200 to implement the floating point data processing method provided in various embodiments of the present application.

[0187] The input / output (I / O) device 204 may include a user interface to enable a user to interact with the terminal 200. For example, in some embodiments, the input / output (I / O) device 204 may include an output device such as a display for displaying the result obtained after the terminal 200 executes the floating-point data processing method, and may also include input devices such as a keyboard, a mouse, and a touch screen. Product developers may interact with the terminal 200 through the user interface and input devices such as a keyboard, a mouse, and a touch screen.

[0188] The communication interface 205 may include a transceiver for providing a wired or wireless communication interface for the terminal 200, and then communicating with any other suitable device through one or more networks. In some embodiments, the communication interface 205 may be integrated into other components of the terminal 200, for example, the communication interface 205 may be integrated into the processor 210. In some embodiments, the terminal 200 can communicate with other devices through the communication interface 205.

[0189] System control logic 206 may include any suitable interface controller to provide any suitable interface with other modules of terminal 200. For example, in some embodiments, system control logic 206 may include one or more memory controllers to provide interfaces to system memory 202 and non-volatile memory 203.

[0190] In some embodiments, at least one of the processors 210 may be packaged together with the logic of one or more controllers for the system control logic 206 to form a system in package (SiP). In other embodiments, at least one of the processors 210 may also be integrated with the logic of one or more controllers for the system control logic 206 on the same chip to form a system-on-chip (SoC).

[0191] It can be understood that the terminal 200 can be any electronic device that can execute the risk level acquisition method provided in the present application, including but not limited to a computer, a server, a tablet computer, a handheld computer, etc., and the embodiments of the present application are not limited thereto.

[0192] It is understood that the structure of the terminal 200 shown in the embodiment of the present application does not constitute a specific limitation on the terminal 200. In other embodiments of the present application, the terminal 200 may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0193] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.

[0194] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.

[0195] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.

[0196] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROM), random access memories (RAM), erasable programmable read-only memories (EPROM), electrically erasable programmable read-only memories (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable memories for transmitting information (e.g., carrier waves, infrared signal digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).

[0197] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.

[0198] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.

[0199] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one" do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0200] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.

Claims

1. An electronic device, characterized in that: include: a memory for storing instructions to be executed by one or more processors of the electronic device, and Processor, when the instruction is executed by one or more processors of the electronic device, the processor performs the following operations: Get the input floating point data to be processed; Determine a biased exponent E field corresponding to the floating point data to be processed when it is stored in the electronic device; Determine that the floating-point data to be processed meets a reciprocal square root operation condition, and determine, according to the value of the E field, an operation order of performing a reciprocal operation and a square root operation on the floating-point data to be processed; Based on the control unit, when it is determined that the decimal value corresponding to the E field is less than a set threshold, firstly a square root operation is performed on the floating-point data to be processed to obtain a square root operation result of the floating-point data to be processed, and then a reciprocal operation is performed on the square root operation result to obtain a reciprocal square root of the floating-point data to be processed; or Based on the control unit, when it is determined that the decimal value corresponding to the E field is greater than or equal to the set threshold value, firstly performing a reciprocal operation on the floating-point data to be processed to obtain a reciprocal operation result of the floating-point data to be processed, and then performing a square root operation on the reciprocal operation result to obtain a reciprocal square root of the floating-point data to be processed; Output the inverse square root of the floating-point data to be processed.

2. The electronic device according to claim 1, characterized in that: The square root reciprocal operation conditions include: The floating-point data to be processed is not any one of 0, negative number, positive infinity, and NaN.

3. The electronic device according to claim 1 or 2, characterized in that: The processor determines the set threshold value by: Determining the number of bits of a binary value corresponding to the floating-point data to be processed when stored in the electronic device; Determine a floating-point data range that can be represented by a multi-bit binary number having the same number of bits as the binary value corresponding to the floating-point data to be processed; The set threshold is determined according to whether a reciprocal operation result obtained after performing a reciprocal operation on the floating-point data to be processed is within the floating-point data range.

4. The electronic device according to claim 1 or 2, characterized in that: The set threshold is 1.

5. The electronic device according to claim 4, characterized in that: The floating-point data to be processed is image data.

6. A method for processing floating point data, used in electronic equipment, characterized in that: and The method comprises: Get the input floating point data to be processed; Determine a biased exponent E field corresponding to the floating point data to be processed when it is stored in the electronic device; Determine that the floating-point data to be processed meets a reciprocal square root operation condition, and determine, according to the value of the E field, an operation order of performing a reciprocal operation and a square root operation on the floating-point data to be processed; Based on the control unit, when it is determined that the decimal value corresponding to the E field is less than a set threshold, firstly performing a square root operation on the floating-point data to be processed to obtain a square root operation result of the floating-point data to be processed, and then performing a reciprocal operation on the square root operation result to obtain a reciprocal square root of the floating-point data to be processed; or Based on the control unit, when it is determined that the decimal value corresponding to the E field is greater than or equal to the set threshold value, firstly performing a reciprocal operation on the floating-point data to be processed to obtain a reciprocal operation result of the floating-point data to be processed, and then performing a square root operation on the reciprocal operation result to obtain a reciprocal square root of the floating-point data to be processed; Output the inverse square root of the floating-point data to be processed.

7. The method according to claim 6, characterized in that The square root reciprocal operation conditions include: The floating-point data to be processed is not any one of 0, negative number, positive infinity, and NaN.

8. The method according to claim 6 or 7, characterized in that: The set threshold is determined by: Determining the number of bits of a binary value corresponding to the floating-point data to be processed when stored in the electronic device; Determine a floating-point data range that can be represented by a multi-bit binary number having the same number of bits as the binary value corresponding to the floating-point data to be processed; The set threshold is determined according to whether a reciprocal operation result obtained after performing a reciprocal operation on the floating-point data to be processed is within the floating-point data range.

9. The method according to claim 6 or 7, characterized in that: The set threshold is 1.

10. The method according to claim 9, characterized in that The floating-point data to be processed is image data.

11. An electronic device, characterized in that: include: A special data processing unit, used for obtaining input floating point data to be processed, and determining, according to a biased exponent E field corresponding to the floating point data to be processed when the floating point data to be processed is stored in the electronic device, that the floating point data to be processed satisfies a reciprocal square root operation condition; A control unit, configured to, when it is determined that the decimal value corresponding to the E field is less than a set threshold, first perform a square root operation on the floating-point data to be processed to obtain a square root operation result of the floating-point data to be processed, and then perform a reciprocal operation on the square root operation result to obtain a square root reciprocal of the floating-point data to be processed; or, when it is determined that the decimal value corresponding to the E field is greater than or equal to the set threshold, first perform a reciprocal operation on the floating-point data to be processed to obtain a reciprocal operation result of the floating-point data to be processed, and then perform a square root operation on the reciprocal operation result to obtain a square root reciprocal of the floating-point data to be processed; A reciprocal operation unit, used for performing a reciprocal operation on the floating-point data to be processed or a square root operation result of the floating-point data to be processed; A square root operation unit, used for performing a square root operation on the floating point data to be processed or a reciprocal operation result of the floating point data to be processed; A multi-way selection unit is used to output the inverse square root of the floating-point data to be processed.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on an electronic device, the electronic device executes the floating-point data processing method according to any one of claims 6 to 10.

13. A computer program product, characterized in that The computer program product comprises instructions for implementing the floating point data processing method according to any one of claims 6 to 10.

14. A chip device, characterized in that: The chip device comprises: A communication interface for inputting and / or outputting information; A processor is used to execute a computer executable program so that an electronic device equipped with the chip device executes the floating-point data processing method as described in any one of claims 6 to 10.

Citation Information

Patent Citations

  • Preliminary treatment circuit structure for floating point division and quadratic root algorithm

    CN101216753A

  • Apparatus and method for performing floating-point square root operation

    US20160026437A1

  • Integer division using floating-point reciprocal

    US8938485B1